Merge 3.9-rc5 into staging-next
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 1 Apr 2013 18:46:45 +0000 (11:46 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 1 Apr 2013 18:46:45 +0000 (11:46 -0700)
This pulls in all of the good fixes we need here.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
510 files changed:
Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt [new file with mode: 0644]
Documentation/devicetree/bindings/iio/iio-bindings.txt [new file with mode: 0644]
MAINTAINERS
drivers/hwmon/Kconfig
drivers/hwmon/Makefile
drivers/hwmon/iio_hwmon.c [new file with mode: 0644]
drivers/iio/accel/hid-sensor-accel-3d.c
drivers/iio/accel/kxsd9.c
drivers/iio/accel/st_accel_buffer.c
drivers/iio/adc/Kconfig
drivers/iio/adc/Makefile
drivers/iio/adc/ad7266.c
drivers/iio/adc/ad7298.c
drivers/iio/adc/ad7476.c
drivers/iio/adc/ad7887.c
drivers/iio/adc/ad7923.c [new file with mode: 0644]
drivers/iio/adc/ad_sigma_delta.c
drivers/iio/adc/at91_adc.c
drivers/iio/adc/exynos_adc.c [new file with mode: 0644]
drivers/iio/adc/lp8788_adc.c
drivers/iio/adc/max1363.c
drivers/iio/adc/ti-adc081c.c
drivers/iio/adc/ti_am335x_adc.c
drivers/iio/adc/viperboard_adc.c
drivers/iio/amplifiers/ad8366.c
drivers/iio/common/hid-sensors/hid-sensor-trigger.c
drivers/iio/common/st_sensors/st_sensors_spi.c
drivers/iio/common/st_sensors/st_sensors_trigger.c
drivers/iio/dac/ad5064.c
drivers/iio/dac/ad5360.c
drivers/iio/dac/ad5380.c
drivers/iio/dac/ad5421.c
drivers/iio/dac/ad5446.c
drivers/iio/dac/ad5449.c
drivers/iio/dac/ad5504.c
drivers/iio/dac/ad5624r_spi.c
drivers/iio/dac/ad5686.c
drivers/iio/dac/ad5755.c
drivers/iio/dac/ad5764.c
drivers/iio/dac/ad5791.c
drivers/iio/dac/max517.c
drivers/iio/dac/mcp4725.c
drivers/iio/frequency/ad9523.c
drivers/iio/gyro/adis16080.c
drivers/iio/gyro/adis16136.c
drivers/iio/gyro/adxrs450.c
drivers/iio/gyro/hid-sensor-gyro-3d.c
drivers/iio/gyro/itg3200_buffer.c
drivers/iio/gyro/itg3200_core.c
drivers/iio/gyro/st_gyro_buffer.c
drivers/iio/iio_core.h
drivers/iio/imu/adis16400_core.c
drivers/iio/imu/adis16480.c
drivers/iio/imu/adis_trigger.c
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
drivers/iio/industrialio-core.c
drivers/iio/industrialio-event.c
drivers/iio/inkern.c
drivers/iio/light/adjd_s311.c
drivers/iio/light/hid-sensor-als.c
drivers/iio/light/lm3533-als.c
drivers/iio/light/tsl2563.c
drivers/iio/light/vcnl4000.c
drivers/iio/magnetometer/hid-sensor-magn-3d.c
drivers/staging/Kconfig
drivers/staging/Makefile
drivers/staging/android/Kconfig
drivers/staging/android/Makefile
drivers/staging/android/ashmem.c
drivers/staging/android/ashmem.h
drivers/staging/android/binder.c
drivers/staging/android/logger.c
drivers/staging/android/logger.h
drivers/staging/android/lowmemorykiller.c
drivers/staging/android/sw_sync.c [new file with mode: 0644]
drivers/staging/android/sw_sync.h [new file with mode: 0644]
drivers/staging/android/sync.c [new file with mode: 0644]
drivers/staging/android/sync.h [new file with mode: 0644]
drivers/staging/android/trace/sync.h [new file with mode: 0644]
drivers/staging/bcm/Bcmchar.c
drivers/staging/bcm/InterfaceDld.c
drivers/staging/bcm/PHSModule.c
drivers/staging/bcm/nvm.c
drivers/staging/ccg/Kconfig [deleted file]
drivers/staging/ccg/Makefile [deleted file]
drivers/staging/ccg/TODO [deleted file]
drivers/staging/ccg/ccg.c [deleted file]
drivers/staging/ccg/composite.c [deleted file]
drivers/staging/ccg/composite.h [deleted file]
drivers/staging/ccg/config.c [deleted file]
drivers/staging/ccg/epautoconf.c [deleted file]
drivers/staging/ccg/f_acm.c [deleted file]
drivers/staging/ccg/f_fs.c [deleted file]
drivers/staging/ccg/f_mass_storage.c [deleted file]
drivers/staging/ccg/f_rndis.c [deleted file]
drivers/staging/ccg/gadget_chips.h [deleted file]
drivers/staging/ccg/ndis.h [deleted file]
drivers/staging/ccg/rndis.c [deleted file]
drivers/staging/ccg/rndis.h [deleted file]
drivers/staging/ccg/storage_common.c [deleted file]
drivers/staging/ccg/sysfs-class-ccg_usb [deleted file]
drivers/staging/ccg/u_ether.c [deleted file]
drivers/staging/ccg/u_ether.h [deleted file]
drivers/staging/ccg/u_serial.c [deleted file]
drivers/staging/ccg/u_serial.h [deleted file]
drivers/staging/ccg/usbstring.c [deleted file]
drivers/staging/comedi/Kconfig
drivers/staging/comedi/comedi_fops.c
drivers/staging/comedi/comedi_pci.c
drivers/staging/comedi/comedidev.h
drivers/staging/comedi/drivers.c
drivers/staging/comedi/drivers/8255_pci.c
drivers/staging/comedi/drivers/Makefile
drivers/staging/comedi/drivers/addi-data/APCI1710_Ssi.c
drivers/staging/comedi/drivers/addi-data/addi_common.c
drivers/staging/comedi/drivers/addi-data/addi_common.h
drivers/staging/comedi/drivers/addi_apci_035.c
drivers/staging/comedi/drivers/addi_apci_1032.c
drivers/staging/comedi/drivers/addi_apci_1500.c
drivers/staging/comedi/drivers/addi_apci_1516.c
drivers/staging/comedi/drivers/addi_apci_1564.c
drivers/staging/comedi/drivers/addi_apci_16xx.c
drivers/staging/comedi/drivers/addi_apci_1710.c
drivers/staging/comedi/drivers/addi_apci_2032.c
drivers/staging/comedi/drivers/addi_apci_2200.c
drivers/staging/comedi/drivers/addi_apci_3120.c
drivers/staging/comedi/drivers/addi_apci_3200.c
drivers/staging/comedi/drivers/addi_apci_3501.c
drivers/staging/comedi/drivers/addi_apci_3xxx.c
drivers/staging/comedi/drivers/adl_pci6208.c
drivers/staging/comedi/drivers/adl_pci7x3x.c
drivers/staging/comedi/drivers/adl_pci8164.c
drivers/staging/comedi/drivers/adl_pci9111.c
drivers/staging/comedi/drivers/adl_pci9118.c
drivers/staging/comedi/drivers/adv_pci1710.c
drivers/staging/comedi/drivers/adv_pci1723.c
drivers/staging/comedi/drivers/adv_pci1724.c [new file with mode: 0644]
drivers/staging/comedi/drivers/adv_pci_dio.c
drivers/staging/comedi/drivers/amplc_dio200.c
drivers/staging/comedi/drivers/amplc_dio200.h [new file with mode: 0644]
drivers/staging/comedi/drivers/amplc_dio200_common.c [new file with mode: 0644]
drivers/staging/comedi/drivers/amplc_dio200_pci.c [new file with mode: 0644]
drivers/staging/comedi/drivers/amplc_pc236.c
drivers/staging/comedi/drivers/amplc_pc263.c
drivers/staging/comedi/drivers/amplc_pci224.c
drivers/staging/comedi/drivers/amplc_pci230.c
drivers/staging/comedi/drivers/cb_pcidas.c
drivers/staging/comedi/drivers/cb_pcidas64.c
drivers/staging/comedi/drivers/cb_pcidda.c
drivers/staging/comedi/drivers/cb_pcimdas.c
drivers/staging/comedi/drivers/cb_pcimdda.c
drivers/staging/comedi/drivers/contec_pci_dio.c
drivers/staging/comedi/drivers/daqboard2000.c
drivers/staging/comedi/drivers/das08.h
drivers/staging/comedi/drivers/das08_cs.c
drivers/staging/comedi/drivers/das08_pci.c
drivers/staging/comedi/drivers/das16.c
drivers/staging/comedi/drivers/das16m1.c
drivers/staging/comedi/drivers/das1800.c
drivers/staging/comedi/drivers/dt3000.c
drivers/staging/comedi/drivers/dyna_pci10xx.c
drivers/staging/comedi/drivers/gsc_hpdi.c
drivers/staging/comedi/drivers/icp_multi.c
drivers/staging/comedi/drivers/jr3_pci.c
drivers/staging/comedi/drivers/ke_counter.c
drivers/staging/comedi/drivers/me4000.c
drivers/staging/comedi/drivers/me_daq.c
drivers/staging/comedi/drivers/mite.c
drivers/staging/comedi/drivers/ni_6527.c
drivers/staging/comedi/drivers/ni_65xx.c
drivers/staging/comedi/drivers/ni_660x.c
drivers/staging/comedi/drivers/ni_670x.c
drivers/staging/comedi/drivers/ni_at_a2150.c
drivers/staging/comedi/drivers/ni_atmio.c
drivers/staging/comedi/drivers/ni_labpc.c
drivers/staging/comedi/drivers/ni_labpc.h
drivers/staging/comedi/drivers/ni_labpc_cs.c
drivers/staging/comedi/drivers/ni_mio_common.c
drivers/staging/comedi/drivers/ni_pcidio.c
drivers/staging/comedi/drivers/ni_pcimio.c
drivers/staging/comedi/drivers/ni_stc.h
drivers/staging/comedi/drivers/pcl816.c
drivers/staging/comedi/drivers/rtd520.c
drivers/staging/comedi/drivers/rtd520.h [deleted file]
drivers/staging/comedi/drivers/s626.c
drivers/staging/comedi/drivers/s626.h
drivers/staging/comedi/drivers/skel.c
drivers/staging/comedi/drivers/usbdux.c
drivers/staging/comedi/drivers/usbduxsigma.c
drivers/staging/csr/csr_time.c
drivers/staging/csr/csr_wifi_fsm.h
drivers/staging/csr/csr_wifi_hip_card_sdio.c
drivers/staging/csr/drv.c
drivers/staging/csr/netdev.c
drivers/staging/csr/sdio_mmc.c
drivers/staging/csr/sme_native.c
drivers/staging/csr/sme_wext.c
drivers/staging/csr/unifi_pdu_processing.c
drivers/staging/dgrp/dgrp_dpa_ops.c
drivers/staging/dgrp/dgrp_mon_ops.c
drivers/staging/dgrp/dgrp_net_ops.c
drivers/staging/dgrp/dgrp_ports_ops.c
drivers/staging/dgrp/dgrp_specproc.c
drivers/staging/dwc2/Kconfig [new file with mode: 0644]
drivers/staging/dwc2/Makefile [new file with mode: 0644]
drivers/staging/dwc2/core.c [new file with mode: 0644]
drivers/staging/dwc2/core.h [new file with mode: 0644]
drivers/staging/dwc2/core_intr.c [new file with mode: 0644]
drivers/staging/dwc2/hcd.c [new file with mode: 0644]
drivers/staging/dwc2/hcd.h [new file with mode: 0644]
drivers/staging/dwc2/hcd_ddma.c [new file with mode: 0644]
drivers/staging/dwc2/hcd_intr.c [new file with mode: 0644]
drivers/staging/dwc2/hcd_queue.c [new file with mode: 0644]
drivers/staging/dwc2/hw.h [new file with mode: 0644]
drivers/staging/dwc2/pci.c [new file with mode: 0644]
drivers/staging/et131x/et131x.c
drivers/staging/gdm72xx/gdm_qos.c
drivers/staging/gdm72xx/netlink_k.c
drivers/staging/gdm72xx/sdio_boot.c
drivers/staging/iio/Documentation/trigger.txt
drivers/staging/iio/Kconfig
drivers/staging/iio/Makefile
drivers/staging/iio/accel/adis16201_core.c
drivers/staging/iio/accel/adis16203_core.c
drivers/staging/iio/accel/adis16204_core.c
drivers/staging/iio/accel/adis16209_core.c
drivers/staging/iio/accel/adis16220_core.c
drivers/staging/iio/accel/adis16240_core.c
drivers/staging/iio/accel/lis3l02dq_core.c
drivers/staging/iio/accel/lis3l02dq_ring.c
drivers/staging/iio/accel/sca3000_core.c
drivers/staging/iio/adc/Kconfig
drivers/staging/iio/adc/Makefile
drivers/staging/iio/adc/ad7280a.c
drivers/staging/iio/adc/ad7291.c
drivers/staging/iio/adc/ad7606_core.c
drivers/staging/iio/adc/ad799x.h
drivers/staging/iio/adc/ad799x_core.c
drivers/staging/iio/adc/ad799x_ring.c
drivers/staging/iio/adc/adt7410.c [deleted file]
drivers/staging/iio/adc/lpc32xx_adc.c
drivers/staging/iio/adc/mxs-lradc.c
drivers/staging/iio/adc/spear_adc.c
drivers/staging/iio/cdc/ad7150.c
drivers/staging/iio/cdc/ad7152.c
drivers/staging/iio/cdc/ad7746.c
drivers/staging/iio/gyro/adis16060_core.c
drivers/staging/iio/gyro/adis16130_core.c
drivers/staging/iio/gyro/adis16260_core.c
drivers/staging/iio/iio_hwmon.c [deleted file]
drivers/staging/iio/iio_simple_dummy.c
drivers/staging/iio/impedance-analyzer/ad5933.c
drivers/staging/iio/light/isl29018.c
drivers/staging/iio/light/isl29028.c
drivers/staging/iio/light/tsl2x7x_core.c
drivers/staging/iio/magnetometer/ak8975.c
drivers/staging/iio/magnetometer/hmc5843.c
drivers/staging/iio/meter/ade7758_core.c
drivers/staging/iio/meter/ade7758_trigger.c
drivers/staging/iio/resolver/ad2s1200.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-gpio.c
drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
drivers/staging/iio/trigger/iio-trig-sysfs.c
drivers/staging/imx-drm/ipu-v3/imx-ipu-v3.h
drivers/staging/imx-drm/ipu-v3/ipu-common.c
drivers/staging/imx-drm/ipu-v3/ipu-dp.c
drivers/staging/line6/pod.c
drivers/staging/media/davinci_vpfe/davinci-vpfe-mc.txt
drivers/staging/media/davinci_vpfe/dm365_isif.c
drivers/staging/media/davinci_vpfe/vpfe_video.c
drivers/staging/media/davinci_vpfe/vpfe_video.h
drivers/staging/netlogic/Kconfig [new file with mode: 0644]
drivers/staging/netlogic/Makefile [new file with mode: 0644]
drivers/staging/netlogic/TODO [new file with mode: 0644]
drivers/staging/netlogic/platform_net.c [new file with mode: 0644]
drivers/staging/netlogic/platform_net.h [new file with mode: 0644]
drivers/staging/netlogic/xlr_net.c [new file with mode: 0644]
drivers/staging/netlogic/xlr_net.h [new file with mode: 0644]
drivers/staging/nvec/nvec.c
drivers/staging/olpc_dcon/olpc_dcon.c
drivers/staging/omap-thermal/Kconfig [deleted file]
drivers/staging/omap-thermal/Makefile [deleted file]
drivers/staging/omap-thermal/TODO [deleted file]
drivers/staging/omap-thermal/omap-bandgap.c [deleted file]
drivers/staging/omap-thermal/omap-bandgap.h [deleted file]
drivers/staging/omap-thermal/omap-thermal-common.c [deleted file]
drivers/staging/omap-thermal/omap-thermal.h [deleted file]
drivers/staging/omap-thermal/omap4-thermal.c [deleted file]
drivers/staging/omap-thermal/omap5-thermal.c [deleted file]
drivers/staging/omap-thermal/omap_bandgap.txt [deleted file]
drivers/staging/rtl8192u/r8192U_dm.h
drivers/staging/rtl8712/rtl8712_led.c
drivers/staging/rtl8712/rtl871x_recv.h
drivers/staging/sb105x/sb_mp_register.h
drivers/staging/sb105x/sb_pci_mp.c
drivers/staging/sb105x/sb_pci_mp.h
drivers/staging/sep/sep_crypto.c
drivers/staging/sep/sep_driver_config.h
drivers/staging/sep/sep_main.c
drivers/staging/sep/sep_trace_events.h
drivers/staging/silicom/bp_mod.c
drivers/staging/silicom/bypasslib/bypass.c
drivers/staging/slicoss/slicoss.c
drivers/staging/sm7xxfb/sm7xxfb.c
drivers/staging/speakup/kobjects.c
drivers/staging/speakup/main.c
drivers/staging/speakup/speakup.h
drivers/staging/speakup/varhandlers.c
drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
drivers/staging/ti-soc-thermal/Kconfig [new file with mode: 0644]
drivers/staging/ti-soc-thermal/Makefile [new file with mode: 0644]
drivers/staging/ti-soc-thermal/TODO [new file with mode: 0644]
drivers/staging/ti-soc-thermal/omap4-thermal-data.c [new file with mode: 0644]
drivers/staging/ti-soc-thermal/omap4xxx-bandgap.h [new file with mode: 0644]
drivers/staging/ti-soc-thermal/omap5-thermal-data.c [new file with mode: 0644]
drivers/staging/ti-soc-thermal/omap5xxx-bandgap.h [new file with mode: 0644]
drivers/staging/ti-soc-thermal/ti-bandgap.c [new file with mode: 0644]
drivers/staging/ti-soc-thermal/ti-bandgap.h [new file with mode: 0644]
drivers/staging/ti-soc-thermal/ti-thermal-common.c [new file with mode: 0644]
drivers/staging/ti-soc-thermal/ti-thermal.h [new file with mode: 0644]
drivers/staging/ti-soc-thermal/ti_soc_thermal.txt [new file with mode: 0644]
drivers/staging/tidspbridge/rmgr/proc.c
drivers/staging/tidspbridge/rmgr/strm.c
drivers/staging/usbip/stub_dev.c
drivers/staging/usbip/userspace/libsrc/names.c
drivers/staging/usbip/userspace/libsrc/names.h
drivers/staging/usbip/userspace/libsrc/usbip_common.c
drivers/staging/usbip/userspace/libsrc/usbip_common.h
drivers/staging/usbip/userspace/libsrc/vhci_driver.c
drivers/staging/usbip/userspace/src/usbip_detach.c
drivers/staging/usbip/userspace/src/usbip_network.c
drivers/staging/usbip/userspace/src/usbip_network.h
drivers/staging/usbip/userspace/src/usbipd.c
drivers/staging/usbip/vhci_hcd.c
drivers/staging/vme/devices/vme_user.c
drivers/staging/vt6655/80211hdr.h
drivers/staging/vt6655/80211mgr.c
drivers/staging/vt6655/80211mgr.h
drivers/staging/vt6655/IEEE11h.c
drivers/staging/vt6655/IEEE11h.h
drivers/staging/vt6655/aes_ccmp.c
drivers/staging/vt6655/baseband.c
drivers/staging/vt6655/baseband.h
drivers/staging/vt6655/bssdb.c
drivers/staging/vt6655/bssdb.h
drivers/staging/vt6655/card.c
drivers/staging/vt6655/card.h
drivers/staging/vt6655/channel.c
drivers/staging/vt6655/channel.h
drivers/staging/vt6655/country.h
drivers/staging/vt6655/datarate.c
drivers/staging/vt6655/datarate.h
drivers/staging/vt6655/desc.h
drivers/staging/vt6655/device.h
drivers/staging/vt6655/device_cfg.h
drivers/staging/vt6655/device_main.c
drivers/staging/vt6655/dpc.c
drivers/staging/vt6655/dpc.h
drivers/staging/vt6655/hostap.c
drivers/staging/vt6655/hostap.h
drivers/staging/vt6655/iocmd.h
drivers/staging/vt6655/ioctl.c
drivers/staging/vt6655/ioctl.h
drivers/staging/vt6655/iowpa.h
drivers/staging/vt6655/iwctl.c
drivers/staging/vt6655/iwctl.h
drivers/staging/vt6655/key.c
drivers/staging/vt6655/key.h
drivers/staging/vt6655/mac.c
drivers/staging/vt6655/mac.h
drivers/staging/vt6655/mib.c
drivers/staging/vt6655/mib.h
drivers/staging/vt6655/michael.c
drivers/staging/vt6655/michael.h
drivers/staging/vt6655/power.c
drivers/staging/vt6655/power.h
drivers/staging/vt6655/rc4.c
drivers/staging/vt6655/rc4.h
drivers/staging/vt6655/rf.c
drivers/staging/vt6655/rf.h
drivers/staging/vt6655/rxtx.c
drivers/staging/vt6655/rxtx.h
drivers/staging/vt6655/srom.c
drivers/staging/vt6655/srom.h
drivers/staging/vt6655/tcrc.c
drivers/staging/vt6655/tcrc.h
drivers/staging/vt6655/tether.c
drivers/staging/vt6655/tether.h
drivers/staging/vt6655/tkip.c
drivers/staging/vt6655/tkip.h
drivers/staging/vt6655/tmacro.h
drivers/staging/vt6655/ttype.h
drivers/staging/vt6655/upc.h
drivers/staging/vt6655/vntwifi.c
drivers/staging/vt6655/vntwifi.h
drivers/staging/vt6655/wcmd.c
drivers/staging/vt6655/wcmd.h
drivers/staging/vt6655/wctl.c
drivers/staging/vt6655/wctl.h
drivers/staging/vt6655/wmgr.c
drivers/staging/vt6655/wmgr.h
drivers/staging/vt6655/wpa.c
drivers/staging/vt6655/wpa.h
drivers/staging/vt6655/wpa2.c
drivers/staging/vt6655/wpa2.h
drivers/staging/vt6655/wpactl.c
drivers/staging/vt6655/wpactl.h
drivers/staging/vt6655/wroute.c
drivers/staging/vt6655/wroute.h
drivers/staging/vt6656/80211hdr.h
drivers/staging/vt6656/80211mgr.c
drivers/staging/vt6656/80211mgr.h
drivers/staging/vt6656/TODO
drivers/staging/vt6656/aes_ccmp.c
drivers/staging/vt6656/aes_ccmp.h
drivers/staging/vt6656/baseband.c
drivers/staging/vt6656/baseband.h
drivers/staging/vt6656/bssdb.c
drivers/staging/vt6656/bssdb.h
drivers/staging/vt6656/card.c
drivers/staging/vt6656/card.h
drivers/staging/vt6656/channel.c
drivers/staging/vt6656/channel.h
drivers/staging/vt6656/control.c
drivers/staging/vt6656/control.h
drivers/staging/vt6656/country.h
drivers/staging/vt6656/datarate.c
drivers/staging/vt6656/datarate.h
drivers/staging/vt6656/desc.h
drivers/staging/vt6656/device.h
drivers/staging/vt6656/device_cfg.h
drivers/staging/vt6656/dpc.c
drivers/staging/vt6656/dpc.h
drivers/staging/vt6656/firmware.c
drivers/staging/vt6656/firmware.h
drivers/staging/vt6656/hostap.c
drivers/staging/vt6656/hostap.h
drivers/staging/vt6656/int.c
drivers/staging/vt6656/int.h
drivers/staging/vt6656/iocmd.h
drivers/staging/vt6656/iowpa.h
drivers/staging/vt6656/iwctl.c
drivers/staging/vt6656/iwctl.h
drivers/staging/vt6656/key.c
drivers/staging/vt6656/key.h
drivers/staging/vt6656/mac.c
drivers/staging/vt6656/mac.h
drivers/staging/vt6656/main_usb.c
drivers/staging/vt6656/mib.c
drivers/staging/vt6656/mib.h
drivers/staging/vt6656/michael.c
drivers/staging/vt6656/michael.h
drivers/staging/vt6656/power.c
drivers/staging/vt6656/power.h
drivers/staging/vt6656/rc4.c
drivers/staging/vt6656/rc4.h
drivers/staging/vt6656/rf.c
drivers/staging/vt6656/rf.h
drivers/staging/vt6656/rndis.h
drivers/staging/vt6656/rxtx.c
drivers/staging/vt6656/rxtx.h
drivers/staging/vt6656/srom.h
drivers/staging/vt6656/tcrc.c
drivers/staging/vt6656/tcrc.h
drivers/staging/vt6656/tether.c
drivers/staging/vt6656/tether.h
drivers/staging/vt6656/tkip.c
drivers/staging/vt6656/tkip.h
drivers/staging/vt6656/tmacro.h
drivers/staging/vt6656/ttype.h [deleted file]
drivers/staging/vt6656/usbpipe.c
drivers/staging/vt6656/usbpipe.h
drivers/staging/vt6656/wcmd.c
drivers/staging/vt6656/wcmd.h
drivers/staging/vt6656/wctl.c
drivers/staging/vt6656/wctl.h
drivers/staging/vt6656/wmgr.c
drivers/staging/vt6656/wmgr.h
drivers/staging/vt6656/wpa.c
drivers/staging/vt6656/wpa.h
drivers/staging/vt6656/wpa2.c
drivers/staging/vt6656/wpa2.h
drivers/staging/vt6656/wpactl.c
drivers/staging/vt6656/wpactl.h
drivers/staging/wlan-ng/prism2sta.c
drivers/staging/wlan-ng/prism2usb.c
drivers/staging/xgifb/vb_def.h
drivers/staging/xgifb/vb_init.c
drivers/staging/xgifb/vb_setmode.c
drivers/staging/xgifb/vb_struct.h
drivers/staging/xgifb/vb_table.h
drivers/staging/zcache/Kconfig
drivers/staging/zcache/Makefile
drivers/staging/zcache/TODO
drivers/staging/zcache/debug.c [new file with mode: 0644]
drivers/staging/zcache/debug.h [new file with mode: 0644]
drivers/staging/zcache/zcache-main.c
drivers/staging/zram/zram_drv.c
drivers/staging/zsmalloc/Kconfig
drivers/staging/zsmalloc/zsmalloc-main.c
include/linux/iio/adc/ad_sigma_delta.h
include/linux/iio/common/st_sensors.h
include/linux/iio/iio.h
include/linux/iio/imu/adis.h
include/linux/iio/trigger.h

diff --git a/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt b/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt
new file mode 100644 (file)
index 0000000..47ada1d
--- /dev/null
@@ -0,0 +1,60 @@
+Samsung Exynos Analog to Digital Converter bindings
+
+The devicetree bindings are for the new ADC driver written for
+Exynos4 and upward SoCs from Samsung.
+
+New driver handles the following
+1. Supports ADC IF found on EXYNOS4412/EXYNOS5250
+   and future SoCs from Samsung
+2. Add ADC driver under iio/adc framework
+3. Also adds the Documentation for device tree bindings
+
+Required properties:
+- compatible:          Must be "samsung,exynos-adc-v1"
+                               for exynos4412/5250 controllers.
+                       Must be "samsung,exynos-adc-v2" for
+                               future controllers.
+- reg:                 Contains ADC register address range (base address and
+                       length) and the address of the phy enable register.
+- interrupts:          Contains the interrupt information for the timer. The
+                       format is being dependent on which interrupt controller
+                       the Samsung device uses.
+- #io-channel-cells = <1>; As ADC has multiple outputs
+- clocks               From common clock binding: handle to adc clock.
+- clock-names          From common clock binding: Shall be "adc".
+- vdd-supply           VDD input supply.
+
+Note: child nodes can be added for auto probing from device tree.
+
+Example: adding device info in dtsi file
+
+adc: adc@12D10000 {
+       compatible = "samsung,exynos-adc-v1";
+       reg = <0x12D10000 0x100>, <0x10040718 0x4>;
+       interrupts = <0 106 0>;
+       #io-channel-cells = <1>;
+       io-channel-ranges;
+
+       clocks = <&clock 303>;
+       clock-names = "adc";
+
+       vdd-supply = <&buck5_reg>;
+};
+
+
+Example: Adding child nodes in dts file
+
+adc@12D10000 {
+
+       /* NTC thermistor is a hwmon device */
+       ncp15wb473@0 {
+               compatible = "ntc,ncp15wb473";
+               pullup-uV = <1800000>;
+               pullup-ohm = <47000>;
+               pulldown-ohm = <0>;
+               io-channels = <&adc 4>;
+       };
+};
+
+Note: Does not apply to ADC driver under arch/arm/plat-samsung/
+Note: The child node can be added under the adc node or separately.
diff --git a/Documentation/devicetree/bindings/iio/iio-bindings.txt b/Documentation/devicetree/bindings/iio/iio-bindings.txt
new file mode 100644 (file)
index 0000000..0b447d9
--- /dev/null
@@ -0,0 +1,97 @@
+This binding is derived from clock bindings, and based on suggestions
+from Lars-Peter Clausen [1].
+
+Sources of IIO channels can be represented by any node in the device
+tree. Those nodes are designated as IIO providers. IIO consumer
+nodes use a phandle and IIO specifier pair to connect IIO provider
+outputs to IIO inputs. Similar to the gpio specifiers, an IIO
+specifier is an array of one or more cells identifying the IIO
+output on a device. The length of an IIO specifier is defined by the
+value of a #io-channel-cells property in the IIO provider node.
+
+[1] http://marc.info/?l=linux-iio&m=135902119507483&w=2
+
+==IIO providers==
+
+Required properties:
+#io-channel-cells: Number of cells in an IIO specifier; Typically 0 for nodes
+                  with a single IIO output and 1 for nodes with multiple
+                  IIO outputs.
+
+Example for a simple configuration with no trigger:
+
+       adc: voltage-sensor@35 {
+               compatible = "maxim,max1139";
+               reg = <0x35>;
+               #io-channel-cells = <1>;
+       };
+
+Example for a configuration with trigger:
+
+       adc@35 {
+               compatible = "some-vendor,some-adc";
+               reg = <0x35>;
+
+               adc1: iio-device@0 {
+                       #io-channel-cells = <1>;
+                       /* other properties */
+               };
+               adc2: iio-device@1 {
+                       #io-channel-cells = <1>;
+                       /* other properties */
+               };
+       };
+
+==IIO consumers==
+
+Required properties:
+io-channels:   List of phandle and IIO specifier pairs, one pair
+               for each IIO input to the device. Note: if the
+               IIO provider specifies '0' for #io-channel-cells,
+               then only the phandle portion of the pair will appear.
+
+Optional properties:
+io-channel-names:
+               List of IIO input name strings sorted in the same
+               order as the io-channels property. Consumers drivers
+               will use io-channel-names to match IIO input names
+               with IIO specifiers.
+io-channel-ranges:
+               Empty property indicating that child nodes can inherit named
+               IIO channels from this node. Useful for bus nodes to provide
+               and IIO channel to their children.
+
+For example:
+
+       device {
+               io-channels = <&adc 1>, <&ref 0>;
+               io-channel-names = "vcc", "vdd";
+       };
+
+This represents a device with two IIO inputs, named "vcc" and "vdd".
+The vcc channel is connected to output 1 of the &adc device, and the
+vdd channel is connected to output 0 of the &ref device.
+
+==Example==
+
+       adc: max1139@35 {
+               compatible = "maxim,max1139";
+               reg = <0x35>;
+               #io-channel-cells = <1>;
+       };
+
+       ...
+
+       iio_hwmon {
+               compatible = "iio-hwmon";
+               io-channels = <&adc 0>, <&adc 1>, <&adc 2>,
+                       <&adc 3>, <&adc 4>, <&adc 5>,
+                       <&adc 6>, <&adc 7>, <&adc 8>,
+                       <&adc 9>;
+       };
+
+       some_consumer {
+               compatible = "some-consumer";
+               io-channels = <&adc 10>, <&adc 11>;
+               io-channel-names = "adc1", "adc2";
+       };
index 74e58a4d035b953fe2aa28f86b1cab87249a3223..6d91c6a7dbcb4f90f9c14146834c95198a0ff0c0 100644 (file)
@@ -2458,6 +2458,12 @@ M:       Matthew Garrett <mjg59@srcf.ucam.org>
 S:     Maintained
 F:     drivers/platform/x86/dell-wmi.c
 
+DESIGNWARE USB2 DRD IP DRIVER
+M:     Paul Zimmerman <paulz@synopsys.com>
+L:     linux-usb@vger.kernel.org
+S:     Maintained
+F:     drivers/staging/dwc2/
+
 DESIGNWARE USB3 DRD IP DRIVER
 M:     Felipe Balbi <balbi@ti.com>
 L:     linux-usb@vger.kernel.org
@@ -7920,6 +7926,12 @@ T:       git git://repo.or.cz/linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git
 S:     Maintained
 F:     drivers/platform/x86/thinkpad_acpi.c
 
+TI BANDGAP AND THERMAL DRIVER
+M:     Eduardo Valentin <eduardo.valentin@ti.com>
+L:     linux-pm@vger.kernel.org
+S:     Maintained
+F:     drivers/staging/omap-thermal/
+
 TI FLASH MEDIA INTERFACE DRIVER
 M:     Alex Dubov <oakad@yahoo.com>
 S:     Maintained
index 89ac1cb26f24e6649b40ec253436bc4ee96437a5..effbd11ff5ec3da870e177eaafc659ec44515432 100644 (file)
@@ -499,6 +499,15 @@ config SENSORS_IBMPEX
          This driver can also be built as a module.  If so, the module
          will be called ibmpex.
 
+config SENSORS_IIO_HWMON
+       tristate "Hwmon driver that uses channels specified via iio maps"
+       depends on IIO
+       help
+         This is a platform driver that in combination with a suitable
+         map allows IIO devices to provide basic hwmon functionality
+         for those channels specified in the map.  This map can be provided
+         either via platform data or the device tree bindings.
+
 config SENSORS_IT87
        tristate "ITE IT87xx and compatibles"
        depends on !PPC
index 8d6d97ea7c1e3d9e161f425cb236c79fce18c295..a87fdabddfffc2e49bf5872d3d9acc34ec4cdad4 100644 (file)
@@ -65,6 +65,7 @@ obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o
 obj-$(CONFIG_SENSORS_I5K_AMB)  += i5k_amb.o
 obj-$(CONFIG_SENSORS_IBMAEM)   += ibmaem.o
 obj-$(CONFIG_SENSORS_IBMPEX)   += ibmpex.o
+obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o
 obj-$(CONFIG_SENSORS_INA209)   += ina209.o
 obj-$(CONFIG_SENSORS_INA2XX)   += ina2xx.o
 obj-$(CONFIG_SENSORS_IT87)     += it87.o
diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
new file mode 100644 (file)
index 0000000..aafa453
--- /dev/null
@@ -0,0 +1,196 @@
+/* Hwmon client for industrial I/O devices
+ *
+ * Copyright (c) 2011 Jonathan Cameron
+ *
+ * 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/slab.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/hwmon.h>
+#include <linux/of.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/iio/consumer.h>
+#include <linux/iio/types.h>
+
+/**
+ * struct iio_hwmon_state - device instance state
+ * @channels:          filled with array of channels from iio
+ * @num_channels:      number of channels in channels (saves counting twice)
+ * @hwmon_dev:         associated hwmon device
+ * @attr_group:        the group of attributes
+ * @attrs:             null terminated array of attribute pointers.
+ */
+struct iio_hwmon_state {
+       struct iio_channel *channels;
+       int num_channels;
+       struct device *hwmon_dev;
+       struct attribute_group attr_group;
+       struct attribute **attrs;
+};
+
+/*
+ * Assumes that IIO and hwmon operate in the same base units.
+ * This is supposed to be true, but needs verification for
+ * new channel types.
+ */
+static ssize_t iio_hwmon_read_val(struct device *dev,
+                                 struct device_attribute *attr,
+                                 char *buf)
+{
+       int result;
+       int ret;
+       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+       struct iio_hwmon_state *state = dev_get_drvdata(dev);
+
+       ret = iio_read_channel_processed(&state->channels[sattr->index],
+                                       &result);
+       if (ret < 0)
+               return ret;
+
+       return sprintf(buf, "%d\n", result);
+}
+
+static ssize_t show_name(struct device *dev, struct device_attribute *attr,
+                        char *buf)
+{
+       const char *name = "iio_hwmon";
+
+       if (dev->of_node && dev->of_node->name)
+               name = dev->of_node->name;
+
+       return sprintf(buf, "%s\n", name);
+}
+
+static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
+
+static int iio_hwmon_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct iio_hwmon_state *st;
+       struct sensor_device_attribute *a;
+       int ret, i;
+       int in_i = 1, temp_i = 1, curr_i = 1;
+       enum iio_chan_type type;
+       struct iio_channel *channels;
+
+       channels = iio_channel_get_all(dev);
+       if (IS_ERR(channels))
+               return PTR_ERR(channels);
+
+       st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL);
+       if (st == NULL)
+               return -ENOMEM;
+
+       st->channels = channels;
+
+       /* count how many attributes we have */
+       while (st->channels[st->num_channels].indio_dev)
+               st->num_channels++;
+
+       st->attrs = devm_kzalloc(dev,
+                                sizeof(*st->attrs) * (st->num_channels + 2),
+                                GFP_KERNEL);
+       if (st->attrs == NULL) {
+               ret = -ENOMEM;
+               goto error_release_channels;
+       }
+
+       for (i = 0; i < st->num_channels; i++) {
+               a = devm_kzalloc(dev, sizeof(*a), GFP_KERNEL);
+               if (a == NULL) {
+                       ret = -ENOMEM;
+                       goto error_release_channels;
+               }
+
+               sysfs_attr_init(&a->dev_attr.attr);
+               ret = iio_get_channel_type(&st->channels[i], &type);
+               if (ret < 0)
+                       goto error_release_channels;
+
+               switch (type) {
+               case IIO_VOLTAGE:
+                       a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
+                                                         "in%d_input",
+                                                         in_i++);
+                       break;
+               case IIO_TEMP:
+                       a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
+                                                         "temp%d_input",
+                                                         temp_i++);
+                       break;
+               case IIO_CURRENT:
+                       a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
+                                                         "curr%d_input",
+                                                         curr_i++);
+                       break;
+               default:
+                       ret = -EINVAL;
+                       goto error_release_channels;
+               }
+               if (a->dev_attr.attr.name == NULL) {
+                       ret = -ENOMEM;
+                       goto error_release_channels;
+               }
+               a->dev_attr.show = iio_hwmon_read_val;
+               a->dev_attr.attr.mode = S_IRUGO;
+               a->index = i;
+               st->attrs[i] = &a->dev_attr.attr;
+       }
+       st->attrs[st->num_channels] = &dev_attr_name.attr;
+       st->attr_group.attrs = st->attrs;
+       platform_set_drvdata(pdev, st);
+       ret = sysfs_create_group(&dev->kobj, &st->attr_group);
+       if (ret < 0)
+               goto error_release_channels;
+
+       st->hwmon_dev = hwmon_device_register(dev);
+       if (IS_ERR(st->hwmon_dev)) {
+               ret = PTR_ERR(st->hwmon_dev);
+               goto error_remove_group;
+       }
+       return 0;
+
+error_remove_group:
+       sysfs_remove_group(&dev->kobj, &st->attr_group);
+error_release_channels:
+       iio_channel_release_all(st->channels);
+       return ret;
+}
+
+static int iio_hwmon_remove(struct platform_device *pdev)
+{
+       struct iio_hwmon_state *st = platform_get_drvdata(pdev);
+
+       hwmon_device_unregister(st->hwmon_dev);
+       sysfs_remove_group(&pdev->dev.kobj, &st->attr_group);
+       iio_channel_release_all(st->channels);
+
+       return 0;
+}
+
+static struct of_device_id iio_hwmon_of_match[] = {
+       { .compatible = "iio-hwmon", },
+       { }
+};
+
+static struct platform_driver __refdata iio_hwmon_driver = {
+       .driver = {
+               .name = "iio_hwmon",
+               .owner = THIS_MODULE,
+               .of_match_table = iio_hwmon_of_match,
+       },
+       .probe = iio_hwmon_probe,
+       .remove = iio_hwmon_remove,
+};
+
+module_platform_driver(iio_hwmon_driver);
+
+MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
+MODULE_DESCRIPTION("IIO to hwmon driver");
+MODULE_LICENSE("GPL v2");
index dd8ea428493450cfce48dfb3161202d85b5d9177..bbcbd7101f337cae06f458eb73f6420ce230fd8f 100644 (file)
@@ -60,28 +60,28 @@ static const struct iio_chan_spec accel_3d_channels[] = {
                .type = IIO_ACCEL,
                .modified = 1,
                .channel2 = IIO_MOD_X,
-               .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |
-               IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT |
-               IIO_CHAN_INFO_HYSTERESIS_SHARED_BIT,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+               BIT(IIO_CHAN_INFO_SCALE) |
+               BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+               BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_X,
        }, {
                .type = IIO_ACCEL,
                .modified = 1,
                .channel2 = IIO_MOD_Y,
-               .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |
-               IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT |
-               IIO_CHAN_INFO_HYSTERESIS_SHARED_BIT,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+               BIT(IIO_CHAN_INFO_SCALE) |
+               BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+               BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_Y,
        }, {
                .type = IIO_ACCEL,
                .modified = 1,
                .channel2 = IIO_MOD_Z,
-               .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |
-               IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT |
-               IIO_CHAN_INFO_HYSTERESIS_SHARED_BIT,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+               BIT(IIO_CHAN_INFO_SCALE) |
+               BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+               BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_Z,
        }
 };
index c2229a521ab9b58f7c902e0b7f1e0f21f94082ee..7229645bf1d74ca58b500218be9d1f2639d42d53 100644 (file)
@@ -177,8 +177,8 @@ error_ret:
                .type = IIO_ACCEL,                                      \
                .modified = 1,                                          \
                .channel2 = IIO_MOD_##axis,                             \
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |           \
-                       IIO_CHAN_INFO_SCALE_SHARED_BIT,                 \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
                .address = KXSD9_REG_##axis,                            \
        }
 
@@ -186,7 +186,7 @@ static const struct iio_chan_spec kxsd9_channels[] = {
        KXSD9_ACCEL_CHAN(X), KXSD9_ACCEL_CHAN(Y), KXSD9_ACCEL_CHAN(Z),
        {
                .type = IIO_VOLTAGE,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .indexed = 1,
                .address = KXSD9_REG_AUX,
        }
index 6bd82c7f769c51a7b45bbb81bb5d62ddf10daf31..d9b350756f90f11d1bc77cd88362fe45639d295e 100644 (file)
@@ -25,7 +25,7 @@
 
 int st_accel_trig_set_state(struct iio_trigger *trig, bool state)
 {
-       struct iio_dev *indio_dev = trig->private_data;
+       struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
 
        return st_sensors_set_dataready_irq(indio_dev, state);
 }
index e372257a84945dc5ef0082aded855b0f7578dc20..ab0767e6727ec5b5d04ac149b28e0247219c3a55 100644 (file)
@@ -30,6 +30,18 @@ config AD7298
          To compile this driver as a module, choose M here: the
          module will be called ad7298.
 
+config AD7923
+       tristate "Analog Devices AD7923 and similar ADCs driver"
+       depends on SPI
+       select IIO_BUFFER
+       select IIO_TRIGGERED_BUFFER
+       help
+         Say yes here to build support for Analog Devices
+         AD7904, AD7914, AD7923, AD7924 4 Channel ADCs.
+
+         To compile this driver as a module, choose M here: the
+         module will be called ad7923.
+
 config AD7791
        tristate "Analog Devices AD7791 ADC driver"
        depends on SPI
@@ -91,6 +103,14 @@ config AT91_ADC
        help
          Say yes here to build support for Atmel AT91 ADC.
 
+config EXYNOS_ADC
+       bool "Exynos ADC driver support"
+       depends on OF
+       help
+         Core support for the ADC block found in the Samsung EXYNOS series
+         of SoCs for drivers such as the touchscreen and hwmon to use to share
+         this resource.
+
 config LP8788_ADC
        bool "LP8788 ADC driver"
        depends on MFD_LP8788
index 2d5f10080d8d5ca6b4c86b14e85375e6ef0759f6..0a825bed43f6a1fa56e9901c1cb87520ceaee947 100644 (file)
@@ -5,11 +5,13 @@
 obj-$(CONFIG_AD_SIGMA_DELTA) += ad_sigma_delta.o
 obj-$(CONFIG_AD7266) += ad7266.o
 obj-$(CONFIG_AD7298) += ad7298.o
+obj-$(CONFIG_AD7923) += ad7923.o
 obj-$(CONFIG_AD7476) += ad7476.o
 obj-$(CONFIG_AD7791) += ad7791.o
 obj-$(CONFIG_AD7793) += ad7793.o
 obj-$(CONFIG_AD7887) += ad7887.o
 obj-$(CONFIG_AT91_ADC) += at91_adc.o
+obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
index bbad9b94cd75770b136499728497ff73ce4067d9..c2744a75c3b09e541fba56a9bcd66bfb0f02f940 100644 (file)
@@ -201,9 +201,9 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
        .indexed = 1,                                   \
        .channel = (_chan),                             \
        .address = (_chan),                             \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT     \
-               | IIO_CHAN_INFO_SCALE_SHARED_BIT        \
-               | IIO_CHAN_INFO_OFFSET_SHARED_BIT,      \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \
+               | BIT(IIO_CHAN_INFO_OFFSET),                    \
        .scan_index = (_chan),                          \
        .scan_type = {                                  \
                .sign = (_sign),                        \
@@ -249,9 +249,9 @@ static AD7266_DECLARE_SINGLE_ENDED_CHANNELS_FIXED(s, 's');
        .channel = (_chan) * 2,                         \
        .channel2 = (_chan) * 2 + 1,                    \
        .address = (_chan),                             \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT     \
-               | IIO_CHAN_INFO_SCALE_SHARED_BIT        \
-               | IIO_CHAN_INFO_OFFSET_SHARED_BIT,      \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE)    \
+               | BIT(IIO_CHAN_INFO_OFFSET),                    \
        .scan_index = (_chan),                          \
        .scan_type = {                                  \
                .sign = _sign,                  \
index b34d754994d50d53f60fee694440658ba0b137dd..03b77189dbfe64daac3b6bd562b8c56ad96297ee 100644 (file)
@@ -63,8 +63,8 @@ struct ad7298_state {
                .type = IIO_VOLTAGE,                                    \
                .indexed = 1,                                           \
                .channel = index,                                       \
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |           \
-               IIO_CHAN_INFO_SCALE_SHARED_BIT,                         \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
                .address = index,                                       \
                .scan_index = index,                                    \
                .scan_type = {                                          \
@@ -80,9 +80,9 @@ static const struct iio_chan_spec ad7298_channels[] = {
                .type = IIO_TEMP,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
-                       IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE) |
+                       BIT(IIO_CHAN_INFO_OFFSET),
                .address = AD7298_CH_TEMP,
                .scan_index = -1,
                .scan_type = {
index 1491fa6debb2c5e2cc8be063fbf3409e7b5d0b40..2e98bef4af673fd6ebadcac12d7ef56fe0c0d226 100644 (file)
@@ -140,12 +140,12 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
        return -EINVAL;
 }
 
-#define _AD7476_CHAN(bits, _shift, _info_mask)                 \
+#define _AD7476_CHAN(bits, _shift, _info_mask_sep)             \
        {                                                       \
        .type = IIO_VOLTAGE,                                    \
        .indexed = 1,                                           \
-       .info_mask = _info_mask |                               \
-       IIO_CHAN_INFO_SCALE_SHARED_BIT,                         \
+       .info_mask_separate = _info_mask_sep,                   \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
        .scan_type = {                                          \
                .sign = 'u',                                    \
                .realbits = (bits),                             \
@@ -156,9 +156,9 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
 }
 
 #define AD7476_CHAN(bits) _AD7476_CHAN((bits), 13 - (bits), \
-               IIO_CHAN_INFO_RAW_SEPARATE_BIT)
+               BIT(IIO_CHAN_INFO_RAW))
 #define AD7940_CHAN(bits) _AD7476_CHAN((bits), 15 - (bits), \
-               IIO_CHAN_INFO_RAW_SEPARATE_BIT)
+               BIT(IIO_CHAN_INFO_RAW))
 #define AD7091R_CHAN(bits) _AD7476_CHAN((bits), 16 - (bits), 0)
 
 static const struct ad7476_chip_info ad7476_chip_info_tbl[] = {
index a33d5cd1a53696062596f53f8a6216c61a0c7661..dd15a5b0f701a042446bb6ec9c3438a68dca5098 100644 (file)
@@ -207,8 +207,8 @@ static const struct ad7887_chip_info ad7887_chip_info_tbl[] = {
                        .type = IIO_VOLTAGE,
                        .indexed = 1,
                        .channel = 1,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SHARED_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+                       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                        .address = 1,
                        .scan_index = 1,
                        .scan_type = IIO_ST('u', 12, 16, 0),
@@ -217,8 +217,8 @@ static const struct ad7887_chip_info ad7887_chip_info_tbl[] = {
                        .type = IIO_VOLTAGE,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SHARED_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+                       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                        .address = 0,
                        .scan_index = 0,
                        .scan_type = IIO_ST('u', 12, 16, 0),
diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
new file mode 100644 (file)
index 0000000..97fa0d3
--- /dev/null
@@ -0,0 +1,383 @@
+/*
+ * AD7904/AD7914/AD7923/AD7924 SPI ADC driver
+ *
+ * Copyright 2011 Analog Devices Inc (from AD7923 Driver)
+ * Copyright 2012 CS Systemes d'Information
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/sysfs.h>
+#include <linux/spi/spi.h>
+#include <linux/regulator/consumer.h>
+#include <linux/err.h>
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+
+#define AD7923_WRITE_CR                (1 << 11)       /* write control register */
+#define AD7923_RANGE           (1 << 1)        /* range to REFin */
+#define AD7923_CODING          (1 << 0)        /* coding is straight binary */
+#define AD7923_PM_MODE_AS      (1)             /* auto shutdown */
+#define AD7923_PM_MODE_FS      (2)             /* full shutdown */
+#define AD7923_PM_MODE_OPS     (3)             /* normal operation */
+#define AD7923_CHANNEL_0       (0)             /* analog input 0 */
+#define AD7923_CHANNEL_1       (1)             /* analog input 1 */
+#define AD7923_CHANNEL_2       (2)             /* analog input 2 */
+#define AD7923_CHANNEL_3       (3)             /* analog input 3 */
+#define AD7923_SEQUENCE_OFF    (0)             /* no sequence fonction */
+#define AD7923_SEQUENCE_PROTECT        (2)             /* no interrupt write cycle */
+#define AD7923_SEQUENCE_ON     (3)             /* continuous sequence */
+
+#define AD7923_MAX_CHAN                4
+
+#define AD7923_PM_MODE_WRITE(mode)     (mode << 4)     /* write mode */
+#define AD7923_CHANNEL_WRITE(channel)  (channel << 6)  /* write channel */
+#define AD7923_SEQUENCE_WRITE(sequence)        (((sequence & 1) << 3) \
+                                       + ((sequence & 2) << 9))
+                                               /* write sequence fonction */
+/* left shift for CR : bit 11 transmit in first */
+#define AD7923_SHIFT_REGISTER  4
+
+/* val = value, dec = left shift, bits = number of bits of the mask */
+#define EXTRACT(val, dec, bits)                ((val >> dec) & ((1 << bits) - 1))
+
+struct ad7923_state {
+       struct spi_device               *spi;
+       struct spi_transfer             ring_xfer[5];
+       struct spi_transfer             scan_single_xfer[2];
+       struct spi_message              ring_msg;
+       struct spi_message              scan_single_msg;
+
+       struct regulator                *reg;
+
+       unsigned int                    settings;
+
+       /*
+        * DMA (thus cache coherency maintenance) requires the
+        * transfer buffers to live in their own cache lines.
+        */
+       __be16                          rx_buf[4] ____cacheline_aligned;
+       __be16                          tx_buf[4];
+};
+
+struct ad7923_chip_info {
+       const struct iio_chan_spec *channels;
+       unsigned int num_channels;
+};
+
+enum ad7923_id {
+       AD7904,
+       AD7914,
+       AD7924,
+};
+
+#define AD7923_V_CHAN(index, bits)                                     \
+       {                                                               \
+               .type = IIO_VOLTAGE,                                    \
+               .indexed = 1,                                           \
+               .channel = index,                                       \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
+               .address = index,                                       \
+               .scan_index = index,                                    \
+               .scan_type = {                                          \
+                       .sign = 'u',                                    \
+                       .realbits = (bits),                             \
+                       .storagebits = 16,                              \
+                       .endianness = IIO_BE,                           \
+               },                                                      \
+       }
+
+#define DECLARE_AD7923_CHANNELS(name, bits) \
+const struct iio_chan_spec name ## _channels[] = { \
+       AD7923_V_CHAN(0, bits), \
+       AD7923_V_CHAN(1, bits), \
+       AD7923_V_CHAN(2, bits), \
+       AD7923_V_CHAN(3, bits), \
+       IIO_CHAN_SOFT_TIMESTAMP(4), \
+}
+
+static DECLARE_AD7923_CHANNELS(ad7904, 8);
+static DECLARE_AD7923_CHANNELS(ad7914, 10);
+static DECLARE_AD7923_CHANNELS(ad7924, 12);
+
+static const struct ad7923_chip_info ad7923_chip_info[] = {
+       [AD7904] = {
+               .channels = ad7904_channels,
+               .num_channels = ARRAY_SIZE(ad7904_channels),
+       },
+       [AD7914] = {
+               .channels = ad7914_channels,
+               .num_channels = ARRAY_SIZE(ad7914_channels),
+       },
+       [AD7924] = {
+               .channels = ad7924_channels,
+               .num_channels = ARRAY_SIZE(ad7924_channels),
+       },
+};
+
+/**
+ * ad7923_update_scan_mode() setup the spi transfer buffer for the new scan mask
+ **/
+static int ad7923_update_scan_mode(struct iio_dev *indio_dev,
+       const unsigned long *active_scan_mask)
+{
+       struct ad7923_state *st = iio_priv(indio_dev);
+       int i, cmd, len;
+
+       len = 0;
+       for_each_set_bit(i, active_scan_mask, AD7923_MAX_CHAN) {
+               cmd = AD7923_WRITE_CR | AD7923_CHANNEL_WRITE(i) |
+                       AD7923_SEQUENCE_WRITE(AD7923_SEQUENCE_OFF) |
+                       st->settings;
+               cmd <<= AD7923_SHIFT_REGISTER;
+               st->tx_buf[len++] = cpu_to_be16(cmd);
+       }
+       /* build spi ring message */
+       st->ring_xfer[0].tx_buf = &st->tx_buf[0];
+       st->ring_xfer[0].len = len;
+       st->ring_xfer[0].cs_change = 1;
+
+       spi_message_init(&st->ring_msg);
+       spi_message_add_tail(&st->ring_xfer[0], &st->ring_msg);
+
+       for (i = 0; i < len; i++) {
+               st->ring_xfer[i + 1].rx_buf = &st->rx_buf[i];
+               st->ring_xfer[i + 1].len = 2;
+               st->ring_xfer[i + 1].cs_change = 1;
+               spi_message_add_tail(&st->ring_xfer[i + 1], &st->ring_msg);
+       }
+       /* make sure last transfer cs_change is not set */
+       st->ring_xfer[i + 1].cs_change = 0;
+
+       return 0;
+}
+
+/**
+ * ad7923_trigger_handler() bh of trigger launched polling to ring buffer
+ *
+ * Currently there is no option in this driver to disable the saving of
+ * timestamps within the ring.
+ **/
+static irqreturn_t ad7923_trigger_handler(int irq, void *p)
+{
+       struct iio_poll_func *pf = p;
+       struct iio_dev *indio_dev = pf->indio_dev;
+       struct ad7923_state *st = iio_priv(indio_dev);
+       s64 time_ns = 0;
+       int b_sent;
+
+       b_sent = spi_sync(st->spi, &st->ring_msg);
+       if (b_sent)
+               goto done;
+
+       if (indio_dev->scan_timestamp) {
+               time_ns = iio_get_time_ns();
+               memcpy((u8 *)st->rx_buf + indio_dev->scan_bytes - sizeof(s64),
+                       &time_ns, sizeof(time_ns));
+       }
+
+       iio_push_to_buffers(indio_dev, (u8 *)st->rx_buf);
+
+done:
+       iio_trigger_notify_done(indio_dev->trig);
+
+       return IRQ_HANDLED;
+}
+
+static int ad7923_scan_direct(struct ad7923_state *st, unsigned ch)
+{
+       int ret, cmd;
+
+       cmd = AD7923_WRITE_CR | AD7923_CHANNEL_WRITE(ch) |
+               AD7923_SEQUENCE_WRITE(AD7923_SEQUENCE_OFF) |
+               st->settings;
+       cmd <<= AD7923_SHIFT_REGISTER;
+       st->tx_buf[0] = cpu_to_be16(cmd);
+
+       ret = spi_sync(st->spi, &st->scan_single_msg);
+       if (ret)
+               return ret;
+
+       return be16_to_cpu(st->rx_buf[0]);
+}
+
+static int ad7923_get_range(struct ad7923_state *st)
+{
+       int vref;
+
+       vref = regulator_get_voltage(st->reg);
+       if (vref < 0)
+               return vref;
+
+       vref /= 1000;
+
+       if (!(st->settings & AD7923_RANGE))
+               vref *= 2;
+
+       return vref;
+}
+
+static int ad7923_read_raw(struct iio_dev *indio_dev,
+                          struct iio_chan_spec const *chan,
+                          int *val,
+                          int *val2,
+                          long m)
+{
+       int ret;
+       struct ad7923_state *st = iio_priv(indio_dev);
+
+       switch (m) {
+       case IIO_CHAN_INFO_RAW:
+               mutex_lock(&indio_dev->mlock);
+               if (iio_buffer_enabled(indio_dev))
+                       ret = -EBUSY;
+               else
+                       ret = ad7923_scan_direct(st, chan->address);
+               mutex_unlock(&indio_dev->mlock);
+
+               if (ret < 0)
+                       return ret;
+
+               if (chan->address == EXTRACT(ret, 12, 4))
+                       *val = EXTRACT(ret, 0, 12);
+               else
+                       return -EIO;
+
+               return IIO_VAL_INT;
+       case IIO_CHAN_INFO_SCALE:
+               ret = ad7923_get_range(st);
+               if (ret < 0)
+                       return ret;
+               *val = ret;
+               *val2 = chan->scan_type.realbits;
+               return IIO_VAL_FRACTIONAL_LOG2;
+       }
+       return -EINVAL;
+}
+
+static const struct iio_info ad7923_info = {
+       .read_raw = &ad7923_read_raw,
+       .update_scan_mode = ad7923_update_scan_mode,
+       .driver_module = THIS_MODULE,
+};
+
+static int ad7923_probe(struct spi_device *spi)
+{
+       struct ad7923_state *st;
+       struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
+       const struct ad7923_chip_info *info;
+       int ret;
+
+       if (indio_dev == NULL)
+               return -ENOMEM;
+
+       st = iio_priv(indio_dev);
+
+       spi_set_drvdata(spi, indio_dev);
+
+       st->spi = spi;
+       st->settings = AD7923_CODING | AD7923_RANGE |
+                       AD7923_PM_MODE_WRITE(AD7923_PM_MODE_OPS);
+
+       info = &ad7923_chip_info[spi_get_device_id(spi)->driver_data];
+
+       indio_dev->name = spi_get_device_id(spi)->name;
+       indio_dev->dev.parent = &spi->dev;
+       indio_dev->modes = INDIO_DIRECT_MODE;
+       indio_dev->channels = info->channels;
+       indio_dev->num_channels = info->num_channels;
+       indio_dev->info = &ad7923_info;
+
+       /* Setup default message */
+
+       st->scan_single_xfer[0].tx_buf = &st->tx_buf[0];
+       st->scan_single_xfer[0].len = 2;
+       st->scan_single_xfer[0].cs_change = 1;
+       st->scan_single_xfer[1].rx_buf = &st->rx_buf[0];
+       st->scan_single_xfer[1].len = 2;
+
+       spi_message_init(&st->scan_single_msg);
+       spi_message_add_tail(&st->scan_single_xfer[0], &st->scan_single_msg);
+       spi_message_add_tail(&st->scan_single_xfer[1], &st->scan_single_msg);
+
+       st->reg = regulator_get(&spi->dev, "refin");
+       if (IS_ERR(st->reg)) {
+               ret = PTR_ERR(st->reg);
+               goto error_free;
+       }
+       ret = regulator_enable(st->reg);
+       if (ret)
+               goto error_put_reg;
+
+       ret = iio_triggered_buffer_setup(indio_dev, NULL,
+                       &ad7923_trigger_handler, NULL);
+       if (ret)
+               goto error_disable_reg;
+
+       ret = iio_device_register(indio_dev);
+       if (ret)
+               goto error_cleanup_ring;
+
+       return 0;
+
+error_cleanup_ring:
+       iio_triggered_buffer_cleanup(indio_dev);
+error_disable_reg:
+       regulator_disable(st->reg);
+error_put_reg:
+       regulator_put(st->reg);
+error_free:
+       iio_device_free(indio_dev);
+
+       return ret;
+}
+
+static int ad7923_remove(struct spi_device *spi)
+{
+       struct iio_dev *indio_dev = spi_get_drvdata(spi);
+       struct ad7923_state *st = iio_priv(indio_dev);
+
+       iio_device_unregister(indio_dev);
+       iio_triggered_buffer_cleanup(indio_dev);
+       regulator_disable(st->reg);
+       regulator_put(st->reg);
+       iio_device_free(indio_dev);
+
+       return 0;
+}
+
+static const struct spi_device_id ad7923_id[] = {
+       {"ad7904", AD7904},
+       {"ad7914", AD7914},
+       {"ad7923", AD7924},
+       {"ad7924", AD7924},
+       {}
+};
+MODULE_DEVICE_TABLE(spi, ad7923_id);
+
+static struct spi_driver ad7923_driver = {
+       .driver = {
+               .name   = "ad7923",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = ad7923_probe,
+       .remove         = ad7923_remove,
+       .id_table       = ad7923_id,
+};
+module_spi_driver(ad7923_driver);
+
+MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
+MODULE_AUTHOR("Patrick Vasseur <patrick.vasseur@c-s.fr>");
+MODULE_DESCRIPTION("Analog Devices AD7904/AD7914/AD7923/AD7924 ADC");
+MODULE_LICENSE("GPL v2");
index afe6d78c8ff0f6cf4dcb54727e2999749010bdba..f0d6335ae08760d418f56ced0eaec227772fa1ce 100644 (file)
@@ -470,7 +470,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)
                disable_irq_nosync(sigma_delta->spi->irq);
        }
        sigma_delta->trig->dev.parent = &sigma_delta->spi->dev;
-       sigma_delta->trig->private_data = sigma_delta;
+       iio_trigger_set_drvdata(sigma_delta->trig, sigma_delta);
 
        ret = iio_trigger_register(sigma_delta->trig);
        if (ret)
index 83c836ba600f9678da11afbd199b62251230bda1..6fc43c15f02878a295c80d9aab6fbcbbe00f98c1 100644 (file)
@@ -140,8 +140,8 @@ static int at91_adc_channel_init(struct iio_dev *idev)
                chan->scan_type.sign = 'u';
                chan->scan_type.realbits = 10;
                chan->scan_type.storagebits = 16;
-               chan->info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT |
-                       IIO_CHAN_INFO_RAW_SEPARATE_BIT;
+               chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE);
+               chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
                idx++;
        }
        timestamp = chan_array + idx;
@@ -188,7 +188,7 @@ static u8 at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
 
 static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state)
 {
-       struct iio_dev *idev = trig->private_data;
+       struct iio_dev *idev = iio_trigger_get_drvdata(trig);
        struct at91_adc_state *st = iio_priv(idev);
        struct iio_buffer *buffer = idev->buffer;
        struct at91_adc_reg_desc *reg = st->registers;
@@ -254,7 +254,7 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev,
                return NULL;
 
        trig->dev.parent = idev->dev.parent;
-       trig->private_data = idev;
+       iio_trigger_set_drvdata(trig, idev);
        trig->ops = &at91_adc_trigger_ops;
 
        ret = iio_trigger_register(trig);
diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
new file mode 100644 (file)
index 0000000..9f3a8ef
--- /dev/null
@@ -0,0 +1,452 @@
+/*
+ *  exynos_adc.c - Support for ADC in EXYNOS SoCs
+ *
+ *  8 ~ 10 channel, 10/12-bit ADC
+ *
+ *  Copyright (C) 2013 Naveen Krishna Chatradhi <ch.naveen@samsung.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.
+ *
+ *  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>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/io.h>
+#include <linux/clk.h>
+#include <linux/completion.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>
+#include <linux/regulator/consumer.h>
+#include <linux/of_platform.h>
+
+#include <linux/iio/iio.h>
+#include <linux/iio/machine.h>
+#include <linux/iio/driver.h>
+
+enum adc_version {
+       ADC_V1,
+       ADC_V2
+};
+
+/* EXYNOS4412/5250 ADC_V1 registers definitions */
+#define ADC_V1_CON(x)          ((x) + 0x00)
+#define ADC_V1_DLY(x)          ((x) + 0x08)
+#define ADC_V1_DATX(x)         ((x) + 0x0C)
+#define ADC_V1_INTCLR(x)       ((x) + 0x18)
+#define ADC_V1_MUX(x)          ((x) + 0x1c)
+
+/* Future ADC_V2 registers definitions */
+#define ADC_V2_CON1(x)         ((x) + 0x00)
+#define ADC_V2_CON2(x)         ((x) + 0x04)
+#define ADC_V2_STAT(x)         ((x) + 0x08)
+#define ADC_V2_INT_EN(x)       ((x) + 0x10)
+#define ADC_V2_INT_ST(x)       ((x) + 0x14)
+#define ADC_V2_VER(x)          ((x) + 0x20)
+
+/* Bit definitions for ADC_V1 */
+#define ADC_V1_CON_RES         (1u << 16)
+#define ADC_V1_CON_PRSCEN      (1u << 14)
+#define ADC_V1_CON_PRSCLV(x)   (((x) & 0xFF) << 6)
+#define ADC_V1_CON_STANDBY     (1u << 2)
+
+/* Bit definitions for ADC_V2 */
+#define ADC_V2_CON1_SOFT_RESET (1u << 2)
+
+#define ADC_V2_CON2_OSEL       (1u << 10)
+#define ADC_V2_CON2_ESEL       (1u << 9)
+#define ADC_V2_CON2_HIGHF      (1u << 8)
+#define ADC_V2_CON2_C_TIME(x)  (((x) & 7) << 4)
+#define ADC_V2_CON2_ACH_SEL(x) (((x) & 0xF) << 0)
+#define ADC_V2_CON2_ACH_MASK   0xF
+
+#define MAX_ADC_V2_CHANNELS    10
+#define MAX_ADC_V1_CHANNELS    8
+
+/* Bit definitions common for ADC_V1 and ADC_V2 */
+#define ADC_CON_EN_START       (1u << 0)
+#define ADC_DATX_MASK          0xFFF
+
+#define EXYNOS_ADC_TIMEOUT     (msecs_to_jiffies(1000))
+
+struct exynos_adc {
+       void __iomem            *regs;
+       void __iomem            *enable_reg;
+       struct clk              *clk;
+       unsigned int            irq;
+       struct regulator        *vdd;
+
+       struct completion       completion;
+
+       u32                     value;
+       unsigned int            version;
+};
+
+static const struct of_device_id exynos_adc_match[] = {
+       { .compatible = "samsung,exynos-adc-v1", .data = (void *)ADC_V1 },
+       { .compatible = "samsung,exynos-adc-v2", .data = (void *)ADC_V2 },
+       {},
+};
+MODULE_DEVICE_TABLE(of, exynos_adc_match);
+
+static inline unsigned int exynos_adc_get_version(struct platform_device *pdev)
+{
+       const struct of_device_id *match;
+
+       match = of_match_node(exynos_adc_match, pdev->dev.of_node);
+       return (unsigned int)match->data;
+}
+
+static int exynos_read_raw(struct iio_dev *indio_dev,
+                               struct iio_chan_spec const *chan,
+                               int *val,
+                               int *val2,
+                               long mask)
+{
+       struct exynos_adc *info = iio_priv(indio_dev);
+       unsigned long timeout;
+       u32 con1, con2;
+
+       if (mask != IIO_CHAN_INFO_RAW)
+               return -EINVAL;
+
+       mutex_lock(&indio_dev->mlock);
+
+       /* Select the channel to be used and Trigger conversion */
+       if (info->version == ADC_V2) {
+               con2 = readl(ADC_V2_CON2(info->regs));
+               con2 &= ~ADC_V2_CON2_ACH_MASK;
+               con2 |= ADC_V2_CON2_ACH_SEL(chan->address);
+               writel(con2, ADC_V2_CON2(info->regs));
+
+               con1 = readl(ADC_V2_CON1(info->regs));
+               writel(con1 | ADC_CON_EN_START,
+                               ADC_V2_CON1(info->regs));
+       } else {
+               writel(chan->address, ADC_V1_MUX(info->regs));
+
+               con1 = readl(ADC_V1_CON(info->regs));
+               writel(con1 | ADC_CON_EN_START,
+                               ADC_V1_CON(info->regs));
+       }
+
+       timeout = wait_for_completion_interruptible_timeout
+                       (&info->completion, EXYNOS_ADC_TIMEOUT);
+       *val = info->value;
+
+       mutex_unlock(&indio_dev->mlock);
+
+       if (timeout == 0)
+               return -ETIMEDOUT;
+
+       return IIO_VAL_INT;
+}
+
+static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
+{
+       struct exynos_adc *info = (struct exynos_adc *)dev_id;
+
+       /* Read value */
+       info->value = readl(ADC_V1_DATX(info->regs)) &
+                                               ADC_DATX_MASK;
+       /* clear irq */
+       if (info->version == ADC_V2)
+               writel(1, ADC_V2_INT_ST(info->regs));
+       else
+               writel(1, ADC_V1_INTCLR(info->regs));
+
+       complete(&info->completion);
+
+       return IRQ_HANDLED;
+}
+
+static int exynos_adc_reg_access(struct iio_dev *indio_dev,
+                             unsigned reg, unsigned writeval,
+                             unsigned *readval)
+{
+       struct exynos_adc *info = iio_priv(indio_dev);
+
+       if (readval == NULL)
+               return -EINVAL;
+
+       *readval = readl(info->regs + reg);
+
+       return 0;
+}
+
+static const struct iio_info exynos_adc_iio_info = {
+       .read_raw = &exynos_read_raw,
+       .debugfs_reg_access = &exynos_adc_reg_access,
+       .driver_module = THIS_MODULE,
+};
+
+#define ADC_CHANNEL(_index, _id) {                     \
+       .type = IIO_VOLTAGE,                            \
+       .indexed = 1,                                   \
+       .channel = _index,                              \
+       .address = _index,                              \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
+       .datasheet_name = _id,                          \
+}
+
+static const struct iio_chan_spec exynos_adc_iio_channels[] = {
+       ADC_CHANNEL(0, "adc0"),
+       ADC_CHANNEL(1, "adc1"),
+       ADC_CHANNEL(2, "adc2"),
+       ADC_CHANNEL(3, "adc3"),
+       ADC_CHANNEL(4, "adc4"),
+       ADC_CHANNEL(5, "adc5"),
+       ADC_CHANNEL(6, "adc6"),
+       ADC_CHANNEL(7, "adc7"),
+       ADC_CHANNEL(8, "adc8"),
+       ADC_CHANNEL(9, "adc9"),
+};
+
+static int exynos_adc_remove_devices(struct device *dev, void *c)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+
+       platform_device_unregister(pdev);
+
+       return 0;
+}
+
+static void exynos_adc_hw_init(struct exynos_adc *info)
+{
+       u32 con1, con2;
+
+       if (info->version == ADC_V2) {
+               con1 = ADC_V2_CON1_SOFT_RESET;
+               writel(con1, ADC_V2_CON1(info->regs));
+
+               con2 = ADC_V2_CON2_OSEL | ADC_V2_CON2_ESEL |
+                       ADC_V2_CON2_HIGHF | ADC_V2_CON2_C_TIME(0);
+               writel(con2, ADC_V2_CON2(info->regs));
+
+               /* Enable interrupts */
+               writel(1, ADC_V2_INT_EN(info->regs));
+       } else {
+               /* set default prescaler values and Enable prescaler */
+               con1 =  ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
+
+               /* Enable 12-bit ADC resolution */
+               con1 |= ADC_V1_CON_RES;
+               writel(con1, ADC_V1_CON(info->regs));
+       }
+}
+
+static int exynos_adc_probe(struct platform_device *pdev)
+{
+       struct exynos_adc *info = NULL;
+       struct device_node *np = pdev->dev.of_node;
+       struct iio_dev *indio_dev = NULL;
+       struct resource *mem;
+       int ret = -ENODEV;
+       int irq;
+
+       if (!np)
+               return ret;
+
+       indio_dev = iio_device_alloc(sizeof(struct exynos_adc));
+       if (!indio_dev) {
+               dev_err(&pdev->dev, "failed allocating iio device\n");
+               return -ENOMEM;
+       }
+
+       info = iio_priv(indio_dev);
+
+       mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       info->regs = devm_request_and_ioremap(&pdev->dev, mem);
+       if (!info->regs) {
+               ret = -ENOMEM;
+               goto err_iio;
+       }
+
+       mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+       info->enable_reg = devm_request_and_ioremap(&pdev->dev, mem);
+       if (!info->enable_reg) {
+               ret = -ENOMEM;
+               goto err_iio;
+       }
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
+               dev_err(&pdev->dev, "no irq resource?\n");
+               ret = irq;
+               goto err_iio;
+       }
+
+       info->irq = irq;
+
+       init_completion(&info->completion);
+
+       ret = request_irq(info->irq, exynos_adc_isr,
+                                       0, dev_name(&pdev->dev), info);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "failed requesting irq, irq = %d\n",
+                                                       info->irq);
+               goto err_iio;
+       }
+
+       writel(1, info->enable_reg);
+
+       info->clk = devm_clk_get(&pdev->dev, "adc");
+       if (IS_ERR(info->clk)) {
+               dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
+                                                       PTR_ERR(info->clk));
+               ret = PTR_ERR(info->clk);
+               goto err_irq;
+       }
+
+       info->vdd = devm_regulator_get(&pdev->dev, "vdd");
+       if (IS_ERR(info->vdd)) {
+               dev_err(&pdev->dev, "failed getting regulator, err = %ld\n",
+                                                       PTR_ERR(info->vdd));
+               ret = PTR_ERR(info->vdd);
+               goto err_irq;
+       }
+
+       info->version = exynos_adc_get_version(pdev);
+
+       platform_set_drvdata(pdev, indio_dev);
+
+       indio_dev->name = dev_name(&pdev->dev);
+       indio_dev->dev.parent = &pdev->dev;
+       indio_dev->dev.of_node = pdev->dev.of_node;
+       indio_dev->info = &exynos_adc_iio_info;
+       indio_dev->modes = INDIO_DIRECT_MODE;
+       indio_dev->channels = exynos_adc_iio_channels;
+
+       if (info->version == ADC_V1)
+               indio_dev->num_channels = MAX_ADC_V1_CHANNELS;
+       else
+               indio_dev->num_channels = MAX_ADC_V2_CHANNELS;
+
+       ret = iio_device_register(indio_dev);
+       if (ret)
+               goto err_irq;
+
+       ret = regulator_enable(info->vdd);
+       if (ret)
+               goto err_iio_dev;
+
+       clk_prepare_enable(info->clk);
+
+       exynos_adc_hw_init(info);
+
+       ret = of_platform_populate(np, exynos_adc_match, NULL, &pdev->dev);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "failed adding child nodes\n");
+               goto err_of_populate;
+       }
+
+       return 0;
+
+err_of_populate:
+       device_for_each_child(&pdev->dev, NULL,
+                               exynos_adc_remove_devices);
+       regulator_disable(info->vdd);
+       clk_disable_unprepare(info->clk);
+err_iio_dev:
+       iio_device_unregister(indio_dev);
+err_irq:
+       free_irq(info->irq, info);
+err_iio:
+       iio_device_free(indio_dev);
+       return ret;
+}
+
+static int exynos_adc_remove(struct platform_device *pdev)
+{
+       struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+       struct exynos_adc *info = iio_priv(indio_dev);
+
+       device_for_each_child(&pdev->dev, NULL,
+                               exynos_adc_remove_devices);
+       regulator_disable(info->vdd);
+       clk_disable_unprepare(info->clk);
+       writel(0, info->enable_reg);
+       iio_device_unregister(indio_dev);
+       free_irq(info->irq, info);
+       iio_device_free(indio_dev);
+
+       return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int exynos_adc_suspend(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct exynos_adc *info = platform_get_drvdata(pdev);
+       u32 con;
+
+       if (info->version == ADC_V2) {
+               con = readl(ADC_V2_CON1(info->regs));
+               con &= ~ADC_CON_EN_START;
+               writel(con, ADC_V2_CON1(info->regs));
+       } else {
+               con = readl(ADC_V1_CON(info->regs));
+               con |= ADC_V1_CON_STANDBY;
+               writel(con, ADC_V1_CON(info->regs));
+       }
+
+       clk_disable_unprepare(info->clk);
+       writel(0, info->enable_reg);
+       regulator_disable(info->vdd);
+
+       return 0;
+}
+
+static int exynos_adc_resume(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct exynos_adc *info = platform_get_drvdata(pdev);
+       int ret;
+
+       ret = regulator_enable(info->vdd);
+       if (ret)
+               return ret;
+
+       writel(1, info->enable_reg);
+       clk_prepare_enable(info->clk);
+
+       exynos_adc_hw_init(info);
+
+       return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(exynos_adc_pm_ops,
+                       exynos_adc_suspend,
+                       exynos_adc_resume);
+
+static struct platform_driver exynos_adc_driver = {
+       .probe          = exynos_adc_probe,
+       .remove         = exynos_adc_remove,
+       .driver         = {
+               .name   = "exynos-adc",
+               .owner  = THIS_MODULE,
+               .of_match_table = exynos_adc_match,
+               .pm     = &exynos_adc_pm_ops,
+       },
+};
+
+module_platform_driver(exynos_adc_driver);
+
+MODULE_AUTHOR("Naveen Krishna Chatradhi <ch.naveen@samsung.com>");
+MODULE_DESCRIPTION("Samsung EXYNOS5 ADC driver");
+MODULE_LICENSE("GPL v2");
index 763f57565ee43fe98701d3b42c9e16511031a000..62bc39e9c94f239651f922817268bb98024e6b1e 100644 (file)
@@ -132,8 +132,8 @@ static const struct iio_info lp8788_adc_info = {
                .type = _type,                                  \
                .indexed = 1,                                   \
                .channel = LPADC_##_id,                         \
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |   \
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT,       \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |  \
+                       BIT(IIO_CHAN_INFO_SCALE),               \
                .datasheet_name = #_id,                         \
 }
 
index 6c1cfb74bdfc394c0a04b6653d23669edfd1568b..9e6da72ad82324d1a7b2d11294d9da76616408ba 100644 (file)
@@ -427,15 +427,15 @@ static const enum max1363_modes max1363_mode_list[] = {
 #define MAX1363_EV_M                                           \
        (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)      \
         | IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
-#define MAX1363_INFO_MASK (IIO_CHAN_INFO_RAW_SEPARATE_BIT |    \
-                          IIO_CHAN_INFO_SCALE_SHARED_BIT)
+
 #define MAX1363_CHAN_U(num, addr, si, bits, evmask)                    \
        {                                                               \
                .type = IIO_VOLTAGE,                                    \
                .indexed = 1,                                           \
                .channel = num,                                         \
                .address = addr,                                        \
-               .info_mask = MAX1363_INFO_MASK,                         \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
                .datasheet_name = "AIN"#num,                            \
                .scan_type = {                                          \
                        .sign = 'u',                                    \
@@ -456,7 +456,8 @@ static const enum max1363_modes max1363_mode_list[] = {
                .channel = num,                                         \
                .channel2 = num2,                                       \
                .address = addr,                                        \
-               .info_mask = MAX1363_INFO_MASK,                         \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
                .datasheet_name = "AIN"#num"-AIN"#num2,                 \
                .scan_type = {                                          \
                        .sign = 's',                                    \
index f4a46dd8f43b0c2c91539a59f07a5c93388e59ef..2826faae706c11a85f76aa8afa2586bfacf8238c 100644 (file)
@@ -55,8 +55,8 @@ static int adc081c_read_raw(struct iio_dev *iio,
 
 static const struct iio_chan_spec adc081c_channel = {
        .type = IIO_VOLTAGE,
-       .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT |
-                    IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 };
 
 static const struct iio_info adc081c_info = {
index cd030e100c395416e4043ad6659f7030266b9b7e..5f9a7e7d313520c71529ffcea02c6f59cc816a93 100644 (file)
@@ -89,7 +89,7 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)
                chan->type = IIO_VOLTAGE;
                chan->indexed = 1;
                chan->channel = i;
-               chan->info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT;
+               chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
        }
 
        indio_dev->channels = chan_array;
index ad0261533deeded96c55bdf6ba8b7a60129c21ee..56ac481c73c0bde09575536f6a92066a7fc946c7 100644 (file)
@@ -41,7 +41,7 @@ struct vprbrd_adc {
        .type = IIO_VOLTAGE,                            \
        .indexed = 1,                                   \
        .channel = _index,                              \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,    \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
        .scan_index = _index,                           \
        .scan_type = {                                  \
                .sign = 'u',                            \
index d6c0af23a2a74a8dae8260e88d3bd87f84ab1c27..d354554b51b3e072bbfc260eb945d215332c1933 100644 (file)
@@ -125,7 +125,7 @@ static const struct iio_info ad8366_info = {
        .output = 1,                                    \
        .indexed = 1,                                   \
        .channel = _channel,                            \
-       .info_mask = IIO_CHAN_INFO_HARDWAREGAIN_SEPARATE_BIT,\
+       .info_mask_separate = BIT(IIO_CHAN_INFO_HARDWAREGAIN),\
 }
 
 static const struct iio_chan_spec ad8366_channels[] = {
index 7a525a91105d38a7570c1caddf85e41bdaf9553d..87419c41b991da24d8d284d33502c81f72c1c377 100644 (file)
@@ -31,7 +31,7 @@
 static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
                                                bool state)
 {
-       struct hid_sensor_common *st = trig->private_data;
+       struct hid_sensor_common *st = iio_trigger_get_drvdata(trig);
        int state_val;
 
        state_val = state ? 1 : 0;
@@ -76,7 +76,7 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
        }
 
        trig->dev.parent = indio_dev->dev.parent;
-       trig->private_data = attrb;
+       iio_trigger_set_drvdata(trig, attrb);
        trig->ops = &hid_sensor_trigger_ops;
        ret = iio_trigger_register(trig);
 
index f0aa2f1052224b5a94b49bacae034c77afa76ce4..251baf6abc2522138a838bc8c3ada1b1a2a8b607 100644 (file)
@@ -29,7 +29,6 @@ static unsigned int st_sensors_spi_get_irq(struct iio_dev *indio_dev)
 static int st_sensors_spi_read(struct st_sensor_transfer_buffer *tb,
        struct device *dev, u8 reg_addr, int len, u8 *data, bool multiread_bit)
 {
-       struct spi_message msg;
        int err;
 
        struct spi_transfer xfers[] = {
@@ -51,10 +50,7 @@ static int st_sensors_spi_read(struct st_sensor_transfer_buffer *tb,
        else
                tb->tx_buf[0] = reg_addr | ST_SENSORS_SPI_READ;
 
-       spi_message_init(&msg);
-       spi_message_add_tail(&xfers[0], &msg);
-       spi_message_add_tail(&xfers[1], &msg);
-       err = spi_sync(to_spi_device(dev), &msg);
+       err = spi_sync_transfer(to_spi_device(dev), xfers, ARRAY_SIZE(xfers));
        if (err)
                goto acc_spi_read_error;
 
@@ -83,7 +79,6 @@ static int st_sensors_spi_read_multiple_byte(
 static int st_sensors_spi_write_byte(struct st_sensor_transfer_buffer *tb,
                                struct device *dev, u8 reg_addr, u8 data)
 {
-       struct spi_message msg;
        int err;
 
        struct spi_transfer xfers = {
@@ -96,9 +91,7 @@ static int st_sensors_spi_write_byte(struct st_sensor_transfer_buffer *tb,
        tb->tx_buf[0] = reg_addr;
        tb->tx_buf[1] = data;
 
-       spi_message_init(&msg);
-       spi_message_add_tail(&xfers, &msg);
-       err = spi_sync(to_spi_device(dev), &msg);
+       err = spi_sync_transfer(to_spi_device(dev), &xfers, 1);
        mutex_unlock(&tb->buf_lock);
 
        return err;
index 139ed030abb0615f2c316990e6b3aa92b6c092c2..8fc3a97eb266e6302367653248017c3b6078a021 100644 (file)
@@ -40,7 +40,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
        if (err)
                goto request_irq_error;
 
-       sdata->trig->private_data = indio_dev;
+       iio_trigger_set_drvdata(sdata->trig, indio_dev);
        sdata->trig->ops = trigger_ops;
        sdata->trig->dev.parent = sdata->dev;
 
index 74f2d52795f6e6c44fe49025b49adbe13f33fc39..aa26d50ab63854e7522dc093ea2dce80f0961358 100644 (file)
@@ -296,8 +296,8 @@ static const struct iio_chan_spec_ext_info ad5064_ext_info[] = {
        .indexed = 1,                                           \
        .output = 1,                                            \
        .channel = (chan),                                      \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |           \
-       IIO_CHAN_INFO_SCALE_SEPARATE_BIT,                       \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |          \
+       BIT(IIO_CHAN_INFO_SCALE),                                       \
        .address = addr,                                        \
        .scan_type = IIO_ST('u', (bits), 16, 20 - (bits)),      \
        .ext_info = ad5064_ext_info,                            \
index 92771217f6656590015b65d730c79b4fa1a4b8c8..80923af424f2776a76343cd96b892a0132eeab36 100644 (file)
@@ -102,11 +102,11 @@ enum ad5360_type {
        .type = IIO_VOLTAGE,                                    \
        .indexed = 1,                                           \
        .output = 1,                                            \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |           \
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT |              \
-               IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |             \
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT | \
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,   \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |          \
+               BIT(IIO_CHAN_INFO_SCALE) |                              \
+               BIT(IIO_CHAN_INFO_OFFSET) |                             \
+               BIT(IIO_CHAN_INFO_CALIBSCALE) |                 \
+               BIT(IIO_CHAN_INFO_CALIBBIAS),                   \
        .scan_type = IIO_ST('u', (bits), 16, 16 - (bits))       \
 }
 
index 483fc379a2da9ca64a29fb13313b16f3d76d8b43..bf2db02215c287c5d535b8adf3f21bf1f60a3b47 100644 (file)
@@ -257,10 +257,10 @@ static struct iio_chan_spec_ext_info ad5380_ext_info[] = {
        .type = IIO_VOLTAGE,                                    \
        .indexed = 1,                                           \
        .output = 1,                                            \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |           \
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |                \
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |         \
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,           \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |          \
+               BIT(IIO_CHAN_INFO_CALIBSCALE) |                 \
+               BIT(IIO_CHAN_INFO_CALIBBIAS),                   \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
        .scan_type = IIO_ST('u', (_bits), 16, 14 - (_bits)),    \
        .ext_info = ad5380_ext_info,                            \
 }
index 6b86a638dad04ed806e93abb0d3c26af94139abe..98f24407c3ceeeb977ac7450fbc4aae74389a05a 100644 (file)
@@ -86,11 +86,11 @@ static const struct iio_chan_spec ad5421_channels[] = {
                .indexed = 1,
                .output = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SHARED_BIT |
-                       IIO_CHAN_INFO_OFFSET_SHARED_BIT |
-                       IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-                       IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_CALIBSCALE) |
+                       BIT(IIO_CHAN_INFO_CALIBBIAS),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |
+                       BIT(IIO_CHAN_INFO_OFFSET),
                .scan_type = IIO_ST('u', 16, 16, 0),
                .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |
                        IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING),
index f5583aedfb597cf927e3e39969b80e5e0184085e..cae8f6056ac33ebebe6dcd2ce874503884f71f6f 100644 (file)
@@ -143,8 +143,8 @@ static const struct iio_chan_spec_ext_info ad5446_ext_info_powerdown[] = {
        .indexed = 1, \
        .output = 1, \
        .channel = 0, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-       IIO_CHAN_INFO_SCALE_SHARED_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
        .scan_type = IIO_ST('u', (bits), (storage), (shift)), \
        .ext_info = (ext), \
 }
index c4731b7b577b0670eda5d1f08ccce300f21e6f2f..ba1c914b0399adc8f77d198c9bd7886c254f4cbc 100644 (file)
@@ -206,8 +206,8 @@ static const struct iio_info ad5449_info = {
        .indexed = 1,                                           \
        .output = 1,                                            \
        .channel = (chan),                                      \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |           \
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT,               \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |          \
+               BIT(IIO_CHAN_INFO_SCALE),                       \
        .address = (chan),                                      \
        .scan_type = IIO_ST('u', (bits), 16, 12 - (bits)),      \
 }
index e5e59749f109d1379b72aaa81950e987e7bb57ef..139206e84cb7bf32cd17d88d0b526174a32cfee5 100644 (file)
@@ -259,8 +259,8 @@ static const struct iio_chan_spec_ext_info ad5504_ext_info[] = {
        .indexed = 1, \
        .output = 1, \
        .channel = (_chan), \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-                    IIO_CHAN_INFO_SCALE_SHARED_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
        .address = AD5504_ADDR_DAC(_chan), \
        .scan_type = IIO_ST('u', 12, 16, 0), \
        .ext_info = ad5504_ext_info, \
index f6e116627b714e044569c1ef5e85fff59dfc5c20..bb298aaff321f5cc8639fcf3d710b635da37e2e5 100644 (file)
@@ -174,8 +174,8 @@ static const struct iio_chan_spec_ext_info ad5624r_ext_info[] = {
        .indexed = 1, \
        .output = 1, \
        .channel = (_chan), \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-                    IIO_CHAN_INFO_SCALE_SHARED_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
        .address = (_chan), \
        .scan_type = IIO_ST('u', (_bits), 16, 16 - (_bits)), \
        .ext_info = ad5624r_ext_info, \
index 5e554af21703cad89c4490427859e4e8b8812520..06439b1af9b6ff1edcbc55a7a021e87a9c8f9137 100644 (file)
@@ -276,9 +276,9 @@ static const struct iio_chan_spec_ext_info ad5686_ext_info[] = {
                .indexed = 1,                                   \
                .output = 1,                                    \
                .channel = chan,                                \
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |   \
-               IIO_CHAN_INFO_SCALE_SHARED_BIT,                 \
-               .address = AD5686_ADDR_DAC(chan),                       \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
+               .address = AD5686_ADDR_DAC(chan),               \
                .scan_type = IIO_ST('u', bits, 16, shift),      \
                .ext_info = ad5686_ext_info,                    \
 }
index 71faabc6b14e1f9ff143ee6ae826de5b2c61bf9c..12bb315e55f8530373682864d291dcca7b151b4d 100644 (file)
@@ -393,11 +393,11 @@ static const struct iio_chan_spec_ext_info ad5755_ext_info[] = {
 #define AD5755_CHANNEL(_bits) {                                        \
        .indexed = 1,                                           \
        .output = 1,                                            \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |           \
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT |              \
-               IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |             \
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |         \
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,           \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |          \
+               BIT(IIO_CHAN_INFO_SCALE) |                      \
+               BIT(IIO_CHAN_INFO_OFFSET) |                     \
+               BIT(IIO_CHAN_INFO_CALIBSCALE) |                 \
+               BIT(IIO_CHAN_INFO_CALIBBIAS),                   \
        .scan_type = IIO_ST('u', (_bits), 16, 16 - (_bits)),    \
        .ext_info = ad5755_ext_info,                            \
 }
index 5b7acd3a2c77865b8cc3e777d17f43f845f45246..7a53f7d70dacf2f88af0e654ed35564308ed7279 100644 (file)
@@ -78,11 +78,11 @@ enum ad5764_type {
        .output = 1,                                            \
        .channel = (_chan),                                     \
        .address = (_chan),                                     \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |           \
-               IIO_CHAN_INFO_OFFSET_SHARED_BIT |               \
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT |              \
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |         \
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,           \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |          \
+               BIT(IIO_CHAN_INFO_SCALE) |                      \
+               BIT(IIO_CHAN_INFO_CALIBSCALE) |                 \
+               BIT(IIO_CHAN_INFO_CALIBBIAS),                   \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET),  \
        .scan_type = IIO_ST('u', (_bits), 16, 16 - (_bits))     \
 }
 
index 8dfd3da8a07b57813881bf89c5743427b2ddc0a2..97c1e5d780dfc06106bfbc5d753a41822b3883b5 100644 (file)
@@ -302,9 +302,9 @@ static const struct iio_chan_spec_ext_info ad5791_ext_info[] = {
        .indexed = 1,                                   \
        .address = AD5791_ADDR_DAC0,                    \
        .channel = 0,                                   \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |   \
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |        \
-               IIO_CHAN_INFO_OFFSET_SHARED_BIT,        \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |  \
+               BIT(IIO_CHAN_INFO_OFFSET),              \
        .scan_type = IIO_ST('u', bits, 24, shift),      \
        .ext_info = ad5791_ext_info,                    \
 }
index 352abe2004a4cd46a4542439c40659feb9b61f9f..ebfaa4156246fde0db21df9ddad241079dcf3102 100644 (file)
@@ -146,8 +146,8 @@ static const struct iio_info max517_info = {
        .indexed = 1,                                   \
        .output = 1,                                    \
        .channel = (chan),                              \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |   \
-       IIO_CHAN_INFO_SCALE_SEPARATE_BIT,               \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |  \
+       BIT(IIO_CHAN_INFO_SCALE),                       \
        .scan_type = IIO_ST('u', 8, 8, 0),              \
 }
 
index 8f88cc4059a2a95620681edc30116db75dd06f8b..a612ec766d96f41042ce57324a2e2f3df668fda5 100644 (file)
@@ -69,8 +69,8 @@ static const struct iio_chan_spec mcp4725_channel = {
        .indexed        = 1,
        .output         = 1,
        .channel        = 0,
-       .info_mask      = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                         IIO_CHAN_INFO_SCALE_SHARED_BIT,
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
        .scan_type      = IIO_ST('u', 12, 16, 0),
 };
 
index 1ea132e239ea29408be9d13ca29b5a17863f73cb..92276deeb026d0fc0741b5ca505626cc2fbd6afa 100644 (file)
@@ -920,10 +920,10 @@ static int ad9523_setup(struct iio_dev *indio_dev)
                        st->ad9523_channels[i].channel = chan->channel_num;
                        st->ad9523_channels[i].extend_name =
                                chan->extended_name;
-                       st->ad9523_channels[i].info_mask =
-                               IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                               IIO_CHAN_INFO_PHASE_SEPARATE_BIT |
-                               IIO_CHAN_INFO_FREQUENCY_SEPARATE_BIT;
+                       st->ad9523_channels[i].info_mask_separate =
+                               BIT(IIO_CHAN_INFO_RAW) |
+                               BIT(IIO_CHAN_INFO_PHASE) |
+                               BIT(IIO_CHAN_INFO_FREQUENCY);
                }
        }
 
index 1861287911f120af48172f2e3e9638549352cc10..e1bb5f994a548406728e3eb86f35200e76ede502 100644 (file)
@@ -136,32 +136,32 @@ static const struct iio_chan_spec adis16080_channels[] = {
                .type = IIO_ANGL_VEL,
                .modified = 1,
                .channel2 = IIO_MOD_Z,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE),
                .address = ADIS16080_DIN_GYRO,
        }, {
                .type = IIO_VOLTAGE,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
-                       IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE) |
+                       BIT(IIO_CHAN_INFO_OFFSET),
                .address = ADIS16080_DIN_AIN1,
        }, {
                .type = IIO_VOLTAGE,
                .indexed = 1,
                .channel = 1,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
-                       IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE) |
+                       BIT(IIO_CHAN_INFO_OFFSET),
                .address = ADIS16080_DIN_AIN2,
        }, {
                .type = IIO_TEMP,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
-                       IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE) |
+                       BIT(IIO_CHAN_INFO_OFFSET),
                .address = ADIS16080_DIN_TEMP,
        }
 };
index 8cb0bcbfd609cb1e905e23000528897412955b1e..058e6d5c955fa8270012fda23c16df968fe44801 100644 (file)
@@ -357,10 +357,11 @@ static const struct iio_chan_spec adis16136_channels[] = {
                .type = IIO_ANGL_VEL,
                .modified = 1,
                .channel2 = IIO_MOD_X,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SHARED_BIT |
-                       IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_CALIBBIAS) |
+                       BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+
                .address = ADIS16136_REG_GYRO_OUT2,
                .scan_index = ADIS16136_SCAN_GYRO,
                .scan_type = {
@@ -373,8 +374,8 @@ static const struct iio_chan_spec adis16136_channels[] = {
                .type = IIO_TEMP,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE),
                .address = ADIS16136_REG_TEMP_OUT,
                .scan_index = ADIS16136_SCAN_TEMP,
                .scan_type = {
index 5b79953f70113b780c8de154031f80dc00d24b84..8bd72b490b7f11dd1092b2ff8148cba569db677e 100644 (file)
@@ -383,16 +383,16 @@ static const struct iio_chan_spec adxrs450_channels[2][2] = {
                        .type = IIO_ANGL_VEL,
                        .modified = 1,
                        .channel2 = IIO_MOD_Z,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
-                       IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_CALIBBIAS) |
+                       BIT(IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE),
                }, {
                        .type = IIO_TEMP,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE),
                }
        },
        [ID_ADXRS453] = {
@@ -400,15 +400,15 @@ static const struct iio_chan_spec adxrs450_channels[2][2] = {
                        .type = IIO_ANGL_VEL,
                        .modified = 1,
                        .channel2 = IIO_MOD_Z,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
-                       IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE) |
+                       BIT(IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW),
                }, {
                        .type = IIO_TEMP,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE),
                }
        },
 };
index fcfc83a9f86119a91899769632477f7005052c43..bc943dd47da5b6eb24e3f4b9b862cc9684227127 100644 (file)
@@ -60,28 +60,28 @@ static const struct iio_chan_spec gyro_3d_channels[] = {
                .type = IIO_ANGL_VEL,
                .modified = 1,
                .channel2 = IIO_MOD_X,
-               .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |
-               IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT |
-               IIO_CHAN_INFO_HYSTERESIS_SHARED_BIT,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+               BIT(IIO_CHAN_INFO_SCALE) |
+               BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+               BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_X,
        }, {
                .type = IIO_ANGL_VEL,
                .modified = 1,
                .channel2 = IIO_MOD_Y,
-               .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |
-               IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT |
-               IIO_CHAN_INFO_HYSTERESIS_SHARED_BIT,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+               BIT(IIO_CHAN_INFO_SCALE) |
+               BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+               BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_Y,
        }, {
                .type = IIO_ANGL_VEL,
                .modified = 1,
                .channel2 = IIO_MOD_Z,
-               .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |
-               IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT |
-               IIO_CHAN_INFO_HYSTERESIS_SHARED_BIT,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+               BIT(IIO_CHAN_INFO_SCALE) |
+               BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+               BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_Z,
        }
 };
index f667d2c8c00f0c417a04caab2c1a694e016e96a1..6c43af9bb0a4474097f2def7ec15d973a7238b47 100644 (file)
@@ -81,7 +81,7 @@ void itg3200_buffer_unconfigure(struct iio_dev *indio_dev)
 static int itg3200_data_rdy_trigger_set_state(struct iio_trigger *trig,
                bool state)
 {
-       struct iio_dev *indio_dev = trig->private_data;
+       struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
        int ret;
        u8 msc;
 
@@ -129,7 +129,7 @@ int itg3200_probe_trigger(struct iio_dev *indio_dev)
 
        st->trig->dev.parent = &st->i2c->dev;
        st->trig->ops = &itg3200_trigger_ops;
-       st->trig->private_data = indio_dev;
+       iio_trigger_set_drvdata(st->trig, indio_dev);
        ret = iio_trigger_register(st->trig);
        if (ret)
                goto error_free_irq;
index df2e6aa5d73bd2d4aee4b03d15eb75f2df68fda7..d66605d2629d810b95688785622f993e7322a897 100644 (file)
@@ -248,12 +248,6 @@ err_ret:
        return ret;
 }
 
-#define ITG3200_TEMP_INFO_MASK (IIO_CHAN_INFO_OFFSET_SHARED_BIT | \
-                                IIO_CHAN_INFO_SCALE_SHARED_BIT | \
-                                IIO_CHAN_INFO_RAW_SEPARATE_BIT)
-#define ITG3200_GYRO_INFO_MASK (IIO_CHAN_INFO_SCALE_SHARED_BIT | \
-                                IIO_CHAN_INFO_RAW_SEPARATE_BIT)
-
 #define ITG3200_ST                                             \
        { .sign = 's', .realbits = 16, .storagebits = 16, .endianness = IIO_BE }
 
@@ -261,7 +255,8 @@ err_ret:
        .type = IIO_ANGL_VEL, \
        .modified = 1, \
        .channel2 = IIO_MOD_ ## _mod, \
-       .info_mask = ITG3200_GYRO_INFO_MASK, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
        .address = ITG3200_REG_GYRO_ ## _mod ## OUT_H, \
        .scan_index = ITG3200_SCAN_GYRO_ ## _mod, \
        .scan_type = ITG3200_ST, \
@@ -271,7 +266,9 @@ static const struct iio_chan_spec itg3200_channels[] = {
        {
                .type = IIO_TEMP,
                .channel2 = IIO_NO_MOD,
-               .info_mask = ITG3200_TEMP_INFO_MASK,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+               BIT(IIO_CHAN_INFO_SCALE),
                .address = ITG3200_REG_TEMP_OUT_H,
                .scan_index = ITG3200_SCAN_TEMP,
                .scan_type = ITG3200_ST,
index da4d122ec7dc1a4efb4aec0d4fe1e1eb6a33a1a1..69017c7ec302a785ffd86afca90ff3b2ae1e9d3e 100644 (file)
@@ -25,7 +25,7 @@
 
 int st_gyro_trig_set_state(struct iio_trigger *trig, bool state)
 {
-       struct iio_dev *indio_dev = trig->private_data;
+       struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
 
        return st_sensors_set_dataready_irq(indio_dev, state);
 }
index f652e6ae5a35991b20f7be95eb8c2cafa49debf4..05c1b74502a37265c86a23edaf97d4e602ead575 100644 (file)
@@ -18,6 +18,7 @@
 struct iio_chan_spec;
 struct iio_dev;
 
+extern struct device_type iio_device_type;
 
 int __iio_add_chan_devattr(const char *postfix,
                           struct iio_chan_spec const *chan,
index b7f215eab5de35fd21181042e7527eac0c5476ed..f60591f0b925743a9ad5ede585b24585f3dd597a 100644 (file)
@@ -484,8 +484,8 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
        .indexed = 1, \
        .channel = 0, \
        .extend_name = name, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+               BIT(IIO_CHAN_INFO_SCALE), \
        .address = (addr), \
        .scan_index = (si), \
        .scan_type = { \
@@ -507,10 +507,10 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
        .type = IIO_ANGL_VEL, \
        .modified = 1, \
        .channel2 = IIO_MOD_ ## mod, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \
-               IIO_CHAN_INFO_SCALE_SHARED_BIT | \
-               IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+               BIT(IIO_CHAN_INFO_CALIBBIAS),             \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
+               BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
        .address = addr, \
        .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \
        .scan_type = { \
@@ -526,10 +526,10 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
        .type = IIO_ACCEL, \
        .modified = 1, \
        .channel2 = IIO_MOD_ ## mod, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \
-               IIO_CHAN_INFO_SCALE_SHARED_BIT | \
-               IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+               BIT(IIO_CHAN_INFO_CALIBBIAS), \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
+               BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
        .address = (addr), \
        .scan_index = ADIS16400_SCAN_ACC_ ## mod, \
        .scan_type = { \
@@ -545,9 +545,9 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
        .type = IIO_MAGN, \
        .modified = 1, \
        .channel2 = IIO_MOD_ ## mod, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-               IIO_CHAN_INFO_SCALE_SHARED_BIT | \
-               IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
+               BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
        .address = (addr), \
        .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \
        .scan_type = { \
@@ -568,10 +568,11 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
        .indexed = 1, \
        .channel = 0, \
        .extend_name = ADIS16400_MOD_TEMP_NAME_ ## mod, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-               IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \
-               IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+               BIT(IIO_CHAN_INFO_OFFSET) | \
+               BIT(IIO_CHAN_INFO_SCALE), \
+       .info_mask_shared_by_type = \
+               BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
        .address = (addr), \
        .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \
        .scan_type = { \
@@ -587,9 +588,9 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
        .type = IIO_TEMP, \
        .indexed = 1, \
        .channel = 0, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-               IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+               BIT(IIO_CHAN_INFO_OFFSET) | \
+               BIT(IIO_CHAN_INFO_SCALE), \
        .address = (addr), \
        .scan_index = ADIS16350_SCAN_TEMP_X, \
        .scan_type = { \
@@ -605,8 +606,8 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
        .type = IIO_INCLI, \
        .modified = 1, \
        .channel2 = IIO_MOD_ ## mod, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-               IIO_CHAN_INFO_SCALE_SHARED_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
        .address = (addr), \
        .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \
        .scan_type = { \
@@ -646,8 +647,8 @@ static const struct iio_chan_spec adis16448_channels[] = {
        ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 16),
        {
                .type = IIO_PRESSURE,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = ADIS16448_BARO_OUT,
                .scan_index = ADIS16400_SCAN_BARO,
                .scan_type = IIO_ST('s', 16, 16, 0),
index 8c26a5f7cd5d1deaae1b6857cb43330ef0d8b5ed..b7db3837629549cdf1a928faa337b11f89b1bc26 100644 (file)
@@ -591,15 +591,15 @@ static int adis16480_write_raw(struct iio_dev *indio_dev,
        }
 }
 
-#define ADIS16480_MOD_CHANNEL(_type, _mod, _address, _si, _info, _bits) \
+#define ADIS16480_MOD_CHANNEL(_type, _mod, _address, _si, _info_sep, _bits) \
        { \
                .type = (_type), \
                .modified = 1, \
                .channel2 = (_mod), \
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-                       IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \
-                       IIO_CHAN_INFO_SCALE_SHARED_BIT | \
-                       _info, \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+                       BIT(IIO_CHAN_INFO_CALIBBIAS) | \
+                       _info_sep, \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
                .address = (_address), \
                .scan_index = (_si), \
                .scan_type = { \
@@ -613,21 +613,21 @@ static int adis16480_write_raw(struct iio_dev *indio_dev,
 #define ADIS16480_GYRO_CHANNEL(_mod) \
        ADIS16480_MOD_CHANNEL(IIO_ANGL_VEL, IIO_MOD_ ## _mod, \
        ADIS16480_REG_ ## _mod ## _GYRO_OUT, ADIS16480_SCAN_GYRO_ ## _mod, \
-       IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SEPARATE_BIT | \
-       IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, \
+       BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \
+       BIT(IIO_CHAN_INFO_CALIBSCALE), \
        32)
 
 #define ADIS16480_ACCEL_CHANNEL(_mod) \
        ADIS16480_MOD_CHANNEL(IIO_ACCEL, IIO_MOD_ ## _mod, \
        ADIS16480_REG_ ## _mod ## _ACCEL_OUT, ADIS16480_SCAN_ACCEL_ ## _mod, \
-       IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SEPARATE_BIT | \
-       IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, \
+       BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \
+       BIT(IIO_CHAN_INFO_CALIBSCALE), \
        32)
 
 #define ADIS16480_MAGN_CHANNEL(_mod) \
        ADIS16480_MOD_CHANNEL(IIO_MAGN, IIO_MOD_ ## _mod, \
        ADIS16480_REG_ ## _mod ## _MAGN_OUT, ADIS16480_SCAN_MAGN_ ## _mod, \
-       IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SEPARATE_BIT, \
+       BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
        16)
 
 #define ADIS16480_PRESSURE_CHANNEL() \
@@ -635,9 +635,9 @@ static int adis16480_write_raw(struct iio_dev *indio_dev,
                .type = IIO_PRESSURE, \
                .indexed = 1, \
                .channel = 0, \
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-                       IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+                       BIT(IIO_CHAN_INFO_CALIBBIAS) | \
+                       BIT(IIO_CHAN_INFO_SCALE), \
                .address = ADIS16480_REG_BAROM_OUT, \
                .scan_index = ADIS16480_SCAN_BARO, \
                .scan_type = { \
@@ -652,9 +652,9 @@ static int adis16480_write_raw(struct iio_dev *indio_dev,
                .type = IIO_TEMP, \
                .indexed = 1, \
                .channel = 0, \
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \
-                       IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+                       BIT(IIO_CHAN_INFO_SCALE) | \
+                       BIT(IIO_CHAN_INFO_OFFSET), \
                .address = ADIS16480_REG_TEMP_OUT, \
                .scan_index = ADIS16480_SCAN_TEMP, \
                .scan_type = { \
index 5a24c9cac3436ae3d833cac2c58b6913f4588dcc..e0017c22bb9c6ce3b4f4f9c753a8ce1364621b19 100644 (file)
@@ -19,7 +19,7 @@
 static int adis_data_rdy_trigger_set_state(struct iio_trigger *trig,
                                                bool state)
 {
-       struct adis *adis = trig->private_data;
+       struct adis *adis = iio_trigger_get_drvdata(trig);
 
        return adis_enable_irq(adis, state);
 }
@@ -57,7 +57,7 @@ int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
 
        adis->trig->dev.parent = &adis->spi->dev;
        adis->trig->ops = &adis_trigger_ops;
-       adis->trig->private_data = adis;
+       iio_trigger_set_drvdata(adis->trig, adis);
        ret = iio_trigger_register(adis->trig);
 
        indio_dev->trig = adis->trig;
index 37ca05b47e4b70599500bb1b59774fecd3cc2722..fe4c61e219f38781d194028be6bad811287b36e6 100644 (file)
@@ -544,8 +544,8 @@ static int inv_mpu6050_validate_trigger(struct iio_dev *indio_dev,
                .type = _type,                                        \
                .modified = 1,                                        \
                .channel2 = _channel2,                                \
-               .info_mask =  IIO_CHAN_INFO_SCALE_SHARED_BIT          \
-                               | IIO_CHAN_INFO_RAW_SEPARATE_BIT,     \
+               .info_mask_shared_by_type =  BIT(IIO_CHAN_INFO_SCALE), \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),         \
                .scan_index = _index,                                 \
                .scan_type = {                                        \
                                .sign = 's',                          \
@@ -564,9 +564,9 @@ static const struct iio_chan_spec inv_mpu_channels[] = {
         */
        {
                .type = IIO_TEMP,
-               .info_mask =  IIO_CHAN_INFO_RAW_SEPARATE_BIT
-                               | IIO_CHAN_INFO_OFFSET_SEPARATE_BIT
-                               | IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate =  BIT(IIO_CHAN_INFO_RAW)
+                               | BIT(IIO_CHAN_INFO_OFFSET)
+                               | BIT(IIO_CHAN_INFO_SCALE),
                .scan_index = -1,
        },
        INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X),
index 331781ffbb1514df87acdc06df2927a915d74ed0..7da0832f187b8d320cd8618eb3379b2015bee927 100644 (file)
@@ -105,9 +105,8 @@ irqreturn_t inv_mpu6050_irq_handler(int irq, void *p)
        s64 timestamp;
 
        timestamp = iio_get_time_ns();
-       spin_lock(&st->time_stamp_lock);
-       kfifo_in(&st->timestamps, &timestamp, 1);
-       spin_unlock(&st->time_stamp_lock);
+       kfifo_in_spinlocked(&st->timestamps, &timestamp, 1,
+                               &st->time_stamp_lock);
 
        return IRQ_WAKE_THREAD;
 }
index e1d0869e0ad174545bccaec73c13eb685e977fec..03b9372c1212a99c5a6a2452cc081f7395a259ca 100644 (file)
@@ -103,7 +103,7 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable)
 static int inv_mpu_data_rdy_trigger_set_state(struct iio_trigger *trig,
                                                bool state)
 {
-       return inv_mpu6050_set_enable(trig->private_data, state);
+       return inv_mpu6050_set_enable(iio_trigger_get_drvdata(trig), state);
 }
 
 static const struct iio_trigger_ops inv_mpu_trigger_ops = {
@@ -130,8 +130,8 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev)
        if (ret)
                goto error_free_trig;
        st->trig->dev.parent = &st->client->dev;
-       st->trig->private_data = indio_dev;
        st->trig->ops = &inv_mpu_trigger_ops;
+       iio_trigger_set_drvdata(st->trig, indio_dev);
        ret = iio_trigger_register(st->trig);
        if (ret)
                goto error_free_irq;
index 8848f16c547b07a44e2de1f1834283b8f88e8fb5..e145931ef1b82906478c5a32505cada2d8eb1547 100644 (file)
@@ -691,21 +691,34 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
 
        if (chan->channel < 0)
                return 0;
-       for_each_set_bit(i, &chan->info_mask, sizeof(long)*8) {
-               ret = __iio_add_chan_devattr(iio_chan_info_postfix[i/2],
+       for_each_set_bit(i, &chan->info_mask_separate, sizeof(long)*8) {
+               ret = __iio_add_chan_devattr(iio_chan_info_postfix[i],
                                             chan,
                                             &iio_read_channel_info,
                                             &iio_write_channel_info,
-                                            i/2,
-                                            !(i%2),
+                                            i,
+                                            0,
                                             &indio_dev->dev,
                                             &indio_dev->channel_attr_list);
-               if (ret == -EBUSY && (i%2 == 0)) {
+               if (ret < 0)
+                       goto error_ret;
+               attrcount++;
+       }
+       for_each_set_bit(i, &chan->info_mask_shared_by_type, sizeof(long)*8) {
+               ret = __iio_add_chan_devattr(iio_chan_info_postfix[i],
+                                            chan,
+                                            &iio_read_channel_info,
+                                            &iio_write_channel_info,
+                                            i,
+                                            1,
+                                            &indio_dev->dev,
+                                            &indio_dev->channel_attr_list);
+               if (ret == -EBUSY) {
                        ret = 0;
                        continue;
-               }
-               if (ret < 0)
+               } else if (ret < 0) {
                        goto error_ret;
+               }
                attrcount++;
        }
 
@@ -847,7 +860,7 @@ static void iio_dev_release(struct device *device)
        kfree(indio_dev);
 }
 
-static struct device_type iio_dev_type = {
+struct device_type iio_device_type = {
        .name = "iio_device",
        .release = iio_dev_release,
 };
@@ -869,7 +882,7 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
 
        if (dev) {
                dev->dev.groups = dev->groups;
-               dev->dev.type = &iio_dev_type;
+               dev->dev.type = &iio_device_type;
                dev->dev.bus = &iio_bus_type;
                device_initialize(&dev->dev);
                dev_set_drvdata(&dev->dev, (void *)dev);
@@ -960,6 +973,10 @@ int iio_device_register(struct iio_dev *indio_dev)
 {
        int ret;
 
+       /* If the calling driver did not initialize of_node, do it here */
+       if (!indio_dev->dev.of_node && indio_dev->dev.parent)
+               indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
+
        /* configure elements for the chrdev */
        indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
 
index 261cae00557e06f98c029d18c432ec14cb1b15e4..10aa9ef86cece1b80fa09c57d2a52e344e4dfc12 100644 (file)
@@ -46,10 +46,11 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
 {
        struct iio_event_interface *ev_int = indio_dev->event_interface;
        struct iio_event_data ev;
+       unsigned long flags;
        int copied;
 
        /* Does anyone care? */
-       spin_lock(&ev_int->wait.lock);
+       spin_lock_irqsave(&ev_int->wait.lock, flags);
        if (test_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) {
 
                ev.id = ev_code;
@@ -59,7 +60,7 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
                if (copied != 0)
                        wake_up_locked_poll(&ev_int->wait, POLLIN);
        }
-       spin_unlock(&ev_int->wait.lock);
+       spin_unlock_irqrestore(&ev_int->wait.lock, flags);
 
        return 0;
 }
@@ -76,10 +77,10 @@ static unsigned int iio_event_poll(struct file *filep,
 
        poll_wait(filep, &ev_int->wait, wait);
 
-       spin_lock(&ev_int->wait.lock);
+       spin_lock_irq(&ev_int->wait.lock);
        if (!kfifo_is_empty(&ev_int->det_events))
                events = POLLIN | POLLRDNORM;
-       spin_unlock(&ev_int->wait.lock);
+       spin_unlock_irq(&ev_int->wait.lock);
 
        return events;
 }
@@ -96,14 +97,14 @@ static ssize_t iio_event_chrdev_read(struct file *filep,
        if (count < sizeof(struct iio_event_data))
                return -EINVAL;
 
-       spin_lock(&ev_int->wait.lock);
+       spin_lock_irq(&ev_int->wait.lock);
        if (kfifo_is_empty(&ev_int->det_events)) {
                if (filep->f_flags & O_NONBLOCK) {
                        ret = -EAGAIN;
                        goto error_unlock;
                }
                /* Blocking on device; waiting for something to be there */
-               ret = wait_event_interruptible_locked(ev_int->wait,
+               ret = wait_event_interruptible_locked_irq(ev_int->wait,
                                        !kfifo_is_empty(&ev_int->det_events));
                if (ret)
                        goto error_unlock;
@@ -113,7 +114,7 @@ static ssize_t iio_event_chrdev_read(struct file *filep,
        ret = kfifo_to_user(&ev_int->det_events, buf, count, &copied);
 
 error_unlock:
-       spin_unlock(&ev_int->wait.lock);
+       spin_unlock_irq(&ev_int->wait.lock);
 
        return ret ? ret : copied;
 }
@@ -122,7 +123,7 @@ static int iio_event_chrdev_release(struct inode *inode, struct file *filep)
 {
        struct iio_event_interface *ev_int = filep->private_data;
 
-       spin_lock(&ev_int->wait.lock);
+       spin_lock_irq(&ev_int->wait.lock);
        __clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
        /*
         * In order to maintain a clean state for reopening,
@@ -130,7 +131,7 @@ static int iio_event_chrdev_release(struct inode *inode, struct file *filep)
         * any new __iio_push_event calls running.
         */
        kfifo_reset_out(&ev_int->det_events);
-       spin_unlock(&ev_int->wait.lock);
+       spin_unlock_irq(&ev_int->wait.lock);
 
        return 0;
 }
@@ -151,18 +152,18 @@ int iio_event_getfd(struct iio_dev *indio_dev)
        if (ev_int == NULL)
                return -ENODEV;
 
-       spin_lock(&ev_int->wait.lock);
+       spin_lock_irq(&ev_int->wait.lock);
        if (__test_and_set_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) {
-               spin_unlock(&ev_int->wait.lock);
+               spin_unlock_irq(&ev_int->wait.lock);
                return -EBUSY;
        }
-       spin_unlock(&ev_int->wait.lock);
+       spin_unlock_irq(&ev_int->wait.lock);
        fd = anon_inode_getfd("iio:event",
                                &iio_event_chrdev_fileops, ev_int, O_RDONLY);
        if (fd < 0) {
-               spin_lock(&ev_int->wait.lock);
+               spin_lock_irq(&ev_int->wait.lock);
                __clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
-               spin_unlock(&ev_int->wait.lock);
+               spin_unlock_irq(&ev_int->wait.lock);
        }
        return fd;
 }
index b289915b8469774664ccd181cc0fa9883dda35d8..795d100b4c36fea7c82785e4f4b8545a13ff7eab 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
 
 #include <linux/iio/iio.h>
 #include "iio_core.h"
@@ -92,6 +93,164 @@ static const struct iio_chan_spec
        return chan;
 }
 
+#ifdef CONFIG_OF
+
+static int iio_dev_node_match(struct device *dev, void *data)
+{
+       return dev->of_node == data && dev->type == &iio_device_type;
+}
+
+static int __of_iio_channel_get(struct iio_channel *channel,
+                               struct device_node *np, int index)
+{
+       struct device *idev;
+       struct iio_dev *indio_dev;
+       int err;
+       struct of_phandle_args iiospec;
+
+       err = of_parse_phandle_with_args(np, "io-channels",
+                                        "#io-channel-cells",
+                                        index, &iiospec);
+       if (err)
+               return err;
+
+       idev = bus_find_device(&iio_bus_type, NULL, iiospec.np,
+                              iio_dev_node_match);
+       of_node_put(iiospec.np);
+       if (idev == NULL)
+               return -EPROBE_DEFER;
+
+       indio_dev = dev_to_iio_dev(idev);
+       channel->indio_dev = indio_dev;
+       index = iiospec.args_count ? iiospec.args[0] : 0;
+       if (index >= indio_dev->num_channels) {
+               return -EINVAL;
+               goto err_put;
+       }
+       channel->channel = &indio_dev->channels[index];
+
+       return 0;
+
+err_put:
+       iio_device_put(indio_dev);
+       return err;
+}
+
+static struct iio_channel *of_iio_channel_get(struct device_node *np, int index)
+{
+       struct iio_channel *channel;
+       int err;
+
+       if (index < 0)
+               return ERR_PTR(-EINVAL);
+
+       channel = kzalloc(sizeof(*channel), GFP_KERNEL);
+       if (channel == NULL)
+               return ERR_PTR(-ENOMEM);
+
+       err = __of_iio_channel_get(channel, np, index);
+       if (err)
+               goto err_free_channel;
+
+       return channel;
+
+err_free_channel:
+       kfree(channel);
+       return ERR_PTR(err);
+}
+
+static struct iio_channel *of_iio_channel_get_by_name(struct device_node *np,
+                                                     const char *name)
+{
+       struct iio_channel *chan = NULL;
+
+       /* Walk up the tree of devices looking for a matching iio channel */
+       while (np) {
+               int index = 0;
+
+               /*
+                * For named iio channels, first look up the name in the
+                * "io-channel-names" property.  If it cannot be found, the
+                * index will be an error code, and of_iio_channel_get()
+                * will fail.
+                */
+               if (name)
+                       index = of_property_match_string(np, "io-channel-names",
+                                                        name);
+               chan = of_iio_channel_get(np, index);
+               if (!IS_ERR(chan))
+                       break;
+               else if (name && index >= 0) {
+                       pr_err("ERROR: could not get IIO channel %s:%s(%i)\n",
+                               np->full_name, name ? name : "", index);
+                       return chan;
+               }
+
+               /*
+                * No matching IIO channel found on this node.
+                * If the parent node has a "io-channel-ranges" property,
+                * then we can try one of its channels.
+                */
+               np = np->parent;
+               if (np && !of_get_property(np, "io-channel-ranges", NULL))
+                       break;
+       }
+       return chan;
+}
+
+static struct iio_channel *of_iio_channel_get_all(struct device *dev)
+{
+       struct iio_channel *chans;
+       int i, mapind, nummaps = 0;
+       int ret;
+
+       do {
+               ret = of_parse_phandle_with_args(dev->of_node,
+                                                "io-channels",
+                                                "#io-channel-cells",
+                                                nummaps, NULL);
+               if (ret < 0)
+                       break;
+       } while (++nummaps);
+
+       if (nummaps == 0)       /* no error, return NULL to search map table */
+               return NULL;
+
+       /* NULL terminated array to save passing size */
+       chans = kcalloc(nummaps + 1, sizeof(*chans), GFP_KERNEL);
+       if (chans == NULL)
+               return ERR_PTR(-ENOMEM);
+
+       /* Search for OF matches */
+       for (mapind = 0; mapind < nummaps; mapind++) {
+               ret = __of_iio_channel_get(&chans[mapind], dev->of_node,
+                                          mapind);
+               if (ret)
+                       goto error_free_chans;
+       }
+       return chans;
+
+error_free_chans:
+       for (i = 0; i < mapind; i++)
+               iio_device_put(chans[i].indio_dev);
+       kfree(chans);
+       return ERR_PTR(ret);
+}
+
+#else /* CONFIG_OF */
+
+static inline struct iio_channel *
+of_iio_channel_get_by_name(struct device_node *np, const char *name)
+{
+       return NULL;
+}
+
+static inline struct iio_channel *of_iio_channel_get_all(struct device *dev)
+{
+       return NULL;
+}
+
+#endif /* CONFIG_OF */
 
 static struct iio_channel *iio_channel_get_sys(const char *name,
                                               const char *channel_name)
@@ -150,7 +309,14 @@ struct iio_channel *iio_channel_get(struct device *dev,
                                    const char *channel_name)
 {
        const char *name = dev ? dev_name(dev) : NULL;
+       struct iio_channel *channel;
 
+       if (dev) {
+               channel = of_iio_channel_get_by_name(dev->of_node,
+                                                    channel_name);
+               if (channel != NULL)
+                       return channel;
+       }
        return iio_channel_get_sys(name, channel_name);
 }
 EXPORT_SYMBOL_GPL(iio_channel_get);
@@ -173,6 +339,11 @@ struct iio_channel *iio_channel_get_all(struct device *dev)
 
        if (dev == NULL)
                return ERR_PTR(-EINVAL);
+
+       chans = of_iio_channel_get_all(dev);
+       if (chans)
+               return chans;
+
        name = dev_name(dev);
 
        mutex_lock(&iio_map_list_lock);
index d5b9d39d95b2aeecfbe07d28edf88b30494d648a..5f4749e60b0428ae6fb3ffb1be7b4de00913b699 100644 (file)
@@ -207,8 +207,8 @@ static const struct iio_chan_spec_ext_info adjd_s311_ext_info[] = {
        .type = IIO_INTENSITY, \
        .modified = 1, \
        .address = (IDX_##_color), \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-               IIO_CHAN_INFO_HARDWAREGAIN_SEPARATE_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+               BIT(IIO_CHAN_INFO_HARDWAREGAIN), \
        .channel2 = (IIO_MOD_LIGHT_##_color), \
        .scan_index = (_scan_idx), \
        .scan_type = IIO_ST('u', 10, 16, 0), \
index 3d7e8c9b4beb15eb9cce8f3790ea136701a77c79..80d68ff02d296df8ff1350208a720ed9e89fa4e5 100644 (file)
@@ -49,10 +49,10 @@ static const struct iio_chan_spec als_channels[] = {
                .type = IIO_INTENSITY,
                .modified = 1,
                .channel2 = IIO_MOD_LIGHT_BOTH,
-               .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |
-               IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT |
-               IIO_CHAN_INFO_HYSTERESIS_SHARED_BIT,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+               BIT(IIO_CHAN_INFO_SCALE) |
+               BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+               BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_ILLUM,
        }
 };
index 7503012ce9333ddc98ecbd8f25eecaf11345c379..5fa31a4ef82a7289bf3e2d649a2ef08a955635de 100644 (file)
@@ -231,7 +231,7 @@ static int lm3533_als_read_raw(struct iio_dev *indio_dev,
                .channel        = _channel,                             \
                .indexed        = true,                                 \
                .output         = true,                                 \
-               .info_mask      = IIO_CHAN_INFO_RAW_SEPARATE_BIT,       \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
        }
 
 static const struct iio_chan_spec lm3533_als_channels[] = {
@@ -239,8 +239,8 @@ static const struct iio_chan_spec lm3533_als_channels[] = {
                .type           = IIO_LIGHT,
                .channel        = 0,
                .indexed        = true,
-               .info_mask      = (IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT |
-                                  IIO_CHAN_INFO_RAW_SEPARATE_BIT),
+               .info_mask_separate = BIT(IIO_CHAN_INFO_AVERAGE_RAW) |
+                                  BIT(IIO_CHAN_INFO_RAW),
        },
        CHANNEL_CURRENT(0),
        CHANNEL_CURRENT(1),
index fd8be69b7d05ac6e78ec3b3ff0766ca339ef1ce2..1f529f36f138bd2b4490eb50ac610e8bec73d9fd 100644 (file)
@@ -530,14 +530,14 @@ static const struct iio_chan_spec tsl2563_channels[] = {
        {
                .type = IIO_LIGHT,
                .indexed = 1,
-               .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
                .channel = 0,
        }, {
                .type = IIO_INTENSITY,
                .modified = 1,
                .channel2 = IIO_MOD_LIGHT_BOTH,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_CALIBSCALE),
                .event_mask = (IIO_EV_BIT(IIO_EV_TYPE_THRESH,
                                          IIO_EV_DIR_RISING) |
                               IIO_EV_BIT(IIO_EV_TYPE_THRESH,
@@ -546,8 +546,8 @@ static const struct iio_chan_spec tsl2563_channels[] = {
                .type = IIO_INTENSITY,
                .modified = 1,
                .channel2 = IIO_MOD_LIGHT_IR,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_CALIBSCALE),
        }
 };
 
index 2aa748fbdc0ed4fc5b9d230cb28e648a5a6c46cf..1014943d949a1c7223b56294bcd07cd4a84280d5 100644 (file)
@@ -93,11 +93,11 @@ static int vcnl4000_measure(struct vcnl4000_data *data, u8 req_mask,
 static const struct iio_chan_spec vcnl4000_channels[] = {
        {
                .type = IIO_LIGHT,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE),
        }, {
                .type = IIO_PROXIMITY,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
        }
 };
 
index d8d01265220bfe5048be6adc3610524857a8b5df..99f4e494513b74da5608baa0c7298ea189311abf 100644 (file)
@@ -60,28 +60,28 @@ static const struct iio_chan_spec magn_3d_channels[] = {
                .type = IIO_MAGN,
                .modified = 1,
                .channel2 = IIO_MOD_X,
-               .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |
-               IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT |
-               IIO_CHAN_INFO_HYSTERESIS_SHARED_BIT,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+               BIT(IIO_CHAN_INFO_SCALE) |
+               BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+               BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_X,
        }, {
                .type = IIO_MAGN,
                .modified = 1,
                .channel2 = IIO_MOD_Y,
-               .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |
-               IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT |
-               IIO_CHAN_INFO_HYSTERESIS_SHARED_BIT,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+               BIT(IIO_CHAN_INFO_SCALE) |
+               BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+               BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_Y,
        }, {
                .type = IIO_MAGN,
                .modified = 1,
                .channel2 = IIO_MOD_Z,
-               .info_mask = IIO_CHAN_INFO_OFFSET_SHARED_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT |
-               IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT |
-               IIO_CHAN_INFO_HYSTERESIS_SHARED_BIT,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+               BIT(IIO_CHAN_INFO_SCALE) |
+               BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+               BIT(IIO_CHAN_INFO_HYSTERESIS),
                .scan_index = CHANNEL_SCAN_INDEX_Z,
        }
 };
index 093f10c88ccef5cefb5905a4a7aa4a8aa1acde40..5e62d00fb9e5f324cdb6b10bf63782a77319482d 100644 (file)
@@ -116,13 +116,11 @@ source "drivers/staging/android/Kconfig"
 
 source "drivers/staging/ozwpan/Kconfig"
 
-source "drivers/staging/ccg/Kconfig"
-
 source "drivers/staging/gdm72xx/Kconfig"
 
 source "drivers/staging/csr/Kconfig"
 
-source "drivers/staging/omap-thermal/Kconfig"
+source "drivers/staging/ti-soc-thermal/Kconfig"
 
 source "drivers/staging/silicom/Kconfig"
 
@@ -140,4 +138,8 @@ source "drivers/staging/zcache/Kconfig"
 
 source "drivers/staging/goldfish/Kconfig"
 
+source "drivers/staging/netlogic/Kconfig"
+
+source "drivers/staging/dwc2/Kconfig"
+
 endif # STAGING
index fa41b04cf4cb7e49a38af98dfa9fd0c519c5d940..b6d15ec95dd0f93d3cc454d6bda9a3c27ea7533a 100644 (file)
@@ -23,6 +23,7 @@ obj-$(CONFIG_RTS5139)         += rts5139/
 obj-$(CONFIG_TRANZPORT)                += frontier/
 obj-$(CONFIG_IDE_PHISON)       += phison/
 obj-$(CONFIG_LINE6_USB)                += line6/
+obj-$(CONFIG_NETLOGIC_XLR_NET) += netlogic/
 obj-$(CONFIG_USB_SERIAL_QUATECH2)      += serqt_usb2/
 obj-$(CONFIG_OCTEON_ETHERNET)  += octeon/
 obj-$(CONFIG_VT6655)           += vt6655/
@@ -50,10 +51,9 @@ obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4) += ste_rmi4/
 obj-$(CONFIG_MFD_NVEC)         += nvec/
 obj-$(CONFIG_ANDROID)          += android/
 obj-$(CONFIG_USB_WPAN_HCD)     += ozwpan/
-obj-$(CONFIG_USB_G_CCG)                += ccg/
 obj-$(CONFIG_WIMAX_GDM72XX)    += gdm72xx/
 obj-$(CONFIG_CSR_WIFI)         += csr/
-obj-$(CONFIG_OMAP_BANDGAP)     += omap-thermal/
+obj-$(CONFIG_TI_SOC_THERMAL)   += ti-soc-thermal/
 obj-$(CONFIG_NET_VENDOR_SILICOM)       += silicom/
 obj-$(CONFIG_CED1401)          += ced1401/
 obj-$(CONFIG_DRM_IMX)          += imx-drm/
@@ -62,3 +62,4 @@ obj-$(CONFIG_SB105X)          += sb105x/
 obj-$(CONFIG_FIREWIRE_SERIAL)  += fwserial/
 obj-$(CONFIG_ZCACHE)           += zcache/
 obj-$(CONFIG_GOLDFISH)         += goldfish/
+obj-$(CONFIG_USB_DWC2)         += dwc2/
index 465a28c08f20f890bd2e24fbd680fa4a8d7ada92..9f61d46da157ed031c67a102ba6584fbfb022d05 100644 (file)
@@ -22,7 +22,7 @@ config ANDROID_BINDER_IPC
 config ASHMEM
        bool "Enable the Anonymous Shared Memory Subsystem"
        default n
-       depends on SHMEM || TINY_SHMEM
+       depends on SHMEM
        ---help---
          The ashmem subsystem is a new shared memory allocator, similar to
          POSIX SHM but with different behavior and sporting a simpler
@@ -72,6 +72,33 @@ config ANDROID_INTF_ALARM_DEV
          elapsed realtime, and a non-wakeup alarm on the monotonic clock.
          Also exports the alarm interface to user-space.
 
+config SYNC
+       bool "Synchronization framework"
+       default n
+       select ANON_INODES
+       help
+         This option enables the framework for synchronization between multiple
+         drivers.  Sync implementations can take advantage of hardware
+         synchronization built into devices like GPUs.
+
+config SW_SYNC
+       bool "Software synchronization objects"
+       default n
+       depends on SYNC
+       help
+         A sync object driver that uses a 32bit counter to coordinate
+         syncrhronization.  Useful when there is no hardware primitive backing
+         the synchronization.
+
+config SW_SYNC_USER
+       bool "Userspace API for SW_SYNC"
+       default n
+       depends on SW_SYNC
+       help
+         Provides a user space API to the sw sync object.
+         *WARNING* improper use of this can result in deadlocking kernel
+         drivers from userspace.
+
 endif # if ANDROID
 
 endmenu
index b35a631734d6313e9c6dce8f945b9dd68ab8dd1c..c136299e05afd6f5657061e3577dc46e549e6d6b 100644 (file)
@@ -7,3 +7,5 @@ obj-$(CONFIG_ANDROID_TIMED_OUTPUT)      += timed_output.o
 obj-$(CONFIG_ANDROID_TIMED_GPIO)       += timed_gpio.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)        += lowmemorykiller.o
 obj-$(CONFIG_ANDROID_INTF_ALARM_DEV)   += alarm-dev.o
+obj-$(CONFIG_SYNC)                     += sync.o
+obj-$(CONFIG_SW_SYNC)                  += sw_sync.o
index 634b9ae713e090d087b76c58bfe595637766d9f6..e681bdd9aa5f46fb31e2a1390c3559387b333bf2 100644 (file)
@@ -414,20 +414,29 @@ out:
 static int set_name(struct ashmem_area *asma, void __user *name)
 {
        int ret = 0;
+       char local_name[ASHMEM_NAME_LEN];
 
-       mutex_lock(&ashmem_mutex);
+       /*
+        * Holding the ashmem_mutex while doing a copy_from_user might cause
+        * an data abort which would try to access mmap_sem. If another
+        * thread has invoked ashmem_mmap then it will be holding the
+        * semaphore and will be waiting for ashmem_mutex, there by leading to
+        * deadlock. We'll release the mutex  and take the name to a local
+        * variable that does not need protection and later copy the local
+        * variable to the structure member with lock held.
+        */
+       if (copy_from_user(local_name, name, ASHMEM_NAME_LEN))
+               return -EFAULT;
 
+       mutex_lock(&ashmem_mutex);
        /* cannot change an existing mapping's name */
        if (unlikely(asma->file)) {
                ret = -EINVAL;
                goto out;
        }
-
-       if (unlikely(copy_from_user(asma->name + ASHMEM_NAME_PREFIX_LEN,
-                                   name, ASHMEM_NAME_LEN)))
-               ret = -EFAULT;
+       memcpy(asma->name + ASHMEM_NAME_PREFIX_LEN,
+               local_name, ASHMEM_NAME_LEN);
        asma->name[ASHMEM_FULL_NAME_LEN-1] = '\0';
-
 out:
        mutex_unlock(&ashmem_mutex);
 
@@ -437,26 +446,36 @@ out:
 static int get_name(struct ashmem_area *asma, void __user *name)
 {
        int ret = 0;
+       size_t len;
+       /*
+        * Have a local variable to which we'll copy the content
+        * from asma with the lock held. Later we can copy this to the user
+        * space safely without holding any locks. So even if we proceed to
+        * wait for mmap_sem, it won't lead to deadlock.
+        */
+       char local_name[ASHMEM_NAME_LEN];
 
        mutex_lock(&ashmem_mutex);
        if (asma->name[ASHMEM_NAME_PREFIX_LEN] != '\0') {
-               size_t len;
 
                /*
                 * Copying only `len', instead of ASHMEM_NAME_LEN, bytes
                 * prevents us from revealing one user's stack to another.
                 */
                len = strlen(asma->name + ASHMEM_NAME_PREFIX_LEN) + 1;
-               if (unlikely(copy_to_user(name,
-                               asma->name + ASHMEM_NAME_PREFIX_LEN, len)))
-                       ret = -EFAULT;
+               memcpy(local_name, asma->name + ASHMEM_NAME_PREFIX_LEN, len);
        } else {
-               if (unlikely(copy_to_user(name, ASHMEM_NAME_DEF,
-                                         sizeof(ASHMEM_NAME_DEF))))
-                       ret = -EFAULT;
+               len = sizeof(ASHMEM_NAME_DEF);
+               memcpy(local_name, ASHMEM_NAME_DEF, len);
        }
        mutex_unlock(&ashmem_mutex);
 
+       /*
+        * Now we are just copying from the stack variable to userland
+        * No lock held
+        */
+       if (unlikely(copy_to_user(name, local_name, len)))
+               ret = -EFAULT;
        return ret;
 }
 
@@ -683,6 +702,23 @@ static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        return ret;
 }
 
+/* support of 32bit userspace on 64bit platforms */
+#ifdef CONFIG_COMPAT
+static long compat_ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+
+       switch (cmd) {
+       case COMPAT_ASHMEM_SET_SIZE:
+               cmd = ASHMEM_SET_SIZE;
+               break;
+       case COMPAT_ASHMEM_SET_PROT_MASK:
+               cmd = ASHMEM_SET_PROT_MASK;
+               break;
+       }
+       return ashmem_ioctl(file, cmd, arg);
+}
+#endif
+
 static const struct file_operations ashmem_fops = {
        .owner = THIS_MODULE,
        .open = ashmem_open,
@@ -691,7 +727,9 @@ static const struct file_operations ashmem_fops = {
        .llseek = ashmem_llseek,
        .mmap = ashmem_mmap,
        .unlocked_ioctl = ashmem_ioctl,
-       .compat_ioctl = ashmem_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = compat_ashmem_ioctl,
+#endif
 };
 
 static struct miscdevice ashmem_misc = {
index 1976b10ef93ebedf06b587ee8b6956b99d685e9c..8dc0f0d3adf310b651cf6b17742795ae5269600d 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <linux/limits.h>
 #include <linux/ioctl.h>
+#include <linux/compat.h>
 
 #define ASHMEM_NAME_LEN                256
 
@@ -45,4 +46,10 @@ struct ashmem_pin {
 #define ASHMEM_GET_PIN_STATUS  _IO(__ASHMEMIOC, 9)
 #define ASHMEM_PURGE_ALL_CACHES        _IO(__ASHMEMIOC, 10)
 
+/* support of 32bit userspace on 64bit platforms */
+#ifdef CONFIG_COMPAT
+#define COMPAT_ASHMEM_SET_SIZE         _IOW(__ASHMEMIOC, 3, compat_size_t)
+#define COMPAT_ASHMEM_SET_PROT_MASK    _IOW(__ASHMEMIOC, 5, unsigned int)
+#endif
+
 #endif /* _LINUX_ASHMEM_H */
index 24456a0de6b2143f3ceadff6edc26c48152d9701..1567ac296b393163225237c830c48a726e529b4e 100644 (file)
@@ -2878,82 +2878,109 @@ static int binder_release(struct inode *nodp, struct file *filp)
        return 0;
 }
 
+static int binder_node_release(struct binder_node *node, int refs)
+{
+       struct binder_ref *ref;
+       int death = 0;
+
+       list_del_init(&node->work.entry);
+       binder_release_work(&node->async_todo);
+
+       if (hlist_empty(&node->refs)) {
+               kfree(node);
+               binder_stats_deleted(BINDER_STAT_NODE);
+
+               return refs;
+       }
+
+       node->proc = NULL;
+       node->local_strong_refs = 0;
+       node->local_weak_refs = 0;
+       hlist_add_head(&node->dead_node, &binder_dead_nodes);
+
+       hlist_for_each_entry(ref, &node->refs, node_entry) {
+               refs++;
+
+               if (!ref->death)
+                       goto out;
+
+               death++;
+
+               if (list_empty(&ref->death->work.entry)) {
+                       ref->death->work.type = BINDER_WORK_DEAD_BINDER;
+                       list_add_tail(&ref->death->work.entry,
+                                     &ref->proc->todo);
+                       wake_up_interruptible(&ref->proc->wait);
+               } else
+                       BUG();
+       }
+
+out:
+       binder_debug(BINDER_DEBUG_DEAD_BINDER,
+                    "node %d now dead, refs %d, death %d\n",
+                    node->debug_id, refs, death);
+
+       return refs;
+}
+
 static void binder_deferred_release(struct binder_proc *proc)
 {
        struct binder_transaction *t;
        struct rb_node *n;
-       int threads, nodes, incoming_refs, outgoing_refs, buffers, active_transactions, page_count;
+       int threads, nodes, incoming_refs, outgoing_refs, buffers,
+               active_transactions, page_count;
 
        BUG_ON(proc->vma);
        BUG_ON(proc->files);
 
        hlist_del(&proc->proc_node);
+
        if (binder_context_mgr_node && binder_context_mgr_node->proc == proc) {
                binder_debug(BINDER_DEBUG_DEAD_BINDER,
-                            "binder_release: %d context_mgr_node gone\n",
-                            proc->pid);
+                            "%s: %d context_mgr_node gone\n",
+                            __func__, proc->pid);
                binder_context_mgr_node = NULL;
        }
 
        threads = 0;
        active_transactions = 0;
        while ((n = rb_first(&proc->threads))) {
-               struct binder_thread *thread = rb_entry(n, struct binder_thread, rb_node);
+               struct binder_thread *thread;
+
+               thread = rb_entry(n, struct binder_thread, rb_node);
                threads++;
                active_transactions += binder_free_thread(proc, thread);
        }
+
        nodes = 0;
        incoming_refs = 0;
        while ((n = rb_first(&proc->nodes))) {
-               struct binder_node *node = rb_entry(n, struct binder_node, rb_node);
+               struct binder_node *node;
 
+               node = rb_entry(n, struct binder_node, rb_node);
                nodes++;
                rb_erase(&node->rb_node, &proc->nodes);
-               list_del_init(&node->work.entry);
-               binder_release_work(&node->async_todo);
-               if (hlist_empty(&node->refs)) {
-                       kfree(node);
-                       binder_stats_deleted(BINDER_STAT_NODE);
-               } else {
-                       struct binder_ref *ref;
-                       int death = 0;
-
-                       node->proc = NULL;
-                       node->local_strong_refs = 0;
-                       node->local_weak_refs = 0;
-                       hlist_add_head(&node->dead_node, &binder_dead_nodes);
-
-                       hlist_for_each_entry(ref, &node->refs, node_entry) {
-                               incoming_refs++;
-                               if (ref->death) {
-                                       death++;
-                                       if (list_empty(&ref->death->work.entry)) {
-                                               ref->death->work.type = BINDER_WORK_DEAD_BINDER;
-                                               list_add_tail(&ref->death->work.entry, &ref->proc->todo);
-                                               wake_up_interruptible(&ref->proc->wait);
-                                       } else
-                                               BUG();
-                               }
-                       }
-                       binder_debug(BINDER_DEBUG_DEAD_BINDER,
-                                    "node %d now dead, refs %d, death %d\n",
-                                     node->debug_id, incoming_refs, death);
-               }
+               incoming_refs = binder_node_release(node, incoming_refs);
        }
+
        outgoing_refs = 0;
        while ((n = rb_first(&proc->refs_by_desc))) {
-               struct binder_ref *ref = rb_entry(n, struct binder_ref,
-                                                 rb_node_desc);
+               struct binder_ref *ref;
+
+               ref = rb_entry(n, struct binder_ref, rb_node_desc);
                outgoing_refs++;
                binder_delete_ref(ref);
        }
+
        binder_release_work(&proc->todo);
        binder_release_work(&proc->delivered_death);
-       buffers = 0;
 
+       buffers = 0;
        while ((n = rb_first(&proc->allocated_buffers))) {
-               struct binder_buffer *buffer = rb_entry(n, struct binder_buffer,
-                                                       rb_node);
+               struct binder_buffer *buffer;
+
+               buffer = rb_entry(n, struct binder_buffer, rb_node);
+
                t = buffer->transaction;
                if (t) {
                        t->buffer = NULL;
@@ -2962,6 +2989,7 @@ static void binder_deferred_release(struct binder_proc *proc)
                               proc->pid, t->debug_id);
                        /*BUG();*/
                }
+
                binder_free_buf(proc, buffer);
                buffers++;
        }
@@ -2971,18 +2999,20 @@ static void binder_deferred_release(struct binder_proc *proc)
        page_count = 0;
        if (proc->pages) {
                int i;
+
                for (i = 0; i < proc->buffer_size / PAGE_SIZE; i++) {
-                       if (proc->pages[i]) {
-                               void *page_addr = proc->buffer + i * PAGE_SIZE;
-                               binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
-                                            "binder_release: %d: page %d at %p not freed\n",
-                                            proc->pid, i,
-                                            page_addr);
-                               unmap_kernel_range((unsigned long)page_addr,
-                                       PAGE_SIZE);
-                               __free_page(proc->pages[i]);
-                               page_count++;
-                       }
+                       void *page_addr;
+
+                       if (!proc->pages[i])
+                               continue;
+
+                       page_addr = proc->buffer + i * PAGE_SIZE;
+                       binder_debug(BINDER_DEBUG_BUFFER_ALLOC,
+                                    "%s: %d: page %d at %p not freed\n",
+                                    __func__, proc->pid, i, page_addr);
+                       unmap_kernel_range((unsigned long)page_addr, PAGE_SIZE);
+                       __free_page(proc->pages[i]);
+                       page_count++;
                }
                kfree(proc->pages);
                vfree(proc->buffer);
@@ -2991,9 +3021,9 @@ static void binder_deferred_release(struct binder_proc *proc)
        put_task_struct(proc->tsk);
 
        binder_debug(BINDER_DEBUG_OPEN_CLOSE,
-                    "binder_release: %d threads %d, nodes %d (ref %d), refs %d, active transactions %d, buffers %d, pages %d\n",
-                    proc->pid, threads, nodes, incoming_refs, outgoing_refs,
-                    active_transactions, buffers, page_count);
+                    "%s: %d threads %d, nodes %d (ref %d), refs %d, active transactions %d, buffers %d, pages %d\n",
+                    __func__, proc->pid, threads, nodes, incoming_refs,
+                    outgoing_refs, active_transactions, buffers, page_count);
 
        kfree(proc);
 }
index dbc63cbb4d3a2394a4132874dc3d1f5f5ec46444..b14a55742559986781331e2bdd10cd7711b01d5f 100644 (file)
@@ -68,6 +68,8 @@ static LIST_HEAD(log_list);
  * @log:       The associated log
  * @list:      The associated entry in @logger_log's list
  * @r_off:     The current read head offset.
+ * @r_all:     Reader can read all entries
+ * @r_ver:     Reader ABI version
  *
  * This object lives from open to release, so we don't need additional
  * reference counting. The structure is protected by log->mutex.
@@ -76,6 +78,8 @@ struct logger_reader {
        struct logger_log       *log;
        struct list_head        list;
        size_t                  r_off;
+       bool                    r_all;
+       int                     r_ver;
 };
 
 /* logger_offset - returns index 'n' into the log via (optimized) modulus */
@@ -109,8 +113,29 @@ static inline struct logger_log *file_get_log(struct file *file)
 }
 
 /*
- * get_entry_len - Grabs the length of the payload of the next entry starting
- * from 'off'.
+ * get_entry_header - returns a pointer to the logger_entry header within
+ * 'log' starting at offset 'off'. A temporary logger_entry 'scratch' must
+ * be provided. Typically the return value will be a pointer within
+ * 'logger->buf'.  However, a pointer to 'scratch' may be returned if
+ * the log entry spans the end and beginning of the circular buffer.
+ */
+static struct logger_entry *get_entry_header(struct logger_log *log,
+               size_t off, struct logger_entry *scratch)
+{
+       size_t len = min(sizeof(struct logger_entry), log->size - off);
+       if (len != sizeof(struct logger_entry)) {
+               memcpy(((void *) scratch), log->buffer + off, len);
+               memcpy(((void *) scratch) + len, log->buffer,
+                       sizeof(struct logger_entry) - len);
+               return scratch;
+       }
+
+       return (struct logger_entry *) (log->buffer + off);
+}
+
+/*
+ * get_entry_msg_len - Grabs the length of the message of the entry
+ * starting from from 'off'.
  *
  * An entry length is 2 bytes (16 bits) in host endian order.
  * In the log, the length does not include the size of the log entry structure.
@@ -118,20 +143,45 @@ static inline struct logger_log *file_get_log(struct file *file)
  *
  * Caller needs to hold log->mutex.
  */
-static __u32 get_entry_len(struct logger_log *log, size_t off)
+static __u32 get_entry_msg_len(struct logger_log *log, size_t off)
 {
-       __u16 val;
+       struct logger_entry scratch;
+       struct logger_entry *entry;
 
-       /* copy 2 bytes from buffer, in memcpy order, */
-       /* handling possible wrap at end of buffer */
+       entry = get_entry_header(log, off, &scratch);
+       return entry->len;
+}
 
-       ((__u8 *)&val)[0] = log->buffer[off];
-       if (likely(off+1 < log->size))
-               ((__u8 *)&val)[1] = log->buffer[off+1];
+static size_t get_user_hdr_len(int ver)
+{
+       if (ver < 2)
+               return sizeof(struct user_logger_entry_compat);
        else
-               ((__u8 *)&val)[1] = log->buffer[0];
+               return sizeof(struct logger_entry);
+}
 
-       return sizeof(struct logger_entry) + val;
+static ssize_t copy_header_to_user(int ver, struct logger_entry *entry,
+                                        char __user *buf)
+{
+       void *hdr;
+       size_t hdr_len;
+       struct user_logger_entry_compat v1;
+
+       if (ver < 2) {
+               v1.len      = entry->len;
+               v1.__pad    = 0;
+               v1.pid      = entry->pid;
+               v1.tid      = entry->tid;
+               v1.sec      = entry->sec;
+               v1.nsec     = entry->nsec;
+               hdr         = &v1;
+               hdr_len     = sizeof(struct user_logger_entry_compat);
+       } else {
+               hdr         = entry;
+               hdr_len     = sizeof(struct logger_entry);
+       }
+
+       return copy_to_user(buf, hdr, hdr_len);
 }
 
 /*
@@ -145,15 +195,31 @@ static ssize_t do_read_log_to_user(struct logger_log *log,
                                   char __user *buf,
                                   size_t count)
 {
+       struct logger_entry scratch;
+       struct logger_entry *entry;
        size_t len;
+       size_t msg_start;
 
        /*
-        * We read from the log in two disjoint operations. First, we read from
-        * the current read head offset up to 'count' bytes or to the end of
+        * First, copy the header to userspace, using the version of
+        * the header requested
+        */
+       entry = get_entry_header(log, reader->r_off, &scratch);
+       if (copy_header_to_user(reader->r_ver, entry, buf))
+               return -EFAULT;
+
+       count -= get_user_hdr_len(reader->r_ver);
+       buf += get_user_hdr_len(reader->r_ver);
+       msg_start = logger_offset(log,
+               reader->r_off + sizeof(struct logger_entry));
+
+       /*
+        * We read from the msg in two disjoint operations. First, we read from
+        * the current msg head offset up to 'count' bytes or to the end of
         * the log, whichever comes first.
         */
-       len = min(count, log->size - reader->r_off);
-       if (copy_to_user(buf, log->buffer + reader->r_off, len))
+       len = min(count, log->size - msg_start);
+       if (copy_to_user(buf, log->buffer + msg_start, len))
                return -EFAULT;
 
        /*
@@ -164,9 +230,34 @@ static ssize_t do_read_log_to_user(struct logger_log *log,
                if (copy_to_user(buf + len, log->buffer, count - len))
                        return -EFAULT;
 
-       reader->r_off = logger_offset(log, reader->r_off + count);
+       reader->r_off = logger_offset(log, reader->r_off +
+               sizeof(struct logger_entry) + count);
 
-       return count;
+       return count + get_user_hdr_len(reader->r_ver);
+}
+
+/*
+ * get_next_entry_by_uid - Starting at 'off', returns an offset into
+ * 'log->buffer' which contains the first entry readable by 'euid'
+ */
+static size_t get_next_entry_by_uid(struct logger_log *log,
+               size_t off, uid_t euid)
+{
+       while (off != log->w_off) {
+               struct logger_entry *entry;
+               struct logger_entry scratch;
+               size_t next_len;
+
+               entry = get_entry_header(log, off, &scratch);
+
+               if (entry->euid == euid)
+                       return off;
+
+               next_len = sizeof(struct logger_entry) + entry->len;
+               off = logger_offset(log, off + next_len);
+       }
+
+       return off;
 }
 
 /*
@@ -178,7 +269,7 @@ static ssize_t do_read_log_to_user(struct logger_log *log,
  *     - If there are no log entries to read, blocks until log is written to
  *     - Atomically reads exactly one log entry
  *
- * Optimal read size is LOGGER_ENTRY_MAX_LEN. Will set errno to EINVAL if read
+ * Will set errno to EINVAL if read
  * buffer is insufficient to hold next entry.
  */
 static ssize_t logger_read(struct file *file, char __user *buf,
@@ -219,6 +310,10 @@ start:
 
        mutex_lock(&log->mutex);
 
+       if (!reader->r_all)
+               reader->r_off = get_next_entry_by_uid(log,
+                       reader->r_off, current_euid());
+
        /* is there still something to read or did we race? */
        if (unlikely(log->w_off == reader->r_off)) {
                mutex_unlock(&log->mutex);
@@ -226,7 +321,8 @@ start:
        }
 
        /* get the size of the next entry */
-       ret = get_entry_len(log, reader->r_off);
+       ret = get_user_hdr_len(reader->r_ver) +
+               get_entry_msg_len(log, reader->r_off);
        if (count < ret) {
                ret = -EINVAL;
                goto out;
@@ -252,7 +348,8 @@ static size_t get_next_entry(struct logger_log *log, size_t off, size_t len)
        size_t count = 0;
 
        do {
-               size_t nr = get_entry_len(log, off);
+               size_t nr = sizeof(struct logger_entry) +
+                       get_entry_msg_len(log, off);
                off = logger_offset(log, off + nr);
                count += nr;
        } while (count < len);
@@ -382,7 +479,9 @@ static ssize_t logger_aio_write(struct kiocb *iocb, const struct iovec *iov,
        header.tid = current->pid;
        header.sec = now.tv_sec;
        header.nsec = now.tv_nsec;
+       header.euid = current_euid();
        header.len = min_t(size_t, iocb->ki_left, LOGGER_ENTRY_MAX_PAYLOAD);
+       header.hdr_size = sizeof(struct logger_entry);
 
        /* null writes succeed, return zero */
        if (unlikely(!header.len))
@@ -463,6 +562,10 @@ static int logger_open(struct inode *inode, struct file *file)
                        return -ENOMEM;
 
                reader->log = log;
+               reader->r_ver = 1;
+               reader->r_all = in_egroup_p(inode->i_gid) ||
+                       capable(CAP_SYSLOG);
+
                INIT_LIST_HEAD(&reader->list);
 
                mutex_lock(&log->mutex);
@@ -522,6 +625,10 @@ static unsigned int logger_poll(struct file *file, poll_table *wait)
        poll_wait(file, &log->wq, wait);
 
        mutex_lock(&log->mutex);
+       if (!reader->r_all)
+               reader->r_off = get_next_entry_by_uid(log,
+                       reader->r_off, current_euid());
+
        if (log->w_off != reader->r_off)
                ret |= POLLIN | POLLRDNORM;
        mutex_unlock(&log->mutex);
@@ -529,11 +636,25 @@ static unsigned int logger_poll(struct file *file, poll_table *wait)
        return ret;
 }
 
+static long logger_set_version(struct logger_reader *reader, void __user *arg)
+{
+       int version;
+       if (copy_from_user(&version, arg, sizeof(int)))
+               return -EFAULT;
+
+       if ((version < 1) || (version > 2))
+               return -EINVAL;
+
+       reader->r_ver = version;
+       return 0;
+}
+
 static long logger_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        struct logger_log *log = file_get_log(file);
        struct logger_reader *reader;
-       long ret = -ENOTTY;
+       long ret = -EINVAL;
+       void __user *argp = (void __user *) arg;
 
        mutex_lock(&log->mutex);
 
@@ -558,8 +679,14 @@ static long logger_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        break;
                }
                reader = file->private_data;
+
+               if (!reader->r_all)
+                       reader->r_off = get_next_entry_by_uid(log,
+                               reader->r_off, current_euid());
+
                if (log->w_off != reader->r_off)
-                       ret = get_entry_len(log, reader->r_off);
+                       ret = get_user_hdr_len(reader->r_ver) +
+                               get_entry_msg_len(log, reader->r_off);
                else
                        ret = 0;
                break;
@@ -568,11 +695,32 @@ static long logger_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        ret = -EBADF;
                        break;
                }
+               if (!(in_egroup_p(file->f_dentry->d_inode->i_gid) ||
+                               capable(CAP_SYSLOG))) {
+                       ret = -EPERM;
+                       break;
+               }
                list_for_each_entry(reader, &log->readers, list)
                        reader->r_off = log->w_off;
                log->head = log->w_off;
                ret = 0;
                break;
+       case LOGGER_GET_VERSION:
+               if (!(file->f_mode & FMODE_READ)) {
+                       ret = -EBADF;
+                       break;
+               }
+               reader = file->private_data;
+               ret = reader->r_ver;
+               break;
+       case LOGGER_SET_VERSION:
+               if (!(file->f_mode & FMODE_READ)) {
+                       ret = -EBADF;
+                       break;
+               }
+               reader = file->private_data;
+               ret = logger_set_version(reader, argp);
+               break;
        }
 
        mutex_unlock(&log->mutex);
@@ -592,8 +740,8 @@ static const struct file_operations logger_fops = {
 };
 
 /*
- * Log size must be a power of two, greater than LOGGER_ENTRY_MAX_LEN,
- * and less than LONG_MAX minus LOGGER_ENTRY_MAX_LEN.
+ * Log size must must be a power of two, and greater than
+ * (LOGGER_ENTRY_MAX_PAYLOAD + sizeof(struct logger_entry)).
  */
 static int __init create_log(char *log_name, int size)
 {
index 9b929a8c7468b37dadfc0d30db6c644be03b0991..cc6bbd99c8e0326838246557f104d90fd11f9998 100644 (file)
@@ -21,7 +21,7 @@
 #include <linux/ioctl.h>
 
 /**
- * struct logger_entry - defines a single entry that is given to a logger
+ * struct user_logger_entry_compat - defines a single entry that is given to a logger
  * @len:       The length of the payload
  * @__pad:     Two bytes of padding that appear to be required
  * @pid:       The generating process' process ID
  * @sec:       The number of seconds that have elapsed since the Epoch
  * @nsec:      The number of nanoseconds that have elapsed since @sec
  * @msg:       The message that is to be logged
+ *
+ * The userspace structure for version 1 of the logger_entry ABI.
+ * This structure is returned to userspace unless the caller requests
+ * an upgrade to a newer ABI version.
  */
-struct logger_entry {
+struct user_logger_entry_compat {
        __u16           len;
        __u16           __pad;
        __s32           pid;
@@ -40,14 +44,38 @@ struct logger_entry {
        char            msg[0];
 };
 
+/**
+ * struct logger_entry - defines a single entry that is given to a logger
+ * @len:       The length of the payload
+ * @hdr_size:  sizeof(struct logger_entry_v2)
+ * @pid:       The generating process' process ID
+ * @tid:       The generating process' thread ID
+ * @sec:       The number of seconds that have elapsed since the Epoch
+ * @nsec:      The number of nanoseconds that have elapsed since @sec
+ * @euid:      Effective UID of logger
+ * @msg:       The message that is to be logged
+ *
+ * The structure for version 2 of the logger_entry ABI.
+ * This structure is returned to userspace if ioctl(LOGGER_SET_VERSION)
+ * is called with version >= 2
+ */
+struct logger_entry {
+       __u16           len;
+       __u16           hdr_size;
+       __s32           pid;
+       __s32           tid;
+       __s32           sec;
+       __s32           nsec;
+       uid_t           euid;
+       char            msg[0];
+};
+
 #define LOGGER_LOG_RADIO       "log_radio"     /* radio-related messages */
 #define LOGGER_LOG_EVENTS      "log_events"    /* system/hardware events */
 #define LOGGER_LOG_SYSTEM      "log_system"    /* system/framework messages */
 #define LOGGER_LOG_MAIN                "log_main"      /* everything else */
 
-#define LOGGER_ENTRY_MAX_LEN           (4*1024)
-#define LOGGER_ENTRY_MAX_PAYLOAD       \
-       (LOGGER_ENTRY_MAX_LEN - sizeof(struct logger_entry))
+#define LOGGER_ENTRY_MAX_PAYLOAD       4076
 
 #define __LOGGERIO     0xAE
 
@@ -55,5 +83,7 @@ struct logger_entry {
 #define LOGGER_GET_LOG_LEN             _IO(__LOGGERIO, 2) /* used log len */
 #define LOGGER_GET_NEXT_ENTRY_LEN      _IO(__LOGGERIO, 3) /* next entry len */
 #define LOGGER_FLUSH_LOG               _IO(__LOGGERIO, 4) /* flush log */
+#define LOGGER_GET_VERSION             _IO(__LOGGERIO, 5) /* abi version */
+#define LOGGER_SET_VERSION             _IO(__LOGGERIO, 6) /* abi version */
 
 #endif /* _LINUX_LOGGER_H */
index 3b91b0fd4de3c7194c68e18f5a10b514c1544e75..fe74494868ef33037e7e43602471b51780f6c37d 100644 (file)
  *
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/oom.h>
 #include <linux/sched.h>
+#include <linux/swap.h>
 #include <linux/rcupdate.h>
 #include <linux/profile.h>
 #include <linux/notifier.h>
 
-static uint32_t lowmem_debug_level = 2;
+static uint32_t lowmem_debug_level = 1;
 static short lowmem_adj[6] = {
        0,
        1,
@@ -60,7 +63,7 @@ static unsigned long lowmem_deathpending_timeout;
 #define lowmem_print(level, x...)                      \
        do {                                            \
                if (lowmem_debug_level >= (level))      \
-                       printk(x);                      \
+                       pr_info(x);                     \
        } while (0)
 
 static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
@@ -74,7 +77,7 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
        int selected_tasksize = 0;
        short selected_oom_score_adj;
        int array_size = ARRAY_SIZE(lowmem_adj);
-       int other_free = global_page_state(NR_FREE_PAGES);
+       int other_free = global_page_state(NR_FREE_PAGES) - totalreserve_pages;
        int other_file = global_page_state(NR_FILE_PAGES) -
                                                global_page_state(NR_SHMEM);
 
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
new file mode 100644 (file)
index 0000000..4928f93
--- /dev/null
@@ -0,0 +1,264 @@
+/*
+ * drivers/base/sw_sync.c
+ *
+ * Copyright (C) 2012 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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/kernel.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>
+
+#include "sw_sync.h"
+
+static int sw_sync_cmp(u32 a, u32 b)
+{
+       if (a == b)
+               return 0;
+
+       return ((s32)a - (s32)b) < 0 ? -1 : 1;
+}
+
+struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value)
+{
+       struct sw_sync_pt *pt;
+
+       pt = (struct sw_sync_pt *)
+               sync_pt_create(&obj->obj, sizeof(struct sw_sync_pt));
+
+       pt->value = value;
+
+       return (struct sync_pt *)pt;
+}
+EXPORT_SYMBOL(sw_sync_pt_create);
+
+static struct sync_pt *sw_sync_pt_dup(struct sync_pt *sync_pt)
+{
+       struct sw_sync_pt *pt = (struct sw_sync_pt *) sync_pt;
+       struct sw_sync_timeline *obj =
+               (struct sw_sync_timeline *)sync_pt->parent;
+
+       return (struct sync_pt *) sw_sync_pt_create(obj, pt->value);
+}
+
+static int sw_sync_pt_has_signaled(struct sync_pt *sync_pt)
+{
+       struct sw_sync_pt *pt = (struct sw_sync_pt *)sync_pt;
+       struct sw_sync_timeline *obj =
+               (struct sw_sync_timeline *)sync_pt->parent;
+
+       return sw_sync_cmp(obj->value, pt->value) >= 0;
+}
+
+static int sw_sync_pt_compare(struct sync_pt *a, struct sync_pt *b)
+{
+       struct sw_sync_pt *pt_a = (struct sw_sync_pt *)a;
+       struct sw_sync_pt *pt_b = (struct sw_sync_pt *)b;
+
+       return sw_sync_cmp(pt_a->value, pt_b->value);
+}
+
+static int sw_sync_fill_driver_data(struct sync_pt *sync_pt,
+                                   void *data, int size)
+{
+       struct sw_sync_pt *pt = (struct sw_sync_pt *)sync_pt;
+
+       if (size < sizeof(pt->value))
+               return -ENOMEM;
+
+       memcpy(data, &pt->value, sizeof(pt->value));
+
+       return sizeof(pt->value);
+}
+
+static void sw_sync_timeline_value_str(struct sync_timeline *sync_timeline,
+                                      char *str, int size)
+{
+       struct sw_sync_timeline *timeline =
+               (struct sw_sync_timeline *)sync_timeline;
+       snprintf(str, size, "%d", timeline->value);
+}
+
+static void sw_sync_pt_value_str(struct sync_pt *sync_pt,
+                                      char *str, int size)
+{
+       struct sw_sync_pt *pt = (struct sw_sync_pt *)sync_pt;
+       snprintf(str, size, "%d", pt->value);
+}
+
+static struct sync_timeline_ops sw_sync_timeline_ops = {
+       .driver_name = "sw_sync",
+       .dup = sw_sync_pt_dup,
+       .has_signaled = sw_sync_pt_has_signaled,
+       .compare = sw_sync_pt_compare,
+       .fill_driver_data = sw_sync_fill_driver_data,
+       .timeline_value_str = sw_sync_timeline_value_str,
+       .pt_value_str = sw_sync_pt_value_str,
+};
+
+
+struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
+{
+       struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
+               sync_timeline_create(&sw_sync_timeline_ops,
+                                    sizeof(struct sw_sync_timeline),
+                                    name);
+
+       return obj;
+}
+EXPORT_SYMBOL(sw_sync_timeline_create);
+
+void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
+{
+       obj->value += inc;
+
+       sync_timeline_signal(&obj->obj);
+}
+EXPORT_SYMBOL(sw_sync_timeline_inc);
+
+#ifdef CONFIG_SW_SYNC_USER
+/* *WARNING*
+ *
+ * improper use of this can result in deadlocking kernel drivers from userspace.
+ */
+
+/* opening sw_sync create a new sync obj */
+static int sw_sync_open(struct inode *inode, struct file *file)
+{
+       struct sw_sync_timeline *obj;
+       char task_comm[TASK_COMM_LEN];
+
+       get_task_comm(task_comm, current);
+
+       obj = sw_sync_timeline_create(task_comm);
+       if (obj == NULL)
+               return -ENOMEM;
+
+       file->private_data = obj;
+
+       return 0;
+}
+
+static int sw_sync_release(struct inode *inode, struct file *file)
+{
+       struct sw_sync_timeline *obj = file->private_data;
+       sync_timeline_destroy(&obj->obj);
+       return 0;
+}
+
+static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj, unsigned long arg)
+{
+       int fd = get_unused_fd();
+       int err;
+       struct sync_pt *pt;
+       struct sync_fence *fence;
+       struct sw_sync_create_fence_data data;
+
+       if (fd < 0)
+               return fd;
+
+       if (copy_from_user(&data, (void __user *)arg, sizeof(data))) {
+               err = -EFAULT;
+               goto err;
+       }
+
+       pt = sw_sync_pt_create(obj, data.value);
+       if (pt == NULL) {
+               err = -ENOMEM;
+               goto err;
+       }
+
+       data.name[sizeof(data.name) - 1] = '\0';
+       fence = sync_fence_create(data.name, pt);
+       if (fence == NULL) {
+               sync_pt_free(pt);
+               err = -ENOMEM;
+               goto err;
+       }
+
+       data.fence = fd;
+       if (copy_to_user((void __user *)arg, &data, sizeof(data))) {
+               sync_fence_put(fence);
+               err = -EFAULT;
+               goto err;
+       }
+
+       sync_fence_install(fence, fd);
+
+       return 0;
+
+err:
+       put_unused_fd(fd);
+       return err;
+}
+
+static long sw_sync_ioctl_inc(struct sw_sync_timeline *obj, unsigned long arg)
+{
+       u32 value;
+
+       if (copy_from_user(&value, (void __user *)arg, sizeof(value)))
+               return -EFAULT;
+
+       sw_sync_timeline_inc(obj, value);
+
+       return 0;
+}
+
+static long sw_sync_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+       struct sw_sync_timeline *obj = file->private_data;
+
+       switch (cmd) {
+       case SW_SYNC_IOC_CREATE_FENCE:
+               return sw_sync_ioctl_create_fence(obj, arg);
+
+       case SW_SYNC_IOC_INC:
+               return sw_sync_ioctl_inc(obj, arg);
+
+       default:
+               return -ENOTTY;
+       }
+}
+
+static const struct file_operations sw_sync_fops = {
+       .owner = THIS_MODULE,
+       .open = sw_sync_open,
+       .release = sw_sync_release,
+       .unlocked_ioctl = sw_sync_ioctl,
+       .compat_ioctl = sw_sync_ioctl,
+};
+
+static struct miscdevice sw_sync_dev = {
+       .minor  = MISC_DYNAMIC_MINOR,
+       .name   = "sw_sync",
+       .fops   = &sw_sync_fops,
+};
+
+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);
+
+#endif /* CONFIG_SW_SYNC_USER */
diff --git a/drivers/staging/android/sw_sync.h b/drivers/staging/android/sw_sync.h
new file mode 100644 (file)
index 0000000..585040b
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * include/linux/sw_sync.h
+ *
+ * Copyright (C) 2012 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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 _LINUX_SW_SYNC_H
+#define _LINUX_SW_SYNC_H
+
+#include <linux/types.h>
+
+#ifdef __KERNEL__
+
+#include "sync.h"
+
+struct sw_sync_timeline {
+       struct  sync_timeline   obj;
+
+       u32                     value;
+};
+
+struct sw_sync_pt {
+       struct sync_pt          pt;
+
+       u32                     value;
+};
+
+struct sw_sync_timeline *sw_sync_timeline_create(const char *name);
+void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc);
+
+struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value);
+
+#endif /* __KERNEL __ */
+
+struct sw_sync_create_fence_data {
+       __u32   value;
+       char    name[32];
+       __s32   fence; /* fd of new fence */
+};
+
+#define SW_SYNC_IOC_MAGIC      'W'
+
+#define SW_SYNC_IOC_CREATE_FENCE       _IOWR(SW_SYNC_IOC_MAGIC, 0,\
+               struct sw_sync_create_fence_data)
+#define SW_SYNC_IOC_INC                        _IOW(SW_SYNC_IOC_MAGIC, 1, __u32)
+
+
+#endif /* _LINUX_SW_SYNC_H */
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
new file mode 100644 (file)
index 0000000..3893a35
--- /dev/null
@@ -0,0 +1,1017 @@
+/*
+ * drivers/base/sync.c
+ *
+ * Copyright (C) 2012 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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/debugfs.h>
+#include <linux/export.h>
+#include <linux/file.h>
+#include <linux/fs.h>
+#include <linux/kernel.h>
+#include <linux/poll.h>
+#include <linux/sched.h>
+#include <linux/seq_file.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+#include <linux/anon_inodes.h>
+
+#include "sync.h"
+
+#define CREATE_TRACE_POINTS
+#include "trace/sync.h"
+
+static void sync_fence_signal_pt(struct sync_pt *pt);
+static int _sync_pt_has_signaled(struct sync_pt *pt);
+static void sync_fence_free(struct kref *kref);
+static void sync_dump(void);
+
+static LIST_HEAD(sync_timeline_list_head);
+static DEFINE_SPINLOCK(sync_timeline_list_lock);
+
+static LIST_HEAD(sync_fence_list_head);
+static DEFINE_SPINLOCK(sync_fence_list_lock);
+
+struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
+                                          int size, const char *name)
+{
+       struct sync_timeline *obj;
+       unsigned long flags;
+
+       if (size < sizeof(struct sync_timeline))
+               return NULL;
+
+       obj = kzalloc(size, GFP_KERNEL);
+       if (obj == NULL)
+               return NULL;
+
+       kref_init(&obj->kref);
+       obj->ops = ops;
+       strlcpy(obj->name, name, sizeof(obj->name));
+
+       INIT_LIST_HEAD(&obj->child_list_head);
+       spin_lock_init(&obj->child_list_lock);
+
+       INIT_LIST_HEAD(&obj->active_list_head);
+       spin_lock_init(&obj->active_list_lock);
+
+       spin_lock_irqsave(&sync_timeline_list_lock, flags);
+       list_add_tail(&obj->sync_timeline_list, &sync_timeline_list_head);
+       spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
+
+       return obj;
+}
+EXPORT_SYMBOL(sync_timeline_create);
+
+static void sync_timeline_free(struct kref *kref)
+{
+       struct sync_timeline *obj =
+               container_of(kref, struct sync_timeline, kref);
+       unsigned long flags;
+
+       if (obj->ops->release_obj)
+               obj->ops->release_obj(obj);
+
+       spin_lock_irqsave(&sync_timeline_list_lock, flags);
+       list_del(&obj->sync_timeline_list);
+       spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
+
+       kfree(obj);
+}
+
+void sync_timeline_destroy(struct sync_timeline *obj)
+{
+       obj->destroyed = true;
+
+       /*
+        * If this is not the last reference, signal any children
+        * that their parent is going away.
+        */
+
+       if (!kref_put(&obj->kref, sync_timeline_free))
+               sync_timeline_signal(obj);
+}
+EXPORT_SYMBOL(sync_timeline_destroy);
+
+static void sync_timeline_add_pt(struct sync_timeline *obj, struct sync_pt *pt)
+{
+       unsigned long flags;
+
+       pt->parent = obj;
+
+       spin_lock_irqsave(&obj->child_list_lock, flags);
+       list_add_tail(&pt->child_list, &obj->child_list_head);
+       spin_unlock_irqrestore(&obj->child_list_lock, flags);
+}
+
+static void sync_timeline_remove_pt(struct sync_pt *pt)
+{
+       struct sync_timeline *obj = pt->parent;
+       unsigned long flags;
+
+       spin_lock_irqsave(&obj->active_list_lock, flags);
+       if (!list_empty(&pt->active_list))
+               list_del_init(&pt->active_list);
+       spin_unlock_irqrestore(&obj->active_list_lock, flags);
+
+       spin_lock_irqsave(&obj->child_list_lock, flags);
+       if (!list_empty(&pt->child_list)) {
+               list_del_init(&pt->child_list);
+       }
+       spin_unlock_irqrestore(&obj->child_list_lock, flags);
+}
+
+void sync_timeline_signal(struct sync_timeline *obj)
+{
+       unsigned long flags;
+       LIST_HEAD(signaled_pts);
+       struct list_head *pos, *n;
+
+       trace_sync_timeline(obj);
+
+       spin_lock_irqsave(&obj->active_list_lock, flags);
+
+       list_for_each_safe(pos, n, &obj->active_list_head) {
+               struct sync_pt *pt =
+                       container_of(pos, struct sync_pt, active_list);
+
+               if (_sync_pt_has_signaled(pt)) {
+                       list_del_init(pos);
+                       list_add(&pt->signaled_list, &signaled_pts);
+                       kref_get(&pt->fence->kref);
+               }
+       }
+
+       spin_unlock_irqrestore(&obj->active_list_lock, flags);
+
+       list_for_each_safe(pos, n, &signaled_pts) {
+               struct sync_pt *pt =
+                       container_of(pos, struct sync_pt, signaled_list);
+
+               list_del_init(pos);
+               sync_fence_signal_pt(pt);
+               kref_put(&pt->fence->kref, sync_fence_free);
+       }
+}
+EXPORT_SYMBOL(sync_timeline_signal);
+
+struct sync_pt *sync_pt_create(struct sync_timeline *parent, int size)
+{
+       struct sync_pt *pt;
+
+       if (size < sizeof(struct sync_pt))
+               return NULL;
+
+       pt = kzalloc(size, GFP_KERNEL);
+       if (pt == NULL)
+               return NULL;
+
+       INIT_LIST_HEAD(&pt->active_list);
+       kref_get(&parent->kref);
+       sync_timeline_add_pt(parent, pt);
+
+       return pt;
+}
+EXPORT_SYMBOL(sync_pt_create);
+
+void sync_pt_free(struct sync_pt *pt)
+{
+       if (pt->parent->ops->free_pt)
+               pt->parent->ops->free_pt(pt);
+
+       sync_timeline_remove_pt(pt);
+
+       kref_put(&pt->parent->kref, sync_timeline_free);
+
+       kfree(pt);
+}
+EXPORT_SYMBOL(sync_pt_free);
+
+/* call with pt->parent->active_list_lock held */
+static int _sync_pt_has_signaled(struct sync_pt *pt)
+{
+       int old_status = pt->status;
+
+       if (!pt->status)
+               pt->status = pt->parent->ops->has_signaled(pt);
+
+       if (!pt->status && pt->parent->destroyed)
+               pt->status = -ENOENT;
+
+       if (pt->status != old_status)
+               pt->timestamp = ktime_get();
+
+       return pt->status;
+}
+
+static struct sync_pt *sync_pt_dup(struct sync_pt *pt)
+{
+       return pt->parent->ops->dup(pt);
+}
+
+/* Adds a sync pt to the active queue.  Called when added to a fence */
+static void sync_pt_activate(struct sync_pt *pt)
+{
+       struct sync_timeline *obj = pt->parent;
+       unsigned long flags;
+       int err;
+
+       spin_lock_irqsave(&obj->active_list_lock, flags);
+
+       err = _sync_pt_has_signaled(pt);
+       if (err != 0)
+               goto out;
+
+       list_add_tail(&pt->active_list, &obj->active_list_head);
+
+out:
+       spin_unlock_irqrestore(&obj->active_list_lock, flags);
+}
+
+static int sync_fence_release(struct inode *inode, struct file *file);
+static unsigned int sync_fence_poll(struct file *file, poll_table *wait);
+static long sync_fence_ioctl(struct file *file, unsigned int cmd,
+                            unsigned long arg);
+
+
+static const struct file_operations sync_fence_fops = {
+       .release = sync_fence_release,
+       .poll = sync_fence_poll,
+       .unlocked_ioctl = sync_fence_ioctl,
+       .compat_ioctl = sync_fence_ioctl,
+};
+
+static struct sync_fence *sync_fence_alloc(const char *name)
+{
+       struct sync_fence *fence;
+       unsigned long flags;
+
+       fence = kzalloc(sizeof(struct sync_fence), GFP_KERNEL);
+       if (fence == NULL)
+               return NULL;
+
+       fence->file = anon_inode_getfile("sync_fence", &sync_fence_fops,
+                                        fence, 0);
+       if (IS_ERR(fence->file))
+               goto err;
+
+       kref_init(&fence->kref);
+       strlcpy(fence->name, name, sizeof(fence->name));
+
+       INIT_LIST_HEAD(&fence->pt_list_head);
+       INIT_LIST_HEAD(&fence->waiter_list_head);
+       spin_lock_init(&fence->waiter_list_lock);
+
+       init_waitqueue_head(&fence->wq);
+
+       spin_lock_irqsave(&sync_fence_list_lock, flags);
+       list_add_tail(&fence->sync_fence_list, &sync_fence_list_head);
+       spin_unlock_irqrestore(&sync_fence_list_lock, flags);
+
+       return fence;
+
+err:
+       kfree(fence);
+       return NULL;
+}
+
+/* TODO: implement a create which takes more that one sync_pt */
+struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt)
+{
+       struct sync_fence *fence;
+
+       if (pt->fence)
+               return NULL;
+
+       fence = sync_fence_alloc(name);
+       if (fence == NULL)
+               return NULL;
+
+       pt->fence = fence;
+       list_add(&pt->pt_list, &fence->pt_list_head);
+       sync_pt_activate(pt);
+
+       /*
+        * signal the fence in case pt was activated before
+        * sync_pt_activate(pt) was called
+        */
+       sync_fence_signal_pt(pt);
+
+       return fence;
+}
+EXPORT_SYMBOL(sync_fence_create);
+
+static int sync_fence_copy_pts(struct sync_fence *dst, struct sync_fence *src)
+{
+       struct list_head *pos;
+
+       list_for_each(pos, &src->pt_list_head) {
+               struct sync_pt *orig_pt =
+                       container_of(pos, struct sync_pt, pt_list);
+               struct sync_pt *new_pt = sync_pt_dup(orig_pt);
+
+               if (new_pt == NULL)
+                       return -ENOMEM;
+
+               new_pt->fence = dst;
+               list_add(&new_pt->pt_list, &dst->pt_list_head);
+       }
+
+       return 0;
+}
+
+static int sync_fence_merge_pts(struct sync_fence *dst, struct sync_fence *src)
+{
+       struct list_head *src_pos, *dst_pos, *n;
+
+       list_for_each(src_pos, &src->pt_list_head) {
+               struct sync_pt *src_pt =
+                       container_of(src_pos, struct sync_pt, pt_list);
+               bool collapsed = false;
+
+               list_for_each_safe(dst_pos, n, &dst->pt_list_head) {
+                       struct sync_pt *dst_pt =
+                               container_of(dst_pos, struct sync_pt, pt_list);
+                       /* collapse two sync_pts on the same timeline
+                        * to a single sync_pt that will signal at
+                        * the later of the two
+                        */
+                       if (dst_pt->parent == src_pt->parent) {
+                               if (dst_pt->parent->ops->compare(dst_pt, src_pt)
+                                                == -1) {
+                                       struct sync_pt *new_pt =
+                                               sync_pt_dup(src_pt);
+                                       if (new_pt == NULL)
+                                               return -ENOMEM;
+
+                                       new_pt->fence = dst;
+                                       list_replace(&dst_pt->pt_list,
+                                                    &new_pt->pt_list);
+                                       sync_pt_free(dst_pt);
+                               }
+                               collapsed = true;
+                               break;
+                       }
+               }
+
+               if (!collapsed) {
+                       struct sync_pt *new_pt = sync_pt_dup(src_pt);
+
+                       if (new_pt == NULL)
+                               return -ENOMEM;
+
+                       new_pt->fence = dst;
+                       list_add(&new_pt->pt_list, &dst->pt_list_head);
+               }
+       }
+
+       return 0;
+}
+
+static void sync_fence_detach_pts(struct sync_fence *fence)
+{
+       struct list_head *pos, *n;
+
+       list_for_each_safe(pos, n, &fence->pt_list_head) {
+               struct sync_pt *pt = container_of(pos, struct sync_pt, pt_list);
+               sync_timeline_remove_pt(pt);
+       }
+}
+
+static void sync_fence_free_pts(struct sync_fence *fence)
+{
+       struct list_head *pos, *n;
+
+       list_for_each_safe(pos, n, &fence->pt_list_head) {
+               struct sync_pt *pt = container_of(pos, struct sync_pt, pt_list);
+               sync_pt_free(pt);
+       }
+}
+
+struct sync_fence *sync_fence_fdget(int fd)
+{
+       struct file *file = fget(fd);
+
+       if (file == NULL)
+               return NULL;
+
+       if (file->f_op != &sync_fence_fops)
+               goto err;
+
+       return file->private_data;
+
+err:
+       fput(file);
+       return NULL;
+}
+EXPORT_SYMBOL(sync_fence_fdget);
+
+void sync_fence_put(struct sync_fence *fence)
+{
+       fput(fence->file);
+}
+EXPORT_SYMBOL(sync_fence_put);
+
+void sync_fence_install(struct sync_fence *fence, int fd)
+{
+       fd_install(fd, fence->file);
+}
+EXPORT_SYMBOL(sync_fence_install);
+
+static int sync_fence_get_status(struct sync_fence *fence)
+{
+       struct list_head *pos;
+       int status = 1;
+
+       list_for_each(pos, &fence->pt_list_head) {
+               struct sync_pt *pt = container_of(pos, struct sync_pt, pt_list);
+               int pt_status = pt->status;
+
+               if (pt_status < 0) {
+                       status = pt_status;
+                       break;
+               } else if (status == 1) {
+                       status = pt_status;
+               }
+       }
+
+       return status;
+}
+
+struct sync_fence *sync_fence_merge(const char *name,
+                                   struct sync_fence *a, struct sync_fence *b)
+{
+       struct sync_fence *fence;
+       struct list_head *pos;
+       int err;
+
+       fence = sync_fence_alloc(name);
+       if (fence == NULL)
+               return NULL;
+
+       err = sync_fence_copy_pts(fence, a);
+       if (err < 0)
+               goto err;
+
+       err = sync_fence_merge_pts(fence, b);
+       if (err < 0)
+               goto err;
+
+       list_for_each(pos, &fence->pt_list_head) {
+               struct sync_pt *pt =
+                       container_of(pos, struct sync_pt, pt_list);
+               sync_pt_activate(pt);
+       }
+
+       /*
+        * signal the fence in case one of it's pts were activated before
+        * they were activated
+        */
+       sync_fence_signal_pt(list_first_entry(&fence->pt_list_head,
+                                             struct sync_pt,
+                                             pt_list));
+
+       return fence;
+err:
+       sync_fence_free_pts(fence);
+       kfree(fence);
+       return NULL;
+}
+EXPORT_SYMBOL(sync_fence_merge);
+
+static void sync_fence_signal_pt(struct sync_pt *pt)
+{
+       LIST_HEAD(signaled_waiters);
+       struct sync_fence *fence = pt->fence;
+       struct list_head *pos;
+       struct list_head *n;
+       unsigned long flags;
+       int status;
+
+       status = sync_fence_get_status(fence);
+
+       spin_lock_irqsave(&fence->waiter_list_lock, flags);
+       /*
+        * this should protect against two threads racing on the signaled
+        * false -> true transition
+        */
+       if (status && !fence->status) {
+               list_for_each_safe(pos, n, &fence->waiter_list_head)
+                       list_move(pos, &signaled_waiters);
+
+               fence->status = status;
+       } else {
+               status = 0;
+       }
+       spin_unlock_irqrestore(&fence->waiter_list_lock, flags);
+
+       if (status) {
+               list_for_each_safe(pos, n, &signaled_waiters) {
+                       struct sync_fence_waiter *waiter =
+                               container_of(pos, struct sync_fence_waiter,
+                                            waiter_list);
+
+                       list_del(pos);
+                       waiter->callback(fence, waiter);
+               }
+               wake_up(&fence->wq);
+       }
+}
+
+int sync_fence_wait_async(struct sync_fence *fence,
+                         struct sync_fence_waiter *waiter)
+{
+       unsigned long flags;
+       int err = 0;
+
+       spin_lock_irqsave(&fence->waiter_list_lock, flags);
+
+       if (fence->status) {
+               err = fence->status;
+               goto out;
+       }
+
+       list_add_tail(&waiter->waiter_list, &fence->waiter_list_head);
+out:
+       spin_unlock_irqrestore(&fence->waiter_list_lock, flags);
+
+       return err;
+}
+EXPORT_SYMBOL(sync_fence_wait_async);
+
+int sync_fence_cancel_async(struct sync_fence *fence,
+                            struct sync_fence_waiter *waiter)
+{
+       struct list_head *pos;
+       struct list_head *n;
+       unsigned long flags;
+       int ret = -ENOENT;
+
+       spin_lock_irqsave(&fence->waiter_list_lock, flags);
+       /*
+        * Make sure waiter is still in waiter_list because it is possible for
+        * the waiter to be removed from the list while the callback is still
+        * pending.
+        */
+       list_for_each_safe(pos, n, &fence->waiter_list_head) {
+               struct sync_fence_waiter *list_waiter =
+                       container_of(pos, struct sync_fence_waiter,
+                                    waiter_list);
+               if (list_waiter == waiter) {
+                       list_del(pos);
+                       ret = 0;
+                       break;
+               }
+       }
+       spin_unlock_irqrestore(&fence->waiter_list_lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(sync_fence_cancel_async);
+
+static bool sync_fence_check(struct sync_fence *fence)
+{
+       /*
+        * Make sure that reads to fence->status are ordered with the
+        * wait queue event triggering
+        */
+       smp_rmb();
+       return fence->status != 0;
+}
+
+int sync_fence_wait(struct sync_fence *fence, long timeout)
+{
+       int err = 0;
+       struct sync_pt *pt;
+
+       trace_sync_wait(fence, 1);
+       list_for_each_entry(pt, &fence->pt_list_head, pt_list)
+               trace_sync_pt(pt);
+
+       if (timeout > 0) {
+               timeout = msecs_to_jiffies(timeout);
+               err = wait_event_interruptible_timeout(fence->wq,
+                                                      sync_fence_check(fence),
+                                                      timeout);
+       } else if (timeout < 0) {
+               err = wait_event_interruptible(fence->wq,
+                                              sync_fence_check(fence));
+       }
+       trace_sync_wait(fence, 0);
+
+       if (err < 0)
+               return err;
+
+       if (fence->status < 0) {
+               pr_info("fence error %d on [%p]\n", fence->status, fence);
+               sync_dump();
+               return fence->status;
+       }
+
+       if (fence->status == 0) {
+               if (timeout > 0) {
+                       pr_info("fence timeout on [%p] after %dms\n", fence,
+                               jiffies_to_msecs(timeout));
+                       sync_dump();
+               }
+               return -ETIME;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(sync_fence_wait);
+
+static void sync_fence_free(struct kref *kref)
+{
+       struct sync_fence *fence = container_of(kref, struct sync_fence, kref);
+
+       sync_fence_free_pts(fence);
+
+       kfree(fence);
+}
+
+static int sync_fence_release(struct inode *inode, struct file *file)
+{
+       struct sync_fence *fence = file->private_data;
+       unsigned long flags;
+
+       /*
+        * We need to remove all ways to access this fence before droping
+        * our ref.
+        *
+        * start with its membership in the global fence list
+        */
+       spin_lock_irqsave(&sync_fence_list_lock, flags);
+       list_del(&fence->sync_fence_list);
+       spin_unlock_irqrestore(&sync_fence_list_lock, flags);
+
+       /*
+        * remove its pts from their parents so that sync_timeline_signal()
+        * can't reference the fence.
+        */
+       sync_fence_detach_pts(fence);
+
+       kref_put(&fence->kref, sync_fence_free);
+
+       return 0;
+}
+
+static unsigned int sync_fence_poll(struct file *file, poll_table *wait)
+{
+       struct sync_fence *fence = file->private_data;
+
+       poll_wait(file, &fence->wq, wait);
+
+       /*
+        * Make sure that reads to fence->status are ordered with the
+        * wait queue event triggering
+        */
+       smp_rmb();
+
+       if (fence->status == 1)
+               return POLLIN;
+       else if (fence->status < 0)
+               return POLLERR;
+       else
+               return 0;
+}
+
+static long sync_fence_ioctl_wait(struct sync_fence *fence, unsigned long arg)
+{
+       __s32 value;
+
+       if (copy_from_user(&value, (void __user *)arg, sizeof(value)))
+               return -EFAULT;
+
+       return sync_fence_wait(fence, value);
+}
+
+static long sync_fence_ioctl_merge(struct sync_fence *fence, unsigned long arg)
+{
+       int fd = get_unused_fd();
+       int err;
+       struct sync_fence *fence2, *fence3;
+       struct sync_merge_data data;
+
+       if (fd < 0)
+               return fd;
+
+       if (copy_from_user(&data, (void __user *)arg, sizeof(data))) {
+               err = -EFAULT;
+               goto err_put_fd;
+       }
+
+       fence2 = sync_fence_fdget(data.fd2);
+       if (fence2 == NULL) {
+               err = -ENOENT;
+               goto err_put_fd;
+       }
+
+       data.name[sizeof(data.name) - 1] = '\0';
+       fence3 = sync_fence_merge(data.name, fence, fence2);
+       if (fence3 == NULL) {
+               err = -ENOMEM;
+               goto err_put_fence2;
+       }
+
+       data.fence = fd;
+       if (copy_to_user((void __user *)arg, &data, sizeof(data))) {
+               err = -EFAULT;
+               goto err_put_fence3;
+       }
+
+       sync_fence_install(fence3, fd);
+       sync_fence_put(fence2);
+       return 0;
+
+err_put_fence3:
+       sync_fence_put(fence3);
+
+err_put_fence2:
+       sync_fence_put(fence2);
+
+err_put_fd:
+       put_unused_fd(fd);
+       return err;
+}
+
+static int sync_fill_pt_info(struct sync_pt *pt, void *data, int size)
+{
+       struct sync_pt_info *info = data;
+       int ret;
+
+       if (size < sizeof(struct sync_pt_info))
+               return -ENOMEM;
+
+       info->len = sizeof(struct sync_pt_info);
+
+       if (pt->parent->ops->fill_driver_data) {
+               ret = pt->parent->ops->fill_driver_data(pt, info->driver_data,
+                                                       size - sizeof(*info));
+               if (ret < 0)
+                       return ret;
+
+               info->len += ret;
+       }
+
+       strlcpy(info->obj_name, pt->parent->name, sizeof(info->obj_name));
+       strlcpy(info->driver_name, pt->parent->ops->driver_name,
+               sizeof(info->driver_name));
+       info->status = pt->status;
+       info->timestamp_ns = ktime_to_ns(pt->timestamp);
+
+       return info->len;
+}
+
+static long sync_fence_ioctl_fence_info(struct sync_fence *fence,
+                                       unsigned long arg)
+{
+       struct sync_fence_info_data *data;
+       struct list_head *pos;
+       __u32 size;
+       __u32 len = 0;
+       int ret;
+
+       if (copy_from_user(&size, (void __user *)arg, sizeof(size)))
+               return -EFAULT;
+
+       if (size < sizeof(struct sync_fence_info_data))
+               return -EINVAL;
+
+       if (size > 4096)
+               size = 4096;
+
+       data = kzalloc(size, GFP_KERNEL);
+       if (data == NULL)
+               return -ENOMEM;
+
+       strlcpy(data->name, fence->name, sizeof(data->name));
+       data->status = fence->status;
+       len = sizeof(struct sync_fence_info_data);
+
+       list_for_each(pos, &fence->pt_list_head) {
+               struct sync_pt *pt =
+                       container_of(pos, struct sync_pt, pt_list);
+
+               ret = sync_fill_pt_info(pt, (u8 *)data + len, size - len);
+
+               if (ret < 0)
+                       goto out;
+
+               len += ret;
+       }
+
+       data->len = len;
+
+       if (copy_to_user((void __user *)arg, data, len))
+               ret = -EFAULT;
+       else
+               ret = 0;
+
+out:
+       kfree(data);
+
+       return ret;
+}
+
+static long sync_fence_ioctl(struct file *file, unsigned int cmd,
+                            unsigned long arg)
+{
+       struct sync_fence *fence = file->private_data;
+       switch (cmd) {
+       case SYNC_IOC_WAIT:
+               return sync_fence_ioctl_wait(fence, arg);
+
+       case SYNC_IOC_MERGE:
+               return sync_fence_ioctl_merge(fence, arg);
+
+       case SYNC_IOC_FENCE_INFO:
+               return sync_fence_ioctl_fence_info(fence, arg);
+
+       default:
+               return -ENOTTY;
+       }
+}
+
+#ifdef CONFIG_DEBUG_FS
+static const char *sync_status_str(int status)
+{
+       if (status > 0)
+               return "signaled";
+       else if (status == 0)
+               return "active";
+       else
+               return "error";
+}
+
+static void sync_print_pt(struct seq_file *s, struct sync_pt *pt, bool fence)
+{
+       int status = pt->status;
+       seq_printf(s, "  %s%spt %s",
+                  fence ? pt->parent->name : "",
+                  fence ? "_" : "",
+                  sync_status_str(status));
+       if (pt->status) {
+               struct timeval tv = ktime_to_timeval(pt->timestamp);
+               seq_printf(s, "@%ld.%06ld", tv.tv_sec, tv.tv_usec);
+       }
+
+       if (pt->parent->ops->timeline_value_str &&
+           pt->parent->ops->pt_value_str) {
+               char value[64];
+               pt->parent->ops->pt_value_str(pt, value, sizeof(value));
+               seq_printf(s, ": %s", value);
+               if (fence) {
+                       pt->parent->ops->timeline_value_str(pt->parent, value,
+                                                   sizeof(value));
+                       seq_printf(s, " / %s", value);
+               }
+       } else if (pt->parent->ops->print_pt) {
+               seq_printf(s, ": ");
+               pt->parent->ops->print_pt(s, pt);
+       }
+
+       seq_printf(s, "\n");
+}
+
+static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj)
+{
+       struct list_head *pos;
+       unsigned long flags;
+
+       seq_printf(s, "%s %s", obj->name, obj->ops->driver_name);
+
+       if (obj->ops->timeline_value_str) {
+               char value[64];
+               obj->ops->timeline_value_str(obj, value, sizeof(value));
+               seq_printf(s, ": %s", value);
+       } else if (obj->ops->print_obj) {
+               seq_printf(s, ": ");
+               obj->ops->print_obj(s, obj);
+       }
+
+       seq_printf(s, "\n");
+
+       spin_lock_irqsave(&obj->child_list_lock, flags);
+       list_for_each(pos, &obj->child_list_head) {
+               struct sync_pt *pt =
+                       container_of(pos, struct sync_pt, child_list);
+               sync_print_pt(s, pt, false);
+       }
+       spin_unlock_irqrestore(&obj->child_list_lock, flags);
+}
+
+static void sync_print_fence(struct seq_file *s, struct sync_fence *fence)
+{
+       struct list_head *pos;
+       unsigned long flags;
+
+       seq_printf(s, "[%p] %s: %s\n", fence, fence->name,
+                  sync_status_str(fence->status));
+
+       list_for_each(pos, &fence->pt_list_head) {
+               struct sync_pt *pt =
+                       container_of(pos, struct sync_pt, pt_list);
+               sync_print_pt(s, pt, true);
+       }
+
+       spin_lock_irqsave(&fence->waiter_list_lock, flags);
+       list_for_each(pos, &fence->waiter_list_head) {
+               struct sync_fence_waiter *waiter =
+                       container_of(pos, struct sync_fence_waiter,
+                                    waiter_list);
+
+               seq_printf(s, "waiter %pF\n", waiter->callback);
+       }
+       spin_unlock_irqrestore(&fence->waiter_list_lock, flags);
+}
+
+static int sync_debugfs_show(struct seq_file *s, void *unused)
+{
+       unsigned long flags;
+       struct list_head *pos;
+
+       seq_printf(s, "objs:\n--------------\n");
+
+       spin_lock_irqsave(&sync_timeline_list_lock, flags);
+       list_for_each(pos, &sync_timeline_list_head) {
+               struct sync_timeline *obj =
+                       container_of(pos, struct sync_timeline,
+                                    sync_timeline_list);
+
+               sync_print_obj(s, obj);
+               seq_printf(s, "\n");
+       }
+       spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
+
+       seq_printf(s, "fences:\n--------------\n");
+
+       spin_lock_irqsave(&sync_fence_list_lock, flags);
+       list_for_each(pos, &sync_fence_list_head) {
+               struct sync_fence *fence =
+                       container_of(pos, struct sync_fence, sync_fence_list);
+
+               sync_print_fence(s, fence);
+               seq_printf(s, "\n");
+       }
+       spin_unlock_irqrestore(&sync_fence_list_lock, flags);
+       return 0;
+}
+
+static int sync_debugfs_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, sync_debugfs_show, inode->i_private);
+}
+
+static const struct file_operations sync_debugfs_fops = {
+       .open           = sync_debugfs_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static __init int sync_debugfs_init(void)
+{
+       debugfs_create_file("sync", S_IRUGO, NULL, NULL, &sync_debugfs_fops);
+       return 0;
+}
+late_initcall(sync_debugfs_init);
+
+#define DUMP_CHUNK 256
+static char sync_dump_buf[64 * 1024];
+void sync_dump(void)
+{
+       struct seq_file s = {
+               .buf = sync_dump_buf,
+               .size = sizeof(sync_dump_buf) - 1,
+       };
+       int i;
+
+       sync_debugfs_show(&s, NULL);
+
+       for (i = 0; i < s.count; i += DUMP_CHUNK) {
+               if ((s.count - i) > DUMP_CHUNK) {
+                       char c = s.buf[i + DUMP_CHUNK];
+                       s.buf[i + DUMP_CHUNK] = 0;
+                       pr_cont("%s", s.buf + i);
+                       s.buf[i + DUMP_CHUNK] = c;
+               } else {
+                       s.buf[s.count] = 0;
+                       pr_cont("%s", s.buf + i);
+               }
+       }
+}
+#else
+static void sync_dump(void)
+{
+}
+#endif
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
new file mode 100644 (file)
index 0000000..38ea986
--- /dev/null
@@ -0,0 +1,426 @@
+/*
+ * include/linux/sync.h
+ *
+ * Copyright (C) 2012 Google, Inc.
+ *
+ * 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 _LINUX_SYNC_H
+#define _LINUX_SYNC_H
+
+#include <linux/types.h>
+#ifdef __KERNEL__
+
+#include <linux/kref.h>
+#include <linux/ktime.h>
+#include <linux/list.h>
+#include <linux/spinlock.h>
+#include <linux/wait.h>
+
+struct sync_timeline;
+struct sync_pt;
+struct sync_fence;
+
+/**
+ * struct sync_timeline_ops - sync object implementation ops
+ * @driver_name:       name of the implentation
+ * @dup:               duplicate a sync_pt
+ * @has_signaled:      returns:
+ *                       1 if pt has signaled
+ *                       0 if pt has not signaled
+ *                      <0 on error
+ * @compare:           returns:
+ *                       1 if b will signal before a
+ *                       0 if a and b will signal at the same time
+ *                      -1 if a will signabl before b
+ * @free_pt:           called before sync_pt is freed
+ * @release_obj:       called before sync_timeline is freed
+ * @print_obj:         deprecated
+ * @print_pt:          deprecated
+ * @fill_driver_data:  write implmentation specific driver data to data.
+ *                       should return an error if there is not enough room
+ *                       as specified by size.  This information is returned
+ *                       to userspace by SYNC_IOC_FENCE_INFO.
+ * @timeline_value_str: fill str with the value of the sync_timeline's counter
+ * @pt_value_str:      fill str with the value of the sync_pt
+ */
+struct sync_timeline_ops {
+       const char *driver_name;
+
+       /* required */
+       struct sync_pt *(*dup)(struct sync_pt *pt);
+
+       /* required */
+       int (*has_signaled)(struct sync_pt *pt);
+
+       /* required */
+       int (*compare)(struct sync_pt *a, struct sync_pt *b);
+
+       /* optional */
+       void (*free_pt)(struct sync_pt *sync_pt);
+
+       /* optional */
+       void (*release_obj)(struct sync_timeline *sync_timeline);
+
+       /* deprecated */
+       void (*print_obj)(struct seq_file *s,
+                         struct sync_timeline *sync_timeline);
+
+       /* deprecated */
+       void (*print_pt)(struct seq_file *s, struct sync_pt *sync_pt);
+
+       /* optional */
+       int (*fill_driver_data)(struct sync_pt *syncpt, void *data, int size);
+
+       /* optional */
+       void (*timeline_value_str)(struct sync_timeline *timeline, char *str,
+                                  int size);
+
+       /* optional */
+       void (*pt_value_str)(struct sync_pt *pt, char *str, int size);
+};
+
+/**
+ * struct sync_timeline - sync object
+ * @kref:              reference count on fence.
+ * @ops:               ops that define the implementaiton of the sync_timeline
+ * @name:              name of the sync_timeline. Useful for debugging
+ * @destoryed:         set when sync_timeline is destroyed
+ * @child_list_head:   list of children sync_pts for this sync_timeline
+ * @child_list_lock:   lock protecting @child_list_head, destroyed, and
+ *                       sync_pt.status
+ * @active_list_head:  list of active (unsignaled/errored) sync_pts
+ * @sync_timeline_list:        membership in global sync_timeline_list
+ */
+struct sync_timeline {
+       struct kref             kref;
+       const struct sync_timeline_ops  *ops;
+       char                    name[32];
+
+       /* protected by child_list_lock */
+       bool                    destroyed;
+
+       struct list_head        child_list_head;
+       spinlock_t              child_list_lock;
+
+       struct list_head        active_list_head;
+       spinlock_t              active_list_lock;
+
+       struct list_head        sync_timeline_list;
+};
+
+/**
+ * struct sync_pt - sync point
+ * @parent:            sync_timeline to which this sync_pt belongs
+ * @child_list:                membership in sync_timeline.child_list_head
+ * @active_list:       membership in sync_timeline.active_list_head
+ * @signaled_list:     membership in temorary signaled_list on stack
+ * @fence:             sync_fence to which the sync_pt belongs
+ * @pt_list:           membership in sync_fence.pt_list_head
+ * @status:            1: signaled, 0:active, <0: error
+ * @timestamp:         time which sync_pt status transitioned from active to
+ *                       singaled or error.
+ */
+struct sync_pt {
+       struct sync_timeline            *parent;
+       struct list_head        child_list;
+
+       struct list_head        active_list;
+       struct list_head        signaled_list;
+
+       struct sync_fence       *fence;
+       struct list_head        pt_list;
+
+       /* protected by parent->active_list_lock */
+       int                     status;
+
+       ktime_t                 timestamp;
+};
+
+/**
+ * struct sync_fence - sync fence
+ * @file:              file representing this fence
+ * @kref:              referenace count on fence.
+ * @name:              name of sync_fence.  Useful for debugging
+ * @pt_list_head:      list of sync_pts in ths fence.  immutable once fence
+ *                       is created
+ * @waiter_list_head:  list of asynchronous waiters on this fence
+ * @waiter_list_lock:  lock protecting @waiter_list_head and @status
+ * @status:            1: signaled, 0:active, <0: error
+ *
+ * @wq:                        wait queue for fence signaling
+ * @sync_fence_list:   membership in global fence list
+ */
+struct sync_fence {
+       struct file             *file;
+       struct kref             kref;
+       char                    name[32];
+
+       /* this list is immutable once the fence is created */
+       struct list_head        pt_list_head;
+
+       struct list_head        waiter_list_head;
+       spinlock_t              waiter_list_lock; /* also protects status */
+       int                     status;
+
+       wait_queue_head_t       wq;
+
+       struct list_head        sync_fence_list;
+};
+
+struct sync_fence_waiter;
+typedef void (*sync_callback_t)(struct sync_fence *fence,
+                               struct sync_fence_waiter *waiter);
+
+/**
+ * struct sync_fence_waiter - metadata for asynchronous waiter on a fence
+ * @waiter_list:       membership in sync_fence.waiter_list_head
+ * @callback:          function pointer to call when fence signals
+ * @callback_data:     pointer to pass to @callback
+ */
+struct sync_fence_waiter {
+       struct list_head        waiter_list;
+
+       sync_callback_t         callback;
+};
+
+static inline void sync_fence_waiter_init(struct sync_fence_waiter *waiter,
+                                         sync_callback_t callback)
+{
+       waiter->callback = callback;
+}
+
+/*
+ * API for sync_timeline implementers
+ */
+
+/**
+ * sync_timeline_create() - creates a sync object
+ * @ops:       specifies the implemention ops for the object
+ * @size:      size to allocate for this obj
+ * @name:      sync_timeline name
+ *
+ * Creates a new sync_timeline which will use the implemetation specified by
+ * @ops.  @size bytes will be allocated allowing for implemntation specific
+ * data to be kept after the generic sync_timeline stuct.
+ */
+struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
+                                          int size, const char *name);
+
+/**
+ * sync_timeline_destory() - destorys a sync object
+ * @obj:       sync_timeline to destroy
+ *
+ * A sync implemntation should call this when the @obj is going away
+ * (i.e. module unload.)  @obj won't actually be freed until all its childern
+ * sync_pts are freed.
+ */
+void sync_timeline_destroy(struct sync_timeline *obj);
+
+/**
+ * sync_timeline_signal() - signal a status change on a sync_timeline
+ * @obj:       sync_timeline to signal
+ *
+ * A sync implemntation should call this any time one of it's sync_pts
+ * has signaled or has an error condition.
+ */
+void sync_timeline_signal(struct sync_timeline *obj);
+
+/**
+ * sync_pt_create() - creates a sync pt
+ * @parent:    sync_pt's parent sync_timeline
+ * @size:      size to allocate for this pt
+ *
+ * Creates a new sync_pt as a chiled of @parent.  @size bytes will be
+ * allocated allowing for implemntation specific data to be kept after
+ * the generic sync_timeline struct.
+ */
+struct sync_pt *sync_pt_create(struct sync_timeline *parent, int size);
+
+/**
+ * sync_pt_free() - frees a sync pt
+ * @pt:                sync_pt to free
+ *
+ * This should only be called on sync_pts which have been created but
+ * not added to a fence.
+ */
+void sync_pt_free(struct sync_pt *pt);
+
+/**
+ * sync_fence_create() - creates a sync fence
+ * @name:      name of fence to create
+ * @pt:                sync_pt to add to the fence
+ *
+ * Creates a fence containg @pt.  Once this is called, the fence takes
+ * ownership of @pt.
+ */
+struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt);
+
+/*
+ * API for sync_fence consumers
+ */
+
+/**
+ * sync_fence_merge() - merge two fences
+ * @name:      name of new fence
+ * @a:         fence a
+ * @b:         fence b
+ *
+ * Creates a new fence which contains copies of all the sync_pts in both
+ * @a and @b.  @a and @b remain valid, independent fences.
+ */
+struct sync_fence *sync_fence_merge(const char *name,
+                                   struct sync_fence *a, struct sync_fence *b);
+
+/**
+ * sync_fence_fdget() - get a fence from an fd
+ * @fd:                fd referencing a fence
+ *
+ * Ensures @fd references a valid fence, increments the refcount of the backing
+ * file, and returns the fence.
+ */
+struct sync_fence *sync_fence_fdget(int fd);
+
+/**
+ * sync_fence_put() - puts a refernnce of a sync fence
+ * @fence:     fence to put
+ *
+ * Puts a reference on @fence.  If this is the last reference, the fence and
+ * all it's sync_pts will be freed
+ */
+void sync_fence_put(struct sync_fence *fence);
+
+/**
+ * sync_fence_install() - installs a fence into a file descriptor
+ * @fence:     fence to instal
+ * @fd:                file descriptor in which to install the fence
+ *
+ * Installs @fence into @fd.  @fd's should be acquired through get_unused_fd().
+ */
+void sync_fence_install(struct sync_fence *fence, int fd);
+
+/**
+ * sync_fence_wait_async() - registers and async wait on the fence
+ * @fence:             fence to wait on
+ * @waiter:            waiter callback struck
+ *
+ * Returns 1 if @fence has already signaled.
+ *
+ * Registers a callback to be called when @fence signals or has an error.
+ * @waiter should be initialized with sync_fence_waiter_init().
+ */
+int sync_fence_wait_async(struct sync_fence *fence,
+                         struct sync_fence_waiter *waiter);
+
+/**
+ * sync_fence_cancel_async() - cancels an async wait
+ * @fence:             fence to wait on
+ * @waiter:            waiter callback struck
+ *
+ * returns 0 if waiter was removed from fence's async waiter list.
+ * returns -ENOENT if waiter was not found on fence's async waiter list.
+ *
+ * Cancels a previously registered async wait.  Will fail gracefully if
+ * @waiter was never registered or if @fence has already signaled @waiter.
+ */
+int sync_fence_cancel_async(struct sync_fence *fence,
+                           struct sync_fence_waiter *waiter);
+
+/**
+ * sync_fence_wait() - wait on fence
+ * @fence:     fence to wait on
+ * @tiemout:   timeout in ms
+ *
+ * Wait for @fence to be signaled or have an error.  Waits indefinitely
+ * if @timeout < 0
+ */
+int sync_fence_wait(struct sync_fence *fence, long timeout);
+
+#endif /* __KERNEL__ */
+
+/**
+ * struct sync_merge_data - data passed to merge ioctl
+ * @fd2:       file descriptor of second fence
+ * @name:      name of new fence
+ * @fence:     returns the fd of the new fence to userspace
+ */
+struct sync_merge_data {
+       __s32   fd2; /* fd of second fence */
+       char    name[32]; /* name of new fence */
+       __s32   fence; /* fd on newly created fence */
+};
+
+/**
+ * struct sync_pt_info - detailed sync_pt information
+ * @len:               length of sync_pt_info including any driver_data
+ * @obj_name:          name of parent sync_timeline
+ * @driver_name:       name of driver implmenting the parent
+ * @status:            status of the sync_pt 0:active 1:signaled <0:error
+ * @timestamp_ns:      timestamp of status change in nanoseconds
+ * @driver_data:       any driver dependant data
+ */
+struct sync_pt_info {
+       __u32   len;
+       char    obj_name[32];
+       char    driver_name[32];
+       __s32   status;
+       __u64   timestamp_ns;
+
+       __u8    driver_data[0];
+};
+
+/**
+ * struct sync_fence_info_data - data returned from fence info ioctl
+ * @len:       ioctl caller writes the size of the buffer its passing in.
+ *             ioctl returns length of sync_fence_data reutnred to userspace
+ *             including pt_info.
+ * @name:      name of fence
+ * @status:    status of fence. 1: signaled 0:active <0:error
+ * @pt_info:   a sync_pt_info struct for every sync_pt in the fence
+ */
+struct sync_fence_info_data {
+       __u32   len;
+       char    name[32];
+       __s32   status;
+
+       __u8    pt_info[0];
+};
+
+#define SYNC_IOC_MAGIC         '>'
+
+/**
+ * DOC: SYNC_IOC_WAIT - wait for a fence to signal
+ *
+ * pass timeout in milliseconds.  Waits indefinitely timeout < 0.
+ */
+#define SYNC_IOC_WAIT          _IOW(SYNC_IOC_MAGIC, 0, __s32)
+
+/**
+ * DOC: SYNC_IOC_MERGE - merge two fences
+ *
+ * Takes a struct sync_merge_data.  Creates a new fence containing copies of
+ * the sync_pts in both the calling fd and sync_merge_data.fd2.  Returns the
+ * new fence's fd in sync_merge_data.fence
+ */
+#define SYNC_IOC_MERGE         _IOWR(SYNC_IOC_MAGIC, 1, struct sync_merge_data)
+
+/**
+ * DOC: SYNC_IOC_FENCE_INFO - get detailed information on a fence
+ *
+ * Takes a struct sync_fence_info_data with extra space allocated for pt_info.
+ * Caller should write the size of the buffer into len.  On return, len is
+ * updated to reflect the total size of the sync_fence_info_data including
+ * pt_info.
+ *
+ * pt_info is a buffer containing sync_pt_infos for every sync_pt in the fence.
+ * To itterate over the sync_pt_infos, use the sync_pt_info.len field.
+ */
+#define SYNC_IOC_FENCE_INFO    _IOWR(SYNC_IOC_MAGIC, 2,\
+       struct sync_fence_info_data)
+
+#endif /* _LINUX_SYNC_H */
diff --git a/drivers/staging/android/trace/sync.h b/drivers/staging/android/trace/sync.h
new file mode 100644 (file)
index 0000000..9546235
--- /dev/null
@@ -0,0 +1,82 @@
+#undef TRACE_SYSTEM
+#define TRACE_INCLUDE_PATH ../../drivers/staging/android/trace
+#define TRACE_SYSTEM sync
+
+#if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_SYNC_H
+
+#include "../sync.h"
+#include <linux/tracepoint.h>
+
+TRACE_EVENT(sync_timeline,
+       TP_PROTO(struct sync_timeline *timeline),
+
+       TP_ARGS(timeline),
+
+       TP_STRUCT__entry(
+                       __string(name, timeline->name)
+                       __array(char, value, 32)
+       ),
+
+       TP_fast_assign(
+                       __assign_str(name, timeline->name);
+                       if (timeline->ops->timeline_value_str) {
+                               timeline->ops->timeline_value_str(timeline,
+                                                       __entry->value,
+                                                       sizeof(__entry->value));
+                       } else {
+                               __entry->value[0] = '\0';
+                       }
+       ),
+
+       TP_printk("name=%s value=%s", __get_str(name), __entry->value)
+);
+
+TRACE_EVENT(sync_wait,
+       TP_PROTO(struct sync_fence *fence, int begin),
+
+       TP_ARGS(fence, begin),
+
+       TP_STRUCT__entry(
+                       __string(name, fence->name)
+                       __field(s32, status)
+                       __field(u32, begin)
+       ),
+
+       TP_fast_assign(
+                       __assign_str(name, fence->name);
+                       __entry->status = fence->status;
+                       __entry->begin = begin;
+       ),
+
+       TP_printk("%s name=%s state=%d", __entry->begin ? "begin" : "end",
+                       __get_str(name), __entry->status)
+);
+
+TRACE_EVENT(sync_pt,
+       TP_PROTO(struct sync_pt *pt),
+
+       TP_ARGS(pt),
+
+       TP_STRUCT__entry(
+               __string(timeline, pt->parent->name)
+               __array(char, value, 32)
+       ),
+
+       TP_fast_assign(
+               __assign_str(timeline, pt->parent->name);
+               if (pt->parent->ops->pt_value_str) {
+                       pt->parent->ops->pt_value_str(pt, __entry->value,
+                                                       sizeof(__entry->value));
+               } else {
+                       __entry->value[0] = '\0';
+               }
+       ),
+
+       TP_printk("name=%s value=%s", __get_str(timeline), __entry->value)
+);
+
+#endif /* if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
index 491e2bfbc46487a51cbb4e62ef71613876b0cddb..35641e529396759d5e7c860457155b28fde21f94 100644 (file)
@@ -1148,8 +1148,8 @@ cntrlEnd:
 
                if (((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
                        ((ULONG)pBulkBuffer->Register & 0x3)) {
-                       kfree(pvBuffer);
                        BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)pBulkBuffer->Register);
+                       kfree(pvBuffer);
                        Status = -EINVAL;
                        break;
                }
index 64ea6edb9dc2b8c39c260ee9eeb204aead27afc3..348ad75b340dddcda08338d1c2f90a1a5e900001 100644 (file)
@@ -205,30 +205,6 @@ static int bcm_download_config_file(struct bcm_mini_adapter *Adapter, struct bcm
        return retval;
 }
 
-static int bcm_compare_buff_contents(unsigned char *readbackbuff, unsigned char *buff, unsigned int len)
-{
-       int retval = STATUS_SUCCESS;
-       struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
-       if ((len-sizeof(unsigned int)) < 4) {
-               if (memcmp(readbackbuff , buff, len))
-                       retval = -EINVAL;
-       } else {
-               len -= 4;
-
-               while (len) {
-                       if (*(unsigned int *)&readbackbuff[len] != *(unsigned int *)&buff[len]) {
-                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Firmware Download is not proper");
-                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Val from Binary %x, Val From Read Back %x ", *(unsigned int *)&buff[len], *(unsigned int*)&readbackbuff[len]);
-                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "len =%x!!!", len);
-                               retval = -EINVAL;
-                               break;
-                       }
-                       len -= 4;
-               }
-       }
-       return retval;
-}
-
 int bcm_ioctl_fw_download(struct bcm_mini_adapter *Adapter, struct bcm_firmware_info *psFwInfo)
 {
        int retval = STATUS_SUCCESS;
@@ -321,9 +297,11 @@ static INT buffRdbkVerify(struct bcm_mini_adapter *Adapter, PUCHAR mappedbuffer,
                        break;
                }
 
-               retval = bcm_compare_buff_contents(readbackbuff, mappedbuffer, len);
-               if (STATUS_SUCCESS != retval)
-                       break;
+               if (memcmp(readbackbuff, mappedbuffer, len) != 0) {
+                       pr_err("%s() failed.  The firmware doesn't match what was written",
+                              __func__);
+                       retval = -EIO;
+               }
 
                u32StartingAddress += len;
                u32FirmwareLength -= len;
index 7028bc95b4f9413933d66a7717a7a89235e879aa..af5d22faa7f03c5a787d0cb054d8f5c50f2143a8 100644 (file)
 #include "headers.h"
 
-static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16  uiClsId, struct bcm_phs_table *psServiceFlowTable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI);
+static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid, B_UINT16 uiClsId, struct bcm_phs_table *psServiceFlowTable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI);
 
-static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16  uiClsId, struct bcm_phs_entry *pstServiceFlowEntry, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI);
+static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid, B_UINT16  uiClsId, struct bcm_phs_entry *pstServiceFlowEntry, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI);
 
-static UINT CreateClassifierPHSRule(B_UINT16  uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule, enum bcm_phs_classifier_context eClsContext,B_UINT8 u8AssociatedPHSI);
+static UINT CreateClassifierPHSRule(B_UINT16  uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule, enum bcm_phs_classifier_context eClsContext, B_UINT8 u8AssociatedPHSI);
 
-static UINT UpdateClassifierPHSRule(B_UINT16  uiClsId, struct bcm_phs_classifier_entry *pstClassifierEntry, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI);
+static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId, struct bcm_phs_classifier_entry *pstClassifierEntry, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI);
 
 static BOOLEAN ValidatePHSRuleComplete(struct bcm_phs_rule *psPhsRule);
 
-static BOOLEAN DerefPhsRule(B_UINT16  uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *pstPhsRule);
+static BOOLEAN DerefPhsRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *pstPhsRule);
 
-static UINT GetClassifierEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_classifier_entry **ppstClassifierEntry);
+static UINT GetClassifierEntry(struct bcm_phs_classifier_table *pstClassifierTable, B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_classifier_entry **ppstClassifierEntry);
 
-static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_rule **ppstPhsRule);
+static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable, B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_rule **ppstPhsRule);
 
 static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable);
 
 static int phs_compress(struct bcm_phs_rule *phs_members, unsigned char *in_buf,
-                                               unsigned char *out_buf,unsigned int *header_size,UINT *new_header_size );
+                       unsigned char *out_buf, unsigned int *header_size, UINT *new_header_size);
 
+static int verify_suppress_phsf(unsigned char *in_buffer, unsigned char *out_buffer,
+                               unsigned char *phsf, unsigned char *phsm, unsigned int phss, unsigned int phsv, UINT *new_header_size);
 
-static int verify_suppress_phsf(unsigned char *in_buffer,unsigned char *out_buffer,
-                                                               unsigned char *phsf,unsigned char *phsm,unsigned int phss,unsigned int phsv,UINT *new_header_size );
-
-static int phs_decompress(unsigned char *in_buf,unsigned char *out_buf,\
-                                                 struct bcm_phs_rule *phs_rules, UINT *header_size);
-
-
-static ULONG PhsCompress(void* pvContext,
-                                 B_UINT16 uiVcid,
-                                 B_UINT16 uiClsId,
-                                 void *pvInputBuffer,
-                                 void *pvOutputBuffer,
-                                 UINT *pOldHeaderSize,
-                                 UINT *pNewHeaderSize );
-
-static ULONG PhsDeCompress(void* pvContext,
-                                 B_UINT16 uiVcid,
-                                 void *pvInputBuffer,
-                                 void *pvOutputBuffer,
-                                 UINT *pInHeaderSize,
-                                 UINT *pOutHeaderSize);
+static int phs_decompress(unsigned char *in_buf, unsigned char *out_buf,
+                       struct bcm_phs_rule *phs_rules, UINT *header_size);
 
+static ULONG PhsCompress(void *pvContext,
+                       B_UINT16 uiVcid,
+                       B_UINT16 uiClsId,
+                       void *pvInputBuffer,
+                       void *pvOutputBuffer,
+                       UINT *pOldHeaderSize,
+                       UINT *pNewHeaderSize);
 
+static ULONG PhsDeCompress(void *pvContext,
+                       B_UINT16 uiVcid,
+                       void *pvInputBuffer,
+                       void *pvOutputBuffer,
+                       UINT *pInHeaderSize,
+                       UINT *pOutHeaderSize);
 
 #define IN
 #define OUT
 
 /*
-Function:                              PHSTransmit
-
-Description:                   This routine handle PHS(Payload Header Suppression for Tx path.
-                                       It extracts a fragment of the NDIS_PACKET containing the header
-                                       to be suppressed. It then suppresses the header by invoking PHS exported compress routine.
-                                       The header data after suppression is copied back to the NDIS_PACKET.
-
-
-Input parameters:              IN struct bcm_mini_adapter *Adapter         - Miniport Adapter Context
-                                               IN Packet                               - NDIS packet containing data to be transmitted
-                                               IN USHORT Vcid        - vcid pertaining to connection on which the packet is being sent.Used to
-                                                                                       identify PHS rule to be applied.
-                                               B_UINT16 uiClassifierRuleID - Classifier Rule ID
-                                               BOOLEAN bHeaderSuppressionEnabled - indicates if header suprression is enabled for SF.
-
-Return:                                        STATUS_SUCCESS - If the send was successful.
-                                               Other  - If an error occurred.
-*/
+ * Function: PHSTransmit
+ * Description:        This routine handle PHS(Payload Header Suppression for Tx path.
+ *     It extracts a fragment of the NDIS_PACKET containing the header
+ *     to be suppressed. It then suppresses the header by invoking PHS exported compress routine.
+ *     The header data after suppression is copied back to the NDIS_PACKET.
+ *
+ * Input parameters: IN struct bcm_mini_adapter *Adapter         - Miniport Adapter Context
+ *     IN Packet - NDIS packet containing data to be transmitted
+ *     IN USHORT Vcid - vcid pertaining to connection on which the packet is being sent.Used to
+ *             identify PHS rule to be applied.
+ *     B_UINT16 uiClassifierRuleID - Classifier Rule ID
+ *     BOOLEAN bHeaderSuppressionEnabled - indicates if header suprression is enabled for SF.
+ *
+ * Return:     STATUS_SUCCESS - If the send was successful.
+ *     Other  - If an error occurred.
+ */
 
 int PHSTransmit(struct bcm_mini_adapter *Adapter,
-                                        struct sk_buff **pPacket,
-                                        USHORT Vcid,
-                                        B_UINT16 uiClassifierRuleID,
-                                        BOOLEAN bHeaderSuppressionEnabled,
-                                        UINT *PacketLen,
-                                        UCHAR bEthCSSupport)
+               struct sk_buff **pPacket,
+               USHORT Vcid,
+               B_UINT16 uiClassifierRuleID,
+               BOOLEAN bHeaderSuppressionEnabled,
+               UINT *PacketLen,
+               UCHAR bEthCSSupport)
 {
-
-       //PHS Sepcific
-       UINT    unPHSPktHdrBytesCopied = 0;
-       UINT    unPhsOldHdrSize = 0;
-       UINT    unPHSNewPktHeaderLen = 0;
+       /* PHS Sepcific */
+       UINT unPHSPktHdrBytesCopied = 0;
+       UINT unPhsOldHdrSize = 0;
+       UINT unPHSNewPktHeaderLen = 0;
        /* Pointer to PHS IN Hdr Buffer */
-       PUCHAR pucPHSPktHdrInBuf =
-                               Adapter->stPhsTxContextInfo.ucaHdrSuppressionInBuf;
+       PUCHAR pucPHSPktHdrInBuf = Adapter->stPhsTxContextInfo.ucaHdrSuppressionInBuf;
        /* Pointer to PHS OUT Hdr Buffer */
-       PUCHAR  pucPHSPktHdrOutBuf =
-                                       Adapter->stPhsTxContextInfo.ucaHdrSuppressionOutBuf;
-       UINT       usPacketType;
-       UINT       BytesToRemove=0;
-       BOOLEAN  bPHSI = 0;
+       PUCHAR pucPHSPktHdrOutBuf = Adapter->stPhsTxContextInfo.ucaHdrSuppressionOutBuf;
+       UINT usPacketType;
+       UINT BytesToRemove = 0;
+       BOOLEAN bPHSI = 0;
        LONG ulPhsStatus = 0;
-       UINT    numBytesCompressed = 0;
+       UINT numBytesCompressed = 0;
        struct sk_buff *newPacket = NULL;
        struct sk_buff *Packet = *pPacket;
 
-       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "In PHSTransmit");
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "In PHSTransmit");
 
-       if(!bEthCSSupport)
-               BytesToRemove=ETH_HLEN;
+       if (!bEthCSSupport)
+               BytesToRemove = ETH_HLEN;
        /*
-               Accumulate the header upto the size we support suppression
-               from NDIS packet
-       */
-
-       usPacketType=((struct ethhdr *)(Packet->data))->h_proto;
+        * Accumulate the header upto the size we support suppression
+        * from NDIS packet
+        */
 
+       usPacketType = ((struct ethhdr *)(Packet->data))->h_proto;
 
        pucPHSPktHdrInBuf = Packet->data + BytesToRemove;
-       //considering data after ethernet header
-       if((*PacketLen - BytesToRemove) < MAX_PHS_LENGTHS)
-       {
-
+       /* considering data after ethernet header */
+       if ((*PacketLen - BytesToRemove) < MAX_PHS_LENGTHS)
                unPHSPktHdrBytesCopied = (*PacketLen - BytesToRemove);
-       }
        else
-       {
                unPHSPktHdrBytesCopied = MAX_PHS_LENGTHS;
-       }
 
-       if( (unPHSPktHdrBytesCopied > 0 ) &&
-               (unPHSPktHdrBytesCopied <= MAX_PHS_LENGTHS))
-       {
-
-
-               // Step 2 Suppress Header using PHS and fill into intermediate ucaPHSPktHdrOutBuf.
-       // Suppress only if IP Header and PHS Enabled For the Service Flow
-               if(((usPacketType == ETHERNET_FRAMETYPE_IPV4) ||
-                       (usPacketType == ETHERNET_FRAMETYPE_IPV6)) &&
-                       (bHeaderSuppressionEnabled))
-               {
-                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"\nTrying to PHS Compress Using Classifier rule 0x%X",uiClassifierRuleID);
-
-
-                               unPHSNewPktHeaderLen = unPHSPktHdrBytesCopied;
-                               ulPhsStatus = PhsCompress(&Adapter->stBCMPhsContext,
-                                       Vcid,
-                                       uiClassifierRuleID,
-                                       pucPHSPktHdrInBuf,
-                                       pucPHSPktHdrOutBuf,
-                                       &unPhsOldHdrSize,
-                                       &unPHSNewPktHeaderLen);
-                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"\nPHS Old header Size : %d New Header Size  %d\n",unPhsOldHdrSize,unPHSNewPktHeaderLen);
-
-                               if(unPHSNewPktHeaderLen == unPhsOldHdrSize)
-                               {
-                                       if(  ulPhsStatus == STATUS_PHS_COMPRESSED)
-                                                       bPHSI = *pucPHSPktHdrOutBuf;
-                                       ulPhsStatus = STATUS_PHS_NOCOMPRESSION;
-                               }
-
-                               if(  ulPhsStatus == STATUS_PHS_COMPRESSED)
-                               {
-                                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"PHS Sending packet Compressed");
+       if ((unPHSPktHdrBytesCopied > 0) &&
+               (unPHSPktHdrBytesCopied <= MAX_PHS_LENGTHS)) {
 
-                                       if(skb_cloned(Packet))
-                                       {
-                                               newPacket = skb_copy(Packet, GFP_ATOMIC);
+               /*
+                * Step 2 Suppress Header using PHS and fill into intermediate ucaPHSPktHdrOutBuf.
+                * Suppress only if IP Header and PHS Enabled For the Service Flow
+                */
+               if (((usPacketType == ETHERNET_FRAMETYPE_IPV4) ||
+                               (usPacketType == ETHERNET_FRAMETYPE_IPV6)) &&
+                       (bHeaderSuppressionEnabled)) {
+
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nTrying to PHS Compress Using Classifier rule 0x%X", uiClassifierRuleID);
+                       unPHSNewPktHeaderLen = unPHSPktHdrBytesCopied;
+                       ulPhsStatus = PhsCompress(&Adapter->stBCMPhsContext,
+                                               Vcid,
+                                               uiClassifierRuleID,
+                                               pucPHSPktHdrInBuf,
+                                               pucPHSPktHdrOutBuf,
+                                               &unPhsOldHdrSize,
+                                               &unPHSNewPktHeaderLen);
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nPHS Old header Size : %d New Header Size  %d\n", unPhsOldHdrSize, unPHSNewPktHeaderLen);
+
+                       if (unPHSNewPktHeaderLen == unPhsOldHdrSize) {
+
+                               if (ulPhsStatus == STATUS_PHS_COMPRESSED)
+                                       bPHSI = *pucPHSPktHdrOutBuf;
+
+                               ulPhsStatus = STATUS_PHS_NOCOMPRESSION;
+                       }
 
-                                               if(newPacket == NULL)
-                                                       return STATUS_FAILURE;
+                       if (ulPhsStatus == STATUS_PHS_COMPRESSED) {
 
-                                               dev_kfree_skb(Packet);
-                                               *pPacket = Packet = newPacket;
-                                               pucPHSPktHdrInBuf = Packet->data  + BytesToRemove;
-                                       }
+                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "PHS Sending packet Compressed");
 
-                                       numBytesCompressed = unPhsOldHdrSize - (unPHSNewPktHeaderLen+PHSI_LEN);
+                               if (skb_cloned(Packet)) {
+                                       newPacket = skb_copy(Packet, GFP_ATOMIC);
 
-                                       memcpy(pucPHSPktHdrInBuf + numBytesCompressed, pucPHSPktHdrOutBuf, unPHSNewPktHeaderLen + PHSI_LEN);
-                                       memcpy(Packet->data + numBytesCompressed, Packet->data, BytesToRemove);
-                                       skb_pull(Packet, numBytesCompressed);
+                                       if (newPacket == NULL)
+                                               return STATUS_FAILURE;
 
-                                       return STATUS_SUCCESS;
+                                       dev_kfree_skb(Packet);
+                                       *pPacket = Packet = newPacket;
+                                       pucPHSPktHdrInBuf = Packet->data  + BytesToRemove;
                                }
 
-                               else
-                               {
-                                       //if one byte headroom is not available, increase it through skb_cow
-                                       if(!(skb_headroom(Packet) > 0))
-                                       {
-                                               if(skb_cow(Packet, 1))
-                                               {
-                                                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "SKB Cow Failed\n");
-                                                       return STATUS_FAILURE;
-                                               }
-                                       }
-                                       skb_push(Packet, 1);
+                               numBytesCompressed = unPhsOldHdrSize - (unPHSNewPktHeaderLen + PHSI_LEN);
 
-                                       // CAUTION: The MAC Header is getting corrupted here for IP CS - can be saved by copying 14 Bytes.  not needed .... hence corrupting it.
-                                       *(Packet->data + BytesToRemove) = bPHSI;
-                                       return STATUS_SUCCESS;
-                       }
-               }
-               else
-               {
-                       if(!bHeaderSuppressionEnabled)
-                       {
-                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"\nHeader Suppression Disabled For SF: No PHS\n");
+                               memcpy(pucPHSPktHdrInBuf + numBytesCompressed, pucPHSPktHdrOutBuf, unPHSNewPktHeaderLen + PHSI_LEN);
+                               memcpy(Packet->data + numBytesCompressed, Packet->data, BytesToRemove);
+                               skb_pull(Packet, numBytesCompressed);
+
+                               return STATUS_SUCCESS;
+                       } else {
+                               /* if one byte headroom is not available, increase it through skb_cow */
+                               if (!(skb_headroom(Packet) > 0)) {
+
+                                       if (skb_cow(Packet, 1)) {
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "SKB Cow Failed\n");
+                                               return STATUS_FAILURE;
+                                       }
+                               }
+                               skb_push(Packet, 1);
+
+                               /*
+                                * CAUTION: The MAC Header is getting corrupted
+                                * here for IP CS - can be saved by copying 14
+                                * Bytes.  not needed .... hence corrupting it.
+                                */
+                               *(Packet->data + BytesToRemove) = bPHSI;
+                               return STATUS_SUCCESS;
                        }
+               } else {
+
+                       if (!bHeaderSuppressionEnabled)
+                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nHeader Suppression Disabled For SF: No PHS\n");
 
                        return STATUS_SUCCESS;
                }
        }
 
-       //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"PHSTransmit : Dumping data packet After PHS");
+       /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"PHSTransmit : Dumping data packet After PHS"); */
        return STATUS_SUCCESS;
 }
 
 int PHSReceive(struct bcm_mini_adapter *Adapter,
-                                       USHORT usVcid,
-                                       struct sk_buff *packet,
-                                       UINT *punPacketLen,
-                                       UCHAR *pucEthernetHdr,
-                                       UINT    bHeaderSuppressionEnabled)
+       USHORT usVcid,
+       struct sk_buff *packet,
+       UINT *punPacketLen,
+       UCHAR *pucEthernetHdr,
+       UINT bHeaderSuppressionEnabled)
 {
-       u32   nStandardPktHdrLen                        = 0;
-       u32   nTotalsuppressedPktHdrBytes  = 0;
-       int     ulPhsStatus             = 0;
-       PUCHAR pucInBuff = NULL ;
+       u32 nStandardPktHdrLen = 0;
+       u32 nTotalsuppressedPktHdrBytes = 0;
+       int ulPhsStatus = 0;
+       PUCHAR pucInBuff = NULL;
        UINT TotalBytesAdded = 0;
-       if(!bHeaderSuppressionEnabled)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nPhs Disabled for incoming packet");
+
+       if (!bHeaderSuppressionEnabled) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nPhs Disabled for incoming packet");
                return ulPhsStatus;
        }
 
        pucInBuff = packet->data;
 
-       //Restore  PHS suppressed header
+       /* Restore PHS suppressed header */
        nStandardPktHdrLen = packet->len;
        ulPhsStatus = PhsDeCompress(&Adapter->stBCMPhsContext,
-               usVcid,
-               pucInBuff,
-               Adapter->ucaPHSPktRestoreBuf,
-               &nTotalsuppressedPktHdrBytes,
-               &nStandardPktHdrLen);
+                               usVcid,
+                               pucInBuff,
+                               Adapter->ucaPHSPktRestoreBuf,
+                               &nTotalsuppressedPktHdrBytes,
+                               &nStandardPktHdrLen);
 
-       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nSuppressed PktHdrLen : 0x%x Restored PktHdrLen : 0x%x",
-                                       nTotalsuppressedPktHdrBytes,nStandardPktHdrLen);
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nSuppressed PktHdrLen : 0x%x Restored PktHdrLen : 0x%x",
+                       nTotalsuppressedPktHdrBytes, nStandardPktHdrLen);
 
-       if(ulPhsStatus != STATUS_PHS_COMPRESSED)
-       {
+       if (ulPhsStatus != STATUS_PHS_COMPRESSED) {
                skb_pull(packet, 1);
                return STATUS_SUCCESS;
-       }
-       else
-       {
+       } else {
                TotalBytesAdded = nStandardPktHdrLen - nTotalsuppressedPktHdrBytes - PHSI_LEN;
-               if(TotalBytesAdded)
-               {
-                       if(skb_headroom(packet) >= (SKB_RESERVE_ETHERNET_HEADER + TotalBytesAdded))
+
+               if (TotalBytesAdded) {
+                       if (skb_headroom(packet) >= (SKB_RESERVE_ETHERNET_HEADER + TotalBytesAdded))
                                skb_push(packet, TotalBytesAdded);
-                       else
-                       {
-                               if(skb_cow(packet, skb_headroom(packet) + TotalBytesAdded))
-                               {
-                                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "cow failed in receive\n");
+                       else {
+                               if (skb_cow(packet, skb_headroom(packet) + TotalBytesAdded)) {
+                                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "cow failed in receive\n");
                                        return STATUS_FAILURE;
                                }
 
@@ -271,90 +246,80 @@ int PHSReceive(struct bcm_mini_adapter *Adapter,
        return STATUS_SUCCESS;
 }
 
-void DumpFullPacket(UCHAR *pBuf,UINT nPktLen)
+void DumpFullPacket(UCHAR *pBuf, UINT nPktLen)
 {
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
-    BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL,"Dumping Data Packet");
-    BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL,pBuf,nPktLen);
+
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Dumping Data Packet");
+       BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, pBuf, nPktLen);
 }
 
-//-----------------------------------------------------------------------------
-// Procedure:   phs_init
-//
-// Description: This routine is responsible for allocating memory for classifier and
-// PHS rules.
-//
-// Arguments:
-// pPhsdeviceExtension - ptr to Device extension containing PHS Classifier rules and PHS Rules , RX, TX buffer etc
-//
-// Returns:
-// TRUE(1)     -If allocation of memory was success full.
-// FALSE       -If allocation of memory fails.
-//-----------------------------------------------------------------------------
+/*
+ * Procedure:   phs_init
+ *
+ * Description: This routine is responsible for allocating memory for classifier and
+ * PHS rules.
+ *
+ * Arguments:
+ * pPhsdeviceExtension - ptr to Device extension containing PHS Classifier rules and PHS Rules , RX, TX buffer etc
+ *
+ * Returns:
+ * TRUE(1)     -If allocation of memory was successful.
+ * FALSE       -If allocation of memory fails.
+ */
 int phs_init(struct bcm_phs_extension *pPhsdeviceExtension, struct bcm_mini_adapter *Adapter)
 {
        int i;
        struct bcm_phs_table *pstServiceFlowTable;
-    BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nPHS:phs_init function ");
 
-       if(pPhsdeviceExtension->pstServiceFlowPhsRulesTable)
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nPHS:phs_init function");
+
+       if (pPhsdeviceExtension->pstServiceFlowPhsRulesTable)
                return -EINVAL;
 
-       pPhsdeviceExtension->pstServiceFlowPhsRulesTable =
-               kzalloc(sizeof(struct bcm_phs_table), GFP_KERNEL);
+       pPhsdeviceExtension->pstServiceFlowPhsRulesTable = kzalloc(sizeof(struct bcm_phs_table), GFP_KERNEL);
 
-    if(!pPhsdeviceExtension->pstServiceFlowPhsRulesTable)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation ServiceFlowPhsRulesTable failed");
+       if (!pPhsdeviceExtension->pstServiceFlowPhsRulesTable) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation ServiceFlowPhsRulesTable failed");
                return -ENOMEM;
        }
 
        pstServiceFlowTable = pPhsdeviceExtension->pstServiceFlowPhsRulesTable;
-       for(i=0;i<MAX_SERVICEFLOWS;i++)
-       {
+       for (i = 0; i < MAX_SERVICEFLOWS; i++) {
                struct bcm_phs_entry sServiceFlow = pstServiceFlowTable->stSFList[i];
                sServiceFlow.pstClassifierTable = kzalloc(sizeof(struct bcm_phs_classifier_table), GFP_KERNEL);
-               if(!sServiceFlow.pstClassifierTable)
-               {
-                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
-                       free_phs_serviceflow_rules(pPhsdeviceExtension->
-                pstServiceFlowPhsRulesTable);
+               if (!sServiceFlow.pstClassifierTable) {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
+                       free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable);
                        pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL;
                        return -ENOMEM;
                }
        }
 
        pPhsdeviceExtension->CompressedTxBuffer = kmalloc(PHS_BUFFER_SIZE, GFP_KERNEL);
-
-    if(pPhsdeviceExtension->CompressedTxBuffer == NULL)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
+       if (pPhsdeviceExtension->CompressedTxBuffer == NULL) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
                free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable);
                pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL;
                return -ENOMEM;
        }
 
-    pPhsdeviceExtension->UnCompressedRxBuffer = kmalloc(PHS_BUFFER_SIZE, GFP_KERNEL);
-       if(pPhsdeviceExtension->UnCompressedRxBuffer == NULL)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
+       pPhsdeviceExtension->UnCompressedRxBuffer = kmalloc(PHS_BUFFER_SIZE, GFP_KERNEL);
+       if (pPhsdeviceExtension->UnCompressedRxBuffer == NULL) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
                kfree(pPhsdeviceExtension->CompressedTxBuffer);
                free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable);
                pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL;
                return -ENOMEM;
        }
 
-
-
-       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\n phs_init Successful");
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\n phs_init Successful");
        return STATUS_SUCCESS;
 }
 
-
 int PhsCleanup(IN struct bcm_phs_extension *pPHSDeviceExt)
 {
-       if(pPHSDeviceExt->pstServiceFlowPhsRulesTable)
-       {
+       if (pPHSDeviceExt->pstServiceFlowPhsRulesTable) {
                free_phs_serviceflow_rules(pPHSDeviceExt->pstServiceFlowPhsRulesTable);
                pPHSDeviceExt->pstServiceFlowPhsRulesTable = NULL;
        }
@@ -368,200 +333,173 @@ int PhsCleanup(IN struct bcm_phs_extension *pPHSDeviceExt)
        return 0;
 }
 
-
-
-//PHS functions
-/*++
-PhsUpdateClassifierRule
-
-Routine Description:
-    Exported function to add or modify a PHS Rule.
-
-Arguments:
-       IN void* pvContext - PHS Driver Specific Context
-       IN B_UINT16 uiVcid    - The Service Flow ID for which the PHS rule applies
-       IN B_UINT16  uiClsId   - The Classifier ID within the Service Flow for which the PHS rule applies.
-       IN struct bcm_phs_rule *psPhsRule - The PHS Rule strcuture to be added to the PHS Rule table.
-
-Return Value:
-
-    0 if successful,
-    >0 Error.
-
---*/
-ULONG PhsUpdateClassifierRule(IN void* pvContext,
-                                                               IN B_UINT16  uiVcid ,
-                                                               IN B_UINT16  uiClsId   ,
-                                                               IN struct bcm_phs_rule *psPhsRule,
-                                                               IN B_UINT8  u8AssociatedPHSI)
+/*
+ * PHS functions
+ * PhsUpdateClassifierRule
+ *
+ * Routine Description:
+ *   Exported function to add or modify a PHS Rule.
+ *
+ * Arguments:
+ *     IN void* pvContext - PHS Driver Specific Context
+ *     IN B_UINT16 uiVcid    - The Service Flow ID for which the PHS rule applies
+ *     IN B_UINT16  uiClsId   - The Classifier ID within the Service Flow for which the PHS rule applies.
+ *     IN struct bcm_phs_rule *psPhsRule - The PHS Rule strcuture to be added to the PHS Rule table.
+ *
+ * Return Value:
+ *
+ * 0 if successful,
+ * >0 Error.
+ */
+ULONG PhsUpdateClassifierRule(IN void *pvContext,
+                       IN B_UINT16 uiVcid ,
+                       IN B_UINT16 uiClsId   ,
+                       IN struct bcm_phs_rule *psPhsRule,
+                       IN B_UINT8 u8AssociatedPHSI)
 {
-       ULONG lStatus =0;
-       UINT nSFIndex =;
+       ULONG lStatus = 0;
+       UINT nSFIndex = 0;
        struct bcm_phs_entry *pstServiceFlowEntry = NULL;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
+       struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
 
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "PHS With Corr2 Changes\n");
 
-
-       struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext;
-
-       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"PHS With Corr2 Changes \n");
-
-       if(pDeviceExtension == NULL)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"Invalid Device Extension\n");
+       if (pDeviceExtension == NULL) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "Invalid Device Extension\n");
                return ERR_PHS_INVALID_DEVICE_EXETENSION;
        }
 
-
-       if(u8AssociatedPHSI == 0)
-       {
+       if (u8AssociatedPHSI == 0)
                return ERR_PHS_INVALID_PHS_RULE;
-       }
 
        /* Retrieve the SFID Entry Index for requested Service Flow */
-
        nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
-                       uiVcid,&pstServiceFlowEntry);
+                               uiVcid, &pstServiceFlowEntry);
 
-    if(nSFIndex == PHS_INVALID_TABLE_INDEX)
-       {
+       if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
                /* This is a new SF. Create a mapping entry for this */
                lStatus = CreateSFToClassifierRuleMapping(uiVcid, uiClsId,
-                     pDeviceExtension->pstServiceFlowPhsRulesTable, psPhsRule, u8AssociatedPHSI);
+                                                       pDeviceExtension->pstServiceFlowPhsRulesTable, psPhsRule, u8AssociatedPHSI);
                return lStatus;
        }
 
        /* SF already Exists Add PHS Rule to existing SF */
-       lStatus = CreateClassiferToPHSRuleMapping(uiVcid, uiClsId,
-                 pstServiceFlowEntry, psPhsRule, u8AssociatedPHSI);
+       lStatus = CreateClassiferToPHSRuleMapping(uiVcid, uiClsId,
+                                               pstServiceFlowEntry, psPhsRule, u8AssociatedPHSI);
 
-    return lStatus;
+       return lStatus;
 }
 
-/*++
-PhsDeletePHSRule
-
-Routine Description:
-   Deletes the specified phs Rule within Vcid
-
-Arguments:
-       IN void* pvContext - PHS Driver Specific Context
-       IN B_UINT16  uiVcid    - The Service Flow ID for which the PHS rule applies
-       IN B_UINT8  u8PHSI   - the PHS Index identifying PHS rule to be deleted.
-
-Return Value:
-
-    0 if successful,
-    >0 Error.
-
---*/
-
-ULONG PhsDeletePHSRule(IN void* pvContext,IN B_UINT16 uiVcid,IN B_UINT8 u8PHSI)
+/*
+ * PhsDeletePHSRule
+ *
+ * Routine Description:
+ *   Deletes the specified phs Rule within Vcid
+ *
+ * Arguments:
+ *     IN void* pvContext - PHS Driver Specific Context
+ *     IN B_UINT16  uiVcid    - The Service Flow ID for which the PHS rule applies
+ *     IN B_UINT8  u8PHSI   - the PHS Index identifying PHS rule to be deleted.
+ *
+ * Return Value:
+ *
+ * 0 if successful,
+ * >0 Error.
+ */
+ULONG PhsDeletePHSRule(IN void *pvContext, IN B_UINT16 uiVcid, IN B_UINT8 u8PHSI)
 {
-       ULONG lStatus =0;
-       UINT nSFIndex =0, nClsidIndex =0 ;
+       ULONG lStatus = 0;
+       UINT nSFIndex = 0, nClsidIndex = 0;
        struct bcm_phs_entry *pstServiceFlowEntry = NULL;
        struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
+       struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
 
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "======>\n");
 
-       struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext;
+       if (pDeviceExtension) {
+               /* Retrieve the SFID Entry Index for requested Service Flow */
+               nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable, uiVcid, &pstServiceFlowEntry);
 
-       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "======>\n");
-
-       if(pDeviceExtension)
-       {
-
-               //Retrieve the SFID Entry Index for requested Service Flow
-               nSFIndex = GetServiceFlowEntry(pDeviceExtension
-                     ->pstServiceFlowPhsRulesTable,uiVcid,&pstServiceFlowEntry);
-
-       if(nSFIndex == PHS_INVALID_TABLE_INDEX)
-               {
-                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "SFID Match Failed\n");
+               if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "SFID Match Failed\n");
                        return ERR_SF_MATCH_FAIL;
                }
 
-               pstClassifierRulesTable=pstServiceFlowEntry->pstClassifierTable;
-               if(pstClassifierRulesTable)
-               {
-                       for(nClsidIndex=0;nClsidIndex<MAX_PHSRULE_PER_SF;nClsidIndex++)
-                       {
-                               if(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].bUsed && pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule)
-                               {
-                                       if(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8PHSI == u8PHSI)                                     {
-                                               if(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
+               pstClassifierRulesTable = pstServiceFlowEntry->pstClassifierTable;
+               if (pstClassifierRulesTable) {
+                       for (nClsidIndex = 0; nClsidIndex < MAX_PHSRULE_PER_SF; nClsidIndex++) {
+                               if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].bUsed && pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule) {
+                                       if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8PHSI == u8PHSI) {
+
+                                               if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
                                                        pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt--;
-                                               if(0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
+
+                                               if (0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
                                                        kfree(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule);
+
                                                memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0,
                                                        sizeof(struct bcm_phs_classifier_entry));
                                        }
                                }
                        }
                }
-
        }
        return lStatus;
 }
 
-/*++
-PhsDeleteClassifierRule
-
-Routine Description:
-    Exported function to Delete a PHS Rule for the SFID,CLSID Pair.
-
-Arguments:
-       IN void* pvContext - PHS Driver Specific Context
-       IN B_UINT16  uiVcid    - The Service Flow ID for which the PHS rule applies
-       IN B_UINT16  uiClsId   - The Classifier ID within the Service Flow for which the PHS rule applies.
-
-Return Value:
-
-    0 if successful,
-    >0 Error.
-
---*/
-ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16  uiClsId)
+/*
+ * PhsDeleteClassifierRule
+ *
+ * Routine Description:
+ *    Exported function to Delete a PHS Rule for the SFID,CLSID Pair.
+ *
+ * Arguments:
+ *     IN void* pvContext - PHS Driver Specific Context
+ *     IN B_UINT16  uiVcid    - The Service Flow ID for which the PHS rule applies
+ *     IN B_UINT16  uiClsId   - The Classifier ID within the Service Flow for which the PHS rule applies.
+ *
+ * Return Value:
+ *
+ * 0 if successful,
+ * >0 Error.
+ */
+ULONG PhsDeleteClassifierRule(IN void *pvContext, IN B_UINT16 uiVcid, IN B_UINT16 uiClsId)
 {
-       ULONG lStatus =0;
-       UINT nSFIndex =0, nClsidIndex =0 ;
+       ULONG lStatus = 0;
+       UINT nSFIndex = 0, nClsidIndex = 0;
        struct bcm_phs_entry *pstServiceFlowEntry = NULL;
        struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
-       struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext;
-
-       if(pDeviceExtension)
-       {
-               //Retrieve the SFID Entry Index for requested Service Flow
-               nSFIndex = GetServiceFlowEntry(pDeviceExtension
-                     ->pstServiceFlowPhsRulesTable, uiVcid, &pstServiceFlowEntry);
-               if(nSFIndex == PHS_INVALID_TABLE_INDEX)
-               {
-                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"SFID Match Failed\n");
+       struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
+
+       if (pDeviceExtension) {
+               /* Retrieve the SFID Entry Index for requested Service Flow */
+               nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable, uiVcid, &pstServiceFlowEntry);
+               if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "SFID Match Failed\n");
                        return ERR_SF_MATCH_FAIL;
                }
 
                nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable,
-                  uiClsId, eActiveClassifierRuleContext, &pstClassifierEntry);
-               if((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule))
-               {
-                       if(pstClassifierEntry->pstPhsRule)
-                       {
-                               if(pstClassifierEntry->pstPhsRule->u8RefCnt)
-                               pstClassifierEntry->pstPhsRule->u8RefCnt--;
-                               if(0==pstClassifierEntry->pstPhsRule->u8RefCnt)
-                                       kfree(pstClassifierEntry->pstPhsRule);
+                                               uiClsId, eActiveClassifierRuleContext, &pstClassifierEntry);
 
+               if ((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule)) {
+                       if (pstClassifierEntry->pstPhsRule) {
+                               if (pstClassifierEntry->pstPhsRule->u8RefCnt)
+                                       pstClassifierEntry->pstPhsRule->u8RefCnt--;
+
+                               if (0 == pstClassifierEntry->pstPhsRule->u8RefCnt)
+                                       kfree(pstClassifierEntry->pstPhsRule);
                        }
                        memset(pstClassifierEntry, 0, sizeof(struct bcm_phs_classifier_entry));
                }
 
                nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable,
-                    uiClsId,eOldClassifierRuleContext,&pstClassifierEntry);
+                                               uiClsId, eOldClassifierRuleContext, &pstClassifierEntry);
 
-          if((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule))
-               {
+               if ((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule)) {
                        kfree(pstClassifierEntry->pstPhsRule);
                        memset(pstClassifierEntry, 0, sizeof(struct bcm_phs_classifier_entry));
                }
@@ -569,261 +507,223 @@ ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16
        return lStatus;
 }
 
-/*++
-PhsDeleteSFRules
-
-Routine Description:
-    Exported function to Delete a all PHS Rules for the SFID.
-
-Arguments:
-       IN void* pvContext - PHS Driver Specific Context
-       IN B_UINT16 uiVcid   - The Service Flow ID for which the PHS rules need to be deleted
-
-Return Value:
-
-    0 if successful,
-    >0 Error.
-
---*/
-ULONG PhsDeleteSFRules(IN void* pvContext,IN B_UINT16 uiVcid)
+/*
+ * PhsDeleteSFRules
+ *
+ * Routine Description:
+ *    Exported function to Delete a all PHS Rules for the SFID.
+ *
+ * Arguments:
+ *     IN void* pvContext - PHS Driver Specific Context
+ *     IN B_UINT16 uiVcid   - The Service Flow ID for which the PHS rules need to be deleted
+ *
+ * Return Value:
+ *
+ * 0 if successful,
+ * >0 Error.
+ */
+ULONG PhsDeleteSFRules(IN void *pvContext, IN B_UINT16 uiVcid)
 {
-
-       ULONG lStatus =0;
-       UINT nSFIndex =0, nClsidIndex =0  ;
+       ULONG lStatus = 0;
+       UINT nSFIndex = 0, nClsidIndex = 0;
        struct bcm_phs_entry *pstServiceFlowEntry = NULL;
        struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
-       struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext;
-    BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"====> \n");
+       struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
+
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "====>\n");
 
-       if(pDeviceExtension)
-       {
-               //Retrieve the SFID Entry Index for requested Service Flow
+       if (pDeviceExtension) {
+               /* Retrieve the SFID Entry Index for requested Service Flow */
                nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
-                                 uiVcid,&pstServiceFlowEntry);
-               if(nSFIndex == PHS_INVALID_TABLE_INDEX)
-               {
-                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "SFID Match Failed\n");
+                                       uiVcid, &pstServiceFlowEntry);
+               if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "SFID Match Failed\n");
                        return ERR_SF_MATCH_FAIL;
                }
 
-               pstClassifierRulesTable=pstServiceFlowEntry->pstClassifierTable;
-               if(pstClassifierRulesTable)
-               {
-                       for(nClsidIndex=0;nClsidIndex<MAX_PHSRULE_PER_SF;nClsidIndex++)
-                       {
-                               if(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule)
-                               {
-                                       if(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex]
-                                                        .pstPhsRule->u8RefCnt)
-                                               pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex]
-                                                                                   .pstPhsRule->u8RefCnt--;
-                                       if(0==pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex]
-                                                          .pstPhsRule->u8RefCnt)
+               pstClassifierRulesTable = pstServiceFlowEntry->pstClassifierTable;
+               if (pstClassifierRulesTable) {
+                       for (nClsidIndex = 0; nClsidIndex < MAX_PHSRULE_PER_SF; nClsidIndex++) {
+                               if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule) {
+
+                                       if (pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
+                                               pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt--;
+
+                                       if (0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
                                                kfree(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule);
-                                           pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex]
-                                        .pstPhsRule = NULL;
+
+                                       pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule = NULL;
                                }
                                memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0, sizeof(struct bcm_phs_classifier_entry));
-                               if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule)
-                               {
-                                       if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex]
-                                        .pstPhsRule->u8RefCnt)
-                                               pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex]
-                                                                 .pstPhsRule->u8RefCnt--;
-                                       if(0 == pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex]
-                                        .pstPhsRule->u8RefCnt)
-                                               kfree(pstClassifierRulesTable
-                                                     ->stOldPhsRulesList[nClsidIndex].pstPhsRule);
-                                       pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex]
-                              .pstPhsRule = NULL;
+                               if (pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule) {
+
+                                       if (pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
+                                               pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt--;
+
+                                       if (0 == pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
+                                               kfree(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule);
+
+                                       pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule = NULL;
                                }
                                memset(&pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex], 0, sizeof(struct bcm_phs_classifier_entry));
                        }
                }
                pstServiceFlowEntry->bUsed = FALSE;
                pstServiceFlowEntry->uiVcid = 0;
-
        }
 
        return lStatus;
 }
 
-
-/*++
-PhsCompress
-
-Routine Description:
-    Exported function to compress the data using PHS.
-
-Arguments:
-       IN void* pvContext - PHS Driver Specific Context.
-       IN B_UINT16 uiVcid    - The Service Flow ID to which current packet header compression applies.
-       IN UINT  uiClsId   - The Classifier ID to which current packet header compression applies.
-       IN void *pvInputBuffer - The Input buffer containg packet header data
-       IN void *pvOutputBuffer - The output buffer returned by this function after PHS
-       IN UINT *pOldHeaderSize  - The actual size of the header before PHS
-       IN UINT *pNewHeaderSize - The new size of the header after applying PHS
-
-Return Value:
-
-    0 if successful,
-    >0 Error.
-
---*/
-ULONG PhsCompress(IN void* pvContext,
-                                 IN B_UINT16 uiVcid,
-                                 IN B_UINT16 uiClsId,
-                                 IN void *pvInputBuffer,
-                                 OUT void *pvOutputBuffer,
-                                 OUT UINT *pOldHeaderSize,
-                                 OUT UINT *pNewHeaderSize )
+/*
+ * PhsCompress
+ *
+ * Routine Description:
+ *    Exported function to compress the data using PHS.
+ *
+ * Arguments:
+ *     IN void* pvContext - PHS Driver Specific Context.
+ *     IN B_UINT16 uiVcid    - The Service Flow ID to which current packet header compression applies.
+ *     IN UINT  uiClsId   - The Classifier ID to which current packet header compression applies.
+ *     IN void *pvInputBuffer - The Input buffer containg packet header data
+ *     IN void *pvOutputBuffer - The output buffer returned by this function after PHS
+ *     IN UINT *pOldHeaderSize  - The actual size of the header before PHS
+ *     IN UINT *pNewHeaderSize - The new size of the header after applying PHS
+ *
+ * Return Value:
+ *
+ * 0 if successful,
+ * >0 Error.
+ */
+ULONG PhsCompress(IN void *pvContext,
+               IN B_UINT16 uiVcid,
+               IN B_UINT16 uiClsId,
+               IN void *pvInputBuffer,
+               OUT void *pvOutputBuffer,
+               OUT UINT *pOldHeaderSize,
+               OUT UINT *pNewHeaderSize)
 {
-       UINT nSFIndex =0, nClsidIndex =0  ;
+       UINT nSFIndex = 0, nClsidIndex = 0;
        struct bcm_phs_entry *pstServiceFlowEntry = NULL;
        struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
        struct bcm_phs_rule *pstPhsRule = NULL;
-       ULONG lStatus =0;
+       ULONG lStatus = 0;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
+       struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
 
-
-
-       struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext;
-
-
-       if(pDeviceExtension == NULL)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"Invalid Device Extension\n");
-               lStatus =  STATUS_PHS_NOCOMPRESSION ;
+       if (pDeviceExtension == NULL) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "Invalid Device Extension\n");
+               lStatus = STATUS_PHS_NOCOMPRESSION;
                return lStatus;
-
        }
 
-       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"Suppressing header \n");
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "Suppressing header\n");
 
-
-       //Retrieve the SFID Entry Index for requested Service Flow
+       /* Retrieve the SFID Entry Index for requested Service Flow */
        nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
-                         uiVcid,&pstServiceFlowEntry);
-       if(nSFIndex == PHS_INVALID_TABLE_INDEX)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"SFID Match Failed\n");
-               lStatus =  STATUS_PHS_NOCOMPRESSION ;
+                               uiVcid, &pstServiceFlowEntry);
+       if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "SFID Match Failed\n");
+               lStatus = STATUS_PHS_NOCOMPRESSION;
                return lStatus;
        }
 
        nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable,
-                uiClsId,eActiveClassifierRuleContext,&pstClassifierEntry);
+                                       uiClsId, eActiveClassifierRuleContext, &pstClassifierEntry);
 
-    if(nClsidIndex == PHS_INVALID_TABLE_INDEX)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"No PHS Rule Defined For Classifier\n");
-               lStatus =  STATUS_PHS_NOCOMPRESSION ;
+       if (nClsidIndex == PHS_INVALID_TABLE_INDEX) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "No PHS Rule Defined For Classifier\n");
+               lStatus =  STATUS_PHS_NOCOMPRESSION;
                return lStatus;
        }
 
-
-       //get rule from SF id,Cls ID pair and proceed
-       pstPhsRule =  pstClassifierEntry->pstPhsRule;
-
-       if(!ValidatePHSRuleComplete(pstPhsRule))
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"PHS Rule Defined For Classifier But Not Complete\n");
-               lStatus =  STATUS_PHS_NOCOMPRESSION ;
+       /* get rule from SF id,Cls ID pair and proceed */
+       pstPhsRule = pstClassifierEntry->pstPhsRule;
+       if (!ValidatePHSRuleComplete(pstPhsRule)) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "PHS Rule Defined For Classifier But Not Complete\n");
+               lStatus = STATUS_PHS_NOCOMPRESSION;
                return lStatus;
        }
 
-       //Compress Packet
-       lStatus = phs_compress(pstPhsRule,(PUCHAR)pvInputBuffer,
-             (PUCHAR)pvOutputBuffer, pOldHeaderSize,pNewHeaderSize);
+       /* Compress Packet */
+       lStatus = phs_compress(pstPhsRule, (PUCHAR)pvInputBuffer,
+                       (PUCHAR)pvOutputBuffer, pOldHeaderSize, pNewHeaderSize);
 
-       if(lStatus == STATUS_PHS_COMPRESSED)
-       {
+       if (lStatus == STATUS_PHS_COMPRESSED) {
                pstPhsRule->PHSModifiedBytes += *pOldHeaderSize - *pNewHeaderSize - 1;
                pstPhsRule->PHSModifiedNumPackets++;
-       }
-       else
+       } else
                pstPhsRule->PHSErrorNumPackets++;
 
        return lStatus;
 }
 
-/*++
-PhsDeCompress
-
-Routine Description:
-    Exported function to restore the packet header in Rx path.
-
-Arguments:
-       IN void* pvContext - PHS Driver Specific Context.
-       IN B_UINT16 uiVcid    - The Service Flow ID to which current packet header restoration applies.
-       IN  void *pvInputBuffer - The Input buffer containg suppressed packet header data
-       OUT void *pvOutputBuffer - The output buffer returned by this function after restoration
-       OUT UINT *pHeaderSize   - The packet header size after restoration is returned in this parameter.
-
-Return Value:
-
-    0 if successful,
-    >0 Error.
-
---*/
-ULONG PhsDeCompress(IN void* pvContext,
-                                 IN B_UINT16 uiVcid,
-                                 IN void *pvInputBuffer,
-                                 OUT void *pvOutputBuffer,
-                                 OUT UINT *pInHeaderSize,
-                                 OUT UINT *pOutHeaderSize )
+/*
+ * PhsDeCompress
+ *
+ * Routine Description:
+ *    Exported function to restore the packet header in Rx path.
+ *
+ * Arguments:
+ *     IN void* pvContext - PHS Driver Specific Context.
+ *     IN B_UINT16 uiVcid    - The Service Flow ID to which current packet header restoration applies.
+ *     IN  void *pvInputBuffer - The Input buffer containg suppressed packet header data
+ *     OUT void *pvOutputBuffer - The output buffer returned by this function after restoration
+ *     OUT UINT *pHeaderSize   - The packet header size after restoration is returned in this parameter.
+ *
+ * Return Value:
+ *
+ * 0 if successful,
+ * >0 Error.
+ */
+ULONG PhsDeCompress(IN void *pvContext,
+               IN B_UINT16 uiVcid,
+               IN void *pvInputBuffer,
+               OUT void *pvOutputBuffer,
+               OUT UINT *pInHeaderSize,
+               OUT UINT *pOutHeaderSize)
 {
-       UINT nSFIndex =0, nPhsRuleIndex =0 ;
+       UINT nSFIndex = 0, nPhsRuleIndex = 0;
        struct bcm_phs_entry *pstServiceFlowEntry = NULL;
        struct bcm_phs_rule *pstPhsRule = NULL;
        UINT phsi;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
-       struct bcm_phs_extension *pDeviceExtension=
-        (struct bcm_phs_extension *)pvContext;
+       struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
 
        *pInHeaderSize = 0;
-
-       if(pDeviceExtension == NULL)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"Invalid Device Extension\n");
+       if (pDeviceExtension == NULL) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "Invalid Device Extension\n");
                return ERR_PHS_INVALID_DEVICE_EXETENSION;
        }
 
-       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"Restoring header\n");
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "Restoring header\n");
 
        phsi = *((unsigned char *)(pvInputBuffer));
-    BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"PHSI To Be Used For restore : %x\n",phsi);
-    if(phsi == UNCOMPRESSED_PACKET )
-       {
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "PHSI To Be Used For restore : %x\n", phsi);
+       if (phsi == UNCOMPRESSED_PACKET)
                return STATUS_PHS_NOCOMPRESSION;
-       }
 
-       //Retrieve the SFID Entry Index for requested Service Flow
+       /* Retrieve the SFID Entry Index for requested Service Flow */
        nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
-             uiVcid,&pstServiceFlowEntry);
-       if(nSFIndex == PHS_INVALID_TABLE_INDEX)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"SFID Match Failed During Lookup\n");
+                               uiVcid, &pstServiceFlowEntry);
+       if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "SFID Match Failed During Lookup\n");
                return ERR_SF_MATCH_FAIL;
        }
 
-       nPhsRuleIndex = GetPhsRuleEntry(pstServiceFlowEntry->pstClassifierTable,phsi,
-          eActiveClassifierRuleContext,&pstPhsRule);
-       if(nPhsRuleIndex == PHS_INVALID_TABLE_INDEX)
-       {
-               //Phs Rule does not exist in  active rules table. Lets try in the old rules table.
+       nPhsRuleIndex = GetPhsRuleEntry(pstServiceFlowEntry->pstClassifierTable, phsi,
+                                       eActiveClassifierRuleContext, &pstPhsRule);
+       if (nPhsRuleIndex == PHS_INVALID_TABLE_INDEX) {
+               /* Phs Rule does not exist in  active rules table. Lets try in the old rules table. */
                nPhsRuleIndex = GetPhsRuleEntry(pstServiceFlowEntry->pstClassifierTable,
-                     phsi,eOldClassifierRuleContext,&pstPhsRule);
-               if(nPhsRuleIndex == PHS_INVALID_TABLE_INDEX)
-               {
+                                               phsi, eOldClassifierRuleContext, &pstPhsRule);
+               if (nPhsRuleIndex == PHS_INVALID_TABLE_INDEX)
                        return ERR_PHSRULE_MATCH_FAIL;
-               }
-
        }
 
        *pInHeaderSize = phs_decompress((PUCHAR)pvInputBuffer,
-            (PUCHAR)pvOutputBuffer,pstPhsRule,pOutHeaderSize);
+                                       (PUCHAR)pvOutputBuffer, pstPhsRule, pOutHeaderSize);
 
        pstPhsRule->PHSModifiedBytes += *pOutHeaderSize - *pInHeaderSize - 1;
 
@@ -831,112 +731,94 @@ ULONG PhsDeCompress(IN void* pvContext,
        return STATUS_PHS_COMPRESSED;
 }
 
-
-//-----------------------------------------------------------------------------
-// Procedure:   free_phs_serviceflow_rules
-//
-// Description: This routine is responsible for freeing memory allocated for PHS rules.
-//
-// Arguments:
-// rules       - ptr to S_SERVICEFLOW_TABLE structure.
-//
-// Returns:
-// Does not return any value.
-//-----------------------------------------------------------------------------
-
+/*
+ * Procedure:   free_phs_serviceflow_rules
+ *
+ * Description: This routine is responsible for freeing memory allocated for PHS rules.
+ *
+ * Arguments:
+ * rules       - ptr to S_SERVICEFLOW_TABLE structure.
+ *
+ * Returns:
+ * Does not return any value.
+ */
 static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable)
 {
-       int i,j;
+       int i, j;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
 
-       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "=======>\n");
-    if(psServiceFlowRulesTable)
-       {
-               for(i=0;i<MAX_SERVICEFLOWS;i++)
-               {
-                       struct bcm_phs_entry stServiceFlowEntry =
-                psServiceFlowRulesTable->stSFList[i];
-                       struct bcm_phs_classifier_table *pstClassifierRulesTable =
-                stServiceFlowEntry.pstClassifierTable;
-
-                       if(pstClassifierRulesTable)
-                       {
-                               for(j=0;j<MAX_PHSRULE_PER_SF;j++)
-                               {
-                                       if(pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule)
-                                       {
-                                               if(pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule
-                                                                                        ->u8RefCnt)
-                                                       pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule
-                                                                                                       ->u8RefCnt--;
-                                               if(0==pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule
-                                                                ->u8RefCnt)
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "=======>\n");
+
+       if (psServiceFlowRulesTable) {
+               for (i = 0; i < MAX_SERVICEFLOWS; i++) {
+                       struct bcm_phs_entry stServiceFlowEntry = psServiceFlowRulesTable->stSFList[i];
+                       struct bcm_phs_classifier_table *pstClassifierRulesTable = stServiceFlowEntry.pstClassifierTable;
+
+                       if (pstClassifierRulesTable) {
+                               for (j = 0; j < MAX_PHSRULE_PER_SF; j++) {
+                                       if (pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule) {
+
+                                               if (pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule->u8RefCnt)
+                                                       pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule->u8RefCnt--;
+
+                                               if (0 == pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule->u8RefCnt)
                                                        kfree(pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule);
+
                                                pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule = NULL;
                                        }
-                                       if(pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule)
-                                       {
-                                               if(pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule
-                                                                ->u8RefCnt)
-                                                       pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule
-                                                                                                 ->u8RefCnt--;
-                                               if(0==pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule
-                                                                      ->u8RefCnt)
+
+                                       if (pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule) {
+
+                                               if (pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule->u8RefCnt)
+                                                       pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule->u8RefCnt--;
+
+                                               if (0 == pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule->u8RefCnt)
                                                        kfree(pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule);
+
                                                pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule = NULL;
                                        }
                                }
                                kfree(pstClassifierRulesTable);
-                           stServiceFlowEntry.pstClassifierTable = pstClassifierRulesTable = NULL;
+                               stServiceFlowEntry.pstClassifierTable = pstClassifierRulesTable = NULL;
                        }
                }
        }
 
-    kfree(psServiceFlowRulesTable);
-    psServiceFlowRulesTable = NULL;
+       kfree(psServiceFlowRulesTable);
+       psServiceFlowRulesTable = NULL;
 }
 
-
-
 static BOOLEAN ValidatePHSRuleComplete(IN struct bcm_phs_rule *psPhsRule)
 {
-       if(psPhsRule)
-       {
-               if(!psPhsRule->u8PHSI)
-               {
-                       // PHSI is not valid
+       if (psPhsRule) {
+               if (!psPhsRule->u8PHSI) {
+                       /* PHSI is not valid */
                        return FALSE;
                }
 
-               if(!psPhsRule->u8PHSS)
-               {
-                       //PHSS Is Undefined
+               if (!psPhsRule->u8PHSS) {
+                       /* PHSS Is Undefined */
                        return FALSE;
                }
 
-               //Check if PHSF is defines for the PHS Rule
-               if(!psPhsRule->u8PHSFLength) // If any part of PHSF is valid then Rule contains valid PHSF
-               {
+               /* Check if PHSF is defines for the PHS Rule */
+               if (!psPhsRule->u8PHSFLength) /* If any part of PHSF is valid then Rule contains valid PHSF */
                        return FALSE;
-               }
+
                return TRUE;
-       }
-       else
-       {
+       } else
                return FALSE;
-       }
 }
 
 UINT GetServiceFlowEntry(IN struct bcm_phs_table *psServiceFlowTable,
-    IN B_UINT16 uiVcid, struct bcm_phs_entry **ppstServiceFlowEntry)
+                       IN B_UINT16 uiVcid,
+                       struct bcm_phs_entry **ppstServiceFlowEntry)
 {
-       int  i;
-       for(i=0;i<MAX_SERVICEFLOWS;i++)
-       {
-               if(psServiceFlowTable->stSFList[i].bUsed)
-               {
-                       if(psServiceFlowTable->stSFList[i].uiVcid == uiVcid)
-                       {
+       int i;
+
+       for (i = 0; i < MAX_SERVICEFLOWS; i++) {
+               if (psServiceFlowTable->stSFList[i].bUsed) {
+                       if (psServiceFlowTable->stSFList[i].uiVcid == uiVcid) {
                                *ppstServiceFlowEntry = &psServiceFlowTable->stSFList[i];
                                return i;
                        }
@@ -947,34 +829,26 @@ UINT GetServiceFlowEntry(IN struct bcm_phs_table *psServiceFlowTable,
        return PHS_INVALID_TABLE_INDEX;
 }
 
-
 UINT GetClassifierEntry(IN struct bcm_phs_classifier_table *pstClassifierTable,
-        IN B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext,
-        OUT struct bcm_phs_classifier_entry **ppstClassifierEntry)
+                       IN B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext,
+                       OUT struct bcm_phs_classifier_entry **ppstClassifierEntry)
 {
        int  i;
        struct bcm_phs_classifier_entry *psClassifierRules = NULL;
-       for(i=0;i<MAX_PHSRULE_PER_SF;i++)
-       {
 
-               if(eClsContext == eActiveClassifierRuleContext)
-               {
+       for (i = 0; i < MAX_PHSRULE_PER_SF; i++) {
+
+               if (eClsContext == eActiveClassifierRuleContext)
                        psClassifierRules = &pstClassifierTable->stActivePhsRulesList[i];
-               }
                else
-               {
                        psClassifierRules = &pstClassifierTable->stOldPhsRulesList[i];
-               }
 
-               if(psClassifierRules->bUsed)
-               {
-                       if(psClassifierRules->uiClassifierRuleId == uiClsid)
-                       {
+               if (psClassifierRules->bUsed) {
+                       if (psClassifierRules->uiClassifierRuleId == uiClsid) {
                                *ppstClassifierEntry = psClassifierRules;
                                return i;
                        }
                }
-
        }
 
        *ppstClassifierEntry = NULL;
@@ -982,254 +856,227 @@ UINT GetClassifierEntry(IN struct bcm_phs_classifier_table *pstClassifierTable,
 }
 
 static UINT GetPhsRuleEntry(IN struct bcm_phs_classifier_table *pstClassifierTable,
-                           IN B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext,
-                           OUT struct bcm_phs_rule **ppstPhsRule)
+                       IN B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext,
+                       OUT struct bcm_phs_rule **ppstPhsRule)
 {
        int  i;
        struct bcm_phs_classifier_entry *pstClassifierRule = NULL;
-       for(i=0;i<MAX_PHSRULE_PER_SF;i++)
-       {
-               if(eClsContext == eActiveClassifierRuleContext)
-               {
+
+       for (i = 0; i < MAX_PHSRULE_PER_SF; i++) {
+               if (eClsContext == eActiveClassifierRuleContext)
                        pstClassifierRule = &pstClassifierTable->stActivePhsRulesList[i];
-               }
                else
-               {
                        pstClassifierRule = &pstClassifierTable->stOldPhsRulesList[i];
-               }
-               if(pstClassifierRule->bUsed)
-               {
-                       if(pstClassifierRule->u8PHSI == uiPHSI)
-                       {
+
+               if (pstClassifierRule->bUsed) {
+                       if (pstClassifierRule->u8PHSI == uiPHSI) {
                                *ppstPhsRule = pstClassifierRule->pstPhsRule;
                                return i;
                        }
                }
-
        }
 
        *ppstPhsRule = NULL;
        return PHS_INVALID_TABLE_INDEX;
 }
 
-UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid,IN B_UINT16  uiClsId,
-                      IN struct bcm_phs_table *psServiceFlowTable, struct bcm_phs_rule *psPhsRule,
-                      B_UINT8 u8AssociatedPHSI)
+UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid, IN B_UINT16  uiClsId,
+                               IN struct bcm_phs_table *psServiceFlowTable,
+                               struct bcm_phs_rule *psPhsRule,
+                               B_UINT8 u8AssociatedPHSI)
 {
-
        struct bcm_phs_classifier_table *psaClassifiertable = NULL;
        UINT uiStatus = 0;
        int iSfIndex;
-       BOOLEAN bFreeEntryFound =FALSE;
-       //Check for a free entry in SFID table
-       for(iSfIndex=0;iSfIndex < MAX_SERVICEFLOWS;iSfIndex++)
-       {
-               if(!psServiceFlowTable->stSFList[iSfIndex].bUsed)
-               {
+       BOOLEAN bFreeEntryFound = FALSE;
+
+       /* Check for a free entry in SFID table */
+       for (iSfIndex = 0; iSfIndex < MAX_SERVICEFLOWS; iSfIndex++) {
+               if (!psServiceFlowTable->stSFList[iSfIndex].bUsed) {
                        bFreeEntryFound = TRUE;
                        break;
                }
        }
 
-       if(!bFreeEntryFound)
+       if (!bFreeEntryFound)
                return ERR_SFTABLE_FULL;
 
-
        psaClassifiertable = psServiceFlowTable->stSFList[iSfIndex].pstClassifierTable;
-       uiStatus = CreateClassifierPHSRule(uiClsId,psaClassifiertable,psPhsRule,
-                             eActiveClassifierRuleContext,u8AssociatedPHSI);
-       if(uiStatus == PHS_SUCCESS)
-       {
-               //Add entry at free index to the SF
+       uiStatus = CreateClassifierPHSRule(uiClsId, psaClassifiertable, psPhsRule,
+                                       eActiveClassifierRuleContext, u8AssociatedPHSI);
+       if (uiStatus == PHS_SUCCESS) {
+               /* Add entry at free index to the SF */
                psServiceFlowTable->stSFList[iSfIndex].bUsed = TRUE;
                psServiceFlowTable->stSFList[iSfIndex].uiVcid = uiVcid;
        }
 
        return uiStatus;
-
 }
 
 UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid,
-            IN B_UINT16  uiClsId,IN struct bcm_phs_entry *pstServiceFlowEntry,
-              struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI)
+                               IN B_UINT16 uiClsId,
+                               IN struct bcm_phs_entry *pstServiceFlowEntry,
+                               struct bcm_phs_rule *psPhsRule,
+                               B_UINT8 u8AssociatedPHSI)
 {
        struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
-       UINT uiStatus =PHS_SUCCESS;
+       UINT uiStatus = PHS_SUCCESS;
        UINT nClassifierIndex = 0;
        struct bcm_phs_classifier_table *psaClassifiertable = NULL;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
-    psaClassifiertable = pstServiceFlowEntry->pstClassifierTable;
 
-       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "==>");
+       psaClassifiertable = pstServiceFlowEntry->pstClassifierTable;
+
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "==>");
 
        /* Check if the supplied Classifier already exists */
-       nClassifierIndex =GetClassifierEntry(
-                   pstServiceFlowEntry->pstClassifierTable,uiClsId,
-                   eActiveClassifierRuleContext,&pstClassifierEntry);
-       if(nClassifierIndex == PHS_INVALID_TABLE_INDEX)
-       {
+       nClassifierIndex = GetClassifierEntry(
+               pstServiceFlowEntry->pstClassifierTable,
+               uiClsId,
+               eActiveClassifierRuleContext,
+               &pstClassifierEntry);
+
+       if (nClassifierIndex == PHS_INVALID_TABLE_INDEX) {
                /*
-                   The Classifier doesn't exist. So its a new classifier being added.
-                    Add new entry to associate PHS Rule to the Classifier
-               */
+                * The Classifier doesn't exist. So its a new classifier being added.
+                * Add new entry to associate PHS Rule to the Classifier
+                */
 
-               uiStatus = CreateClassifierPHSRule(uiClsId,psaClassifiertable,
-                   psPhsRule,eActiveClassifierRuleContext,u8AssociatedPHSI);
+               uiStatus = CreateClassifierPHSRule(uiClsId, psaClassifiertable,
+                                               psPhsRule,
+                                               eActiveClassifierRuleContext,
+                                               u8AssociatedPHSI);
                return uiStatus;
        }
 
        /*
-         The Classifier exists.The PHS Rule for this classifier
-         is being modified
-         */
-       if(pstClassifierEntry->u8PHSI == psPhsRule->u8PHSI)
-       {
-               if(pstClassifierEntry->pstPhsRule == NULL)
+        * The Classifier exists.The PHS Rule for this classifier
+        * is being modified
+        */
+
+       if (pstClassifierEntry->u8PHSI == psPhsRule->u8PHSI) {
+               if (pstClassifierEntry->pstPhsRule == NULL)
                        return ERR_PHS_INVALID_PHS_RULE;
 
                /*
-                   This rule already exists if any fields are changed for this PHS
-                   rule update them.
+                * This rule already exists if any fields are changed for this PHS
+                * rule update them.
                 */
-                /* If any part of PHSF is valid then we update PHSF */
-               if(psPhsRule->u8PHSFLength)
-               {
-                       //update PHSF
+               /* If any part of PHSF is valid then we update PHSF */
+               if (psPhsRule->u8PHSFLength) {
+                       /* update PHSF */
                        memcpy(pstClassifierEntry->pstPhsRule->u8PHSF,
-                           psPhsRule->u8PHSF , MAX_PHS_LENGTHS);
+                               psPhsRule->u8PHSF, MAX_PHS_LENGTHS);
                }
-               if(psPhsRule->u8PHSFLength)
-               {
-                       //update PHSFLen
-                       pstClassifierEntry->pstPhsRule->u8PHSFLength =
-                           psPhsRule->u8PHSFLength;
+
+               if (psPhsRule->u8PHSFLength) {
+                       /* update PHSFLen */
+                       pstClassifierEntry->pstPhsRule->u8PHSFLength = psPhsRule->u8PHSFLength;
                }
-               if(psPhsRule->u8PHSMLength)
-               {
-                       //update PHSM
+
+               if (psPhsRule->u8PHSMLength) {
+                       /* update PHSM */
                        memcpy(pstClassifierEntry->pstPhsRule->u8PHSM,
-                           psPhsRule->u8PHSM, MAX_PHS_LENGTHS);
+                               psPhsRule->u8PHSM, MAX_PHS_LENGTHS);
                }
-               if(psPhsRule->u8PHSMLength)
-               {
-                       //update PHSM Len
+
+               if (psPhsRule->u8PHSMLength) {
+                       /* update PHSM Len */
                        pstClassifierEntry->pstPhsRule->u8PHSMLength =
-                           psPhsRule->u8PHSMLength;
+                               psPhsRule->u8PHSMLength;
                }
-               if(psPhsRule->u8PHSS)
-               {
-                       //update PHSS
+
+               if (psPhsRule->u8PHSS) {
+                       /* update PHSS */
                        pstClassifierEntry->pstPhsRule->u8PHSS = psPhsRule->u8PHSS;
                }
 
-               //update PHSV
+               /* update PHSV */
                pstClassifierEntry->pstPhsRule->u8PHSV = psPhsRule->u8PHSV;
-
+       } else {
+               /* A new rule is being set for this classifier. */
+               uiStatus = UpdateClassifierPHSRule(uiClsId, pstClassifierEntry,
+                                               psaClassifiertable, psPhsRule, u8AssociatedPHSI);
        }
-       else
-       {
-               /*
-                 A new rule is being set for this classifier.
-               */
-               uiStatus=UpdateClassifierPHSRule( uiClsId,  pstClassifierEntry,
-                     psaClassifiertable,  psPhsRule, u8AssociatedPHSI);
-       }
-
-
 
        return uiStatus;
 }
 
 static UINT CreateClassifierPHSRule(IN B_UINT16  uiClsId,
-    struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule,
-    enum bcm_phs_classifier_context eClsContext,B_UINT8 u8AssociatedPHSI)
+                               struct bcm_phs_classifier_table *psaClassifiertable,
+                               struct bcm_phs_rule *psPhsRule,
+                               enum bcm_phs_classifier_context eClsContext,
+                               B_UINT8 u8AssociatedPHSI)
 {
        UINT iClassifierIndex = 0;
        BOOLEAN bFreeEntryFound = FALSE;
        struct bcm_phs_classifier_entry *psClassifierRules = NULL;
        UINT nStatus = PHS_SUCCESS;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
-       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"Inside CreateClassifierPHSRule");
-    if(psaClassifiertable == NULL)
-       {
+
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "Inside CreateClassifierPHSRule");
+
+       if (psaClassifiertable == NULL)
                return ERR_INVALID_CLASSIFIERTABLE_FOR_SF;
-       }
 
-       if(eClsContext == eOldClassifierRuleContext)
-       {
-               /* If An Old Entry for this classifier ID already exists in the
-                   old rules table replace it. */
+       if (eClsContext == eOldClassifierRuleContext) {
+               /*
+                * If An Old Entry for this classifier ID already exists in the
+                * old rules table replace it.
+                */
 
                iClassifierIndex =
-               GetClassifierEntry(psaClassifiertable, uiClsId,
-                           eClsContext,&psClassifierRules);
-               if(iClassifierIndex != PHS_INVALID_TABLE_INDEX)
-               {
+                       GetClassifierEntry(psaClassifiertable, uiClsId,
+                                       eClsContext, &psClassifierRules);
+
+               if (iClassifierIndex != PHS_INVALID_TABLE_INDEX) {
                        /*
-                           The Classifier already exists in the old rules table
-                       Lets replace the old classifier with the new one.
-                       */
+                        * The Classifier already exists in the old rules table
+                        * Lets replace the old classifier with the new one.
+                        */
                        bFreeEntryFound = TRUE;
                }
        }
 
-       if(!bFreeEntryFound)
-       {
-               /*
-                 Continue to search for a free location to add the rule
-               */
-               for(iClassifierIndex = 0; iClassifierIndex <
-            MAX_PHSRULE_PER_SF; iClassifierIndex++)
-               {
-                       if(eClsContext == eActiveClassifierRuleContext)
-                       {
-                               psClassifierRules =
-              &psaClassifiertable->stActivePhsRulesList[iClassifierIndex];
-                       }
+       if (!bFreeEntryFound) {
+               /* Continue to search for a free location to add the rule */
+               for (iClassifierIndex = 0; iClassifierIndex <
+                            MAX_PHSRULE_PER_SF; iClassifierIndex++) {
+                       if (eClsContext == eActiveClassifierRuleContext)
+                               psClassifierRules = &psaClassifiertable->stActivePhsRulesList[iClassifierIndex];
                        else
-                       {
-                               psClassifierRules =
-                &psaClassifiertable->stOldPhsRulesList[iClassifierIndex];
-                       }
+                               psClassifierRules = &psaClassifiertable->stOldPhsRulesList[iClassifierIndex];
 
-                       if(!psClassifierRules->bUsed)
-                       {
+                       if (!psClassifierRules->bUsed) {
                                bFreeEntryFound = TRUE;
                                break;
                        }
                }
        }
 
-       if(!bFreeEntryFound)
-       {
-               if(eClsContext == eActiveClassifierRuleContext)
-               {
+       if (!bFreeEntryFound) {
+
+               if (eClsContext == eActiveClassifierRuleContext)
                        return ERR_CLSASSIFIER_TABLE_FULL;
-               }
-               else
-               {
-                       //Lets replace the oldest rule if we are looking in old Rule table
-                       if(psaClassifiertable->uiOldestPhsRuleIndex >=
-                MAX_PHSRULE_PER_SF)
-                       {
-                               psaClassifiertable->uiOldestPhsRuleIndex =0;
-                       }
+               else {
+                       /* Lets replace the oldest rule if we are looking in old Rule table */
+                       if (psaClassifiertable->uiOldestPhsRuleIndex >= MAX_PHSRULE_PER_SF)
+                               psaClassifiertable->uiOldestPhsRuleIndex = 0;
 
                        iClassifierIndex = psaClassifiertable->uiOldestPhsRuleIndex;
-                       psClassifierRules =
-              &psaClassifiertable->stOldPhsRulesList[iClassifierIndex];
+                       psClassifierRules = &psaClassifiertable->stOldPhsRulesList[iClassifierIndex];
 
-          (psaClassifiertable->uiOldestPhsRuleIndex)++;
+                       (psaClassifiertable->uiOldestPhsRuleIndex)++;
                }
        }
 
-       if(eClsContext == eOldClassifierRuleContext)
-       {
-               if(psClassifierRules->pstPhsRule == NULL)
-               {
-                       psClassifierRules->pstPhsRule = kmalloc(sizeof(struct bcm_phs_rule),GFP_KERNEL);
+       if (eClsContext == eOldClassifierRuleContext) {
+
+               if (psClassifierRules->pstPhsRule == NULL) {
 
-          if(NULL == psClassifierRules->pstPhsRule)
+                       psClassifierRules->pstPhsRule = kmalloc(sizeof(struct bcm_phs_rule), GFP_KERNEL);
+
+                       if (NULL == psClassifierRules->pstPhsRule)
                                return ERR_PHSRULE_MEMALLOC_FAIL;
                }
 
@@ -1238,70 +1085,62 @@ static UINT CreateClassifierPHSRule(IN B_UINT16  uiClsId,
                psClassifierRules->u8PHSI = psPhsRule->u8PHSI;
                psClassifierRules->bUnclassifiedPHSRule = psPhsRule->bUnclassifiedPHSRule;
 
-        /* Update The PHS rule */
-               memcpy(psClassifierRules->pstPhsRule,
-                   psPhsRule, sizeof(struct bcm_phs_rule));
-       }
-       else
-       {
-               nStatus = UpdateClassifierPHSRule(uiClsId,psClassifierRules,
-            psaClassifiertable,psPhsRule,u8AssociatedPHSI);
-       }
+               /* Update The PHS rule */
+               memcpy(psClassifierRules->pstPhsRule, psPhsRule, sizeof(struct bcm_phs_rule));
+       } else
+               nStatus = UpdateClassifierPHSRule(uiClsId, psClassifierRules,
+                                               psaClassifiertable, psPhsRule, u8AssociatedPHSI);
+
        return nStatus;
 }
 
-
 static UINT UpdateClassifierPHSRule(IN B_UINT16  uiClsId,
-      IN struct bcm_phs_classifier_entry *pstClassifierEntry,
-      struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule,
-      B_UINT8 u8AssociatedPHSI)
+                               IN struct bcm_phs_classifier_entry *pstClassifierEntry,
+                               struct bcm_phs_classifier_table *psaClassifiertable,
+                               struct bcm_phs_rule *psPhsRule,
+                               B_UINT8 u8AssociatedPHSI)
 {
        struct bcm_phs_rule *pstAddPhsRule = NULL;
-       UINT              nPhsRuleIndex = 0;
-       BOOLEAN       bPHSRuleOrphaned = FALSE;
+       UINT nPhsRuleIndex = 0;
+       BOOLEAN bPHSRuleOrphaned = FALSE;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
-       psPhsRule->u8RefCnt =0;
-
-       /* Step 1 Deref Any Exisiting PHS Rule in this classifier Entry*/
-       bPHSRuleOrphaned = DerefPhsRule( uiClsId, psaClassifiertable,
-           pstClassifierEntry->pstPhsRule);
-
-       //Step 2 Search if there is a PHS Rule with u8AssociatedPHSI in Classifier table for this SF
-       nPhsRuleIndex =GetPhsRuleEntry(psaClassifiertable,u8AssociatedPHSI,
-           eActiveClassifierRuleContext, &pstAddPhsRule);
-       if(PHS_INVALID_TABLE_INDEX == nPhsRuleIndex)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAdding New PHSRuleEntry For Classifier");
-
-               if(psPhsRule->u8PHSI == 0)
-               {
-                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nError PHSI is Zero\n");
+
+       psPhsRule->u8RefCnt = 0;
+
+       /* Step 1 Deref Any Exisiting PHS Rule in this classifier Entry */
+       bPHSRuleOrphaned = DerefPhsRule(uiClsId, psaClassifiertable,
+                                       pstClassifierEntry->pstPhsRule);
+
+       /* Step 2 Search if there is a PHS Rule with u8AssociatedPHSI in Classifier table for this SF */
+       nPhsRuleIndex = GetPhsRuleEntry(psaClassifiertable, u8AssociatedPHSI,
+                                       eActiveClassifierRuleContext, &pstAddPhsRule);
+       if (PHS_INVALID_TABLE_INDEX == nPhsRuleIndex) {
+
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAdding New PHSRuleEntry For Classifier");
+
+               if (psPhsRule->u8PHSI == 0) {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nError PHSI is Zero\n");
                        return ERR_PHS_INVALID_PHS_RULE;
                }
-               //Step 2.a PHS Rule Does Not Exist .Create New PHS Rule for uiClsId
-               if(FALSE == bPHSRuleOrphaned)
-               {
+
+               /* Step 2.a PHS Rule Does Not Exist .Create New PHS Rule for uiClsId */
+               if (FALSE == bPHSRuleOrphaned) {
+
                        pstClassifierEntry->pstPhsRule = kmalloc(sizeof(struct bcm_phs_rule), GFP_KERNEL);
-                       if(NULL == pstClassifierEntry->pstPhsRule)
-                       {
+                       if (NULL == pstClassifierEntry->pstPhsRule)
                                return ERR_PHSRULE_MEMALLOC_FAIL;
-                       }
                }
                memcpy(pstClassifierEntry->pstPhsRule, psPhsRule, sizeof(struct bcm_phs_rule));
-
-       }
-       else
-       {
-               //Step 2.b PHS Rule  Exists Tie uiClsId with the existing PHS Rule
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nTying Classifier to Existing PHS Rule");
-               if(bPHSRuleOrphaned)
-               {
+       } else {
+               /* Step 2.b PHS Rule  Exists Tie uiClsId with the existing PHS Rule */
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nTying Classifier to Existing PHS Rule");
+               if (bPHSRuleOrphaned) {
                        kfree(pstClassifierEntry->pstPhsRule);
                        pstClassifierEntry->pstPhsRule = NULL;
                }
                pstClassifierEntry->pstPhsRule = pstAddPhsRule;
-
        }
+
        pstClassifierEntry->bUsed = TRUE;
        pstClassifierEntry->u8PHSI = pstClassifierEntry->pstPhsRule->u8PHSI;
        pstClassifierEntry->uiClassifierRuleId = uiClsId;
@@ -1309,79 +1148,74 @@ static UINT UpdateClassifierPHSRule(IN B_UINT16  uiClsId,
        pstClassifierEntry->bUnclassifiedPHSRule = pstClassifierEntry->pstPhsRule->bUnclassifiedPHSRule;
 
        return PHS_SUCCESS;
-
 }
 
 static BOOLEAN DerefPhsRule(IN B_UINT16  uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *pstPhsRule)
 {
-       if(pstPhsRule==NULL)
+       if (pstPhsRule == NULL)
                return FALSE;
-       if(pstPhsRule->u8RefCnt)
+
+       if (pstPhsRule->u8RefCnt)
                pstPhsRule->u8RefCnt--;
-       if(0==pstPhsRule->u8RefCnt)
-       {
-               /*if(pstPhsRule->u8PHSI)
-               //Store the currently active rule into the old rules list
-               CreateClassifierPHSRule(uiClsId,psaClassifiertable,pstPhsRule,eOldClassifierRuleContext,pstPhsRule->u8PHSI);*/
+
+       if (0 == pstPhsRule->u8RefCnt) {
+               /*
+                * if(pstPhsRule->u8PHSI)
+                * Store the currently active rule into the old rules list
+                * CreateClassifierPHSRule(uiClsId,psaClassifiertable,pstPhsRule,eOldClassifierRuleContext,pstPhsRule->u8PHSI);
+                */
                return TRUE;
-       }
-       else
-       {
+       } else
                return FALSE;
-       }
 }
 
 void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension)
 {
-       int i,j,k,l;
+       int i, j, k, l;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
-    BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n Dumping PHS Rules : \n");
-       for(i=0;i<MAX_SERVICEFLOWS;i++)
-       {
+
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n Dumping PHS Rules :\n");
+
+       for (i = 0; i < MAX_SERVICEFLOWS; i++) {
+
                struct bcm_phs_entry stServFlowEntry =
-                               pDeviceExtension->pstServiceFlowPhsRulesTable->stSFList[i];
-               if(stServFlowEntry.bUsed)
-               {
-                       for(j=0;j<MAX_PHSRULE_PER_SF;j++)
-                       {
-                               for(l=0;l<2;l++)
-                               {
+                       pDeviceExtension->pstServiceFlowPhsRulesTable->stSFList[i];
+               if (stServFlowEntry.bUsed) {
+
+                       for (j = 0; j < MAX_PHSRULE_PER_SF; j++) {
+
+                               for (l = 0; l < 2; l++) {
                                        struct bcm_phs_classifier_entry stClsEntry;
-                                       if(l==0)
-                                       {
+
+                                       if (l == 0) {
                                                stClsEntry = stServFlowEntry.pstClassifierTable->stActivePhsRulesList[j];
-                                               if(stClsEntry.bUsed)
-                                                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n Active PHS Rule : \n");
-                                       }
-                                       else
-                                       {
+                                               if (stClsEntry.bUsed)
+                                                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n Active PHS Rule :\n");
+                                       } else {
                                                stClsEntry = stServFlowEntry.pstClassifierTable->stOldPhsRulesList[j];
-                                               if(stClsEntry.bUsed)
-                                                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n Old PHS Rule : \n");
+                                               if (stClsEntry.bUsed)
+                                                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n Old PHS Rule :\n");
                                        }
-                                       if(stClsEntry.bUsed)
-                                       {
-
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n VCID  : %#X",stServFlowEntry.uiVcid);
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n ClassifierID  : %#X",stClsEntry.uiClassifierRuleId);
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSRuleID  : %#X",stClsEntry.u8PHSI);
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n****************PHS Rule********************\n");
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSI  : %#X",stClsEntry.pstPhsRule->u8PHSI);
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSFLength : %#X ",stClsEntry.pstPhsRule->u8PHSFLength);
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSF : ");
-                                               for(k=0;k<stClsEntry.pstPhsRule->u8PHSFLength;k++)
-                                               {
-                                                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "%#X  ",stClsEntry.pstPhsRule->u8PHSF[k]);
-                                               }
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSMLength  : %#X",stClsEntry.pstPhsRule->u8PHSMLength);
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSM :");
-                                               for(k=0;k<stClsEntry.pstPhsRule->u8PHSMLength;k++)
-                                               {
-                                                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "%#X  ",stClsEntry.pstPhsRule->u8PHSM[k]);
-                                               }
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSS : %#X ",stClsEntry.pstPhsRule->u8PHSS);
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSV  : %#X",stClsEntry.pstPhsRule->u8PHSV);
-                                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n********************************************\n");
+
+                                       if (stClsEntry.bUsed) {
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n VCID  : %#X", stServFlowEntry.uiVcid);
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n ClassifierID  : %#X", stClsEntry.uiClassifierRuleId);
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSRuleID  : %#X", stClsEntry.u8PHSI);
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n****************PHS Rule********************\n");
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSI  : %#X", stClsEntry.pstPhsRule->u8PHSI);
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSFLength : %#X ", stClsEntry.pstPhsRule->u8PHSFLength);
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSF : ");
+
+                                               for (k = 0 ; k < stClsEntry.pstPhsRule->u8PHSFLength; k++)
+                                                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "%#X  ", stClsEntry.pstPhsRule->u8PHSF[k]);
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSMLength  : %#X", stClsEntry.pstPhsRule->u8PHSMLength);
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSM :");
+
+                                               for (k = 0; k < stClsEntry.pstPhsRule->u8PHSMLength; k++)
+                                                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "%#X  ", stClsEntry.pstPhsRule->u8PHSM[k]);
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSS : %#X ", stClsEntry.pstPhsRule->u8PHSS);
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSV  : %#X", stClsEntry.pstPhsRule->u8PHSV);
+                                               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n********************************************\n");
                                        }
                                }
                        }
@@ -1389,66 +1223,69 @@ void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension)
        }
 }
 
-
-//-----------------------------------------------------------------------------
-// Procedure:   phs_decompress
-//
-// Description: This routine restores the static fields within the packet.
-//
-// Arguments:
-//     in_buf                  - ptr to incoming packet buffer.
-//     out_buf                 - ptr to output buffer where the suppressed header is copied.
-//     decomp_phs_rules - ptr to PHS rule.
-//     header_size             - ptr to field which holds the phss or phsf_length.
-//
-// Returns:
-//     size -The number of bytes of dynamic fields present with in the incoming packet
-//                     header.
-//     0       -If PHS rule is NULL.If PHSI is 0 indicateing packet as uncompressed.
-//-----------------------------------------------------------------------------
-
-int phs_decompress(unsigned char *in_buf,unsigned char *out_buf,
-               struct bcm_phs_rule *decomp_phs_rules, UINT *header_size)
+/*
+ * Procedure:   phs_decompress
+ *
+ * Description: This routine restores the static fields within the packet.
+ *
+ * Arguments:
+ *     in_buf                  - ptr to incoming packet buffer.
+ *     out_buf                 - ptr to output buffer where the suppressed header is copied.
+ *     decomp_phs_rules - ptr to PHS rule.
+ *     header_size             - ptr to field which holds the phss or phsf_length.
+ *
+ * Returns:
+ *     size -The number of bytes of dynamic fields present with in the incoming packet
+ *                     header.
+ *     0       -If PHS rule is NULL.If PHSI is 0 indicateing packet as uncompressed.
+ */
+int phs_decompress(unsigned char *in_buf,
+               unsigned char *out_buf,
+               struct bcm_phs_rule *decomp_phs_rules,
+               UINT *header_size)
 {
-       int phss,size=0;
+       int phss, size = 0;
        struct bcm_phs_rule *tmp_memb;
-       int bit,i=0;
-       unsigned char *phsf,*phsm;
-       int in_buf_len = *header_size-1;
+       int bit, i = 0;
+       unsigned char *phsf, *phsm;
+       int in_buf_len = *header_size - 1;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
+
        in_buf++;
-    BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"====>\n");
+
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "====>\n");
        *header_size = 0;
 
-       if((decomp_phs_rules == NULL ))
+       if ((decomp_phs_rules == NULL))
                return 0;
 
-
        tmp_memb = decomp_phs_rules;
-       //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nDECOMP:In phs_decompress PHSI 1  %d",phsi));
-       //*header_size = tmp_memb->u8PHSFLength;
-       phss         = tmp_memb->u8PHSS;
-       phsf         = tmp_memb->u8PHSF;
-       phsm         = tmp_memb->u8PHSM;
-
-       if(phss > MAX_PHS_LENGTHS)
+       /*
+        * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nDECOMP:In phs_decompress PHSI 1  %d",phsi));
+        * header_size = tmp_memb->u8PHSFLength;
+        */
+       phss = tmp_memb->u8PHSS;
+       phsf = tmp_memb->u8PHSF;
+       phsm = tmp_memb->u8PHSM;
+
+       if (phss > MAX_PHS_LENGTHS)
                phss = MAX_PHS_LENGTHS;
-       //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nDECOMP:In phs_decompress PHSI  %d phss %d index %d",phsi,phss,index));
-       while((phss > 0) && (size < in_buf_len))
-       {
-               bit =  ((*phsm << i)& SUPPRESS);
 
-               if(bit == SUPPRESS)
-               {
+       /*
+        * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nDECOMP:
+        * In phs_decompress PHSI  %d phss %d index %d",phsi,phss,index));
+        */
+       while ((phss > 0) && (size < in_buf_len)) {
+               bit = ((*phsm << i) & SUPPRESS);
+
+               if (bit == SUPPRESS) {
                        *out_buf = *phsf;
-                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nDECOMP:In phss  %d phsf %d ouput %d",
-              phss,*phsf,*out_buf);
-               }
-               else
-               {
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nDECOMP:In phss  %d phsf %d ouput %d",
+                                       phss, *phsf, *out_buf);
+               } else {
                        *out_buf = *in_buf;
-                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,"\nDECOMP:In phss  %d input %d ouput %d",
-            phss,*in_buf,*out_buf);
+                       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL, "\nDECOMP:In phss  %d input %d ouput %d",
+                                       phss, *in_buf, *out_buf);
                        in_buf++;
                        size++;
                }
@@ -1456,156 +1293,159 @@ int phs_decompress(unsigned char *in_buf,unsigned char *out_buf,
                phsf++;
                phss--;
                i++;
-               *header_size=*header_size + 1;
+               *header_size = *header_size + 1;
 
-               if(i > MAX_NO_BIT)
-               {
-                       i=0;
+               if (i > MAX_NO_BIT) {
+                       i = 0;
                        phsm++;
                }
        }
+
        return size;
 }
 
-
-
-
-//-----------------------------------------------------------------------------
-// Procedure:   phs_compress
-//
-// Description: This routine suppresses the static fields within the packet.Before
-// that it will verify the fields to be suppressed with the corresponding fields in the
-// phsf. For verification it checks the phsv field of PHS rule. If set and verification
-// succeeds it suppresses the field.If any one static field is found different none of
-// the static fields are suppressed then the packet is sent as uncompressed packet with
-// phsi=0.
-//
-// Arguments:
-//     phs_rule - ptr to PHS rule.
-//     in_buf          - ptr to incoming packet buffer.
-//     out_buf         - ptr to output buffer where the suppressed header is copied.
-//     header_size     - ptr to field which holds the phss.
-//
-// Returns:
-//     size-The number of bytes copied into the output buffer i.e dynamic fields
-//     0       -If PHS rule is NULL.If PHSV field is not set.If the verification fails.
-//-----------------------------------------------------------------------------
-static int phs_compress(struct bcm_phs_rule *phs_rule, unsigned char *in_buf
-                       ,unsigned char *out_buf,UINT *header_size,UINT *new_header_size)
+/*
+ * Procedure:   phs_compress
+ *
+ * Description: This routine suppresses the static fields within the packet.Before
+ * that it will verify the fields to be suppressed with the corresponding fields in the
+ * phsf. For verification it checks the phsv field of PHS rule. If set and verification
+ * succeeds it suppresses the field.If any one static field is found different none of
+ * the static fields are suppressed then the packet is sent as uncompressed packet with
+ * phsi=0.
+ *
+ * Arguments:
+ *     phs_rule - ptr to PHS rule.
+ *     in_buf          - ptr to incoming packet buffer.
+ *     out_buf         - ptr to output buffer where the suppressed header is copied.
+ *     header_size     - ptr to field which holds the phss.
+ *
+ * Returns:
+ *     size-The number of bytes copied into the output buffer i.e dynamic fields
+ *     0       -If PHS rule is NULL.If PHSV field is not set.If the verification fails.
+ */
+static int phs_compress(struct bcm_phs_rule *phs_rule,
+                       unsigned char *in_buf,
+                       unsigned char *out_buf,
+                       UINT *header_size,
+                       UINT *new_header_size)
 {
        unsigned char *old_addr = out_buf;
        int suppress = 0;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
-    if(phs_rule == NULL)
-       {
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"\nphs_compress(): phs_rule null!");
+
+       if (phs_rule == NULL) {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nphs_compress(): phs_rule null!");
                *out_buf = ZERO_PHSI;
                return STATUS_PHS_NOCOMPRESSION;
        }
 
-
-       if(phs_rule->u8PHSS <= *new_header_size)
-       {
+       if (phs_rule->u8PHSS <= *new_header_size)
                *header_size = phs_rule->u8PHSS;
-       }
        else
-       {
                *header_size = *new_header_size;
-       }
-       //To copy PHSI
+
+       /* To copy PHSI */
        out_buf++;
-       suppress = verify_suppress_phsf(in_buf,out_buf,phs_rule->u8PHSF,
-        phs_rule->u8PHSM, phs_rule->u8PHSS, phs_rule->u8PHSV,new_header_size);
+       suppress = verify_suppress_phsf(in_buf, out_buf, phs_rule->u8PHSF,
+                                       phs_rule->u8PHSM, phs_rule->u8PHSS,
+                                       phs_rule->u8PHSV, new_header_size);
 
-       if(suppress == STATUS_PHS_COMPRESSED)
-       {
+       if (suppress == STATUS_PHS_COMPRESSED) {
                *old_addr = (unsigned char)phs_rule->u8PHSI;
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"\nCOMP:In phs_compress phsi %d",phs_rule->u8PHSI);
-       }
-       else
-       {
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In phs_compress phsi %d", phs_rule->u8PHSI);
+       } else {
                *old_addr = ZERO_PHSI;
-               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"\nCOMP:In phs_compress PHSV Verification failed");
+               BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In phs_compress PHSV Verification failed");
        }
+
        return suppress;
 }
 
-
-//-----------------------------------------------------------------------------
-// Procedure:  verify_suppress_phsf
-//
-// Description: This routine verifies the fields of the packet and if all the
-// static fields are equal it adds the phsi of that PHS rule.If any static
-// field differs it woun't suppress any field.
-//
-// Arguments:
-// rules_set   - ptr to classifier_rules.
-// in_buffer   - ptr to incoming packet buffer.
-// out_buffer  - ptr to output buffer where the suppressed header is copied.
-// phsf                        - ptr to phsf.
-// phsm                        - ptr to phsm.
-// phss                        - variable holding phss.
-//
-// Returns:
-//     size-The number of bytes copied into the output buffer i.e dynamic fields.
-//     0       -Packet has failed the verification.
-//-----------------------------------------------------------------------------
-
-static int verify_suppress_phsf(unsigned char *in_buffer,unsigned char *out_buffer,
-                               unsigned char *phsf,unsigned char *phsm,unsigned int phss,
-                               unsigned int phsv,UINT* new_header_size)
+/*
+ * Procedure:  verify_suppress_phsf
+ *
+ * Description: This routine verifies the fields of the packet and if all the
+ * static fields are equal it adds the phsi of that PHS rule.If any static
+ * field differs it woun't suppress any field.
+ *
+ * Arguments:
+ * rules_set   - ptr to classifier_rules.
+ * in_buffer   - ptr to incoming packet buffer.
+ * out_buffer  - ptr to output buffer where the suppressed header is copied.
+ * phsf                        - ptr to phsf.
+ * phsm                        - ptr to phsm.
+ * phss                        - variable holding phss.
+ *
+ * Returns:
+ *     size-The number of bytes copied into the output buffer i.e dynamic fields.
+ *     0       -Packet has failed the verification.
+ */
+static int verify_suppress_phsf(unsigned char *in_buffer,
+                               unsigned char *out_buffer,
+                               unsigned char *phsf,
+                               unsigned char *phsm,
+                               unsigned int phss,
+                               unsigned int phsv,
+                               UINT *new_header_size)
 {
-       unsigned int size=0;
-       int bit,i=0;
+       unsigned int size = 0;
+       int bit, i = 0;
        struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
-    BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"\nCOMP:In verify_phsf PHSM - 0x%X",*phsm);
 
-
-       if(phss>(*new_header_size))
-       {
-               phss=*new_header_size;
-       }
-       while(phss > 0)
-       {
-               bit = ((*phsm << i)& SUPPRESS);
-               if(bit == SUPPRESS)
-               {
-
-                       if(*in_buffer != *phsf)
-                       {
-                               if(phsv == VERIFY)
-                               {
-                                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"\nCOMP:In verify_phsf failed for field  %d buf  %d phsf %d",phss,*in_buffer,*phsf);
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In verify_phsf PHSM - 0x%X", *phsm);
+
+       if (phss > (*new_header_size))
+               phss = *new_header_size;
+
+       while (phss > 0) {
+               bit = ((*phsm << i) & SUPPRESS);
+               if (bit == SUPPRESS) {
+                       if (*in_buffer != *phsf) {
+                               if (phsv == VERIFY) {
+                                       BCM_DEBUG_PRINT(Adapter,
+                                                       DBG_TYPE_OTHERS,
+                                                       PHS_SEND,
+                                                       DBG_LVL_ALL,
+                                                       "\nCOMP:In verify_phsf failed for field  %d buf  %d phsf %d",
+                                                       phss,
+                                                       *in_buffer,
+                                                       *phsf);
                                        return STATUS_PHS_NOCOMPRESSION;
                                }
-                       }
-                       else
-                               BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"\nCOMP:In verify_phsf success for field  %d buf  %d phsf %d",phss,*in_buffer,*phsf);
-               }
-               else
-               {
+                       } else
+                               BCM_DEBUG_PRINT(Adapter,
+                                               DBG_TYPE_OTHERS,
+                                               PHS_SEND,
+                                               DBG_LVL_ALL,
+                                               "\nCOMP:In verify_phsf success for field  %d buf  %d phsf %d",
+                                               phss,
+                                               *in_buffer,
+                                               *phsf);
+               } else {
                        *out_buffer = *in_buffer;
-                       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"\nCOMP:In copying_header input %d  out %d",*in_buffer,*out_buffer);
+                       BCM_DEBUG_PRINT(Adapter,
+                                       DBG_TYPE_OTHERS,
+                                       PHS_SEND,
+                                       DBG_LVL_ALL,
+                                       "\nCOMP:In copying_header input %d  out %d",
+                                       *in_buffer,
+                                       *out_buffer);
                        out_buffer++;
                        size++;
                }
+
                in_buffer++;
                phsf++;
                phss--;
                i++;
-               if(i > MAX_NO_BIT)
-               {
-                       i=0;
+
+               if (i > MAX_NO_BIT) {
+                       i = 0;
                        phsm++;
                }
        }
-       BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"\nCOMP:In verify_phsf success");
+       BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL, "\nCOMP:In verify_phsf success");
        *new_header_size = size;
        return STATUS_PHS_COMPRESSED;
 }
-
-
-
-
-
-
index e6152f4df14b4beaf515907e47098740613c5c82..bea1330f7ea6952aae258d26af35c114ed5f8e3a 100644 (file)
@@ -2228,20 +2228,20 @@ int BcmAllocFlashCSStructure(struct bcm_mini_adapter *psAdapter)
                BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Adapter structure point is NULL");
                return -EINVAL;
        }
-       psAdapter->psFlashCSInfo = (struct bcm_flash_cs_info *)kzalloc(sizeof(struct bcm_flash_cs_info), GFP_KERNEL);
+       psAdapter->psFlashCSInfo = kzalloc(sizeof(struct bcm_flash_cs_info), GFP_KERNEL);
        if (psAdapter->psFlashCSInfo == NULL) {
                BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate memory for Flash 1.x");
                return -ENOMEM;
        }
 
-       psAdapter->psFlash2xCSInfo = (struct bcm_flash2x_cs_info *)kzalloc(sizeof(struct bcm_flash2x_cs_info), GFP_KERNEL);
+       psAdapter->psFlash2xCSInfo = kzalloc(sizeof(struct bcm_flash2x_cs_info), GFP_KERNEL);
        if (!psAdapter->psFlash2xCSInfo) {
                BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate memory for Flash 2.x");
                kfree(psAdapter->psFlashCSInfo);
                return -ENOMEM;
        }
 
-       psAdapter->psFlash2xVendorInfo = (struct bcm_flash2x_vendor_info *)kzalloc(sizeof(struct bcm_flash2x_vendor_info), GFP_KERNEL);
+       psAdapter->psFlash2xVendorInfo = kzalloc(sizeof(struct bcm_flash2x_vendor_info), GFP_KERNEL);
        if (!psAdapter->psFlash2xVendorInfo) {
                BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate Vendor Info Memory for Flash 2.x");
                kfree(psAdapter->psFlashCSInfo);
@@ -4074,7 +4074,7 @@ int BcmCopySection(struct bcm_mini_adapter *Adapter,
        else
                BuffSize = numOfBytes;
 
-       pBuff = (PCHAR)kzalloc(BuffSize, GFP_KERNEL);
+       pBuff = kzalloc(BuffSize, GFP_KERNEL);
        if (!pBuff) {
                BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed.. ");
                return -ENOMEM;
@@ -4154,7 +4154,7 @@ int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned
        }
        /* If Header is present overwrite passed buffer with this */
        if (bHasHeader && (Adapter->bHeaderChangeAllowed == FALSE)) {
-               pTempBuff = (PUCHAR)kzalloc(HeaderSizeToProtect, GFP_KERNEL);
+               pTempBuff = kzalloc(HeaderSizeToProtect, GFP_KERNEL);
                if (!pTempBuff) {
                        BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed");
                        return -ENOMEM;
@@ -4563,7 +4563,7 @@ static int CorruptDSDSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sect
                }
        }
 
-       pBuff = (PUCHAR)kzalloc(MAX_RW_SIZE, GFP_KERNEL);
+       pBuff = kzalloc(MAX_RW_SIZE, GFP_KERNEL);
        if (!pBuff) {
                BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Can't allocate memorey");
                return -ENOMEM;
@@ -4622,7 +4622,7 @@ static int CorruptISOSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sect
                return SECTOR_IS_NOT_WRITABLE;
        }
 
-       pBuff = (PUCHAR)kzalloc(MAX_RW_SIZE, GFP_KERNEL);
+       pBuff = kzalloc(MAX_RW_SIZE, GFP_KERNEL);
        if (!pBuff) {
                BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Can't allocate memorey");
                return -ENOMEM;
diff --git a/drivers/staging/ccg/Kconfig b/drivers/staging/ccg/Kconfig
deleted file mode 100644 (file)
index 7ed5bc6..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-if USB_GADGET
-
-config USB_G_CCG
-       tristate "Configurable Composite Gadget (STAGING)"
-       depends on STAGING && BLOCK && NET && !USB_ZERO && !USB_ZERO_HNPTEST && !USB_AUDIO && !GADGET_UAC1 && !USB_ETH && !USB_ETH_RNDIS && !USB_ETH_EEM && !USB_G_NCM && !USB_GADGETFS && !USB_FUNCTIONFS && !USB_FUNCTIONFS_ETH && !USB_FUNCTIONFS_RNDIS && !USB_FUNCTIONFS_GENERIC && !USB_FILE_STORAGE && !USB_FILE_STORAGE_TEST && !USB_MASS_STORAGE && !USB_G_SERIAL && !USB_MIDI_GADGET && !USB_G_PRINTER && !USB_CDC_COMPOSITE && !USB_G_NOKIA && !USB_G_ACM_MS && !USB_G_MULTI && !USB_G_MULTI_RNDIS && !USB_G_MULTI_CDC && !USB_G_HID && !USB_G_DBGP && !USB_G_WEBCAM && TTY
-       help
-         The Configurable Composite Gadget supports multiple USB
-         functions: acm, mass storage, rndis and FunctionFS.
-         Each function can be configured and enabled/disabled
-         dynamically from userspace through a sysfs interface.
-
-         In order to compile this (either as a module or built-in),
-         "USB Gadget Drivers" and anything under it must not be
-         selected compiled-in in
-         Device Drivers->USB Support->USB Gadget Support.
-         However, you can say "M" there, if you do, the
-         Configurable Composite Gadget can be compiled "M" only
-         or not at all.
-
-         BIG FAT NOTE: DON'T RELY ON THIS USERINTERFACE HERE! AS PART
-         OF THE REWORK DONE HERE WILL BE A NEW USER INTERFACE WITHOUT ANY
-         COMPATIBILITY TO THIS SYSFS INTERFACE HERE. BE AWARE OF THIS
-         BEFORE SELECTING THIS.
-
-endif # USB_GADGET
diff --git a/drivers/staging/ccg/Makefile b/drivers/staging/ccg/Makefile
deleted file mode 100644 (file)
index 814fa9d..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-g_ccg-y                                := ccg.o
-obj-$(CONFIG_USB_G_CCG)                += g_ccg.o
diff --git a/drivers/staging/ccg/TODO b/drivers/staging/ccg/TODO
deleted file mode 100644 (file)
index 18612fe..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-TODO:
-       - change configuration interface from sysfs to configfs
-
-Please send patches to Greg Kroah-Hartmann <gregkh@linuxfoundation.org>,
-Andrzej Pietrasiewicz <andrzej.p@samsung.com>, and
-Cc: Mike Lockwood <lockwood@android.com>
diff --git a/drivers/staging/ccg/ccg.c b/drivers/staging/ccg/ccg.c
deleted file mode 100644 (file)
index ffc5f73..0000000
+++ /dev/null
@@ -1,1292 +0,0 @@
-/*
- * Configurable Composite Gadget
- *
- * Initially contributed as "Android Composite Gdaget" by:
- *
- * Copyright (C) 2008 Google, Inc.
- * Author: Mike Lockwood <lockwood@android.com>
- *         Benoit Goby <benoit@android.com>
- *
- * Tailoring it to become a generic Configurable Composite Gadget is
- *
- * Copyright (C) 2012 Samsung Electronics
- * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * 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/init.h>
-#include <linux/module.h>
-#include <linux/fs.h>
-#include <linux/delay.h>
-#include <linux/kernel.h>
-#include <linux/utsname.h>
-#include <linux/platform_device.h>
-
-#include <linux/usb/ch9.h>
-#include "composite.h"
-#include <linux/usb/gadget.h>
-
-#include "gadget_chips.h"
-
-/*
- * Kbuild is not very cooperative with respect to linking separately
- * compiled library objects into one module.  So for now we won't use
- * separate compilation ... ensuring init/exit sections work to shrink
- * the runtime footprint, and giving us at least some parts of what
- * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
- */
-#include "usbstring.c"
-#include "config.c"
-#include "epautoconf.c"
-#include "composite.c"
-
-#include "f_mass_storage.c"
-#include "u_serial.c"
-#include "f_acm.c"
-#define USB_ETH_RNDIS y
-#include "f_rndis.c"
-#include "rndis.c"
-#include "u_ether.c"
-#include "f_fs.c"
-
-MODULE_AUTHOR("Mike Lockwood, Andrzej Pietrasiewicz");
-MODULE_DESCRIPTION("Configurable Composite USB Gadget");
-MODULE_LICENSE("GPL");
-MODULE_VERSION("1.0");
-
-static const char longname[] = "Configurable Composite Gadget";
-
-/* Default vendor and product IDs, overridden by userspace */
-#define VENDOR_ID              0x1d6b /* Linux Foundation */
-#define PRODUCT_ID             0x0107
-#define GFS_MAX_DEVS           10
-
-struct ccg_usb_function {
-       char *name;
-       void *config;
-
-       struct device *dev;
-       char *dev_name;
-       struct device_attribute **attributes;
-
-       /* for ccg_dev.enabled_functions */
-       struct list_head enabled_list;
-
-       /* Optional: initialization during gadget bind */
-       int (*init)(struct ccg_usb_function *, struct usb_composite_dev *);
-       /* Optional: cleanup during gadget unbind */
-       void (*cleanup)(struct ccg_usb_function *);
-
-       int (*bind_config)(struct ccg_usb_function *,
-                          struct usb_configuration *);
-
-       /* Optional: called when the configuration is removed */
-       void (*unbind_config)(struct ccg_usb_function *,
-                             struct usb_configuration *);
-       /* Optional: handle ctrl requests before the device is configured */
-       int (*ctrlrequest)(struct ccg_usb_function *,
-                          struct usb_composite_dev *,
-                          const struct usb_ctrlrequest *);
-};
-
-struct ffs_obj {
-       const char *name;
-       bool mounted;
-       bool desc_ready;
-       bool used;
-       struct ffs_data *ffs_data;
-};
-
-struct ccg_dev {
-       struct ccg_usb_function **functions;
-       struct list_head enabled_functions;
-       struct usb_composite_dev *cdev;
-       struct device *dev;
-
-       bool enabled;
-       struct mutex mutex;
-       bool connected;
-       bool sw_connected;
-       struct work_struct work;
-
-       unsigned int max_func_num;
-       unsigned int func_num;
-       struct ffs_obj ffs_tab[GFS_MAX_DEVS];
-};
-
-static struct class *ccg_class;
-static struct ccg_dev *_ccg_dev;
-static int ccg_bind_config(struct usb_configuration *c);
-static void ccg_unbind_config(struct usb_configuration *c);
-
-static char func_names_buf[256];
-
-static struct usb_device_descriptor device_desc = {
-       .bLength              = sizeof(device_desc),
-       .bDescriptorType      = USB_DT_DEVICE,
-       .bcdUSB               = __constant_cpu_to_le16(0x0200),
-       .bDeviceClass         = USB_CLASS_PER_INTERFACE,
-       .idVendor             = __constant_cpu_to_le16(VENDOR_ID),
-       .idProduct            = __constant_cpu_to_le16(PRODUCT_ID),
-       .bcdDevice            = __constant_cpu_to_le16(0xffff),
-       .bNumConfigurations   = 1,
-};
-
-static struct usb_configuration ccg_config_driver = {
-       .label          = "ccg",
-       .unbind         = ccg_unbind_config,
-       .bConfigurationValue = 1,
-       .bmAttributes   = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
-       .bMaxPower      = 0xFA, /* 500ma */
-};
-
-static void ccg_work(struct work_struct *data)
-{
-       struct ccg_dev *dev = container_of(data, struct ccg_dev, work);
-       struct usb_composite_dev *cdev = dev->cdev;
-       static char *disconnected[2] = { "USB_STATE=DISCONNECTED", NULL };
-       static char *connected[2]    = { "USB_STATE=CONNECTED", NULL };
-       static char *configured[2]   = { "USB_STATE=CONFIGURED", NULL };
-       char **uevent_envp = NULL;
-       unsigned long flags;
-
-       spin_lock_irqsave(&cdev->lock, flags);
-       if (cdev->config)
-               uevent_envp = configured;
-       else if (dev->connected != dev->sw_connected)
-               uevent_envp = dev->connected ? connected : disconnected;
-       dev->sw_connected = dev->connected;
-       spin_unlock_irqrestore(&cdev->lock, flags);
-
-       if (uevent_envp) {
-               kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, uevent_envp);
-               pr_info("%s: sent uevent %s\n", __func__, uevent_envp[0]);
-       } else {
-               pr_info("%s: did not send uevent (%d %d %p)\n", __func__,
-                        dev->connected, dev->sw_connected, cdev->config);
-       }
-}
-
-
-/*-------------------------------------------------------------------------*/
-/* Supported functions initialization */
-
-static struct ffs_obj *functionfs_find_dev(struct ccg_dev *dev,
-                                          const char *dev_name)
-{
-       int i;
-
-       for (i = 0; i < dev->max_func_num; i++)
-               if (strcmp(dev->ffs_tab[i].name, dev_name) == 0)
-                       return &dev->ffs_tab[i];
-
-       return NULL;
-}
-
-static bool functionfs_all_ready(struct ccg_dev *dev)
-{
-       int i;
-
-       for (i = 0; i < dev->max_func_num; i++)
-               if (dev->ffs_tab[i].used && !dev->ffs_tab[i].desc_ready)
-                       return false;
-
-       return true;
-}
-
-static int functionfs_ready_callback(struct ffs_data *ffs)
-{
-       struct ffs_obj *ffs_obj;
-       int ret;
-
-       mutex_lock(&_ccg_dev->mutex);
-
-       ffs_obj = ffs->private_data;
-       if (!ffs_obj) {
-               ret = -EINVAL;
-               goto done;
-       }
-       if (WARN_ON(ffs_obj->desc_ready)) {
-               ret = -EBUSY;
-               goto done;
-       }
-       ffs_obj->ffs_data = ffs;
-
-       if (functionfs_all_ready(_ccg_dev)) {
-               ret = -EBUSY;
-               goto done;
-       }
-       ffs_obj->desc_ready = true;
-
-done:
-       mutex_unlock(&_ccg_dev->mutex);
-       return ret;
-}
-
-static void reset_usb(struct ccg_dev *dev)
-{
-       /* Cancel pending control requests */
-       usb_ep_dequeue(dev->cdev->gadget->ep0, dev->cdev->req);
-       usb_remove_config(dev->cdev, &ccg_config_driver);
-       dev->enabled = false;
-       usb_gadget_disconnect(dev->cdev->gadget);
-}
-
-static void functionfs_closed_callback(struct ffs_data *ffs)
-{
-       struct ffs_obj *ffs_obj;
-
-       mutex_lock(&_ccg_dev->mutex);
-
-       ffs_obj = ffs->private_data;
-       if (!ffs_obj)
-               goto done;
-
-       ffs_obj->desc_ready = false;
-
-       if (_ccg_dev->enabled)
-               reset_usb(_ccg_dev);
-
-done:
-       mutex_unlock(&_ccg_dev->mutex);
-}
-
-static void *functionfs_acquire_dev_callback(const char *dev_name)
-{
-       struct ffs_obj *ffs_dev;
-
-       mutex_lock(&_ccg_dev->mutex);
-
-       ffs_dev = functionfs_find_dev(_ccg_dev, dev_name);
-       if (!ffs_dev) {
-               ffs_dev = ERR_PTR(-ENODEV);
-               goto done;
-       }
-
-       if (ffs_dev->mounted) {
-               ffs_dev = ERR_PTR(-EBUSY);
-               goto done;
-       }
-       ffs_dev->mounted = true;
-
-done:
-       mutex_unlock(&_ccg_dev->mutex);
-       return ffs_dev;
-}
-
-static void functionfs_release_dev_callback(struct ffs_data *ffs_data)
-{
-       struct ffs_obj *ffs_dev;
-
-       mutex_lock(&_ccg_dev->mutex);
-
-       ffs_dev = ffs_data->private_data;
-       if (ffs_dev)
-               ffs_dev->mounted = false;
-
-       mutex_unlock(&_ccg_dev->mutex);
-}
-
-static int functionfs_function_init(struct ccg_usb_function *f,
-                               struct usb_composite_dev *cdev)
-{
-       return functionfs_init();
-}
-
-static void functionfs_function_cleanup(struct ccg_usb_function *f)
-{
-       functionfs_cleanup();
-}
-
-static int functionfs_function_bind_config(struct ccg_usb_function *f,
-                                          struct usb_configuration *c)
-{
-       struct ccg_dev *dev = _ccg_dev;
-       int i, ret;
-
-       for (i = dev->max_func_num; i--; ) {
-               if (!dev->ffs_tab[i].used)
-                       continue;
-               ret = functionfs_bind(dev->ffs_tab[i].ffs_data, c->cdev);
-               if (unlikely(ret < 0)) {
-                       while (++i < dev->max_func_num)
-                               functionfs_unbind(dev->ffs_tab[i].ffs_data);
-                       return ret;
-               }
-       }
-
-       for (i = dev->max_func_num; i--; ) {
-               if (!dev->ffs_tab[i].used)
-                       continue;
-               ret = functionfs_bind_config(c->cdev, c,
-                                            dev->ffs_tab[i].ffs_data);
-               if (unlikely(ret < 0))
-                       return ret;
-       }
-
-       return 0;
-}
-
-static void functionfs_function_unbind_config(struct ccg_usb_function *f,
-                                             struct usb_configuration *c)
-{
-       struct ccg_dev *dev = _ccg_dev;
-       int i;
-
-       for (i = dev->max_func_num; i--; )
-               if (dev->ffs_tab[i].ffs_data)
-                       functionfs_unbind(dev->ffs_tab[i].ffs_data);
-}
-
-static ssize_t functionfs_user_functions_show(struct device *_dev,
-                                             struct device_attribute *attr,
-                                             char *buf)
-{
-       struct ccg_dev *dev = _ccg_dev;
-       char *buff = buf;
-       int i;
-
-       mutex_lock(&dev->mutex);
-
-       for (i = 0; i < dev->max_func_num; i++)
-               buff += snprintf(buff, PAGE_SIZE + buf - buff, "%s,",
-                                dev->ffs_tab[i].name);
-
-       mutex_unlock(&dev->mutex);
-
-       if (buff != buf)
-               *(buff - 1) = '\n';
-       return buff - buf;
-}
-
-static ssize_t functionfs_user_functions_store(struct device *_dev,
-                                              struct device_attribute *attr,
-                                              const char *buff, size_t size)
-{
-       struct ccg_dev *dev = _ccg_dev;
-       char *name, *b;
-       ssize_t ret = size;
-       int i;
-
-       buff = skip_spaces(buff);
-       if (!*buff)
-               return -EINVAL;
-
-       mutex_lock(&dev->mutex);
-
-       if (dev->enabled) {
-               ret = -EBUSY;
-               goto end;
-       }
-
-       for (i = 0; i < dev->max_func_num; i++)
-               if (dev->ffs_tab[i].mounted) {
-                       ret = -EBUSY;
-                       goto end;
-               }
-
-       strlcpy(func_names_buf, buff, sizeof(func_names_buf));
-       b = strim(func_names_buf);
-
-       /* replace the list of functions */
-       dev->max_func_num = 0;
-       while (b) {
-               name = strsep(&b, ",");
-               if (dev->max_func_num == GFS_MAX_DEVS) {
-                       ret = -ENOSPC;
-                       goto end;
-               }
-               if (functionfs_find_dev(dev, name)) {
-                       ret = -EEXIST;
-                       continue;
-               }
-               dev->ffs_tab[dev->max_func_num++].name = name;
-       }
-
-end:
-       mutex_unlock(&dev->mutex);
-       return ret;
-}
-
-static DEVICE_ATTR(user_functions, S_IRUGO | S_IWUSR,
-                  functionfs_user_functions_show,
-                  functionfs_user_functions_store);
-
-static ssize_t functionfs_max_user_functions_show(struct device *_dev,
-                                                 struct device_attribute *attr,
-                                                 char *buf)
-{
-       return sprintf(buf, "%d", GFS_MAX_DEVS);
-}
-
-static DEVICE_ATTR(max_user_functions, S_IRUGO,
-                  functionfs_max_user_functions_show, NULL);
-
-static struct device_attribute *functionfs_function_attributes[] = {
-       &dev_attr_user_functions,
-       &dev_attr_max_user_functions,
-       NULL
-};
-
-static struct ccg_usb_function functionfs_function = {
-       .name           = "fs",
-       .init           = functionfs_function_init,
-       .cleanup        = functionfs_function_cleanup,
-       .bind_config    = functionfs_function_bind_config,
-       .unbind_config  = functionfs_function_unbind_config,
-       .attributes     = functionfs_function_attributes,
-};
-
-#define MAX_ACM_INSTANCES 4
-struct acm_function_config {
-       int instances;
-};
-
-static int
-acm_function_init(struct ccg_usb_function *f, struct usb_composite_dev *cdev)
-{
-       f->config = kzalloc(sizeof(struct acm_function_config), GFP_KERNEL);
-       if (!f->config)
-               return -ENOMEM;
-
-       return gserial_setup(cdev->gadget, MAX_ACM_INSTANCES);
-}
-
-static void acm_function_cleanup(struct ccg_usb_function *f)
-{
-       gserial_cleanup();
-       kfree(f->config);
-       f->config = NULL;
-}
-
-static int
-acm_function_bind_config(struct ccg_usb_function *f,
-               struct usb_configuration *c)
-{
-       int i;
-       int ret = 0;
-       struct acm_function_config *config = f->config;
-
-       for (i = 0; i < config->instances; i++) {
-               ret = acm_bind_config(c, i);
-               if (ret) {
-                       pr_err("Could not bind acm%u config\n", i);
-                       break;
-               }
-       }
-
-       return ret;
-}
-
-static ssize_t acm_instances_show(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct ccg_usb_function *f = dev_get_drvdata(dev);
-       struct acm_function_config *config = f->config;
-       return sprintf(buf, "%d\n", config->instances);
-}
-
-static ssize_t acm_instances_store(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t size)
-{
-       struct ccg_usb_function *f = dev_get_drvdata(dev);
-       struct acm_function_config *config = f->config;
-       int value;
-       int ret = 0;
-
-       ret = kstrtoint(buf, 10, &value);
-       if (ret)
-               return ret;
-
-       if (value > MAX_ACM_INSTANCES)
-               return -EINVAL;
-
-       config->instances = value;
-
-       return size;
-}
-
-static DEVICE_ATTR(instances, S_IRUGO | S_IWUSR, acm_instances_show,
-                                                acm_instances_store);
-static struct device_attribute *acm_function_attributes[] = {
-       &dev_attr_instances,
-       NULL
-};
-
-static struct ccg_usb_function acm_function = {
-       .name           = "acm",
-       .init           = acm_function_init,
-       .cleanup        = acm_function_cleanup,
-       .bind_config    = acm_function_bind_config,
-       .attributes     = acm_function_attributes,
-};
-
-struct rndis_function_config {
-       u8      ethaddr[ETH_ALEN];
-       u32     vendorID;
-       char    manufacturer[256];
-       /* "Wireless" RNDIS; auto-detected by Windows */
-       bool    wceis;
-};
-
-static int rndis_function_init(struct ccg_usb_function *f,
-                              struct usb_composite_dev *cdev)
-{
-       f->config = kzalloc(sizeof(struct rndis_function_config), GFP_KERNEL);
-       if (!f->config)
-               return -ENOMEM;
-       return 0;
-}
-
-static void rndis_function_cleanup(struct ccg_usb_function *f)
-{
-       kfree(f->config);
-       f->config = NULL;
-}
-
-static int rndis_function_bind_config(struct ccg_usb_function *f,
-                                     struct usb_configuration *c)
-{
-       int ret;
-       struct rndis_function_config *rndis = f->config;
-
-       if (!rndis) {
-               pr_err("%s: rndis_pdata\n", __func__);
-               return -1;
-       }
-
-       pr_info("%s MAC: %pM\n", __func__, rndis->ethaddr);
-
-       ret = gether_setup_name(c->cdev->gadget, rndis->ethaddr, "rndis");
-       if (ret) {
-               pr_err("%s: gether_setup failed\n", __func__);
-               return ret;
-       }
-
-       if (rndis->wceis) {
-               /* "Wireless" RNDIS; auto-detected by Windows */
-               rndis_iad_descriptor.bFunctionClass =
-                                               USB_CLASS_WIRELESS_CONTROLLER;
-               rndis_iad_descriptor.bFunctionSubClass = 0x01;
-               rndis_iad_descriptor.bFunctionProtocol = 0x03;
-               rndis_control_intf.bInterfaceClass =
-                                               USB_CLASS_WIRELESS_CONTROLLER;
-               rndis_control_intf.bInterfaceSubClass =  0x01;
-               rndis_control_intf.bInterfaceProtocol =  0x03;
-       }
-
-       return rndis_bind_config_vendor(c, rndis->ethaddr, rndis->vendorID,
-                                          rndis->manufacturer);
-}
-
-static void rndis_function_unbind_config(struct ccg_usb_function *f,
-                                               struct usb_configuration *c)
-{
-       gether_cleanup();
-}
-
-static ssize_t rndis_manufacturer_show(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct ccg_usb_function *f = dev_get_drvdata(dev);
-       struct rndis_function_config *config = f->config;
-       return sprintf(buf, "%s\n", config->manufacturer);
-}
-
-static ssize_t rndis_manufacturer_store(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t size)
-{
-       struct ccg_usb_function *f = dev_get_drvdata(dev);
-       struct rndis_function_config *config = f->config;
-
-       if (size >= sizeof(config->manufacturer))
-               return -EINVAL;
-       memcpy(config->manufacturer, buf, size);
-       config->manufacturer[size] = 0;
-
-       return size;
-}
-
-static DEVICE_ATTR(manufacturer, S_IRUGO | S_IWUSR, rndis_manufacturer_show,
-                                                   rndis_manufacturer_store);
-
-static ssize_t rndis_wceis_show(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct ccg_usb_function *f = dev_get_drvdata(dev);
-       struct rndis_function_config *config = f->config;
-       return sprintf(buf, "%d\n", config->wceis);
-}
-
-static ssize_t rndis_wceis_store(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t size)
-{
-       struct ccg_usb_function *f = dev_get_drvdata(dev);
-       struct rndis_function_config *config = f->config;
-       int value;
-       int ret;
-
-       ret = kstrtoint(buf, 10, &value);
-       if (ret)
-               return ret;
-
-       config->wceis = value;
-
-       return size;
-}
-
-static DEVICE_ATTR(wceis, S_IRUGO | S_IWUSR, rndis_wceis_show,
-                                            rndis_wceis_store);
-
-static ssize_t rndis_ethaddr_show(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct ccg_usb_function *f = dev_get_drvdata(dev);
-       struct rndis_function_config *rndis = f->config;
-       return sprintf(buf, "%pM\n", rndis->ethaddr);
-}
-
-static ssize_t rndis_ethaddr_store(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t size)
-{
-       struct ccg_usb_function *f = dev_get_drvdata(dev);
-       struct rndis_function_config *rndis = f->config;
-       unsigned char tmp[6];
-
-       if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
-                  tmp + 0, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5) !=
-           ETH_ALEN)
-               return -EINVAL;
-
-       memcpy(rndis->ethaddr, tmp, ETH_ALEN);
-
-       return ETH_ALEN;
-
-}
-
-static DEVICE_ATTR(ethaddr, S_IRUGO | S_IWUSR, rndis_ethaddr_show,
-                                              rndis_ethaddr_store);
-
-static ssize_t rndis_vendorID_show(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct ccg_usb_function *f = dev_get_drvdata(dev);
-       struct rndis_function_config *config = f->config;
-       return sprintf(buf, "%04x\n", config->vendorID);
-}
-
-static ssize_t rndis_vendorID_store(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t size)
-{
-       struct ccg_usb_function *f = dev_get_drvdata(dev);
-       struct rndis_function_config *config = f->config;
-       int value;
-       int ret;
-
-       ret = kstrtou32(buf, 16, &value);
-       if (ret)
-               return ret;
-
-       config->vendorID = value;
-
-       return size;
-}
-
-static DEVICE_ATTR(vendorID, S_IRUGO | S_IWUSR, rndis_vendorID_show,
-                                               rndis_vendorID_store);
-
-static struct device_attribute *rndis_function_attributes[] = {
-       &dev_attr_manufacturer,
-       &dev_attr_wceis,
-       &dev_attr_ethaddr,
-       &dev_attr_vendorID,
-       NULL
-};
-
-static struct ccg_usb_function rndis_function = {
-       .name           = "rndis",
-       .init           = rndis_function_init,
-       .cleanup        = rndis_function_cleanup,
-       .bind_config    = rndis_function_bind_config,
-       .unbind_config  = rndis_function_unbind_config,
-       .attributes     = rndis_function_attributes,
-};
-
-static int mass_storage_function_init(struct ccg_usb_function *f,
-                                       struct usb_composite_dev *cdev)
-{
-       struct fsg_config fsg;
-       struct fsg_common *common;
-       int err;
-
-       memset(&fsg, 0, sizeof(fsg));
-       fsg.nluns = 1;
-       fsg.luns[0].removable = 1;
-       fsg.vendor_name = iManufacturer;
-       fsg.product_name = iProduct;
-
-       common = fsg_common_init(NULL, cdev, &fsg);
-       if (IS_ERR(common))
-               return PTR_ERR(common);
-
-       err = sysfs_create_link(&f->dev->kobj,
-                               &common->luns[0].dev.kobj,
-                               "lun");
-       if (err) {
-               fsg_common_put(common);
-               return err;
-       }
-
-       f->config = common;
-       return 0;
-}
-
-static void mass_storage_function_cleanup(struct ccg_usb_function *f)
-{
-       fsg_common_put(f->config);
-       f->config = NULL;
-}
-
-static int mass_storage_function_bind_config(struct ccg_usb_function *f,
-                                            struct usb_configuration *c)
-{
-       struct fsg_common *common = f->config;
-       return fsg_bind_config(c->cdev, c, common);
-}
-
-static struct ccg_usb_function mass_storage_function = {
-       .name           = "mass_storage",
-       .init           = mass_storage_function_init,
-       .cleanup        = mass_storage_function_cleanup,
-       .bind_config    = mass_storage_function_bind_config,
-};
-
-static struct ccg_usb_function *supported_functions[] = {
-       &functionfs_function,
-       &acm_function,
-       &rndis_function,
-       &mass_storage_function,
-       NULL
-};
-
-
-static int ccg_init_functions(struct ccg_usb_function **functions,
-                                 struct usb_composite_dev *cdev)
-{
-       struct ccg_dev *dev = _ccg_dev;
-       struct ccg_usb_function *f;
-       struct device_attribute **attrs;
-       struct device_attribute *attr;
-       int err;
-       int index = 0;
-
-       for (; (f = *functions++); index++) {
-               f->dev_name = kasprintf(GFP_KERNEL, "f_%s", f->name);
-               if (!f->dev_name) {
-                       pr_err("%s: Failed to alloc name %s", __func__,
-                              f->name);
-                       err = -ENOMEM;
-                       goto err_alloc;
-               }
-               f->dev = device_create(ccg_class, dev->dev,
-                               MKDEV(0, index), f, f->dev_name);
-               if (IS_ERR(f->dev)) {
-                       pr_err("%s: Failed to create dev %s", __func__,
-                                                       f->dev_name);
-                       err = PTR_ERR(f->dev);
-                       f->dev = NULL;
-                       goto err_create;
-               }
-
-               if (f->init) {
-                       err = f->init(f, cdev);
-                       if (err) {
-                               pr_err("%s: Failed to init %s", __func__,
-                                                               f->name);
-                               goto err_out;
-                       }
-               }
-
-               attrs = f->attributes;
-               if (attrs) {
-                       while ((attr = *attrs++) && !err)
-                               err = device_create_file(f->dev, attr);
-               }
-               if (err) {
-                       pr_err("%s: Failed to create function %s attributes",
-                                       __func__, f->name);
-                       goto err_uninit;
-               }
-       }
-       return 0;
-
-err_uninit:
-       if (f->cleanup)
-               f->cleanup(f);
-err_out:
-       device_destroy(ccg_class, f->dev->devt);
-       f->dev = NULL;
-err_create:
-       kfree(f->dev_name);
-err_alloc:
-       return err;
-}
-
-static void ccg_cleanup_functions(struct ccg_usb_function **functions)
-{
-       struct ccg_usb_function *f;
-
-       while (*functions) {
-               f = *functions++;
-
-               if (f->dev) {
-                       if (f->cleanup)
-                               f->cleanup(f);
-                       device_destroy(ccg_class, f->dev->devt);
-                       kfree(f->dev_name);
-               }
-       }
-}
-
-static int ccg_bind_enabled_functions(struct ccg_dev *dev,
-                                     struct usb_configuration *c)
-{
-       struct ccg_usb_function *f;
-       int ret;
-
-       list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
-               ret = f->bind_config(f, c);
-               if (ret) {
-                       pr_err("%s: %s failed", __func__, f->name);
-                       return ret;
-               }
-       }
-       return 0;
-}
-
-static void ccg_unbind_enabled_functions(struct ccg_dev *dev,
-                                        struct usb_configuration *c)
-{
-       struct ccg_usb_function *f;
-
-       list_for_each_entry(f, &dev->enabled_functions, enabled_list)
-               if (f->unbind_config)
-                       f->unbind_config(f, c);
-}
-
-static int ccg_enable_function(struct ccg_dev *dev, char *name)
-{
-       struct ccg_usb_function **functions = dev->functions;
-       struct ccg_usb_function *f;
-       while ((f = *functions++)) {
-               if (!strcmp(name, f->name)) {
-                       list_add_tail(&f->enabled_list,
-                                               &dev->enabled_functions);
-                       return 0;
-               }
-       }
-       return -EINVAL;
-}
-
-/*-------------------------------------------------------------------------*/
-/* /sys/class/ccg_usb/ccg%d/ interface */
-
-static ssize_t
-functions_show(struct device *pdev, struct device_attribute *attr, char *buf)
-{
-       struct ccg_dev *dev = dev_get_drvdata(pdev);
-       struct ccg_usb_function *f;
-       char *buff = buf;
-       int i;
-
-       mutex_lock(&dev->mutex);
-
-       list_for_each_entry(f, &dev->enabled_functions, enabled_list)
-               buff += sprintf(buff, "%s,", f->name);
-       for (i = 0; i < dev->max_func_num; i++)
-               if (dev->ffs_tab[i].used)
-                       buff += sprintf(buff, "%s", dev->ffs_tab[i].name);
-
-       mutex_unlock(&dev->mutex);
-
-       if (buff != buf)
-               *(buff-1) = '\n';
-       return buff - buf;
-}
-
-static ssize_t
-functions_store(struct device *pdev, struct device_attribute *attr,
-                              const char *buff, size_t size)
-{
-       struct ccg_dev *dev = dev_get_drvdata(pdev);
-       char *name;
-       char buf[256], *b;
-       int err, i;
-       bool functionfs_enabled;
-
-       buff = skip_spaces(buff);
-       if (!*buff)
-               return -EINVAL;
-
-       mutex_lock(&dev->mutex);
-
-       if (dev->enabled) {
-               mutex_unlock(&dev->mutex);
-               return -EBUSY;
-       }
-
-       INIT_LIST_HEAD(&dev->enabled_functions);
-       functionfs_enabled = false;
-       for (i = 0; i < dev->max_func_num; i++)
-               dev->ffs_tab[i].used = false;
-
-       strlcpy(buf, buff, sizeof(buf));
-       b = strim(buf);
-
-       while (b) {
-               struct ffs_obj *user_func;
-
-               name = strsep(&b, ",");
-               /* handle FunctionFS implicitly */
-               if (!strcmp(name, functionfs_function.name)) {
-                       pr_err("ccg_usb: Cannot explicitly enable '%s'", name);
-                       continue;
-               }
-               user_func = functionfs_find_dev(dev, name);
-               if (user_func)
-                       name = functionfs_function.name;
-               err = 0;
-               if (!user_func || !functionfs_enabled)
-                       err = ccg_enable_function(dev, name);
-               if (err)
-                       pr_err("ccg_usb: Cannot enable '%s'", name);
-               else if (user_func) {
-                       user_func->used = true;
-                       dev->func_num++;
-                       functionfs_enabled = true;
-               }
-       }
-
-       mutex_unlock(&dev->mutex);
-
-       return size;
-}
-
-static ssize_t enable_show(struct device *pdev, struct device_attribute *attr,
-                          char *buf)
-{
-       struct ccg_dev *dev = dev_get_drvdata(pdev);
-       return sprintf(buf, "%d\n", dev->enabled);
-}
-
-static ssize_t enable_store(struct device *pdev, struct device_attribute *attr,
-                           const char *buff, size_t size)
-{
-       struct ccg_dev *dev = dev_get_drvdata(pdev);
-       struct usb_composite_dev *cdev = dev->cdev;
-       int enabled = 0;
-
-       mutex_lock(&dev->mutex);
-       sscanf(buff, "%d", &enabled);
-       if (enabled && dev->func_num && !functionfs_all_ready(dev)) {
-               mutex_unlock(&dev->mutex);
-               return -ENODEV;
-       }
-
-       if (enabled && !dev->enabled) {
-               int ret;
-
-               cdev->next_string_id = 0;
-               /*
-                * Update values in composite driver's copy of
-                * device descriptor.
-                */
-               cdev->desc.bDeviceClass = device_desc.bDeviceClass;
-               cdev->desc.bDeviceSubClass = device_desc.bDeviceSubClass;
-               cdev->desc.bDeviceProtocol = device_desc.bDeviceProtocol;
-               cdev->desc.idVendor = idVendor;
-               cdev->desc.idProduct = idProduct;
-               cdev->desc.bcdDevice = bcdDevice;
-
-               usb_add_config(cdev, &ccg_config_driver, ccg_bind_config);
-               dev->enabled = true;
-               ret = usb_gadget_connect(cdev->gadget);
-               if (ret) {
-                       dev->enabled = false;
-                       usb_remove_config(cdev, &ccg_config_driver);
-               }
-       } else if (!enabled && dev->enabled) {
-               reset_usb(dev);
-       } else {
-               pr_err("ccg_usb: already %s\n",
-                       dev->enabled ? "enabled" : "disabled");
-       }
-
-       mutex_unlock(&dev->mutex);
-       return size;
-}
-
-static ssize_t state_show(struct device *pdev, struct device_attribute *attr,
-                          char *buf)
-{
-       struct ccg_dev *dev = dev_get_drvdata(pdev);
-       struct usb_composite_dev *cdev = dev->cdev;
-       char *state = "DISCONNECTED";
-       unsigned long flags;
-
-       if (!cdev)
-               goto out;
-
-       spin_lock_irqsave(&cdev->lock, flags);
-       if (cdev->config)
-               state = "CONFIGURED";
-       else if (dev->connected)
-               state = "CONNECTED";
-       spin_unlock_irqrestore(&cdev->lock, flags);
-out:
-       return sprintf(buf, "%s\n", state);
-}
-
-#define DESCRIPTOR_ATTR(field, format_string)                          \
-static ssize_t                                                         \
-field ## _show(struct device *dev, struct device_attribute *attr,      \
-               char *buf)                                              \
-{                                                                      \
-       return sprintf(buf, format_string, device_desc.field);          \
-}                                                                      \
-static ssize_t                                                         \
-field ## _store(struct device *dev, struct device_attribute *attr,     \
-               const char *buf, size_t size)                           \
-{                                                                      \
-       int value;                                                      \
-       if (sscanf(buf, format_string, &value) == 1) {                  \
-               device_desc.field = value;                              \
-               return size;                                            \
-       }                                                               \
-       return -1;                                                      \
-}                                                                      \
-static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, field ## _show, field ## _store);
-
-DESCRIPTOR_ATTR(bDeviceClass, "%d\n")
-DESCRIPTOR_ATTR(bDeviceSubClass, "%d\n")
-DESCRIPTOR_ATTR(bDeviceProtocol, "%d\n")
-
-static DEVICE_ATTR(functions, S_IRUGO | S_IWUSR, functions_show,
-                                                functions_store);
-static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, enable_show, enable_store);
-static DEVICE_ATTR(state, S_IRUGO, state_show, NULL);
-
-static struct device_attribute *ccg_usb_attributes[] = {
-       &dev_attr_bDeviceClass,
-       &dev_attr_bDeviceSubClass,
-       &dev_attr_bDeviceProtocol,
-       &dev_attr_functions,
-       &dev_attr_enable,
-       &dev_attr_state,
-       NULL
-};
-
-/*-------------------------------------------------------------------------*/
-/* Composite driver */
-
-static int ccg_bind_config(struct usb_configuration *c)
-{
-       struct ccg_dev *dev = _ccg_dev;
-       return ccg_bind_enabled_functions(dev, c);
-}
-
-static void ccg_unbind_config(struct usb_configuration *c)
-{
-       struct ccg_dev *dev = _ccg_dev;
-
-       ccg_unbind_enabled_functions(dev, c);
-
-       usb_ep_autoconfig_reset(dev->cdev->gadget);
-}
-
-static int ccg_bind(struct usb_composite_dev *cdev)
-{
-       struct ccg_dev *dev = _ccg_dev;
-       struct usb_gadget       *gadget = cdev->gadget;
-       int                     gcnum, ret;
-
-       /*
-        * Start disconnected. Userspace will connect the gadget once
-        * it is done configuring the functions.
-        */
-       usb_gadget_disconnect(gadget);
-
-       ret = ccg_init_functions(dev->functions, cdev);
-       if (ret)
-               return ret;
-
-       gcnum = usb_gadget_controller_number(gadget);
-       if (gcnum >= 0)
-               device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
-       else {
-               pr_warn("%s: controller '%s' not recognized\n",
-                       longname, gadget->name);
-               device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
-       }
-
-       usb_gadget_set_selfpowered(gadget);
-       dev->cdev = cdev;
-
-       return 0;
-}
-
-static int ccg_usb_unbind(struct usb_composite_dev *cdev)
-{
-       struct ccg_dev *dev = _ccg_dev;
-
-       cancel_work_sync(&dev->work);
-       ccg_cleanup_functions(dev->functions);
-       return 0;
-}
-
-static struct usb_composite_driver ccg_usb_driver = {
-       .name           = "configurable_usb",
-       .dev            = &device_desc,
-       .bind           = ccg_bind,
-       .unbind         = ccg_usb_unbind,
-       .needs_serial   = true,
-       .iManufacturer  = "Linux Foundation",
-       .iProduct       = longname,
-       .iSerialNumber  = "1234567890123456",
-};
-
-static int ccg_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c)
-{
-       struct ccg_dev          *dev = _ccg_dev;
-       struct usb_composite_dev        *cdev = get_gadget_data(gadget);
-       struct usb_request              *req = cdev->req;
-       struct ccg_usb_function *f;
-       int value = -EOPNOTSUPP;
-       unsigned long flags;
-
-       req->zero = 0;
-       req->complete = composite_setup_complete;
-       req->length = 0;
-       gadget->ep0->driver_data = cdev;
-
-       list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
-               if (f->ctrlrequest) {
-                       value = f->ctrlrequest(f, cdev, c);
-                       if (value >= 0)
-                               break;
-               }
-       }
-
-       if (value < 0)
-               value = composite_setup(gadget, c);
-
-       spin_lock_irqsave(&cdev->lock, flags);
-       if (!dev->connected) {
-               dev->connected = 1;
-               schedule_work(&dev->work);
-       } else if (c->bRequest == USB_REQ_SET_CONFIGURATION &&
-                                               cdev->config) {
-               schedule_work(&dev->work);
-       }
-       spin_unlock_irqrestore(&cdev->lock, flags);
-
-       return value;
-}
-
-static void ccg_disconnect(struct usb_gadget *gadget)
-{
-       struct ccg_dev *dev = _ccg_dev;
-       struct usb_composite_dev *cdev = get_gadget_data(gadget);
-       unsigned long flags;
-
-       composite_disconnect(gadget);
-
-       spin_lock_irqsave(&cdev->lock, flags);
-       dev->connected = 0;
-       schedule_work(&dev->work);
-       spin_unlock_irqrestore(&cdev->lock, flags);
-}
-
-static int ccg_create_device(struct ccg_dev *dev)
-{
-       struct device_attribute **attrs = ccg_usb_attributes;
-       struct device_attribute *attr;
-       int err;
-
-       dev->dev = device_create(ccg_class, NULL, MKDEV(0, 0), NULL, "ccg0");
-       if (IS_ERR(dev->dev))
-               return PTR_ERR(dev->dev);
-
-       dev_set_drvdata(dev->dev, dev);
-
-       while ((attr = *attrs++)) {
-               err = device_create_file(dev->dev, attr);
-               if (err) {
-                       device_destroy(ccg_class, dev->dev->devt);
-                       return err;
-               }
-       }
-       return 0;
-}
-
-
-static int __init ccg_init(void)
-{
-       struct ccg_dev *dev;
-       int err;
-
-       ccg_class = class_create(THIS_MODULE, "ccg_usb");
-       if (IS_ERR(ccg_class))
-               return PTR_ERR(ccg_class);
-
-       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
-       if (!dev) {
-               class_destroy(ccg_class);
-               return -ENOMEM;
-       }
-
-       dev->functions = supported_functions;
-       INIT_LIST_HEAD(&dev->enabled_functions);
-       INIT_WORK(&dev->work, ccg_work);
-       mutex_init(&dev->mutex);
-
-       err = ccg_create_device(dev);
-       if (err) {
-               class_destroy(ccg_class);
-               kfree(dev);
-               return err;
-       }
-
-       _ccg_dev = dev;
-
-       /* Override composite driver functions */
-       composite_driver.setup = ccg_setup;
-       composite_driver.disconnect = ccg_disconnect;
-
-       err = usb_composite_probe(&ccg_usb_driver);
-       if (err) {
-               class_destroy(ccg_class);
-               kfree(dev);
-       }
-
-       return err;
-}
-module_init(ccg_init);
-
-static void __exit ccg_exit(void)
-{
-       usb_composite_unregister(&ccg_usb_driver);
-       class_destroy(ccg_class);
-       kfree(_ccg_dev);
-       _ccg_dev = NULL;
-}
-module_exit(ccg_exit);
diff --git a/drivers/staging/ccg/composite.c b/drivers/staging/ccg/composite.c
deleted file mode 100644 (file)
index 228b457..0000000
+++ /dev/null
@@ -1,1688 +0,0 @@
-/*
- * composite.c - infrastructure for Composite USB Gadgets
- *
- * Copyright (C) 2006-2008 David Brownell
- *
- * 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.
- */
-
-/* #define VERBOSE_DEBUG */
-
-#include <linux/kallsyms.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/module.h>
-#include <linux/device.h>
-#include <linux/utsname.h>
-
-#include <linux/usb/composite.h>
-#include <asm/unaligned.h>
-
-/*
- * The code in this file is utility code, used to build a gadget driver
- * from one or more "function" drivers, one or more "configuration"
- * objects, and a "usb_composite_driver" by gluing them together along
- * with the relevant device-wide data.
- */
-
-/* big enough to hold our biggest descriptor */
-#define USB_BUFSIZ     1024
-
-static struct usb_composite_driver *composite;
-
-/* Some systems will need runtime overrides for the  product identifiers
- * published in the device descriptor, either numbers or strings or both.
- * String parameters are in UTF-8 (superset of ASCII's 7 bit characters).
- */
-
-static ushort idVendor;
-module_param(idVendor, ushort, 0644);
-MODULE_PARM_DESC(idVendor, "USB Vendor ID");
-
-static ushort idProduct;
-module_param(idProduct, ushort, 0644);
-MODULE_PARM_DESC(idProduct, "USB Product ID");
-
-static ushort bcdDevice;
-module_param(bcdDevice, ushort, 0644);
-MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)");
-
-static char *iManufacturer;
-module_param(iManufacturer, charp, 0644);
-MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string");
-
-static char *iProduct;
-module_param(iProduct, charp, 0644);
-MODULE_PARM_DESC(iProduct, "USB Product string");
-
-static char *iSerialNumber;
-module_param(iSerialNumber, charp, 0644);
-MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");
-
-static char composite_manufacturer[50];
-
-/*-------------------------------------------------------------------------*/
-/**
- * next_ep_desc() - advance to the next EP descriptor
- * @t: currect pointer within descriptor array
- *
- * Return: next EP descriptor or NULL
- *
- * Iterate over @t until either EP descriptor found or
- * NULL (that indicates end of list) encountered
- */
-static struct usb_descriptor_header**
-next_ep_desc(struct usb_descriptor_header **t)
-{
-       for (; *t; t++) {
-               if ((*t)->bDescriptorType == USB_DT_ENDPOINT)
-                       return t;
-       }
-       return NULL;
-}
-
-/*
- * for_each_ep_desc()- iterate over endpoint descriptors in the
- *             descriptors list
- * @start:     pointer within descriptor array.
- * @ep_desc:   endpoint descriptor to use as the loop cursor
- */
-#define for_each_ep_desc(start, ep_desc) \
-       for (ep_desc = next_ep_desc(start); \
-             ep_desc; ep_desc = next_ep_desc(ep_desc+1))
-
-/**
- * config_ep_by_speed() - configures the given endpoint
- * according to gadget speed.
- * @g: pointer to the gadget
- * @f: usb function
- * @_ep: the endpoint to configure
- *
- * Return: error code, 0 on success
- *
- * This function chooses the right descriptors for a given
- * endpoint according to gadget speed and saves it in the
- * endpoint desc field. If the endpoint already has a descriptor
- * assigned to it - overwrites it with currently corresponding
- * descriptor. The endpoint maxpacket field is updated according
- * to the chosen descriptor.
- * Note: the supplied function should hold all the descriptors
- * for supported speeds
- */
-int config_ep_by_speed(struct usb_gadget *g,
-                       struct usb_function *f,
-                       struct usb_ep *_ep)
-{
-       struct usb_composite_dev        *cdev = get_gadget_data(g);
-       struct usb_endpoint_descriptor *chosen_desc = NULL;
-       struct usb_descriptor_header **speed_desc = NULL;
-
-       struct usb_ss_ep_comp_descriptor *comp_desc = NULL;
-       int want_comp_desc = 0;
-
-       struct usb_descriptor_header **d_spd; /* cursor for speed desc */
-
-       if (!g || !f || !_ep)
-               return -EIO;
-
-       /* select desired speed */
-       switch (g->speed) {
-       case USB_SPEED_SUPER:
-               if (gadget_is_superspeed(g)) {
-                       speed_desc = f->ss_descriptors;
-                       want_comp_desc = 1;
-                       break;
-               }
-               /* else: Fall trough */
-       case USB_SPEED_HIGH:
-               if (gadget_is_dualspeed(g)) {
-                       speed_desc = f->hs_descriptors;
-                       break;
-               }
-               /* else: fall through */
-       default:
-               speed_desc = f->descriptors;
-       }
-       /* find descriptors */
-       for_each_ep_desc(speed_desc, d_spd) {
-               chosen_desc = (struct usb_endpoint_descriptor *)*d_spd;
-               if (chosen_desc->bEndpointAddress == _ep->address)
-                       goto ep_found;
-       }
-       return -EIO;
-
-ep_found:
-       /* commit results */
-       _ep->maxpacket = usb_endpoint_maxp(chosen_desc);
-       _ep->desc = chosen_desc;
-       _ep->comp_desc = NULL;
-       _ep->maxburst = 0;
-       _ep->mult = 0;
-       if (!want_comp_desc)
-               return 0;
-
-       /*
-        * Companion descriptor should follow EP descriptor
-        * USB 3.0 spec, #9.6.7
-        */
-       comp_desc = (struct usb_ss_ep_comp_descriptor *)*(++d_spd);
-       if (!comp_desc ||
-           (comp_desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP))
-               return -EIO;
-       _ep->comp_desc = comp_desc;
-       if (g->speed == USB_SPEED_SUPER) {
-               switch (usb_endpoint_type(_ep->desc)) {
-               case USB_ENDPOINT_XFER_ISOC:
-                       /* mult: bits 1:0 of bmAttributes */
-                       _ep->mult = comp_desc->bmAttributes & 0x3;
-               case USB_ENDPOINT_XFER_BULK:
-               case USB_ENDPOINT_XFER_INT:
-                       _ep->maxburst = comp_desc->bMaxBurst + 1;
-                       break;
-               default:
-                       if (comp_desc->bMaxBurst != 0)
-                               ERROR(cdev, "ep0 bMaxBurst must be 0\n");
-                       _ep->maxburst = 1;
-                       break;
-               }
-       }
-       return 0;
-}
-
-/**
- * usb_add_function() - add a function to a configuration
- * @config: the configuration
- * @function: the function being added
- * Context: single threaded during gadget setup
- *
- * After initialization, each configuration must have one or more
- * functions added to it.  Adding a function involves calling its @bind()
- * method to allocate resources such as interface and string identifiers
- * and endpoints.
- *
- * This function returns the value of the function's bind(), which is
- * zero for success else a negative errno value.
- */
-int usb_add_function(struct usb_configuration *config,
-               struct usb_function *function)
-{
-       int     value = -EINVAL;
-
-       DBG(config->cdev, "adding '%s'/%p to config '%s'/%p\n",
-                       function->name, function,
-                       config->label, config);
-
-       if (!function->set_alt || !function->disable)
-               goto done;
-
-       function->config = config;
-       list_add_tail(&function->list, &config->functions);
-
-       /* REVISIT *require* function->bind? */
-       if (function->bind) {
-               value = function->bind(config, function);
-               if (value < 0) {
-                       list_del(&function->list);
-                       function->config = NULL;
-               }
-       } else
-               value = 0;
-
-       /* We allow configurations that don't work at both speeds.
-        * If we run into a lowspeed Linux system, treat it the same
-        * as full speed ... it's the function drivers that will need
-        * to avoid bulk and ISO transfers.
-        */
-       if (!config->fullspeed && function->descriptors)
-               config->fullspeed = true;
-       if (!config->highspeed && function->hs_descriptors)
-               config->highspeed = true;
-       if (!config->superspeed && function->ss_descriptors)
-               config->superspeed = true;
-
-done:
-       if (value)
-               DBG(config->cdev, "adding '%s'/%p --> %d\n",
-                               function->name, function, value);
-       return value;
-}
-
-/**
- * usb_function_deactivate - prevent function and gadget enumeration
- * @function: the function that isn't yet ready to respond
- *
- * Blocks response of the gadget driver to host enumeration by
- * preventing the data line pullup from being activated.  This is
- * normally called during @bind() processing to change from the
- * initial "ready to respond" state, or when a required resource
- * becomes available.
- *
- * For example, drivers that serve as a passthrough to a userspace
- * daemon can block enumeration unless that daemon (such as an OBEX,
- * MTP, or print server) is ready to handle host requests.
- *
- * Not all systems support software control of their USB peripheral
- * data pullups.
- *
- * Returns zero on success, else negative errno.
- */
-int usb_function_deactivate(struct usb_function *function)
-{
-       struct usb_composite_dev        *cdev = function->config->cdev;
-       unsigned long                   flags;
-       int                             status = 0;
-
-       spin_lock_irqsave(&cdev->lock, flags);
-
-       if (cdev->deactivations == 0)
-               status = usb_gadget_disconnect(cdev->gadget);
-       if (status == 0)
-               cdev->deactivations++;
-
-       spin_unlock_irqrestore(&cdev->lock, flags);
-       return status;
-}
-
-/**
- * usb_function_activate - allow function and gadget enumeration
- * @function: function on which usb_function_activate() was called
- *
- * Reverses effect of usb_function_deactivate().  If no more functions
- * are delaying their activation, the gadget driver will respond to
- * host enumeration procedures.
- *
- * Returns zero on success, else negative errno.
- */
-int usb_function_activate(struct usb_function *function)
-{
-       struct usb_composite_dev        *cdev = function->config->cdev;
-       unsigned long                   flags;
-       int                             status = 0;
-
-       spin_lock_irqsave(&cdev->lock, flags);
-
-       if (WARN_ON(cdev->deactivations == 0))
-               status = -EINVAL;
-       else {
-               cdev->deactivations--;
-               if (cdev->deactivations == 0)
-                       status = usb_gadget_connect(cdev->gadget);
-       }
-
-       spin_unlock_irqrestore(&cdev->lock, flags);
-       return status;
-}
-
-/**
- * usb_interface_id() - allocate an unused interface ID
- * @config: configuration associated with the interface
- * @function: function handling the interface
- * Context: single threaded during gadget setup
- *
- * usb_interface_id() is called from usb_function.bind() callbacks to
- * allocate new interface IDs.  The function driver will then store that
- * ID in interface, association, CDC union, and other descriptors.  It
- * will also handle any control requests targeted at that interface,
- * particularly changing its altsetting via set_alt().  There may
- * also be class-specific or vendor-specific requests to handle.
- *
- * All interface identifier should be allocated using this routine, to
- * ensure that for example different functions don't wrongly assign
- * different meanings to the same identifier.  Note that since interface
- * identifiers are configuration-specific, functions used in more than
- * one configuration (or more than once in a given configuration) need
- * multiple versions of the relevant descriptors.
- *
- * Returns the interface ID which was allocated; or -ENODEV if no
- * more interface IDs can be allocated.
- */
-int usb_interface_id(struct usb_configuration *config,
-               struct usb_function *function)
-{
-       unsigned id = config->next_interface_id;
-
-       if (id < MAX_CONFIG_INTERFACES) {
-               config->interface[id] = function;
-               config->next_interface_id = id + 1;
-               return id;
-       }
-       return -ENODEV;
-}
-
-static int config_buf(struct usb_configuration *config,
-               enum usb_device_speed speed, void *buf, u8 type)
-{
-       struct usb_config_descriptor    *c = buf;
-       void                            *next = buf + USB_DT_CONFIG_SIZE;
-       int                             len = USB_BUFSIZ - USB_DT_CONFIG_SIZE;
-       struct usb_function             *f;
-       int                             status;
-
-       /* write the config descriptor */
-       c = buf;
-       c->bLength = USB_DT_CONFIG_SIZE;
-       c->bDescriptorType = type;
-       /* wTotalLength is written later */
-       c->bNumInterfaces = config->next_interface_id;
-       c->bConfigurationValue = config->bConfigurationValue;
-       c->iConfiguration = config->iConfiguration;
-       c->bmAttributes = USB_CONFIG_ATT_ONE | config->bmAttributes;
-       c->bMaxPower = config->bMaxPower ? : (CONFIG_USB_GADGET_VBUS_DRAW / 2);
-
-       /* There may be e.g. OTG descriptors */
-       if (config->descriptors) {
-               status = usb_descriptor_fillbuf(next, len,
-                               config->descriptors);
-               if (status < 0)
-                       return status;
-               len -= status;
-               next += status;
-       }
-
-       /* add each function's descriptors */
-       list_for_each_entry(f, &config->functions, list) {
-               struct usb_descriptor_header **descriptors;
-
-               switch (speed) {
-               case USB_SPEED_SUPER:
-                       descriptors = f->ss_descriptors;
-                       break;
-               case USB_SPEED_HIGH:
-                       descriptors = f->hs_descriptors;
-                       break;
-               default:
-                       descriptors = f->descriptors;
-               }
-
-               if (!descriptors)
-                       continue;
-               status = usb_descriptor_fillbuf(next, len,
-                       (const struct usb_descriptor_header **) descriptors);
-               if (status < 0)
-                       return status;
-               len -= status;
-               next += status;
-       }
-
-       len = next - buf;
-       c->wTotalLength = cpu_to_le16(len);
-       return len;
-}
-
-static int config_desc(struct usb_composite_dev *cdev, unsigned w_value)
-{
-       struct usb_gadget               *gadget = cdev->gadget;
-       struct usb_configuration        *c;
-       u8                              type = w_value >> 8;
-       enum usb_device_speed           speed = USB_SPEED_UNKNOWN;
-
-       if (gadget->speed == USB_SPEED_SUPER)
-               speed = gadget->speed;
-       else if (gadget_is_dualspeed(gadget)) {
-               int     hs = 0;
-               if (gadget->speed == USB_SPEED_HIGH)
-                       hs = 1;
-               if (type == USB_DT_OTHER_SPEED_CONFIG)
-                       hs = !hs;
-               if (hs)
-                       speed = USB_SPEED_HIGH;
-
-       }
-
-       /* This is a lookup by config *INDEX* */
-       w_value &= 0xff;
-       list_for_each_entry(c, &cdev->configs, list) {
-               /* ignore configs that won't work at this speed */
-               switch (speed) {
-               case USB_SPEED_SUPER:
-                       if (!c->superspeed)
-                               continue;
-                       break;
-               case USB_SPEED_HIGH:
-                       if (!c->highspeed)
-                               continue;
-                       break;
-               default:
-                       if (!c->fullspeed)
-                               continue;
-               }
-
-               if (w_value == 0)
-                       return config_buf(c, speed, cdev->req->buf, type);
-               w_value--;
-       }
-       return -EINVAL;
-}
-
-static int count_configs(struct usb_composite_dev *cdev, unsigned type)
-{
-       struct usb_gadget               *gadget = cdev->gadget;
-       struct usb_configuration        *c;
-       unsigned                        count = 0;
-       int                             hs = 0;
-       int                             ss = 0;
-
-       if (gadget_is_dualspeed(gadget)) {
-               if (gadget->speed == USB_SPEED_HIGH)
-                       hs = 1;
-               if (gadget->speed == USB_SPEED_SUPER)
-                       ss = 1;
-               if (type == USB_DT_DEVICE_QUALIFIER)
-                       hs = !hs;
-       }
-       list_for_each_entry(c, &cdev->configs, list) {
-               /* ignore configs that won't work at this speed */
-               if (ss) {
-                       if (!c->superspeed)
-                               continue;
-               } else if (hs) {
-                       if (!c->highspeed)
-                               continue;
-               } else {
-                       if (!c->fullspeed)
-                               continue;
-               }
-               count++;
-       }
-       return count;
-}
-
-/**
- * bos_desc() - prepares the BOS descriptor.
- * @cdev: pointer to usb_composite device to generate the bos
- *     descriptor for
- *
- * This function generates the BOS (Binary Device Object)
- * descriptor and its device capabilities descriptors. The BOS
- * descriptor should be supported by a SuperSpeed device.
- */
-static int bos_desc(struct usb_composite_dev *cdev)
-{
-       struct usb_ext_cap_descriptor   *usb_ext;
-       struct usb_ss_cap_descriptor    *ss_cap;
-       struct usb_dcd_config_params    dcd_config_params;
-       struct usb_bos_descriptor       *bos = cdev->req->buf;
-
-       bos->bLength = USB_DT_BOS_SIZE;
-       bos->bDescriptorType = USB_DT_BOS;
-
-       bos->wTotalLength = cpu_to_le16(USB_DT_BOS_SIZE);
-       bos->bNumDeviceCaps = 0;
-
-       /*
-        * A SuperSpeed device shall include the USB2.0 extension descriptor
-        * and shall support LPM when operating in USB2.0 HS mode.
-        */
-       usb_ext = cdev->req->buf + le16_to_cpu(bos->wTotalLength);
-       bos->bNumDeviceCaps++;
-       le16_add_cpu(&bos->wTotalLength, USB_DT_USB_EXT_CAP_SIZE);
-       usb_ext->bLength = USB_DT_USB_EXT_CAP_SIZE;
-       usb_ext->bDescriptorType = USB_DT_DEVICE_CAPABILITY;
-       usb_ext->bDevCapabilityType = USB_CAP_TYPE_EXT;
-       usb_ext->bmAttributes = cpu_to_le32(USB_LPM_SUPPORT);
-
-       /*
-        * The Superspeed USB Capability descriptor shall be implemented by all
-        * SuperSpeed devices.
-        */
-       ss_cap = cdev->req->buf + le16_to_cpu(bos->wTotalLength);
-       bos->bNumDeviceCaps++;
-       le16_add_cpu(&bos->wTotalLength, USB_DT_USB_SS_CAP_SIZE);
-       ss_cap->bLength = USB_DT_USB_SS_CAP_SIZE;
-       ss_cap->bDescriptorType = USB_DT_DEVICE_CAPABILITY;
-       ss_cap->bDevCapabilityType = USB_SS_CAP_TYPE;
-       ss_cap->bmAttributes = 0; /* LTM is not supported yet */
-       ss_cap->wSpeedSupported = cpu_to_le16(USB_LOW_SPEED_OPERATION |
-                               USB_FULL_SPEED_OPERATION |
-                               USB_HIGH_SPEED_OPERATION |
-                               USB_5GBPS_OPERATION);
-       ss_cap->bFunctionalitySupport = USB_LOW_SPEED_OPERATION;
-
-       /* Get Controller configuration */
-       if (cdev->gadget->ops->get_config_params)
-               cdev->gadget->ops->get_config_params(&dcd_config_params);
-       else {
-               dcd_config_params.bU1devExitLat = USB_DEFAULT_U1_DEV_EXIT_LAT;
-               dcd_config_params.bU2DevExitLat =
-                       cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT);
-       }
-       ss_cap->bU1devExitLat = dcd_config_params.bU1devExitLat;
-       ss_cap->bU2DevExitLat = dcd_config_params.bU2DevExitLat;
-
-       return le16_to_cpu(bos->wTotalLength);
-}
-
-static void device_qual(struct usb_composite_dev *cdev)
-{
-       struct usb_qualifier_descriptor *qual = cdev->req->buf;
-
-       qual->bLength = sizeof(*qual);
-       qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER;
-       /* POLICY: same bcdUSB and device type info at both speeds */
-       qual->bcdUSB = cdev->desc.bcdUSB;
-       qual->bDeviceClass = cdev->desc.bDeviceClass;
-       qual->bDeviceSubClass = cdev->desc.bDeviceSubClass;
-       qual->bDeviceProtocol = cdev->desc.bDeviceProtocol;
-       /* ASSUME same EP0 fifo size at both speeds */
-       qual->bMaxPacketSize0 = cdev->gadget->ep0->maxpacket;
-       qual->bNumConfigurations = count_configs(cdev, USB_DT_DEVICE_QUALIFIER);
-       qual->bRESERVED = 0;
-}
-
-/*-------------------------------------------------------------------------*/
-
-static void reset_config(struct usb_composite_dev *cdev)
-{
-       struct usb_function             *f;
-
-       DBG(cdev, "reset config\n");
-
-       list_for_each_entry(f, &cdev->config->functions, list) {
-               if (f->disable)
-                       f->disable(f);
-
-               bitmap_zero(f->endpoints, 32);
-       }
-       cdev->config = NULL;
-}
-
-static int set_config(struct usb_composite_dev *cdev,
-               const struct usb_ctrlrequest *ctrl, unsigned number)
-{
-       struct usb_gadget       *gadget = cdev->gadget;
-       struct usb_configuration *c = NULL;
-       int                     result = -EINVAL;
-       unsigned                power = gadget_is_otg(gadget) ? 8 : 100;
-       int                     tmp;
-
-       if (number) {
-               list_for_each_entry(c, &cdev->configs, list) {
-                       if (c->bConfigurationValue == number) {
-                               /*
-                                * We disable the FDs of the previous
-                                * configuration only if the new configuration
-                                * is a valid one
-                                */
-                               if (cdev->config)
-                                       reset_config(cdev);
-                               result = 0;
-                               break;
-                       }
-               }
-               if (result < 0)
-                       goto done;
-       } else { /* Zero configuration value - need to reset the config */
-               if (cdev->config)
-                       reset_config(cdev);
-               result = 0;
-       }
-
-       INFO(cdev, "%s config #%d: %s\n",
-            usb_speed_string(gadget->speed),
-            number, c ? c->label : "unconfigured");
-
-       if (!c)
-               goto done;
-
-       cdev->config = c;
-
-       /* Initialize all interfaces by setting them to altsetting zero. */
-       for (tmp = 0; tmp < MAX_CONFIG_INTERFACES; tmp++) {
-               struct usb_function     *f = c->interface[tmp];
-               struct usb_descriptor_header **descriptors;
-
-               if (!f)
-                       break;
-
-               /*
-                * Record which endpoints are used by the function. This is used
-                * to dispatch control requests targeted at that endpoint to the
-                * function's setup callback instead of the current
-                * configuration's setup callback.
-                */
-               switch (gadget->speed) {
-               case USB_SPEED_SUPER:
-                       descriptors = f->ss_descriptors;
-                       break;
-               case USB_SPEED_HIGH:
-                       descriptors = f->hs_descriptors;
-                       break;
-               default:
-                       descriptors = f->descriptors;
-               }
-
-               for (; *descriptors; ++descriptors) {
-                       struct usb_endpoint_descriptor *ep;
-                       int addr;
-
-                       if ((*descriptors)->bDescriptorType != USB_DT_ENDPOINT)
-                               continue;
-
-                       ep = (struct usb_endpoint_descriptor *)*descriptors;
-                       addr = ((ep->bEndpointAddress & 0x80) >> 3)
-                            |  (ep->bEndpointAddress & 0x0f);
-                       set_bit(addr, f->endpoints);
-               }
-
-               result = f->set_alt(f, tmp, 0);
-               if (result < 0) {
-                       DBG(cdev, "interface %d (%s/%p) alt 0 --> %d\n",
-                                       tmp, f->name, f, result);
-
-                       reset_config(cdev);
-                       goto done;
-               }
-
-               if (result == USB_GADGET_DELAYED_STATUS) {
-                       DBG(cdev,
-                        "%s: interface %d (%s) requested delayed status\n",
-                                       __func__, tmp, f->name);
-                       cdev->delayed_status++;
-                       DBG(cdev, "delayed_status count %d\n",
-                                       cdev->delayed_status);
-               }
-       }
-
-       /* when we return, be sure our power usage is valid */
-       power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW;
-done:
-       usb_gadget_vbus_draw(gadget, power);
-       if (result >= 0 && cdev->delayed_status)
-               result = USB_GADGET_DELAYED_STATUS;
-       return result;
-}
-
-/**
- * usb_add_config() - add a configuration to a device.
- * @cdev: wraps the USB gadget
- * @config: the configuration, with bConfigurationValue assigned
- * @bind: the configuration's bind function
- * Context: single threaded during gadget setup
- *
- * One of the main tasks of a composite @bind() routine is to
- * add each of the configurations it supports, using this routine.
- *
- * This function returns the value of the configuration's @bind(), which
- * is zero for success else a negative errno value.  Binding configurations
- * assigns global resources including string IDs, and per-configuration
- * resources such as interface IDs and endpoints.
- */
-int usb_add_config(struct usb_composite_dev *cdev,
-               struct usb_configuration *config,
-               int (*bind)(struct usb_configuration *))
-{
-       int                             status = -EINVAL;
-       struct usb_configuration        *c;
-
-       DBG(cdev, "adding config #%u '%s'/%p\n",
-                       config->bConfigurationValue,
-                       config->label, config);
-
-       if (!config->bConfigurationValue || !bind)
-               goto done;
-
-       /* Prevent duplicate configuration identifiers */
-       list_for_each_entry(c, &cdev->configs, list) {
-               if (c->bConfigurationValue == config->bConfigurationValue) {
-                       status = -EBUSY;
-                       goto done;
-               }
-       }
-
-       config->cdev = cdev;
-       list_add_tail(&config->list, &cdev->configs);
-
-       INIT_LIST_HEAD(&config->functions);
-       config->next_interface_id = 0;
-       memset(config->interface, 0, sizeof(config->interface));
-
-       status = bind(config);
-       if (status < 0) {
-               while (!list_empty(&config->functions)) {
-                       struct usb_function             *f;
-
-                       f = list_first_entry(&config->functions,
-                                       struct usb_function, list);
-                       list_del(&f->list);
-                       if (f->unbind) {
-                               DBG(cdev, "unbind function '%s'/%p\n",
-                                       f->name, f);
-                               f->unbind(config, f);
-                               /* may free memory for "f" */
-                       }
-               }
-               list_del(&config->list);
-               config->cdev = NULL;
-       } else {
-               unsigned        i;
-
-               DBG(cdev, "cfg %d/%p speeds:%s%s%s\n",
-                       config->bConfigurationValue, config,
-                       config->superspeed ? " super" : "",
-                       config->highspeed ? " high" : "",
-                       config->fullspeed
-                               ? (gadget_is_dualspeed(cdev->gadget)
-                                       ? " full"
-                                       : " full/low")
-                               : "");
-
-               for (i = 0; i < MAX_CONFIG_INTERFACES; i++) {
-                       struct usb_function     *f = config->interface[i];
-
-                       if (!f)
-                               continue;
-                       DBG(cdev, "  interface %d = %s/%p\n",
-                               i, f->name, f);
-               }
-       }
-
-       /* set_alt(), or next bind(), sets up
-        * ep->driver_data as needed.
-        */
-       usb_ep_autoconfig_reset(cdev->gadget);
-
-done:
-       if (status)
-               DBG(cdev, "added config '%s'/%u --> %d\n", config->label,
-                               config->bConfigurationValue, status);
-       return status;
-}
-
-static void remove_config(struct usb_composite_dev *cdev,
-                             struct usb_configuration *config)
-{
-       while (!list_empty(&config->functions)) {
-               struct usb_function             *f;
-
-               f = list_first_entry(&config->functions,
-                               struct usb_function, list);
-               list_del(&f->list);
-               if (f->unbind) {
-                       DBG(cdev, "unbind function '%s'/%p\n", f->name, f);
-                       f->unbind(config, f);
-                       /* may free memory for "f" */
-               }
-       }
-       list_del(&config->list);
-       if (config->unbind) {
-               DBG(cdev, "unbind config '%s'/%p\n", config->label, config);
-               config->unbind(config);
-                       /* may free memory for "c" */
-       }
-}
-
-/**
- * usb_remove_config() - remove a configuration from a device.
- * @cdev: wraps the USB gadget
- * @config: the configuration
- *
- * Drivers must call usb_gadget_disconnect before calling this function
- * to disconnect the device from the host and make sure the host will not
- * try to enumerate the device while we are changing the config list.
- */
-void usb_remove_config(struct usb_composite_dev *cdev,
-                     struct usb_configuration *config)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&cdev->lock, flags);
-
-       if (cdev->config == config)
-               reset_config(cdev);
-
-       spin_unlock_irqrestore(&cdev->lock, flags);
-
-       remove_config(cdev, config);
-}
-
-/*-------------------------------------------------------------------------*/
-
-/* We support strings in multiple languages ... string descriptor zero
- * says which languages are supported.  The typical case will be that
- * only one language (probably English) is used, with I18N handled on
- * the host side.
- */
-
-static void collect_langs(struct usb_gadget_strings **sp, __le16 *buf)
-{
-       const struct usb_gadget_strings *s;
-       __le16                          language;
-       __le16                          *tmp;
-
-       while (*sp) {
-               s = *sp;
-               language = cpu_to_le16(s->language);
-               for (tmp = buf; *tmp && tmp < &buf[126]; tmp++) {
-                       if (*tmp == language)
-                               goto repeat;
-               }
-               *tmp++ = language;
-repeat:
-               sp++;
-       }
-}
-
-static int lookup_string(
-       struct usb_gadget_strings       **sp,
-       void                            *buf,
-       u16                             language,
-       int                             id
-)
-{
-       struct usb_gadget_strings       *s;
-       int                             value;
-
-       while (*sp) {
-               s = *sp++;
-               if (s->language != language)
-                       continue;
-               value = usb_gadget_get_string(s, id, buf);
-               if (value > 0)
-                       return value;
-       }
-       return -EINVAL;
-}
-
-static int get_string(struct usb_composite_dev *cdev,
-               void *buf, u16 language, int id)
-{
-       struct usb_configuration        *c;
-       struct usb_function             *f;
-       int                             len;
-       const char                      *str;
-
-       /* Yes, not only is USB's I18N support probably more than most
-        * folk will ever care about ... also, it's all supported here.
-        * (Except for UTF8 support for Unicode's "Astral Planes".)
-        */
-
-       /* 0 == report all available language codes */
-       if (id == 0) {
-               struct usb_string_descriptor    *s = buf;
-               struct usb_gadget_strings       **sp;
-
-               memset(s, 0, 256);
-               s->bDescriptorType = USB_DT_STRING;
-
-               sp = composite->strings;
-               if (sp)
-                       collect_langs(sp, s->wData);
-
-               list_for_each_entry(c, &cdev->configs, list) {
-                       sp = c->strings;
-                       if (sp)
-                               collect_langs(sp, s->wData);
-
-                       list_for_each_entry(f, &c->functions, list) {
-                               sp = f->strings;
-                               if (sp)
-                                       collect_langs(sp, s->wData);
-                       }
-               }
-
-               for (len = 0; len <= 126 && s->wData[len]; len++)
-                       continue;
-               if (!len)
-                       return -EINVAL;
-
-               s->bLength = 2 * (len + 1);
-               return s->bLength;
-       }
-
-       /* Otherwise, look up and return a specified string.  First
-        * check if the string has not been overridden.
-        */
-       if (cdev->manufacturer_override == id)
-               str = iManufacturer ?: composite->iManufacturer ?:
-                       composite_manufacturer;
-       else if (cdev->product_override == id)
-               str = iProduct ?: composite->iProduct;
-       else if (cdev->serial_override == id)
-               str = iSerialNumber ?: composite->iSerialNumber;
-       else
-               str = NULL;
-       if (str) {
-               struct usb_gadget_strings strings = {
-                       .language = language,
-                       .strings  = &(struct usb_string) { 0xff, str }
-               };
-               return usb_gadget_get_string(&strings, 0xff, buf);
-       }
-
-       /* String IDs are device-scoped, so we look up each string
-        * table we're told about.  These lookups are infrequent;
-        * simpler-is-better here.
-        */
-       if (composite->strings) {
-               len = lookup_string(composite->strings, buf, language, id);
-               if (len > 0)
-                       return len;
-       }
-       list_for_each_entry(c, &cdev->configs, list) {
-               if (c->strings) {
-                       len = lookup_string(c->strings, buf, language, id);
-                       if (len > 0)
-                               return len;
-               }
-               list_for_each_entry(f, &c->functions, list) {
-                       if (!f->strings)
-                               continue;
-                       len = lookup_string(f->strings, buf, language, id);
-                       if (len > 0)
-                               return len;
-               }
-       }
-       return -EINVAL;
-}
-
-/**
- * usb_string_id() - allocate an unused string ID
- * @cdev: the device whose string descriptor IDs are being allocated
- * Context: single threaded during gadget setup
- *
- * @usb_string_id() is called from bind() callbacks to allocate
- * string IDs.  Drivers for functions, configurations, or gadgets will
- * then store that ID in the appropriate descriptors and string table.
- *
- * All string identifier should be allocated using this,
- * @usb_string_ids_tab() or @usb_string_ids_n() routine, to ensure
- * that for example different functions don't wrongly assign different
- * meanings to the same identifier.
- */
-int usb_string_id(struct usb_composite_dev *cdev)
-{
-       if (cdev->next_string_id < 254) {
-               /* string id 0 is reserved by USB spec for list of
-                * supported languages */
-               /* 255 reserved as well? -- mina86 */
-               cdev->next_string_id++;
-               return cdev->next_string_id;
-       }
-       return -ENODEV;
-}
-
-/**
- * usb_string_ids() - allocate unused string IDs in batch
- * @cdev: the device whose string descriptor IDs are being allocated
- * @str: an array of usb_string objects to assign numbers to
- * Context: single threaded during gadget setup
- *
- * @usb_string_ids() is called from bind() callbacks to allocate
- * string IDs.  Drivers for functions, configurations, or gadgets will
- * then copy IDs from the string table to the appropriate descriptors
- * and string table for other languages.
- *
- * All string identifier should be allocated using this,
- * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
- * example different functions don't wrongly assign different meanings
- * to the same identifier.
- */
-int usb_string_ids_tab(struct usb_composite_dev *cdev, struct usb_string *str)
-{
-       int next = cdev->next_string_id;
-
-       for (; str->s; ++str) {
-               if (unlikely(next >= 254))
-                       return -ENODEV;
-               str->id = ++next;
-       }
-
-       cdev->next_string_id = next;
-
-       return 0;
-}
-
-/**
- * usb_string_ids_n() - allocate unused string IDs in batch
- * @c: the device whose string descriptor IDs are being allocated
- * @n: number of string IDs to allocate
- * Context: single threaded during gadget setup
- *
- * Returns the first requested ID.  This ID and next @n-1 IDs are now
- * valid IDs.  At least provided that @n is non-zero because if it
- * is, returns last requested ID which is now very useful information.
- *
- * @usb_string_ids_n() is called from bind() callbacks to allocate
- * string IDs.  Drivers for functions, configurations, or gadgets will
- * then store that ID in the appropriate descriptors and string table.
- *
- * All string identifier should be allocated using this,
- * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
- * example different functions don't wrongly assign different meanings
- * to the same identifier.
- */
-int usb_string_ids_n(struct usb_composite_dev *c, unsigned n)
-{
-       unsigned next = c->next_string_id;
-       if (unlikely(n > 254 || (unsigned)next + n > 254))
-               return -ENODEV;
-       c->next_string_id += n;
-       return next + 1;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       if (req->status || req->actual != req->length)
-               DBG((struct usb_composite_dev *) ep->driver_data,
-                               "setup complete --> %d, %d/%d\n",
-                               req->status, req->actual, req->length);
-}
-
-/*
- * The setup() callback implements all the ep0 functionality that's
- * not handled lower down, in hardware or the hardware driver(like
- * device and endpoint feature flags, and their status).  It's all
- * housekeeping for the gadget function we're implementing.  Most of
- * the work is in config and function specific setup.
- */
-static int
-composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
-{
-       struct usb_composite_dev        *cdev = get_gadget_data(gadget);
-       struct usb_request              *req = cdev->req;
-       int                             value = -EOPNOTSUPP;
-       int                             status = 0;
-       u16                             w_index = le16_to_cpu(ctrl->wIndex);
-       u8                              intf = w_index & 0xFF;
-       u16                             w_value = le16_to_cpu(ctrl->wValue);
-       u16                             w_length = le16_to_cpu(ctrl->wLength);
-       struct usb_function             *f = NULL;
-       u8                              endp;
-
-       /* partial re-init of the response message; the function or the
-        * gadget might need to intercept e.g. a control-OUT completion
-        * when we delegate to it.
-        */
-       req->zero = 0;
-       req->complete = composite_setup_complete;
-       req->length = 0;
-       gadget->ep0->driver_data = cdev;
-
-       switch (ctrl->bRequest) {
-
-       /* we handle all standard USB descriptors */
-       case USB_REQ_GET_DESCRIPTOR:
-               if (ctrl->bRequestType != USB_DIR_IN)
-                       goto unknown;
-               switch (w_value >> 8) {
-
-               case USB_DT_DEVICE:
-                       cdev->desc.bNumConfigurations =
-                               count_configs(cdev, USB_DT_DEVICE);
-                       cdev->desc.bMaxPacketSize0 =
-                               cdev->gadget->ep0->maxpacket;
-                       if (gadget_is_superspeed(gadget)) {
-                               if (gadget->speed >= USB_SPEED_SUPER) {
-                                       cdev->desc.bcdUSB = cpu_to_le16(0x0300);
-                                       cdev->desc.bMaxPacketSize0 = 9;
-                               } else {
-                                       cdev->desc.bcdUSB = cpu_to_le16(0x0210);
-                               }
-                       }
-
-                       value = min(w_length, (u16) sizeof cdev->desc);
-                       memcpy(req->buf, &cdev->desc, value);
-                       break;
-               case USB_DT_DEVICE_QUALIFIER:
-                       if (!gadget_is_dualspeed(gadget) ||
-                           gadget->speed >= USB_SPEED_SUPER)
-                               break;
-                       device_qual(cdev);
-                       value = min_t(int, w_length,
-                               sizeof(struct usb_qualifier_descriptor));
-                       break;
-               case USB_DT_OTHER_SPEED_CONFIG:
-                       if (!gadget_is_dualspeed(gadget) ||
-                           gadget->speed >= USB_SPEED_SUPER)
-                               break;
-                       /* FALLTHROUGH */
-               case USB_DT_CONFIG:
-                       value = config_desc(cdev, w_value);
-                       if (value >= 0)
-                               value = min(w_length, (u16) value);
-                       break;
-               case USB_DT_STRING:
-                       value = get_string(cdev, req->buf,
-                                       w_index, w_value & 0xff);
-                       if (value >= 0)
-                               value = min(w_length, (u16) value);
-                       break;
-               case USB_DT_BOS:
-                       if (gadget_is_superspeed(gadget)) {
-                               value = bos_desc(cdev);
-                               value = min(w_length, (u16) value);
-                       }
-                       break;
-               }
-               break;
-
-       /* any number of configs can work */
-       case USB_REQ_SET_CONFIGURATION:
-               if (ctrl->bRequestType != 0)
-                       goto unknown;
-               if (gadget_is_otg(gadget)) {
-                       if (gadget->a_hnp_support)
-                               DBG(cdev, "HNP available\n");
-                       else if (gadget->a_alt_hnp_support)
-                               DBG(cdev, "HNP on another port\n");
-                       else
-                               VDBG(cdev, "HNP inactive\n");
-               }
-               spin_lock(&cdev->lock);
-               value = set_config(cdev, ctrl, w_value);
-               spin_unlock(&cdev->lock);
-               break;
-       case USB_REQ_GET_CONFIGURATION:
-               if (ctrl->bRequestType != USB_DIR_IN)
-                       goto unknown;
-               if (cdev->config)
-                       *(u8 *)req->buf = cdev->config->bConfigurationValue;
-               else
-                       *(u8 *)req->buf = 0;
-               value = min(w_length, (u16) 1);
-               break;
-
-       /* function drivers must handle get/set altsetting; if there's
-        * no get() method, we know only altsetting zero works.
-        */
-       case USB_REQ_SET_INTERFACE:
-               if (ctrl->bRequestType != USB_RECIP_INTERFACE)
-                       goto unknown;
-               if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
-                       break;
-               f = cdev->config->interface[intf];
-               if (!f)
-                       break;
-               if (w_value && !f->set_alt)
-                       break;
-               value = f->set_alt(f, w_index, w_value);
-               if (value == USB_GADGET_DELAYED_STATUS) {
-                       DBG(cdev,
-                        "%s: interface %d (%s) requested delayed status\n",
-                                       __func__, intf, f->name);
-                       cdev->delayed_status++;
-                       DBG(cdev, "delayed_status count %d\n",
-                                       cdev->delayed_status);
-               }
-               break;
-       case USB_REQ_GET_INTERFACE:
-               if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
-                       goto unknown;
-               if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
-                       break;
-               f = cdev->config->interface[intf];
-               if (!f)
-                       break;
-               /* lots of interfaces only need altsetting zero... */
-               value = f->get_alt ? f->get_alt(f, w_index) : 0;
-               if (value < 0)
-                       break;
-               *((u8 *)req->buf) = value;
-               value = min(w_length, (u16) 1);
-               break;
-
-       /*
-        * USB 3.0 additions:
-        * Function driver should handle get_status request. If such cb
-        * wasn't supplied we respond with default value = 0
-        * Note: function driver should supply such cb only for the first
-        * interface of the function
-        */
-       case USB_REQ_GET_STATUS:
-               if (!gadget_is_superspeed(gadget))
-                       goto unknown;
-               if (ctrl->bRequestType != (USB_DIR_IN | USB_RECIP_INTERFACE))
-                       goto unknown;
-               value = 2;      /* This is the length of the get_status reply */
-               put_unaligned_le16(0, req->buf);
-               if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
-                       break;
-               f = cdev->config->interface[intf];
-               if (!f)
-                       break;
-               status = f->get_status ? f->get_status(f) : 0;
-               if (status < 0)
-                       break;
-               put_unaligned_le16(status & 0x0000ffff, req->buf);
-               break;
-       /*
-        * Function drivers should handle SetFeature/ClearFeature
-        * (FUNCTION_SUSPEND) request. function_suspend cb should be supplied
-        * only for the first interface of the function
-        */
-       case USB_REQ_CLEAR_FEATURE:
-       case USB_REQ_SET_FEATURE:
-               if (!gadget_is_superspeed(gadget))
-                       goto unknown;
-               if (ctrl->bRequestType != (USB_DIR_OUT | USB_RECIP_INTERFACE))
-                       goto unknown;
-               switch (w_value) {
-               case USB_INTRF_FUNC_SUSPEND:
-                       if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
-                               break;
-                       f = cdev->config->interface[intf];
-                       if (!f)
-                               break;
-                       value = 0;
-                       if (f->func_suspend)
-                               value = f->func_suspend(f, w_index >> 8);
-                       if (value < 0) {
-                               ERROR(cdev,
-                                     "func_suspend() returned error %d\n",
-                                     value);
-                               value = 0;
-                       }
-                       break;
-               }
-               break;
-       default:
-unknown:
-               VDBG(cdev,
-                       "non-core control req%02x.%02x v%04x i%04x l%d\n",
-                       ctrl->bRequestType, ctrl->bRequest,
-                       w_value, w_index, w_length);
-
-               /* functions always handle their interfaces and endpoints...
-                * punt other recipients (other, WUSB, ...) to the current
-                * configuration code.
-                *
-                * REVISIT it could make sense to let the composite device
-                * take such requests too, if that's ever needed:  to work
-                * in config 0, etc.
-                */
-               switch (ctrl->bRequestType & USB_RECIP_MASK) {
-               case USB_RECIP_INTERFACE:
-                       if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
-                               break;
-                       f = cdev->config->interface[intf];
-                       break;
-
-               case USB_RECIP_ENDPOINT:
-                       endp = ((w_index & 0x80) >> 3) | (w_index & 0x0f);
-                       list_for_each_entry(f, &cdev->config->functions, list) {
-                               if (test_bit(endp, f->endpoints))
-                                       break;
-                       }
-                       if (&f->list == &cdev->config->functions)
-                               f = NULL;
-                       break;
-               }
-
-               if (f && f->setup)
-                       value = f->setup(f, ctrl);
-               else {
-                       struct usb_configuration        *c;
-
-                       c = cdev->config;
-                       if (c && c->setup)
-                               value = c->setup(c, ctrl);
-               }
-
-               goto done;
-       }
-
-       /* respond with data transfer before status phase? */
-       if (value >= 0 && value != USB_GADGET_DELAYED_STATUS) {
-               req->length = value;
-               req->zero = value < w_length;
-               value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
-               if (value < 0) {
-                       DBG(cdev, "ep_queue --> %d\n", value);
-                       req->status = 0;
-                       composite_setup_complete(gadget->ep0, req);
-               }
-       } else if (value == USB_GADGET_DELAYED_STATUS && w_length != 0) {
-               WARN(cdev,
-                       "%s: Delayed status not supported for w_length != 0",
-                       __func__);
-       }
-
-done:
-       /* device either stalls (value < 0) or reports success */
-       return value;
-}
-
-static void composite_disconnect(struct usb_gadget *gadget)
-{
-       struct usb_composite_dev        *cdev = get_gadget_data(gadget);
-       unsigned long                   flags;
-
-       /* REVISIT:  should we have config and device level
-        * disconnect callbacks?
-        */
-       spin_lock_irqsave(&cdev->lock, flags);
-       if (cdev->config)
-               reset_config(cdev);
-       if (composite->disconnect)
-               composite->disconnect(cdev);
-       spin_unlock_irqrestore(&cdev->lock, flags);
-}
-
-/*-------------------------------------------------------------------------*/
-
-static ssize_t composite_show_suspended(struct device *dev,
-                                       struct device_attribute *attr,
-                                       char *buf)
-{
-       struct usb_gadget *gadget = dev_to_usb_gadget(dev);
-       struct usb_composite_dev *cdev = get_gadget_data(gadget);
-
-       return sprintf(buf, "%d\n", cdev->suspended);
-}
-
-static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL);
-
-static void
-composite_unbind(struct usb_gadget *gadget)
-{
-       struct usb_composite_dev        *cdev = get_gadget_data(gadget);
-
-       /* composite_disconnect() must already have been called
-        * by the underlying peripheral controller driver!
-        * so there's no i/o concurrency that could affect the
-        * state protected by cdev->lock.
-        */
-       WARN_ON(cdev->config);
-
-       while (!list_empty(&cdev->configs)) {
-               struct usb_configuration        *c;
-               c = list_first_entry(&cdev->configs,
-                               struct usb_configuration, list);
-               remove_config(cdev, c);
-       }
-       if (composite->unbind)
-               composite->unbind(cdev);
-
-       if (cdev->req) {
-               kfree(cdev->req->buf);
-               usb_ep_free_request(gadget->ep0, cdev->req);
-       }
-       device_remove_file(&gadget->dev, &dev_attr_suspended);
-       kfree(cdev);
-       set_gadget_data(gadget, NULL);
-       composite = NULL;
-}
-
-static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
-{
-       if (!*desc) {
-               int ret = usb_string_id(cdev);
-               if (unlikely(ret < 0))
-                       WARNING(cdev, "failed to override string ID\n");
-               else
-                       *desc = ret;
-       }
-
-       return *desc;
-}
-
-static int composite_bind(struct usb_gadget *gadget,
-               struct usb_gadget_driver *driver)
-{
-       struct usb_composite_dev        *cdev;
-       int                             status = -ENOMEM;
-
-       cdev = kzalloc(sizeof *cdev, GFP_KERNEL);
-       if (!cdev)
-               return status;
-
-       spin_lock_init(&cdev->lock);
-       cdev->gadget = gadget;
-       set_gadget_data(gadget, cdev);
-       INIT_LIST_HEAD(&cdev->configs);
-
-       /* preallocate control response and buffer */
-       cdev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
-       if (!cdev->req)
-               goto fail;
-       cdev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL);
-       if (!cdev->req->buf)
-               goto fail;
-       cdev->req->complete = composite_setup_complete;
-       gadget->ep0->driver_data = cdev;
-
-       cdev->bufsiz = USB_BUFSIZ;
-       cdev->driver = composite;
-
-       /*
-        * As per USB compliance update, a device that is actively drawing
-        * more than 100mA from USB must report itself as bus-powered in
-        * the GetStatus(DEVICE) call.
-        */
-       if (CONFIG_USB_GADGET_VBUS_DRAW <= USB_SELF_POWER_VBUS_MAX_DRAW)
-               usb_gadget_set_selfpowered(gadget);
-
-       /* interface and string IDs start at zero via kzalloc.
-        * we force endpoints to start unassigned; few controller
-        * drivers will zero ep->driver_data.
-        */
-       usb_ep_autoconfig_reset(cdev->gadget);
-
-       /* composite gadget needs to assign strings for whole device (like
-        * serial number), register function drivers, potentially update
-        * power state and consumption, etc
-        */
-       status = composite->bind(cdev);
-       if (status < 0)
-               goto fail;
-
-       cdev->desc = *composite->dev;
-
-       /* standardized runtime overrides for device ID data */
-       if (idVendor)
-               cdev->desc.idVendor = cpu_to_le16(idVendor);
-       else
-               idVendor = le16_to_cpu(cdev->desc.idVendor);
-       if (idProduct)
-               cdev->desc.idProduct = cpu_to_le16(idProduct);
-       else
-               idProduct = le16_to_cpu(cdev->desc.idProduct);
-       if (bcdDevice)
-               cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
-       else
-               bcdDevice = le16_to_cpu(cdev->desc.bcdDevice);
-
-       /* string overrides */
-       if (iManufacturer || !cdev->desc.iManufacturer) {
-               if (!iManufacturer && !composite->iManufacturer &&
-                   !*composite_manufacturer)
-                       snprintf(composite_manufacturer,
-                                sizeof composite_manufacturer,
-                                "%s %s with %s",
-                                init_utsname()->sysname,
-                                init_utsname()->release,
-                                gadget->name);
-
-               cdev->manufacturer_override =
-                       override_id(cdev, &cdev->desc.iManufacturer);
-       }
-
-       if (iProduct || (!cdev->desc.iProduct && composite->iProduct))
-               cdev->product_override =
-                       override_id(cdev, &cdev->desc.iProduct);
-
-       if (iSerialNumber ||
-           (!cdev->desc.iSerialNumber && composite->iSerialNumber))
-               cdev->serial_override =
-                       override_id(cdev, &cdev->desc.iSerialNumber);
-
-       /* has userspace failed to provide a serial number? */
-       if (composite->needs_serial && !cdev->desc.iSerialNumber)
-               WARNING(cdev, "userspace failed to provide iSerialNumber\n");
-
-       /* finish up */
-       status = device_create_file(&gadget->dev, &dev_attr_suspended);
-       if (status)
-               goto fail;
-
-       INFO(cdev, "%s ready\n", composite->name);
-       return 0;
-
-fail:
-       composite_unbind(gadget);
-       return status;
-}
-
-/*-------------------------------------------------------------------------*/
-
-static void
-composite_suspend(struct usb_gadget *gadget)
-{
-       struct usb_composite_dev        *cdev = get_gadget_data(gadget);
-       struct usb_function             *f;
-
-       /* REVISIT:  should we have config level
-        * suspend/resume callbacks?
-        */
-       DBG(cdev, "suspend\n");
-       if (cdev->config) {
-               list_for_each_entry(f, &cdev->config->functions, list) {
-                       if (f->suspend)
-                               f->suspend(f);
-               }
-       }
-       if (composite->suspend)
-               composite->suspend(cdev);
-
-       cdev->suspended = 1;
-
-       usb_gadget_vbus_draw(gadget, 2);
-}
-
-static void
-composite_resume(struct usb_gadget *gadget)
-{
-       struct usb_composite_dev        *cdev = get_gadget_data(gadget);
-       struct usb_function             *f;
-       u8                              maxpower;
-
-       /* REVISIT:  should we have config level
-        * suspend/resume callbacks?
-        */
-       DBG(cdev, "resume\n");
-       if (composite->resume)
-               composite->resume(cdev);
-       if (cdev->config) {
-               list_for_each_entry(f, &cdev->config->functions, list) {
-                       if (f->resume)
-                               f->resume(f);
-               }
-
-               maxpower = cdev->config->bMaxPower;
-
-               usb_gadget_vbus_draw(gadget, maxpower ?
-                       (2 * maxpower) : CONFIG_USB_GADGET_VBUS_DRAW);
-       }
-
-       cdev->suspended = 0;
-}
-
-/*-------------------------------------------------------------------------*/
-
-static struct usb_gadget_driver composite_driver = {
-       .bind           = composite_bind,
-       .unbind         = composite_unbind,
-
-       .setup          = composite_setup,
-       .disconnect     = composite_disconnect,
-
-       .suspend        = composite_suspend,
-       .resume         = composite_resume,
-
-       .driver = {
-               .owner          = THIS_MODULE,
-       },
-};
-
-/**
- * usb_composite_probe() - register a composite driver
- * @driver: the driver to register
- * @bind: the callback used to allocate resources that are shared across the
- *     whole device, such as string IDs, and add its configurations using
- *     @usb_add_config().  This may fail by returning a negative errno
- *     value; it should return zero on successful initialization.
- * Context: single threaded during gadget setup
- *
- * This function is used to register drivers using the composite driver
- * framework.  The return value is zero, or a negative errno value.
- * Those values normally come from the driver's @bind method, which does
- * all the work of setting up the driver to match the hardware.
- *
- * On successful return, the gadget is ready to respond to requests from
- * the host, unless one of its components invokes usb_gadget_disconnect()
- * while it was binding.  That would usually be done in order to wait for
- * some userspace participation.
- */
-int usb_composite_probe(struct usb_composite_driver *driver)
-{
-       if (!driver || !driver->dev || composite || !driver->bind)
-               return -EINVAL;
-
-       if (!driver->name)
-               driver->name = "composite";
-       if (!driver->iProduct)
-               driver->iProduct = driver->name;
-       composite_driver.function =  (char *) driver->name;
-       composite_driver.driver.name = driver->name;
-       composite_driver.max_speed = driver->max_speed;
-       composite = driver;
-
-       return usb_gadget_probe_driver(&composite_driver);
-}
-
-/**
- * usb_composite_unregister() - unregister a composite driver
- * @driver: the driver to unregister
- *
- * This function is used to unregister drivers using the composite
- * driver framework.
- */
-void usb_composite_unregister(struct usb_composite_driver *driver)
-{
-       if (composite != driver)
-               return;
-       usb_gadget_unregister_driver(&composite_driver);
-}
-
-/**
- * usb_composite_setup_continue() - Continue with the control transfer
- * @cdev: the composite device who's control transfer was kept waiting
- *
- * This function must be called by the USB function driver to continue
- * with the control transfer's data/status stage in case it had requested to
- * delay the data/status stages. A USB function's setup handler (e.g. set_alt())
- * can request the composite framework to delay the setup request's data/status
- * stages by returning USB_GADGET_DELAYED_STATUS.
- */
-void usb_composite_setup_continue(struct usb_composite_dev *cdev)
-{
-       int                     value;
-       struct usb_request      *req = cdev->req;
-       unsigned long           flags;
-
-       DBG(cdev, "%s\n", __func__);
-       spin_lock_irqsave(&cdev->lock, flags);
-
-       if (cdev->delayed_status == 0) {
-               WARN(cdev, "%s: Unexpected call\n", __func__);
-
-       } else if (--cdev->delayed_status == 0) {
-               DBG(cdev, "%s: Completing delayed status\n", __func__);
-               req->length = 0;
-               value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
-               if (value < 0) {
-                       DBG(cdev, "ep_queue --> %d\n", value);
-                       req->status = 0;
-                       composite_setup_complete(cdev->gadget->ep0, req);
-               }
-       }
-
-       spin_unlock_irqrestore(&cdev->lock, flags);
-}
-
diff --git a/drivers/staging/ccg/composite.h b/drivers/staging/ccg/composite.h
deleted file mode 100644 (file)
index 19a5adf..0000000
+++ /dev/null
@@ -1,395 +0,0 @@
-/*
- * composite.h -- framework for usb gadgets which are composite devices
- *
- * Copyright (C) 2006-2008 David Brownell
- *
- * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#ifndef        __LINUX_USB_COMPOSITE_H
-#define        __LINUX_USB_COMPOSITE_H
-
-/*
- * This framework is an optional layer on top of the USB Gadget interface,
- * making it easier to build (a) Composite devices, supporting multiple
- * functions within any single configuration, and (b) Multi-configuration
- * devices, also supporting multiple functions but without necessarily
- * having more than one function per configuration.
- *
- * Example:  a device with a single configuration supporting both network
- * link and mass storage functions is a composite device.  Those functions
- * might alternatively be packaged in individual configurations, but in
- * the composite model the host can use both functions at the same time.
- */
-
-#include <linux/usb/ch9.h>
-#include <linux/usb/gadget.h>
-
-/*
- * USB function drivers should return USB_GADGET_DELAYED_STATUS if they
- * wish to delay the data/status stages of the control transfer till they
- * are ready. The control transfer will then be kept from completing till
- * all the function drivers that requested for USB_GADGET_DELAYED_STAUS
- * invoke usb_composite_setup_continue().
- */
-#define USB_GADGET_DELAYED_STATUS       0x7fff /* Impossibly large value */
-
-struct usb_configuration;
-
-/**
- * struct usb_function - describes one function of a configuration
- * @name: For diagnostics, identifies the function.
- * @strings: tables of strings, keyed by identifiers assigned during bind()
- *     and by language IDs provided in control requests
- * @descriptors: Table of full (or low) speed descriptors, using interface and
- *     string identifiers assigned during @bind().  If this pointer is null,
- *     the function will not be available at full speed (or at low speed).
- * @hs_descriptors: Table of high speed descriptors, using interface and
- *     string identifiers assigned during @bind().  If this pointer is null,
- *     the function will not be available at high speed.
- * @ss_descriptors: Table of super speed descriptors, using interface and
- *     string identifiers assigned during @bind(). If this
- *     pointer is null after initiation, the function will not
- *     be available at super speed.
- * @config: assigned when @usb_add_function() is called; this is the
- *     configuration with which this function is associated.
- * @bind: Before the gadget can register, all of its functions bind() to the
- *     available resources including string and interface identifiers used
- *     in interface or class descriptors; endpoints; I/O buffers; and so on.
- * @unbind: Reverses @bind; called as a side effect of unregistering the
- *     driver which added this function.
- * @set_alt: (REQUIRED) Reconfigures altsettings; function drivers may
- *     initialize usb_ep.driver data at this time (when it is used).
- *     Note that setting an interface to its current altsetting resets
- *     interface state, and that all interfaces have a disabled state.
- * @get_alt: Returns the active altsetting.  If this is not provided,
- *     then only altsetting zero is supported.
- * @disable: (REQUIRED) Indicates the function should be disabled.  Reasons
- *     include host resetting or reconfiguring the gadget, and disconnection.
- * @setup: Used for interface-specific control requests.
- * @suspend: Notifies functions when the host stops sending USB traffic.
- * @resume: Notifies functions when the host restarts USB traffic.
- * @get_status: Returns function status as a reply to
- *     GetStatus() request when the recepient is Interface.
- * @func_suspend: callback to be called when
- *     SetFeature(FUNCTION_SUSPEND) is reseived
- *
- * A single USB function uses one or more interfaces, and should in most
- * cases support operation at both full and high speeds.  Each function is
- * associated by @usb_add_function() with a one configuration; that function
- * causes @bind() to be called so resources can be allocated as part of
- * setting up a gadget driver.  Those resources include endpoints, which
- * should be allocated using @usb_ep_autoconfig().
- *
- * To support dual speed operation, a function driver provides descriptors
- * for both high and full speed operation.  Except in rare cases that don't
- * involve bulk endpoints, each speed needs different endpoint descriptors.
- *
- * Function drivers choose their own strategies for managing instance data.
- * The simplest strategy just declares it "static', which means the function
- * can only be activated once.  If the function needs to be exposed in more
- * than one configuration at a given speed, it needs to support multiple
- * usb_function structures (one for each configuration).
- *
- * A more complex strategy might encapsulate a @usb_function structure inside
- * a driver-specific instance structure to allows multiple activations.  An
- * example of multiple activations might be a CDC ACM function that supports
- * two or more distinct instances within the same configuration, providing
- * several independent logical data links to a USB host.
- */
-struct usb_function {
-       const char                      *name;
-       struct usb_gadget_strings       **strings;
-       struct usb_descriptor_header    **descriptors;
-       struct usb_descriptor_header    **hs_descriptors;
-       struct usb_descriptor_header    **ss_descriptors;
-
-       struct usb_configuration        *config;
-
-       /* REVISIT:  bind() functions can be marked __init, which
-        * makes trouble for section mismatch analysis.  See if
-        * we can't restructure things to avoid mismatching.
-        * Related:  unbind() may kfree() but bind() won't...
-        */
-
-       /* configuration management:  bind/unbind */
-       int                     (*bind)(struct usb_configuration *,
-                                       struct usb_function *);
-       void                    (*unbind)(struct usb_configuration *,
-                                       struct usb_function *);
-
-       /* runtime state management */
-       int                     (*set_alt)(struct usb_function *,
-                                       unsigned interface, unsigned alt);
-       int                     (*get_alt)(struct usb_function *,
-                                       unsigned interface);
-       void                    (*disable)(struct usb_function *);
-       int                     (*setup)(struct usb_function *,
-                                       const struct usb_ctrlrequest *);
-       void                    (*suspend)(struct usb_function *);
-       void                    (*resume)(struct usb_function *);
-
-       /* USB 3.0 additions */
-       int                     (*get_status)(struct usb_function *);
-       int                     (*func_suspend)(struct usb_function *,
-                                               u8 suspend_opt);
-       /* private: */
-       /* internals */
-       struct list_head                list;
-       DECLARE_BITMAP(endpoints, 32);
-};
-
-int usb_add_function(struct usb_configuration *, struct usb_function *);
-
-int usb_function_deactivate(struct usb_function *);
-int usb_function_activate(struct usb_function *);
-
-int usb_interface_id(struct usb_configuration *, struct usb_function *);
-
-int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f,
-                       struct usb_ep *_ep);
-
-#define        MAX_CONFIG_INTERFACES           16      /* arbitrary; max 255 */
-
-/**
- * struct usb_configuration - represents one gadget configuration
- * @label: For diagnostics, describes the configuration.
- * @strings: Tables of strings, keyed by identifiers assigned during @bind()
- *     and by language IDs provided in control requests.
- * @descriptors: Table of descriptors preceding all function descriptors.
- *     Examples include OTG and vendor-specific descriptors.
- * @unbind: Reverses @bind; called as a side effect of unregistering the
- *     driver which added this configuration.
- * @setup: Used to delegate control requests that aren't handled by standard
- *     device infrastructure or directed at a specific interface.
- * @bConfigurationValue: Copied into configuration descriptor.
- * @iConfiguration: Copied into configuration descriptor.
- * @bmAttributes: Copied into configuration descriptor.
- * @bMaxPower: Copied into configuration descriptor.
- * @cdev: assigned by @usb_add_config() before calling @bind(); this is
- *     the device associated with this configuration.
- *
- * Configurations are building blocks for gadget drivers structured around
- * function drivers.  Simple USB gadgets require only one function and one
- * configuration, and handle dual-speed hardware by always providing the same
- * functionality.  Slightly more complex gadgets may have more than one
- * single-function configuration at a given speed; or have configurations
- * that only work at one speed.
- *
- * Composite devices are, by definition, ones with configurations which
- * include more than one function.
- *
- * The lifecycle of a usb_configuration includes allocation, initialization
- * of the fields described above, and calling @usb_add_config() to set up
- * internal data and bind it to a specific device.  The configuration's
- * @bind() method is then used to initialize all the functions and then
- * call @usb_add_function() for them.
- *
- * Those functions would normally be independent of each other, but that's
- * not mandatory.  CDC WMC devices are an example where functions often
- * depend on other functions, with some functions subsidiary to others.
- * Such interdependency may be managed in any way, so long as all of the
- * descriptors complete by the time the composite driver returns from
- * its bind() routine.
- */
-struct usb_configuration {
-       const char                      *label;
-       struct usb_gadget_strings       **strings;
-       const struct usb_descriptor_header **descriptors;
-
-       /* REVISIT:  bind() functions can be marked __init, which
-        * makes trouble for section mismatch analysis.  See if
-        * we can't restructure things to avoid mismatching...
-        */
-
-       /* configuration management: unbind/setup */
-       void                    (*unbind)(struct usb_configuration *);
-       int                     (*setup)(struct usb_configuration *,
-                                       const struct usb_ctrlrequest *);
-
-       /* fields in the config descriptor */
-       u8                      bConfigurationValue;
-       u8                      iConfiguration;
-       u8                      bmAttributes;
-       u8                      bMaxPower;
-
-       struct usb_composite_dev        *cdev;
-
-       /* private: */
-       /* internals */
-       struct list_head        list;
-       struct list_head        functions;
-       u8                      next_interface_id;
-       unsigned                superspeed:1;
-       unsigned                highspeed:1;
-       unsigned                fullspeed:1;
-       struct usb_function     *interface[MAX_CONFIG_INTERFACES];
-};
-
-int usb_add_config(struct usb_composite_dev *,
-               struct usb_configuration *,
-               int (*)(struct usb_configuration *));
-
-void usb_remove_config(struct usb_composite_dev *,
-               struct usb_configuration *);
-
-/**
- * struct usb_composite_driver - groups configurations into a gadget
- * @name: For diagnostics, identifies the driver.
- * @iProduct: Used as iProduct override if @dev->iProduct is not set.
- *     If NULL value of @name is taken.
- * @iManufacturer: Used as iManufacturer override if @dev->iManufacturer is
- *     not set. If NULL a default "<system> <release> with <udc>" value
- *     will be used.
- * @iSerialNumber: Used as iSerialNumber override if @dev->iSerialNumber is
- *     not set.
- * @dev: Template descriptor for the device, including default device
- *     identifiers.
- * @strings: tables of strings, keyed by identifiers assigned during @bind
- *     and language IDs provided in control requests
- * @max_speed: Highest speed the driver supports.
- * @needs_serial: set to 1 if the gadget needs userspace to provide
- *     a serial number.  If one is not provided, warning will be printed.
- * @bind: (REQUIRED) Used to allocate resources that are shared across the
- *     whole device, such as string IDs, and add its configurations using
- *     @usb_add_config(). This may fail by returning a negative errno
- *     value; it should return zero on successful initialization.
- * @unbind: Reverses @bind; called as a side effect of unregistering
- *     this driver.
- * @disconnect: optional driver disconnect method
- * @suspend: Notifies when the host stops sending USB traffic,
- *     after function notifications
- * @resume: Notifies configuration when the host restarts USB traffic,
- *     before function notifications
- *
- * Devices default to reporting self powered operation.  Devices which rely
- * on bus powered operation should report this in their @bind method.
- *
- * Before returning from @bind, various fields in the template descriptor
- * may be overridden.  These include the idVendor/idProduct/bcdDevice values
- * normally to bind the appropriate host side driver, and the three strings
- * (iManufacturer, iProduct, iSerialNumber) normally used to provide user
- * meaningful device identifiers.  (The strings will not be defined unless
- * they are defined in @dev and @strings.)  The correct ep0 maxpacket size
- * is also reported, as defined by the underlying controller driver.
- */
-struct usb_composite_driver {
-       const char                              *name;
-       const char                              *iProduct;
-       const char                              *iManufacturer;
-       const char                              *iSerialNumber;
-       const struct usb_device_descriptor      *dev;
-       struct usb_gadget_strings               **strings;
-       enum usb_device_speed                   max_speed;
-       unsigned                needs_serial:1;
-
-       int                     (*bind)(struct usb_composite_dev *cdev);
-       int                     (*unbind)(struct usb_composite_dev *);
-
-       void                    (*disconnect)(struct usb_composite_dev *);
-
-       /* global suspend hooks */
-       void                    (*suspend)(struct usb_composite_dev *);
-       void                    (*resume)(struct usb_composite_dev *);
-};
-
-extern int usb_composite_probe(struct usb_composite_driver *driver);
-extern void usb_composite_unregister(struct usb_composite_driver *driver);
-extern void usb_composite_setup_continue(struct usb_composite_dev *cdev);
-
-
-/**
- * struct usb_composite_device - represents one composite usb gadget
- * @gadget: read-only, abstracts the gadget's usb peripheral controller
- * @req: used for control responses; buffer is pre-allocated
- * @bufsiz: size of buffer pre-allocated in @req
- * @config: the currently active configuration
- *
- * One of these devices is allocated and initialized before the
- * associated device driver's bind() is called.
- *
- * OPEN ISSUE:  it appears that some WUSB devices will need to be
- * built by combining a normal (wired) gadget with a wireless one.
- * This revision of the gadget framework should probably try to make
- * sure doing that won't hurt too much.
- *
- * One notion for how to handle Wireless USB devices involves:
- * (a) a second gadget here, discovery mechanism TBD, but likely
- *     needing separate "register/unregister WUSB gadget" calls;
- * (b) updates to usb_gadget to include flags "is it wireless",
- *     "is it wired", plus (presumably in a wrapper structure)
- *     bandgroup and PHY info;
- * (c) presumably a wireless_ep wrapping a usb_ep, and reporting
- *     wireless-specific parameters like maxburst and maxsequence;
- * (d) configurations that are specific to wireless links;
- * (e) function drivers that understand wireless configs and will
- *     support wireless for (additional) function instances;
- * (f) a function to support association setup (like CBAF), not
- *     necessarily requiring a wireless adapter;
- * (g) composite device setup that can create one or more wireless
- *     configs, including appropriate association setup support;
- * (h) more, TBD.
- */
-struct usb_composite_dev {
-       struct usb_gadget               *gadget;
-       struct usb_request              *req;
-       unsigned                        bufsiz;
-
-       struct usb_configuration        *config;
-
-       /* private: */
-       /* internals */
-       unsigned int                    suspended:1;
-       struct usb_device_descriptor    desc;
-       struct list_head                configs;
-       struct usb_composite_driver     *driver;
-       u8                              next_string_id;
-       u8                              manufacturer_override;
-       u8                              product_override;
-       u8                              serial_override;
-
-       /* the gadget driver won't enable the data pullup
-        * while the deactivation count is nonzero.
-        */
-       unsigned                        deactivations;
-
-       /* the composite driver won't complete the control transfer's
-        * data/status stages till delayed_status is zero.
-        */
-       int                             delayed_status;
-
-       /* protects deactivations and delayed_status counts*/
-       spinlock_t                      lock;
-};
-
-extern int usb_string_id(struct usb_composite_dev *c);
-extern int usb_string_ids_tab(struct usb_composite_dev *c,
-                             struct usb_string *str);
-extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n);
-
-
-/* messaging utils */
-#define DBG(d, fmt, args...) \
-       dev_dbg(&(d)->gadget->dev , fmt , ## args)
-#define VDBG(d, fmt, args...) \
-       dev_vdbg(&(d)->gadget->dev , fmt , ## args)
-#define ERROR(d, fmt, args...) \
-       dev_err(&(d)->gadget->dev , fmt , ## args)
-#define WARNING(d, fmt, args...) \
-       dev_warn(&(d)->gadget->dev , fmt , ## args)
-#define INFO(d, fmt, args...) \
-       dev_info(&(d)->gadget->dev , fmt , ## args)
-
-#endif /* __LINUX_USB_COMPOSITE_H */
diff --git a/drivers/staging/ccg/config.c b/drivers/staging/ccg/config.c
deleted file mode 100644 (file)
index 7542a72..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * usb/gadget/config.c -- simplify building config descriptors
- *
- * Copyright (C) 2003 David Brownell
- *
- * 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/errno.h>
-#include <linux/slab.h>
-#include <linux/kernel.h>
-#include <linux/list.h>
-#include <linux/string.h>
-#include <linux/device.h>
-
-#include <linux/usb/ch9.h>
-#include <linux/usb/gadget.h>
-
-
-/**
- * usb_descriptor_fillbuf - fill buffer with descriptors
- * @buf: Buffer to be filled
- * @buflen: Size of buf
- * @src: Array of descriptor pointers, terminated by null pointer.
- *
- * Copies descriptors into the buffer, returning the length or a
- * negative error code if they can't all be copied.  Useful when
- * assembling descriptors for an associated set of interfaces used
- * as part of configuring a composite device; or in other cases where
- * sets of descriptors need to be marshaled.
- */
-int
-usb_descriptor_fillbuf(void *buf, unsigned buflen,
-               const struct usb_descriptor_header **src)
-{
-       u8      *dest = buf;
-
-       if (!src)
-               return -EINVAL;
-
-       /* fill buffer from src[] until null descriptor ptr */
-       for (; NULL != *src; src++) {
-               unsigned                len = (*src)->bLength;
-
-               if (len > buflen)
-                       return -EINVAL;
-               memcpy(dest, *src, len);
-               buflen -= len;
-               dest += len;
-       }
-       return dest - (u8 *)buf;
-}
-
-
-/**
- * usb_gadget_config_buf - builts a complete configuration descriptor
- * @config: Header for the descriptor, including characteristics such
- *     as power requirements and number of interfaces.
- * @desc: Null-terminated vector of pointers to the descriptors (interface,
- *     endpoint, etc) defining all functions in this device configuration.
- * @buf: Buffer for the resulting configuration descriptor.
- * @length: Length of buffer.  If this is not big enough to hold the
- *     entire configuration descriptor, an error code will be returned.
- *
- * This copies descriptors into the response buffer, building a descriptor
- * for that configuration.  It returns the buffer length or a negative
- * status code.  The config.wTotalLength field is set to match the length
- * of the result, but other descriptor fields (including power usage and
- * interface count) must be set by the caller.
- *
- * Gadget drivers could use this when constructing a config descriptor
- * in response to USB_REQ_GET_DESCRIPTOR.  They will need to patch the
- * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
- */
-int usb_gadget_config_buf(
-       const struct usb_config_descriptor      *config,
-       void                                    *buf,
-       unsigned                                length,
-       const struct usb_descriptor_header      **desc
-)
-{
-       struct usb_config_descriptor            *cp = buf;
-       int                                     len;
-
-       /* config descriptor first */
-       if (length < USB_DT_CONFIG_SIZE || !desc)
-               return -EINVAL;
-       *cp = *config;
-
-       /* then interface/endpoint/class/vendor/... */
-       len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
-                       length - USB_DT_CONFIG_SIZE, desc);
-       if (len < 0)
-               return len;
-       len += USB_DT_CONFIG_SIZE;
-       if (len > 0xffff)
-               return -EINVAL;
-
-       /* patch up the config descriptor */
-       cp->bLength = USB_DT_CONFIG_SIZE;
-       cp->bDescriptorType = USB_DT_CONFIG;
-       cp->wTotalLength = cpu_to_le16(len);
-       cp->bmAttributes |= USB_CONFIG_ATT_ONE;
-       return len;
-}
-
-/**
- * usb_copy_descriptors - copy a vector of USB descriptors
- * @src: null-terminated vector to copy
- * Context: initialization code, which may sleep
- *
- * This makes a copy of a vector of USB descriptors.  Its primary use
- * is to support usb_function objects which can have multiple copies,
- * each needing different descriptors.  Functions may have static
- * tables of descriptors, which are used as templates and customized
- * with identifiers (for interfaces, strings, endpoints, and more)
- * as needed by a given function instance.
- */
-struct usb_descriptor_header **
-usb_copy_descriptors(struct usb_descriptor_header **src)
-{
-       struct usb_descriptor_header **tmp;
-       unsigned bytes;
-       unsigned n_desc;
-       void *mem;
-       struct usb_descriptor_header **ret;
-
-       /* count descriptors and their sizes; then add vector size */
-       for (bytes = 0, n_desc = 0, tmp = src; *tmp; tmp++, n_desc++)
-               bytes += (*tmp)->bLength;
-       bytes += (n_desc + 1) * sizeof(*tmp);
-
-       mem = kmalloc(bytes, GFP_KERNEL);
-       if (!mem)
-               return NULL;
-
-       /* fill in pointers starting at "tmp",
-        * to descriptors copied starting at "mem";
-        * and return "ret"
-        */
-       tmp = mem;
-       ret = mem;
-       mem += (n_desc + 1) * sizeof(*tmp);
-       while (*src) {
-               memcpy(mem, *src, (*src)->bLength);
-               *tmp = mem;
-               tmp++;
-               mem += (*src)->bLength;
-               src++;
-       }
-       *tmp = NULL;
-
-       return ret;
-}
-
diff --git a/drivers/staging/ccg/epautoconf.c b/drivers/staging/ccg/epautoconf.c
deleted file mode 100644 (file)
index 51f3d42..0000000
+++ /dev/null
@@ -1,393 +0,0 @@
-/*
- * epautoconf.c -- endpoint autoconfiguration for usb gadget drivers
- *
- * Copyright (C) 2004 David Brownell
- *
- * 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/init.h>
-#include <linux/types.h>
-#include <linux/device.h>
-
-#include <linux/ctype.h>
-#include <linux/string.h>
-
-#include <linux/usb/ch9.h>
-#include <linux/usb/gadget.h>
-
-#include "gadget_chips.h"
-
-
-/* we must assign addresses for configurable endpoints (like net2280) */
-static unsigned epnum;
-
-// #define MANY_ENDPOINTS
-#ifdef MANY_ENDPOINTS
-/* more than 15 configurable endpoints */
-static unsigned in_epnum;
-#endif
-
-
-/*
- * This should work with endpoints from controller drivers sharing the
- * same endpoint naming convention.  By example:
- *
- *     - ep1, ep2, ... address is fixed, not direction or type
- *     - ep1in, ep2out, ... address and direction are fixed, not type
- *     - ep1-bulk, ep2-bulk, ... address and type are fixed, not direction
- *     - ep1in-bulk, ep2out-iso, ... all three are fixed
- *     - ep-* ... no functionality restrictions
- *
- * Type suffixes are "-bulk", "-iso", or "-int".  Numbers are decimal.
- * Less common restrictions are implied by gadget_is_*().
- *
- * NOTE:  each endpoint is unidirectional, as specified by its USB
- * descriptor; and isn't specific to a configuration or altsetting.
- */
-static int
-ep_matches (
-       struct usb_gadget               *gadget,
-       struct usb_ep                   *ep,
-       struct usb_endpoint_descriptor  *desc,
-       struct usb_ss_ep_comp_descriptor *ep_comp
-)
-{
-       u8              type;
-       const char      *tmp;
-       u16             max;
-
-       int             num_req_streams = 0;
-
-       /* endpoint already claimed? */
-       if (NULL != ep->driver_data)
-               return 0;
-
-       /* only support ep0 for portable CONTROL traffic */
-       type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
-       if (USB_ENDPOINT_XFER_CONTROL == type)
-               return 0;
-
-       /* some other naming convention */
-       if ('e' != ep->name[0])
-               return 0;
-
-       /* type-restriction:  "-iso", "-bulk", or "-int".
-        * direction-restriction:  "in", "out".
-        */
-       if ('-' != ep->name[2]) {
-               tmp = strrchr (ep->name, '-');
-               if (tmp) {
-                       switch (type) {
-                       case USB_ENDPOINT_XFER_INT:
-                               /* bulk endpoints handle interrupt transfers,
-                                * except the toggle-quirky iso-synch kind
-                                */
-                               if ('s' == tmp[2])      // == "-iso"
-                                       return 0;
-                               /* for now, avoid PXA "interrupt-in";
-                                * it's documented as never using DATA1.
-                                */
-                               if (gadget_is_pxa (gadget)
-                                               && 'i' == tmp [1])
-                                       return 0;
-                               break;
-                       case USB_ENDPOINT_XFER_BULK:
-                               if ('b' != tmp[1])      // != "-bulk"
-                                       return 0;
-                               break;
-                       case USB_ENDPOINT_XFER_ISOC:
-                               if ('s' != tmp[2])      // != "-iso"
-                                       return 0;
-                       }
-               } else {
-                       tmp = ep->name + strlen (ep->name);
-               }
-
-               /* direction-restriction:  "..in-..", "out-.." */
-               tmp--;
-               if (!isdigit (*tmp)) {
-                       if (desc->bEndpointAddress & USB_DIR_IN) {
-                               if ('n' != *tmp)
-                                       return 0;
-                       } else {
-                               if ('t' != *tmp)
-                                       return 0;
-                       }
-               }
-       }
-
-       /*
-        * Get the number of required streams from the EP companion
-        * descriptor and see if the EP matches it
-        */
-       if (usb_endpoint_xfer_bulk(desc)) {
-               if (ep_comp && gadget->max_speed >= USB_SPEED_SUPER) {
-                       num_req_streams = ep_comp->bmAttributes & 0x1f;
-                       if (num_req_streams > ep->max_streams)
-                               return 0;
-               }
-
-       }
-
-       /*
-        * If the protocol driver hasn't yet decided on wMaxPacketSize
-        * and wants to know the maximum possible, provide the info.
-        */
-       if (desc->wMaxPacketSize == 0)
-               desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket);
-
-       /* endpoint maxpacket size is an input parameter, except for bulk
-        * where it's an output parameter representing the full speed limit.
-        * the usb spec fixes high speed bulk maxpacket at 512 bytes.
-        */
-       max = 0x7ff & usb_endpoint_maxp(desc);
-       switch (type) {
-       case USB_ENDPOINT_XFER_INT:
-               /* INT:  limit 64 bytes full speed, 1024 high/super speed */
-               if (!gadget_is_dualspeed(gadget) && max > 64)
-                       return 0;
-               /* FALLTHROUGH */
-
-       case USB_ENDPOINT_XFER_ISOC:
-               /* ISO:  limit 1023 bytes full speed, 1024 high/super speed */
-               if (ep->maxpacket < max)
-                       return 0;
-               if (!gadget_is_dualspeed(gadget) && max > 1023)
-                       return 0;
-
-               /* BOTH:  "high bandwidth" works only at high speed */
-               if ((desc->wMaxPacketSize & cpu_to_le16(3<<11))) {
-                       if (!gadget_is_dualspeed(gadget))
-                               return 0;
-                       /* configure your hardware with enough buffering!! */
-               }
-               break;
-       }
-
-       /* MATCH!! */
-
-       /* report address */
-       desc->bEndpointAddress &= USB_DIR_IN;
-       if (isdigit (ep->name [2])) {
-               u8      num = simple_strtoul (&ep->name [2], NULL, 10);
-               desc->bEndpointAddress |= num;
-#ifdef MANY_ENDPOINTS
-       } else if (desc->bEndpointAddress & USB_DIR_IN) {
-               if (++in_epnum > 15)
-                       return 0;
-               desc->bEndpointAddress = USB_DIR_IN | in_epnum;
-#endif
-       } else {
-               if (++epnum > 15)
-                       return 0;
-               desc->bEndpointAddress |= epnum;
-       }
-
-       /* report (variable) full speed bulk maxpacket */
-       if ((USB_ENDPOINT_XFER_BULK == type) && !ep_comp) {
-               int size = ep->maxpacket;
-
-               /* min() doesn't work on bitfields with gcc-3.5 */
-               if (size > 64)
-                       size = 64;
-               desc->wMaxPacketSize = cpu_to_le16(size);
-       }
-       ep->address = desc->bEndpointAddress;
-       return 1;
-}
-
-static struct usb_ep *
-find_ep (struct usb_gadget *gadget, const char *name)
-{
-       struct usb_ep   *ep;
-
-       list_for_each_entry (ep, &gadget->ep_list, ep_list) {
-               if (0 == strcmp (ep->name, name))
-                       return ep;
-       }
-       return NULL;
-}
-
-/**
- * usb_ep_autoconfig_ss() - choose an endpoint matching the ep
- * descriptor and ep companion descriptor
- * @gadget: The device to which the endpoint must belong.
- * @desc: Endpoint descriptor, with endpoint direction and transfer mode
- *    initialized.  For periodic transfers, the maximum packet
- *    size must also be initialized.  This is modified on
- *    success.
- * @ep_comp: Endpoint companion descriptor, with the required
- *    number of streams. Will be modified when the chosen EP
- *    supports a different number of streams.
- *
- * This routine replaces the usb_ep_autoconfig when needed
- * superspeed enhancments. If such enhancemnets are required,
- * the FD should call usb_ep_autoconfig_ss directly and provide
- * the additional ep_comp parameter.
- *
- * By choosing an endpoint to use with the specified descriptor,
- * this routine simplifies writing gadget drivers that work with
- * multiple USB device controllers.  The endpoint would be
- * passed later to usb_ep_enable(), along with some descriptor.
- *
- * That second descriptor won't always be the same as the first one.
- * For example, isochronous endpoints can be autoconfigured for high
- * bandwidth, and then used in several lower bandwidth altsettings.
- * Also, high and full speed descriptors will be different.
- *
- * Be sure to examine and test the results of autoconfiguration
- * on your hardware.  This code may not make the best choices
- * about how to use the USB controller, and it can't know all
- * the restrictions that may apply. Some combinations of driver
- * and hardware won't be able to autoconfigure.
- *
- * On success, this returns an un-claimed usb_ep, and modifies the endpoint
- * descriptor bEndpointAddress.  For bulk endpoints, the wMaxPacket value
- * is initialized as if the endpoint were used at full speed and
- * the bmAttribute field in the ep companion descriptor is
- * updated with the assigned number of streams if it is
- * different from the original value. To prevent the endpoint
- * from being returned by a later autoconfig call, claim it by
- * assigning ep->driver_data to some non-null value.
- *
- * On failure, this returns a null endpoint descriptor.
- */
-struct usb_ep *usb_ep_autoconfig_ss(
-       struct usb_gadget               *gadget,
-       struct usb_endpoint_descriptor  *desc,
-       struct usb_ss_ep_comp_descriptor *ep_comp
-)
-{
-       struct usb_ep   *ep;
-       u8              type;
-
-       type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
-
-       /* First, apply chip-specific "best usage" knowledge.
-        * This might make a good usb_gadget_ops hook ...
-        */
-       if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) {
-               /* ep-e, ep-f are PIO with only 64 byte fifos */
-               ep = find_ep (gadget, "ep-e");
-               if (ep && ep_matches(gadget, ep, desc, ep_comp))
-                       goto found_ep;
-               ep = find_ep (gadget, "ep-f");
-               if (ep && ep_matches(gadget, ep, desc, ep_comp))
-                       goto found_ep;
-
-       } else if (gadget_is_goku (gadget)) {
-               if (USB_ENDPOINT_XFER_INT == type) {
-                       /* single buffering is enough */
-                       ep = find_ep(gadget, "ep3-bulk");
-                       if (ep && ep_matches(gadget, ep, desc, ep_comp))
-                               goto found_ep;
-               } else if (USB_ENDPOINT_XFER_BULK == type
-                               && (USB_DIR_IN & desc->bEndpointAddress)) {
-                       /* DMA may be available */
-                       ep = find_ep(gadget, "ep2-bulk");
-                       if (ep && ep_matches(gadget, ep, desc,
-                                             ep_comp))
-                               goto found_ep;
-               }
-
-#ifdef CONFIG_BLACKFIN
-       } else if (gadget_is_musbhdrc(gadget)) {
-               if ((USB_ENDPOINT_XFER_BULK == type) ||
-                   (USB_ENDPOINT_XFER_ISOC == type)) {
-                       if (USB_DIR_IN & desc->bEndpointAddress)
-                               ep = find_ep (gadget, "ep5in");
-                       else
-                               ep = find_ep (gadget, "ep6out");
-               } else if (USB_ENDPOINT_XFER_INT == type) {
-                       if (USB_DIR_IN & desc->bEndpointAddress)
-                               ep = find_ep(gadget, "ep1in");
-                       else
-                               ep = find_ep(gadget, "ep2out");
-               } else
-                       ep = NULL;
-               if (ep && ep_matches(gadget, ep, desc, ep_comp))
-                       goto found_ep;
-#endif
-       }
-
-       /* Second, look at endpoints until an unclaimed one looks usable */
-       list_for_each_entry (ep, &gadget->ep_list, ep_list) {
-               if (ep_matches(gadget, ep, desc, ep_comp))
-                       goto found_ep;
-       }
-
-       /* Fail */
-       return NULL;
-found_ep:
-       ep->desc = NULL;
-       ep->comp_desc = NULL;
-       return ep;
-}
-
-/**
- * usb_ep_autoconfig() - choose an endpoint matching the
- * descriptor
- * @gadget: The device to which the endpoint must belong.
- * @desc: Endpoint descriptor, with endpoint direction and transfer mode
- *     initialized.  For periodic transfers, the maximum packet
- *     size must also be initialized.  This is modified on success.
- *
- * By choosing an endpoint to use with the specified descriptor, this
- * routine simplifies writing gadget drivers that work with multiple
- * USB device controllers.  The endpoint would be passed later to
- * usb_ep_enable(), along with some descriptor.
- *
- * That second descriptor won't always be the same as the first one.
- * For example, isochronous endpoints can be autoconfigured for high
- * bandwidth, and then used in several lower bandwidth altsettings.
- * Also, high and full speed descriptors will be different.
- *
- * Be sure to examine and test the results of autoconfiguration on your
- * hardware.  This code may not make the best choices about how to use the
- * USB controller, and it can't know all the restrictions that may apply.
- * Some combinations of driver and hardware won't be able to autoconfigure.
- *
- * On success, this returns an un-claimed usb_ep, and modifies the endpoint
- * descriptor bEndpointAddress.  For bulk endpoints, the wMaxPacket value
- * is initialized as if the endpoint were used at full speed.  To prevent
- * the endpoint from being returned by a later autoconfig call, claim it
- * by assigning ep->driver_data to some non-null value.
- *
- * On failure, this returns a null endpoint descriptor.
- */
-struct usb_ep *usb_ep_autoconfig(
-       struct usb_gadget               *gadget,
-       struct usb_endpoint_descriptor  *desc
-)
-{
-       return usb_ep_autoconfig_ss(gadget, desc, NULL);
-}
-
-
-/**
- * usb_ep_autoconfig_reset - reset endpoint autoconfig state
- * @gadget: device for which autoconfig state will be reset
- *
- * Use this for devices where one configuration may need to assign
- * endpoint resources very differently from the next one.  It clears
- * state such as ep->driver_data and the record of assigned endpoints
- * used by usb_ep_autoconfig().
- */
-void usb_ep_autoconfig_reset (struct usb_gadget *gadget)
-{
-       struct usb_ep   *ep;
-
-       list_for_each_entry (ep, &gadget->ep_list, ep_list) {
-               ep->driver_data = NULL;
-       }
-#ifdef MANY_ENDPOINTS
-       in_epnum = 0;
-#endif
-       epnum = 0;
-}
-
diff --git a/drivers/staging/ccg/f_acm.c b/drivers/staging/ccg/f_acm.c
deleted file mode 100644 (file)
index d672250..0000000
+++ /dev/null
@@ -1,814 +0,0 @@
-/*
- * f_acm.c -- USB CDC serial (ACM) function driver
- *
- * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
- * Copyright (C) 2008 by David Brownell
- * Copyright (C) 2008 by Nokia Corporation
- * Copyright (C) 2009 by Samsung Electronics
- * Author: Michal Nazarewicz (mina86@mina86.com)
- *
- * This software is 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.
- */
-
-/* #define VERBOSE_DEBUG */
-
-#include <linux/slab.h>
-#include <linux/kernel.h>
-#include <linux/device.h>
-
-#include "u_serial.h"
-#include "gadget_chips.h"
-
-
-/*
- * This CDC ACM function support just wraps control functions and
- * notifications around the generic serial-over-usb code.
- *
- * Because CDC ACM is standardized by the USB-IF, many host operating
- * systems have drivers for it.  Accordingly, ACM is the preferred
- * interop solution for serial-port type connections.  The control
- * models are often not necessary, and in any case don't do much in
- * this bare-bones implementation.
- *
- * Note that even MS-Windows has some support for ACM.  However, that
- * support is somewhat broken because when you use ACM in a composite
- * device, having multiple interfaces confuses the poor OS.  It doesn't
- * seem to understand CDC Union descriptors.  The new "association"
- * descriptors (roughly equivalent to CDC Unions) may sometimes help.
- */
-
-struct f_acm {
-       struct gserial                  port;
-       u8                              ctrl_id, data_id;
-       u8                              port_num;
-
-       u8                              pending;
-
-       /* lock is mostly for pending and notify_req ... they get accessed
-        * by callbacks both from tty (open/close/break) under its spinlock,
-        * and notify_req.complete() which can't use that lock.
-        */
-       spinlock_t                      lock;
-
-       struct usb_ep                   *notify;
-       struct usb_request              *notify_req;
-
-       struct usb_cdc_line_coding      port_line_coding;       /* 8-N-1 etc */
-
-       /* SetControlLineState request -- CDC 1.1 section 6.2.14 (INPUT) */
-       u16                             port_handshake_bits;
-#define ACM_CTRL_RTS   (1 << 1)        /* unused with full duplex */
-#define ACM_CTRL_DTR   (1 << 0)        /* host is ready for data r/w */
-
-       /* SerialState notification -- CDC 1.1 section 6.3.5 (OUTPUT) */
-       u16                             serial_state;
-#define ACM_CTRL_OVERRUN       (1 << 6)
-#define ACM_CTRL_PARITY                (1 << 5)
-#define ACM_CTRL_FRAMING       (1 << 4)
-#define ACM_CTRL_RI            (1 << 3)
-#define ACM_CTRL_BRK           (1 << 2)
-#define ACM_CTRL_DSR           (1 << 1)
-#define ACM_CTRL_DCD           (1 << 0)
-};
-
-static inline struct f_acm *func_to_acm(struct usb_function *f)
-{
-       return container_of(f, struct f_acm, port.func);
-}
-
-static inline struct f_acm *port_to_acm(struct gserial *p)
-{
-       return container_of(p, struct f_acm, port);
-}
-
-/*-------------------------------------------------------------------------*/
-
-/* notification endpoint uses smallish and infrequent fixed-size messages */
-
-#define GS_LOG2_NOTIFY_INTERVAL                5       /* 1 << 5 == 32 msec */
-#define GS_NOTIFY_MAXPACKET            10      /* notification + 2 bytes */
-
-/* interface and class descriptors: */
-
-static struct usb_interface_assoc_descriptor
-acm_iad_descriptor = {
-       .bLength =              sizeof acm_iad_descriptor,
-       .bDescriptorType =      USB_DT_INTERFACE_ASSOCIATION,
-
-       /* .bFirstInterface =   DYNAMIC, */
-       .bInterfaceCount =      2,      // control + data
-       .bFunctionClass =       USB_CLASS_COMM,
-       .bFunctionSubClass =    USB_CDC_SUBCLASS_ACM,
-       .bFunctionProtocol =    USB_CDC_ACM_PROTO_AT_V25TER,
-       /* .iFunction =         DYNAMIC */
-};
-
-
-static struct usb_interface_descriptor acm_control_interface_desc = {
-       .bLength =              USB_DT_INTERFACE_SIZE,
-       .bDescriptorType =      USB_DT_INTERFACE,
-       /* .bInterfaceNumber = DYNAMIC */
-       .bNumEndpoints =        1,
-       .bInterfaceClass =      USB_CLASS_COMM,
-       .bInterfaceSubClass =   USB_CDC_SUBCLASS_ACM,
-       .bInterfaceProtocol =   USB_CDC_ACM_PROTO_AT_V25TER,
-       /* .iInterface = DYNAMIC */
-};
-
-static struct usb_interface_descriptor acm_data_interface_desc = {
-       .bLength =              USB_DT_INTERFACE_SIZE,
-       .bDescriptorType =      USB_DT_INTERFACE,
-       /* .bInterfaceNumber = DYNAMIC */
-       .bNumEndpoints =        2,
-       .bInterfaceClass =      USB_CLASS_CDC_DATA,
-       .bInterfaceSubClass =   0,
-       .bInterfaceProtocol =   0,
-       /* .iInterface = DYNAMIC */
-};
-
-static struct usb_cdc_header_desc acm_header_desc = {
-       .bLength =              sizeof(acm_header_desc),
-       .bDescriptorType =      USB_DT_CS_INTERFACE,
-       .bDescriptorSubType =   USB_CDC_HEADER_TYPE,
-       .bcdCDC =               cpu_to_le16(0x0110),
-};
-
-static struct usb_cdc_call_mgmt_descriptor
-acm_call_mgmt_descriptor = {
-       .bLength =              sizeof(acm_call_mgmt_descriptor),
-       .bDescriptorType =      USB_DT_CS_INTERFACE,
-       .bDescriptorSubType =   USB_CDC_CALL_MANAGEMENT_TYPE,
-       .bmCapabilities =       0,
-       /* .bDataInterface = DYNAMIC */
-};
-
-static struct usb_cdc_acm_descriptor acm_descriptor = {
-       .bLength =              sizeof(acm_descriptor),
-       .bDescriptorType =      USB_DT_CS_INTERFACE,
-       .bDescriptorSubType =   USB_CDC_ACM_TYPE,
-       .bmCapabilities =       USB_CDC_CAP_LINE,
-};
-
-static struct usb_cdc_union_desc acm_union_desc = {
-       .bLength =              sizeof(acm_union_desc),
-       .bDescriptorType =      USB_DT_CS_INTERFACE,
-       .bDescriptorSubType =   USB_CDC_UNION_TYPE,
-       /* .bMasterInterface0 = DYNAMIC */
-       /* .bSlaveInterface0 =  DYNAMIC */
-};
-
-/* full speed support: */
-
-static struct usb_endpoint_descriptor acm_fs_notify_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-       .bEndpointAddress =     USB_DIR_IN,
-       .bmAttributes =         USB_ENDPOINT_XFER_INT,
-       .wMaxPacketSize =       cpu_to_le16(GS_NOTIFY_MAXPACKET),
-       .bInterval =            1 << GS_LOG2_NOTIFY_INTERVAL,
-};
-
-static struct usb_endpoint_descriptor acm_fs_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-       .bEndpointAddress =     USB_DIR_IN,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-};
-
-static struct usb_endpoint_descriptor acm_fs_out_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-       .bEndpointAddress =     USB_DIR_OUT,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-};
-
-static struct usb_descriptor_header *acm_fs_function[] = {
-       (struct usb_descriptor_header *) &acm_iad_descriptor,
-       (struct usb_descriptor_header *) &acm_control_interface_desc,
-       (struct usb_descriptor_header *) &acm_header_desc,
-       (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
-       (struct usb_descriptor_header *) &acm_descriptor,
-       (struct usb_descriptor_header *) &acm_union_desc,
-       (struct usb_descriptor_header *) &acm_fs_notify_desc,
-       (struct usb_descriptor_header *) &acm_data_interface_desc,
-       (struct usb_descriptor_header *) &acm_fs_in_desc,
-       (struct usb_descriptor_header *) &acm_fs_out_desc,
-       NULL,
-};
-
-/* high speed support: */
-
-static struct usb_endpoint_descriptor acm_hs_notify_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-       .bEndpointAddress =     USB_DIR_IN,
-       .bmAttributes =         USB_ENDPOINT_XFER_INT,
-       .wMaxPacketSize =       cpu_to_le16(GS_NOTIFY_MAXPACKET),
-       .bInterval =            GS_LOG2_NOTIFY_INTERVAL+4,
-};
-
-static struct usb_endpoint_descriptor acm_hs_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(512),
-};
-
-static struct usb_endpoint_descriptor acm_hs_out_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(512),
-};
-
-static struct usb_descriptor_header *acm_hs_function[] = {
-       (struct usb_descriptor_header *) &acm_iad_descriptor,
-       (struct usb_descriptor_header *) &acm_control_interface_desc,
-       (struct usb_descriptor_header *) &acm_header_desc,
-       (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
-       (struct usb_descriptor_header *) &acm_descriptor,
-       (struct usb_descriptor_header *) &acm_union_desc,
-       (struct usb_descriptor_header *) &acm_hs_notify_desc,
-       (struct usb_descriptor_header *) &acm_data_interface_desc,
-       (struct usb_descriptor_header *) &acm_hs_in_desc,
-       (struct usb_descriptor_header *) &acm_hs_out_desc,
-       NULL,
-};
-
-static struct usb_endpoint_descriptor acm_ss_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(1024),
-};
-
-static struct usb_endpoint_descriptor acm_ss_out_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(1024),
-};
-
-static struct usb_ss_ep_comp_descriptor acm_ss_bulk_comp_desc = {
-       .bLength =              sizeof acm_ss_bulk_comp_desc,
-       .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
-};
-
-static struct usb_descriptor_header *acm_ss_function[] = {
-       (struct usb_descriptor_header *) &acm_iad_descriptor,
-       (struct usb_descriptor_header *) &acm_control_interface_desc,
-       (struct usb_descriptor_header *) &acm_header_desc,
-       (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
-       (struct usb_descriptor_header *) &acm_descriptor,
-       (struct usb_descriptor_header *) &acm_union_desc,
-       (struct usb_descriptor_header *) &acm_hs_notify_desc,
-       (struct usb_descriptor_header *) &acm_ss_bulk_comp_desc,
-       (struct usb_descriptor_header *) &acm_data_interface_desc,
-       (struct usb_descriptor_header *) &acm_ss_in_desc,
-       (struct usb_descriptor_header *) &acm_ss_bulk_comp_desc,
-       (struct usb_descriptor_header *) &acm_ss_out_desc,
-       (struct usb_descriptor_header *) &acm_ss_bulk_comp_desc,
-       NULL,
-};
-
-/* string descriptors: */
-
-#define ACM_CTRL_IDX   0
-#define ACM_DATA_IDX   1
-#define ACM_IAD_IDX    2
-
-/* static strings, in UTF-8 */
-static struct usb_string acm_string_defs[] = {
-       [ACM_CTRL_IDX].s = "CDC Abstract Control Model (ACM)",
-       [ACM_DATA_IDX].s = "CDC ACM Data",
-       [ACM_IAD_IDX ].s = "CDC Serial",
-       {  /* ZEROES END LIST */ },
-};
-
-static struct usb_gadget_strings acm_string_table = {
-       .language =             0x0409, /* en-us */
-       .strings =              acm_string_defs,
-};
-
-static struct usb_gadget_strings *acm_strings[] = {
-       &acm_string_table,
-       NULL,
-};
-
-/*-------------------------------------------------------------------------*/
-
-/* ACM control ... data handling is delegated to tty library code.
- * The main task of this function is to activate and deactivate
- * that code based on device state; track parameters like line
- * speed, handshake state, and so on; and issue notifications.
- */
-
-static void acm_complete_set_line_coding(struct usb_ep *ep,
-               struct usb_request *req)
-{
-       struct f_acm    *acm = ep->driver_data;
-       struct usb_composite_dev *cdev = acm->port.func.config->cdev;
-
-       if (req->status != 0) {
-               DBG(cdev, "acm ttyGS%d completion, err %d\n",
-                               acm->port_num, req->status);
-               return;
-       }
-
-       /* normal completion */
-       if (req->actual != sizeof(acm->port_line_coding)) {
-               DBG(cdev, "acm ttyGS%d short resp, len %d\n",
-                               acm->port_num, req->actual);
-               usb_ep_set_halt(ep);
-       } else {
-               struct usb_cdc_line_coding      *value = req->buf;
-
-               /* REVISIT:  we currently just remember this data.
-                * If we change that, (a) validate it first, then
-                * (b) update whatever hardware needs updating,
-                * (c) worry about locking.  This is information on
-                * the order of 9600-8-N-1 ... most of which means
-                * nothing unless we control a real RS232 line.
-                */
-               acm->port_line_coding = *value;
-       }
-}
-
-static int acm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
-{
-       struct f_acm            *acm = func_to_acm(f);
-       struct usb_composite_dev *cdev = f->config->cdev;
-       struct usb_request      *req = cdev->req;
-       int                     value = -EOPNOTSUPP;
-       u16                     w_index = le16_to_cpu(ctrl->wIndex);
-       u16                     w_value = le16_to_cpu(ctrl->wValue);
-       u16                     w_length = le16_to_cpu(ctrl->wLength);
-
-       /* composite driver infrastructure handles everything except
-        * CDC class messages; interface activation uses set_alt().
-        *
-        * Note CDC spec table 4 lists the ACM request profile.  It requires
-        * encapsulated command support ... we don't handle any, and respond
-        * to them by stalling.  Options include get/set/clear comm features
-        * (not that useful) and SEND_BREAK.
-        */
-       switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
-
-       /* SET_LINE_CODING ... just read and save what the host sends */
-       case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
-                       | USB_CDC_REQ_SET_LINE_CODING:
-               if (w_length != sizeof(struct usb_cdc_line_coding)
-                               || w_index != acm->ctrl_id)
-                       goto invalid;
-
-               value = w_length;
-               cdev->gadget->ep0->driver_data = acm;
-               req->complete = acm_complete_set_line_coding;
-               break;
-
-       /* GET_LINE_CODING ... return what host sent, or initial value */
-       case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
-                       | USB_CDC_REQ_GET_LINE_CODING:
-               if (w_index != acm->ctrl_id)
-                       goto invalid;
-
-               value = min_t(unsigned, w_length,
-                               sizeof(struct usb_cdc_line_coding));
-               memcpy(req->buf, &acm->port_line_coding, value);
-               break;
-
-       /* SET_CONTROL_LINE_STATE ... save what the host sent */
-       case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
-                       | USB_CDC_REQ_SET_CONTROL_LINE_STATE:
-               if (w_index != acm->ctrl_id)
-                       goto invalid;
-
-               value = 0;
-
-               /* FIXME we should not allow data to flow until the
-                * host sets the ACM_CTRL_DTR bit; and when it clears
-                * that bit, we should return to that no-flow state.
-                */
-               acm->port_handshake_bits = w_value;
-               break;
-
-       default:
-invalid:
-               VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
-                       ctrl->bRequestType, ctrl->bRequest,
-                       w_value, w_index, w_length);
-       }
-
-       /* respond with data transfer or status phase? */
-       if (value >= 0) {
-               DBG(cdev, "acm ttyGS%d req%02x.%02x v%04x i%04x l%d\n",
-                       acm->port_num, ctrl->bRequestType, ctrl->bRequest,
-                       w_value, w_index, w_length);
-               req->zero = 0;
-               req->length = value;
-               value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
-               if (value < 0)
-                       ERROR(cdev, "acm response on ttyGS%d, err %d\n",
-                                       acm->port_num, value);
-       }
-
-       /* device either stalls (value < 0) or reports success */
-       return value;
-}
-
-static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
-{
-       struct f_acm            *acm = func_to_acm(f);
-       struct usb_composite_dev *cdev = f->config->cdev;
-
-       /* we know alt == 0, so this is an activation or a reset */
-
-       if (intf == acm->ctrl_id) {
-               if (acm->notify->driver_data) {
-                       VDBG(cdev, "reset acm control interface %d\n", intf);
-                       usb_ep_disable(acm->notify);
-               } else {
-                       VDBG(cdev, "init acm ctrl interface %d\n", intf);
-                       if (config_ep_by_speed(cdev->gadget, f, acm->notify))
-                               return -EINVAL;
-               }
-               usb_ep_enable(acm->notify);
-               acm->notify->driver_data = acm;
-
-       } else if (intf == acm->data_id) {
-               if (acm->port.in->driver_data) {
-                       DBG(cdev, "reset acm ttyGS%d\n", acm->port_num);
-                       gserial_disconnect(&acm->port);
-               }
-               if (!acm->port.in->desc || !acm->port.out->desc) {
-                       DBG(cdev, "activate acm ttyGS%d\n", acm->port_num);
-                       if (config_ep_by_speed(cdev->gadget, f,
-                                              acm->port.in) ||
-                           config_ep_by_speed(cdev->gadget, f,
-                                              acm->port.out)) {
-                               acm->port.in->desc = NULL;
-                               acm->port.out->desc = NULL;
-                               return -EINVAL;
-                       }
-               }
-               gserial_connect(&acm->port, acm->port_num);
-
-       } else
-               return -EINVAL;
-
-       return 0;
-}
-
-static void acm_disable(struct usb_function *f)
-{
-       struct f_acm    *acm = func_to_acm(f);
-       struct usb_composite_dev *cdev = f->config->cdev;
-
-       DBG(cdev, "acm ttyGS%d deactivated\n", acm->port_num);
-       gserial_disconnect(&acm->port);
-       usb_ep_disable(acm->notify);
-       acm->notify->driver_data = NULL;
-}
-
-/*-------------------------------------------------------------------------*/
-
-/**
- * acm_cdc_notify - issue CDC notification to host
- * @acm: wraps host to be notified
- * @type: notification type
- * @value: Refer to cdc specs, wValue field.
- * @data: data to be sent
- * @length: size of data
- * Context: irqs blocked, acm->lock held, acm_notify_req non-null
- *
- * Returns zero on success or a negative errno.
- *
- * See section 6.3.5 of the CDC 1.1 specification for information
- * about the only notification we issue:  SerialState change.
- */
-static int acm_cdc_notify(struct f_acm *acm, u8 type, u16 value,
-               void *data, unsigned length)
-{
-       struct usb_ep                   *ep = acm->notify;
-       struct usb_request              *req;
-       struct usb_cdc_notification     *notify;
-       const unsigned                  len = sizeof(*notify) + length;
-       void                            *buf;
-       int                             status;
-
-       req = acm->notify_req;
-       acm->notify_req = NULL;
-       acm->pending = false;
-
-       req->length = len;
-       notify = req->buf;
-       buf = notify + 1;
-
-       notify->bmRequestType = USB_DIR_IN | USB_TYPE_CLASS
-                       | USB_RECIP_INTERFACE;
-       notify->bNotificationType = type;
-       notify->wValue = cpu_to_le16(value);
-       notify->wIndex = cpu_to_le16(acm->ctrl_id);
-       notify->wLength = cpu_to_le16(length);
-       memcpy(buf, data, length);
-
-       /* ep_queue() can complete immediately if it fills the fifo... */
-       spin_unlock(&acm->lock);
-       status = usb_ep_queue(ep, req, GFP_ATOMIC);
-       spin_lock(&acm->lock);
-
-       if (status < 0) {
-               ERROR(acm->port.func.config->cdev,
-                               "acm ttyGS%d can't notify serial state, %d\n",
-                               acm->port_num, status);
-               acm->notify_req = req;
-       }
-
-       return status;
-}
-
-static int acm_notify_serial_state(struct f_acm *acm)
-{
-       struct usb_composite_dev *cdev = acm->port.func.config->cdev;
-       int                     status;
-
-       spin_lock(&acm->lock);
-       if (acm->notify_req) {
-               DBG(cdev, "acm ttyGS%d serial state %04x\n",
-                               acm->port_num, acm->serial_state);
-               status = acm_cdc_notify(acm, USB_CDC_NOTIFY_SERIAL_STATE,
-                               0, &acm->serial_state, sizeof(acm->serial_state));
-       } else {
-               acm->pending = true;
-               status = 0;
-       }
-       spin_unlock(&acm->lock);
-       return status;
-}
-
-static void acm_cdc_notify_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       struct f_acm            *acm = req->context;
-       u8                      doit = false;
-
-       /* on this call path we do NOT hold the port spinlock,
-        * which is why ACM needs its own spinlock
-        */
-       spin_lock(&acm->lock);
-       if (req->status != -ESHUTDOWN)
-               doit = acm->pending;
-       acm->notify_req = req;
-       spin_unlock(&acm->lock);
-
-       if (doit)
-               acm_notify_serial_state(acm);
-}
-
-/* connect == the TTY link is open */
-
-static void acm_connect(struct gserial *port)
-{
-       struct f_acm            *acm = port_to_acm(port);
-
-       acm->serial_state |= ACM_CTRL_DSR | ACM_CTRL_DCD;
-       acm_notify_serial_state(acm);
-}
-
-static void acm_disconnect(struct gserial *port)
-{
-       struct f_acm            *acm = port_to_acm(port);
-
-       acm->serial_state &= ~(ACM_CTRL_DSR | ACM_CTRL_DCD);
-       acm_notify_serial_state(acm);
-}
-
-static int acm_send_break(struct gserial *port, int duration)
-{
-       struct f_acm            *acm = port_to_acm(port);
-       u16                     state;
-
-       state = acm->serial_state;
-       state &= ~ACM_CTRL_BRK;
-       if (duration)
-               state |= ACM_CTRL_BRK;
-
-       acm->serial_state = state;
-       return acm_notify_serial_state(acm);
-}
-
-/*-------------------------------------------------------------------------*/
-
-/* ACM function driver setup/binding */
-static int
-acm_bind(struct usb_configuration *c, struct usb_function *f)
-{
-       struct usb_composite_dev *cdev = c->cdev;
-       struct f_acm            *acm = func_to_acm(f);
-       int                     status;
-       struct usb_ep           *ep;
-
-       /* allocate instance-specific interface IDs, and patch descriptors */
-       status = usb_interface_id(c, f);
-       if (status < 0)
-               goto fail;
-       acm->ctrl_id = status;
-       acm_iad_descriptor.bFirstInterface = status;
-
-       acm_control_interface_desc.bInterfaceNumber = status;
-       acm_union_desc .bMasterInterface0 = status;
-
-       status = usb_interface_id(c, f);
-       if (status < 0)
-               goto fail;
-       acm->data_id = status;
-
-       acm_data_interface_desc.bInterfaceNumber = status;
-       acm_union_desc.bSlaveInterface0 = status;
-       acm_call_mgmt_descriptor.bDataInterface = status;
-
-       status = -ENODEV;
-
-       /* allocate instance-specific endpoints */
-       ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_in_desc);
-       if (!ep)
-               goto fail;
-       acm->port.in = ep;
-       ep->driver_data = cdev; /* claim */
-
-       ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_out_desc);
-       if (!ep)
-               goto fail;
-       acm->port.out = ep;
-       ep->driver_data = cdev; /* claim */
-
-       ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_notify_desc);
-       if (!ep)
-               goto fail;
-       acm->notify = ep;
-       ep->driver_data = cdev; /* claim */
-
-       /* allocate notification */
-       acm->notify_req = gs_alloc_req(ep,
-                       sizeof(struct usb_cdc_notification) + 2,
-                       GFP_KERNEL);
-       if (!acm->notify_req)
-               goto fail;
-
-       acm->notify_req->complete = acm_cdc_notify_complete;
-       acm->notify_req->context = acm;
-
-       /* copy descriptors */
-       f->descriptors = usb_copy_descriptors(acm_fs_function);
-       if (!f->descriptors)
-               goto fail;
-
-       /* support all relevant hardware speeds... we expect that when
-        * hardware is dual speed, all bulk-capable endpoints work at
-        * both speeds
-        */
-       if (gadget_is_dualspeed(c->cdev->gadget)) {
-               acm_hs_in_desc.bEndpointAddress =
-                               acm_fs_in_desc.bEndpointAddress;
-               acm_hs_out_desc.bEndpointAddress =
-                               acm_fs_out_desc.bEndpointAddress;
-               acm_hs_notify_desc.bEndpointAddress =
-                               acm_fs_notify_desc.bEndpointAddress;
-
-               /* copy descriptors */
-               f->hs_descriptors = usb_copy_descriptors(acm_hs_function);
-       }
-       if (gadget_is_superspeed(c->cdev->gadget)) {
-               acm_ss_in_desc.bEndpointAddress =
-                       acm_fs_in_desc.bEndpointAddress;
-               acm_ss_out_desc.bEndpointAddress =
-                       acm_fs_out_desc.bEndpointAddress;
-
-               /* copy descriptors, and track endpoint copies */
-               f->ss_descriptors = usb_copy_descriptors(acm_ss_function);
-               if (!f->ss_descriptors)
-                       goto fail;
-       }
-
-       DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n",
-                       acm->port_num,
-                       gadget_is_superspeed(c->cdev->gadget) ? "super" :
-                       gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
-                       acm->port.in->name, acm->port.out->name,
-                       acm->notify->name);
-       return 0;
-
-fail:
-       if (acm->notify_req)
-               gs_free_req(acm->notify, acm->notify_req);
-
-       /* we might as well release our claims on endpoints */
-       if (acm->notify)
-               acm->notify->driver_data = NULL;
-       if (acm->port.out)
-               acm->port.out->driver_data = NULL;
-       if (acm->port.in)
-               acm->port.in->driver_data = NULL;
-
-       ERROR(cdev, "%s/%p: can't bind, err %d\n", f->name, f, status);
-
-       return status;
-}
-
-static void
-acm_unbind(struct usb_configuration *c, struct usb_function *f)
-{
-       struct f_acm            *acm = func_to_acm(f);
-
-       if (gadget_is_dualspeed(c->cdev->gadget))
-               usb_free_descriptors(f->hs_descriptors);
-       if (gadget_is_superspeed(c->cdev->gadget))
-               usb_free_descriptors(f->ss_descriptors);
-       usb_free_descriptors(f->descriptors);
-       gs_free_req(acm->notify, acm->notify_req);
-       kfree(acm);
-}
-
-/* Some controllers can't support CDC ACM ... */
-static inline bool can_support_cdc(struct usb_configuration *c)
-{
-       /* everything else is *probably* fine ... */
-       return true;
-}
-
-/**
- * acm_bind_config - add a CDC ACM function to a configuration
- * @c: the configuration to support the CDC ACM instance
- * @port_num: /dev/ttyGS* port this interface will use
- * Context: single threaded during gadget setup
- *
- * Returns zero on success, else negative errno.
- *
- * Caller must have called @gserial_setup() with enough ports to
- * handle all the ones it binds.  Caller is also responsible
- * for calling @gserial_cleanup() before module unload.
- */
-int acm_bind_config(struct usb_configuration *c, u8 port_num)
-{
-       struct f_acm    *acm;
-       int             status;
-
-       if (!can_support_cdc(c))
-               return -EINVAL;
-
-       /* REVISIT might want instance-specific strings to help
-        * distinguish instances ...
-        */
-
-       /* maybe allocate device-global string IDs, and patch descriptors */
-       if (acm_string_defs[ACM_CTRL_IDX].id == 0) {
-               status = usb_string_id(c->cdev);
-               if (status < 0)
-                       return status;
-               acm_string_defs[ACM_CTRL_IDX].id = status;
-
-               acm_control_interface_desc.iInterface = status;
-
-               status = usb_string_id(c->cdev);
-               if (status < 0)
-                       return status;
-               acm_string_defs[ACM_DATA_IDX].id = status;
-
-               acm_data_interface_desc.iInterface = status;
-
-               status = usb_string_id(c->cdev);
-               if (status < 0)
-                       return status;
-               acm_string_defs[ACM_IAD_IDX].id = status;
-
-               acm_iad_descriptor.iFunction = status;
-       }
-
-       /* allocate and initialize one new instance */
-       acm = kzalloc(sizeof *acm, GFP_KERNEL);
-       if (!acm)
-               return -ENOMEM;
-
-       spin_lock_init(&acm->lock);
-
-       acm->port_num = port_num;
-
-       acm->port.connect = acm_connect;
-       acm->port.disconnect = acm_disconnect;
-       acm->port.send_break = acm_send_break;
-
-       acm->port.func.name = "acm";
-       acm->port.func.strings = acm_strings;
-       /* descriptors are per-instance copies */
-       acm->port.func.bind = acm_bind;
-       acm->port.func.unbind = acm_unbind;
-       acm->port.func.set_alt = acm_set_alt;
-       acm->port.func.setup = acm_setup;
-       acm->port.func.disable = acm_disable;
-
-       status = usb_add_function(c, &acm->port.func);
-       if (status)
-               kfree(acm);
-       return status;
-}
diff --git a/drivers/staging/ccg/f_fs.c b/drivers/staging/ccg/f_fs.c
deleted file mode 100644 (file)
index f6373da..0000000
+++ /dev/null
@@ -1,2456 +0,0 @@
-/*
- * f_fs.c -- user mode file system API for USB composite function controllers
- *
- * Copyright (C) 2010 Samsung Electronics
- * Author: Michal Nazarewicz <mina86@mina86.com>
- *
- * Based on inode.c (GadgetFS) which was:
- * Copyright (C) 2003-2004 David Brownell
- * Copyright (C) 2003 Agilent Technologies
- *
- * 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.
- */
-
-
-/* #define DEBUG */
-/* #define VERBOSE_DEBUG */
-
-#include <linux/blkdev.h>
-#include <linux/pagemap.h>
-#include <linux/export.h>
-#include <linux/hid.h>
-#include <asm/unaligned.h>
-
-#include <linux/usb/composite.h>
-#include <linux/usb/functionfs.h>
-
-
-#define FUNCTIONFS_MAGIC       0xa647361 /* Chosen by a honest dice roll ;) */
-
-
-/* Debugging ****************************************************************/
-
-#ifdef VERBOSE_DEBUG
-#  define pr_vdebug pr_debug
-#  define ffs_dump_mem(prefix, ptr, len) \
-       print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len)
-#else
-#  define pr_vdebug(...)                 do { } while (0)
-#  define ffs_dump_mem(prefix, ptr, len) do { } while (0)
-#endif /* VERBOSE_DEBUG */
-
-#define ENTER()    pr_vdebug("%s()\n", __func__)
-
-
-/* The data structure and setup file ****************************************/
-
-enum ffs_state {
-       /*
-        * Waiting for descriptors and strings.
-        *
-        * In this state no open(2), read(2) or write(2) on epfiles
-        * may succeed (which should not be the problem as there
-        * should be no such files opened in the first place).
-        */
-       FFS_READ_DESCRIPTORS,
-       FFS_READ_STRINGS,
-
-       /*
-        * We've got descriptors and strings.  We are or have called
-        * functionfs_ready_callback().  functionfs_bind() may have
-        * been called but we don't know.
-        *
-        * This is the only state in which operations on epfiles may
-        * succeed.
-        */
-       FFS_ACTIVE,
-
-       /*
-        * All endpoints have been closed.  This state is also set if
-        * we encounter an unrecoverable error.  The only
-        * unrecoverable error is situation when after reading strings
-        * from user space we fail to initialise epfiles or
-        * functionfs_ready_callback() returns with error (<0).
-        *
-        * In this state no open(2), read(2) or write(2) (both on ep0
-        * as well as epfile) may succeed (at this point epfiles are
-        * unlinked and all closed so this is not a problem; ep0 is
-        * also closed but ep0 file exists and so open(2) on ep0 must
-        * fail).
-        */
-       FFS_CLOSING
-};
-
-
-enum ffs_setup_state {
-       /* There is no setup request pending. */
-       FFS_NO_SETUP,
-       /*
-        * User has read events and there was a setup request event
-        * there.  The next read/write on ep0 will handle the
-        * request.
-        */
-       FFS_SETUP_PENDING,
-       /*
-        * There was event pending but before user space handled it
-        * some other event was introduced which canceled existing
-        * setup.  If this state is set read/write on ep0 return
-        * -EIDRM.  This state is only set when adding event.
-        */
-       FFS_SETUP_CANCELED
-};
-
-
-
-struct ffs_epfile;
-struct ffs_function;
-
-struct ffs_data {
-       struct usb_gadget               *gadget;
-
-       /*
-        * Protect access read/write operations, only one read/write
-        * at a time.  As a consequence protects ep0req and company.
-        * While setup request is being processed (queued) this is
-        * held.
-        */
-       struct mutex                    mutex;
-
-       /*
-        * Protect access to endpoint related structures (basically
-        * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for
-        * endpoint zero.
-        */
-       spinlock_t                      eps_lock;
-
-       /*
-        * XXX REVISIT do we need our own request? Since we are not
-        * handling setup requests immediately user space may be so
-        * slow that another setup will be sent to the gadget but this
-        * time not to us but another function and then there could be
-        * a race.  Is that the case? Or maybe we can use cdev->req
-        * after all, maybe we just need some spinlock for that?
-        */
-       struct usb_request              *ep0req;                /* P: mutex */
-       struct completion               ep0req_completion;      /* P: mutex */
-       int                             ep0req_status;          /* P: mutex */
-
-       /* reference counter */
-       atomic_t                        ref;
-       /* how many files are opened (EP0 and others) */
-       atomic_t                        opened;
-
-       /* EP0 state */
-       enum ffs_state                  state;
-
-       /*
-        * Possible transitions:
-        * + FFS_NO_SETUP       -> FFS_SETUP_PENDING  -- P: ev.waitq.lock
-        *               happens only in ep0 read which is P: mutex
-        * + FFS_SETUP_PENDING  -> FFS_NO_SETUP       -- P: ev.waitq.lock
-        *               happens only in ep0 i/o  which is P: mutex
-        * + FFS_SETUP_PENDING  -> FFS_SETUP_CANCELED -- P: ev.waitq.lock
-        * + FFS_SETUP_CANCELED -> FFS_NO_SETUP       -- cmpxchg
-        */
-       enum ffs_setup_state            setup_state;
-
-#define FFS_SETUP_STATE(ffs)                                   \
-       ((enum ffs_setup_state)cmpxchg(&(ffs)->setup_state,     \
-                                      FFS_SETUP_CANCELED, FFS_NO_SETUP))
-
-       /* Events & such. */
-       struct {
-               u8                              types[4];
-               unsigned short                  count;
-               /* XXX REVISIT need to update it in some places, or do we? */
-               unsigned short                  can_stall;
-               struct usb_ctrlrequest          setup;
-
-               wait_queue_head_t               waitq;
-       } ev; /* the whole structure, P: ev.waitq.lock */
-
-       /* Flags */
-       unsigned long                   flags;
-#define FFS_FL_CALL_CLOSED_CALLBACK 0
-#define FFS_FL_BOUND                1
-
-       /* Active function */
-       struct ffs_function             *func;
-
-       /*
-        * Device name, write once when file system is mounted.
-        * Intended for user to read if she wants.
-        */
-       const char                      *dev_name;
-       /* Private data for our user (ie. gadget).  Managed by user. */
-       void                            *private_data;
-
-       /* filled by __ffs_data_got_descs() */
-       /*
-        * Real descriptors are 16 bytes after raw_descs (so you need
-        * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the
-        * first full speed descriptor).  raw_descs_length and
-        * raw_fs_descs_length do not have those 16 bytes added.
-        */
-       const void                      *raw_descs;
-       unsigned                        raw_descs_length;
-       unsigned                        raw_fs_descs_length;
-       unsigned                        fs_descs_count;
-       unsigned                        hs_descs_count;
-
-       unsigned short                  strings_count;
-       unsigned short                  interfaces_count;
-       unsigned short                  eps_count;
-       unsigned short                  _pad1;
-
-       /* filled by __ffs_data_got_strings() */
-       /* ids in stringtabs are set in functionfs_bind() */
-       const void                      *raw_strings;
-       struct usb_gadget_strings       **stringtabs;
-
-       /*
-        * File system's super block, write once when file system is
-        * mounted.
-        */
-       struct super_block              *sb;
-
-       /* File permissions, written once when fs is mounted */
-       struct ffs_file_perms {
-               umode_t                         mode;
-               uid_t                           uid;
-               gid_t                           gid;
-       }                               file_perms;
-
-       /*
-        * The endpoint files, filled by ffs_epfiles_create(),
-        * destroyed by ffs_epfiles_destroy().
-        */
-       struct ffs_epfile               *epfiles;
-};
-
-/* Reference counter handling */
-static void ffs_data_get(struct ffs_data *ffs);
-static void ffs_data_put(struct ffs_data *ffs);
-/* Creates new ffs_data object. */
-static struct ffs_data *__must_check ffs_data_new(void) __attribute__((malloc));
-
-/* Opened counter handling. */
-static void ffs_data_opened(struct ffs_data *ffs);
-static void ffs_data_closed(struct ffs_data *ffs);
-
-/* Called with ffs->mutex held; take over ownership of data. */
-static int __must_check
-__ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len);
-static int __must_check
-__ffs_data_got_strings(struct ffs_data *ffs, char *data, size_t len);
-
-
-/* The function structure ***************************************************/
-
-struct ffs_ep;
-
-struct ffs_function {
-       struct usb_configuration        *conf;
-       struct usb_gadget               *gadget;
-       struct ffs_data                 *ffs;
-
-       struct ffs_ep                   *eps;
-       u8                              eps_revmap[16];
-       short                           *interfaces_nums;
-
-       struct usb_function             function;
-};
-
-
-static struct ffs_function *ffs_func_from_usb(struct usb_function *f)
-{
-       return container_of(f, struct ffs_function, function);
-}
-
-static void ffs_func_free(struct ffs_function *func);
-
-static void ffs_func_eps_disable(struct ffs_function *func);
-static int __must_check ffs_func_eps_enable(struct ffs_function *func);
-
-static int ffs_func_bind(struct usb_configuration *,
-                        struct usb_function *);
-static void ffs_func_unbind(struct usb_configuration *,
-                           struct usb_function *);
-static int ffs_func_set_alt(struct usb_function *, unsigned, unsigned);
-static void ffs_func_disable(struct usb_function *);
-static int ffs_func_setup(struct usb_function *,
-                         const struct usb_ctrlrequest *);
-static void ffs_func_suspend(struct usb_function *);
-static void ffs_func_resume(struct usb_function *);
-
-
-static int ffs_func_revmap_ep(struct ffs_function *func, u8 num);
-static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf);
-
-
-/* The endpoints structures *************************************************/
-
-struct ffs_ep {
-       struct usb_ep                   *ep;    /* P: ffs->eps_lock */
-       struct usb_request              *req;   /* P: epfile->mutex */
-
-       /* [0]: full speed, [1]: high speed */
-       struct usb_endpoint_descriptor  *descs[2];
-
-       u8                              num;
-
-       int                             status; /* P: epfile->mutex */
-};
-
-struct ffs_epfile {
-       /* Protects ep->ep and ep->req. */
-       struct mutex                    mutex;
-       wait_queue_head_t               wait;
-
-       struct ffs_data                 *ffs;
-       struct ffs_ep                   *ep;    /* P: ffs->eps_lock */
-
-       struct dentry                   *dentry;
-
-       char                            name[5];
-
-       unsigned char                   in;     /* P: ffs->eps_lock */
-       unsigned char                   isoc;   /* P: ffs->eps_lock */
-
-       unsigned char                   _pad;
-};
-
-static int  __must_check ffs_epfiles_create(struct ffs_data *ffs);
-static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count);
-
-static struct inode *__must_check
-ffs_sb_create_file(struct super_block *sb, const char *name, void *data,
-                  const struct file_operations *fops,
-                  struct dentry **dentry_p);
-
-
-/* Misc helper functions ****************************************************/
-
-static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock)
-       __attribute__((warn_unused_result, nonnull));
-static char *ffs_prepare_buffer(const char * __user buf, size_t len)
-       __attribute__((warn_unused_result, nonnull));
-
-
-/* Control file aka ep0 *****************************************************/
-
-static void ffs_ep0_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       struct ffs_data *ffs = req->context;
-
-       complete_all(&ffs->ep0req_completion);
-}
-
-static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
-{
-       struct usb_request *req = ffs->ep0req;
-       int ret;
-
-       req->zero     = len < le16_to_cpu(ffs->ev.setup.wLength);
-
-       spin_unlock_irq(&ffs->ev.waitq.lock);
-
-       req->buf      = data;
-       req->length   = len;
-
-       /*
-        * UDC layer requires to provide a buffer even for ZLP, but should
-        * not use it at all. Let's provide some poisoned pointer to catch
-        * possible bug in the driver.
-        */
-       if (req->buf == NULL)
-               req->buf = (void *)0xDEADBABE;
-
-       INIT_COMPLETION(ffs->ep0req_completion);
-
-       ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC);
-       if (unlikely(ret < 0))
-               return ret;
-
-       ret = wait_for_completion_interruptible(&ffs->ep0req_completion);
-       if (unlikely(ret)) {
-               usb_ep_dequeue(ffs->gadget->ep0, req);
-               return -EINTR;
-       }
-
-       ffs->setup_state = FFS_NO_SETUP;
-       return ffs->ep0req_status;
-}
-
-static int __ffs_ep0_stall(struct ffs_data *ffs)
-{
-       if (ffs->ev.can_stall) {
-               pr_vdebug("ep0 stall\n");
-               usb_ep_set_halt(ffs->gadget->ep0);
-               ffs->setup_state = FFS_NO_SETUP;
-               return -EL2HLT;
-       } else {
-               pr_debug("bogus ep0 stall!\n");
-               return -ESRCH;
-       }
-}
-
-static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
-                            size_t len, loff_t *ptr)
-{
-       struct ffs_data *ffs = file->private_data;
-       ssize_t ret;
-       char *data;
-
-       ENTER();
-
-       /* Fast check if setup was canceled */
-       if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED)
-               return -EIDRM;
-
-       /* Acquire mutex */
-       ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
-       if (unlikely(ret < 0))
-               return ret;
-
-       /* Check state */
-       switch (ffs->state) {
-       case FFS_READ_DESCRIPTORS:
-       case FFS_READ_STRINGS:
-               /* Copy data */
-               if (unlikely(len < 16)) {
-                       ret = -EINVAL;
-                       break;
-               }
-
-               data = ffs_prepare_buffer(buf, len);
-               if (IS_ERR(data)) {
-                       ret = PTR_ERR(data);
-                       break;
-               }
-
-               /* Handle data */
-               if (ffs->state == FFS_READ_DESCRIPTORS) {
-                       pr_info("read descriptors\n");
-                       ret = __ffs_data_got_descs(ffs, data, len);
-                       if (unlikely(ret < 0))
-                               break;
-
-                       ffs->state = FFS_READ_STRINGS;
-                       ret = len;
-               } else {
-                       pr_info("read strings\n");
-                       ret = __ffs_data_got_strings(ffs, data, len);
-                       if (unlikely(ret < 0))
-                               break;
-
-                       ret = ffs_epfiles_create(ffs);
-                       if (unlikely(ret)) {
-                               ffs->state = FFS_CLOSING;
-                               break;
-                       }
-
-                       ffs->state = FFS_ACTIVE;
-                       mutex_unlock(&ffs->mutex);
-
-                       ret = functionfs_ready_callback(ffs);
-                       if (unlikely(ret < 0)) {
-                               ffs->state = FFS_CLOSING;
-                               return ret;
-                       }
-
-                       set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags);
-                       return len;
-               }
-               break;
-
-       case FFS_ACTIVE:
-               data = NULL;
-               /*
-                * We're called from user space, we can use _irq
-                * rather then _irqsave
-                */
-               spin_lock_irq(&ffs->ev.waitq.lock);
-               switch (FFS_SETUP_STATE(ffs)) {
-               case FFS_SETUP_CANCELED:
-                       ret = -EIDRM;
-                       goto done_spin;
-
-               case FFS_NO_SETUP:
-                       ret = -ESRCH;
-                       goto done_spin;
-
-               case FFS_SETUP_PENDING:
-                       break;
-               }
-
-               /* FFS_SETUP_PENDING */
-               if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) {
-                       spin_unlock_irq(&ffs->ev.waitq.lock);
-                       ret = __ffs_ep0_stall(ffs);
-                       break;
-               }
-
-               /* FFS_SETUP_PENDING and not stall */
-               len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength));
-
-               spin_unlock_irq(&ffs->ev.waitq.lock);
-
-               data = ffs_prepare_buffer(buf, len);
-               if (IS_ERR(data)) {
-                       ret = PTR_ERR(data);
-                       break;
-               }
-
-               spin_lock_irq(&ffs->ev.waitq.lock);
-
-               /*
-                * We are guaranteed to be still in FFS_ACTIVE state
-                * but the state of setup could have changed from
-                * FFS_SETUP_PENDING to FFS_SETUP_CANCELED so we need
-                * to check for that.  If that happened we copied data
-                * from user space in vain but it's unlikely.
-                *
-                * For sure we are not in FFS_NO_SETUP since this is
-                * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP
-                * transition can be performed and it's protected by
-                * mutex.
-                */
-               if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) {
-                       ret = -EIDRM;
-done_spin:
-                       spin_unlock_irq(&ffs->ev.waitq.lock);
-               } else {
-                       /* unlocks spinlock */
-                       ret = __ffs_ep0_queue_wait(ffs, data, len);
-               }
-               kfree(data);
-               break;
-
-       default:
-               ret = -EBADFD;
-               break;
-       }
-
-       mutex_unlock(&ffs->mutex);
-       return ret;
-}
-
-static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf,
-                                    size_t n)
-{
-       /*
-        * We are holding ffs->ev.waitq.lock and ffs->mutex and we need
-        * to release them.
-        */
-       struct usb_functionfs_event events[n];
-       unsigned i = 0;
-
-       memset(events, 0, sizeof events);
-
-       do {
-               events[i].type = ffs->ev.types[i];
-               if (events[i].type == FUNCTIONFS_SETUP) {
-                       events[i].u.setup = ffs->ev.setup;
-                       ffs->setup_state = FFS_SETUP_PENDING;
-               }
-       } while (++i < n);
-
-       if (n < ffs->ev.count) {
-               ffs->ev.count -= n;
-               memmove(ffs->ev.types, ffs->ev.types + n,
-                       ffs->ev.count * sizeof *ffs->ev.types);
-       } else {
-               ffs->ev.count = 0;
-       }
-
-       spin_unlock_irq(&ffs->ev.waitq.lock);
-       mutex_unlock(&ffs->mutex);
-
-       return unlikely(__copy_to_user(buf, events, sizeof events))
-               ? -EFAULT : sizeof events;
-}
-
-static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
-                           size_t len, loff_t *ptr)
-{
-       struct ffs_data *ffs = file->private_data;
-       char *data = NULL;
-       size_t n;
-       int ret;
-
-       ENTER();
-
-       /* Fast check if setup was canceled */
-       if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED)
-               return -EIDRM;
-
-       /* Acquire mutex */
-       ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
-       if (unlikely(ret < 0))
-               return ret;
-
-       /* Check state */
-       if (ffs->state != FFS_ACTIVE) {
-               ret = -EBADFD;
-               goto done_mutex;
-       }
-
-       /*
-        * We're called from user space, we can use _irq rather then
-        * _irqsave
-        */
-       spin_lock_irq(&ffs->ev.waitq.lock);
-
-       switch (FFS_SETUP_STATE(ffs)) {
-       case FFS_SETUP_CANCELED:
-               ret = -EIDRM;
-               break;
-
-       case FFS_NO_SETUP:
-               n = len / sizeof(struct usb_functionfs_event);
-               if (unlikely(!n)) {
-                       ret = -EINVAL;
-                       break;
-               }
-
-               if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) {
-                       ret = -EAGAIN;
-                       break;
-               }
-
-               if (wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq,
-                                                       ffs->ev.count)) {
-                       ret = -EINTR;
-                       break;
-               }
-
-               return __ffs_ep0_read_events(ffs, buf,
-                                            min(n, (size_t)ffs->ev.count));
-
-       case FFS_SETUP_PENDING:
-               if (ffs->ev.setup.bRequestType & USB_DIR_IN) {
-                       spin_unlock_irq(&ffs->ev.waitq.lock);
-                       ret = __ffs_ep0_stall(ffs);
-                       goto done_mutex;
-               }
-
-               len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength));
-
-               spin_unlock_irq(&ffs->ev.waitq.lock);
-
-               if (likely(len)) {
-                       data = kmalloc(len, GFP_KERNEL);
-                       if (unlikely(!data)) {
-                               ret = -ENOMEM;
-                               goto done_mutex;
-                       }
-               }
-
-               spin_lock_irq(&ffs->ev.waitq.lock);
-
-               /* See ffs_ep0_write() */
-               if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) {
-                       ret = -EIDRM;
-                       break;
-               }
-
-               /* unlocks spinlock */
-               ret = __ffs_ep0_queue_wait(ffs, data, len);
-               if (likely(ret > 0) && unlikely(__copy_to_user(buf, data, len)))
-                       ret = -EFAULT;
-               goto done_mutex;
-
-       default:
-               ret = -EBADFD;
-               break;
-       }
-
-       spin_unlock_irq(&ffs->ev.waitq.lock);
-done_mutex:
-       mutex_unlock(&ffs->mutex);
-       kfree(data);
-       return ret;
-}
-
-static int ffs_ep0_open(struct inode *inode, struct file *file)
-{
-       struct ffs_data *ffs = inode->i_private;
-
-       ENTER();
-
-       if (unlikely(ffs->state == FFS_CLOSING))
-               return -EBUSY;
-
-       file->private_data = ffs;
-       ffs_data_opened(ffs);
-
-       return 0;
-}
-
-static int ffs_ep0_release(struct inode *inode, struct file *file)
-{
-       struct ffs_data *ffs = file->private_data;
-
-       ENTER();
-
-       ffs_data_closed(ffs);
-
-       return 0;
-}
-
-static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
-{
-       struct ffs_data *ffs = file->private_data;
-       struct usb_gadget *gadget = ffs->gadget;
-       long ret;
-
-       ENTER();
-
-       if (code == FUNCTIONFS_INTERFACE_REVMAP) {
-               struct ffs_function *func = ffs->func;
-               ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
-       } else if (gadget && gadget->ops->ioctl) {
-               ret = gadget->ops->ioctl(gadget, code, value);
-       } else {
-               ret = -ENOTTY;
-       }
-
-       return ret;
-}
-
-static const struct file_operations ffs_ep0_operations = {
-       .owner =        THIS_MODULE,
-       .llseek =       no_llseek,
-
-       .open =         ffs_ep0_open,
-       .write =        ffs_ep0_write,
-       .read =         ffs_ep0_read,
-       .release =      ffs_ep0_release,
-       .unlocked_ioctl =       ffs_ep0_ioctl,
-};
-
-
-/* "Normal" endpoints operations ********************************************/
-
-static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
-{
-       ENTER();
-       if (likely(req->context)) {
-               struct ffs_ep *ep = _ep->driver_data;
-               ep->status = req->status ? req->status : req->actual;
-               complete(req->context);
-       }
-}
-
-static ssize_t ffs_epfile_io(struct file *file,
-                            char __user *buf, size_t len, int read)
-{
-       struct ffs_epfile *epfile = file->private_data;
-       struct ffs_ep *ep;
-       char *data = NULL;
-       ssize_t ret;
-       int halt;
-
-       goto first_try;
-       do {
-               spin_unlock_irq(&epfile->ffs->eps_lock);
-               mutex_unlock(&epfile->mutex);
-
-first_try:
-               /* Are we still active? */
-               if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) {
-                       ret = -ENODEV;
-                       goto error;
-               }
-
-               /* Wait for endpoint to be enabled */
-               ep = epfile->ep;
-               if (!ep) {
-                       if (file->f_flags & O_NONBLOCK) {
-                               ret = -EAGAIN;
-                               goto error;
-                       }
-
-                       if (wait_event_interruptible(epfile->wait,
-                                                    (ep = epfile->ep))) {
-                               ret = -EINTR;
-                               goto error;
-                       }
-               }
-
-               /* Do we halt? */
-               halt = !read == !epfile->in;
-               if (halt && epfile->isoc) {
-                       ret = -EINVAL;
-                       goto error;
-               }
-
-               /* Allocate & copy */
-               if (!halt && !data) {
-                       data = kzalloc(len, GFP_KERNEL);
-                       if (unlikely(!data))
-                               return -ENOMEM;
-
-                       if (!read &&
-                           unlikely(__copy_from_user(data, buf, len))) {
-                               ret = -EFAULT;
-                               goto error;
-                       }
-               }
-
-               /* We will be using request */
-               ret = ffs_mutex_lock(&epfile->mutex,
-                                    file->f_flags & O_NONBLOCK);
-               if (unlikely(ret))
-                       goto error;
-
-               /*
-                * We're called from user space, we can use _irq rather then
-                * _irqsave
-                */
-               spin_lock_irq(&epfile->ffs->eps_lock);
-
-               /*
-                * While we were acquiring mutex endpoint got disabled
-                * or changed?
-                */
-       } while (unlikely(epfile->ep != ep));
-
-       /* Halt */
-       if (unlikely(halt)) {
-               if (likely(epfile->ep == ep) && !WARN_ON(!ep->ep))
-                       usb_ep_set_halt(ep->ep);
-               spin_unlock_irq(&epfile->ffs->eps_lock);
-               ret = -EBADMSG;
-       } else {
-               /* Fire the request */
-               DECLARE_COMPLETION_ONSTACK(done);
-
-               struct usb_request *req = ep->req;
-               req->context  = &done;
-               req->complete = ffs_epfile_io_complete;
-               req->buf      = data;
-               req->length   = len;
-
-               ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC);
-
-               spin_unlock_irq(&epfile->ffs->eps_lock);
-
-               if (unlikely(ret < 0)) {
-                       /* nop */
-               } else if (unlikely(wait_for_completion_interruptible(&done))) {
-                       ret = -EINTR;
-                       usb_ep_dequeue(ep->ep, req);
-               } else {
-                       ret = ep->status;
-                       if (read && ret > 0 &&
-                           unlikely(copy_to_user(buf, data, ret)))
-                               ret = -EFAULT;
-               }
-       }
-
-       mutex_unlock(&epfile->mutex);
-error:
-       kfree(data);
-       return ret;
-}
-
-static ssize_t
-ffs_epfile_write(struct file *file, const char __user *buf, size_t len,
-                loff_t *ptr)
-{
-       ENTER();
-
-       return ffs_epfile_io(file, (char __user *)buf, len, 0);
-}
-
-static ssize_t
-ffs_epfile_read(struct file *file, char __user *buf, size_t len, loff_t *ptr)
-{
-       ENTER();
-
-       return ffs_epfile_io(file, buf, len, 1);
-}
-
-static int
-ffs_epfile_open(struct inode *inode, struct file *file)
-{
-       struct ffs_epfile *epfile = inode->i_private;
-
-       ENTER();
-
-       if (WARN_ON(epfile->ffs->state != FFS_ACTIVE))
-               return -ENODEV;
-
-       file->private_data = epfile;
-       ffs_data_opened(epfile->ffs);
-
-       return 0;
-}
-
-static int
-ffs_epfile_release(struct inode *inode, struct file *file)
-{
-       struct ffs_epfile *epfile = inode->i_private;
-
-       ENTER();
-
-       ffs_data_closed(epfile->ffs);
-
-       return 0;
-}
-
-static long ffs_epfile_ioctl(struct file *file, unsigned code,
-                            unsigned long value)
-{
-       struct ffs_epfile *epfile = file->private_data;
-       int ret;
-
-       ENTER();
-
-       if (WARN_ON(epfile->ffs->state != FFS_ACTIVE))
-               return -ENODEV;
-
-       spin_lock_irq(&epfile->ffs->eps_lock);
-       if (likely(epfile->ep)) {
-               switch (code) {
-               case FUNCTIONFS_FIFO_STATUS:
-                       ret = usb_ep_fifo_status(epfile->ep->ep);
-                       break;
-               case FUNCTIONFS_FIFO_FLUSH:
-                       usb_ep_fifo_flush(epfile->ep->ep);
-                       ret = 0;
-                       break;
-               case FUNCTIONFS_CLEAR_HALT:
-                       ret = usb_ep_clear_halt(epfile->ep->ep);
-                       break;
-               case FUNCTIONFS_ENDPOINT_REVMAP:
-                       ret = epfile->ep->num;
-                       break;
-               default:
-                       ret = -ENOTTY;
-               }
-       } else {
-               ret = -ENODEV;
-       }
-       spin_unlock_irq(&epfile->ffs->eps_lock);
-
-       return ret;
-}
-
-static const struct file_operations ffs_epfile_operations = {
-       .owner =        THIS_MODULE,
-       .llseek =       no_llseek,
-
-       .open =         ffs_epfile_open,
-       .write =        ffs_epfile_write,
-       .read =         ffs_epfile_read,
-       .release =      ffs_epfile_release,
-       .unlocked_ioctl =       ffs_epfile_ioctl,
-};
-
-
-/* File system and super block operations ***********************************/
-
-/*
- * Mounting the file system creates a controller file, used first for
- * function configuration then later for event monitoring.
- */
-
-static struct inode *__must_check
-ffs_sb_make_inode(struct super_block *sb, void *data,
-                 const struct file_operations *fops,
-                 const struct inode_operations *iops,
-                 struct ffs_file_perms *perms)
-{
-       struct inode *inode;
-
-       ENTER();
-
-       inode = new_inode(sb);
-
-       if (likely(inode)) {
-               struct timespec current_time = CURRENT_TIME;
-
-               inode->i_ino     = get_next_ino();
-               inode->i_mode    = perms->mode;
-               inode->i_uid     = perms->uid;
-               inode->i_gid     = perms->gid;
-               inode->i_atime   = current_time;
-               inode->i_mtime   = current_time;
-               inode->i_ctime   = current_time;
-               inode->i_private = data;
-               if (fops)
-                       inode->i_fop = fops;
-               if (iops)
-                       inode->i_op  = iops;
-       }
-
-       return inode;
-}
-
-/* Create "regular" file */
-static struct inode *ffs_sb_create_file(struct super_block *sb,
-                                       const char *name, void *data,
-                                       const struct file_operations *fops,
-                                       struct dentry **dentry_p)
-{
-       struct ffs_data *ffs = sb->s_fs_info;
-       struct dentry   *dentry;
-       struct inode    *inode;
-
-       ENTER();
-
-       dentry = d_alloc_name(sb->s_root, name);
-       if (unlikely(!dentry))
-               return NULL;
-
-       inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms);
-       if (unlikely(!inode)) {
-               dput(dentry);
-               return NULL;
-       }
-
-       d_add(dentry, inode);
-       if (dentry_p)
-               *dentry_p = dentry;
-
-       return inode;
-}
-
-/* Super block */
-static const struct super_operations ffs_sb_operations = {
-       .statfs =       simple_statfs,
-       .drop_inode =   generic_delete_inode,
-};
-
-struct ffs_sb_fill_data {
-       struct ffs_file_perms perms;
-       umode_t root_mode;
-       const char *dev_name;
-       union {
-               /* set by ffs_fs_mount(), read by ffs_sb_fill() */
-               void *private_data;
-               /* set by ffs_sb_fill(), read by ffs_fs_mount */
-               struct ffs_data *ffs_data;
-       };
-};
-
-static int ffs_sb_fill(struct super_block *sb, void *_data, int silent)
-{
-       struct ffs_sb_fill_data *data = _data;
-       struct inode    *inode;
-       struct ffs_data *ffs;
-
-       ENTER();
-
-       /* Initialise data */
-       ffs = ffs_data_new();
-       if (unlikely(!ffs))
-               goto Enomem;
-
-       ffs->sb              = sb;
-       ffs->dev_name        = kstrdup(data->dev_name, GFP_KERNEL);
-       if (unlikely(!ffs->dev_name))
-               goto Enomem;
-       ffs->file_perms      = data->perms;
-       ffs->private_data    = data->private_data;
-
-       /* used by the caller of this function */
-       data->ffs_data       = ffs;
-
-       sb->s_fs_info        = ffs;
-       sb->s_blocksize      = PAGE_CACHE_SIZE;
-       sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
-       sb->s_magic          = FUNCTIONFS_MAGIC;
-       sb->s_op             = &ffs_sb_operations;
-       sb->s_time_gran      = 1;
-
-       /* Root inode */
-       data->perms.mode = data->root_mode;
-       inode = ffs_sb_make_inode(sb, NULL,
-                                 &simple_dir_operations,
-                                 &simple_dir_inode_operations,
-                                 &data->perms);
-       sb->s_root = d_make_root(inode);
-       if (unlikely(!sb->s_root))
-               goto Enomem;
-
-       /* EP0 file */
-       if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs,
-                                        &ffs_ep0_operations, NULL)))
-               goto Enomem;
-
-       return 0;
-
-Enomem:
-       return -ENOMEM;
-}
-
-static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
-{
-       ENTER();
-
-       if (!opts || !*opts)
-               return 0;
-
-       for (;;) {
-               char *end, *eq, *comma;
-               unsigned long value;
-
-               /* Option limit */
-               comma = strchr(opts, ',');
-               if (comma)
-                       *comma = 0;
-
-               /* Value limit */
-               eq = strchr(opts, '=');
-               if (unlikely(!eq)) {
-                       pr_err("'=' missing in %s\n", opts);
-                       return -EINVAL;
-               }
-               *eq = 0;
-
-               /* Parse value */
-               value = simple_strtoul(eq + 1, &end, 0);
-               if (unlikely(*end != ',' && *end != 0)) {
-                       pr_err("%s: invalid value: %s\n", opts, eq + 1);
-                       return -EINVAL;
-               }
-
-               /* Interpret option */
-               switch (eq - opts) {
-               case 5:
-                       if (!memcmp(opts, "rmode", 5))
-                               data->root_mode  = (value & 0555) | S_IFDIR;
-                       else if (!memcmp(opts, "fmode", 5))
-                               data->perms.mode = (value & 0666) | S_IFREG;
-                       else
-                               goto invalid;
-                       break;
-
-               case 4:
-                       if (!memcmp(opts, "mode", 4)) {
-                               data->root_mode  = (value & 0555) | S_IFDIR;
-                               data->perms.mode = (value & 0666) | S_IFREG;
-                       } else {
-                               goto invalid;
-                       }
-                       break;
-
-               case 3:
-                       if (!memcmp(opts, "uid", 3))
-                               data->perms.uid = value;
-                       else if (!memcmp(opts, "gid", 3))
-                               data->perms.gid = value;
-                       else
-                               goto invalid;
-                       break;
-
-               default:
-invalid:
-                       pr_err("%s: invalid option\n", opts);
-                       return -EINVAL;
-               }
-
-               /* Next iteration */
-               if (!comma)
-                       break;
-               opts = comma + 1;
-       }
-
-       return 0;
-}
-
-/* "mount -t functionfs dev_name /dev/function" ends up here */
-
-static struct dentry *
-ffs_fs_mount(struct file_system_type *t, int flags,
-             const char *dev_name, void *opts)
-{
-       struct ffs_sb_fill_data data = {
-               .perms = {
-                       .mode = S_IFREG | 0600,
-                       .uid = 0,
-                       .gid = 0
-               },
-               .root_mode = S_IFDIR | 0500,
-       };
-       struct dentry *rv;
-       int ret;
-       void *ffs_dev;
-
-       ENTER();
-
-       ret = ffs_fs_parse_opts(&data, opts);
-       if (unlikely(ret < 0))
-               return ERR_PTR(ret);
-
-       ffs_dev = functionfs_acquire_dev_callback(dev_name);
-       if (IS_ERR(ffs_dev))
-               return ffs_dev;
-
-       data.dev_name = dev_name;
-       data.private_data = ffs_dev;
-       rv = mount_nodev(t, flags, &data, ffs_sb_fill);
-
-       /* data.ffs_data is set by ffs_sb_fill */
-       if (IS_ERR(rv))
-               functionfs_release_dev_callback(data.ffs_data);
-
-       return rv;
-}
-
-static void
-ffs_fs_kill_sb(struct super_block *sb)
-{
-       ENTER();
-
-       kill_litter_super(sb);
-       if (sb->s_fs_info) {
-               functionfs_release_dev_callback(sb->s_fs_info);
-               ffs_data_put(sb->s_fs_info);
-       }
-}
-
-static struct file_system_type ffs_fs_type = {
-       .owner          = THIS_MODULE,
-       .name           = "functionfs",
-       .mount          = ffs_fs_mount,
-       .kill_sb        = ffs_fs_kill_sb,
-};
-MODULE_ALIAS_FS("functionfs");
-
-
-/* Driver's main init/cleanup functions *************************************/
-
-static int functionfs_init(void)
-{
-       int ret;
-
-       ENTER();
-
-       ret = register_filesystem(&ffs_fs_type);
-       if (likely(!ret))
-               pr_info("file system registered\n");
-       else
-               pr_err("failed registering file system (%d)\n", ret);
-
-       return ret;
-}
-
-static void functionfs_cleanup(void)
-{
-       ENTER();
-
-       pr_info("unloading\n");
-       unregister_filesystem(&ffs_fs_type);
-}
-
-
-/* ffs_data and ffs_function construction and destruction code **************/
-
-static void ffs_data_clear(struct ffs_data *ffs);
-static void ffs_data_reset(struct ffs_data *ffs);
-
-static void ffs_data_get(struct ffs_data *ffs)
-{
-       ENTER();
-
-       atomic_inc(&ffs->ref);
-}
-
-static void ffs_data_opened(struct ffs_data *ffs)
-{
-       ENTER();
-
-       atomic_inc(&ffs->ref);
-       atomic_inc(&ffs->opened);
-}
-
-static void ffs_data_put(struct ffs_data *ffs)
-{
-       ENTER();
-
-       if (unlikely(atomic_dec_and_test(&ffs->ref))) {
-               pr_info("%s(): freeing\n", __func__);
-               ffs_data_clear(ffs);
-               BUG_ON(waitqueue_active(&ffs->ev.waitq) ||
-                      waitqueue_active(&ffs->ep0req_completion.wait));
-               kfree(ffs->dev_name);
-               kfree(ffs);
-       }
-}
-
-static void ffs_data_closed(struct ffs_data *ffs)
-{
-       ENTER();
-
-       if (atomic_dec_and_test(&ffs->opened)) {
-               ffs->state = FFS_CLOSING;
-               ffs_data_reset(ffs);
-       }
-
-       ffs_data_put(ffs);
-}
-
-static struct ffs_data *ffs_data_new(void)
-{
-       struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL);
-       if (unlikely(!ffs))
-               return 0;
-
-       ENTER();
-
-       atomic_set(&ffs->ref, 1);
-       atomic_set(&ffs->opened, 0);
-       ffs->state = FFS_READ_DESCRIPTORS;
-       mutex_init(&ffs->mutex);
-       spin_lock_init(&ffs->eps_lock);
-       init_waitqueue_head(&ffs->ev.waitq);
-       init_completion(&ffs->ep0req_completion);
-
-       /* XXX REVISIT need to update it in some places, or do we? */
-       ffs->ev.can_stall = 1;
-
-       return ffs;
-}
-
-static void ffs_data_clear(struct ffs_data *ffs)
-{
-       ENTER();
-
-       if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags))
-               functionfs_closed_callback(ffs);
-
-       BUG_ON(ffs->gadget);
-
-       if (ffs->epfiles)
-               ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count);
-
-       kfree(ffs->raw_descs);
-       kfree(ffs->raw_strings);
-       kfree(ffs->stringtabs);
-}
-
-static void ffs_data_reset(struct ffs_data *ffs)
-{
-       ENTER();
-
-       ffs_data_clear(ffs);
-
-       ffs->epfiles = NULL;
-       ffs->raw_descs = NULL;
-       ffs->raw_strings = NULL;
-       ffs->stringtabs = NULL;
-
-       ffs->raw_descs_length = 0;
-       ffs->raw_fs_descs_length = 0;
-       ffs->fs_descs_count = 0;
-       ffs->hs_descs_count = 0;
-
-       ffs->strings_count = 0;
-       ffs->interfaces_count = 0;
-       ffs->eps_count = 0;
-
-       ffs->ev.count = 0;
-
-       ffs->state = FFS_READ_DESCRIPTORS;
-       ffs->setup_state = FFS_NO_SETUP;
-       ffs->flags = 0;
-}
-
-
-static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev)
-{
-       struct usb_gadget_strings **lang;
-       int first_id;
-
-       ENTER();
-
-       if (WARN_ON(ffs->state != FFS_ACTIVE
-                || test_and_set_bit(FFS_FL_BOUND, &ffs->flags)))
-               return -EBADFD;
-
-       first_id = usb_string_ids_n(cdev, ffs->strings_count);
-       if (unlikely(first_id < 0))
-               return first_id;
-
-       ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL);
-       if (unlikely(!ffs->ep0req))
-               return -ENOMEM;
-       ffs->ep0req->complete = ffs_ep0_complete;
-       ffs->ep0req->context = ffs;
-
-       lang = ffs->stringtabs;
-       for (lang = ffs->stringtabs; *lang; ++lang) {
-               struct usb_string *str = (*lang)->strings;
-               int id = first_id;
-               for (; str->s; ++id, ++str)
-                       str->id = id;
-       }
-
-       ffs->gadget = cdev->gadget;
-       ffs_data_get(ffs);
-       return 0;
-}
-
-static void functionfs_unbind(struct ffs_data *ffs)
-{
-       ENTER();
-
-       if (!WARN_ON(!ffs->gadget)) {
-               usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req);
-               ffs->ep0req = NULL;
-               ffs->gadget = NULL;
-               ffs_data_put(ffs);
-               clear_bit(FFS_FL_BOUND, &ffs->flags);
-       }
-}
-
-static int ffs_epfiles_create(struct ffs_data *ffs)
-{
-       struct ffs_epfile *epfile, *epfiles;
-       unsigned i, count;
-
-       ENTER();
-
-       count = ffs->eps_count;
-       epfiles = kcalloc(count, sizeof(*epfiles), GFP_KERNEL);
-       if (!epfiles)
-               return -ENOMEM;
-
-       epfile = epfiles;
-       for (i = 1; i <= count; ++i, ++epfile) {
-               epfile->ffs = ffs;
-               mutex_init(&epfile->mutex);
-               init_waitqueue_head(&epfile->wait);
-               sprintf(epfiles->name, "ep%u",  i);
-               if (!unlikely(ffs_sb_create_file(ffs->sb, epfiles->name, epfile,
-                                                &ffs_epfile_operations,
-                                                &epfile->dentry))) {
-                       ffs_epfiles_destroy(epfiles, i - 1);
-                       return -ENOMEM;
-               }
-       }
-
-       ffs->epfiles = epfiles;
-       return 0;
-}
-
-static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count)
-{
-       struct ffs_epfile *epfile = epfiles;
-
-       ENTER();
-
-       for (; count; --count, ++epfile) {
-               BUG_ON(mutex_is_locked(&epfile->mutex) ||
-                      waitqueue_active(&epfile->wait));
-               if (epfile->dentry) {
-                       d_delete(epfile->dentry);
-                       dput(epfile->dentry);
-                       epfile->dentry = NULL;
-               }
-       }
-
-       kfree(epfiles);
-}
-
-static int functionfs_bind_config(struct usb_composite_dev *cdev,
-                                 struct usb_configuration *c,
-                                 struct ffs_data *ffs)
-{
-       struct ffs_function *func;
-       int ret;
-
-       ENTER();
-
-       func = kzalloc(sizeof *func, GFP_KERNEL);
-       if (unlikely(!func))
-               return -ENOMEM;
-
-       func->function.name    = "Function FS Gadget";
-       func->function.strings = ffs->stringtabs;
-
-       func->function.bind    = ffs_func_bind;
-       func->function.unbind  = ffs_func_unbind;
-       func->function.set_alt = ffs_func_set_alt;
-       func->function.disable = ffs_func_disable;
-       func->function.setup   = ffs_func_setup;
-       func->function.suspend = ffs_func_suspend;
-       func->function.resume  = ffs_func_resume;
-
-       func->conf   = c;
-       func->gadget = cdev->gadget;
-       func->ffs = ffs;
-       ffs_data_get(ffs);
-
-       ret = usb_add_function(c, &func->function);
-       if (unlikely(ret))
-               ffs_func_free(func);
-
-       return ret;
-}
-
-static void ffs_func_free(struct ffs_function *func)
-{
-       struct ffs_ep *ep         = func->eps;
-       unsigned count            = func->ffs->eps_count;
-       unsigned long flags;
-
-       ENTER();
-
-       /* cleanup after autoconfig */
-       spin_lock_irqsave(&func->ffs->eps_lock, flags);
-       do {
-               if (ep->ep && ep->req)
-                       usb_ep_free_request(ep->ep, ep->req);
-               ep->req = NULL;
-               ++ep;
-       } while (--count);
-       spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
-
-       ffs_data_put(func->ffs);
-
-       kfree(func->eps);
-       /*
-        * eps and interfaces_nums are allocated in the same chunk so
-        * only one free is required.  Descriptors are also allocated
-        * in the same chunk.
-        */
-
-       kfree(func);
-}
-
-static void ffs_func_eps_disable(struct ffs_function *func)
-{
-       struct ffs_ep *ep         = func->eps;
-       struct ffs_epfile *epfile = func->ffs->epfiles;
-       unsigned count            = func->ffs->eps_count;
-       unsigned long flags;
-
-       spin_lock_irqsave(&func->ffs->eps_lock, flags);
-       do {
-               /* pending requests get nuked */
-               if (likely(ep->ep))
-                       usb_ep_disable(ep->ep);
-               epfile->ep = NULL;
-
-               ++ep;
-               ++epfile;
-       } while (--count);
-       spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
-}
-
-static int ffs_func_eps_enable(struct ffs_function *func)
-{
-       struct ffs_data *ffs      = func->ffs;
-       struct ffs_ep *ep         = func->eps;
-       struct ffs_epfile *epfile = ffs->epfiles;
-       unsigned count            = ffs->eps_count;
-       unsigned long flags;
-       int ret = 0;
-
-       spin_lock_irqsave(&func->ffs->eps_lock, flags);
-       do {
-               struct usb_endpoint_descriptor *ds;
-               ds = ep->descs[ep->descs[1] ? 1 : 0];
-
-               ep->ep->driver_data = ep;
-               ep->ep->desc = ds;
-               ret = usb_ep_enable(ep->ep);
-               if (likely(!ret)) {
-                       epfile->ep = ep;
-                       epfile->in = usb_endpoint_dir_in(ds);
-                       epfile->isoc = usb_endpoint_xfer_isoc(ds);
-               } else {
-                       break;
-               }
-
-               wake_up(&epfile->wait);
-
-               ++ep;
-               ++epfile;
-       } while (--count);
-       spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
-
-       return ret;
-}
-
-
-/* Parsing and building descriptors and strings *****************************/
-
-/*
- * This validates if data pointed by data is a valid USB descriptor as
- * well as record how many interfaces, endpoints and strings are
- * required by given configuration.  Returns address after the
- * descriptor or NULL if data is invalid.
- */
-
-enum ffs_entity_type {
-       FFS_DESCRIPTOR, FFS_INTERFACE, FFS_STRING, FFS_ENDPOINT
-};
-
-typedef int (*ffs_entity_callback)(enum ffs_entity_type entity,
-                                  u8 *valuep,
-                                  struct usb_descriptor_header *desc,
-                                  void *priv);
-
-static int __must_check ffs_do_desc(char *data, unsigned len,
-                                   ffs_entity_callback entity, void *priv)
-{
-       struct usb_descriptor_header *_ds = (void *)data;
-       u8 length;
-       int ret;
-
-       ENTER();
-
-       /* At least two bytes are required: length and type */
-       if (len < 2) {
-               pr_vdebug("descriptor too short\n");
-               return -EINVAL;
-       }
-
-       /* If we have at least as many bytes as the descriptor takes? */
-       length = _ds->bLength;
-       if (len < length) {
-               pr_vdebug("descriptor longer then available data\n");
-               return -EINVAL;
-       }
-
-#define __entity_check_INTERFACE(val)  1
-#define __entity_check_STRING(val)     (val)
-#define __entity_check_ENDPOINT(val)   ((val) & USB_ENDPOINT_NUMBER_MASK)
-#define __entity(type, val) do {                                       \
-               pr_vdebug("entity " #type "(%02x)\n", (val));           \
-               if (unlikely(!__entity_check_ ##type(val))) {           \
-                       pr_vdebug("invalid entity's value\n");          \
-                       return -EINVAL;                                 \
-               }                                                       \
-               ret = entity(FFS_ ##type, &val, _ds, priv);             \
-               if (unlikely(ret < 0)) {                                \
-                       pr_debug("entity " #type "(%02x); ret = %d\n",  \
-                                (val), ret);                           \
-                       return ret;                                     \
-               }                                                       \
-       } while (0)
-
-       /* Parse descriptor depending on type. */
-       switch (_ds->bDescriptorType) {
-       case USB_DT_DEVICE:
-       case USB_DT_CONFIG:
-       case USB_DT_STRING:
-       case USB_DT_DEVICE_QUALIFIER:
-               /* function can't have any of those */
-               pr_vdebug("descriptor reserved for gadget: %d\n",
-                     _ds->bDescriptorType);
-               return -EINVAL;
-
-       case USB_DT_INTERFACE: {
-               struct usb_interface_descriptor *ds = (void *)_ds;
-               pr_vdebug("interface descriptor\n");
-               if (length != sizeof *ds)
-                       goto inv_length;
-
-               __entity(INTERFACE, ds->bInterfaceNumber);
-               if (ds->iInterface)
-                       __entity(STRING, ds->iInterface);
-       }
-               break;
-
-       case USB_DT_ENDPOINT: {
-               struct usb_endpoint_descriptor *ds = (void *)_ds;
-               pr_vdebug("endpoint descriptor\n");
-               if (length != USB_DT_ENDPOINT_SIZE &&
-                   length != USB_DT_ENDPOINT_AUDIO_SIZE)
-                       goto inv_length;
-               __entity(ENDPOINT, ds->bEndpointAddress);
-       }
-               break;
-
-       case HID_DT_HID:
-               pr_vdebug("hid descriptor\n");
-               if (length != sizeof(struct hid_descriptor))
-                       goto inv_length;
-               break;
-
-       case USB_DT_OTG:
-               if (length != sizeof(struct usb_otg_descriptor))
-                       goto inv_length;
-               break;
-
-       case USB_DT_INTERFACE_ASSOCIATION: {
-               struct usb_interface_assoc_descriptor *ds = (void *)_ds;
-               pr_vdebug("interface association descriptor\n");
-               if (length != sizeof *ds)
-                       goto inv_length;
-               if (ds->iFunction)
-                       __entity(STRING, ds->iFunction);
-       }
-               break;
-
-       case USB_DT_OTHER_SPEED_CONFIG:
-       case USB_DT_INTERFACE_POWER:
-       case USB_DT_DEBUG:
-       case USB_DT_SECURITY:
-       case USB_DT_CS_RADIO_CONTROL:
-               /* TODO */
-               pr_vdebug("unimplemented descriptor: %d\n", _ds->bDescriptorType);
-               return -EINVAL;
-
-       default:
-               /* We should never be here */
-               pr_vdebug("unknown descriptor: %d\n", _ds->bDescriptorType);
-               return -EINVAL;
-
-inv_length:
-               pr_vdebug("invalid length: %d (descriptor %d)\n",
-                         _ds->bLength, _ds->bDescriptorType);
-               return -EINVAL;
-       }
-
-#undef __entity
-#undef __entity_check_DESCRIPTOR
-#undef __entity_check_INTERFACE
-#undef __entity_check_STRING
-#undef __entity_check_ENDPOINT
-
-       return length;
-}
-
-static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,
-                                    ffs_entity_callback entity, void *priv)
-{
-       const unsigned _len = len;
-       unsigned long num = 0;
-
-       ENTER();
-
-       for (;;) {
-               int ret;
-
-               if (num == count)
-                       data = NULL;
-
-               /* Record "descriptor" entity */
-               ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv);
-               if (unlikely(ret < 0)) {
-                       pr_debug("entity DESCRIPTOR(%02lx); ret = %d\n",
-                                num, ret);
-                       return ret;
-               }
-
-               if (!data)
-                       return _len - len;
-
-               ret = ffs_do_desc(data, len, entity, priv);
-               if (unlikely(ret < 0)) {
-                       pr_debug("%s returns %d\n", __func__, ret);
-                       return ret;
-               }
-
-               len -= ret;
-               data += ret;
-               ++num;
-       }
-}
-
-static int __ffs_data_do_entity(enum ffs_entity_type type,
-                               u8 *valuep, struct usb_descriptor_header *desc,
-                               void *priv)
-{
-       struct ffs_data *ffs = priv;
-
-       ENTER();
-
-       switch (type) {
-       case FFS_DESCRIPTOR:
-               break;
-
-       case FFS_INTERFACE:
-               /*
-                * Interfaces are indexed from zero so if we
-                * encountered interface "n" then there are at least
-                * "n+1" interfaces.
-                */
-               if (*valuep >= ffs->interfaces_count)
-                       ffs->interfaces_count = *valuep + 1;
-               break;
-
-       case FFS_STRING:
-               /*
-                * Strings are indexed from 1 (0 is magic ;) reserved
-                * for languages list or some such)
-                */
-               if (*valuep > ffs->strings_count)
-                       ffs->strings_count = *valuep;
-               break;
-
-       case FFS_ENDPOINT:
-               /* Endpoints are indexed from 1 as well. */
-               if ((*valuep & USB_ENDPOINT_NUMBER_MASK) > ffs->eps_count)
-                       ffs->eps_count = (*valuep & USB_ENDPOINT_NUMBER_MASK);
-               break;
-       }
-
-       return 0;
-}
-
-static int __ffs_data_got_descs(struct ffs_data *ffs,
-                               char *const _data, size_t len)
-{
-       unsigned fs_count, hs_count;
-       int fs_len, ret = -EINVAL;
-       char *data = _data;
-
-       ENTER();
-
-       if (unlikely(get_unaligned_le32(data) != FUNCTIONFS_DESCRIPTORS_MAGIC ||
-                    get_unaligned_le32(data + 4) != len))
-               goto error;
-       fs_count = get_unaligned_le32(data +  8);
-       hs_count = get_unaligned_le32(data + 12);
-
-       if (!fs_count && !hs_count)
-               goto einval;
-
-       data += 16;
-       len  -= 16;
-
-       if (likely(fs_count)) {
-               fs_len = ffs_do_descs(fs_count, data, len,
-                                     __ffs_data_do_entity, ffs);
-               if (unlikely(fs_len < 0)) {
-                       ret = fs_len;
-                       goto error;
-               }
-
-               data += fs_len;
-               len  -= fs_len;
-       } else {
-               fs_len = 0;
-       }
-
-       if (likely(hs_count)) {
-               ret = ffs_do_descs(hs_count, data, len,
-                                  __ffs_data_do_entity, ffs);
-               if (unlikely(ret < 0))
-                       goto error;
-       } else {
-               ret = 0;
-       }
-
-       if (unlikely(len != ret))
-               goto einval;
-
-       ffs->raw_fs_descs_length = fs_len;
-       ffs->raw_descs_length    = fs_len + ret;
-       ffs->raw_descs           = _data;
-       ffs->fs_descs_count      = fs_count;
-       ffs->hs_descs_count      = hs_count;
-
-       return 0;
-
-einval:
-       ret = -EINVAL;
-error:
-       kfree(_data);
-       return ret;
-}
-
-static int __ffs_data_got_strings(struct ffs_data *ffs,
-                                 char *const _data, size_t len)
-{
-       u32 str_count, needed_count, lang_count;
-       struct usb_gadget_strings **stringtabs, *t;
-       struct usb_string *strings, *s;
-       const char *data = _data;
-
-       ENTER();
-
-       if (unlikely(get_unaligned_le32(data) != FUNCTIONFS_STRINGS_MAGIC ||
-                    get_unaligned_le32(data + 4) != len))
-               goto error;
-       str_count  = get_unaligned_le32(data + 8);
-       lang_count = get_unaligned_le32(data + 12);
-
-       /* if one is zero the other must be zero */
-       if (unlikely(!str_count != !lang_count))
-               goto error;
-
-       /* Do we have at least as many strings as descriptors need? */
-       needed_count = ffs->strings_count;
-       if (unlikely(str_count < needed_count))
-               goto error;
-
-       /*
-        * If we don't need any strings just return and free all
-        * memory.
-        */
-       if (!needed_count) {
-               kfree(_data);
-               return 0;
-       }
-
-       /* Allocate everything in one chunk so there's less maintenance. */
-       {
-               struct {
-                       struct usb_gadget_strings *stringtabs[lang_count + 1];
-                       struct usb_gadget_strings stringtab[lang_count];
-                       struct usb_string strings[lang_count*(needed_count+1)];
-               } *d;
-               unsigned i = 0;
-
-               d = kmalloc(sizeof *d, GFP_KERNEL);
-               if (unlikely(!d)) {
-                       kfree(_data);
-                       return -ENOMEM;
-               }
-
-               stringtabs = d->stringtabs;
-               t = d->stringtab;
-               i = lang_count;
-               do {
-                       *stringtabs++ = t++;
-               } while (--i);
-               *stringtabs = NULL;
-
-               stringtabs = d->stringtabs;
-               t = d->stringtab;
-               s = d->strings;
-               strings = s;
-       }
-
-       /* For each language */
-       data += 16;
-       len -= 16;
-
-       do { /* lang_count > 0 so we can use do-while */
-               unsigned needed = needed_count;
-
-               if (unlikely(len < 3))
-                       goto error_free;
-               t->language = get_unaligned_le16(data);
-               t->strings  = s;
-               ++t;
-
-               data += 2;
-               len -= 2;
-
-               /* For each string */
-               do { /* str_count > 0 so we can use do-while */
-                       size_t length = strnlen(data, len);
-
-                       if (unlikely(length == len))
-                               goto error_free;
-
-                       /*
-                        * User may provide more strings then we need,
-                        * if that's the case we simply ignore the
-                        * rest
-                        */
-                       if (likely(needed)) {
-                               /*
-                                * s->id will be set while adding
-                                * function to configuration so for
-                                * now just leave garbage here.
-                                */
-                               s->s = data;
-                               --needed;
-                               ++s;
-                       }
-
-                       data += length + 1;
-                       len -= length + 1;
-               } while (--str_count);
-
-               s->id = 0;   /* terminator */
-               s->s = NULL;
-               ++s;
-
-       } while (--lang_count);
-
-       /* Some garbage left? */
-       if (unlikely(len))
-               goto error_free;
-
-       /* Done! */
-       ffs->stringtabs = stringtabs;
-       ffs->raw_strings = _data;
-
-       return 0;
-
-error_free:
-       kfree(stringtabs);
-error:
-       kfree(_data);
-       return -EINVAL;
-}
-
-
-/* Events handling and management *******************************************/
-
-static void __ffs_event_add(struct ffs_data *ffs,
-                           enum usb_functionfs_event_type type)
-{
-       enum usb_functionfs_event_type rem_type1, rem_type2 = type;
-       int neg = 0;
-
-       /*
-        * Abort any unhandled setup
-        *
-        * We do not need to worry about some cmpxchg() changing value
-        * of ffs->setup_state without holding the lock because when
-        * state is FFS_SETUP_PENDING cmpxchg() in several places in
-        * the source does nothing.
-        */
-       if (ffs->setup_state == FFS_SETUP_PENDING)
-               ffs->setup_state = FFS_SETUP_CANCELED;
-
-       switch (type) {
-       case FUNCTIONFS_RESUME:
-               rem_type2 = FUNCTIONFS_SUSPEND;
-               /* FALL THROUGH */
-       case FUNCTIONFS_SUSPEND:
-       case FUNCTIONFS_SETUP:
-               rem_type1 = type;
-               /* Discard all similar events */
-               break;
-
-       case FUNCTIONFS_BIND:
-       case FUNCTIONFS_UNBIND:
-       case FUNCTIONFS_DISABLE:
-       case FUNCTIONFS_ENABLE:
-               /* Discard everything other then power management. */
-               rem_type1 = FUNCTIONFS_SUSPEND;
-               rem_type2 = FUNCTIONFS_RESUME;
-               neg = 1;
-               break;
-
-       default:
-               BUG();
-       }
-
-       {
-               u8 *ev  = ffs->ev.types, *out = ev;
-               unsigned n = ffs->ev.count;
-               for (; n; --n, ++ev)
-                       if ((*ev == rem_type1 || *ev == rem_type2) == neg)
-                               *out++ = *ev;
-                       else
-                               pr_vdebug("purging event %d\n", *ev);
-               ffs->ev.count = out - ffs->ev.types;
-       }
-
-       pr_vdebug("adding event %d\n", type);
-       ffs->ev.types[ffs->ev.count++] = type;
-       wake_up_locked(&ffs->ev.waitq);
-}
-
-static void ffs_event_add(struct ffs_data *ffs,
-                         enum usb_functionfs_event_type type)
-{
-       unsigned long flags;
-       spin_lock_irqsave(&ffs->ev.waitq.lock, flags);
-       __ffs_event_add(ffs, type);
-       spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags);
-}
-
-
-/* Bind/unbind USB function hooks *******************************************/
-
-static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
-                                   struct usb_descriptor_header *desc,
-                                   void *priv)
-{
-       struct usb_endpoint_descriptor *ds = (void *)desc;
-       struct ffs_function *func = priv;
-       struct ffs_ep *ffs_ep;
-
-       /*
-        * If hs_descriptors is not NULL then we are reading hs
-        * descriptors now
-        */
-       const int isHS = func->function.hs_descriptors != NULL;
-       unsigned idx;
-
-       if (type != FFS_DESCRIPTOR)
-               return 0;
-
-       if (isHS)
-               func->function.hs_descriptors[(long)valuep] = desc;
-       else
-               func->function.descriptors[(long)valuep]    = desc;
-
-       if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT)
-               return 0;
-
-       idx = (ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) - 1;
-       ffs_ep = func->eps + idx;
-
-       if (unlikely(ffs_ep->descs[isHS])) {
-               pr_vdebug("two %sspeed descriptors for EP %d\n",
-                         isHS ? "high" : "full",
-                         ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
-               return -EINVAL;
-       }
-       ffs_ep->descs[isHS] = ds;
-
-       ffs_dump_mem(": Original  ep desc", ds, ds->bLength);
-       if (ffs_ep->ep) {
-               ds->bEndpointAddress = ffs_ep->descs[0]->bEndpointAddress;
-               if (!ds->wMaxPacketSize)
-                       ds->wMaxPacketSize = ffs_ep->descs[0]->wMaxPacketSize;
-       } else {
-               struct usb_request *req;
-               struct usb_ep *ep;
-
-               pr_vdebug("autoconfig\n");
-               ep = usb_ep_autoconfig(func->gadget, ds);
-               if (unlikely(!ep))
-                       return -ENOTSUPP;
-               ep->driver_data = func->eps + idx;
-
-               req = usb_ep_alloc_request(ep, GFP_KERNEL);
-               if (unlikely(!req))
-                       return -ENOMEM;
-
-               ffs_ep->ep  = ep;
-               ffs_ep->req = req;
-               func->eps_revmap[ds->bEndpointAddress &
-                                USB_ENDPOINT_NUMBER_MASK] = idx + 1;
-       }
-       ffs_dump_mem(": Rewritten ep desc", ds, ds->bLength);
-
-       return 0;
-}
-
-static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep,
-                                  struct usb_descriptor_header *desc,
-                                  void *priv)
-{
-       struct ffs_function *func = priv;
-       unsigned idx;
-       u8 newValue;
-
-       switch (type) {
-       default:
-       case FFS_DESCRIPTOR:
-               /* Handled in previous pass by __ffs_func_bind_do_descs() */
-               return 0;
-
-       case FFS_INTERFACE:
-               idx = *valuep;
-               if (func->interfaces_nums[idx] < 0) {
-                       int id = usb_interface_id(func->conf, &func->function);
-                       if (unlikely(id < 0))
-                               return id;
-                       func->interfaces_nums[idx] = id;
-               }
-               newValue = func->interfaces_nums[idx];
-               break;
-
-       case FFS_STRING:
-               /* String' IDs are allocated when fsf_data is bound to cdev */
-               newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id;
-               break;
-
-       case FFS_ENDPOINT:
-               /*
-                * USB_DT_ENDPOINT are handled in
-                * __ffs_func_bind_do_descs().
-                */
-               if (desc->bDescriptorType == USB_DT_ENDPOINT)
-                       return 0;
-
-               idx = (*valuep & USB_ENDPOINT_NUMBER_MASK) - 1;
-               if (unlikely(!func->eps[idx].ep))
-                       return -EINVAL;
-
-               {
-                       struct usb_endpoint_descriptor **descs;
-                       descs = func->eps[idx].descs;
-                       newValue = descs[descs[0] ? 0 : 1]->bEndpointAddress;
-               }
-               break;
-       }
-
-       pr_vdebug("%02x -> %02x\n", *valuep, newValue);
-       *valuep = newValue;
-       return 0;
-}
-
-static int ffs_func_bind(struct usb_configuration *c,
-                        struct usb_function *f)
-{
-       struct ffs_function *func = ffs_func_from_usb(f);
-       struct ffs_data *ffs = func->ffs;
-
-       const int full = !!func->ffs->fs_descs_count;
-       const int high = gadget_is_dualspeed(func->gadget) &&
-               func->ffs->hs_descs_count;
-
-       int ret;
-
-       /* Make it a single chunk, less management later on */
-       struct {
-               struct ffs_ep eps[ffs->eps_count];
-               struct usb_descriptor_header
-                       *fs_descs[full ? ffs->fs_descs_count + 1 : 0];
-               struct usb_descriptor_header
-                       *hs_descs[high ? ffs->hs_descs_count + 1 : 0];
-               short inums[ffs->interfaces_count];
-               char raw_descs[high ? ffs->raw_descs_length
-                                   : ffs->raw_fs_descs_length];
-       } *data;
-
-       ENTER();
-
-       /* Only high speed but not supported by gadget? */
-       if (unlikely(!(full | high)))
-               return -ENOTSUPP;
-
-       /* Allocate */
-       data = kmalloc(sizeof *data, GFP_KERNEL);
-       if (unlikely(!data))
-               return -ENOMEM;
-
-       /* Zero */
-       memset(data->eps, 0, sizeof data->eps);
-       memcpy(data->raw_descs, ffs->raw_descs + 16, sizeof data->raw_descs);
-       memset(data->inums, 0xff, sizeof data->inums);
-       for (ret = ffs->eps_count; ret; --ret)
-               data->eps[ret].num = -1;
-
-       /* Save pointers */
-       func->eps             = data->eps;
-       func->interfaces_nums = data->inums;
-
-       /*
-        * Go through all the endpoint descriptors and allocate
-        * endpoints first, so that later we can rewrite the endpoint
-        * numbers without worrying that it may be described later on.
-        */
-       if (likely(full)) {
-               func->function.descriptors = data->fs_descs;
-               ret = ffs_do_descs(ffs->fs_descs_count,
-                                  data->raw_descs,
-                                  sizeof data->raw_descs,
-                                  __ffs_func_bind_do_descs, func);
-               if (unlikely(ret < 0))
-                       goto error;
-       } else {
-               ret = 0;
-       }
-
-       if (likely(high)) {
-               func->function.hs_descriptors = data->hs_descs;
-               ret = ffs_do_descs(ffs->hs_descs_count,
-                                  data->raw_descs + ret,
-                                  (sizeof data->raw_descs) - ret,
-                                  __ffs_func_bind_do_descs, func);
-       }
-
-       /*
-        * Now handle interface numbers allocation and interface and
-        * endpoint numbers rewriting.  We can do that in one go
-        * now.
-        */
-       ret = ffs_do_descs(ffs->fs_descs_count +
-                          (high ? ffs->hs_descs_count : 0),
-                          data->raw_descs, sizeof data->raw_descs,
-                          __ffs_func_bind_do_nums, func);
-       if (unlikely(ret < 0))
-               goto error;
-
-       /* And we're done */
-       ffs_event_add(ffs, FUNCTIONFS_BIND);
-       return 0;
-
-error:
-       /* XXX Do we need to release all claimed endpoints here? */
-       return ret;
-}
-
-
-/* Other USB function hooks *************************************************/
-
-static void ffs_func_unbind(struct usb_configuration *c,
-                           struct usb_function *f)
-{
-       struct ffs_function *func = ffs_func_from_usb(f);
-       struct ffs_data *ffs = func->ffs;
-
-       ENTER();
-
-       if (ffs->func == func) {
-               ffs_func_eps_disable(func);
-               ffs->func = NULL;
-       }
-
-       ffs_event_add(ffs, FUNCTIONFS_UNBIND);
-
-       ffs_func_free(func);
-}
-
-static int ffs_func_set_alt(struct usb_function *f,
-                           unsigned interface, unsigned alt)
-{
-       struct ffs_function *func = ffs_func_from_usb(f);
-       struct ffs_data *ffs = func->ffs;
-       int ret = 0, intf;
-
-       if (alt != (unsigned)-1) {
-               intf = ffs_func_revmap_intf(func, interface);
-               if (unlikely(intf < 0))
-                       return intf;
-       }
-
-       if (ffs->func)
-               ffs_func_eps_disable(ffs->func);
-
-       if (ffs->state != FFS_ACTIVE)
-               return -ENODEV;
-
-       if (alt == (unsigned)-1) {
-               ffs->func = NULL;
-               ffs_event_add(ffs, FUNCTIONFS_DISABLE);
-               return 0;
-       }
-
-       ffs->func = func;
-       ret = ffs_func_eps_enable(func);
-       if (likely(ret >= 0))
-               ffs_event_add(ffs, FUNCTIONFS_ENABLE);
-       return ret;
-}
-
-static void ffs_func_disable(struct usb_function *f)
-{
-       ffs_func_set_alt(f, 0, (unsigned)-1);
-}
-
-static int ffs_func_setup(struct usb_function *f,
-                         const struct usb_ctrlrequest *creq)
-{
-       struct ffs_function *func = ffs_func_from_usb(f);
-       struct ffs_data *ffs = func->ffs;
-       unsigned long flags;
-       int ret;
-
-       ENTER();
-
-       pr_vdebug("creq->bRequestType = %02x\n", creq->bRequestType);
-       pr_vdebug("creq->bRequest     = %02x\n", creq->bRequest);
-       pr_vdebug("creq->wValue       = %04x\n", le16_to_cpu(creq->wValue));
-       pr_vdebug("creq->wIndex       = %04x\n", le16_to_cpu(creq->wIndex));
-       pr_vdebug("creq->wLength      = %04x\n", le16_to_cpu(creq->wLength));
-
-       /*
-        * Most requests directed to interface go through here
-        * (notable exceptions are set/get interface) so we need to
-        * handle them.  All other either handled by composite or
-        * passed to usb_configuration->setup() (if one is set).  No
-        * matter, we will handle requests directed to endpoint here
-        * as well (as it's straightforward) but what to do with any
-        * other request?
-        */
-       if (ffs->state != FFS_ACTIVE)
-               return -ENODEV;
-
-       switch (creq->bRequestType & USB_RECIP_MASK) {
-       case USB_RECIP_INTERFACE:
-               ret = ffs_func_revmap_intf(func, le16_to_cpu(creq->wIndex));
-               if (unlikely(ret < 0))
-                       return ret;
-               break;
-
-       case USB_RECIP_ENDPOINT:
-               ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex));
-               if (unlikely(ret < 0))
-                       return ret;
-               break;
-
-       default:
-               return -EOPNOTSUPP;
-       }
-
-       spin_lock_irqsave(&ffs->ev.waitq.lock, flags);
-       ffs->ev.setup = *creq;
-       ffs->ev.setup.wIndex = cpu_to_le16(ret);
-       __ffs_event_add(ffs, FUNCTIONFS_SETUP);
-       spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags);
-
-       return 0;
-}
-
-static void ffs_func_suspend(struct usb_function *f)
-{
-       ENTER();
-       ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND);
-}
-
-static void ffs_func_resume(struct usb_function *f)
-{
-       ENTER();
-       ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME);
-}
-
-
-/* Endpoint and interface numbers reverse mapping ***************************/
-
-static int ffs_func_revmap_ep(struct ffs_function *func, u8 num)
-{
-       num = func->eps_revmap[num & USB_ENDPOINT_NUMBER_MASK];
-       return num ? num : -EDOM;
-}
-
-static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf)
-{
-       short *nums = func->interfaces_nums;
-       unsigned count = func->ffs->interfaces_count;
-
-       for (; count; --count, ++nums) {
-               if (*nums >= 0 && *nums == intf)
-                       return nums - func->interfaces_nums;
-       }
-
-       return -EDOM;
-}
-
-
-/* Misc helper functions ****************************************************/
-
-static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock)
-{
-       return nonblock
-               ? likely(mutex_trylock(mutex)) ? 0 : -EAGAIN
-               : mutex_lock_interruptible(mutex);
-}
-
-static char *ffs_prepare_buffer(const char * __user buf, size_t len)
-{
-       char *data;
-
-       if (unlikely(!len))
-               return NULL;
-
-       data = kmalloc(len, GFP_KERNEL);
-       if (unlikely(!data))
-               return ERR_PTR(-ENOMEM);
-
-       if (unlikely(__copy_from_user(data, buf, len))) {
-               kfree(data);
-               return ERR_PTR(-EFAULT);
-       }
-
-       pr_vdebug("Buffer from user space:\n");
-       ffs_dump_mem("", data, len);
-
-       return data;
-}
diff --git a/drivers/staging/ccg/f_mass_storage.c b/drivers/staging/ccg/f_mass_storage.c
deleted file mode 100644 (file)
index 20bc2b4..0000000
+++ /dev/null
@@ -1,3135 +0,0 @@
-/*
- * f_mass_storage.c -- Mass Storage USB Composite Function
- *
- * Copyright (C) 2003-2008 Alan Stern
- * Copyright (C) 2009 Samsung Electronics
- *                    Author: Michal Nazarewicz <mina86@mina86.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions, and the following disclaimer,
- *    without modification.
- * 2. 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.
- * 3. The names of the above-listed copyright holders may not 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 OWNER 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.
- */
-
-/*
- * The Mass Storage Function acts as a USB Mass Storage device,
- * appearing to the host as a disk drive or as a CD-ROM drive.  In
- * addition to providing an example of a genuinely useful composite
- * function for a USB device, it also illustrates a technique of
- * double-buffering for increased throughput.
- *
- * For more information about MSF and in particular its module
- * parameters and sysfs interface read the
- * <Documentation/usb/mass-storage.txt> file.
- */
-
-/*
- * MSF is configured by specifying a fsg_config structure.  It has the
- * following fields:
- *
- *     nluns           Number of LUNs function have (anywhere from 1
- *                             to FSG_MAX_LUNS which is 8).
- *     luns            An array of LUN configuration values.  This
- *                             should be filled for each LUN that
- *                             function will include (ie. for "nluns"
- *                             LUNs).  Each element of the array has
- *                             the following fields:
- *     ->filename      The path to the backing file for the LUN.
- *                             Required if LUN is not marked as
- *                             removable.
- *     ->ro            Flag specifying access to the LUN shall be
- *                             read-only.  This is implied if CD-ROM
- *                             emulation is enabled as well as when
- *                             it was impossible to open "filename"
- *                             in R/W mode.
- *     ->removable     Flag specifying that LUN shall be indicated as
- *                             being removable.
- *     ->cdrom         Flag specifying that LUN shall be reported as
- *                             being a CD-ROM.
- *     ->nofua         Flag specifying that FUA flag in SCSI WRITE(10,12)
- *                             commands for this LUN shall be ignored.
- *
- *     vendor_name
- *     product_name
- *     release         Information used as a reply to INQUIRY
- *                             request.  To use default set to NULL,
- *                             NULL, 0xffff respectively.  The first
- *                             field should be 8 and the second 16
- *                             characters or less.
- *
- *     can_stall       Set to permit function to halt bulk endpoints.
- *                             Disabled on some USB devices known not
- *                             to work correctly.  You should set it
- *                             to true.
- *
- * If "removable" is not set for a LUN then a backing file must be
- * specified.  If it is set, then NULL filename means the LUN's medium
- * is not loaded (an empty string as "filename" in the fsg_config
- * structure causes error).  The CD-ROM emulation includes a single
- * data track and no audio tracks; hence there need be only one
- * backing file per LUN.
- *
- * This function is heavily based on "File-backed Storage Gadget" by
- * Alan Stern which in turn is heavily based on "Gadget Zero" by David
- * Brownell.  The driver's SCSI command interface was based on the
- * "Information technology - Small Computer System Interface - 2"
- * document from X3T9.2 Project 375D, Revision 10L, 7-SEP-93,
- * available at <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>.
- * The single exception is opcode 0x23 (READ FORMAT CAPACITIES), which
- * was based on the "Universal Serial Bus Mass Storage Class UFI
- * Command Specification" document, Revision 1.0, December 14, 1998,
- * available at
- * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
- */
-
-/*
- *                             Driver Design
- *
- * The MSF is fairly straightforward.  There is a main kernel
- * thread that handles most of the work.  Interrupt routines field
- * callbacks from the controller driver: bulk- and interrupt-request
- * completion notifications, endpoint-0 events, and disconnect events.
- * Completion events are passed to the main thread by wakeup calls.  Many
- * ep0 requests are handled at interrupt time, but SetInterface,
- * SetConfiguration, and device reset requests are forwarded to the
- * thread in the form of "exceptions" using SIGUSR1 signals (since they
- * should interrupt any ongoing file I/O operations).
- *
- * The thread's main routine implements the standard command/data/status
- * parts of a SCSI interaction.  It and its subroutines are full of tests
- * for pending signals/exceptions -- all this polling is necessary since
- * the kernel has no setjmp/longjmp equivalents.  (Maybe this is an
- * indication that the driver really wants to be running in userspace.)
- * An important point is that so long as the thread is alive it keeps an
- * open reference to the backing file.  This will prevent unmounting
- * the backing file's underlying filesystem and could cause problems
- * during system shutdown, for example.  To prevent such problems, the
- * thread catches INT, TERM, and KILL signals and converts them into
- * an EXIT exception.
- *
- * In normal operation the main thread is started during the gadget's
- * fsg_bind() callback and stopped during fsg_unbind().  But it can
- * also exit when it receives a signal, and there's no point leaving
- * the gadget running when the thread is dead.  As of this moment, MSF
- * provides no way to deregister the gadget when thread dies -- maybe
- * a callback functions is needed.
- *
- * To provide maximum throughput, the driver uses a circular pipeline of
- * buffer heads (struct fsg_buffhd).  In principle the pipeline can be
- * arbitrarily long; in practice the benefits don't justify having more
- * than 2 stages (i.e., double buffering).  But it helps to think of the
- * pipeline as being a long one.  Each buffer head contains a bulk-in and
- * a bulk-out request pointer (since the buffer can be used for both
- * output and input -- directions always are given from the host's
- * point of view) as well as a pointer to the buffer and various state
- * variables.
- *
- * Use of the pipeline follows a simple protocol.  There is a variable
- * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
- * At any time that buffer head may still be in use from an earlier
- * request, so each buffer head has a state variable indicating whether
- * it is EMPTY, FULL, or BUSY.  Typical use involves waiting for the
- * buffer head to be EMPTY, filling the buffer either by file I/O or by
- * USB I/O (during which the buffer head is BUSY), and marking the buffer
- * head FULL when the I/O is complete.  Then the buffer will be emptied
- * (again possibly by USB I/O, during which it is marked BUSY) and
- * finally marked EMPTY again (possibly by a completion routine).
- *
- * A module parameter tells the driver to avoid stalling the bulk
- * endpoints wherever the transport specification allows.  This is
- * necessary for some UDCs like the SuperH, which cannot reliably clear a
- * halt on a bulk endpoint.  However, under certain circumstances the
- * Bulk-only specification requires a stall.  In such cases the driver
- * will halt the endpoint and set a flag indicating that it should clear
- * the halt in software during the next device reset.  Hopefully this
- * will permit everything to work correctly.  Furthermore, although the
- * specification allows the bulk-out endpoint to halt when the host sends
- * too much data, implementing this would cause an unavoidable race.
- * The driver will always use the "no-stall" approach for OUT transfers.
- *
- * One subtle point concerns sending status-stage responses for ep0
- * requests.  Some of these requests, such as device reset, can involve
- * interrupting an ongoing file I/O operation, which might take an
- * arbitrarily long time.  During that delay the host might give up on
- * the original ep0 request and issue a new one.  When that happens the
- * driver should not notify the host about completion of the original
- * request, as the host will no longer be waiting for it.  So the driver
- * assigns to each ep0 request a unique tag, and it keeps track of the
- * tag value of the request associated with a long-running exception
- * (device-reset, interface-change, or configuration-change).  When the
- * exception handler is finished, the status-stage response is submitted
- * only if the current ep0 request tag is equal to the exception request
- * tag.  Thus only the most recently received ep0 request will get a
- * status-stage response.
- *
- * Warning: This driver source file is too long.  It ought to be split up
- * into a header file plus about 3 separate .c files, to handle the details
- * of the Gadget, USB Mass Storage, and SCSI protocols.
- */
-
-
-/* #define VERBOSE_DEBUG */
-/* #define DUMP_MSGS */
-
-#include <linux/blkdev.h>
-#include <linux/completion.h>
-#include <linux/dcache.h>
-#include <linux/delay.h>
-#include <linux/device.h>
-#include <linux/fcntl.h>
-#include <linux/file.h>
-#include <linux/fs.h>
-#include <linux/kref.h>
-#include <linux/kthread.h>
-#include <linux/limits.h>
-#include <linux/rwsem.h>
-#include <linux/slab.h>
-#include <linux/spinlock.h>
-#include <linux/string.h>
-#include <linux/freezer.h>
-#include <linux/utsname.h>
-
-#include <linux/usb/ch9.h>
-#include <linux/usb/gadget.h>
-#include <linux/usb/composite.h>
-
-#include "gadget_chips.h"
-
-
-/*------------------------------------------------------------------------*/
-
-#define FSG_DRIVER_DESC                "Mass Storage Function"
-#define FSG_DRIVER_VERSION     "2009/09/11"
-
-static const char fsg_string_interface[] = "Mass Storage";
-
-#define FSG_NO_DEVICE_STRINGS    1
-#define FSG_NO_OTG               1
-#define FSG_NO_INTR_EP           1
-
-#include "storage_common.c"
-
-
-/*-------------------------------------------------------------------------*/
-
-struct fsg_dev;
-struct fsg_common;
-
-/* FSF callback functions */
-struct fsg_operations {
-       /*
-        * Callback function to call when thread exits.  If no
-        * callback is set or it returns value lower then zero MSF
-        * will force eject all LUNs it operates on (including those
-        * marked as non-removable or with prevent_medium_removal flag
-        * set).
-        */
-       int (*thread_exits)(struct fsg_common *common);
-
-       /*
-        * Called prior to ejection.  Negative return means error,
-        * zero means to continue with ejection, positive means not to
-        * eject.
-        */
-       int (*pre_eject)(struct fsg_common *common,
-                        struct fsg_lun *lun, int num);
-       /*
-        * Called after ejection.  Negative return means error, zero
-        * or positive is just a success.
-        */
-       int (*post_eject)(struct fsg_common *common,
-                         struct fsg_lun *lun, int num);
-};
-
-/* Data shared by all the FSG instances. */
-struct fsg_common {
-       struct usb_gadget       *gadget;
-       struct usb_composite_dev *cdev;
-       struct fsg_dev          *fsg, *new_fsg;
-       wait_queue_head_t       fsg_wait;
-
-       /* filesem protects: backing files in use */
-       struct rw_semaphore     filesem;
-
-       /* lock protects: state, all the req_busy's */
-       spinlock_t              lock;
-
-       struct usb_ep           *ep0;           /* Copy of gadget->ep0 */
-       struct usb_request      *ep0req;        /* Copy of cdev->req */
-       unsigned int            ep0_req_tag;
-
-       struct fsg_buffhd       *next_buffhd_to_fill;
-       struct fsg_buffhd       *next_buffhd_to_drain;
-       struct fsg_buffhd       *buffhds;
-
-       int                     cmnd_size;
-       u8                      cmnd[MAX_COMMAND_SIZE];
-
-       unsigned int            nluns;
-       unsigned int            lun;
-       struct fsg_lun          *luns;
-       struct fsg_lun          *curlun;
-
-       unsigned int            bulk_out_maxpacket;
-       enum fsg_state          state;          /* For exception handling */
-       unsigned int            exception_req_tag;
-
-       enum data_direction     data_dir;
-       u32                     data_size;
-       u32                     data_size_from_cmnd;
-       u32                     tag;
-       u32                     residue;
-       u32                     usb_amount_left;
-
-       unsigned int            can_stall:1;
-       unsigned int            free_storage_on_release:1;
-       unsigned int            phase_error:1;
-       unsigned int            short_packet_received:1;
-       unsigned int            bad_lun_okay:1;
-       unsigned int            running:1;
-
-       int                     thread_wakeup_needed;
-       struct completion       thread_notifier;
-       struct task_struct      *thread_task;
-
-       /* Callback functions. */
-       const struct fsg_operations     *ops;
-       /* Gadget's private data. */
-       void                    *private_data;
-
-       /*
-        * Vendor (8 chars), product (16 chars), release (4
-        * hexadecimal digits) and NUL byte
-        */
-       char inquiry_string[8 + 16 + 4 + 1];
-
-       struct kref             ref;
-};
-
-struct fsg_config {
-       unsigned nluns;
-       struct fsg_lun_config {
-               const char *filename;
-               char ro;
-               char removable;
-               char cdrom;
-               char nofua;
-       } luns[FSG_MAX_LUNS];
-
-       /* Callback functions. */
-       const struct fsg_operations     *ops;
-       /* Gadget's private data. */
-       void                    *private_data;
-
-       const char *vendor_name;                /*  8 characters or less */
-       const char *product_name;               /* 16 characters or less */
-       u16 release;
-
-       char                    can_stall;
-};
-
-struct fsg_dev {
-       struct usb_function     function;
-       struct usb_gadget       *gadget;        /* Copy of cdev->gadget */
-       struct fsg_common       *common;
-
-       u16                     interface_number;
-
-       unsigned int            bulk_in_enabled:1;
-       unsigned int            bulk_out_enabled:1;
-
-       unsigned long           atomic_bitflags;
-#define IGNORE_BULK_OUT                0
-
-       struct usb_ep           *bulk_in;
-       struct usb_ep           *bulk_out;
-};
-
-static inline int __fsg_is_set(struct fsg_common *common,
-                              const char *func, unsigned line)
-{
-       if (common->fsg)
-               return 1;
-       ERROR(common, "common->fsg is NULL in %s at %u\n", func, line);
-       WARN_ON(1);
-       return 0;
-}
-
-#define fsg_is_set(common) likely(__fsg_is_set(common, __func__, __LINE__))
-
-static inline struct fsg_dev *fsg_from_func(struct usb_function *f)
-{
-       return container_of(f, struct fsg_dev, function);
-}
-
-typedef void (*fsg_routine_t)(struct fsg_dev *);
-
-static int exception_in_progress(struct fsg_common *common)
-{
-       return common->state > FSG_STATE_IDLE;
-}
-
-/* Make bulk-out requests be divisible by the maxpacket size */
-static void set_bulk_out_req_length(struct fsg_common *common,
-                                   struct fsg_buffhd *bh, unsigned int length)
-{
-       unsigned int    rem;
-
-       bh->bulk_out_intended_length = length;
-       rem = length % common->bulk_out_maxpacket;
-       if (rem > 0)
-               length += common->bulk_out_maxpacket - rem;
-       bh->outreq->length = length;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
-{
-       const char      *name;
-
-       if (ep == fsg->bulk_in)
-               name = "bulk-in";
-       else if (ep == fsg->bulk_out)
-               name = "bulk-out";
-       else
-               name = ep->name;
-       DBG(fsg, "%s set halt\n", name);
-       return usb_ep_set_halt(ep);
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-/* These routines may be called in process context or in_irq */
-
-/* Caller must hold fsg->lock */
-static void wakeup_thread(struct fsg_common *common)
-{
-       /* Tell the main thread that something has happened */
-       common->thread_wakeup_needed = 1;
-       if (common->thread_task)
-               wake_up_process(common->thread_task);
-}
-
-static void raise_exception(struct fsg_common *common, enum fsg_state new_state)
-{
-       unsigned long           flags;
-
-       /*
-        * Do nothing if a higher-priority exception is already in progress.
-        * If a lower-or-equal priority exception is in progress, preempt it
-        * and notify the main thread by sending it a signal.
-        */
-       spin_lock_irqsave(&common->lock, flags);
-       if (common->state <= new_state) {
-               common->exception_req_tag = common->ep0_req_tag;
-               common->state = new_state;
-               if (common->thread_task)
-                       send_sig_info(SIGUSR1, SEND_SIG_FORCED,
-                                     common->thread_task);
-       }
-       spin_unlock_irqrestore(&common->lock, flags);
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static int ep0_queue(struct fsg_common *common)
-{
-       int     rc;
-
-       rc = usb_ep_queue(common->ep0, common->ep0req, GFP_ATOMIC);
-       common->ep0->driver_data = common;
-       if (rc != 0 && rc != -ESHUTDOWN) {
-               /* We can't do much more than wait for a reset */
-               WARNING(common, "error in submission: %s --> %d\n",
-                       common->ep0->name, rc);
-       }
-       return rc;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-/* Completion handlers. These always run in_irq. */
-
-static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       struct fsg_common       *common = ep->driver_data;
-       struct fsg_buffhd       *bh = req->context;
-
-       if (req->status || req->actual != req->length)
-               DBG(common, "%s --> %d, %u/%u\n", __func__,
-                   req->status, req->actual, req->length);
-       if (req->status == -ECONNRESET)         /* Request was cancelled */
-               usb_ep_fifo_flush(ep);
-
-       /* Hold the lock while we update the request and buffer states */
-       smp_wmb();
-       spin_lock(&common->lock);
-       bh->inreq_busy = 0;
-       bh->state = BUF_STATE_EMPTY;
-       wakeup_thread(common);
-       spin_unlock(&common->lock);
-}
-
-static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       struct fsg_common       *common = ep->driver_data;
-       struct fsg_buffhd       *bh = req->context;
-
-       dump_msg(common, "bulk-out", req->buf, req->actual);
-       if (req->status || req->actual != bh->bulk_out_intended_length)
-               DBG(common, "%s --> %d, %u/%u\n", __func__,
-                   req->status, req->actual, bh->bulk_out_intended_length);
-       if (req->status == -ECONNRESET)         /* Request was cancelled */
-               usb_ep_fifo_flush(ep);
-
-       /* Hold the lock while we update the request and buffer states */
-       smp_wmb();
-       spin_lock(&common->lock);
-       bh->outreq_busy = 0;
-       bh->state = BUF_STATE_FULL;
-       wakeup_thread(common);
-       spin_unlock(&common->lock);
-}
-
-static int fsg_setup(struct usb_function *f,
-                    const struct usb_ctrlrequest *ctrl)
-{
-       struct fsg_dev          *fsg = fsg_from_func(f);
-       struct usb_request      *req = fsg->common->ep0req;
-       u16                     w_index = le16_to_cpu(ctrl->wIndex);
-       u16                     w_value = le16_to_cpu(ctrl->wValue);
-       u16                     w_length = le16_to_cpu(ctrl->wLength);
-
-       if (!fsg_is_set(fsg->common))
-               return -EOPNOTSUPP;
-
-       ++fsg->common->ep0_req_tag;     /* Record arrival of a new request */
-       req->context = NULL;
-       req->length = 0;
-       dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
-
-       switch (ctrl->bRequest) {
-
-       case US_BULK_RESET_REQUEST:
-               if (ctrl->bRequestType !=
-                   (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
-                       break;
-               if (w_index != fsg->interface_number || w_value != 0 ||
-                               w_length != 0)
-                       return -EDOM;
-
-               /*
-                * Raise an exception to stop the current operation
-                * and reinitialize our state.
-                */
-               DBG(fsg, "bulk reset request\n");
-               raise_exception(fsg->common, FSG_STATE_RESET);
-               return DELAYED_STATUS;
-
-       case US_BULK_GET_MAX_LUN:
-               if (ctrl->bRequestType !=
-                   (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
-                       break;
-               if (w_index != fsg->interface_number || w_value != 0 ||
-                               w_length != 1)
-                       return -EDOM;
-               VDBG(fsg, "get max LUN\n");
-               *(u8 *)req->buf = fsg->common->nluns - 1;
-
-               /* Respond with data/status */
-               req->length = min((u16)1, w_length);
-               return ep0_queue(fsg->common);
-       }
-
-       VDBG(fsg,
-            "unknown class-specific control req %02x.%02x v%04x i%04x l%u\n",
-            ctrl->bRequestType, ctrl->bRequest,
-            le16_to_cpu(ctrl->wValue), w_index, w_length);
-       return -EOPNOTSUPP;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-/* All the following routines run in process context */
-
-/* Use this for bulk or interrupt transfers, not ep0 */
-static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
-                          struct usb_request *req, int *pbusy,
-                          enum fsg_buffer_state *state)
-{
-       int     rc;
-
-       if (ep == fsg->bulk_in)
-               dump_msg(fsg, "bulk-in", req->buf, req->length);
-
-       spin_lock_irq(&fsg->common->lock);
-       *pbusy = 1;
-       *state = BUF_STATE_BUSY;
-       spin_unlock_irq(&fsg->common->lock);
-       rc = usb_ep_queue(ep, req, GFP_KERNEL);
-       if (rc != 0) {
-               *pbusy = 0;
-               *state = BUF_STATE_EMPTY;
-
-               /* We can't do much more than wait for a reset */
-
-               /*
-                * Note: currently the net2280 driver fails zero-length
-                * submissions if DMA is enabled.
-                */
-               if (rc != -ESHUTDOWN &&
-                   !(rc == -EOPNOTSUPP && req->length == 0))
-                       WARNING(fsg, "error in submission: %s --> %d\n",
-                               ep->name, rc);
-       }
-}
-
-static bool start_in_transfer(struct fsg_common *common, struct fsg_buffhd *bh)
-{
-       if (!fsg_is_set(common))
-               return false;
-       start_transfer(common->fsg, common->fsg->bulk_in,
-                      bh->inreq, &bh->inreq_busy, &bh->state);
-       return true;
-}
-
-static bool start_out_transfer(struct fsg_common *common, struct fsg_buffhd *bh)
-{
-       if (!fsg_is_set(common))
-               return false;
-       start_transfer(common->fsg, common->fsg->bulk_out,
-                      bh->outreq, &bh->outreq_busy, &bh->state);
-       return true;
-}
-
-static int sleep_thread(struct fsg_common *common)
-{
-       int     rc = 0;
-
-       /* Wait until a signal arrives or we are woken up */
-       for (;;) {
-               try_to_freeze();
-               set_current_state(TASK_INTERRUPTIBLE);
-               if (signal_pending(current)) {
-                       rc = -EINTR;
-                       break;
-               }
-               if (common->thread_wakeup_needed)
-                       break;
-               schedule();
-       }
-       __set_current_state(TASK_RUNNING);
-       common->thread_wakeup_needed = 0;
-       return rc;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static int do_read(struct fsg_common *common)
-{
-       struct fsg_lun          *curlun = common->curlun;
-       u32                     lba;
-       struct fsg_buffhd       *bh;
-       int                     rc;
-       u32                     amount_left;
-       loff_t                  file_offset, file_offset_tmp;
-       unsigned int            amount;
-       ssize_t                 nread;
-
-       /*
-        * Get the starting Logical Block Address and check that it's
-        * not too big.
-        */
-       if (common->cmnd[0] == READ_6)
-               lba = get_unaligned_be24(&common->cmnd[1]);
-       else {
-               lba = get_unaligned_be32(&common->cmnd[2]);
-
-               /*
-                * We allow DPO (Disable Page Out = don't save data in the
-                * cache) and FUA (Force Unit Access = don't read from the
-                * cache), but we don't implement them.
-                */
-               if ((common->cmnd[1] & ~0x18) != 0) {
-                       curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
-                       return -EINVAL;
-               }
-       }
-       if (lba >= curlun->num_sectors) {
-               curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
-               return -EINVAL;
-       }
-       file_offset = ((loff_t) lba) << curlun->blkbits;
-
-       /* Carry out the file reads */
-       amount_left = common->data_size_from_cmnd;
-       if (unlikely(amount_left == 0))
-               return -EIO;            /* No default reply */
-
-       for (;;) {
-               /*
-                * Figure out how much we need to read:
-                * Try to read the remaining amount.
-                * But don't read more than the buffer size.
-                * And don't try to read past the end of the file.
-                */
-               amount = min(amount_left, FSG_BUFLEN);
-               amount = min((loff_t)amount,
-                            curlun->file_length - file_offset);
-
-               /* Wait for the next buffer to become available */
-               bh = common->next_buffhd_to_fill;
-               while (bh->state != BUF_STATE_EMPTY) {
-                       rc = sleep_thread(common);
-                       if (rc)
-                               return rc;
-               }
-
-               /*
-                * If we were asked to read past the end of file,
-                * end with an empty buffer.
-                */
-               if (amount == 0) {
-                       curlun->sense_data =
-                                       SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
-                       curlun->sense_data_info =
-                                       file_offset >> curlun->blkbits;
-                       curlun->info_valid = 1;
-                       bh->inreq->length = 0;
-                       bh->state = BUF_STATE_FULL;
-                       break;
-               }
-
-               /* Perform the read */
-               file_offset_tmp = file_offset;
-               nread = vfs_read(curlun->filp,
-                                (char __user *)bh->buf,
-                                amount, &file_offset_tmp);
-               VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
-                     (unsigned long long)file_offset, (int)nread);
-               if (signal_pending(current))
-                       return -EINTR;
-
-               if (nread < 0) {
-                       LDBG(curlun, "error in file read: %d\n", (int)nread);
-                       nread = 0;
-               } else if (nread < amount) {
-                       LDBG(curlun, "partial file read: %d/%u\n",
-                            (int)nread, amount);
-                       nread = round_down(nread, curlun->blksize);
-               }
-               file_offset  += nread;
-               amount_left  -= nread;
-               common->residue -= nread;
-
-               /*
-                * Except at the end of the transfer, nread will be
-                * equal to the buffer size, which is divisible by the
-                * bulk-in maxpacket size.
-                */
-               bh->inreq->length = nread;
-               bh->state = BUF_STATE_FULL;
-
-               /* If an error occurred, report it and its position */
-               if (nread < amount) {
-                       curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
-                       curlun->sense_data_info =
-                                       file_offset >> curlun->blkbits;
-                       curlun->info_valid = 1;
-                       break;
-               }
-
-               if (amount_left == 0)
-                       break;          /* No more left to read */
-
-               /* Send this buffer and go read some more */
-               bh->inreq->zero = 0;
-               if (!start_in_transfer(common, bh))
-                       /* Don't know what to do if common->fsg is NULL */
-                       return -EIO;
-               common->next_buffhd_to_fill = bh->next;
-       }
-
-       return -EIO;            /* No default reply */
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static int do_write(struct fsg_common *common)
-{
-       struct fsg_lun          *curlun = common->curlun;
-       u32                     lba;
-       struct fsg_buffhd       *bh;
-       int                     get_some_more;
-       u32                     amount_left_to_req, amount_left_to_write;
-       loff_t                  usb_offset, file_offset, file_offset_tmp;
-       unsigned int            amount;
-       ssize_t                 nwritten;
-       int                     rc;
-
-       if (curlun->ro) {
-               curlun->sense_data = SS_WRITE_PROTECTED;
-               return -EINVAL;
-       }
-       spin_lock(&curlun->filp->f_lock);
-       curlun->filp->f_flags &= ~O_SYNC;       /* Default is not to wait */
-       spin_unlock(&curlun->filp->f_lock);
-
-       /*
-        * Get the starting Logical Block Address and check that it's
-        * not too big
-        */
-       if (common->cmnd[0] == WRITE_6)
-               lba = get_unaligned_be24(&common->cmnd[1]);
-       else {
-               lba = get_unaligned_be32(&common->cmnd[2]);
-
-               /*
-                * We allow DPO (Disable Page Out = don't save data in the
-                * cache) and FUA (Force Unit Access = write directly to the
-                * medium).  We don't implement DPO; we implement FUA by
-                * performing synchronous output.
-                */
-               if (common->cmnd[1] & ~0x18) {
-                       curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
-                       return -EINVAL;
-               }
-               if (!curlun->nofua && (common->cmnd[1] & 0x08)) { /* FUA */
-                       spin_lock(&curlun->filp->f_lock);
-                       curlun->filp->f_flags |= O_SYNC;
-                       spin_unlock(&curlun->filp->f_lock);
-               }
-       }
-       if (lba >= curlun->num_sectors) {
-               curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
-               return -EINVAL;
-       }
-
-       /* Carry out the file writes */
-       get_some_more = 1;
-       file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
-       amount_left_to_req = common->data_size_from_cmnd;
-       amount_left_to_write = common->data_size_from_cmnd;
-
-       while (amount_left_to_write > 0) {
-
-               /* Queue a request for more data from the host */
-               bh = common->next_buffhd_to_fill;
-               if (bh->state == BUF_STATE_EMPTY && get_some_more) {
-
-                       /*
-                        * Figure out how much we want to get:
-                        * Try to get the remaining amount,
-                        * but not more than the buffer size.
-                        */
-                       amount = min(amount_left_to_req, FSG_BUFLEN);
-
-                       /* Beyond the end of the backing file? */
-                       if (usb_offset >= curlun->file_length) {
-                               get_some_more = 0;
-                               curlun->sense_data =
-                                       SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
-                               curlun->sense_data_info =
-                                       usb_offset >> curlun->blkbits;
-                               curlun->info_valid = 1;
-                               continue;
-                       }
-
-                       /* Get the next buffer */
-                       usb_offset += amount;
-                       common->usb_amount_left -= amount;
-                       amount_left_to_req -= amount;
-                       if (amount_left_to_req == 0)
-                               get_some_more = 0;
-
-                       /*
-                        * Except at the end of the transfer, amount will be
-                        * equal to the buffer size, which is divisible by
-                        * the bulk-out maxpacket size.
-                        */
-                       set_bulk_out_req_length(common, bh, amount);
-                       if (!start_out_transfer(common, bh))
-                               /* Dunno what to do if common->fsg is NULL */
-                               return -EIO;
-                       common->next_buffhd_to_fill = bh->next;
-                       continue;
-               }
-
-               /* Write the received data to the backing file */
-               bh = common->next_buffhd_to_drain;
-               if (bh->state == BUF_STATE_EMPTY && !get_some_more)
-                       break;                  /* We stopped early */
-               if (bh->state == BUF_STATE_FULL) {
-                       smp_rmb();
-                       common->next_buffhd_to_drain = bh->next;
-                       bh->state = BUF_STATE_EMPTY;
-
-                       /* Did something go wrong with the transfer? */
-                       if (bh->outreq->status != 0) {
-                               curlun->sense_data = SS_COMMUNICATION_FAILURE;
-                               curlun->sense_data_info =
-                                       file_offset >> curlun->blkbits;
-                               curlun->info_valid = 1;
-                               break;
-                       }
-
-                       amount = bh->outreq->actual;
-                       if (curlun->file_length - file_offset < amount) {
-                               LERROR(curlun,
-                                      "write %u @ %llu beyond end %llu\n",
-                                      amount, (unsigned long long)file_offset,
-                                      (unsigned long long)curlun->file_length);
-                               amount = curlun->file_length - file_offset;
-                       }
-
-                       /* Don't accept excess data.  The spec doesn't say
-                        * what to do in this case.  We'll ignore the error.
-                        */
-                       amount = min(amount, bh->bulk_out_intended_length);
-
-                       /* Don't write a partial block */
-                       amount = round_down(amount, curlun->blksize);
-                       if (amount == 0)
-                               goto empty_write;
-
-                       /* Perform the write */
-                       file_offset_tmp = file_offset;
-                       nwritten = vfs_write(curlun->filp,
-                                            (char __user *)bh->buf,
-                                            amount, &file_offset_tmp);
-                       VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
-                             (unsigned long long)file_offset, (int)nwritten);
-                       if (signal_pending(current))
-                               return -EINTR;          /* Interrupted! */
-
-                       if (nwritten < 0) {
-                               LDBG(curlun, "error in file write: %d\n",
-                                    (int)nwritten);
-                               nwritten = 0;
-                       } else if (nwritten < amount) {
-                               LDBG(curlun, "partial file write: %d/%u\n",
-                                    (int)nwritten, amount);
-                               nwritten = round_down(nwritten, curlun->blksize);
-                       }
-                       file_offset += nwritten;
-                       amount_left_to_write -= nwritten;
-                       common->residue -= nwritten;
-
-                       /* If an error occurred, report it and its position */
-                       if (nwritten < amount) {
-                               curlun->sense_data = SS_WRITE_ERROR;
-                               curlun->sense_data_info =
-                                       file_offset >> curlun->blkbits;
-                               curlun->info_valid = 1;
-                               break;
-                       }
-
- empty_write:
-                       /* Did the host decide to stop early? */
-                       if (bh->outreq->actual < bh->bulk_out_intended_length) {
-                               common->short_packet_received = 1;
-                               break;
-                       }
-                       continue;
-               }
-
-               /* Wait for something to happen */
-               rc = sleep_thread(common);
-               if (rc)
-                       return rc;
-       }
-
-       return -EIO;            /* No default reply */
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static int do_synchronize_cache(struct fsg_common *common)
-{
-       struct fsg_lun  *curlun = common->curlun;
-       int             rc;
-
-       /* We ignore the requested LBA and write out all file's
-        * dirty data buffers. */
-       rc = fsg_lun_fsync_sub(curlun);
-       if (rc)
-               curlun->sense_data = SS_WRITE_ERROR;
-       return 0;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static void invalidate_sub(struct fsg_lun *curlun)
-{
-       struct file     *filp = curlun->filp;
-       struct inode    *inode = file_inode(filp);
-       unsigned long   rc;
-
-       rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
-       VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
-}
-
-static int do_verify(struct fsg_common *common)
-{
-       struct fsg_lun          *curlun = common->curlun;
-       u32                     lba;
-       u32                     verification_length;
-       struct fsg_buffhd       *bh = common->next_buffhd_to_fill;
-       loff_t                  file_offset, file_offset_tmp;
-       u32                     amount_left;
-       unsigned int            amount;
-       ssize_t                 nread;
-
-       /*
-        * Get the starting Logical Block Address and check that it's
-        * not too big.
-        */
-       lba = get_unaligned_be32(&common->cmnd[2]);
-       if (lba >= curlun->num_sectors) {
-               curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
-               return -EINVAL;
-       }
-
-       /*
-        * We allow DPO (Disable Page Out = don't save data in the
-        * cache) but we don't implement it.
-        */
-       if (common->cmnd[1] & ~0x10) {
-               curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
-               return -EINVAL;
-       }
-
-       verification_length = get_unaligned_be16(&common->cmnd[7]);
-       if (unlikely(verification_length == 0))
-               return -EIO;            /* No default reply */
-
-       /* Prepare to carry out the file verify */
-       amount_left = verification_length << curlun->blkbits;
-       file_offset = ((loff_t) lba) << curlun->blkbits;
-
-       /* Write out all the dirty buffers before invalidating them */
-       fsg_lun_fsync_sub(curlun);
-       if (signal_pending(current))
-               return -EINTR;
-
-       invalidate_sub(curlun);
-       if (signal_pending(current))
-               return -EINTR;
-
-       /* Just try to read the requested blocks */
-       while (amount_left > 0) {
-               /*
-                * Figure out how much we need to read:
-                * Try to read the remaining amount, but not more than
-                * the buffer size.
-                * And don't try to read past the end of the file.
-                */
-               amount = min(amount_left, FSG_BUFLEN);
-               amount = min((loff_t)amount,
-                            curlun->file_length - file_offset);
-               if (amount == 0) {
-                       curlun->sense_data =
-                                       SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
-                       curlun->sense_data_info =
-                               file_offset >> curlun->blkbits;
-                       curlun->info_valid = 1;
-                       break;
-               }
-
-               /* Perform the read */
-               file_offset_tmp = file_offset;
-               nread = vfs_read(curlun->filp,
-                               (char __user *) bh->buf,
-                               amount, &file_offset_tmp);
-               VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
-                               (unsigned long long) file_offset,
-                               (int) nread);
-               if (signal_pending(current))
-                       return -EINTR;
-
-               if (nread < 0) {
-                       LDBG(curlun, "error in file verify: %d\n", (int)nread);
-                       nread = 0;
-               } else if (nread < amount) {
-                       LDBG(curlun, "partial file verify: %d/%u\n",
-                            (int)nread, amount);
-                       nread = round_down(nread, curlun->blksize);
-               }
-               if (nread == 0) {
-                       curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
-                       curlun->sense_data_info =
-                               file_offset >> curlun->blkbits;
-                       curlun->info_valid = 1;
-                       break;
-               }
-               file_offset += nread;
-               amount_left -= nread;
-       }
-       return 0;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static int do_inquiry(struct fsg_common *common, struct fsg_buffhd *bh)
-{
-       struct fsg_lun *curlun = common->curlun;
-       u8      *buf = (u8 *) bh->buf;
-
-       if (!curlun) {          /* Unsupported LUNs are okay */
-               common->bad_lun_okay = 1;
-               memset(buf, 0, 36);
-               buf[0] = 0x7f;          /* Unsupported, no device-type */
-               buf[4] = 31;            /* Additional length */
-               return 36;
-       }
-
-       buf[0] = curlun->cdrom ? TYPE_ROM : TYPE_DISK;
-       buf[1] = curlun->removable ? 0x80 : 0;
-       buf[2] = 2;             /* ANSI SCSI level 2 */
-       buf[3] = 2;             /* SCSI-2 INQUIRY data format */
-       buf[4] = 31;            /* Additional length */
-       buf[5] = 0;             /* No special options */
-       buf[6] = 0;
-       buf[7] = 0;
-       memcpy(buf + 8, common->inquiry_string, sizeof common->inquiry_string);
-       return 36;
-}
-
-static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh)
-{
-       struct fsg_lun  *curlun = common->curlun;
-       u8              *buf = (u8 *) bh->buf;
-       u32             sd, sdinfo;
-       int             valid;
-
-       /*
-        * From the SCSI-2 spec., section 7.9 (Unit attention condition):
-        *
-        * If a REQUEST SENSE command is received from an initiator
-        * with a pending unit attention condition (before the target
-        * generates the contingent allegiance condition), then the
-        * target shall either:
-        *   a) report any pending sense data and preserve the unit
-        *      attention condition on the logical unit, or,
-        *   b) report the unit attention condition, may discard any
-        *      pending sense data, and clear the unit attention
-        *      condition on the logical unit for that initiator.
-        *
-        * FSG normally uses option a); enable this code to use option b).
-        */
-#if 0
-       if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
-               curlun->sense_data = curlun->unit_attention_data;
-               curlun->unit_attention_data = SS_NO_SENSE;
-       }
-#endif
-
-       if (!curlun) {          /* Unsupported LUNs are okay */
-               common->bad_lun_okay = 1;
-               sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
-               sdinfo = 0;
-               valid = 0;
-       } else {
-               sd = curlun->sense_data;
-               sdinfo = curlun->sense_data_info;
-               valid = curlun->info_valid << 7;
-               curlun->sense_data = SS_NO_SENSE;
-               curlun->sense_data_info = 0;
-               curlun->info_valid = 0;
-       }
-
-       memset(buf, 0, 18);
-       buf[0] = valid | 0x70;                  /* Valid, current error */
-       buf[2] = SK(sd);
-       put_unaligned_be32(sdinfo, &buf[3]);    /* Sense information */
-       buf[7] = 18 - 8;                        /* Additional sense length */
-       buf[12] = ASC(sd);
-       buf[13] = ASCQ(sd);
-       return 18;
-}
-
-static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh)
-{
-       struct fsg_lun  *curlun = common->curlun;
-       u32             lba = get_unaligned_be32(&common->cmnd[2]);
-       int             pmi = common->cmnd[8];
-       u8              *buf = (u8 *)bh->buf;
-
-       /* Check the PMI and LBA fields */
-       if (pmi > 1 || (pmi == 0 && lba != 0)) {
-               curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
-               return -EINVAL;
-       }
-
-       put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
-                                               /* Max logical block */
-       put_unaligned_be32(curlun->blksize, &buf[4]);/* Block length */
-       return 8;
-}
-
-static int do_read_header(struct fsg_common *common, struct fsg_buffhd *bh)
-{
-       struct fsg_lun  *curlun = common->curlun;
-       int             msf = common->cmnd[1] & 0x02;
-       u32             lba = get_unaligned_be32(&common->cmnd[2]);
-       u8              *buf = (u8 *)bh->buf;
-
-       if (common->cmnd[1] & ~0x02) {          /* Mask away MSF */
-               curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
-               return -EINVAL;
-       }
-       if (lba >= curlun->num_sectors) {
-               curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
-               return -EINVAL;
-       }
-
-       memset(buf, 0, 8);
-       buf[0] = 0x01;          /* 2048 bytes of user data, rest is EC */
-       store_cdrom_address(&buf[4], msf, lba);
-       return 8;
-}
-
-static int do_read_toc(struct fsg_common *common, struct fsg_buffhd *bh)
-{
-       struct fsg_lun  *curlun = common->curlun;
-       int             msf = common->cmnd[1] & 0x02;
-       int             start_track = common->cmnd[6];
-       u8              *buf = (u8 *)bh->buf;
-
-       if ((common->cmnd[1] & ~0x02) != 0 ||   /* Mask away MSF */
-                       start_track > 1) {
-               curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
-               return -EINVAL;
-       }
-
-       memset(buf, 0, 20);
-       buf[1] = (20-2);                /* TOC data length */
-       buf[2] = 1;                     /* First track number */
-       buf[3] = 1;                     /* Last track number */
-       buf[5] = 0x16;                  /* Data track, copying allowed */
-       buf[6] = 0x01;                  /* Only track is number 1 */
-       store_cdrom_address(&buf[8], msf, 0);
-
-       buf[13] = 0x16;                 /* Lead-out track is data */
-       buf[14] = 0xAA;                 /* Lead-out track number */
-       store_cdrom_address(&buf[16], msf, curlun->num_sectors);
-       return 20;
-}
-
-static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
-{
-       struct fsg_lun  *curlun = common->curlun;
-       int             mscmnd = common->cmnd[0];
-       u8              *buf = (u8 *) bh->buf;
-       u8              *buf0 = buf;
-       int             pc, page_code;
-       int             changeable_values, all_pages;
-       int             valid_page = 0;
-       int             len, limit;
-
-       if ((common->cmnd[1] & ~0x08) != 0) {   /* Mask away DBD */
-               curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
-               return -EINVAL;
-       }
-       pc = common->cmnd[2] >> 6;
-       page_code = common->cmnd[2] & 0x3f;
-       if (pc == 3) {
-               curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
-               return -EINVAL;
-       }
-       changeable_values = (pc == 1);
-       all_pages = (page_code == 0x3f);
-
-       /*
-        * Write the mode parameter header.  Fixed values are: default
-        * medium type, no cache control (DPOFUA), and no block descriptors.
-        * The only variable value is the WriteProtect bit.  We will fill in
-        * the mode data length later.
-        */
-       memset(buf, 0, 8);
-       if (mscmnd == MODE_SENSE) {
-               buf[2] = (curlun->ro ? 0x80 : 0x00);            /* WP, DPOFUA */
-               buf += 4;
-               limit = 255;
-       } else {                        /* MODE_SENSE_10 */
-               buf[3] = (curlun->ro ? 0x80 : 0x00);            /* WP, DPOFUA */
-               buf += 8;
-               limit = 65535;          /* Should really be FSG_BUFLEN */
-       }
-
-       /* No block descriptors */
-
-       /*
-        * The mode pages, in numerical order.  The only page we support
-        * is the Caching page.
-        */
-       if (page_code == 0x08 || all_pages) {
-               valid_page = 1;
-               buf[0] = 0x08;          /* Page code */
-               buf[1] = 10;            /* Page length */
-               memset(buf+2, 0, 10);   /* None of the fields are changeable */
-
-               if (!changeable_values) {
-                       buf[2] = 0x04;  /* Write cache enable, */
-                                       /* Read cache not disabled */
-                                       /* No cache retention priorities */
-                       put_unaligned_be16(0xffff, &buf[4]);
-                                       /* Don't disable prefetch */
-                                       /* Minimum prefetch = 0 */
-                       put_unaligned_be16(0xffff, &buf[8]);
-                                       /* Maximum prefetch */
-                       put_unaligned_be16(0xffff, &buf[10]);
-                                       /* Maximum prefetch ceiling */
-               }
-               buf += 12;
-       }
-
-       /*
-        * Check that a valid page was requested and the mode data length
-        * isn't too long.
-        */
-       len = buf - buf0;
-       if (!valid_page || len > limit) {
-               curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
-               return -EINVAL;
-       }
-
-       /*  Store the mode data length */
-       if (mscmnd == MODE_SENSE)
-               buf0[0] = len - 1;
-       else
-               put_unaligned_be16(len - 2, buf0);
-       return len;
-}
-
-static int do_start_stop(struct fsg_common *common)
-{
-       struct fsg_lun  *curlun = common->curlun;
-       int             loej, start;
-
-       if (!curlun) {
-               return -EINVAL;
-       } else if (!curlun->removable) {
-               curlun->sense_data = SS_INVALID_COMMAND;
-               return -EINVAL;
-       } else if ((common->cmnd[1] & ~0x01) != 0 || /* Mask away Immed */
-                  (common->cmnd[4] & ~0x03) != 0) { /* Mask LoEj, Start */
-               curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
-               return -EINVAL;
-       }
-
-       loej  = common->cmnd[4] & 0x02;
-       start = common->cmnd[4] & 0x01;
-
-       /*
-        * Our emulation doesn't support mounting; the medium is
-        * available for use as soon as it is loaded.
-        */
-       if (start) {
-               if (!fsg_lun_is_open(curlun)) {
-                       curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
-                       return -EINVAL;
-               }
-               return 0;
-       }
-
-       /* Are we allowed to unload the media? */
-       if (curlun->prevent_medium_removal) {
-               LDBG(curlun, "unload attempt prevented\n");
-               curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
-               return -EINVAL;
-       }
-
-       if (!loej)
-               return 0;
-
-       /* Simulate an unload/eject */
-       if (common->ops && common->ops->pre_eject) {
-               int r = common->ops->pre_eject(common, curlun,
-                                              curlun - common->luns);
-               if (unlikely(r < 0))
-                       return r;
-               else if (r)
-                       return 0;
-       }
-
-       up_read(&common->filesem);
-       down_write(&common->filesem);
-       fsg_lun_close(curlun);
-       up_write(&common->filesem);
-       down_read(&common->filesem);
-
-       return common->ops && common->ops->post_eject
-               ? min(0, common->ops->post_eject(common, curlun,
-                                                curlun - common->luns))
-               : 0;
-}
-
-static int do_prevent_allow(struct fsg_common *common)
-{
-       struct fsg_lun  *curlun = common->curlun;
-       int             prevent;
-
-       if (!common->curlun) {
-               return -EINVAL;
-       } else if (!common->curlun->removable) {
-               common->curlun->sense_data = SS_INVALID_COMMAND;
-               return -EINVAL;
-       }
-
-       prevent = common->cmnd[4] & 0x01;
-       if ((common->cmnd[4] & ~0x01) != 0) {   /* Mask away Prevent */
-               curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
-               return -EINVAL;
-       }
-
-       if (curlun->prevent_medium_removal && !prevent)
-               fsg_lun_fsync_sub(curlun);
-       curlun->prevent_medium_removal = prevent;
-       return 0;
-}
-
-static int do_read_format_capacities(struct fsg_common *common,
-                       struct fsg_buffhd *bh)
-{
-       struct fsg_lun  *curlun = common->curlun;
-       u8              *buf = (u8 *) bh->buf;
-
-       buf[0] = buf[1] = buf[2] = 0;
-       buf[3] = 8;     /* Only the Current/Maximum Capacity Descriptor */
-       buf += 4;
-
-       put_unaligned_be32(curlun->num_sectors, &buf[0]);
-                                               /* Number of blocks */
-       put_unaligned_be32(curlun->blksize, &buf[4]);/* Block length */
-       buf[4] = 0x02;                          /* Current capacity */
-       return 12;
-}
-
-static int do_mode_select(struct fsg_common *common, struct fsg_buffhd *bh)
-{
-       struct fsg_lun  *curlun = common->curlun;
-
-       /* We don't support MODE SELECT */
-       if (curlun)
-               curlun->sense_data = SS_INVALID_COMMAND;
-       return -EINVAL;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
-{
-       int     rc;
-
-       rc = fsg_set_halt(fsg, fsg->bulk_in);
-       if (rc == -EAGAIN)
-               VDBG(fsg, "delayed bulk-in endpoint halt\n");
-       while (rc != 0) {
-               if (rc != -EAGAIN) {
-                       WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
-                       rc = 0;
-                       break;
-               }
-
-               /* Wait for a short time and then try again */
-               if (msleep_interruptible(100) != 0)
-                       return -EINTR;
-               rc = usb_ep_set_halt(fsg->bulk_in);
-       }
-       return rc;
-}
-
-static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
-{
-       int     rc;
-
-       DBG(fsg, "bulk-in set wedge\n");
-       rc = usb_ep_set_wedge(fsg->bulk_in);
-       if (rc == -EAGAIN)
-               VDBG(fsg, "delayed bulk-in endpoint wedge\n");
-       while (rc != 0) {
-               if (rc != -EAGAIN) {
-                       WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
-                       rc = 0;
-                       break;
-               }
-
-               /* Wait for a short time and then try again */
-               if (msleep_interruptible(100) != 0)
-                       return -EINTR;
-               rc = usb_ep_set_wedge(fsg->bulk_in);
-       }
-       return rc;
-}
-
-static int throw_away_data(struct fsg_common *common)
-{
-       struct fsg_buffhd       *bh;
-       u32                     amount;
-       int                     rc;
-
-       for (bh = common->next_buffhd_to_drain;
-            bh->state != BUF_STATE_EMPTY || common->usb_amount_left > 0;
-            bh = common->next_buffhd_to_drain) {
-
-               /* Throw away the data in a filled buffer */
-               if (bh->state == BUF_STATE_FULL) {
-                       smp_rmb();
-                       bh->state = BUF_STATE_EMPTY;
-                       common->next_buffhd_to_drain = bh->next;
-
-                       /* A short packet or an error ends everything */
-                       if (bh->outreq->actual < bh->bulk_out_intended_length ||
-                           bh->outreq->status != 0) {
-                               raise_exception(common,
-                                               FSG_STATE_ABORT_BULK_OUT);
-                               return -EINTR;
-                       }
-                       continue;
-               }
-
-               /* Try to submit another request if we need one */
-               bh = common->next_buffhd_to_fill;
-               if (bh->state == BUF_STATE_EMPTY
-                && common->usb_amount_left > 0) {
-                       amount = min(common->usb_amount_left, FSG_BUFLEN);
-
-                       /*
-                        * Except at the end of the transfer, amount will be
-                        * equal to the buffer size, which is divisible by
-                        * the bulk-out maxpacket size.
-                        */
-                       set_bulk_out_req_length(common, bh, amount);
-                       if (!start_out_transfer(common, bh))
-                               /* Dunno what to do if common->fsg is NULL */
-                               return -EIO;
-                       common->next_buffhd_to_fill = bh->next;
-                       common->usb_amount_left -= amount;
-                       continue;
-               }
-
-               /* Otherwise wait for something to happen */
-               rc = sleep_thread(common);
-               if (rc)
-                       return rc;
-       }
-       return 0;
-}
-
-static int finish_reply(struct fsg_common *common)
-{
-       struct fsg_buffhd       *bh = common->next_buffhd_to_fill;
-       int                     rc = 0;
-
-       switch (common->data_dir) {
-       case DATA_DIR_NONE:
-               break;                  /* Nothing to send */
-
-       /*
-        * If we don't know whether the host wants to read or write,
-        * this must be CB or CBI with an unknown command.  We mustn't
-        * try to send or receive any data.  So stall both bulk pipes
-        * if we can and wait for a reset.
-        */
-       case DATA_DIR_UNKNOWN:
-               if (!common->can_stall) {
-                       /* Nothing */
-               } else if (fsg_is_set(common)) {
-                       fsg_set_halt(common->fsg, common->fsg->bulk_out);
-                       rc = halt_bulk_in_endpoint(common->fsg);
-               } else {
-                       /* Don't know what to do if common->fsg is NULL */
-                       rc = -EIO;
-               }
-               break;
-
-       /* All but the last buffer of data must have already been sent */
-       case DATA_DIR_TO_HOST:
-               if (common->data_size == 0) {
-                       /* Nothing to send */
-
-               /* Don't know what to do if common->fsg is NULL */
-               } else if (!fsg_is_set(common)) {
-                       rc = -EIO;
-
-               /* If there's no residue, simply send the last buffer */
-               } else if (common->residue == 0) {
-                       bh->inreq->zero = 0;
-                       if (!start_in_transfer(common, bh))
-                               return -EIO;
-                       common->next_buffhd_to_fill = bh->next;
-
-               /*
-                * For Bulk-only, mark the end of the data with a short
-                * packet.  If we are allowed to stall, halt the bulk-in
-                * endpoint.  (Note: This violates the Bulk-Only Transport
-                * specification, which requires us to pad the data if we
-                * don't halt the endpoint.  Presumably nobody will mind.)
-                */
-               } else {
-                       bh->inreq->zero = 1;
-                       if (!start_in_transfer(common, bh))
-                               rc = -EIO;
-                       common->next_buffhd_to_fill = bh->next;
-                       if (common->can_stall)
-                               rc = halt_bulk_in_endpoint(common->fsg);
-               }
-               break;
-
-       /*
-        * We have processed all we want from the data the host has sent.
-        * There may still be outstanding bulk-out requests.
-        */
-       case DATA_DIR_FROM_HOST:
-               if (common->residue == 0) {
-                       /* Nothing to receive */
-
-               /* Did the host stop sending unexpectedly early? */
-               } else if (common->short_packet_received) {
-                       raise_exception(common, FSG_STATE_ABORT_BULK_OUT);
-                       rc = -EINTR;
-
-               /*
-                * We haven't processed all the incoming data.  Even though
-                * we may be allowed to stall, doing so would cause a race.
-                * The controller may already have ACK'ed all the remaining
-                * bulk-out packets, in which case the host wouldn't see a
-                * STALL.  Not realizing the endpoint was halted, it wouldn't
-                * clear the halt -- leading to problems later on.
-                */
-#if 0
-               } else if (common->can_stall) {
-                       if (fsg_is_set(common))
-                               fsg_set_halt(common->fsg,
-                                            common->fsg->bulk_out);
-                       raise_exception(common, FSG_STATE_ABORT_BULK_OUT);
-                       rc = -EINTR;
-#endif
-
-               /*
-                * We can't stall.  Read in the excess data and throw it
-                * all away.
-                */
-               } else {
-                       rc = throw_away_data(common);
-               }
-               break;
-       }
-       return rc;
-}
-
-static int send_status(struct fsg_common *common)
-{
-       struct fsg_lun          *curlun = common->curlun;
-       struct fsg_buffhd       *bh;
-       struct bulk_cs_wrap     *csw;
-       int                     rc;
-       u8                      status = US_BULK_STAT_OK;
-       u32                     sd, sdinfo = 0;
-
-       /* Wait for the next buffer to become available */
-       bh = common->next_buffhd_to_fill;
-       while (bh->state != BUF_STATE_EMPTY) {
-               rc = sleep_thread(common);
-               if (rc)
-                       return rc;
-       }
-
-       if (curlun) {
-               sd = curlun->sense_data;
-               sdinfo = curlun->sense_data_info;
-       } else if (common->bad_lun_okay)
-               sd = SS_NO_SENSE;
-       else
-               sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
-
-       if (common->phase_error) {
-               DBG(common, "sending phase-error status\n");
-               status = US_BULK_STAT_PHASE;
-               sd = SS_INVALID_COMMAND;
-       } else if (sd != SS_NO_SENSE) {
-               DBG(common, "sending command-failure status\n");
-               status = US_BULK_STAT_FAIL;
-               VDBG(common, "  sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
-                               "  info x%x\n",
-                               SK(sd), ASC(sd), ASCQ(sd), sdinfo);
-       }
-
-       /* Store and send the Bulk-only CSW */
-       csw = (void *)bh->buf;
-
-       csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
-       csw->Tag = common->tag;
-       csw->Residue = cpu_to_le32(common->residue);
-       csw->Status = status;
-
-       bh->inreq->length = US_BULK_CS_WRAP_LEN;
-       bh->inreq->zero = 0;
-       if (!start_in_transfer(common, bh))
-               /* Don't know what to do if common->fsg is NULL */
-               return -EIO;
-
-       common->next_buffhd_to_fill = bh->next;
-       return 0;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-/*
- * Check whether the command is properly formed and whether its data size
- * and direction agree with the values we already have.
- */
-static int check_command(struct fsg_common *common, int cmnd_size,
-                        enum data_direction data_dir, unsigned int mask,
-                        int needs_medium, const char *name)
-{
-       int                     i;
-       int                     lun = common->cmnd[1] >> 5;
-       static const char       dirletter[4] = {'u', 'o', 'i', 'n'};
-       char                    hdlen[20];
-       struct fsg_lun          *curlun;
-
-       hdlen[0] = 0;
-       if (common->data_dir != DATA_DIR_UNKNOWN)
-               sprintf(hdlen, ", H%c=%u", dirletter[(int) common->data_dir],
-                       common->data_size);
-       VDBG(common, "SCSI command: %s;  Dc=%d, D%c=%u;  Hc=%d%s\n",
-            name, cmnd_size, dirletter[(int) data_dir],
-            common->data_size_from_cmnd, common->cmnd_size, hdlen);
-
-       /*
-        * We can't reply at all until we know the correct data direction
-        * and size.
-        */
-       if (common->data_size_from_cmnd == 0)
-               data_dir = DATA_DIR_NONE;
-       if (common->data_size < common->data_size_from_cmnd) {
-               /*
-                * Host data size < Device data size is a phase error.
-                * Carry out the command, but only transfer as much as
-                * we are allowed.
-                */
-               common->data_size_from_cmnd = common->data_size;
-               common->phase_error = 1;
-       }
-       common->residue = common->data_size;
-       common->usb_amount_left = common->data_size;
-
-       /* Conflicting data directions is a phase error */
-       if (common->data_dir != data_dir && common->data_size_from_cmnd > 0) {
-               common->phase_error = 1;
-               return -EINVAL;
-       }
-
-       /* Verify the length of the command itself */
-       if (cmnd_size != common->cmnd_size) {
-
-               /*
-                * Special case workaround: There are plenty of buggy SCSI
-                * implementations. Many have issues with cbw->Length
-                * field passing a wrong command size. For those cases we
-                * always try to work around the problem by using the length
-                * sent by the host side provided it is at least as large
-                * as the correct command length.
-                * Examples of such cases would be MS-Windows, which issues
-                * REQUEST SENSE with cbw->Length == 12 where it should
-                * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
-                * REQUEST SENSE with cbw->Length == 10 where it should
-                * be 6 as well.
-                */
-               if (cmnd_size <= common->cmnd_size) {
-                       DBG(common, "%s is buggy! Expected length %d "
-                           "but we got %d\n", name,
-                           cmnd_size, common->cmnd_size);
-                       cmnd_size = common->cmnd_size;
-               } else {
-                       common->phase_error = 1;
-                       return -EINVAL;
-               }
-       }
-
-       /* Check that the LUN values are consistent */
-       if (common->lun != lun)
-               DBG(common, "using LUN %d from CBW, not LUN %d from CDB\n",
-                   common->lun, lun);
-
-       /* Check the LUN */
-       curlun = common->curlun;
-       if (curlun) {
-               if (common->cmnd[0] != REQUEST_SENSE) {
-                       curlun->sense_data = SS_NO_SENSE;
-                       curlun->sense_data_info = 0;
-                       curlun->info_valid = 0;
-               }
-       } else {
-               common->bad_lun_okay = 0;
-
-               /*
-                * INQUIRY and REQUEST SENSE commands are explicitly allowed
-                * to use unsupported LUNs; all others may not.
-                */
-               if (common->cmnd[0] != INQUIRY &&
-                   common->cmnd[0] != REQUEST_SENSE) {
-                       DBG(common, "unsupported LUN %d\n", common->lun);
-                       return -EINVAL;
-               }
-       }
-
-       /*
-        * If a unit attention condition exists, only INQUIRY and
-        * REQUEST SENSE commands are allowed; anything else must fail.
-        */
-       if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
-           common->cmnd[0] != INQUIRY &&
-           common->cmnd[0] != REQUEST_SENSE) {
-               curlun->sense_data = curlun->unit_attention_data;
-               curlun->unit_attention_data = SS_NO_SENSE;
-               return -EINVAL;
-       }
-
-       /* Check that only command bytes listed in the mask are non-zero */
-       common->cmnd[1] &= 0x1f;                        /* Mask away the LUN */
-       for (i = 1; i < cmnd_size; ++i) {
-               if (common->cmnd[i] && !(mask & (1 << i))) {
-                       if (curlun)
-                               curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
-                       return -EINVAL;
-               }
-       }
-
-       /* If the medium isn't mounted and the command needs to access
-        * it, return an error. */
-       if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
-               curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-/* wrapper of check_command for data size in blocks handling */
-static int check_command_size_in_blocks(struct fsg_common *common,
-               int cmnd_size, enum data_direction data_dir,
-               unsigned int mask, int needs_medium, const char *name)
-{
-       if (common->curlun)
-               common->data_size_from_cmnd <<= common->curlun->blkbits;
-       return check_command(common, cmnd_size, data_dir,
-                       mask, needs_medium, name);
-}
-
-static int do_scsi_command(struct fsg_common *common)
-{
-       struct fsg_buffhd       *bh;
-       int                     rc;
-       int                     reply = -EINVAL;
-       int                     i;
-       static char             unknown[16];
-
-       dump_cdb(common);
-
-       /* Wait for the next buffer to become available for data or status */
-       bh = common->next_buffhd_to_fill;
-       common->next_buffhd_to_drain = bh;
-       while (bh->state != BUF_STATE_EMPTY) {
-               rc = sleep_thread(common);
-               if (rc)
-                       return rc;
-       }
-       common->phase_error = 0;
-       common->short_packet_received = 0;
-
-       down_read(&common->filesem);    /* We're using the backing file */
-       switch (common->cmnd[0]) {
-
-       case INQUIRY:
-               common->data_size_from_cmnd = common->cmnd[4];
-               reply = check_command(common, 6, DATA_DIR_TO_HOST,
-                                     (1<<4), 0,
-                                     "INQUIRY");
-               if (reply == 0)
-                       reply = do_inquiry(common, bh);
-               break;
-
-       case MODE_SELECT:
-               common->data_size_from_cmnd = common->cmnd[4];
-               reply = check_command(common, 6, DATA_DIR_FROM_HOST,
-                                     (1<<1) | (1<<4), 0,
-                                     "MODE SELECT(6)");
-               if (reply == 0)
-                       reply = do_mode_select(common, bh);
-               break;
-
-       case MODE_SELECT_10:
-               common->data_size_from_cmnd =
-                       get_unaligned_be16(&common->cmnd[7]);
-               reply = check_command(common, 10, DATA_DIR_FROM_HOST,
-                                     (1<<1) | (3<<7), 0,
-                                     "MODE SELECT(10)");
-               if (reply == 0)
-                       reply = do_mode_select(common, bh);
-               break;
-
-       case MODE_SENSE:
-               common->data_size_from_cmnd = common->cmnd[4];
-               reply = check_command(common, 6, DATA_DIR_TO_HOST,
-                                     (1<<1) | (1<<2) | (1<<4), 0,
-                                     "MODE SENSE(6)");
-               if (reply == 0)
-                       reply = do_mode_sense(common, bh);
-               break;
-
-       case MODE_SENSE_10:
-               common->data_size_from_cmnd =
-                       get_unaligned_be16(&common->cmnd[7]);
-               reply = check_command(common, 10, DATA_DIR_TO_HOST,
-                                     (1<<1) | (1<<2) | (3<<7), 0,
-                                     "MODE SENSE(10)");
-               if (reply == 0)
-                       reply = do_mode_sense(common, bh);
-               break;
-
-       case ALLOW_MEDIUM_REMOVAL:
-               common->data_size_from_cmnd = 0;
-               reply = check_command(common, 6, DATA_DIR_NONE,
-                                     (1<<4), 0,
-                                     "PREVENT-ALLOW MEDIUM REMOVAL");
-               if (reply == 0)
-                       reply = do_prevent_allow(common);
-               break;
-
-       case READ_6:
-               i = common->cmnd[4];
-               common->data_size_from_cmnd = (i == 0) ? 256 : i;
-               reply = check_command_size_in_blocks(common, 6,
-                                     DATA_DIR_TO_HOST,
-                                     (7<<1) | (1<<4), 1,
-                                     "READ(6)");
-               if (reply == 0)
-                       reply = do_read(common);
-               break;
-
-       case READ_10:
-               common->data_size_from_cmnd =
-                               get_unaligned_be16(&common->cmnd[7]);
-               reply = check_command_size_in_blocks(common, 10,
-                                     DATA_DIR_TO_HOST,
-                                     (1<<1) | (0xf<<2) | (3<<7), 1,
-                                     "READ(10)");
-               if (reply == 0)
-                       reply = do_read(common);
-               break;
-
-       case READ_12:
-               common->data_size_from_cmnd =
-                               get_unaligned_be32(&common->cmnd[6]);
-               reply = check_command_size_in_blocks(common, 12,
-                                     DATA_DIR_TO_HOST,
-                                     (1<<1) | (0xf<<2) | (0xf<<6), 1,
-                                     "READ(12)");
-               if (reply == 0)
-                       reply = do_read(common);
-               break;
-
-       case READ_CAPACITY:
-               common->data_size_from_cmnd = 8;
-               reply = check_command(common, 10, DATA_DIR_TO_HOST,
-                                     (0xf<<2) | (1<<8), 1,
-                                     "READ CAPACITY");
-               if (reply == 0)
-                       reply = do_read_capacity(common, bh);
-               break;
-
-       case READ_HEADER:
-               if (!common->curlun || !common->curlun->cdrom)
-                       goto unknown_cmnd;
-               common->data_size_from_cmnd =
-                       get_unaligned_be16(&common->cmnd[7]);
-               reply = check_command(common, 10, DATA_DIR_TO_HOST,
-                                     (3<<7) | (0x1f<<1), 1,
-                                     "READ HEADER");
-               if (reply == 0)
-                       reply = do_read_header(common, bh);
-               break;
-
-       case READ_TOC:
-               if (!common->curlun || !common->curlun->cdrom)
-                       goto unknown_cmnd;
-               common->data_size_from_cmnd =
-                       get_unaligned_be16(&common->cmnd[7]);
-               reply = check_command(common, 10, DATA_DIR_TO_HOST,
-                                     (7<<6) | (1<<1), 1,
-                                     "READ TOC");
-               if (reply == 0)
-                       reply = do_read_toc(common, bh);
-               break;
-
-       case READ_FORMAT_CAPACITIES:
-               common->data_size_from_cmnd =
-                       get_unaligned_be16(&common->cmnd[7]);
-               reply = check_command(common, 10, DATA_DIR_TO_HOST,
-                                     (3<<7), 1,
-                                     "READ FORMAT CAPACITIES");
-               if (reply == 0)
-                       reply = do_read_format_capacities(common, bh);
-               break;
-
-       case REQUEST_SENSE:
-               common->data_size_from_cmnd = common->cmnd[4];
-               reply = check_command(common, 6, DATA_DIR_TO_HOST,
-                                     (1<<4), 0,
-                                     "REQUEST SENSE");
-               if (reply == 0)
-                       reply = do_request_sense(common, bh);
-               break;
-
-       case START_STOP:
-               common->data_size_from_cmnd = 0;
-               reply = check_command(common, 6, DATA_DIR_NONE,
-                                     (1<<1) | (1<<4), 0,
-                                     "START-STOP UNIT");
-               if (reply == 0)
-                       reply = do_start_stop(common);
-               break;
-
-       case SYNCHRONIZE_CACHE:
-               common->data_size_from_cmnd = 0;
-               reply = check_command(common, 10, DATA_DIR_NONE,
-                                     (0xf<<2) | (3<<7), 1,
-                                     "SYNCHRONIZE CACHE");
-               if (reply == 0)
-                       reply = do_synchronize_cache(common);
-               break;
-
-       case TEST_UNIT_READY:
-               common->data_size_from_cmnd = 0;
-               reply = check_command(common, 6, DATA_DIR_NONE,
-                               0, 1,
-                               "TEST UNIT READY");
-               break;
-
-       /*
-        * Although optional, this command is used by MS-Windows.  We
-        * support a minimal version: BytChk must be 0.
-        */
-       case VERIFY:
-               common->data_size_from_cmnd = 0;
-               reply = check_command(common, 10, DATA_DIR_NONE,
-                                     (1<<1) | (0xf<<2) | (3<<7), 1,
-                                     "VERIFY");
-               if (reply == 0)
-                       reply = do_verify(common);
-               break;
-
-       case WRITE_6:
-               i = common->cmnd[4];
-               common->data_size_from_cmnd = (i == 0) ? 256 : i;
-               reply = check_command_size_in_blocks(common, 6,
-                                     DATA_DIR_FROM_HOST,
-                                     (7<<1) | (1<<4), 1,
-                                     "WRITE(6)");
-               if (reply == 0)
-                       reply = do_write(common);
-               break;
-
-       case WRITE_10:
-               common->data_size_from_cmnd =
-                               get_unaligned_be16(&common->cmnd[7]);
-               reply = check_command_size_in_blocks(common, 10,
-                                     DATA_DIR_FROM_HOST,
-                                     (1<<1) | (0xf<<2) | (3<<7), 1,
-                                     "WRITE(10)");
-               if (reply == 0)
-                       reply = do_write(common);
-               break;
-
-       case WRITE_12:
-               common->data_size_from_cmnd =
-                               get_unaligned_be32(&common->cmnd[6]);
-               reply = check_command_size_in_blocks(common, 12,
-                                     DATA_DIR_FROM_HOST,
-                                     (1<<1) | (0xf<<2) | (0xf<<6), 1,
-                                     "WRITE(12)");
-               if (reply == 0)
-                       reply = do_write(common);
-               break;
-
-       /*
-        * Some mandatory commands that we recognize but don't implement.
-        * They don't mean much in this setting.  It's left as an exercise
-        * for anyone interested to implement RESERVE and RELEASE in terms
-        * of Posix locks.
-        */
-       case FORMAT_UNIT:
-       case RELEASE:
-       case RESERVE:
-       case SEND_DIAGNOSTIC:
-               /* Fall through */
-
-       default:
-unknown_cmnd:
-               common->data_size_from_cmnd = 0;
-               sprintf(unknown, "Unknown x%02x", common->cmnd[0]);
-               reply = check_command(common, common->cmnd_size,
-                                     DATA_DIR_UNKNOWN, ~0, 0, unknown);
-               if (reply == 0) {
-                       common->curlun->sense_data = SS_INVALID_COMMAND;
-                       reply = -EINVAL;
-               }
-               break;
-       }
-       up_read(&common->filesem);
-
-       if (reply == -EINTR || signal_pending(current))
-               return -EINTR;
-
-       /* Set up the single reply buffer for finish_reply() */
-       if (reply == -EINVAL)
-               reply = 0;              /* Error reply length */
-       if (reply >= 0 && common->data_dir == DATA_DIR_TO_HOST) {
-               reply = min((u32)reply, common->data_size_from_cmnd);
-               bh->inreq->length = reply;
-               bh->state = BUF_STATE_FULL;
-               common->residue -= reply;
-       }                               /* Otherwise it's already set */
-
-       return 0;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
-{
-       struct usb_request      *req = bh->outreq;
-       struct bulk_cb_wrap     *cbw = req->buf;
-       struct fsg_common       *common = fsg->common;
-
-       /* Was this a real packet?  Should it be ignored? */
-       if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
-               return -EINVAL;
-
-       /* Is the CBW valid? */
-       if (req->actual != US_BULK_CB_WRAP_LEN ||
-                       cbw->Signature != cpu_to_le32(
-                               US_BULK_CB_SIGN)) {
-               DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
-                               req->actual,
-                               le32_to_cpu(cbw->Signature));
-
-               /*
-                * The Bulk-only spec says we MUST stall the IN endpoint
-                * (6.6.1), so it's unavoidable.  It also says we must
-                * retain this state until the next reset, but there's
-                * no way to tell the controller driver it should ignore
-                * Clear-Feature(HALT) requests.
-                *
-                * We aren't required to halt the OUT endpoint; instead
-                * we can simply accept and discard any data received
-                * until the next reset.
-                */
-               wedge_bulk_in_endpoint(fsg);
-               set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
-               return -EINVAL;
-       }
-
-       /* Is the CBW meaningful? */
-       if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
-                       cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
-               DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
-                               "cmdlen %u\n",
-                               cbw->Lun, cbw->Flags, cbw->Length);
-
-               /*
-                * We can do anything we want here, so let's stall the
-                * bulk pipes if we are allowed to.
-                */
-               if (common->can_stall) {
-                       fsg_set_halt(fsg, fsg->bulk_out);
-                       halt_bulk_in_endpoint(fsg);
-               }
-               return -EINVAL;
-       }
-
-       /* Save the command for later */
-       common->cmnd_size = cbw->Length;
-       memcpy(common->cmnd, cbw->CDB, common->cmnd_size);
-       if (cbw->Flags & US_BULK_FLAG_IN)
-               common->data_dir = DATA_DIR_TO_HOST;
-       else
-               common->data_dir = DATA_DIR_FROM_HOST;
-       common->data_size = le32_to_cpu(cbw->DataTransferLength);
-       if (common->data_size == 0)
-               common->data_dir = DATA_DIR_NONE;
-       common->lun = cbw->Lun;
-       if (common->lun >= 0 && common->lun < common->nluns)
-               common->curlun = &common->luns[common->lun];
-       else
-               common->curlun = NULL;
-       common->tag = cbw->Tag;
-       return 0;
-}
-
-static int get_next_command(struct fsg_common *common)
-{
-       struct fsg_buffhd       *bh;
-       int                     rc = 0;
-
-       /* Wait for the next buffer to become available */
-       bh = common->next_buffhd_to_fill;
-       while (bh->state != BUF_STATE_EMPTY) {
-               rc = sleep_thread(common);
-               if (rc)
-                       return rc;
-       }
-
-       /* Queue a request to read a Bulk-only CBW */
-       set_bulk_out_req_length(common, bh, US_BULK_CB_WRAP_LEN);
-       if (!start_out_transfer(common, bh))
-               /* Don't know what to do if common->fsg is NULL */
-               return -EIO;
-
-       /*
-        * We will drain the buffer in software, which means we
-        * can reuse it for the next filling.  No need to advance
-        * next_buffhd_to_fill.
-        */
-
-       /* Wait for the CBW to arrive */
-       while (bh->state != BUF_STATE_FULL) {
-               rc = sleep_thread(common);
-               if (rc)
-                       return rc;
-       }
-       smp_rmb();
-       rc = fsg_is_set(common) ? received_cbw(common->fsg, bh) : -EIO;
-       bh->state = BUF_STATE_EMPTY;
-
-       return rc;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static int alloc_request(struct fsg_common *common, struct usb_ep *ep,
-               struct usb_request **preq)
-{
-       *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
-       if (*preq)
-               return 0;
-       ERROR(common, "can't allocate request for %s\n", ep->name);
-       return -ENOMEM;
-}
-
-/* Reset interface setting and re-init endpoint state (toggle etc). */
-static int do_set_interface(struct fsg_common *common, struct fsg_dev *new_fsg)
-{
-       struct fsg_dev *fsg;
-       int i, rc = 0;
-
-       if (common->running)
-               DBG(common, "reset interface\n");
-
-reset:
-       /* Deallocate the requests */
-       if (common->fsg) {
-               fsg = common->fsg;
-
-               for (i = 0; i < fsg_num_buffers; ++i) {
-                       struct fsg_buffhd *bh = &common->buffhds[i];
-
-                       if (bh->inreq) {
-                               usb_ep_free_request(fsg->bulk_in, bh->inreq);
-                               bh->inreq = NULL;
-                       }
-                       if (bh->outreq) {
-                               usb_ep_free_request(fsg->bulk_out, bh->outreq);
-                               bh->outreq = NULL;
-                       }
-               }
-
-               /* Disable the endpoints */
-               if (fsg->bulk_in_enabled) {
-                       usb_ep_disable(fsg->bulk_in);
-                       fsg->bulk_in_enabled = 0;
-               }
-               if (fsg->bulk_out_enabled) {
-                       usb_ep_disable(fsg->bulk_out);
-                       fsg->bulk_out_enabled = 0;
-               }
-
-               common->fsg = NULL;
-               wake_up(&common->fsg_wait);
-       }
-
-       common->running = 0;
-       if (!new_fsg || rc)
-               return rc;
-
-       common->fsg = new_fsg;
-       fsg = common->fsg;
-
-       /* Enable the endpoints */
-       rc = config_ep_by_speed(common->gadget, &(fsg->function), fsg->bulk_in);
-       if (rc)
-               goto reset;
-       rc = usb_ep_enable(fsg->bulk_in);
-       if (rc)
-               goto reset;
-       fsg->bulk_in->driver_data = common;
-       fsg->bulk_in_enabled = 1;
-
-       rc = config_ep_by_speed(common->gadget, &(fsg->function),
-                               fsg->bulk_out);
-       if (rc)
-               goto reset;
-       rc = usb_ep_enable(fsg->bulk_out);
-       if (rc)
-               goto reset;
-       fsg->bulk_out->driver_data = common;
-       fsg->bulk_out_enabled = 1;
-       common->bulk_out_maxpacket = usb_endpoint_maxp(fsg->bulk_out->desc);
-       clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
-
-       /* Allocate the requests */
-       for (i = 0; i < fsg_num_buffers; ++i) {
-               struct fsg_buffhd       *bh = &common->buffhds[i];
-
-               rc = alloc_request(common, fsg->bulk_in, &bh->inreq);
-               if (rc)
-                       goto reset;
-               rc = alloc_request(common, fsg->bulk_out, &bh->outreq);
-               if (rc)
-                       goto reset;
-               bh->inreq->buf = bh->outreq->buf = bh->buf;
-               bh->inreq->context = bh->outreq->context = bh;
-               bh->inreq->complete = bulk_in_complete;
-               bh->outreq->complete = bulk_out_complete;
-       }
-
-       common->running = 1;
-       for (i = 0; i < common->nluns; ++i)
-               common->luns[i].unit_attention_data = SS_RESET_OCCURRED;
-       return rc;
-}
-
-
-/****************************** ALT CONFIGS ******************************/
-
-static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
-{
-       struct fsg_dev *fsg = fsg_from_func(f);
-       fsg->common->new_fsg = fsg;
-       raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
-       return USB_GADGET_DELAYED_STATUS;
-}
-
-static void fsg_disable(struct usb_function *f)
-{
-       struct fsg_dev *fsg = fsg_from_func(f);
-       fsg->common->new_fsg = NULL;
-       raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static void handle_exception(struct fsg_common *common)
-{
-       siginfo_t               info;
-       int                     i;
-       struct fsg_buffhd       *bh;
-       enum fsg_state          old_state;
-       struct fsg_lun          *curlun;
-       unsigned int            exception_req_tag;
-
-       /*
-        * Clear the existing signals.  Anything but SIGUSR1 is converted
-        * into a high-priority EXIT exception.
-        */
-       for (;;) {
-               int sig =
-                       dequeue_signal_lock(current, &current->blocked, &info);
-               if (!sig)
-                       break;
-               if (sig != SIGUSR1) {
-                       if (common->state < FSG_STATE_EXIT)
-                               DBG(common, "Main thread exiting on signal\n");
-                       raise_exception(common, FSG_STATE_EXIT);
-               }
-       }
-
-       /* Cancel all the pending transfers */
-       if (likely(common->fsg)) {
-               for (i = 0; i < fsg_num_buffers; ++i) {
-                       bh = &common->buffhds[i];
-                       if (bh->inreq_busy)
-                               usb_ep_dequeue(common->fsg->bulk_in, bh->inreq);
-                       if (bh->outreq_busy)
-                               usb_ep_dequeue(common->fsg->bulk_out,
-                                              bh->outreq);
-               }
-
-               /* Wait until everything is idle */
-               for (;;) {
-                       int num_active = 0;
-                       for (i = 0; i < fsg_num_buffers; ++i) {
-                               bh = &common->buffhds[i];
-                               num_active += bh->inreq_busy + bh->outreq_busy;
-                       }
-                       if (num_active == 0)
-                               break;
-                       if (sleep_thread(common))
-                               return;
-               }
-
-               /* Clear out the controller's fifos */
-               if (common->fsg->bulk_in_enabled)
-                       usb_ep_fifo_flush(common->fsg->bulk_in);
-               if (common->fsg->bulk_out_enabled)
-                       usb_ep_fifo_flush(common->fsg->bulk_out);
-       }
-
-       /*
-        * Reset the I/O buffer states and pointers, the SCSI
-        * state, and the exception.  Then invoke the handler.
-        */
-       spin_lock_irq(&common->lock);
-
-       for (i = 0; i < fsg_num_buffers; ++i) {
-               bh = &common->buffhds[i];
-               bh->state = BUF_STATE_EMPTY;
-       }
-       common->next_buffhd_to_fill = &common->buffhds[0];
-       common->next_buffhd_to_drain = &common->buffhds[0];
-       exception_req_tag = common->exception_req_tag;
-       old_state = common->state;
-
-       if (old_state == FSG_STATE_ABORT_BULK_OUT)
-               common->state = FSG_STATE_STATUS_PHASE;
-       else {
-               for (i = 0; i < common->nluns; ++i) {
-                       curlun = &common->luns[i];
-                       curlun->prevent_medium_removal = 0;
-                       curlun->sense_data = SS_NO_SENSE;
-                       curlun->unit_attention_data = SS_NO_SENSE;
-                       curlun->sense_data_info = 0;
-                       curlun->info_valid = 0;
-               }
-               common->state = FSG_STATE_IDLE;
-       }
-       spin_unlock_irq(&common->lock);
-
-       /* Carry out any extra actions required for the exception */
-       switch (old_state) {
-       case FSG_STATE_ABORT_BULK_OUT:
-               send_status(common);
-               spin_lock_irq(&common->lock);
-               if (common->state == FSG_STATE_STATUS_PHASE)
-                       common->state = FSG_STATE_IDLE;
-               spin_unlock_irq(&common->lock);
-               break;
-
-       case FSG_STATE_RESET:
-               /*
-                * In case we were forced against our will to halt a
-                * bulk endpoint, clear the halt now.  (The SuperH UDC
-                * requires this.)
-                */
-               if (!fsg_is_set(common))
-                       break;
-               if (test_and_clear_bit(IGNORE_BULK_OUT,
-                                      &common->fsg->atomic_bitflags))
-                       usb_ep_clear_halt(common->fsg->bulk_in);
-
-               if (common->ep0_req_tag == exception_req_tag)
-                       ep0_queue(common);      /* Complete the status stage */
-
-               /*
-                * Technically this should go here, but it would only be
-                * a waste of time.  Ditto for the INTERFACE_CHANGE and
-                * CONFIG_CHANGE cases.
-                */
-               /* for (i = 0; i < common->nluns; ++i) */
-               /*      common->luns[i].unit_attention_data = */
-               /*              SS_RESET_OCCURRED;  */
-               break;
-
-       case FSG_STATE_CONFIG_CHANGE:
-               do_set_interface(common, common->new_fsg);
-               if (common->new_fsg)
-                       usb_composite_setup_continue(common->cdev);
-               break;
-
-       case FSG_STATE_EXIT:
-       case FSG_STATE_TERMINATED:
-               do_set_interface(common, NULL);         /* Free resources */
-               spin_lock_irq(&common->lock);
-               common->state = FSG_STATE_TERMINATED;   /* Stop the thread */
-               spin_unlock_irq(&common->lock);
-               break;
-
-       case FSG_STATE_INTERFACE_CHANGE:
-       case FSG_STATE_DISCONNECT:
-       case FSG_STATE_COMMAND_PHASE:
-       case FSG_STATE_DATA_PHASE:
-       case FSG_STATE_STATUS_PHASE:
-       case FSG_STATE_IDLE:
-               break;
-       }
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static int fsg_main_thread(void *common_)
-{
-       struct fsg_common       *common = common_;
-
-       /*
-        * Allow the thread to be killed by a signal, but set the signal mask
-        * to block everything but INT, TERM, KILL, and USR1.
-        */
-       allow_signal(SIGINT);
-       allow_signal(SIGTERM);
-       allow_signal(SIGKILL);
-       allow_signal(SIGUSR1);
-
-       /* Allow the thread to be frozen */
-       set_freezable();
-
-       /*
-        * Arrange for userspace references to be interpreted as kernel
-        * pointers.  That way we can pass a kernel pointer to a routine
-        * that expects a __user pointer and it will work okay.
-        */
-       set_fs(get_ds());
-
-       /* The main loop */
-       while (common->state != FSG_STATE_TERMINATED) {
-               if (exception_in_progress(common) || signal_pending(current)) {
-                       handle_exception(common);
-                       continue;
-               }
-
-               if (!common->running) {
-                       sleep_thread(common);
-                       continue;
-               }
-
-               if (get_next_command(common))
-                       continue;
-
-               spin_lock_irq(&common->lock);
-               if (!exception_in_progress(common))
-                       common->state = FSG_STATE_DATA_PHASE;
-               spin_unlock_irq(&common->lock);
-
-               if (do_scsi_command(common) || finish_reply(common))
-                       continue;
-
-               spin_lock_irq(&common->lock);
-               if (!exception_in_progress(common))
-                       common->state = FSG_STATE_STATUS_PHASE;
-               spin_unlock_irq(&common->lock);
-
-               if (send_status(common))
-                       continue;
-
-               spin_lock_irq(&common->lock);
-               if (!exception_in_progress(common))
-                       common->state = FSG_STATE_IDLE;
-               spin_unlock_irq(&common->lock);
-       }
-
-       spin_lock_irq(&common->lock);
-       common->thread_task = NULL;
-       spin_unlock_irq(&common->lock);
-
-       if (!common->ops || !common->ops->thread_exits
-        || common->ops->thread_exits(common) < 0) {
-               struct fsg_lun *curlun = common->luns;
-               unsigned i = common->nluns;
-
-               down_write(&common->filesem);
-               for (; i--; ++curlun) {
-                       if (!fsg_lun_is_open(curlun))
-                               continue;
-
-                       fsg_lun_close(curlun);
-                       curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT;
-               }
-               up_write(&common->filesem);
-       }
-
-       /* Let fsg_unbind() know the thread has exited */
-       complete_and_exit(&common->thread_notifier, 0);
-}
-
-
-/*************************** DEVICE ATTRIBUTES ***************************/
-
-static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
-static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, fsg_store_nofua);
-static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file);
-
-static struct device_attribute dev_attr_ro_cdrom =
-       __ATTR(ro, 0444, fsg_show_ro, NULL);
-static struct device_attribute dev_attr_file_nonremovable =
-       __ATTR(file, 0444, fsg_show_file, NULL);
-
-
-/****************************** FSG COMMON ******************************/
-
-static void fsg_common_release(struct kref *ref);
-
-static void fsg_lun_release(struct device *dev)
-{
-       /* Nothing needs to be done */
-}
-
-static inline void fsg_common_get(struct fsg_common *common)
-{
-       kref_get(&common->ref);
-}
-
-static inline void fsg_common_put(struct fsg_common *common)
-{
-       kref_put(&common->ref, fsg_common_release);
-}
-
-static struct fsg_common *fsg_common_init(struct fsg_common *common,
-                                         struct usb_composite_dev *cdev,
-                                         struct fsg_config *cfg)
-{
-       struct usb_gadget *gadget = cdev->gadget;
-       struct fsg_buffhd *bh;
-       struct fsg_lun *curlun;
-       struct fsg_lun_config *lcfg;
-       int nluns, i, rc;
-       char *pathbuf;
-
-       rc = fsg_num_buffers_validate();
-       if (rc != 0)
-               return ERR_PTR(rc);
-
-       /* Find out how many LUNs there should be */
-       nluns = cfg->nluns;
-       if (nluns < 1 || nluns > FSG_MAX_LUNS) {
-               dev_err(&gadget->dev, "invalid number of LUNs: %u\n", nluns);
-               return ERR_PTR(-EINVAL);
-       }
-
-       /* Allocate? */
-       if (!common) {
-               common = kzalloc(sizeof *common, GFP_KERNEL);
-               if (!common)
-                       return ERR_PTR(-ENOMEM);
-               common->free_storage_on_release = 1;
-       } else {
-               memset(common, 0, sizeof *common);
-               common->free_storage_on_release = 0;
-       }
-
-       common->buffhds = kcalloc(fsg_num_buffers,
-                                 sizeof *(common->buffhds), GFP_KERNEL);
-       if (!common->buffhds) {
-               if (common->free_storage_on_release)
-                       kfree(common);
-               return ERR_PTR(-ENOMEM);
-       }
-
-       common->ops = cfg->ops;
-       common->private_data = cfg->private_data;
-
-       common->gadget = gadget;
-       common->ep0 = gadget->ep0;
-       common->ep0req = cdev->req;
-       common->cdev = cdev;
-
-       /* Maybe allocate device-global string IDs, and patch descriptors */
-       if (fsg_strings[FSG_STRING_INTERFACE].id == 0) {
-               rc = usb_string_id(cdev);
-               if (unlikely(rc < 0))
-                       goto error_release;
-               fsg_strings[FSG_STRING_INTERFACE].id = rc;
-               fsg_intf_desc.iInterface = rc;
-       }
-
-       /*
-        * Create the LUNs, open their backing files, and register the
-        * LUN devices in sysfs.
-        */
-       curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL);
-       if (unlikely(!curlun)) {
-               rc = -ENOMEM;
-               goto error_release;
-       }
-       common->luns = curlun;
-
-       init_rwsem(&common->filesem);
-
-       for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun, ++lcfg) {
-               curlun->cdrom = !!lcfg->cdrom;
-               curlun->ro = lcfg->cdrom || lcfg->ro;
-               curlun->initially_ro = curlun->ro;
-               curlun->removable = lcfg->removable;
-               curlun->dev.release = fsg_lun_release;
-               curlun->dev.parent = &gadget->dev;
-               /* curlun->dev.driver = &fsg_driver.driver; XXX */
-               dev_set_drvdata(&curlun->dev, &common->filesem);
-               dev_set_name(&curlun->dev, "lun%d", i);
-
-               rc = device_register(&curlun->dev);
-               if (rc) {
-                       INFO(common, "failed to register LUN%d: %d\n", i, rc);
-                       common->nluns = i;
-                       put_device(&curlun->dev);
-                       goto error_release;
-               }
-
-               rc = device_create_file(&curlun->dev,
-                                       curlun->cdrom
-                                     ? &dev_attr_ro_cdrom
-                                     : &dev_attr_ro);
-               if (rc)
-                       goto error_luns;
-               rc = device_create_file(&curlun->dev,
-                                       curlun->removable
-                                     ? &dev_attr_file
-                                     : &dev_attr_file_nonremovable);
-               if (rc)
-                       goto error_luns;
-               rc = device_create_file(&curlun->dev, &dev_attr_nofua);
-               if (rc)
-                       goto error_luns;
-
-               if (lcfg->filename) {
-                       rc = fsg_lun_open(curlun, lcfg->filename);
-                       if (rc)
-                               goto error_luns;
-               } else if (!curlun->removable) {
-                       ERROR(common, "no file given for LUN%d\n", i);
-                       rc = -EINVAL;
-                       goto error_luns;
-               }
-       }
-       common->nluns = nluns;
-
-       /* Data buffers cyclic list */
-       bh = common->buffhds;
-       i = fsg_num_buffers;
-       goto buffhds_first_it;
-       do {
-               bh->next = bh + 1;
-               ++bh;
-buffhds_first_it:
-               bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
-               if (unlikely(!bh->buf)) {
-                       rc = -ENOMEM;
-                       goto error_release;
-               }
-       } while (--i);
-       bh->next = common->buffhds;
-
-       /* Prepare inquiryString */
-       if (cfg->release != 0xffff) {
-               i = cfg->release;
-       } else {
-               i = usb_gadget_controller_number(gadget);
-               if (i >= 0) {
-                       i = 0x0300 + i;
-               } else {
-                       WARNING(common, "controller '%s' not recognized\n",
-                               gadget->name);
-                       i = 0x0399;
-               }
-       }
-       snprintf(common->inquiry_string, sizeof common->inquiry_string,
-                "%-8s%-16s%04x", cfg->vendor_name ?: "Linux",
-                /* Assume product name dependent on the first LUN */
-                cfg->product_name ?: (common->luns->cdrom
-                                    ? "File-Stor Gadget"
-                                    : "File-CD Gadget"),
-                i);
-
-       /*
-        * Some peripheral controllers are known not to be able to
-        * halt bulk endpoints correctly.  If one of them is present,
-        * disable stalls.
-        */
-       common->can_stall = cfg->can_stall &&
-               !(gadget_is_at91(common->gadget));
-
-       spin_lock_init(&common->lock);
-       kref_init(&common->ref);
-
-       /* Tell the thread to start working */
-       common->thread_task =
-               kthread_create(fsg_main_thread, common, "file-storage");
-       if (IS_ERR(common->thread_task)) {
-               rc = PTR_ERR(common->thread_task);
-               goto error_release;
-       }
-       init_completion(&common->thread_notifier);
-       init_waitqueue_head(&common->fsg_wait);
-
-       /* Information */
-       INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
-       INFO(common, "Number of LUNs=%d\n", common->nluns);
-
-       pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
-       for (i = 0, nluns = common->nluns, curlun = common->luns;
-            i < nluns;
-            ++curlun, ++i) {
-               char *p = "(no medium)";
-               if (fsg_lun_is_open(curlun)) {
-                       p = "(error)";
-                       if (pathbuf) {
-                               p = d_path(&curlun->filp->f_path,
-                                          pathbuf, PATH_MAX);
-                               if (IS_ERR(p))
-                                       p = "(error)";
-                       }
-               }
-               LINFO(curlun, "LUN: %s%s%sfile: %s\n",
-                     curlun->removable ? "removable " : "",
-                     curlun->ro ? "read only " : "",
-                     curlun->cdrom ? "CD-ROM " : "",
-                     p);
-       }
-       kfree(pathbuf);
-
-       DBG(common, "I/O thread pid: %d\n", task_pid_nr(common->thread_task));
-
-       wake_up_process(common->thread_task);
-
-       return common;
-
-error_luns:
-       common->nluns = i + 1;
-error_release:
-       common->state = FSG_STATE_TERMINATED;   /* The thread is dead */
-       /* Call fsg_common_release() directly, ref might be not initialised. */
-       fsg_common_release(&common->ref);
-       return ERR_PTR(rc);
-}
-
-static void fsg_common_release(struct kref *ref)
-{
-       struct fsg_common *common = container_of(ref, struct fsg_common, ref);
-
-       /* If the thread isn't already dead, tell it to exit now */
-       if (common->state != FSG_STATE_TERMINATED) {
-               raise_exception(common, FSG_STATE_EXIT);
-               wait_for_completion(&common->thread_notifier);
-       }
-
-       if (likely(common->luns)) {
-               struct fsg_lun *lun = common->luns;
-               unsigned i = common->nluns;
-
-               /* In error recovery common->nluns may be zero. */
-               for (; i; --i, ++lun) {
-                       device_remove_file(&lun->dev, &dev_attr_nofua);
-                       device_remove_file(&lun->dev,
-                                          lun->cdrom
-                                        ? &dev_attr_ro_cdrom
-                                        : &dev_attr_ro);
-                       device_remove_file(&lun->dev,
-                                          lun->removable
-                                        ? &dev_attr_file
-                                        : &dev_attr_file_nonremovable);
-                       fsg_lun_close(lun);
-                       device_unregister(&lun->dev);
-               }
-
-               kfree(common->luns);
-       }
-
-       {
-               struct fsg_buffhd *bh = common->buffhds;
-               unsigned i = fsg_num_buffers;
-               do {
-                       kfree(bh->buf);
-               } while (++bh, --i);
-       }
-
-       kfree(common->buffhds);
-       if (common->free_storage_on_release)
-               kfree(common);
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
-{
-       struct fsg_dev          *fsg = fsg_from_func(f);
-       struct fsg_common       *common = fsg->common;
-
-       DBG(fsg, "unbind\n");
-       if (fsg->common->fsg == fsg) {
-               fsg->common->new_fsg = NULL;
-               raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
-               /* FIXME: make interruptible or killable somehow? */
-               wait_event(common->fsg_wait, common->fsg != fsg);
-       }
-
-       fsg_common_put(common);
-       usb_free_descriptors(fsg->function.descriptors);
-       usb_free_descriptors(fsg->function.hs_descriptors);
-       usb_free_descriptors(fsg->function.ss_descriptors);
-       kfree(fsg);
-}
-
-static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
-{
-       struct fsg_dev          *fsg = fsg_from_func(f);
-       struct usb_gadget       *gadget = c->cdev->gadget;
-       int                     i;
-       struct usb_ep           *ep;
-
-       fsg->gadget = gadget;
-
-       /* New interface */
-       i = usb_interface_id(c, f);
-       if (i < 0)
-               return i;
-       fsg_intf_desc.bInterfaceNumber = i;
-       fsg->interface_number = i;
-
-       /* Find all the endpoints we will use */
-       ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
-       if (!ep)
-               goto autoconf_fail;
-       ep->driver_data = fsg->common;  /* claim the endpoint */
-       fsg->bulk_in = ep;
-
-       ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
-       if (!ep)
-               goto autoconf_fail;
-       ep->driver_data = fsg->common;  /* claim the endpoint */
-       fsg->bulk_out = ep;
-
-       /* Copy descriptors */
-       f->descriptors = usb_copy_descriptors(fsg_fs_function);
-       if (unlikely(!f->descriptors))
-               return -ENOMEM;
-
-       if (gadget_is_dualspeed(gadget)) {
-               /* Assume endpoint addresses are the same for both speeds */
-               fsg_hs_bulk_in_desc.bEndpointAddress =
-                       fsg_fs_bulk_in_desc.bEndpointAddress;
-               fsg_hs_bulk_out_desc.bEndpointAddress =
-                       fsg_fs_bulk_out_desc.bEndpointAddress;
-               f->hs_descriptors = usb_copy_descriptors(fsg_hs_function);
-               if (unlikely(!f->hs_descriptors)) {
-                       usb_free_descriptors(f->descriptors);
-                       return -ENOMEM;
-               }
-       }
-
-       if (gadget_is_superspeed(gadget)) {
-               unsigned        max_burst;
-
-               /* Calculate bMaxBurst, we know packet size is 1024 */
-               max_burst = min_t(unsigned, FSG_BUFLEN / 1024, 15);
-
-               fsg_ss_bulk_in_desc.bEndpointAddress =
-                       fsg_fs_bulk_in_desc.bEndpointAddress;
-               fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
-
-               fsg_ss_bulk_out_desc.bEndpointAddress =
-                       fsg_fs_bulk_out_desc.bEndpointAddress;
-               fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
-
-               f->ss_descriptors = usb_copy_descriptors(fsg_ss_function);
-               if (unlikely(!f->ss_descriptors)) {
-                       usb_free_descriptors(f->hs_descriptors);
-                       usb_free_descriptors(f->descriptors);
-                       return -ENOMEM;
-               }
-       }
-
-       return 0;
-
-autoconf_fail:
-       ERROR(fsg, "unable to autoconfigure all endpoints\n");
-       return -ENOTSUPP;
-}
-
-
-/****************************** ADD FUNCTION ******************************/
-
-static struct usb_gadget_strings *fsg_strings_array[] = {
-       &fsg_stringtab,
-       NULL,
-};
-
-static int fsg_bind_config(struct usb_composite_dev *cdev,
-                          struct usb_configuration *c,
-                          struct fsg_common *common)
-{
-       struct fsg_dev *fsg;
-       int rc;
-
-       fsg = kzalloc(sizeof *fsg, GFP_KERNEL);
-       if (unlikely(!fsg))
-               return -ENOMEM;
-
-       fsg->function.name        = FSG_DRIVER_DESC;
-       fsg->function.strings     = fsg_strings_array;
-       fsg->function.bind        = fsg_bind;
-       fsg->function.unbind      = fsg_unbind;
-       fsg->function.setup       = fsg_setup;
-       fsg->function.set_alt     = fsg_set_alt;
-       fsg->function.disable     = fsg_disable;
-
-       fsg->common               = common;
-       /*
-        * Our caller holds a reference to common structure so we
-        * don't have to be worry about it being freed until we return
-        * from this function.  So instead of incrementing counter now
-        * and decrement in error recovery we increment it only when
-        * call to usb_add_function() was successful.
-        */
-
-       rc = usb_add_function(c, &fsg->function);
-       if (unlikely(rc))
-               kfree(fsg);
-       else
-               fsg_common_get(fsg->common);
-       return rc;
-}
-
-
-/************************* Module parameters *************************/
-
-struct fsg_module_parameters {
-       char            *file[FSG_MAX_LUNS];
-       bool            ro[FSG_MAX_LUNS];
-       bool            removable[FSG_MAX_LUNS];
-       bool            cdrom[FSG_MAX_LUNS];
-       bool            nofua[FSG_MAX_LUNS];
-
-       unsigned int    file_count, ro_count, removable_count, cdrom_count;
-       unsigned int    nofua_count;
-       unsigned int    luns;   /* nluns */
-       bool            stall;  /* can_stall */
-};
-
-#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc)      \
-       module_param_array_named(prefix ## name, params.name, type,     \
-                                &prefix ## params.name ## _count,      \
-                                S_IRUGO);                              \
-       MODULE_PARM_DESC(prefix ## name, desc)
-
-#define _FSG_MODULE_PARAM(prefix, params, name, type, desc)            \
-       module_param_named(prefix ## name, params.name, type,           \
-                          S_IRUGO);                                    \
-       MODULE_PARM_DESC(prefix ## name, desc)
-
-#define FSG_MODULE_PARAMETERS(prefix, params)                          \
-       _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp,            \
-                               "names of backing files or devices");   \
-       _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool,               \
-                               "true to force read-only");             \
-       _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool,        \
-                               "true to simulate removable media");    \
-       _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool,            \
-                               "true to simulate CD-ROM instead of disk"); \
-       _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool,            \
-                               "true to ignore SCSI WRITE(10,12) FUA bit"); \
-       _FSG_MODULE_PARAM(prefix, params, luns, uint,                   \
-                         "number of LUNs");                            \
-       _FSG_MODULE_PARAM(prefix, params, stall, bool,                  \
-                         "false to prevent bulk stalls")
-
-static void
-fsg_config_from_params(struct fsg_config *cfg,
-                      const struct fsg_module_parameters *params)
-{
-       struct fsg_lun_config *lun;
-       unsigned i;
-
-       /* Configure LUNs */
-       cfg->nluns =
-               min(params->luns ?: (params->file_count ?: 1u),
-                   (unsigned)FSG_MAX_LUNS);
-       for (i = 0, lun = cfg->luns; i < cfg->nluns; ++i, ++lun) {
-               lun->ro = !!params->ro[i];
-               lun->cdrom = !!params->cdrom[i];
-               lun->removable = !!params->removable[i];
-               lun->filename =
-                       params->file_count > i && params->file[i][0]
-                       ? params->file[i]
-                       : 0;
-       }
-
-       /* Let MSF use defaults */
-       cfg->vendor_name = 0;
-       cfg->product_name = 0;
-       cfg->release = 0xffff;
-
-       cfg->ops = NULL;
-       cfg->private_data = NULL;
-
-       /* Finalise */
-       cfg->can_stall = params->stall;
-}
-
-static inline struct fsg_common *
-fsg_common_from_params(struct fsg_common *common,
-                      struct usb_composite_dev *cdev,
-                      const struct fsg_module_parameters *params)
-       __attribute__((unused));
-static inline struct fsg_common *
-fsg_common_from_params(struct fsg_common *common,
-                      struct usb_composite_dev *cdev,
-                      const struct fsg_module_parameters *params)
-{
-       struct fsg_config cfg;
-       fsg_config_from_params(&cfg, params);
-       return fsg_common_init(common, cdev, &cfg);
-}
diff --git a/drivers/staging/ccg/f_rndis.c b/drivers/staging/ccg/f_rndis.c
deleted file mode 100644 (file)
index b1681e4..0000000
+++ /dev/null
@@ -1,918 +0,0 @@
-/*
- * f_rndis.c -- RNDIS link function driver
- *
- * Copyright (C) 2003-2005,2008 David Brownell
- * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
- * Copyright (C) 2008 Nokia Corporation
- * Copyright (C) 2009 Samsung Electronics
- *                    Author: Michal Nazarewicz (mina86@mina86.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.
- */
-
-/* #define VERBOSE_DEBUG */
-
-#include <linux/slab.h>
-#include <linux/kernel.h>
-#include <linux/device.h>
-#include <linux/etherdevice.h>
-
-#include <linux/atomic.h>
-
-#include "u_ether.h"
-#include "rndis.h"
-
-
-/*
- * This function is an RNDIS Ethernet port -- a Microsoft protocol that's
- * been promoted instead of the standard CDC Ethernet.  The published RNDIS
- * spec is ambiguous, incomplete, and needlessly complex.  Variants such as
- * ActiveSync have even worse status in terms of specification.
- *
- * In short:  it's a protocol controlled by (and for) Microsoft, not for an
- * Open ecosystem or markets.  Linux supports it *only* because Microsoft
- * doesn't support the CDC Ethernet standard.
- *
- * The RNDIS data transfer model is complex, with multiple Ethernet packets
- * per USB message, and out of band data.  The control model is built around
- * what's essentially an "RNDIS RPC" protocol.  It's all wrapped in a CDC ACM
- * (modem, not Ethernet) veneer, with those ACM descriptors being entirely
- * useless (they're ignored).  RNDIS expects to be the only function in its
- * configuration, so it's no real help if you need composite devices; and
- * it expects to be the first configuration too.
- *
- * There is a single technical advantage of RNDIS over CDC Ethernet, if you
- * discount the fluff that its RPC can be made to deliver: it doesn't need
- * a NOP altsetting for the data interface.  That lets it work on some of the
- * "so smart it's stupid" hardware which takes over configuration changes
- * from the software, and adds restrictions like "no altsettings".
- *
- * Unfortunately MSFT's RNDIS drivers are buggy.  They hang or oops, and
- * have all sorts of contrary-to-specification oddities that can prevent
- * them from working sanely.  Since bugfixes (or accurate specs, letting
- * Linux work around those bugs) are unlikely to ever come from MSFT, you
- * may want to avoid using RNDIS on purely operational grounds.
- *
- * Omissions from the RNDIS 1.0 specification include:
- *
- *   - Power management ... references data that's scattered around lots
- *     of other documentation, which is incorrect/incomplete there too.
- *
- *   - There are various undocumented protocol requirements, like the need
- *     to send garbage in some control-OUT messages.
- *
- *   - MS-Windows drivers sometimes emit undocumented requests.
- */
-
-struct f_rndis {
-       struct gether                   port;
-       u8                              ctrl_id, data_id;
-       u8                              ethaddr[ETH_ALEN];
-       u32                             vendorID;
-       const char                      *manufacturer;
-       int                             config;
-
-       struct usb_ep                   *notify;
-       struct usb_request              *notify_req;
-       atomic_t                        notify_count;
-};
-
-static inline struct f_rndis *func_to_rndis(struct usb_function *f)
-{
-       return container_of(f, struct f_rndis, port.func);
-}
-
-/* peak (theoretical) bulk transfer rate in bits-per-second */
-static unsigned int bitrate(struct usb_gadget *g)
-{
-       if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
-               return 13 * 1024 * 8 * 1000 * 8;
-       else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
-               return 13 * 512 * 8 * 1000 * 8;
-       else
-               return 19 * 64 * 1 * 1000 * 8;
-}
-
-/*-------------------------------------------------------------------------*/
-
-/*
- */
-
-#define LOG2_STATUS_INTERVAL_MSEC      5       /* 1 << 5 == 32 msec */
-#define STATUS_BYTECOUNT               8       /* 8 bytes data */
-
-
-/* interface descriptor: */
-
-static struct usb_interface_descriptor rndis_control_intf = {
-       .bLength =              sizeof rndis_control_intf,
-       .bDescriptorType =      USB_DT_INTERFACE,
-
-       /* .bInterfaceNumber = DYNAMIC */
-       /* status endpoint is optional; this could be patched later */
-       .bNumEndpoints =        1,
-       .bInterfaceClass =      USB_CLASS_COMM,
-       .bInterfaceSubClass =   USB_CDC_SUBCLASS_ACM,
-       .bInterfaceProtocol =   USB_CDC_ACM_PROTO_VENDOR,
-       /* .iInterface = DYNAMIC */
-};
-
-static struct usb_cdc_header_desc header_desc = {
-       .bLength =              sizeof header_desc,
-       .bDescriptorType =      USB_DT_CS_INTERFACE,
-       .bDescriptorSubType =   USB_CDC_HEADER_TYPE,
-
-       .bcdCDC =               cpu_to_le16(0x0110),
-};
-
-static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor = {
-       .bLength =              sizeof call_mgmt_descriptor,
-       .bDescriptorType =      USB_DT_CS_INTERFACE,
-       .bDescriptorSubType =   USB_CDC_CALL_MANAGEMENT_TYPE,
-
-       .bmCapabilities =       0x00,
-       .bDataInterface =       0x01,
-};
-
-static struct usb_cdc_acm_descriptor rndis_acm_descriptor = {
-       .bLength =              sizeof rndis_acm_descriptor,
-       .bDescriptorType =      USB_DT_CS_INTERFACE,
-       .bDescriptorSubType =   USB_CDC_ACM_TYPE,
-
-       .bmCapabilities =       0x00,
-};
-
-static struct usb_cdc_union_desc rndis_union_desc = {
-       .bLength =              sizeof(rndis_union_desc),
-       .bDescriptorType =      USB_DT_CS_INTERFACE,
-       .bDescriptorSubType =   USB_CDC_UNION_TYPE,
-       /* .bMasterInterface0 = DYNAMIC */
-       /* .bSlaveInterface0 =  DYNAMIC */
-};
-
-/* the data interface has two bulk endpoints */
-
-static struct usb_interface_descriptor rndis_data_intf = {
-       .bLength =              sizeof rndis_data_intf,
-       .bDescriptorType =      USB_DT_INTERFACE,
-
-       /* .bInterfaceNumber = DYNAMIC */
-       .bNumEndpoints =        2,
-       .bInterfaceClass =      USB_CLASS_CDC_DATA,
-       .bInterfaceSubClass =   0,
-       .bInterfaceProtocol =   0,
-       /* .iInterface = DYNAMIC */
-};
-
-
-static struct usb_interface_assoc_descriptor
-rndis_iad_descriptor = {
-       .bLength =              sizeof rndis_iad_descriptor,
-       .bDescriptorType =      USB_DT_INTERFACE_ASSOCIATION,
-
-       .bFirstInterface =      0, /* XXX, hardcoded */
-       .bInterfaceCount =      2,      // control + data
-       .bFunctionClass =       USB_CLASS_COMM,
-       .bFunctionSubClass =    USB_CDC_SUBCLASS_ETHERNET,
-       .bFunctionProtocol =    USB_CDC_PROTO_NONE,
-       /* .iFunction = DYNAMIC */
-};
-
-/* full speed support: */
-
-static struct usb_endpoint_descriptor fs_notify_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_IN,
-       .bmAttributes =         USB_ENDPOINT_XFER_INT,
-       .wMaxPacketSize =       cpu_to_le16(STATUS_BYTECOUNT),
-       .bInterval =            1 << LOG2_STATUS_INTERVAL_MSEC,
-};
-
-static struct usb_endpoint_descriptor fs_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_IN,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-};
-
-static struct usb_endpoint_descriptor fs_out_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_OUT,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-};
-
-static struct usb_descriptor_header *eth_fs_function[] = {
-       (struct usb_descriptor_header *) &rndis_iad_descriptor,
-
-       /* control interface matches ACM, not Ethernet */
-       (struct usb_descriptor_header *) &rndis_control_intf,
-       (struct usb_descriptor_header *) &header_desc,
-       (struct usb_descriptor_header *) &call_mgmt_descriptor,
-       (struct usb_descriptor_header *) &rndis_acm_descriptor,
-       (struct usb_descriptor_header *) &rndis_union_desc,
-       (struct usb_descriptor_header *) &fs_notify_desc,
-
-       /* data interface has no altsetting */
-       (struct usb_descriptor_header *) &rndis_data_intf,
-       (struct usb_descriptor_header *) &fs_in_desc,
-       (struct usb_descriptor_header *) &fs_out_desc,
-       NULL,
-};
-
-/* high speed support: */
-
-static struct usb_endpoint_descriptor hs_notify_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_IN,
-       .bmAttributes =         USB_ENDPOINT_XFER_INT,
-       .wMaxPacketSize =       cpu_to_le16(STATUS_BYTECOUNT),
-       .bInterval =            LOG2_STATUS_INTERVAL_MSEC + 4,
-};
-
-static struct usb_endpoint_descriptor hs_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_IN,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(512),
-};
-
-static struct usb_endpoint_descriptor hs_out_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_OUT,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(512),
-};
-
-static struct usb_descriptor_header *eth_hs_function[] = {
-       (struct usb_descriptor_header *) &rndis_iad_descriptor,
-
-       /* control interface matches ACM, not Ethernet */
-       (struct usb_descriptor_header *) &rndis_control_intf,
-       (struct usb_descriptor_header *) &header_desc,
-       (struct usb_descriptor_header *) &call_mgmt_descriptor,
-       (struct usb_descriptor_header *) &rndis_acm_descriptor,
-       (struct usb_descriptor_header *) &rndis_union_desc,
-       (struct usb_descriptor_header *) &hs_notify_desc,
-
-       /* data interface has no altsetting */
-       (struct usb_descriptor_header *) &rndis_data_intf,
-       (struct usb_descriptor_header *) &hs_in_desc,
-       (struct usb_descriptor_header *) &hs_out_desc,
-       NULL,
-};
-
-/* super speed support: */
-
-static struct usb_endpoint_descriptor ss_notify_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_IN,
-       .bmAttributes =         USB_ENDPOINT_XFER_INT,
-       .wMaxPacketSize =       cpu_to_le16(STATUS_BYTECOUNT),
-       .bInterval =            LOG2_STATUS_INTERVAL_MSEC + 4,
-};
-
-static struct usb_ss_ep_comp_descriptor ss_intr_comp_desc = {
-       .bLength =              sizeof ss_intr_comp_desc,
-       .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
-
-       /* the following 3 values can be tweaked if necessary */
-       /* .bMaxBurst =         0, */
-       /* .bmAttributes =      0, */
-       .wBytesPerInterval =    cpu_to_le16(STATUS_BYTECOUNT),
-};
-
-static struct usb_endpoint_descriptor ss_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_IN,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(1024),
-};
-
-static struct usb_endpoint_descriptor ss_out_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_OUT,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(1024),
-};
-
-static struct usb_ss_ep_comp_descriptor ss_bulk_comp_desc = {
-       .bLength =              sizeof ss_bulk_comp_desc,
-       .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
-
-       /* the following 2 values can be tweaked if necessary */
-       /* .bMaxBurst =         0, */
-       /* .bmAttributes =      0, */
-};
-
-static struct usb_descriptor_header *eth_ss_function[] = {
-       (struct usb_descriptor_header *) &rndis_iad_descriptor,
-
-       /* control interface matches ACM, not Ethernet */
-       (struct usb_descriptor_header *) &rndis_control_intf,
-       (struct usb_descriptor_header *) &header_desc,
-       (struct usb_descriptor_header *) &call_mgmt_descriptor,
-       (struct usb_descriptor_header *) &rndis_acm_descriptor,
-       (struct usb_descriptor_header *) &rndis_union_desc,
-       (struct usb_descriptor_header *) &ss_notify_desc,
-       (struct usb_descriptor_header *) &ss_intr_comp_desc,
-
-       /* data interface has no altsetting */
-       (struct usb_descriptor_header *) &rndis_data_intf,
-       (struct usb_descriptor_header *) &ss_in_desc,
-       (struct usb_descriptor_header *) &ss_bulk_comp_desc,
-       (struct usb_descriptor_header *) &ss_out_desc,
-       (struct usb_descriptor_header *) &ss_bulk_comp_desc,
-       NULL,
-};
-
-/* string descriptors: */
-
-static struct usb_string rndis_string_defs[] = {
-       [0].s = "RNDIS Communications Control",
-       [1].s = "RNDIS Ethernet Data",
-       [2].s = "RNDIS",
-       {  } /* end of list */
-};
-
-static struct usb_gadget_strings rndis_string_table = {
-       .language =             0x0409, /* en-us */
-       .strings =              rndis_string_defs,
-};
-
-static struct usb_gadget_strings *rndis_strings[] = {
-       &rndis_string_table,
-       NULL,
-};
-
-/*-------------------------------------------------------------------------*/
-
-static struct sk_buff *rndis_add_header(struct gether *port,
-                                       struct sk_buff *skb)
-{
-       struct sk_buff *skb2;
-
-       skb2 = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type));
-       if (skb2)
-               rndis_add_hdr(skb2);
-
-       dev_kfree_skb_any(skb);
-       return skb2;
-}
-
-static void rndis_response_available(void *_rndis)
-{
-       struct f_rndis                  *rndis = _rndis;
-       struct usb_request              *req = rndis->notify_req;
-       struct usb_composite_dev        *cdev = rndis->port.func.config->cdev;
-       __le32                          *data = req->buf;
-       int                             status;
-
-       if (atomic_inc_return(&rndis->notify_count) != 1)
-               return;
-
-       /* Send RNDIS RESPONSE_AVAILABLE notification; a
-        * USB_CDC_NOTIFY_RESPONSE_AVAILABLE "should" work too
-        *
-        * This is the only notification defined by RNDIS.
-        */
-       data[0] = cpu_to_le32(1);
-       data[1] = cpu_to_le32(0);
-
-       status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
-       if (status) {
-               atomic_dec(&rndis->notify_count);
-               DBG(cdev, "notify/0 --> %d\n", status);
-       }
-}
-
-static void rndis_response_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       struct f_rndis                  *rndis = req->context;
-       struct usb_composite_dev        *cdev = rndis->port.func.config->cdev;
-       int                             status = req->status;
-
-       /* after TX:
-        *  - USB_CDC_GET_ENCAPSULATED_RESPONSE (ep0/control)
-        *  - RNDIS_RESPONSE_AVAILABLE (status/irq)
-        */
-       switch (status) {
-       case -ECONNRESET:
-       case -ESHUTDOWN:
-               /* connection gone */
-               atomic_set(&rndis->notify_count, 0);
-               break;
-       default:
-               DBG(cdev, "RNDIS %s response error %d, %d/%d\n",
-                       ep->name, status,
-                       req->actual, req->length);
-               /* FALLTHROUGH */
-       case 0:
-               if (ep != rndis->notify)
-                       break;
-
-               /* handle multiple pending RNDIS_RESPONSE_AVAILABLE
-                * notifications by resending until we're done
-                */
-               if (atomic_dec_and_test(&rndis->notify_count))
-                       break;
-               status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
-               if (status) {
-                       atomic_dec(&rndis->notify_count);
-                       DBG(cdev, "notify/1 --> %d\n", status);
-               }
-               break;
-       }
-}
-
-static void rndis_command_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       struct f_rndis                  *rndis = req->context;
-       struct usb_composite_dev        *cdev = rndis->port.func.config->cdev;
-       int                             status;
-
-       /* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
-//     spin_lock(&dev->lock);
-       status = rndis_msg_parser(rndis->config, (u8 *) req->buf);
-       if (status < 0)
-               ERROR(cdev, "RNDIS command error %d, %d/%d\n",
-                       status, req->actual, req->length);
-//     spin_unlock(&dev->lock);
-}
-
-static int
-rndis_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
-{
-       struct f_rndis          *rndis = func_to_rndis(f);
-       struct usb_composite_dev *cdev = f->config->cdev;
-       struct usb_request      *req = cdev->req;
-       int                     value = -EOPNOTSUPP;
-       u16                     w_index = le16_to_cpu(ctrl->wIndex);
-       u16                     w_value = le16_to_cpu(ctrl->wValue);
-       u16                     w_length = le16_to_cpu(ctrl->wLength);
-
-       /* composite driver infrastructure handles everything except
-        * CDC class messages; interface activation uses set_alt().
-        */
-       switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
-
-       /* RNDIS uses the CDC command encapsulation mechanism to implement
-        * an RPC scheme, with much getting/setting of attributes by OID.
-        */
-       case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
-                       | USB_CDC_SEND_ENCAPSULATED_COMMAND:
-               if (w_value || w_index != rndis->ctrl_id)
-                       goto invalid;
-               /* read the request; process it later */
-               value = w_length;
-               req->complete = rndis_command_complete;
-               req->context = rndis;
-               /* later, rndis_response_available() sends a notification */
-               break;
-
-       case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
-                       | USB_CDC_GET_ENCAPSULATED_RESPONSE:
-               if (w_value || w_index != rndis->ctrl_id)
-                       goto invalid;
-               else {
-                       u8 *buf;
-                       u32 n;
-
-                       /* return the result */
-                       buf = rndis_get_next_response(rndis->config, &n);
-                       if (buf) {
-                               memcpy(req->buf, buf, n);
-                               req->complete = rndis_response_complete;
-                               req->context = rndis;
-                               rndis_free_response(rndis->config, buf);
-                               value = n;
-                       }
-                       /* else stalls ... spec says to avoid that */
-               }
-               break;
-
-       default:
-invalid:
-               VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
-                       ctrl->bRequestType, ctrl->bRequest,
-                       w_value, w_index, w_length);
-       }
-
-       /* respond with data transfer or status phase? */
-       if (value >= 0) {
-               DBG(cdev, "rndis req%02x.%02x v%04x i%04x l%d\n",
-                       ctrl->bRequestType, ctrl->bRequest,
-                       w_value, w_index, w_length);
-               req->zero = (value < w_length);
-               req->length = value;
-               value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
-               if (value < 0)
-                       ERROR(cdev, "rndis response on err %d\n", value);
-       }
-
-       /* device either stalls (value < 0) or reports success */
-       return value;
-}
-
-
-static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
-{
-       struct f_rndis          *rndis = func_to_rndis(f);
-       struct usb_composite_dev *cdev = f->config->cdev;
-
-       /* we know alt == 0 */
-
-       if (intf == rndis->ctrl_id) {
-               if (rndis->notify->driver_data) {
-                       VDBG(cdev, "reset rndis control %d\n", intf);
-                       usb_ep_disable(rndis->notify);
-               }
-               if (!rndis->notify->desc) {
-                       VDBG(cdev, "init rndis ctrl %d\n", intf);
-                       if (config_ep_by_speed(cdev->gadget, f, rndis->notify))
-                               goto fail;
-               }
-               usb_ep_enable(rndis->notify);
-               rndis->notify->driver_data = rndis;
-
-       } else if (intf == rndis->data_id) {
-               struct net_device       *net;
-
-               if (rndis->port.in_ep->driver_data) {
-                       DBG(cdev, "reset rndis\n");
-                       gether_disconnect(&rndis->port);
-               }
-
-               if (!rndis->port.in_ep->desc || !rndis->port.out_ep->desc) {
-                       DBG(cdev, "init rndis\n");
-                       if (config_ep_by_speed(cdev->gadget, f,
-                                              rndis->port.in_ep) ||
-                           config_ep_by_speed(cdev->gadget, f,
-                                              rndis->port.out_ep)) {
-                               rndis->port.in_ep->desc = NULL;
-                               rndis->port.out_ep->desc = NULL;
-                               goto fail;
-                       }
-               }
-
-               /* Avoid ZLPs; they can be troublesome. */
-               rndis->port.is_zlp_ok = false;
-
-               /* RNDIS should be in the "RNDIS uninitialized" state,
-                * either never activated or after rndis_uninit().
-                *
-                * We don't want data to flow here until a nonzero packet
-                * filter is set, at which point it enters "RNDIS data
-                * initialized" state ... but we do want the endpoints
-                * to be activated.  It's a strange little state.
-                *
-                * REVISIT the RNDIS gadget code has done this wrong for a
-                * very long time.  We need another call to the link layer
-                * code -- gether_updown(...bool) maybe -- to do it right.
-                */
-               rndis->port.cdc_filter = 0;
-
-               DBG(cdev, "RNDIS RX/TX early activation ... \n");
-               net = gether_connect(&rndis->port);
-               if (IS_ERR(net))
-                       return PTR_ERR(net);
-
-               rndis_set_param_dev(rndis->config, net,
-                               &rndis->port.cdc_filter);
-       } else
-               goto fail;
-
-       return 0;
-fail:
-       return -EINVAL;
-}
-
-static void rndis_disable(struct usb_function *f)
-{
-       struct f_rndis          *rndis = func_to_rndis(f);
-       struct usb_composite_dev *cdev = f->config->cdev;
-
-       if (!rndis->notify->driver_data)
-               return;
-
-       DBG(cdev, "rndis deactivated\n");
-
-       rndis_uninit(rndis->config);
-       gether_disconnect(&rndis->port);
-
-       usb_ep_disable(rndis->notify);
-       rndis->notify->driver_data = NULL;
-}
-
-/*-------------------------------------------------------------------------*/
-
-/*
- * This isn't quite the same mechanism as CDC Ethernet, since the
- * notification scheme passes less data, but the same set of link
- * states must be tested.  A key difference is that altsettings are
- * not used to tell whether the link should send packets or not.
- */
-
-static void rndis_open(struct gether *geth)
-{
-       struct f_rndis          *rndis = func_to_rndis(&geth->func);
-       struct usb_composite_dev *cdev = geth->func.config->cdev;
-
-       DBG(cdev, "%s\n", __func__);
-
-       rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3,
-                               bitrate(cdev->gadget) / 100);
-       rndis_signal_connect(rndis->config);
-}
-
-static void rndis_close(struct gether *geth)
-{
-       struct f_rndis          *rndis = func_to_rndis(&geth->func);
-
-       DBG(geth->func.config->cdev, "%s\n", __func__);
-
-       rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0);
-       rndis_signal_disconnect(rndis->config);
-}
-
-/*-------------------------------------------------------------------------*/
-
-/* ethernet function driver setup/binding */
-
-static int
-rndis_bind(struct usb_configuration *c, struct usb_function *f)
-{
-       struct usb_composite_dev *cdev = c->cdev;
-       struct f_rndis          *rndis = func_to_rndis(f);
-       int                     status;
-       struct usb_ep           *ep;
-
-       /* allocate instance-specific interface IDs */
-       status = usb_interface_id(c, f);
-       if (status < 0)
-               goto fail;
-       rndis->ctrl_id = status;
-       rndis_iad_descriptor.bFirstInterface = status;
-
-       rndis_control_intf.bInterfaceNumber = status;
-       rndis_union_desc.bMasterInterface0 = status;
-
-       status = usb_interface_id(c, f);
-       if (status < 0)
-               goto fail;
-       rndis->data_id = status;
-
-       rndis_data_intf.bInterfaceNumber = status;
-       rndis_union_desc.bSlaveInterface0 = status;
-
-       status = -ENODEV;
-
-       /* allocate instance-specific endpoints */
-       ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc);
-       if (!ep)
-               goto fail;
-       rndis->port.in_ep = ep;
-       ep->driver_data = cdev; /* claim */
-
-       ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc);
-       if (!ep)
-               goto fail;
-       rndis->port.out_ep = ep;
-       ep->driver_data = cdev; /* claim */
-
-       /* NOTE:  a status/notification endpoint is, strictly speaking,
-        * optional.  We don't treat it that way though!  It's simpler,
-        * and some newer profiles don't treat it as optional.
-        */
-       ep = usb_ep_autoconfig(cdev->gadget, &fs_notify_desc);
-       if (!ep)
-               goto fail;
-       rndis->notify = ep;
-       ep->driver_data = cdev; /* claim */
-
-       status = -ENOMEM;
-
-       /* allocate notification request and buffer */
-       rndis->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
-       if (!rndis->notify_req)
-               goto fail;
-       rndis->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL);
-       if (!rndis->notify_req->buf)
-               goto fail;
-       rndis->notify_req->length = STATUS_BYTECOUNT;
-       rndis->notify_req->context = rndis;
-       rndis->notify_req->complete = rndis_response_complete;
-
-       /* copy descriptors, and track endpoint copies */
-       f->descriptors = usb_copy_descriptors(eth_fs_function);
-       if (!f->descriptors)
-               goto fail;
-
-       /* support all relevant hardware speeds... we expect that when
-        * hardware is dual speed, all bulk-capable endpoints work at
-        * both speeds
-        */
-       if (gadget_is_dualspeed(c->cdev->gadget)) {
-               hs_in_desc.bEndpointAddress =
-                               fs_in_desc.bEndpointAddress;
-               hs_out_desc.bEndpointAddress =
-                               fs_out_desc.bEndpointAddress;
-               hs_notify_desc.bEndpointAddress =
-                               fs_notify_desc.bEndpointAddress;
-
-               /* copy descriptors, and track endpoint copies */
-               f->hs_descriptors = usb_copy_descriptors(eth_hs_function);
-               if (!f->hs_descriptors)
-                       goto fail;
-       }
-
-       if (gadget_is_superspeed(c->cdev->gadget)) {
-               ss_in_desc.bEndpointAddress =
-                               fs_in_desc.bEndpointAddress;
-               ss_out_desc.bEndpointAddress =
-                               fs_out_desc.bEndpointAddress;
-               ss_notify_desc.bEndpointAddress =
-                               fs_notify_desc.bEndpointAddress;
-
-               /* copy descriptors, and track endpoint copies */
-               f->ss_descriptors = usb_copy_descriptors(eth_ss_function);
-               if (!f->ss_descriptors)
-                       goto fail;
-       }
-
-       rndis->port.open = rndis_open;
-       rndis->port.close = rndis_close;
-
-       status = rndis_register(rndis_response_available, rndis);
-       if (status < 0)
-               goto fail;
-       rndis->config = status;
-
-       rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0);
-       rndis_set_host_mac(rndis->config, rndis->ethaddr);
-
-       if (rndis->manufacturer && rndis->vendorID &&
-                       rndis_set_param_vendor(rndis->config, rndis->vendorID,
-                                              rndis->manufacturer))
-               goto fail;
-
-       /* NOTE:  all that is done without knowing or caring about
-        * the network link ... which is unavailable to this code
-        * until we're activated via set_alt().
-        */
-
-       DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n",
-                       gadget_is_superspeed(c->cdev->gadget) ? "super" :
-                       gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
-                       rndis->port.in_ep->name, rndis->port.out_ep->name,
-                       rndis->notify->name);
-       return 0;
-
-fail:
-       if (gadget_is_superspeed(c->cdev->gadget) && f->ss_descriptors)
-               usb_free_descriptors(f->ss_descriptors);
-       if (gadget_is_dualspeed(c->cdev->gadget) && f->hs_descriptors)
-               usb_free_descriptors(f->hs_descriptors);
-       if (f->descriptors)
-               usb_free_descriptors(f->descriptors);
-
-       if (rndis->notify_req) {
-               kfree(rndis->notify_req->buf);
-               usb_ep_free_request(rndis->notify, rndis->notify_req);
-       }
-
-       /* we might as well release our claims on endpoints */
-       if (rndis->notify)
-               rndis->notify->driver_data = NULL;
-       if (rndis->port.out_ep->desc)
-               rndis->port.out_ep->driver_data = NULL;
-       if (rndis->port.in_ep->desc)
-               rndis->port.in_ep->driver_data = NULL;
-
-       ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
-
-       return status;
-}
-
-static void
-rndis_unbind(struct usb_configuration *c, struct usb_function *f)
-{
-       struct f_rndis          *rndis = func_to_rndis(f);
-
-       rndis_deregister(rndis->config);
-       rndis_exit();
-       rndis_string_defs[0].id = 0;
-
-       if (gadget_is_superspeed(c->cdev->gadget))
-               usb_free_descriptors(f->ss_descriptors);
-       if (gadget_is_dualspeed(c->cdev->gadget))
-               usb_free_descriptors(f->hs_descriptors);
-       usb_free_descriptors(f->descriptors);
-
-       kfree(rndis->notify_req->buf);
-       usb_ep_free_request(rndis->notify, rndis->notify_req);
-
-       kfree(rndis);
-}
-
-/* Some controllers can't support RNDIS ... */
-static inline bool can_support_rndis(struct usb_configuration *c)
-{
-       /* everything else is *presumably* fine */
-       return true;
-}
-
-int
-rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
-                               u32 vendorID, const char *manufacturer)
-{
-       struct f_rndis  *rndis;
-       int             status;
-
-       if (!can_support_rndis(c) || !ethaddr)
-               return -EINVAL;
-
-       /* maybe allocate device-global string IDs */
-       if (rndis_string_defs[0].id == 0) {
-
-               /* ... and setup RNDIS itself */
-               status = rndis_init();
-               if (status < 0)
-                       return status;
-
-               /* control interface label */
-               status = usb_string_id(c->cdev);
-               if (status < 0)
-                       return status;
-               rndis_string_defs[0].id = status;
-               rndis_control_intf.iInterface = status;
-
-               /* data interface label */
-               status = usb_string_id(c->cdev);
-               if (status < 0)
-                       return status;
-               rndis_string_defs[1].id = status;
-               rndis_data_intf.iInterface = status;
-
-               /* IAD iFunction label */
-               status = usb_string_id(c->cdev);
-               if (status < 0)
-                       return status;
-               rndis_string_defs[2].id = status;
-               rndis_iad_descriptor.iFunction = status;
-       }
-
-       /* allocate and initialize one new instance */
-       status = -ENOMEM;
-       rndis = kzalloc(sizeof *rndis, GFP_KERNEL);
-       if (!rndis)
-               goto fail;
-
-       memcpy(rndis->ethaddr, ethaddr, ETH_ALEN);
-       rndis->vendorID = vendorID;
-       rndis->manufacturer = manufacturer;
-
-       /* RNDIS activates when the host changes this filter */
-       rndis->port.cdc_filter = 0;
-
-       /* RNDIS has special (and complex) framing */
-       rndis->port.header_len = sizeof(struct rndis_packet_msg_type);
-       rndis->port.wrap = rndis_add_header;
-       rndis->port.unwrap = rndis_rm_hdr;
-
-       rndis->port.func.name = "rndis";
-       rndis->port.func.strings = rndis_strings;
-       /* descriptors are per-instance copies */
-       rndis->port.func.bind = rndis_bind;
-       rndis->port.func.unbind = rndis_unbind;
-       rndis->port.func.set_alt = rndis_set_alt;
-       rndis->port.func.setup = rndis_setup;
-       rndis->port.func.disable = rndis_disable;
-
-       status = usb_add_function(c, &rndis->port.func);
-       if (status) {
-               kfree(rndis);
-fail:
-               rndis_exit();
-       }
-       return status;
-}
diff --git a/drivers/staging/ccg/gadget_chips.h b/drivers/staging/ccg/gadget_chips.h
deleted file mode 100644 (file)
index 0ccca58..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * USB device controllers have lots of quirks.  Use these macros in
- * gadget drivers or other code that needs to deal with them, and which
- * autoconfigures instead of using early binding to the hardware.
- *
- * This SHOULD eventually work like the ARM mach_is_*() stuff, driven by
- * some config file that gets updated as new hardware is supported.
- * (And avoiding all runtime comparisons in typical one-choice configs!)
- *
- * NOTE:  some of these controller drivers may not be available yet.
- * Some are available on 2.4 kernels; several are available, but not
- * yet pushed in the 2.6 mainline tree.
- */
-
-#ifndef __GADGET_CHIPS_H
-#define __GADGET_CHIPS_H
-
-/*
- * NOTICE: the entries below are alphabetical and should be kept
- * that way.
- *
- * Always be sure to add new entries to the correct position or
- * accept the bashing later.
- *
- * If you have forgotten the alphabetical order let VIM/EMACS
- * do that for you.
- */
-#define gadget_is_amd5536udc(g)                (!strcmp("amd5536udc", (g)->name))
-#define gadget_is_at91(g)              (!strcmp("at91_udc", (g)->name))
-#define gadget_is_atmel_usba(g)                (!strcmp("atmel_usba_udc", (g)->name))
-#define gadget_is_bcm63xx(g)           (!strcmp("bcm63xx_udc", (g)->name))
-#define gadget_is_ci13xxx_msm(g)       (!strcmp("ci13xxx_msm", (g)->name))
-#define gadget_is_ci13xxx_pci(g)       (!strcmp("ci13xxx_pci", (g)->name))
-#define gadget_is_dummy(g)             (!strcmp("dummy_udc", (g)->name))
-#define gadget_is_dwc3(g)              (!strcmp("dwc3-gadget", (g)->name))
-#define gadget_is_fsl_qe(g)            (!strcmp("fsl_qe_udc", (g)->name))
-#define gadget_is_fsl_usb2(g)          (!strcmp("fsl-usb2-udc", (g)->name))
-#define gadget_is_goku(g)              (!strcmp("goku_udc", (g)->name))
-#define gadget_is_imx(g)               (!strcmp("imx_udc", (g)->name))
-#define gadget_is_langwell(g)          (!strcmp("langwell_udc", (g)->name))
-#define gadget_is_lpc32xx(g)           (!strcmp("lpc32xx_udc", (g)->name))
-#define gadget_is_m66592(g)            (!strcmp("m66592_udc", (g)->name))
-#define gadget_is_musbhdrc(g)          (!strcmp("musb-hdrc", (g)->name))
-#define gadget_is_net2272(g)           (!strcmp("net2272", (g)->name))
-#define gadget_is_net2280(g)           (!strcmp("net2280", (g)->name))
-#define gadget_is_omap(g)              (!strcmp("omap_udc", (g)->name))
-#define gadget_is_pch(g)               (!strcmp("pch_udc", (g)->name))
-#define gadget_is_pxa(g)               (!strcmp("pxa25x_udc", (g)->name))
-#define gadget_is_pxa27x(g)            (!strcmp("pxa27x_udc", (g)->name))
-#define gadget_is_r8a66597(g)          (!strcmp("r8a66597_udc", (g)->name))
-#define gadget_is_renesas_usbhs(g)     (!strcmp("renesas_usbhs_udc", (g)->name))
-#define gadget_is_s3c2410(g)           (!strcmp("s3c2410_udc", (g)->name))
-#define gadget_is_s3c_hsotg(g)         (!strcmp("s3c-hsotg", (g)->name))
-#define gadget_is_s3c_hsudc(g)         (!strcmp("s3c-hsudc", (g)->name))
-
-/**
- * usb_gadget_controller_number - support bcdDevice id convention
- * @gadget: the controller being driven
- *
- * Return a 2-digit BCD value associated with the peripheral controller,
- * suitable for use as part of a bcdDevice value, or a negative error code.
- *
- * NOTE:  this convention is purely optional, and has no meaning in terms of
- * any USB specification.  If you want to use a different convention in your
- * gadget driver firmware -- maybe a more formal revision ID -- feel free.
- *
- * Hosts see these bcdDevice numbers, and are allowed (but not encouraged!)
- * to change their behavior accordingly.  For example it might help avoiding
- * some chip bug.
- */
-static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
-{
-       if (gadget_is_net2280(gadget))
-               return 0x01;
-       else if (gadget_is_dummy(gadget))
-               return 0x02;
-       else if (gadget_is_pxa(gadget))
-               return 0x03;
-       else if (gadget_is_goku(gadget))
-               return 0x06;
-       else if (gadget_is_omap(gadget))
-               return 0x08;
-       else if (gadget_is_pxa27x(gadget))
-               return 0x11;
-       else if (gadget_is_s3c2410(gadget))
-               return 0x12;
-       else if (gadget_is_at91(gadget))
-               return 0x13;
-       else if (gadget_is_imx(gadget))
-               return 0x14;
-       else if (gadget_is_musbhdrc(gadget))
-               return 0x16;
-       else if (gadget_is_atmel_usba(gadget))
-               return 0x18;
-       else if (gadget_is_fsl_usb2(gadget))
-               return 0x19;
-       else if (gadget_is_amd5536udc(gadget))
-               return 0x20;
-       else if (gadget_is_m66592(gadget))
-               return 0x21;
-       else if (gadget_is_fsl_qe(gadget))
-               return 0x22;
-       else if (gadget_is_ci13xxx_pci(gadget))
-               return 0x23;
-       else if (gadget_is_langwell(gadget))
-               return 0x24;
-       else if (gadget_is_r8a66597(gadget))
-               return 0x25;
-       else if (gadget_is_s3c_hsotg(gadget))
-               return 0x26;
-       else if (gadget_is_pch(gadget))
-               return 0x27;
-       else if (gadget_is_ci13xxx_msm(gadget))
-               return 0x28;
-       else if (gadget_is_renesas_usbhs(gadget))
-               return 0x29;
-       else if (gadget_is_s3c_hsudc(gadget))
-               return 0x30;
-       else if (gadget_is_net2272(gadget))
-               return 0x31;
-       else if (gadget_is_dwc3(gadget))
-               return 0x32;
-       else if (gadget_is_lpc32xx(gadget))
-               return 0x33;
-       else if (gadget_is_bcm63xx(gadget))
-               return 0x34;
-
-       return -ENOENT;
-}
-
-
-/**
- * gadget_supports_altsettings - return true if altsettings work
- * @gadget: the gadget in question
- */
-static inline bool gadget_supports_altsettings(struct usb_gadget *gadget)
-{
-       /* PXA 21x/25x/26x has no altsettings at all */
-       if (gadget_is_pxa(gadget))
-               return false;
-
-       /* PXA 27x and 3xx have *broken* altsetting support */
-       if (gadget_is_pxa27x(gadget))
-               return false;
-
-       /* Everything else is *presumably* fine ... */
-       return true;
-}
-
-#endif /* __GADGET_CHIPS_H */
diff --git a/drivers/staging/ccg/ndis.h b/drivers/staging/ccg/ndis.h
deleted file mode 100644 (file)
index a19f72d..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * ndis.h
- *
- * ntddndis.h modified by Benedikt Spranger <b.spranger@pengutronix.de>
- *
- * Thanks to the cygwin development team,
- * espacially to Casper S. Hornstrup <chorns@users.sourceforge.net>
- *
- * THIS SOFTWARE IS NOT COPYRIGHTED
- *
- * This source code is offered for use in the public domain. You may
- * use, modify or distribute it freely.
- */
-
-#ifndef _LINUX_NDIS_H
-#define _LINUX_NDIS_H
-
-enum NDIS_DEVICE_POWER_STATE {
-       NdisDeviceStateUnspecified = 0,
-       NdisDeviceStateD0,
-       NdisDeviceStateD1,
-       NdisDeviceStateD2,
-       NdisDeviceStateD3,
-       NdisDeviceStateMaximum
-};
-
-struct NDIS_PM_WAKE_UP_CAPABILITIES {
-       enum NDIS_DEVICE_POWER_STATE  MinMagicPacketWakeUp;
-       enum NDIS_DEVICE_POWER_STATE  MinPatternWakeUp;
-       enum NDIS_DEVICE_POWER_STATE  MinLinkChangeWakeUp;
-};
-
-struct NDIS_PNP_CAPABILITIES {
-       __le32                                  Flags;
-       struct NDIS_PM_WAKE_UP_CAPABILITIES     WakeUpCapabilities;
-};
-
-struct NDIS_PM_PACKET_PATTERN {
-       __le32  Priority;
-       __le32  Reserved;
-       __le32  MaskSize;
-       __le32  PatternOffset;
-       __le32  PatternSize;
-       __le32  PatternFlags;
-};
-
-#endif /* _LINUX_NDIS_H */
diff --git a/drivers/staging/ccg/rndis.c b/drivers/staging/ccg/rndis.c
deleted file mode 100644 (file)
index d9297ee..0000000
+++ /dev/null
@@ -1,1175 +0,0 @@
-/*
- * RNDIS MSG parser
- *
- * Authors:    Benedikt Spranger, Pengutronix
- *             Robert Schwebel, Pengutronix
- *
- *              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 software was originally developed in conformance with
- *             Microsoft's Remote NDIS Specification License Agreement.
- *
- * 03/12/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
- *             Fixed message length bug in init_response
- *
- * 03/25/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
- *             Fixed rndis_rm_hdr length bug.
- *
- * Copyright (C) 2004 by David Brownell
- *             updates to merge with Linux 2.6, better match RNDIS spec
- */
-
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/init.h>
-#include <linux/list.h>
-#include <linux/proc_fs.h>
-#include <linux/slab.h>
-#include <linux/seq_file.h>
-#include <linux/netdevice.h>
-
-#include <asm/io.h>
-#include <asm/byteorder.h>
-#include <asm/unaligned.h>
-
-
-#undef VERBOSE_DEBUG
-
-#include "rndis.h"
-
-
-/* The driver for your USB chip needs to support ep0 OUT to work with
- * RNDIS, plus all three CDC Ethernet endpoints (interrupt not optional).
- *
- * Windows hosts need an INF file like Documentation/usb/linux.inf
- * and will be happier if you provide the host_addr module parameter.
- */
-
-#if 0
-static int rndis_debug = 0;
-module_param (rndis_debug, int, 0);
-MODULE_PARM_DESC (rndis_debug, "enable debugging");
-#else
-#define rndis_debug            0
-#endif
-
-#define RNDIS_MAX_CONFIGS      1
-
-
-static rndis_params rndis_per_dev_params[RNDIS_MAX_CONFIGS];
-
-/* Driver Version */
-static const __le32 rndis_driver_version = cpu_to_le32(1);
-
-/* Function Prototypes */
-static rndis_resp_t *rndis_add_response(int configNr, u32 length);
-
-
-/* supported OIDs */
-static const u32 oid_supported_list[] =
-{
-       /* the general stuff */
-       RNDIS_OID_GEN_SUPPORTED_LIST,
-       RNDIS_OID_GEN_HARDWARE_STATUS,
-       RNDIS_OID_GEN_MEDIA_SUPPORTED,
-       RNDIS_OID_GEN_MEDIA_IN_USE,
-       RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE,
-       RNDIS_OID_GEN_LINK_SPEED,
-       RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE,
-       RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE,
-       RNDIS_OID_GEN_VENDOR_ID,
-       RNDIS_OID_GEN_VENDOR_DESCRIPTION,
-       RNDIS_OID_GEN_VENDOR_DRIVER_VERSION,
-       RNDIS_OID_GEN_CURRENT_PACKET_FILTER,
-       RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE,
-       RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
-       RNDIS_OID_GEN_PHYSICAL_MEDIUM,
-
-       /* the statistical stuff */
-       RNDIS_OID_GEN_XMIT_OK,
-       RNDIS_OID_GEN_RCV_OK,
-       RNDIS_OID_GEN_XMIT_ERROR,
-       RNDIS_OID_GEN_RCV_ERROR,
-       RNDIS_OID_GEN_RCV_NO_BUFFER,
-#ifdef RNDIS_OPTIONAL_STATS
-       RNDIS_OID_GEN_DIRECTED_BYTES_XMIT,
-       RNDIS_OID_GEN_DIRECTED_FRAMES_XMIT,
-       RNDIS_OID_GEN_MULTICAST_BYTES_XMIT,
-       RNDIS_OID_GEN_MULTICAST_FRAMES_XMIT,
-       RNDIS_OID_GEN_BROADCAST_BYTES_XMIT,
-       RNDIS_OID_GEN_BROADCAST_FRAMES_XMIT,
-       RNDIS_OID_GEN_DIRECTED_BYTES_RCV,
-       RNDIS_OID_GEN_DIRECTED_FRAMES_RCV,
-       RNDIS_OID_GEN_MULTICAST_BYTES_RCV,
-       RNDIS_OID_GEN_MULTICAST_FRAMES_RCV,
-       RNDIS_OID_GEN_BROADCAST_BYTES_RCV,
-       RNDIS_OID_GEN_BROADCAST_FRAMES_RCV,
-       RNDIS_OID_GEN_RCV_CRC_ERROR,
-       RNDIS_OID_GEN_TRANSMIT_QUEUE_LENGTH,
-#endif /* RNDIS_OPTIONAL_STATS */
-
-       /* mandatory 802.3 */
-       /* the general stuff */
-       RNDIS_OID_802_3_PERMANENT_ADDRESS,
-       RNDIS_OID_802_3_CURRENT_ADDRESS,
-       RNDIS_OID_802_3_MULTICAST_LIST,
-       RNDIS_OID_802_3_MAC_OPTIONS,
-       RNDIS_OID_802_3_MAXIMUM_LIST_SIZE,
-
-       /* the statistical stuff */
-       RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT,
-       RNDIS_OID_802_3_XMIT_ONE_COLLISION,
-       RNDIS_OID_802_3_XMIT_MORE_COLLISIONS,
-#ifdef RNDIS_OPTIONAL_STATS
-       RNDIS_OID_802_3_XMIT_DEFERRED,
-       RNDIS_OID_802_3_XMIT_MAX_COLLISIONS,
-       RNDIS_OID_802_3_RCV_OVERRUN,
-       RNDIS_OID_802_3_XMIT_UNDERRUN,
-       RNDIS_OID_802_3_XMIT_HEARTBEAT_FAILURE,
-       RNDIS_OID_802_3_XMIT_TIMES_CRS_LOST,
-       RNDIS_OID_802_3_XMIT_LATE_COLLISIONS,
-#endif /* RNDIS_OPTIONAL_STATS */
-
-#ifdef RNDIS_PM
-       /* PM and wakeup are "mandatory" for USB, but the RNDIS specs
-        * don't say what they mean ... and the NDIS specs are often
-        * confusing and/or ambiguous in this context.  (That is, more
-        * so than their specs for the other OIDs.)
-        *
-        * FIXME someone who knows what these should do, please
-        * implement them!
-        */
-
-       /* power management */
-       OID_PNP_CAPABILITIES,
-       OID_PNP_QUERY_POWER,
-       OID_PNP_SET_POWER,
-
-#ifdef RNDIS_WAKEUP
-       /* wake up host */
-       OID_PNP_ENABLE_WAKE_UP,
-       OID_PNP_ADD_WAKE_UP_PATTERN,
-       OID_PNP_REMOVE_WAKE_UP_PATTERN,
-#endif /* RNDIS_WAKEUP */
-#endif /* RNDIS_PM */
-};
-
-
-/* NDIS Functions */
-static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
-                              unsigned buf_len, rndis_resp_t *r)
-{
-       int retval = -ENOTSUPP;
-       u32 length = 4; /* usually */
-       __le32 *outbuf;
-       int i, count;
-       rndis_query_cmplt_type *resp;
-       struct net_device *net;
-       struct rtnl_link_stats64 temp;
-       const struct rtnl_link_stats64 *stats;
-
-       if (!r) return -ENOMEM;
-       resp = (rndis_query_cmplt_type *)r->buf;
-
-       if (!resp) return -ENOMEM;
-
-       if (buf_len && rndis_debug > 1) {
-               pr_debug("query OID %08x value, len %d:\n", OID, buf_len);
-               for (i = 0; i < buf_len; i += 16) {
-                       pr_debug("%03d: %08x %08x %08x %08x\n", i,
-                               get_unaligned_le32(&buf[i]),
-                               get_unaligned_le32(&buf[i + 4]),
-                               get_unaligned_le32(&buf[i + 8]),
-                               get_unaligned_le32(&buf[i + 12]));
-               }
-       }
-
-       /* response goes here, right after the header */
-       outbuf = (__le32 *)&resp[1];
-       resp->InformationBufferOffset = cpu_to_le32(16);
-
-       net = rndis_per_dev_params[configNr].dev;
-       stats = dev_get_stats(net, &temp);
-
-       switch (OID) {
-
-       /* general oids (table 4-1) */
-
-       /* mandatory */
-       case RNDIS_OID_GEN_SUPPORTED_LIST:
-               pr_debug("%s: RNDIS_OID_GEN_SUPPORTED_LIST\n", __func__);
-               length = sizeof(oid_supported_list);
-               count  = length / sizeof(u32);
-               for (i = 0; i < count; i++)
-                       outbuf[i] = cpu_to_le32(oid_supported_list[i]);
-               retval = 0;
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_HARDWARE_STATUS:
-               pr_debug("%s: RNDIS_OID_GEN_HARDWARE_STATUS\n", __func__);
-               /* Bogus question!
-                * Hardware must be ready to receive high level protocols.
-                * BTW:
-                * reddite ergo quae sunt Caesaris Caesari
-                * et quae sunt Dei Deo!
-                */
-               *outbuf = cpu_to_le32(0);
-               retval = 0;
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_MEDIA_SUPPORTED:
-               pr_debug("%s: RNDIS_OID_GEN_MEDIA_SUPPORTED\n", __func__);
-               *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium);
-               retval = 0;
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_MEDIA_IN_USE:
-               pr_debug("%s: RNDIS_OID_GEN_MEDIA_IN_USE\n", __func__);
-               /* one medium, one transport... (maybe you do it better) */
-               *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium);
-               retval = 0;
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE:
-               pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
-               if (rndis_per_dev_params[configNr].dev) {
-                       *outbuf = cpu_to_le32(
-                               rndis_per_dev_params[configNr].dev->mtu);
-                       retval = 0;
-               }
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_LINK_SPEED:
-               if (rndis_debug > 1)
-                       pr_debug("%s: RNDIS_OID_GEN_LINK_SPEED\n", __func__);
-               if (rndis_per_dev_params[configNr].media_state
-                               == RNDIS_MEDIA_STATE_DISCONNECTED)
-                       *outbuf = cpu_to_le32(0);
-               else
-                       *outbuf = cpu_to_le32(
-                               rndis_per_dev_params[configNr].speed);
-               retval = 0;
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE:
-               pr_debug("%s: RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
-               if (rndis_per_dev_params[configNr].dev) {
-                       *outbuf = cpu_to_le32(
-                               rndis_per_dev_params[configNr].dev->mtu);
-                       retval = 0;
-               }
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE:
-               pr_debug("%s: RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
-               if (rndis_per_dev_params[configNr].dev) {
-                       *outbuf = cpu_to_le32(
-                               rndis_per_dev_params[configNr].dev->mtu);
-                       retval = 0;
-               }
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_VENDOR_ID:
-               pr_debug("%s: RNDIS_OID_GEN_VENDOR_ID\n", __func__);
-               *outbuf = cpu_to_le32(
-                       rndis_per_dev_params[configNr].vendorID);
-               retval = 0;
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_VENDOR_DESCRIPTION:
-               pr_debug("%s: RNDIS_OID_GEN_VENDOR_DESCRIPTION\n", __func__);
-               if (rndis_per_dev_params[configNr].vendorDescr) {
-                       length = strlen(rndis_per_dev_params[configNr].
-                                       vendorDescr);
-                       memcpy(outbuf,
-                               rndis_per_dev_params[configNr].vendorDescr,
-                               length);
-               } else {
-                       outbuf[0] = 0;
-               }
-               retval = 0;
-               break;
-
-       case RNDIS_OID_GEN_VENDOR_DRIVER_VERSION:
-               pr_debug("%s: RNDIS_OID_GEN_VENDOR_DRIVER_VERSION\n", __func__);
-               /* Created as LE */
-               *outbuf = rndis_driver_version;
-               retval = 0;
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_CURRENT_PACKET_FILTER:
-               pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
-               *outbuf = cpu_to_le32(*rndis_per_dev_params[configNr].filter);
-               retval = 0;
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE:
-               pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__);
-               *outbuf = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
-               retval = 0;
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_MEDIA_CONNECT_STATUS:
-               if (rndis_debug > 1)
-                       pr_debug("%s: RNDIS_OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
-               *outbuf = cpu_to_le32(rndis_per_dev_params[configNr]
-                                               .media_state);
-               retval = 0;
-               break;
-
-       case RNDIS_OID_GEN_PHYSICAL_MEDIUM:
-               pr_debug("%s: RNDIS_OID_GEN_PHYSICAL_MEDIUM\n", __func__);
-               *outbuf = cpu_to_le32(0);
-               retval = 0;
-               break;
-
-       /* The RNDIS specification is incomplete/wrong.   Some versions
-        * of MS-Windows expect OIDs that aren't specified there.  Other
-        * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
-        */
-       case RNDIS_OID_GEN_MAC_OPTIONS:         /* from WinME */
-               pr_debug("%s: RNDIS_OID_GEN_MAC_OPTIONS\n", __func__);
-               *outbuf = cpu_to_le32(
-                         RNDIS_MAC_OPTION_RECEIVE_SERIALIZED
-                       | RNDIS_MAC_OPTION_FULL_DUPLEX);
-               retval = 0;
-               break;
-
-       /* statistics OIDs (table 4-2) */
-
-       /* mandatory */
-       case RNDIS_OID_GEN_XMIT_OK:
-               if (rndis_debug > 1)
-                       pr_debug("%s: RNDIS_OID_GEN_XMIT_OK\n", __func__);
-               if (stats) {
-                       *outbuf = cpu_to_le32(stats->tx_packets
-                               - stats->tx_errors - stats->tx_dropped);
-                       retval = 0;
-               }
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_RCV_OK:
-               if (rndis_debug > 1)
-                       pr_debug("%s: RNDIS_OID_GEN_RCV_OK\n", __func__);
-               if (stats) {
-                       *outbuf = cpu_to_le32(stats->rx_packets
-                               - stats->rx_errors - stats->rx_dropped);
-                       retval = 0;
-               }
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_XMIT_ERROR:
-               if (rndis_debug > 1)
-                       pr_debug("%s: RNDIS_OID_GEN_XMIT_ERROR\n", __func__);
-               if (stats) {
-                       *outbuf = cpu_to_le32(stats->tx_errors);
-                       retval = 0;
-               }
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_RCV_ERROR:
-               if (rndis_debug > 1)
-                       pr_debug("%s: RNDIS_OID_GEN_RCV_ERROR\n", __func__);
-               if (stats) {
-                       *outbuf = cpu_to_le32(stats->rx_errors);
-                       retval = 0;
-               }
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_GEN_RCV_NO_BUFFER:
-               pr_debug("%s: RNDIS_OID_GEN_RCV_NO_BUFFER\n", __func__);
-               if (stats) {
-                       *outbuf = cpu_to_le32(stats->rx_dropped);
-                       retval = 0;
-               }
-               break;
-
-       /* ieee802.3 OIDs (table 4-3) */
-
-       /* mandatory */
-       case RNDIS_OID_802_3_PERMANENT_ADDRESS:
-               pr_debug("%s: RNDIS_OID_802_3_PERMANENT_ADDRESS\n", __func__);
-               if (rndis_per_dev_params[configNr].dev) {
-                       length = ETH_ALEN;
-                       memcpy(outbuf,
-                               rndis_per_dev_params[configNr].host_mac,
-                               length);
-                       retval = 0;
-               }
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_802_3_CURRENT_ADDRESS:
-               pr_debug("%s: RNDIS_OID_802_3_CURRENT_ADDRESS\n", __func__);
-               if (rndis_per_dev_params[configNr].dev) {
-                       length = ETH_ALEN;
-                       memcpy(outbuf,
-                               rndis_per_dev_params [configNr].host_mac,
-                               length);
-                       retval = 0;
-               }
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_802_3_MULTICAST_LIST:
-               pr_debug("%s: RNDIS_OID_802_3_MULTICAST_LIST\n", __func__);
-               /* Multicast base address only */
-               *outbuf = cpu_to_le32(0xE0000000);
-               retval = 0;
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_802_3_MAXIMUM_LIST_SIZE:
-               pr_debug("%s: RNDIS_OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
-               /* Multicast base address only */
-               *outbuf = cpu_to_le32(1);
-               retval = 0;
-               break;
-
-       case RNDIS_OID_802_3_MAC_OPTIONS:
-               pr_debug("%s: RNDIS_OID_802_3_MAC_OPTIONS\n", __func__);
-               *outbuf = cpu_to_le32(0);
-               retval = 0;
-               break;
-
-       /* ieee802.3 statistics OIDs (table 4-4) */
-
-       /* mandatory */
-       case RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT:
-               pr_debug("%s: RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__);
-               if (stats) {
-                       *outbuf = cpu_to_le32(stats->rx_frame_errors);
-                       retval = 0;
-               }
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_802_3_XMIT_ONE_COLLISION:
-               pr_debug("%s: RNDIS_OID_802_3_XMIT_ONE_COLLISION\n", __func__);
-               *outbuf = cpu_to_le32(0);
-               retval = 0;
-               break;
-
-       /* mandatory */
-       case RNDIS_OID_802_3_XMIT_MORE_COLLISIONS:
-               pr_debug("%s: RNDIS_OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
-               *outbuf = cpu_to_le32(0);
-               retval = 0;
-               break;
-
-       default:
-               pr_warning("%s: query unknown OID 0x%08X\n",
-                        __func__, OID);
-       }
-       if (retval < 0)
-               length = 0;
-
-       resp->InformationBufferLength = cpu_to_le32(length);
-       r->length = length + sizeof(*resp);
-       resp->MessageLength = cpu_to_le32(r->length);
-       return retval;
-}
-
-static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len,
-                            rndis_resp_t *r)
-{
-       rndis_set_cmplt_type *resp;
-       int i, retval = -ENOTSUPP;
-       struct rndis_params *params;
-
-       if (!r)
-               return -ENOMEM;
-       resp = (rndis_set_cmplt_type *)r->buf;
-       if (!resp)
-               return -ENOMEM;
-
-       if (buf_len && rndis_debug > 1) {
-               pr_debug("set OID %08x value, len %d:\n", OID, buf_len);
-               for (i = 0; i < buf_len; i += 16) {
-                       pr_debug("%03d: %08x %08x %08x %08x\n", i,
-                               get_unaligned_le32(&buf[i]),
-                               get_unaligned_le32(&buf[i + 4]),
-                               get_unaligned_le32(&buf[i + 8]),
-                               get_unaligned_le32(&buf[i + 12]));
-               }
-       }
-
-       params = &rndis_per_dev_params[configNr];
-       switch (OID) {
-       case RNDIS_OID_GEN_CURRENT_PACKET_FILTER:
-
-               /* these NDIS_PACKET_TYPE_* bitflags are shared with
-                * cdc_filter; it's not RNDIS-specific
-                * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
-                *      PROMISCUOUS, DIRECTED,
-                *      MULTICAST, ALL_MULTICAST, BROADCAST
-                */
-               *params->filter = (u16)get_unaligned_le32(buf);
-               pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER %08x\n",
-                       __func__, *params->filter);
-
-               /* this call has a significant side effect:  it's
-                * what makes the packet flow start and stop, like
-                * activating the CDC Ethernet altsetting.
-                */
-               retval = 0;
-               if (*params->filter) {
-                       params->state = RNDIS_DATA_INITIALIZED;
-                       netif_carrier_on(params->dev);
-                       if (netif_running(params->dev))
-                               netif_wake_queue(params->dev);
-               } else {
-                       params->state = RNDIS_INITIALIZED;
-                       netif_carrier_off(params->dev);
-                       netif_stop_queue(params->dev);
-               }
-               break;
-
-       case RNDIS_OID_802_3_MULTICAST_LIST:
-               /* I think we can ignore this */
-               pr_debug("%s: RNDIS_OID_802_3_MULTICAST_LIST\n", __func__);
-               retval = 0;
-               break;
-
-       default:
-               pr_warning("%s: set unknown OID 0x%08X, size %d\n",
-                        __func__, OID, buf_len);
-       }
-
-       return retval;
-}
-
-/*
- * Response Functions
- */
-
-static int rndis_init_response(int configNr, rndis_init_msg_type *buf)
-{
-       rndis_init_cmplt_type *resp;
-       rndis_resp_t *r;
-       struct rndis_params *params = rndis_per_dev_params + configNr;
-
-       if (!params->dev)
-               return -ENOTSUPP;
-
-       r = rndis_add_response(configNr, sizeof(rndis_init_cmplt_type));
-       if (!r)
-               return -ENOMEM;
-       resp = (rndis_init_cmplt_type *)r->buf;
-
-       resp->MessageType = cpu_to_le32(RNDIS_MSG_INIT_C);
-       resp->MessageLength = cpu_to_le32(52);
-       resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
-       resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
-       resp->MajorVersion = cpu_to_le32(RNDIS_MAJOR_VERSION);
-       resp->MinorVersion = cpu_to_le32(RNDIS_MINOR_VERSION);
-       resp->DeviceFlags = cpu_to_le32(RNDIS_DF_CONNECTIONLESS);
-       resp->Medium = cpu_to_le32(RNDIS_MEDIUM_802_3);
-       resp->MaxPacketsPerTransfer = cpu_to_le32(1);
-       resp->MaxTransferSize = cpu_to_le32(
-                 params->dev->mtu
-               + sizeof(struct ethhdr)
-               + sizeof(struct rndis_packet_msg_type)
-               + 22);
-       resp->PacketAlignmentFactor = cpu_to_le32(0);
-       resp->AFListOffset = cpu_to_le32(0);
-       resp->AFListSize = cpu_to_le32(0);
-
-       params->resp_avail(params->v);
-       return 0;
-}
-
-static int rndis_query_response(int configNr, rndis_query_msg_type *buf)
-{
-       rndis_query_cmplt_type *resp;
-       rndis_resp_t *r;
-       struct rndis_params *params = rndis_per_dev_params + configNr;
-
-       /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */
-       if (!params->dev)
-               return -ENOTSUPP;
-
-       /*
-        * we need more memory:
-        * gen_ndis_query_resp expects enough space for
-        * rndis_query_cmplt_type followed by data.
-        * oid_supported_list is the largest data reply
-        */
-       r = rndis_add_response(configNr,
-               sizeof(oid_supported_list) + sizeof(rndis_query_cmplt_type));
-       if (!r)
-               return -ENOMEM;
-       resp = (rndis_query_cmplt_type *)r->buf;
-
-       resp->MessageType = cpu_to_le32(RNDIS_MSG_QUERY_C);
-       resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
-
-       if (gen_ndis_query_resp(configNr, le32_to_cpu(buf->OID),
-                       le32_to_cpu(buf->InformationBufferOffset)
-                                       + 8 + (u8 *)buf,
-                       le32_to_cpu(buf->InformationBufferLength),
-                       r)) {
-               /* OID not supported */
-               resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
-               resp->MessageLength = cpu_to_le32(sizeof *resp);
-               resp->InformationBufferLength = cpu_to_le32(0);
-               resp->InformationBufferOffset = cpu_to_le32(0);
-       } else
-               resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
-
-       params->resp_avail(params->v);
-       return 0;
-}
-
-static int rndis_set_response(int configNr, rndis_set_msg_type *buf)
-{
-       u32 BufLength, BufOffset;
-       rndis_set_cmplt_type *resp;
-       rndis_resp_t *r;
-       struct rndis_params *params = rndis_per_dev_params + configNr;
-
-       r = rndis_add_response(configNr, sizeof(rndis_set_cmplt_type));
-       if (!r)
-               return -ENOMEM;
-       resp = (rndis_set_cmplt_type *)r->buf;
-
-       BufLength = le32_to_cpu(buf->InformationBufferLength);
-       BufOffset = le32_to_cpu(buf->InformationBufferOffset);
-
-#ifdef VERBOSE_DEBUG
-       pr_debug("%s: Length: %d\n", __func__, BufLength);
-       pr_debug("%s: Offset: %d\n", __func__, BufOffset);
-       pr_debug("%s: InfoBuffer: ", __func__);
-
-       for (i = 0; i < BufLength; i++) {
-               pr_debug("%02x ", *(((u8 *) buf) + i + 8 + BufOffset));
-       }
-
-       pr_debug("\n");
-#endif
-
-       resp->MessageType = cpu_to_le32(RNDIS_MSG_SET_C);
-       resp->MessageLength = cpu_to_le32(16);
-       resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
-       if (gen_ndis_set_resp(configNr, le32_to_cpu(buf->OID),
-                       ((u8 *)buf) + 8 + BufOffset, BufLength, r))
-               resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
-       else
-               resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
-
-       params->resp_avail(params->v);
-       return 0;
-}
-
-static int rndis_reset_response(int configNr, rndis_reset_msg_type *buf)
-{
-       rndis_reset_cmplt_type *resp;
-       rndis_resp_t *r;
-       struct rndis_params *params = rndis_per_dev_params + configNr;
-
-       r = rndis_add_response(configNr, sizeof(rndis_reset_cmplt_type));
-       if (!r)
-               return -ENOMEM;
-       resp = (rndis_reset_cmplt_type *)r->buf;
-
-       resp->MessageType = cpu_to_le32(RNDIS_MSG_RESET_C);
-       resp->MessageLength = cpu_to_le32(16);
-       resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
-       /* resent information */
-       resp->AddressingReset = cpu_to_le32(1);
-
-       params->resp_avail(params->v);
-       return 0;
-}
-
-static int rndis_keepalive_response(int configNr,
-                                   rndis_keepalive_msg_type *buf)
-{
-       rndis_keepalive_cmplt_type *resp;
-       rndis_resp_t *r;
-       struct rndis_params *params = rndis_per_dev_params + configNr;
-
-       /* host "should" check only in RNDIS_DATA_INITIALIZED state */
-
-       r = rndis_add_response(configNr, sizeof(rndis_keepalive_cmplt_type));
-       if (!r)
-               return -ENOMEM;
-       resp = (rndis_keepalive_cmplt_type *)r->buf;
-
-       resp->MessageType = cpu_to_le32(RNDIS_MSG_KEEPALIVE_C);
-       resp->MessageLength = cpu_to_le32(16);
-       resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
-       resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
-
-       params->resp_avail(params->v);
-       return 0;
-}
-
-
-/*
- * Device to Host Comunication
- */
-static int rndis_indicate_status_msg(int configNr, u32 status)
-{
-       rndis_indicate_status_msg_type *resp;
-       rndis_resp_t *r;
-       struct rndis_params *params = rndis_per_dev_params + configNr;
-
-       if (params->state == RNDIS_UNINITIALIZED)
-               return -ENOTSUPP;
-
-       r = rndis_add_response(configNr,
-                               sizeof(rndis_indicate_status_msg_type));
-       if (!r)
-               return -ENOMEM;
-       resp = (rndis_indicate_status_msg_type *)r->buf;
-
-       resp->MessageType = cpu_to_le32(RNDIS_MSG_INDICATE);
-       resp->MessageLength = cpu_to_le32(20);
-       resp->Status = cpu_to_le32(status);
-       resp->StatusBufferLength = cpu_to_le32(0);
-       resp->StatusBufferOffset = cpu_to_le32(0);
-
-       params->resp_avail(params->v);
-       return 0;
-}
-
-int rndis_signal_connect(int configNr)
-{
-       rndis_per_dev_params[configNr].media_state
-                       = RNDIS_MEDIA_STATE_CONNECTED;
-       return rndis_indicate_status_msg(configNr,
-                                         RNDIS_STATUS_MEDIA_CONNECT);
-}
-
-int rndis_signal_disconnect(int configNr)
-{
-       rndis_per_dev_params[configNr].media_state
-                       = RNDIS_MEDIA_STATE_DISCONNECTED;
-       return rndis_indicate_status_msg(configNr,
-                                         RNDIS_STATUS_MEDIA_DISCONNECT);
-}
-
-void rndis_uninit(int configNr)
-{
-       u8 *buf;
-       u32 length;
-
-       if (configNr >= RNDIS_MAX_CONFIGS)
-               return;
-       rndis_per_dev_params[configNr].state = RNDIS_UNINITIALIZED;
-
-       /* drain the response queue */
-       while ((buf = rndis_get_next_response(configNr, &length)))
-               rndis_free_response(configNr, buf);
-}
-
-void rndis_set_host_mac(int configNr, const u8 *addr)
-{
-       rndis_per_dev_params[configNr].host_mac = addr;
-}
-
-/*
- * Message Parser
- */
-int rndis_msg_parser(u8 configNr, u8 *buf)
-{
-       u32 MsgType, MsgLength;
-       __le32 *tmp;
-       struct rndis_params *params;
-
-       if (!buf)
-               return -ENOMEM;
-
-       tmp = (__le32 *)buf;
-       MsgType   = get_unaligned_le32(tmp++);
-       MsgLength = get_unaligned_le32(tmp++);
-
-       if (configNr >= RNDIS_MAX_CONFIGS)
-               return -ENOTSUPP;
-       params = &rndis_per_dev_params[configNr];
-
-       /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
-        * rx/tx statistics and link status, in addition to KEEPALIVE traffic
-        * and normal HC level polling to see if there's any IN traffic.
-        */
-
-       /* For USB: responses may take up to 10 seconds */
-       switch (MsgType) {
-       case RNDIS_MSG_INIT:
-               pr_debug("%s: RNDIS_MSG_INIT\n",
-                       __func__);
-               params->state = RNDIS_INITIALIZED;
-               return rndis_init_response(configNr,
-                                       (rndis_init_msg_type *)buf);
-
-       case RNDIS_MSG_HALT:
-               pr_debug("%s: RNDIS_MSG_HALT\n",
-                       __func__);
-               params->state = RNDIS_UNINITIALIZED;
-               if (params->dev) {
-                       netif_carrier_off(params->dev);
-                       netif_stop_queue(params->dev);
-               }
-               return 0;
-
-       case RNDIS_MSG_QUERY:
-               return rndis_query_response(configNr,
-                                       (rndis_query_msg_type *)buf);
-
-       case RNDIS_MSG_SET:
-               return rndis_set_response(configNr,
-                                       (rndis_set_msg_type *)buf);
-
-       case RNDIS_MSG_RESET:
-               pr_debug("%s: RNDIS_MSG_RESET\n",
-                       __func__);
-               return rndis_reset_response(configNr,
-                                       (rndis_reset_msg_type *)buf);
-
-       case RNDIS_MSG_KEEPALIVE:
-               /* For USB: host does this every 5 seconds */
-               if (rndis_debug > 1)
-                       pr_debug("%s: RNDIS_MSG_KEEPALIVE\n",
-                               __func__);
-               return rndis_keepalive_response(configNr,
-                                                (rndis_keepalive_msg_type *)
-                                                buf);
-
-       default:
-               /* At least Windows XP emits some undefined RNDIS messages.
-                * In one case those messages seemed to relate to the host
-                * suspending itself.
-                */
-               pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
-                       __func__, MsgType, MsgLength);
-               print_hex_dump_bytes(__func__, DUMP_PREFIX_OFFSET,
-                                    buf, MsgLength);
-               break;
-       }
-
-       return -ENOTSUPP;
-}
-
-int rndis_register(void (*resp_avail)(void *v), void *v)
-{
-       u8 i;
-
-       if (!resp_avail)
-               return -EINVAL;
-
-       for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
-               if (!rndis_per_dev_params[i].used) {
-                       rndis_per_dev_params[i].used = 1;
-                       rndis_per_dev_params[i].resp_avail = resp_avail;
-                       rndis_per_dev_params[i].v = v;
-                       pr_debug("%s: configNr = %d\n", __func__, i);
-                       return i;
-               }
-       }
-       pr_debug("failed\n");
-
-       return -ENODEV;
-}
-
-void rndis_deregister(int configNr)
-{
-       pr_debug("%s:\n", __func__);
-
-       if (configNr >= RNDIS_MAX_CONFIGS) return;
-       rndis_per_dev_params[configNr].used = 0;
-}
-
-int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter)
-{
-       pr_debug("%s:\n", __func__);
-       if (!dev)
-               return -EINVAL;
-       if (configNr >= RNDIS_MAX_CONFIGS) return -1;
-
-       rndis_per_dev_params[configNr].dev = dev;
-       rndis_per_dev_params[configNr].filter = cdc_filter;
-
-       return 0;
-}
-
-int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr)
-{
-       pr_debug("%s:\n", __func__);
-       if (!vendorDescr) return -1;
-       if (configNr >= RNDIS_MAX_CONFIGS) return -1;
-
-       rndis_per_dev_params[configNr].vendorID = vendorID;
-       rndis_per_dev_params[configNr].vendorDescr = vendorDescr;
-
-       return 0;
-}
-
-int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed)
-{
-       pr_debug("%s: %u %u\n", __func__, medium, speed);
-       if (configNr >= RNDIS_MAX_CONFIGS) return -1;
-
-       rndis_per_dev_params[configNr].medium = medium;
-       rndis_per_dev_params[configNr].speed = speed;
-
-       return 0;
-}
-
-void rndis_add_hdr(struct sk_buff *skb)
-{
-       struct rndis_packet_msg_type *header;
-
-       if (!skb)
-               return;
-       header = (void *)skb_push(skb, sizeof(*header));
-       memset(header, 0, sizeof *header);
-       header->MessageType = cpu_to_le32(RNDIS_MSG_PACKET);
-       header->MessageLength = cpu_to_le32(skb->len);
-       header->DataOffset = cpu_to_le32(36);
-       header->DataLength = cpu_to_le32(skb->len - sizeof(*header));
-}
-
-void rndis_free_response(int configNr, u8 *buf)
-{
-       rndis_resp_t *r;
-       struct list_head *act, *tmp;
-
-       list_for_each_safe(act, tmp,
-                       &(rndis_per_dev_params[configNr].resp_queue))
-       {
-               r = list_entry(act, rndis_resp_t, list);
-               if (r && r->buf == buf) {
-                       list_del(&r->list);
-                       kfree(r);
-               }
-       }
-}
-
-u8 *rndis_get_next_response(int configNr, u32 *length)
-{
-       rndis_resp_t *r;
-       struct list_head *act, *tmp;
-
-       if (!length) return NULL;
-
-       list_for_each_safe(act, tmp,
-                       &(rndis_per_dev_params[configNr].resp_queue))
-       {
-               r = list_entry(act, rndis_resp_t, list);
-               if (!r->send) {
-                       r->send = 1;
-                       *length = r->length;
-                       return r->buf;
-               }
-       }
-
-       return NULL;
-}
-
-static rndis_resp_t *rndis_add_response(int configNr, u32 length)
-{
-       rndis_resp_t *r;
-
-       /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
-       r = kmalloc(sizeof(rndis_resp_t) + length, GFP_ATOMIC);
-       if (!r) return NULL;
-
-       r->buf = (u8 *)(r + 1);
-       r->length = length;
-       r->send = 0;
-
-       list_add_tail(&r->list,
-               &(rndis_per_dev_params[configNr].resp_queue));
-       return r;
-}
-
-int rndis_rm_hdr(struct gether *port,
-                       struct sk_buff *skb,
-                       struct sk_buff_head *list)
-{
-       /* tmp points to a struct rndis_packet_msg_type */
-       __le32 *tmp = (void *)skb->data;
-
-       /* MessageType, MessageLength */
-       if (cpu_to_le32(RNDIS_MSG_PACKET)
-                       != get_unaligned(tmp++)) {
-               dev_kfree_skb_any(skb);
-               return -EINVAL;
-       }
-       tmp++;
-
-       /* DataOffset, DataLength */
-       if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8)) {
-               dev_kfree_skb_any(skb);
-               return -EOVERFLOW;
-       }
-       skb_trim(skb, get_unaligned_le32(tmp++));
-
-       skb_queue_tail(list, skb);
-       return 0;
-}
-
-#ifdef CONFIG_USB_GADGET_DEBUG_FILES
-
-static int rndis_proc_show(struct seq_file *m, void *v)
-{
-       rndis_params *param = m->private;
-
-       seq_printf(m,
-                        "Config Nr. %d\n"
-                        "used      : %s\n"
-                        "state     : %s\n"
-                        "medium    : 0x%08X\n"
-                        "speed     : %d\n"
-                        "cable     : %s\n"
-                        "vendor ID : 0x%08X\n"
-                        "vendor    : %s\n",
-                        param->confignr, (param->used) ? "y" : "n",
-                        ({ char *s = "?";
-                        switch (param->state) {
-                        case RNDIS_UNINITIALIZED:
-                               s = "RNDIS_UNINITIALIZED"; break;
-                        case RNDIS_INITIALIZED:
-                               s = "RNDIS_INITIALIZED"; break;
-                        case RNDIS_DATA_INITIALIZED:
-                               s = "RNDIS_DATA_INITIALIZED"; break;
-                       }; s; }),
-                        param->medium,
-                        (param->media_state) ? 0 : param->speed*100,
-                        (param->media_state) ? "disconnected" : "connected",
-                        param->vendorID, param->vendorDescr);
-       return 0;
-}
-
-static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,
-                               size_t count, loff_t *ppos)
-{
-       rndis_params *p = PDE(file_inode(file))->data;
-       u32 speed = 0;
-       int i, fl_speed = 0;
-
-       for (i = 0; i < count; i++) {
-               char c;
-               if (get_user(c, buffer))
-                       return -EFAULT;
-               switch (c) {
-               case '0':
-               case '1':
-               case '2':
-               case '3':
-               case '4':
-               case '5':
-               case '6':
-               case '7':
-               case '8':
-               case '9':
-                       fl_speed = 1;
-                       speed = speed * 10 + c - '0';
-                       break;
-               case 'C':
-               case 'c':
-                       rndis_signal_connect(p->confignr);
-                       break;
-               case 'D':
-               case 'd':
-                       rndis_signal_disconnect(p->confignr);
-                       break;
-               default:
-                       if (fl_speed) p->speed = speed;
-                       else pr_debug("%c is not valid\n", c);
-                       break;
-               }
-
-               buffer++;
-       }
-
-       return count;
-}
-
-static int rndis_proc_open(struct inode *inode, struct file *file)
-{
-       return single_open(file, rndis_proc_show, PDE(inode)->data);
-}
-
-static const struct file_operations rndis_proc_fops = {
-       .owner          = THIS_MODULE,
-       .open           = rndis_proc_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = single_release,
-       .write          = rndis_proc_write,
-};
-
-#define        NAME_TEMPLATE "driver/rndis-%03d"
-
-static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
-
-#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
-
-
-int rndis_init(void)
-{
-       u8 i;
-
-       for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
-#ifdef CONFIG_USB_GADGET_DEBUG_FILES
-               char name [20];
-
-               sprintf(name, NAME_TEMPLATE, i);
-               rndis_connect_state[i] = proc_create_data(name, 0660, NULL,
-                                       &rndis_proc_fops,
-                                       (void *)(rndis_per_dev_params + i));
-               if (!rndis_connect_state[i]) {
-                       pr_debug("%s: remove entries", __func__);
-                       while (i) {
-                               sprintf(name, NAME_TEMPLATE, --i);
-                               remove_proc_entry(name, NULL);
-                       }
-                       pr_debug("\n");
-                       return -EIO;
-               }
-#endif
-               rndis_per_dev_params[i].confignr = i;
-               rndis_per_dev_params[i].used = 0;
-               rndis_per_dev_params[i].state = RNDIS_UNINITIALIZED;
-               rndis_per_dev_params[i].media_state
-                               = RNDIS_MEDIA_STATE_DISCONNECTED;
-               INIT_LIST_HEAD(&(rndis_per_dev_params[i].resp_queue));
-       }
-
-       return 0;
-}
-
-void rndis_exit(void)
-{
-#ifdef CONFIG_USB_GADGET_DEBUG_FILES
-       u8 i;
-       char name[20];
-
-       for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
-               sprintf(name, NAME_TEMPLATE, i);
-               remove_proc_entry(name, NULL);
-       }
-#endif
-}
diff --git a/drivers/staging/ccg/rndis.h b/drivers/staging/ccg/rndis.h
deleted file mode 100644 (file)
index 0647f2f..0000000
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * RNDIS       Definitions for Remote NDIS
- *
- * Authors:    Benedikt Spranger, Pengutronix
- *             Robert Schwebel, Pengutronix
- *
- *             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 software was originally developed in conformance with
- *             Microsoft's Remote NDIS Specification License Agreement.
- */
-
-#ifndef _LINUX_RNDIS_H
-#define _LINUX_RNDIS_H
-
-#include <linux/rndis.h>
-#include "ndis.h"
-
-#define RNDIS_MAXIMUM_FRAME_SIZE       1518
-#define RNDIS_MAX_TOTAL_SIZE           1558
-
-typedef struct rndis_init_msg_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  RequestID;
-       __le32  MajorVersion;
-       __le32  MinorVersion;
-       __le32  MaxTransferSize;
-} rndis_init_msg_type;
-
-typedef struct rndis_init_cmplt_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  RequestID;
-       __le32  Status;
-       __le32  MajorVersion;
-       __le32  MinorVersion;
-       __le32  DeviceFlags;
-       __le32  Medium;
-       __le32  MaxPacketsPerTransfer;
-       __le32  MaxTransferSize;
-       __le32  PacketAlignmentFactor;
-       __le32  AFListOffset;
-       __le32  AFListSize;
-} rndis_init_cmplt_type;
-
-typedef struct rndis_halt_msg_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  RequestID;
-} rndis_halt_msg_type;
-
-typedef struct rndis_query_msg_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  RequestID;
-       __le32  OID;
-       __le32  InformationBufferLength;
-       __le32  InformationBufferOffset;
-       __le32  DeviceVcHandle;
-} rndis_query_msg_type;
-
-typedef struct rndis_query_cmplt_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  RequestID;
-       __le32  Status;
-       __le32  InformationBufferLength;
-       __le32  InformationBufferOffset;
-} rndis_query_cmplt_type;
-
-typedef struct rndis_set_msg_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  RequestID;
-       __le32  OID;
-       __le32  InformationBufferLength;
-       __le32  InformationBufferOffset;
-       __le32  DeviceVcHandle;
-} rndis_set_msg_type;
-
-typedef struct rndis_set_cmplt_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  RequestID;
-       __le32  Status;
-} rndis_set_cmplt_type;
-
-typedef struct rndis_reset_msg_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  Reserved;
-} rndis_reset_msg_type;
-
-typedef struct rndis_reset_cmplt_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  Status;
-       __le32  AddressingReset;
-} rndis_reset_cmplt_type;
-
-typedef struct rndis_indicate_status_msg_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  Status;
-       __le32  StatusBufferLength;
-       __le32  StatusBufferOffset;
-} rndis_indicate_status_msg_type;
-
-typedef struct rndis_keepalive_msg_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  RequestID;
-} rndis_keepalive_msg_type;
-
-typedef struct rndis_keepalive_cmplt_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  RequestID;
-       __le32  Status;
-} rndis_keepalive_cmplt_type;
-
-struct rndis_packet_msg_type
-{
-       __le32  MessageType;
-       __le32  MessageLength;
-       __le32  DataOffset;
-       __le32  DataLength;
-       __le32  OOBDataOffset;
-       __le32  OOBDataLength;
-       __le32  NumOOBDataElements;
-       __le32  PerPacketInfoOffset;
-       __le32  PerPacketInfoLength;
-       __le32  VcHandle;
-       __le32  Reserved;
-} __attribute__ ((packed));
-
-struct rndis_config_parameter
-{
-       __le32  ParameterNameOffset;
-       __le32  ParameterNameLength;
-       __le32  ParameterType;
-       __le32  ParameterValueOffset;
-       __le32  ParameterValueLength;
-};
-
-/* implementation specific */
-enum rndis_state
-{
-       RNDIS_UNINITIALIZED,
-       RNDIS_INITIALIZED,
-       RNDIS_DATA_INITIALIZED,
-};
-
-typedef struct rndis_resp_t
-{
-       struct list_head        list;
-       u8                      *buf;
-       u32                     length;
-       int                     send;
-} rndis_resp_t;
-
-typedef struct rndis_params
-{
-       u8                      confignr;
-       u8                      used;
-       u16                     saved_filter;
-       enum rndis_state        state;
-       u32                     medium;
-       u32                     speed;
-       u32                     media_state;
-
-       const u8                *host_mac;
-       u16                     *filter;
-       struct net_device       *dev;
-
-       u32                     vendorID;
-       const char              *vendorDescr;
-       void                    (*resp_avail)(void *v);
-       void                    *v;
-       struct list_head        resp_queue;
-} rndis_params;
-
-/* RNDIS Message parser and other useless functions */
-int  rndis_msg_parser (u8 configNr, u8 *buf);
-int  rndis_register(void (*resp_avail)(void *v), void *v);
-void rndis_deregister (int configNr);
-int  rndis_set_param_dev (u8 configNr, struct net_device *dev,
-                        u16 *cdc_filter);
-int  rndis_set_param_vendor (u8 configNr, u32 vendorID,
-                           const char *vendorDescr);
-int  rndis_set_param_medium (u8 configNr, u32 medium, u32 speed);
-void rndis_add_hdr (struct sk_buff *skb);
-int rndis_rm_hdr(struct gether *port, struct sk_buff *skb,
-                       struct sk_buff_head *list);
-u8   *rndis_get_next_response (int configNr, u32 *length);
-void rndis_free_response (int configNr, u8 *buf);
-
-void rndis_uninit (int configNr);
-int  rndis_signal_connect (int configNr);
-int  rndis_signal_disconnect (int configNr);
-int  rndis_state (int configNr);
-extern void rndis_set_host_mac (int configNr, const u8 *addr);
-
-int rndis_init(void);
-void rndis_exit (void);
-
-#endif  /* _LINUX_RNDIS_H */
diff --git a/drivers/staging/ccg/storage_common.c b/drivers/staging/ccg/storage_common.c
deleted file mode 100644 (file)
index abb01ac..0000000
+++ /dev/null
@@ -1,893 +0,0 @@
-/*
- * storage_common.c -- Common definitions for mass storage functionality
- *
- * Copyright (C) 2003-2008 Alan Stern
- * Copyeight (C) 2009 Samsung Electronics
- * Author: Michal Nazarewicz (mina86@mina86.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 file requires the following identifiers used in USB strings to
- * be defined (each of type pointer to char):
- *  - fsg_string_manufacturer -- name of the manufacturer
- *  - fsg_string_product      -- name of the product
- *  - fsg_string_config       -- name of the configuration
- *  - fsg_string_interface    -- name of the interface
- * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS
- * macro is defined prior to including this file.
- */
-
-/*
- * When FSG_NO_INTR_EP is defined fsg_fs_intr_in_desc and
- * fsg_hs_intr_in_desc objects as well as
- * FSG_FS_FUNCTION_PRE_EP_ENTRIES and FSG_HS_FUNCTION_PRE_EP_ENTRIES
- * macros are not defined.
- *
- * When FSG_NO_DEVICE_STRINGS is defined FSG_STRING_MANUFACTURER,
- * FSG_STRING_PRODUCT, FSG_STRING_SERIAL and FSG_STRING_CONFIG are not
- * defined (as well as corresponding entries in string tables are
- * missing) and FSG_STRING_INTERFACE has value of zero.
- *
- * When FSG_NO_OTG is defined fsg_otg_desc won't be defined.
- */
-
-/*
- * When USB_GADGET_DEBUG_FILES is defined the module param num_buffers
- * sets the number of pipeline buffers (length of the fsg_buffhd array).
- * The valid range of num_buffers is: num >= 2 && num <= 4.
- */
-
-
-#include <linux/usb/storage.h>
-#include <scsi/scsi.h>
-#include <asm/unaligned.h>
-
-
-/*
- * Thanks to NetChip Technologies for donating this product ID.
- *
- * DO NOT REUSE THESE IDs with any other driver!!  Ever!!
- * Instead:  allocate your own, using normal USB-IF procedures.
- */
-#define FSG_VENDOR_ID  0x0525  /* NetChip */
-#define FSG_PRODUCT_ID 0xa4a5  /* Linux-USB File-backed Storage Gadget */
-
-
-/*-------------------------------------------------------------------------*/
-
-
-#ifndef DEBUG
-#undef VERBOSE_DEBUG
-#undef DUMP_MSGS
-#endif /* !DEBUG */
-
-#ifdef VERBOSE_DEBUG
-#define VLDBG  LDBG
-#else
-#define VLDBG(lun, fmt, args...) do { } while (0)
-#endif /* VERBOSE_DEBUG */
-
-#define LDBG(lun, fmt, args...)   dev_dbg (&(lun)->dev, fmt, ## args)
-#define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args)
-#define LWARN(lun, fmt, args...)  dev_warn(&(lun)->dev, fmt, ## args)
-#define LINFO(lun, fmt, args...)  dev_info(&(lun)->dev, fmt, ## args)
-
-/*
- * Keep those macros in sync with those in
- * include/linux/usb/composite.h or else GCC will complain.  If they
- * are identical (the same names of arguments, white spaces in the
- * same places) GCC will allow redefinition otherwise (even if some
- * white space is removed or added) warning will be issued.
- *
- * Those macros are needed here because File Storage Gadget does not
- * include the composite.h header.  For composite gadgets those macros
- * are redundant since composite.h is included any way.
- *
- * One could check whether those macros are already defined (which
- * would indicate composite.h had been included) or not (which would
- * indicate we were in FSG) but this is not done because a warning is
- * desired if definitions here differ from the ones in composite.h.
- *
- * We want the definitions to match and be the same in File Storage
- * Gadget as well as Mass Storage Function (and so composite gadgets
- * using MSF).  If someone changes them in composite.h it will produce
- * a warning in this file when building MSF.
- */
-#define DBG(d, fmt, args...)     dev_dbg(&(d)->gadget->dev , fmt , ## args)
-#define VDBG(d, fmt, args...)    dev_vdbg(&(d)->gadget->dev , fmt , ## args)
-#define ERROR(d, fmt, args...)   dev_err(&(d)->gadget->dev , fmt , ## args)
-#define WARNING(d, fmt, args...) dev_warn(&(d)->gadget->dev , fmt , ## args)
-#define INFO(d, fmt, args...)    dev_info(&(d)->gadget->dev , fmt , ## args)
-
-
-
-#ifdef DUMP_MSGS
-
-#  define dump_msg(fsg, /* const char * */ label,                      \
-                  /* const u8 * */ buf, /* unsigned */ length) do {    \
-       if (length < 512) {                                             \
-               DBG(fsg, "%s, length %u:\n", label, length);            \
-               print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET,      \
-                              16, 1, buf, length, 0);                  \
-       }                                                               \
-} while (0)
-
-#  define dump_cdb(fsg) do { } while (0)
-
-#else
-
-#  define dump_msg(fsg, /* const char * */ label, \
-                  /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
-
-#  ifdef VERBOSE_DEBUG
-
-#    define dump_cdb(fsg)                                              \
-       print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE,      \
-                      16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0)         \
-
-#  else
-
-#    define dump_cdb(fsg) do { } while (0)
-
-#  endif /* VERBOSE_DEBUG */
-
-#endif /* DUMP_MSGS */
-
-/*-------------------------------------------------------------------------*/
-
-/* CBI Interrupt data structure */
-struct interrupt_data {
-       u8      bType;
-       u8      bValue;
-};
-
-#define CBI_INTERRUPT_DATA_LEN         2
-
-/* CBI Accept Device-Specific Command request */
-#define USB_CBI_ADSC_REQUEST           0x00
-
-
-/* Length of a SCSI Command Data Block */
-#define MAX_COMMAND_SIZE       16
-
-/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
-#define SS_NO_SENSE                            0
-#define SS_COMMUNICATION_FAILURE               0x040800
-#define SS_INVALID_COMMAND                     0x052000
-#define SS_INVALID_FIELD_IN_CDB                        0x052400
-#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE  0x052100
-#define SS_LOGICAL_UNIT_NOT_SUPPORTED          0x052500
-#define SS_MEDIUM_NOT_PRESENT                  0x023a00
-#define SS_MEDIUM_REMOVAL_PREVENTED            0x055302
-#define SS_NOT_READY_TO_READY_TRANSITION       0x062800
-#define SS_RESET_OCCURRED                      0x062900
-#define SS_SAVING_PARAMETERS_NOT_SUPPORTED     0x053900
-#define SS_UNRECOVERED_READ_ERROR              0x031100
-#define SS_WRITE_ERROR                         0x030c02
-#define SS_WRITE_PROTECTED                     0x072700
-
-#define SK(x)          ((u8) ((x) >> 16))      /* Sense Key byte, etc. */
-#define ASC(x)         ((u8) ((x) >> 8))
-#define ASCQ(x)                ((u8) (x))
-
-
-/*-------------------------------------------------------------------------*/
-
-
-struct fsg_lun {
-       struct file     *filp;
-       loff_t          file_length;
-       loff_t          num_sectors;
-
-       unsigned int    initially_ro:1;
-       unsigned int    ro:1;
-       unsigned int    removable:1;
-       unsigned int    cdrom:1;
-       unsigned int    prevent_medium_removal:1;
-       unsigned int    registered:1;
-       unsigned int    info_valid:1;
-       unsigned int    nofua:1;
-
-       u32             sense_data;
-       u32             sense_data_info;
-       u32             unit_attention_data;
-
-       unsigned int    blkbits;        /* Bits of logical block size of bound block device */
-       unsigned int    blksize;        /* logical block size of bound block device */
-       struct device   dev;
-};
-
-#define fsg_lun_is_open(curlun)        ((curlun)->filp != NULL)
-
-static struct fsg_lun *fsg_lun_from_dev(struct device *dev)
-{
-       return container_of(dev, struct fsg_lun, dev);
-}
-
-
-/* Big enough to hold our biggest descriptor */
-#define EP0_BUFSIZE    256
-#define DELAYED_STATUS (EP0_BUFSIZE + 999)     /* An impossibly large value */
-
-#ifdef CONFIG_USB_GADGET_DEBUG_FILES
-
-static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
-module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);
-MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers");
-
-#else
-
-/*
- * Number of buffers we will use.
- * 2 is usually enough for good buffering pipeline
- */
-#define fsg_num_buffers        CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
-
-#endif /* CONFIG_USB_DEBUG */
-
-/* check if fsg_num_buffers is within a valid range */
-static inline int fsg_num_buffers_validate(void)
-{
-       if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4)
-               return 0;
-       pr_err("fsg_num_buffers %u is out of range (%d to %d)\n",
-              fsg_num_buffers, 2 ,4);
-       return -EINVAL;
-}
-
-/* Default size of buffer length. */
-#define FSG_BUFLEN     ((u32)16384)
-
-/* Maximal number of LUNs supported in mass storage function */
-#define FSG_MAX_LUNS   8
-
-enum fsg_buffer_state {
-       BUF_STATE_EMPTY = 0,
-       BUF_STATE_FULL,
-       BUF_STATE_BUSY
-};
-
-struct fsg_buffhd {
-       void                            *buf;
-       enum fsg_buffer_state           state;
-       struct fsg_buffhd               *next;
-
-       /*
-        * The NetChip 2280 is faster, and handles some protocol faults
-        * better, if we don't submit any short bulk-out read requests.
-        * So we will record the intended request length here.
-        */
-       unsigned int                    bulk_out_intended_length;
-
-       struct usb_request              *inreq;
-       int                             inreq_busy;
-       struct usb_request              *outreq;
-       int                             outreq_busy;
-};
-
-enum fsg_state {
-       /* This one isn't used anywhere */
-       FSG_STATE_COMMAND_PHASE = -10,
-       FSG_STATE_DATA_PHASE,
-       FSG_STATE_STATUS_PHASE,
-
-       FSG_STATE_IDLE = 0,
-       FSG_STATE_ABORT_BULK_OUT,
-       FSG_STATE_RESET,
-       FSG_STATE_INTERFACE_CHANGE,
-       FSG_STATE_CONFIG_CHANGE,
-       FSG_STATE_DISCONNECT,
-       FSG_STATE_EXIT,
-       FSG_STATE_TERMINATED
-};
-
-enum data_direction {
-       DATA_DIR_UNKNOWN = 0,
-       DATA_DIR_FROM_HOST,
-       DATA_DIR_TO_HOST,
-       DATA_DIR_NONE
-};
-
-
-/*-------------------------------------------------------------------------*/
-
-
-static inline u32 get_unaligned_be24(u8 *buf)
-{
-       return 0xffffff & (u32) get_unaligned_be32(buf - 1);
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-
-enum {
-#ifndef FSG_NO_DEVICE_STRINGS
-       FSG_STRING_MANUFACTURER = 1,
-       FSG_STRING_PRODUCT,
-       FSG_STRING_SERIAL,
-       FSG_STRING_CONFIG,
-#endif
-       FSG_STRING_INTERFACE
-};
-
-
-#ifndef FSG_NO_OTG
-static struct usb_otg_descriptor
-fsg_otg_desc = {
-       .bLength =              sizeof fsg_otg_desc,
-       .bDescriptorType =      USB_DT_OTG,
-
-       .bmAttributes =         USB_OTG_SRP,
-};
-#endif
-
-/* There is only one interface. */
-
-static struct usb_interface_descriptor
-fsg_intf_desc = {
-       .bLength =              sizeof fsg_intf_desc,
-       .bDescriptorType =      USB_DT_INTERFACE,
-
-       .bNumEndpoints =        2,              /* Adjusted during fsg_bind() */
-       .bInterfaceClass =      USB_CLASS_MASS_STORAGE,
-       .bInterfaceSubClass =   USB_SC_SCSI,    /* Adjusted during fsg_bind() */
-       .bInterfaceProtocol =   USB_PR_BULK,    /* Adjusted during fsg_bind() */
-       .iInterface =           FSG_STRING_INTERFACE,
-};
-
-/*
- * Three full-speed endpoint descriptors: bulk-in, bulk-out, and
- * interrupt-in.
- */
-
-static struct usb_endpoint_descriptor
-fsg_fs_bulk_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_IN,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       /* wMaxPacketSize set by autoconfiguration */
-};
-
-static struct usb_endpoint_descriptor
-fsg_fs_bulk_out_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_OUT,
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       /* wMaxPacketSize set by autoconfiguration */
-};
-
-#ifndef FSG_NO_INTR_EP
-
-static struct usb_endpoint_descriptor
-fsg_fs_intr_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       .bEndpointAddress =     USB_DIR_IN,
-       .bmAttributes =         USB_ENDPOINT_XFER_INT,
-       .wMaxPacketSize =       cpu_to_le16(2),
-       .bInterval =            32,     /* frames -> 32 ms */
-};
-
-#ifndef FSG_NO_OTG
-#  define FSG_FS_FUNCTION_PRE_EP_ENTRIES       2
-#else
-#  define FSG_FS_FUNCTION_PRE_EP_ENTRIES       1
-#endif
-
-#endif
-
-static struct usb_descriptor_header *fsg_fs_function[] = {
-#ifndef FSG_NO_OTG
-       (struct usb_descriptor_header *) &fsg_otg_desc,
-#endif
-       (struct usb_descriptor_header *) &fsg_intf_desc,
-       (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
-       (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
-#ifndef FSG_NO_INTR_EP
-       (struct usb_descriptor_header *) &fsg_fs_intr_in_desc,
-#endif
-       NULL,
-};
-
-
-/*
- * USB 2.0 devices need to expose both high speed and full speed
- * descriptors, unless they only run at full speed.
- *
- * That means alternate endpoint descriptors (bigger packets)
- * and a "device qualifier" ... plus more construction options
- * for the configuration descriptor.
- */
-static struct usb_endpoint_descriptor
-fsg_hs_bulk_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(512),
-};
-
-static struct usb_endpoint_descriptor
-fsg_hs_bulk_out_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(512),
-       .bInterval =            1,      /* NAK every 1 uframe */
-};
-
-#ifndef FSG_NO_INTR_EP
-
-static struct usb_endpoint_descriptor
-fsg_hs_intr_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */
-       .bmAttributes =         USB_ENDPOINT_XFER_INT,
-       .wMaxPacketSize =       cpu_to_le16(2),
-       .bInterval =            9,      /* 2**(9-1) = 256 uframes -> 32 ms */
-};
-
-#ifndef FSG_NO_OTG
-#  define FSG_HS_FUNCTION_PRE_EP_ENTRIES       2
-#else
-#  define FSG_HS_FUNCTION_PRE_EP_ENTRIES       1
-#endif
-
-#endif
-
-static struct usb_descriptor_header *fsg_hs_function[] = {
-#ifndef FSG_NO_OTG
-       (struct usb_descriptor_header *) &fsg_otg_desc,
-#endif
-       (struct usb_descriptor_header *) &fsg_intf_desc,
-       (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
-       (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
-#ifndef FSG_NO_INTR_EP
-       (struct usb_descriptor_header *) &fsg_hs_intr_in_desc,
-#endif
-       NULL,
-};
-
-static struct usb_endpoint_descriptor
-fsg_ss_bulk_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(1024),
-};
-
-static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = {
-       .bLength =              sizeof(fsg_ss_bulk_in_comp_desc),
-       .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
-
-       /*.bMaxBurst =          DYNAMIC, */
-};
-
-static struct usb_endpoint_descriptor
-fsg_ss_bulk_out_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
-       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize =       cpu_to_le16(1024),
-};
-
-static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = {
-       .bLength =              sizeof(fsg_ss_bulk_in_comp_desc),
-       .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
-
-       /*.bMaxBurst =          DYNAMIC, */
-};
-
-#ifndef FSG_NO_INTR_EP
-
-static struct usb_endpoint_descriptor
-fsg_ss_intr_in_desc = {
-       .bLength =              USB_DT_ENDPOINT_SIZE,
-       .bDescriptorType =      USB_DT_ENDPOINT,
-
-       /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */
-       .bmAttributes =         USB_ENDPOINT_XFER_INT,
-       .wMaxPacketSize =       cpu_to_le16(2),
-       .bInterval =            9,      /* 2**(9-1) = 256 uframes -> 32 ms */
-};
-
-static struct usb_ss_ep_comp_descriptor fsg_ss_intr_in_comp_desc = {
-       .bLength =              sizeof(fsg_ss_bulk_in_comp_desc),
-       .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
-
-       .wBytesPerInterval =    cpu_to_le16(2),
-};
-
-#ifndef FSG_NO_OTG
-#  define FSG_SS_FUNCTION_PRE_EP_ENTRIES       2
-#else
-#  define FSG_SS_FUNCTION_PRE_EP_ENTRIES       1
-#endif
-
-#endif
-
-static __maybe_unused struct usb_ext_cap_descriptor fsg_ext_cap_desc = {
-       .bLength =              USB_DT_USB_EXT_CAP_SIZE,
-       .bDescriptorType =      USB_DT_DEVICE_CAPABILITY,
-       .bDevCapabilityType =   USB_CAP_TYPE_EXT,
-
-       .bmAttributes =         cpu_to_le32(USB_LPM_SUPPORT),
-};
-
-static __maybe_unused struct usb_ss_cap_descriptor fsg_ss_cap_desc = {
-       .bLength =              USB_DT_USB_SS_CAP_SIZE,
-       .bDescriptorType =      USB_DT_DEVICE_CAPABILITY,
-       .bDevCapabilityType =   USB_SS_CAP_TYPE,
-
-       /* .bmAttributes = LTM is not supported yet */
-
-       .wSpeedSupported =      cpu_to_le16(USB_LOW_SPEED_OPERATION
-               | USB_FULL_SPEED_OPERATION
-               | USB_HIGH_SPEED_OPERATION
-               | USB_5GBPS_OPERATION),
-       .bFunctionalitySupport = USB_LOW_SPEED_OPERATION,
-       .bU1devExitLat =        USB_DEFAULT_U1_DEV_EXIT_LAT,
-       .bU2DevExitLat =        cpu_to_le16(USB_DEFAULT_U2_DEV_EXIT_LAT),
-};
-
-static __maybe_unused struct usb_bos_descriptor fsg_bos_desc = {
-       .bLength =              USB_DT_BOS_SIZE,
-       .bDescriptorType =      USB_DT_BOS,
-
-       .wTotalLength =         cpu_to_le16(USB_DT_BOS_SIZE
-                               + USB_DT_USB_EXT_CAP_SIZE
-                               + USB_DT_USB_SS_CAP_SIZE),
-
-       .bNumDeviceCaps =       2,
-};
-
-static struct usb_descriptor_header *fsg_ss_function[] = {
-#ifndef FSG_NO_OTG
-       (struct usb_descriptor_header *) &fsg_otg_desc,
-#endif
-       (struct usb_descriptor_header *) &fsg_intf_desc,
-       (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc,
-       (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc,
-       (struct usb_descriptor_header *) &fsg_ss_bulk_out_desc,
-       (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc,
-#ifndef FSG_NO_INTR_EP
-       (struct usb_descriptor_header *) &fsg_ss_intr_in_desc,
-       (struct usb_descriptor_header *) &fsg_ss_intr_in_comp_desc,
-#endif
-       NULL,
-};
-
-/* Maxpacket and other transfer characteristics vary by speed. */
-static __maybe_unused struct usb_endpoint_descriptor *
-fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
-               struct usb_endpoint_descriptor *hs,
-               struct usb_endpoint_descriptor *ss)
-{
-       if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
-               return ss;
-       else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
-               return hs;
-       return fs;
-}
-
-
-/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
-static struct usb_string               fsg_strings[] = {
-#ifndef FSG_NO_DEVICE_STRINGS
-       {FSG_STRING_MANUFACTURER,       fsg_string_manufacturer},
-       {FSG_STRING_PRODUCT,            fsg_string_product},
-       {FSG_STRING_SERIAL,             ""},
-       {FSG_STRING_CONFIG,             fsg_string_config},
-#endif
-       {FSG_STRING_INTERFACE,          fsg_string_interface},
-       {}
-};
-
-static struct usb_gadget_strings       fsg_stringtab = {
-       .language       = 0x0409,               /* en-us */
-       .strings        = fsg_strings,
-};
-
-
- /*-------------------------------------------------------------------------*/
-
-/*
- * If the next two routines are called while the gadget is registered,
- * the caller must own fsg->filesem for writing.
- */
-
-static void fsg_lun_close(struct fsg_lun *curlun)
-{
-       if (curlun->filp) {
-               LDBG(curlun, "close backing file\n");
-               fput(curlun->filp);
-               curlun->filp = NULL;
-       }
-}
-
-
-static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
-{
-       int                             ro;
-       struct file                     *filp = NULL;
-       int                             rc = -EINVAL;
-       struct inode                    *inode = NULL;
-       loff_t                          size;
-       loff_t                          num_sectors;
-       loff_t                          min_sectors;
-       unsigned int                    blkbits;
-       unsigned int                    blksize;
-
-       /* R/W if we can, R/O if we must */
-       ro = curlun->initially_ro;
-       if (!ro) {
-               filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0);
-               if (PTR_ERR(filp) == -EROFS || PTR_ERR(filp) == -EACCES)
-                       ro = 1;
-       }
-       if (ro)
-               filp = filp_open(filename, O_RDONLY | O_LARGEFILE, 0);
-       if (IS_ERR(filp)) {
-               LINFO(curlun, "unable to open backing file: %s\n", filename);
-               return PTR_ERR(filp);
-       }
-
-       if (!(filp->f_mode & FMODE_WRITE))
-               ro = 1;
-
-       inode = file_inode(filp);
-       if ((!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))) {
-               LINFO(curlun, "invalid file type: %s\n", filename);
-               goto out;
-       }
-
-       /*
-        * If we can't read the file, it's no good.
-        * If we can't write the file, use it read-only.
-        */
-       if (!(filp->f_op->read || filp->f_op->aio_read)) {
-               LINFO(curlun, "file not readable: %s\n", filename);
-               goto out;
-       }
-       if (!(filp->f_op->write || filp->f_op->aio_write))
-               ro = 1;
-
-       size = i_size_read(inode->i_mapping->host);
-       if (size < 0) {
-               LINFO(curlun, "unable to find file size: %s\n", filename);
-               rc = (int) size;
-               goto out;
-       }
-
-       if (curlun->cdrom) {
-               blksize = 2048;
-               blkbits = 11;
-       } else if (inode->i_bdev) {
-               blksize = bdev_logical_block_size(inode->i_bdev);
-               blkbits = blksize_bits(blksize);
-       } else {
-               blksize = 512;
-               blkbits = 9;
-       }
-
-       num_sectors = size >> blkbits; /* File size in logic-block-size blocks */
-       min_sectors = 1;
-       if (curlun->cdrom) {
-               min_sectors = 300;      /* Smallest track is 300 frames */
-               if (num_sectors >= 256*60*75) {
-                       num_sectors = 256*60*75 - 1;
-                       LINFO(curlun, "file too big: %s\n", filename);
-                       LINFO(curlun, "using only first %d blocks\n",
-                                       (int) num_sectors);
-               }
-       }
-       if (num_sectors < min_sectors) {
-               LINFO(curlun, "file too small: %s\n", filename);
-               rc = -ETOOSMALL;
-               goto out;
-       }
-
-       if (fsg_lun_is_open(curlun))
-               fsg_lun_close(curlun);
-
-       curlun->blksize = blksize;
-       curlun->blkbits = blkbits;
-       curlun->ro = ro;
-       curlun->filp = filp;
-       curlun->file_length = size;
-       curlun->num_sectors = num_sectors;
-       LDBG(curlun, "open backing file: %s\n", filename);
-       return 0;
-
-out:
-       fput(filp);
-       return rc;
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-/*
- * Sync the file data, don't bother with the metadata.
- * This code was copied from fs/buffer.c:sys_fdatasync().
- */
-static int fsg_lun_fsync_sub(struct fsg_lun *curlun)
-{
-       struct file     *filp = curlun->filp;
-
-       if (curlun->ro || !filp)
-               return 0;
-       return vfs_fsync(filp, 1);
-}
-
-static void store_cdrom_address(u8 *dest, int msf, u32 addr)
-{
-       if (msf) {
-               /* Convert to Minutes-Seconds-Frames */
-               addr >>= 2;             /* Convert to 2048-byte frames */
-               addr += 2*75;           /* Lead-in occupies 2 seconds */
-               dest[3] = addr % 75;    /* Frames */
-               addr /= 75;
-               dest[2] = addr % 60;    /* Seconds */
-               addr /= 60;
-               dest[1] = addr;         /* Minutes */
-               dest[0] = 0;            /* Reserved */
-       } else {
-               /* Absolute sector */
-               put_unaligned_be32(addr, dest);
-       }
-}
-
-
-/*-------------------------------------------------------------------------*/
-
-
-static ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr,
-                          char *buf)
-{
-       struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
-
-       return sprintf(buf, "%d\n", fsg_lun_is_open(curlun)
-                                 ? curlun->ro
-                                 : curlun->initially_ro);
-}
-
-static ssize_t fsg_show_nofua(struct device *dev, struct device_attribute *attr,
-                             char *buf)
-{
-       struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
-
-       return sprintf(buf, "%u\n", curlun->nofua);
-}
-
-static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
-                            char *buf)
-{
-       struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
-       struct rw_semaphore     *filesem = dev_get_drvdata(dev);
-       char            *p;
-       ssize_t         rc;
-
-       down_read(filesem);
-       if (fsg_lun_is_open(curlun)) {  /* Get the complete pathname */
-               p = d_path(&curlun->filp->f_path, buf, PAGE_SIZE - 1);
-               if (IS_ERR(p))
-                       rc = PTR_ERR(p);
-               else {
-                       rc = strlen(p);
-                       memmove(buf, p, rc);
-                       buf[rc] = '\n';         /* Add a newline */
-                       buf[++rc] = 0;
-               }
-       } else {                                /* No file, return 0 bytes */
-               *buf = 0;
-               rc = 0;
-       }
-       up_read(filesem);
-       return rc;
-}
-
-
-static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
-                           const char *buf, size_t count)
-{
-       ssize_t         rc;
-       struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
-       struct rw_semaphore     *filesem = dev_get_drvdata(dev);
-       unsigned        ro;
-
-       rc = kstrtouint(buf, 2, &ro);
-       if (rc)
-               return rc;
-
-       /*
-        * Allow the write-enable status to change only while the
-        * backing file is closed.
-        */
-       down_read(filesem);
-       if (fsg_lun_is_open(curlun)) {
-               LDBG(curlun, "read-only status change prevented\n");
-               rc = -EBUSY;
-       } else {
-               curlun->ro = ro;
-               curlun->initially_ro = ro;
-               LDBG(curlun, "read-only status set to %d\n", curlun->ro);
-               rc = count;
-       }
-       up_read(filesem);
-       return rc;
-}
-
-static ssize_t fsg_store_nofua(struct device *dev,
-                              struct device_attribute *attr,
-                              const char *buf, size_t count)
-{
-       struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
-       unsigned        nofua;
-       int             ret;
-
-       ret = kstrtouint(buf, 2, &nofua);
-       if (ret)
-               return ret;
-
-       /* Sync data when switching from async mode to sync */
-       if (!nofua && curlun->nofua)
-               fsg_lun_fsync_sub(curlun);
-
-       curlun->nofua = nofua;
-
-       return count;
-}
-
-static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
-                             const char *buf, size_t count)
-{
-       struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
-       struct rw_semaphore     *filesem = dev_get_drvdata(dev);
-       int             rc = 0;
-
-       if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) {
-               LDBG(curlun, "eject attempt prevented\n");
-               return -EBUSY;                          /* "Door is locked" */
-       }
-
-       /* Remove a trailing newline */
-       if (count > 0 && buf[count-1] == '\n')
-               ((char *) buf)[count-1] = 0;            /* Ugh! */
-
-       /* Load new medium */
-       down_write(filesem);
-       if (count > 0 && buf[0]) {
-               /* fsg_lun_open() will close existing file if any. */
-               rc = fsg_lun_open(curlun, buf);
-               if (rc == 0)
-                       curlun->unit_attention_data =
-                                       SS_NOT_READY_TO_READY_TRANSITION;
-       } else if (fsg_lun_is_open(curlun)) {
-               fsg_lun_close(curlun);
-               curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT;
-       }
-       up_write(filesem);
-       return (rc < 0 ? rc : count);
-}
diff --git a/drivers/staging/ccg/sysfs-class-ccg_usb b/drivers/staging/ccg/sysfs-class-ccg_usb
deleted file mode 100644 (file)
index dd12a33..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-What:          /sys/class/ccg_usb
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               The ccg_usb/ class subdirectory belongs to ccg
-               USB gadget.
-
-What:          /sys/class/ccg_usb/ccgX
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               The /sys/class/ccg_usb/ccg{0,1,2,3...} class
-               subdirectories correspond to each ccg gadget device;
-               at the time of this writing there is only ccg0 and it
-               represents the ccg gadget.
-
-What:          /sys/class/ccg_usb/ccgX/functions
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               A comma-separated list of USB function names to be activated
-               in this ccg gadget. It includes both the functions provided
-               in-kernel by the ccg gadget and the functions provided from
-               userspace through FunctionFS.
-
-What:          /sys/class/ccg_usb/ccgX/enable
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               A flag activating/deactivating the ccg usb gadget.
-
-What:          /sys/class/ccg_usb/ccgX/state
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               Configurable usb gadget state:
-
-               DISCONNECTED
-               CONNECTED
-               CONFIGURED
-
-What:          /sys/class/ccg_usb/ccgX/f_acm/
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               The /sys/class/ccg_usb/ccgX/f_acm subdirectory
-               corresponds to the gadget's USB CDC serial (ACM) function
-               driver.
-
-What:          /sys/class/ccg_usb/ccgX/f_acm/instances
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               Maximum number of the /dev/ttyGS<X> interface the driver uses.
-
-What:          /sys/class/ccg_usb/ccgX/f_fs
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               The /sys/class/ccg_usb/ccgX/f_fs subdirectory
-               corresponds to the gadget's FunctionFS driver.
-
-What:          /sys/class/ccg_usb/ccgX/f_fs/user_functions
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               A comma-separeted list of USB function names to be supported
-               from userspace. No other userspace FunctionFS functions can
-               be supported than listed here. However, the actual activation
-               of these functions is still done through
-               /sys/class/ccg_usb/ccgX/functions, where it is possible
-               to specify any subset (including maximum and empty) of
-               /sys/class/ccg_usb/ccgX/f_fs/user_functions.
-
-What:          /sys/class/ccg_usb/ccgX/f_fs/max_user_functions
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               Maximum number of USB functions to be supported from userspace.
-
-What:          /sys/class/ccg_usb/ccgX/f_rndis
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               The /sys/class/ccg_usb/ccgX/f_rndis subdirectory
-               corresponds to the gadget's RNDIS driver.
-
-What:          /sys/class/ccg_usb/ccgX/f_rndis/manufacturer
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               RNDIS Ethernet port manufacturer string.
-
-What:          /sys/class/ccg_usb/ccgX/f_rndis/wceis
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               RNDIS Ethernet port wireless flag.
-
-What:          /sys/class/ccg_usb/ccgX/f_rndis/ethaddr
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               RNDIS Ethernet port Ethernet address.
-
-What:          /sys/class/ccg_usb/ccgX/f_rndis/vendorID
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               RNDIS Ethernet port vendor ID.
-
-What:          /sys/class/ccg_usb/ccgX/f_mass_storage
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               The /sys/class/ccg_usb/ccgX/f_mass_storage subdirectory
-               corresponds to the gadget's USB mass storage driver.
-
-What:          /sys/class/ccg_usb/ccgX/f_mass_storage/lun
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               The /sys/class/ccg_usb/ccgX/f_mass_storage/lun
-               subdirectory corresponds to the gadget's USB mass storage
-               driver and its underlying storage.
-
-What:          /sys/class/ccg_usb/ccgX/f_mass_storage/lun
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               The /sys/class/ccg_usb/ccgX/f_mass_storage/lun
-               subdirectory corresponds to the gadget's USB mass storage
-               driver and its underlying storage.
-
-What:          /sys/class/ccg_usb/ccgX/f_mass_storage/lun/file
-Date:          May 2012
-KernelVersion: 3.4
-Contact:       linux-usb@vger.kernel.org
-Description:
-               Gadget's USB mass storage underlying file.
diff --git a/drivers/staging/ccg/u_ether.c b/drivers/staging/ccg/u_ether.c
deleted file mode 100644 (file)
index fed7886..0000000
+++ /dev/null
@@ -1,986 +0,0 @@
-/*
- * u_ether.c -- Ethernet-over-USB link layer utilities for Gadget stack
- *
- * Copyright (C) 2003-2005,2008 David Brownell
- * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
- * Copyright (C) 2008 Nokia Corporation
- *
- * 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.
- */
-
-/* #define VERBOSE_DEBUG */
-
-#include <linux/kernel.h>
-#include <linux/gfp.h>
-#include <linux/device.h>
-#include <linux/ctype.h>
-#include <linux/etherdevice.h>
-#include <linux/ethtool.h>
-
-#include "u_ether.h"
-
-
-/*
- * This component encapsulates the Ethernet link glue needed to provide
- * one (!) network link through the USB gadget stack, normally "usb0".
- *
- * The control and data models are handled by the function driver which
- * connects to this code; such as CDC Ethernet (ECM or EEM),
- * "CDC Subset", or RNDIS.  That includes all descriptor and endpoint
- * management.
- *
- * Link level addressing is handled by this component using module
- * parameters; if no such parameters are provided, random link level
- * addresses are used.  Each end of the link uses one address.  The
- * host end address is exported in various ways, and is often recorded
- * in configuration databases.
- *
- * The driver which assembles each configuration using such a link is
- * responsible for ensuring that each configuration includes at most one
- * instance of is network link.  (The network layer provides ways for
- * this single "physical" link to be used by multiple virtual links.)
- */
-
-#define UETH__VERSION  "29-May-2008"
-
-struct eth_dev {
-       /* lock is held while accessing port_usb
-        * or updating its backlink port_usb->ioport
-        */
-       spinlock_t              lock;
-       struct gether           *port_usb;
-
-       struct net_device       *net;
-       struct usb_gadget       *gadget;
-
-       spinlock_t              req_lock;       /* guard {rx,tx}_reqs */
-       struct list_head        tx_reqs, rx_reqs;
-       atomic_t                tx_qlen;
-
-       struct sk_buff_head     rx_frames;
-
-       unsigned                header_len;
-       struct sk_buff          *(*wrap)(struct gether *, struct sk_buff *skb);
-       int                     (*unwrap)(struct gether *,
-                                               struct sk_buff *skb,
-                                               struct sk_buff_head *list);
-
-       struct work_struct      work;
-
-       unsigned long           todo;
-#define        WORK_RX_MEMORY          0
-
-       bool                    zlp;
-       u8                      host_mac[ETH_ALEN];
-};
-
-/*-------------------------------------------------------------------------*/
-
-#define RX_EXTRA       20      /* bytes guarding against rx overflows */
-
-#define DEFAULT_QLEN   2       /* double buffering by default */
-
-static unsigned qmult = 5;
-module_param(qmult, uint, S_IRUGO|S_IWUSR);
-MODULE_PARM_DESC(qmult, "queue length multiplier at high/super speed");
-
-/* for dual-speed hardware, use deeper queues at high/super speed */
-static inline int qlen(struct usb_gadget *gadget)
-{
-       if (gadget_is_dualspeed(gadget) && (gadget->speed == USB_SPEED_HIGH ||
-                                           gadget->speed == USB_SPEED_SUPER))
-               return qmult * DEFAULT_QLEN;
-       else
-               return DEFAULT_QLEN;
-}
-
-/*-------------------------------------------------------------------------*/
-
-/* REVISIT there must be a better way than having two sets
- * of debug calls ...
- */
-
-#undef DBG
-#undef VDBG
-#undef ERROR
-#undef INFO
-
-#define xprintk(d, level, fmt, args...) \
-       printk(level "%s: " fmt , (d)->net->name , ## args)
-
-#ifdef DEBUG
-#undef DEBUG
-#define DBG(dev, fmt, args...) \
-       xprintk(dev , KERN_DEBUG , fmt , ## args)
-#else
-#define DBG(dev, fmt, args...) \
-       do { } while (0)
-#endif /* DEBUG */
-
-#ifdef VERBOSE_DEBUG
-#define VDBG   DBG
-#else
-#define VDBG(dev, fmt, args...) \
-       do { } while (0)
-#endif /* DEBUG */
-
-#define ERROR(dev, fmt, args...) \
-       xprintk(dev , KERN_ERR , fmt , ## args)
-#define INFO(dev, fmt, args...) \
-       xprintk(dev , KERN_INFO , fmt , ## args)
-
-/*-------------------------------------------------------------------------*/
-
-/* NETWORK DRIVER HOOKUP (to the layer above this driver) */
-
-static int ueth_change_mtu(struct net_device *net, int new_mtu)
-{
-       struct eth_dev  *dev = netdev_priv(net);
-       unsigned long   flags;
-       int             status = 0;
-
-       /* don't change MTU on "live" link (peer won't know) */
-       spin_lock_irqsave(&dev->lock, flags);
-       if (dev->port_usb)
-               status = -EBUSY;
-       else if (new_mtu <= ETH_HLEN || new_mtu > ETH_FRAME_LEN)
-               status = -ERANGE;
-       else
-               net->mtu = new_mtu;
-       spin_unlock_irqrestore(&dev->lock, flags);
-
-       return status;
-}
-
-static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
-{
-       struct eth_dev *dev = netdev_priv(net);
-
-       strlcpy(p->driver, "g_ether", sizeof(p->driver));
-       strlcpy(p->version, UETH__VERSION, sizeof(p->version));
-       strlcpy(p->fw_version, dev->gadget->name, sizeof(p->fw_version));
-       strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof(p->bus_info));
-}
-
-/* REVISIT can also support:
- *   - WOL (by tracking suspends and issuing remote wakeup)
- *   - msglevel (implies updated messaging)
- *   - ... probably more ethtool ops
- */
-
-static const struct ethtool_ops ops = {
-       .get_drvinfo = eth_get_drvinfo,
-       .get_link = ethtool_op_get_link,
-};
-
-static void defer_kevent(struct eth_dev *dev, int flag)
-{
-       if (test_and_set_bit(flag, &dev->todo))
-               return;
-       if (!schedule_work(&dev->work))
-               ERROR(dev, "kevent %d may have been dropped\n", flag);
-       else
-               DBG(dev, "kevent %d scheduled\n", flag);
-}
-
-static void rx_complete(struct usb_ep *ep, struct usb_request *req);
-
-static int
-rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags)
-{
-       struct sk_buff  *skb;
-       int             retval = -ENOMEM;
-       size_t          size = 0;
-       struct usb_ep   *out;
-       unsigned long   flags;
-
-       spin_lock_irqsave(&dev->lock, flags);
-       if (dev->port_usb)
-               out = dev->port_usb->out_ep;
-       else
-               out = NULL;
-       spin_unlock_irqrestore(&dev->lock, flags);
-
-       if (!out)
-               return -ENOTCONN;
-
-
-       /* Padding up to RX_EXTRA handles minor disagreements with host.
-        * Normally we use the USB "terminate on short read" convention;
-        * so allow up to (N*maxpacket), since that memory is normally
-        * already allocated.  Some hardware doesn't deal well with short
-        * reads (e.g. DMA must be N*maxpacket), so for now don't trim a
-        * byte off the end (to force hardware errors on overflow).
-        *
-        * RNDIS uses internal framing, and explicitly allows senders to
-        * pad to end-of-packet.  That's potentially nice for speed, but
-        * means receivers can't recover lost synch on their own (because
-        * new packets don't only start after a short RX).
-        */
-       size += sizeof(struct ethhdr) + dev->net->mtu + RX_EXTRA;
-       size += dev->port_usb->header_len;
-       size += out->maxpacket - 1;
-       size -= size % out->maxpacket;
-
-       if (dev->port_usb->is_fixed)
-               size = max_t(size_t, size, dev->port_usb->fixed_out_len);
-
-       skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags);
-       if (skb == NULL) {
-               DBG(dev, "no rx skb\n");
-               goto enomem;
-       }
-
-       /* Some platforms perform better when IP packets are aligned,
-        * but on at least one, checksumming fails otherwise.  Note:
-        * RNDIS headers involve variable numbers of LE32 values.
-        */
-       skb_reserve(skb, NET_IP_ALIGN);
-
-       req->buf = skb->data;
-       req->length = size;
-       req->complete = rx_complete;
-       req->context = skb;
-
-       retval = usb_ep_queue(out, req, gfp_flags);
-       if (retval == -ENOMEM)
-enomem:
-               defer_kevent(dev, WORK_RX_MEMORY);
-       if (retval) {
-               DBG(dev, "rx submit --> %d\n", retval);
-               if (skb)
-                       dev_kfree_skb_any(skb);
-               spin_lock_irqsave(&dev->req_lock, flags);
-               list_add(&req->list, &dev->rx_reqs);
-               spin_unlock_irqrestore(&dev->req_lock, flags);
-       }
-       return retval;
-}
-
-static void rx_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       struct sk_buff  *skb = req->context, *skb2;
-       struct eth_dev  *dev = ep->driver_data;
-       int             status = req->status;
-
-       switch (status) {
-
-       /* normal completion */
-       case 0:
-               skb_put(skb, req->actual);
-
-               if (dev->unwrap) {
-                       unsigned long   flags;
-
-                       spin_lock_irqsave(&dev->lock, flags);
-                       if (dev->port_usb) {
-                               status = dev->unwrap(dev->port_usb,
-                                                       skb,
-                                                       &dev->rx_frames);
-                       } else {
-                               dev_kfree_skb_any(skb);
-                               status = -ENOTCONN;
-                       }
-                       spin_unlock_irqrestore(&dev->lock, flags);
-               } else {
-                       skb_queue_tail(&dev->rx_frames, skb);
-               }
-               skb = NULL;
-
-               skb2 = skb_dequeue(&dev->rx_frames);
-               while (skb2) {
-                       if (status < 0
-                                       || ETH_HLEN > skb2->len
-                                       || skb2->len > ETH_FRAME_LEN) {
-                               dev->net->stats.rx_errors++;
-                               dev->net->stats.rx_length_errors++;
-                               DBG(dev, "rx length %d\n", skb2->len);
-                               dev_kfree_skb_any(skb2);
-                               goto next_frame;
-                       }
-                       skb2->protocol = eth_type_trans(skb2, dev->net);
-                       dev->net->stats.rx_packets++;
-                       dev->net->stats.rx_bytes += skb2->len;
-
-                       /* no buffer copies needed, unless hardware can't
-                        * use skb buffers.
-                        */
-                       status = netif_rx(skb2);
-next_frame:
-                       skb2 = skb_dequeue(&dev->rx_frames);
-               }
-               break;
-
-       /* software-driven interface shutdown */
-       case -ECONNRESET:               /* unlink */
-       case -ESHUTDOWN:                /* disconnect etc */
-               VDBG(dev, "rx shutdown, code %d\n", status);
-               goto quiesce;
-
-       /* for hardware automagic (such as pxa) */
-       case -ECONNABORTED:             /* endpoint reset */
-               DBG(dev, "rx %s reset\n", ep->name);
-               defer_kevent(dev, WORK_RX_MEMORY);
-quiesce:
-               dev_kfree_skb_any(skb);
-               goto clean;
-
-       /* data overrun */
-       case -EOVERFLOW:
-               dev->net->stats.rx_over_errors++;
-               /* FALLTHROUGH */
-
-       default:
-               dev->net->stats.rx_errors++;
-               DBG(dev, "rx status %d\n", status);
-               break;
-       }
-
-       if (skb)
-               dev_kfree_skb_any(skb);
-       if (!netif_running(dev->net)) {
-clean:
-               spin_lock(&dev->req_lock);
-               list_add(&req->list, &dev->rx_reqs);
-               spin_unlock(&dev->req_lock);
-               req = NULL;
-       }
-       if (req)
-               rx_submit(dev, req, GFP_ATOMIC);
-}
-
-static int prealloc(struct list_head *list, struct usb_ep *ep, unsigned n)
-{
-       unsigned                i;
-       struct usb_request      *req;
-
-       if (!n)
-               return -ENOMEM;
-
-       /* queue/recycle up to N requests */
-       i = n;
-       list_for_each_entry(req, list, list) {
-               if (i-- == 0)
-                       goto extra;
-       }
-       while (i--) {
-               req = usb_ep_alloc_request(ep, GFP_ATOMIC);
-               if (!req)
-                       return list_empty(list) ? -ENOMEM : 0;
-               list_add(&req->list, list);
-       }
-       return 0;
-
-extra:
-       /* free extras */
-       for (;;) {
-               struct list_head        *next;
-
-               next = req->list.next;
-               list_del(&req->list);
-               usb_ep_free_request(ep, req);
-
-               if (next == list)
-                       break;
-
-               req = container_of(next, struct usb_request, list);
-       }
-       return 0;
-}
-
-static int alloc_requests(struct eth_dev *dev, struct gether *link, unsigned n)
-{
-       int     status;
-
-       spin_lock(&dev->req_lock);
-       status = prealloc(&dev->tx_reqs, link->in_ep, n);
-       if (status < 0)
-               goto fail;
-       status = prealloc(&dev->rx_reqs, link->out_ep, n);
-       if (status < 0)
-               goto fail;
-       goto done;
-fail:
-       DBG(dev, "can't alloc requests\n");
-done:
-       spin_unlock(&dev->req_lock);
-       return status;
-}
-
-static void rx_fill(struct eth_dev *dev, gfp_t gfp_flags)
-{
-       struct usb_request      *req;
-       unsigned long           flags;
-
-       /* fill unused rxq slots with some skb */
-       spin_lock_irqsave(&dev->req_lock, flags);
-       while (!list_empty(&dev->rx_reqs)) {
-               req = container_of(dev->rx_reqs.next,
-                               struct usb_request, list);
-               list_del_init(&req->list);
-               spin_unlock_irqrestore(&dev->req_lock, flags);
-
-               if (rx_submit(dev, req, gfp_flags) < 0) {
-                       defer_kevent(dev, WORK_RX_MEMORY);
-                       return;
-               }
-
-               spin_lock_irqsave(&dev->req_lock, flags);
-       }
-       spin_unlock_irqrestore(&dev->req_lock, flags);
-}
-
-static void eth_work(struct work_struct *work)
-{
-       struct eth_dev  *dev = container_of(work, struct eth_dev, work);
-
-       if (test_and_clear_bit(WORK_RX_MEMORY, &dev->todo)) {
-               if (netif_running(dev->net))
-                       rx_fill(dev, GFP_KERNEL);
-       }
-
-       if (dev->todo)
-               DBG(dev, "work done, flags = 0x%lx\n", dev->todo);
-}
-
-static void tx_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       struct sk_buff  *skb = req->context;
-       struct eth_dev  *dev = ep->driver_data;
-
-       switch (req->status) {
-       default:
-               dev->net->stats.tx_errors++;
-               VDBG(dev, "tx err %d\n", req->status);
-               /* FALLTHROUGH */
-       case -ECONNRESET:               /* unlink */
-       case -ESHUTDOWN:                /* disconnect etc */
-               break;
-       case 0:
-               dev->net->stats.tx_bytes += skb->len;
-       }
-       dev->net->stats.tx_packets++;
-
-       spin_lock(&dev->req_lock);
-       list_add(&req->list, &dev->tx_reqs);
-       spin_unlock(&dev->req_lock);
-       dev_kfree_skb_any(skb);
-
-       atomic_dec(&dev->tx_qlen);
-       if (netif_carrier_ok(dev->net))
-               netif_wake_queue(dev->net);
-}
-
-static inline int is_promisc(u16 cdc_filter)
-{
-       return cdc_filter & USB_CDC_PACKET_TYPE_PROMISCUOUS;
-}
-
-static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
-                                       struct net_device *net)
-{
-       struct eth_dev          *dev = netdev_priv(net);
-       int                     length = skb->len;
-       int                     retval;
-       struct usb_request      *req = NULL;
-       unsigned long           flags;
-       struct usb_ep           *in;
-       u16                     cdc_filter;
-
-       spin_lock_irqsave(&dev->lock, flags);
-       if (dev->port_usb) {
-               in = dev->port_usb->in_ep;
-               cdc_filter = dev->port_usb->cdc_filter;
-       } else {
-               in = NULL;
-               cdc_filter = 0;
-       }
-       spin_unlock_irqrestore(&dev->lock, flags);
-
-       if (!in) {
-               dev_kfree_skb_any(skb);
-               return NETDEV_TX_OK;
-       }
-
-       /* apply outgoing CDC or RNDIS filters */
-       if (!is_promisc(cdc_filter)) {
-               u8              *dest = skb->data;
-
-               if (is_multicast_ether_addr(dest)) {
-                       u16     type;
-
-                       /* ignores USB_CDC_PACKET_TYPE_MULTICAST and host
-                        * SET_ETHERNET_MULTICAST_FILTERS requests
-                        */
-                       if (is_broadcast_ether_addr(dest))
-                               type = USB_CDC_PACKET_TYPE_BROADCAST;
-                       else
-                               type = USB_CDC_PACKET_TYPE_ALL_MULTICAST;
-                       if (!(cdc_filter & type)) {
-                               dev_kfree_skb_any(skb);
-                               return NETDEV_TX_OK;
-                       }
-               }
-               /* ignores USB_CDC_PACKET_TYPE_DIRECTED */
-       }
-
-       spin_lock_irqsave(&dev->req_lock, flags);
-       /*
-        * this freelist can be empty if an interrupt triggered disconnect()
-        * and reconfigured the gadget (shutting down this queue) after the
-        * network stack decided to xmit but before we got the spinlock.
-        */
-       if (list_empty(&dev->tx_reqs)) {
-               spin_unlock_irqrestore(&dev->req_lock, flags);
-               return NETDEV_TX_BUSY;
-       }
-
-       req = container_of(dev->tx_reqs.next, struct usb_request, list);
-       list_del(&req->list);
-
-       /* temporarily stop TX queue when the freelist empties */
-       if (list_empty(&dev->tx_reqs))
-               netif_stop_queue(net);
-       spin_unlock_irqrestore(&dev->req_lock, flags);
-
-       /* no buffer copies needed, unless the network stack did it
-        * or the hardware can't use skb buffers.
-        * or there's not enough space for extra headers we need
-        */
-       if (dev->wrap) {
-               unsigned long   flags;
-
-               spin_lock_irqsave(&dev->lock, flags);
-               if (dev->port_usb)
-                       skb = dev->wrap(dev->port_usb, skb);
-               spin_unlock_irqrestore(&dev->lock, flags);
-               if (!skb)
-                       goto drop;
-
-               length = skb->len;
-       }
-       req->buf = skb->data;
-       req->context = skb;
-       req->complete = tx_complete;
-
-       /* NCM requires no zlp if transfer is dwNtbInMaxSize */
-       if (dev->port_usb->is_fixed &&
-           length == dev->port_usb->fixed_in_len &&
-           (length % in->maxpacket) == 0)
-               req->zero = 0;
-       else
-               req->zero = 1;
-
-       /* use zlp framing on tx for strict CDC-Ether conformance,
-        * though any robust network rx path ignores extra padding.
-        * and some hardware doesn't like to write zlps.
-        */
-       if (req->zero && !dev->zlp && (length % in->maxpacket) == 0)
-               length++;
-
-       req->length = length;
-
-       /* throttle high/super speed IRQ rate back slightly */
-       if (gadget_is_dualspeed(dev->gadget))
-               req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH ||
-                                    dev->gadget->speed == USB_SPEED_SUPER)
-                       ? ((atomic_read(&dev->tx_qlen) % qmult) != 0)
-                       : 0;
-
-       retval = usb_ep_queue(in, req, GFP_ATOMIC);
-       switch (retval) {
-       default:
-               DBG(dev, "tx queue err %d\n", retval);
-               break;
-       case 0:
-               net->trans_start = jiffies;
-               atomic_inc(&dev->tx_qlen);
-       }
-
-       if (retval) {
-               dev_kfree_skb_any(skb);
-drop:
-               dev->net->stats.tx_dropped++;
-               spin_lock_irqsave(&dev->req_lock, flags);
-               if (list_empty(&dev->tx_reqs))
-                       netif_start_queue(net);
-               list_add(&req->list, &dev->tx_reqs);
-               spin_unlock_irqrestore(&dev->req_lock, flags);
-       }
-       return NETDEV_TX_OK;
-}
-
-/*-------------------------------------------------------------------------*/
-
-static void eth_start(struct eth_dev *dev, gfp_t gfp_flags)
-{
-       DBG(dev, "%s\n", __func__);
-
-       /* fill the rx queue */
-       rx_fill(dev, gfp_flags);
-
-       /* and open the tx floodgates */
-       atomic_set(&dev->tx_qlen, 0);
-       netif_wake_queue(dev->net);
-}
-
-static int eth_open(struct net_device *net)
-{
-       struct eth_dev  *dev = netdev_priv(net);
-       struct gether   *link;
-
-       DBG(dev, "%s\n", __func__);
-       if (netif_carrier_ok(dev->net))
-               eth_start(dev, GFP_KERNEL);
-
-       spin_lock_irq(&dev->lock);
-       link = dev->port_usb;
-       if (link && link->open)
-               link->open(link);
-       spin_unlock_irq(&dev->lock);
-
-       return 0;
-}
-
-static int eth_stop(struct net_device *net)
-{
-       struct eth_dev  *dev = netdev_priv(net);
-       unsigned long   flags;
-
-       VDBG(dev, "%s\n", __func__);
-       netif_stop_queue(net);
-
-       DBG(dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld\n",
-               dev->net->stats.rx_packets, dev->net->stats.tx_packets,
-               dev->net->stats.rx_errors, dev->net->stats.tx_errors
-               );
-
-       /* ensure there are no more active requests */
-       spin_lock_irqsave(&dev->lock, flags);
-       if (dev->port_usb) {
-               struct gether   *link = dev->port_usb;
-
-               if (link->close)
-                       link->close(link);
-
-               /* NOTE:  we have no abort-queue primitive we could use
-                * to cancel all pending I/O.  Instead, we disable then
-                * reenable the endpoints ... this idiom may leave toggle
-                * wrong, but that's a self-correcting error.
-                *
-                * REVISIT:  we *COULD* just let the transfers complete at
-                * their own pace; the network stack can handle old packets.
-                * For the moment we leave this here, since it works.
-                */
-               usb_ep_disable(link->in_ep);
-               usb_ep_disable(link->out_ep);
-               if (netif_carrier_ok(net)) {
-                       DBG(dev, "host still using in/out endpoints\n");
-                       usb_ep_enable(link->in_ep);
-                       usb_ep_enable(link->out_ep);
-               }
-       }
-       spin_unlock_irqrestore(&dev->lock, flags);
-
-       return 0;
-}
-
-/*-------------------------------------------------------------------------*/
-
-/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
-static char *dev_addr;
-module_param(dev_addr, charp, S_IRUGO);
-MODULE_PARM_DESC(dev_addr, "Device Ethernet Address");
-
-/* this address is invisible to ifconfig */
-static char *host_addr;
-module_param(host_addr, charp, S_IRUGO);
-MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
-
-static int get_ether_addr(const char *str, u8 *dev_addr)
-{
-       if (str) {
-               unsigned        i;
-
-               for (i = 0; i < 6; i++) {
-                       unsigned char num;
-
-                       if ((*str == '.') || (*str == ':'))
-                               str++;
-                       num = hex_to_bin(*str++) << 4;
-                       num |= hex_to_bin(*str++);
-                       dev_addr [i] = num;
-               }
-               if (is_valid_ether_addr(dev_addr))
-                       return 0;
-       }
-       eth_random_addr(dev_addr);
-       return 1;
-}
-
-static struct eth_dev *the_dev;
-
-static const struct net_device_ops eth_netdev_ops = {
-       .ndo_open               = eth_open,
-       .ndo_stop               = eth_stop,
-       .ndo_start_xmit         = eth_start_xmit,
-       .ndo_change_mtu         = ueth_change_mtu,
-       .ndo_set_mac_address    = eth_mac_addr,
-       .ndo_validate_addr      = eth_validate_addr,
-};
-
-static struct device_type gadget_type = {
-       .name   = "gadget",
-};
-
-/**
- * gether_setup_name - initialize one ethernet-over-usb link
- * @g: gadget to associated with these links
- * @ethaddr: NULL, or a buffer in which the ethernet address of the
- *     host side of the link is recorded
- * @netname: name for network device (for example, "usb")
- * Context: may sleep
- *
- * This sets up the single network link that may be exported by a
- * gadget driver using this framework.  The link layer addresses are
- * set up using module parameters.
- *
- * Returns negative errno, or zero on success
- */
-int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
-               const char *netname)
-{
-       struct eth_dev          *dev;
-       struct net_device       *net;
-       int                     status;
-
-       if (the_dev)
-               return -EBUSY;
-
-       net = alloc_etherdev(sizeof *dev);
-       if (!net)
-               return -ENOMEM;
-
-       dev = netdev_priv(net);
-       spin_lock_init(&dev->lock);
-       spin_lock_init(&dev->req_lock);
-       INIT_WORK(&dev->work, eth_work);
-       INIT_LIST_HEAD(&dev->tx_reqs);
-       INIT_LIST_HEAD(&dev->rx_reqs);
-
-       skb_queue_head_init(&dev->rx_frames);
-
-       /* network device setup */
-       dev->net = net;
-       snprintf(net->name, sizeof(net->name), "%s%%d", netname);
-
-       if (get_ether_addr(dev_addr, net->dev_addr))
-               dev_warn(&g->dev,
-                       "using random %s ethernet address\n", "self");
-       if (get_ether_addr(host_addr, dev->host_mac))
-               dev_warn(&g->dev,
-                       "using random %s ethernet address\n", "host");
-
-       if (ethaddr)
-               memcpy(ethaddr, dev->host_mac, ETH_ALEN);
-
-       net->netdev_ops = &eth_netdev_ops;
-
-       SET_ETHTOOL_OPS(net, &ops);
-
-       dev->gadget = g;
-       SET_NETDEV_DEV(net, &g->dev);
-       SET_NETDEV_DEVTYPE(net, &gadget_type);
-
-       status = register_netdev(net);
-       if (status < 0) {
-               dev_dbg(&g->dev, "register_netdev failed, %d\n", status);
-               free_netdev(net);
-       } else {
-               INFO(dev, "MAC %pM\n", net->dev_addr);
-               INFO(dev, "HOST MAC %pM\n", dev->host_mac);
-
-               the_dev = dev;
-
-               /* two kinds of host-initiated state changes:
-                *  - iff DATA transfer is active, carrier is "on"
-                *  - tx queueing enabled if open *and* carrier is "on"
-                */
-               netif_carrier_off(net);
-       }
-
-       return status;
-}
-
-/**
- * gether_cleanup - remove Ethernet-over-USB device
- * Context: may sleep
- *
- * This is called to free all resources allocated by @gether_setup().
- */
-void gether_cleanup(void)
-{
-       if (!the_dev)
-               return;
-
-       unregister_netdev(the_dev->net);
-       flush_work(&the_dev->work);
-       free_netdev(the_dev->net);
-
-       the_dev = NULL;
-}
-
-
-/**
- * gether_connect - notify network layer that USB link is active
- * @link: the USB link, set up with endpoints, descriptors matching
- *     current device speed, and any framing wrapper(s) set up.
- * Context: irqs blocked
- *
- * This is called to activate endpoints and let the network layer know
- * the connection is active ("carrier detect").  It may cause the I/O
- * queues to open and start letting network packets flow, but will in
- * any case activate the endpoints so that they respond properly to the
- * USB host.
- *
- * Verify net_device pointer returned using IS_ERR().  If it doesn't
- * indicate some error code (negative errno), ep->driver_data values
- * have been overwritten.
- */
-struct net_device *gether_connect(struct gether *link)
-{
-       struct eth_dev          *dev = the_dev;
-       int                     result = 0;
-
-       if (!dev)
-               return ERR_PTR(-EINVAL);
-
-       link->in_ep->driver_data = dev;
-       result = usb_ep_enable(link->in_ep);
-       if (result != 0) {
-               DBG(dev, "enable %s --> %d\n",
-                       link->in_ep->name, result);
-               goto fail0;
-       }
-
-       link->out_ep->driver_data = dev;
-       result = usb_ep_enable(link->out_ep);
-       if (result != 0) {
-               DBG(dev, "enable %s --> %d\n",
-                       link->out_ep->name, result);
-               goto fail1;
-       }
-
-       if (result == 0)
-               result = alloc_requests(dev, link, qlen(dev->gadget));
-
-       if (result == 0) {
-               dev->zlp = link->is_zlp_ok;
-               DBG(dev, "qlen %d\n", qlen(dev->gadget));
-
-               dev->header_len = link->header_len;
-               dev->unwrap = link->unwrap;
-               dev->wrap = link->wrap;
-
-               spin_lock(&dev->lock);
-               dev->port_usb = link;
-               link->ioport = dev;
-               if (netif_running(dev->net)) {
-                       if (link->open)
-                               link->open(link);
-               } else {
-                       if (link->close)
-                               link->close(link);
-               }
-               spin_unlock(&dev->lock);
-
-               netif_carrier_on(dev->net);
-               if (netif_running(dev->net))
-                       eth_start(dev, GFP_ATOMIC);
-
-       /* on error, disable any endpoints  */
-       } else {
-               (void) usb_ep_disable(link->out_ep);
-fail1:
-               (void) usb_ep_disable(link->in_ep);
-       }
-fail0:
-       /* caller is responsible for cleanup on error */
-       if (result < 0)
-               return ERR_PTR(result);
-       return dev->net;
-}
-
-/**
- * gether_disconnect - notify network layer that USB link is inactive
- * @link: the USB link, on which gether_connect() was called
- * Context: irqs blocked
- *
- * This is called to deactivate endpoints and let the network layer know
- * the connection went inactive ("no carrier").
- *
- * On return, the state is as if gether_connect() had never been called.
- * The endpoints are inactive, and accordingly without active USB I/O.
- * Pointers to endpoint descriptors and endpoint private data are nulled.
- */
-void gether_disconnect(struct gether *link)
-{
-       struct eth_dev          *dev = link->ioport;
-       struct usb_request      *req;
-
-       WARN_ON(!dev);
-       if (!dev)
-               return;
-
-       DBG(dev, "%s\n", __func__);
-
-       netif_stop_queue(dev->net);
-       netif_carrier_off(dev->net);
-
-       /* disable endpoints, forcing (synchronous) completion
-        * of all pending i/o.  then free the request objects
-        * and forget about the endpoints.
-        */
-       usb_ep_disable(link->in_ep);
-       spin_lock(&dev->req_lock);
-       while (!list_empty(&dev->tx_reqs)) {
-               req = container_of(dev->tx_reqs.next,
-                                       struct usb_request, list);
-               list_del(&req->list);
-
-               spin_unlock(&dev->req_lock);
-               usb_ep_free_request(link->in_ep, req);
-               spin_lock(&dev->req_lock);
-       }
-       spin_unlock(&dev->req_lock);
-       link->in_ep->driver_data = NULL;
-       link->in_ep->desc = NULL;
-
-       usb_ep_disable(link->out_ep);
-       spin_lock(&dev->req_lock);
-       while (!list_empty(&dev->rx_reqs)) {
-               req = container_of(dev->rx_reqs.next,
-                                       struct usb_request, list);
-               list_del(&req->list);
-
-               spin_unlock(&dev->req_lock);
-               usb_ep_free_request(link->out_ep, req);
-               spin_lock(&dev->req_lock);
-       }
-       spin_unlock(&dev->req_lock);
-       link->out_ep->driver_data = NULL;
-       link->out_ep->desc = NULL;
-
-       /* finish forgetting about this USB link episode */
-       dev->header_len = 0;
-       dev->unwrap = NULL;
-       dev->wrap = NULL;
-
-       spin_lock(&dev->lock);
-       dev->port_usb = NULL;
-       link->ioport = NULL;
-       spin_unlock(&dev->lock);
-}
diff --git a/drivers/staging/ccg/u_ether.h b/drivers/staging/ccg/u_ether.h
deleted file mode 100644 (file)
index 6f4a162..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * u_ether.h -- interface to USB gadget "ethernet link" utilities
- *
- * Copyright (C) 2003-2005,2008 David Brownell
- * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
- * Copyright (C) 2008 Nokia Corporation
- *
- * 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.
- */
-
-#ifndef __U_ETHER_H
-#define __U_ETHER_H
-
-#include <linux/err.h>
-#include <linux/if_ether.h>
-#include <linux/usb/composite.h>
-#include <linux/usb/cdc.h>
-
-#include "gadget_chips.h"
-
-
-/*
- * This represents the USB side of an "ethernet" link, managed by a USB
- * function which provides control and (maybe) framing.  Two functions
- * in different configurations could share the same ethernet link/netdev,
- * using different host interaction models.
- *
- * There is a current limitation that only one instance of this link may
- * be present in any given configuration.  When that's a problem, network
- * layer facilities can be used to package multiple logical links on this
- * single "physical" one.
- */
-struct gether {
-       struct usb_function             func;
-
-       /* updated by gether_{connect,disconnect} */
-       struct eth_dev                  *ioport;
-
-       /* endpoints handle full and/or high speeds */
-       struct usb_ep                   *in_ep;
-       struct usb_ep                   *out_ep;
-
-       bool                            is_zlp_ok;
-
-       u16                             cdc_filter;
-
-       /* hooks for added framing, as needed for RNDIS and EEM. */
-       u32                             header_len;
-       /* NCM requires fixed size bundles */
-       bool                            is_fixed;
-       u32                             fixed_out_len;
-       u32                             fixed_in_len;
-       struct sk_buff                  *(*wrap)(struct gether *port,
-                                               struct sk_buff *skb);
-       int                             (*unwrap)(struct gether *port,
-                                               struct sk_buff *skb,
-                                               struct sk_buff_head *list);
-
-       /* called on network open/close */
-       void                            (*open)(struct gether *);
-       void                            (*close)(struct gether *);
-};
-
-#define        DEFAULT_FILTER  (USB_CDC_PACKET_TYPE_BROADCAST \
-                       |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
-                       |USB_CDC_PACKET_TYPE_PROMISCUOUS \
-                       |USB_CDC_PACKET_TYPE_DIRECTED)
-
-/* variant of gether_setup that allows customizing network device name */
-int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
-               const char *netname);
-
-/* netdev setup/teardown as directed by the gadget driver */
-/* gether_setup - initialize one ethernet-over-usb link
- * @g: gadget to associated with these links
- * @ethaddr: NULL, or a buffer in which the ethernet address of the
- *     host side of the link is recorded
- * Context: may sleep
- *
- * This sets up the single network link that may be exported by a
- * gadget driver using this framework.  The link layer addresses are
- * set up using module parameters.
- *
- * Returns negative errno, or zero on success
- */
-static inline int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
-{
-       return gether_setup_name(g, ethaddr, "usb");
-}
-
-void gether_cleanup(void);
-
-/* connect/disconnect is handled by individual functions */
-struct net_device *gether_connect(struct gether *);
-void gether_disconnect(struct gether *);
-
-/* Some controllers can't support CDC Ethernet (ECM) ... */
-static inline bool can_support_ecm(struct usb_gadget *gadget)
-{
-       if (!gadget_supports_altsettings(gadget))
-               return false;
-
-       /* Everything else is *presumably* fine ... but this is a bit
-        * chancy, so be **CERTAIN** there are no hardware issues with
-        * your controller.  Add it above if it can't handle CDC.
-        */
-       return true;
-}
-
-/* each configuration may bind one instance of an ethernet link */
-int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
-int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
-int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
-int eem_bind_config(struct usb_configuration *c);
-
-#ifdef USB_ETH_RNDIS
-
-int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
-                               u32 vendorID, const char *manufacturer);
-
-#else
-
-static inline int
-rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
-                               u32 vendorID, const char *manufacturer)
-{
-       return 0;
-}
-
-#endif
-
-/**
- * rndis_bind_config - add RNDIS network link to a configuration
- * @c: the configuration to support the network link
- * @ethaddr: a buffer in which the ethernet address of the host side
- *     side of the link was recorded
- * Context: single threaded during gadget setup
- *
- * Returns zero on success, else negative errno.
- *
- * Caller must have called @gether_setup().  Caller is also responsible
- * for calling @gether_cleanup() before module unload.
- */
-static inline int rndis_bind_config(struct usb_configuration *c,
-                                   u8 ethaddr[ETH_ALEN])
-{
-       return rndis_bind_config_vendor(c, ethaddr, 0, NULL);
-}
-
-
-#endif /* __U_ETHER_H */
diff --git a/drivers/staging/ccg/u_serial.c b/drivers/staging/ccg/u_serial.c
deleted file mode 100644 (file)
index b10947a..0000000
+++ /dev/null
@@ -1,1339 +0,0 @@
-/*
- * u_serial.c - utilities for USB gadget "serial port"/TTY support
- *
- * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
- * Copyright (C) 2008 David Brownell
- * Copyright (C) 2008 by Nokia Corporation
- *
- * This code also borrows from usbserial.c, which is
- * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
- * Copyright (C) 2000 Peter Berger (pberger@brimson.com)
- * Copyright (C) 2000 Al Borchers (alborchers@steinerpoint.com)
- *
- * This software is 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.
- */
-
-/* #define VERBOSE_DEBUG */
-
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/interrupt.h>
-#include <linux/device.h>
-#include <linux/delay.h>
-#include <linux/tty.h>
-#include <linux/tty_flip.h>
-#include <linux/slab.h>
-#include <linux/export.h>
-
-#include "u_serial.h"
-
-
-/*
- * This component encapsulates the TTY layer glue needed to provide basic
- * "serial port" functionality through the USB gadget stack.  Each such
- * port is exposed through a /dev/ttyGS* node.
- *
- * After initialization (gserial_setup), these TTY port devices stay
- * available until they are removed (gserial_cleanup).  Each one may be
- * connected to a USB function (gserial_connect), or disconnected (with
- * gserial_disconnect) when the USB host issues a config change event.
- * Data can only flow when the port is connected to the host.
- *
- * A given TTY port can be made available in multiple configurations.
- * For example, each one might expose a ttyGS0 node which provides a
- * login application.  In one case that might use CDC ACM interface 0,
- * while another configuration might use interface 3 for that.  The
- * work to handle that (including descriptor management) is not part
- * of this component.
- *
- * Configurations may expose more than one TTY port.  For example, if
- * ttyGS0 provides login service, then ttyGS1 might provide dialer access
- * for a telephone or fax link.  And ttyGS2 might be something that just
- * needs a simple byte stream interface for some messaging protocol that
- * is managed in userspace ... OBEX, PTP, and MTP have been mentioned.
- */
-
-#define PREFIX "ttyGS"
-
-/*
- * gserial is the lifecycle interface, used by USB functions
- * gs_port is the I/O nexus, used by the tty driver
- * tty_struct links to the tty/filesystem framework
- *
- * gserial <---> gs_port ... links will be null when the USB link is
- * inactive; managed by gserial_{connect,disconnect}().  each gserial
- * instance can wrap its own USB control protocol.
- *     gserial->ioport == usb_ep->driver_data ... gs_port
- *     gs_port->port_usb ... gserial
- *
- * gs_port <---> tty_struct ... links will be null when the TTY file
- * isn't opened; managed by gs_open()/gs_close()
- *     gserial->port_tty ... tty_struct
- *     tty_struct->driver_data ... gserial
- */
-
-/* RX and TX queues can buffer QUEUE_SIZE packets before they hit the
- * next layer of buffering.  For TX that's a circular buffer; for RX
- * consider it a NOP.  A third layer is provided by the TTY code.
- */
-#define QUEUE_SIZE             16
-#define WRITE_BUF_SIZE         8192            /* TX only */
-
-/* circular buffer */
-struct gs_buf {
-       unsigned                buf_size;
-       char                    *buf_buf;
-       char                    *buf_get;
-       char                    *buf_put;
-};
-
-/*
- * The port structure holds info for each port, one for each minor number
- * (and thus for each /dev/ node).
- */
-struct gs_port {
-       struct tty_port         port;
-       spinlock_t              port_lock;      /* guard port_* access */
-
-       struct gserial          *port_usb;
-
-       bool                    openclose;      /* open/close in progress */
-       u8                      port_num;
-
-       struct list_head        read_pool;
-       int read_started;
-       int read_allocated;
-       struct list_head        read_queue;
-       unsigned                n_read;
-       struct tasklet_struct   push;
-
-       struct list_head        write_pool;
-       int write_started;
-       int write_allocated;
-       struct gs_buf           port_write_buf;
-       wait_queue_head_t       drain_wait;     /* wait while writes drain */
-
-       /* REVISIT this state ... */
-       struct usb_cdc_line_coding port_line_coding;    /* 8-N-1 etc */
-};
-
-/* increase N_PORTS if you need more */
-#define N_PORTS                4
-static struct portmaster {
-       struct mutex    lock;                   /* protect open/close */
-       struct gs_port  *port;
-} ports[N_PORTS];
-static unsigned        n_ports;
-
-#define GS_CLOSE_TIMEOUT               15              /* seconds */
-
-
-
-#ifdef VERBOSE_DEBUG
-#define pr_vdebug(fmt, arg...) \
-       pr_debug(fmt, ##arg)
-#else
-#define pr_vdebug(fmt, arg...) \
-       ({ if (0) pr_debug(fmt, ##arg); })
-#endif
-
-/*-------------------------------------------------------------------------*/
-
-/* Circular Buffer */
-
-/*
- * gs_buf_alloc
- *
- * Allocate a circular buffer and all associated memory.
- */
-static int gs_buf_alloc(struct gs_buf *gb, unsigned size)
-{
-       gb->buf_buf = kmalloc(size, GFP_KERNEL);
-       if (gb->buf_buf == NULL)
-               return -ENOMEM;
-
-       gb->buf_size = size;
-       gb->buf_put = gb->buf_buf;
-       gb->buf_get = gb->buf_buf;
-
-       return 0;
-}
-
-/*
- * gs_buf_free
- *
- * Free the buffer and all associated memory.
- */
-static void gs_buf_free(struct gs_buf *gb)
-{
-       kfree(gb->buf_buf);
-       gb->buf_buf = NULL;
-}
-
-/*
- * gs_buf_clear
- *
- * Clear out all data in the circular buffer.
- */
-static void gs_buf_clear(struct gs_buf *gb)
-{
-       gb->buf_get = gb->buf_put;
-       /* equivalent to a get of all data available */
-}
-
-/*
- * gs_buf_data_avail
- *
- * Return the number of bytes of data written into the circular
- * buffer.
- */
-static unsigned gs_buf_data_avail(struct gs_buf *gb)
-{
-       return (gb->buf_size + gb->buf_put - gb->buf_get) % gb->buf_size;
-}
-
-/*
- * gs_buf_space_avail
- *
- * Return the number of bytes of space available in the circular
- * buffer.
- */
-static unsigned gs_buf_space_avail(struct gs_buf *gb)
-{
-       return (gb->buf_size + gb->buf_get - gb->buf_put - 1) % gb->buf_size;
-}
-
-/*
- * gs_buf_put
- *
- * Copy data data from a user buffer and put it into the circular buffer.
- * Restrict to the amount of space available.
- *
- * Return the number of bytes copied.
- */
-static unsigned
-gs_buf_put(struct gs_buf *gb, const char *buf, unsigned count)
-{
-       unsigned len;
-
-       len  = gs_buf_space_avail(gb);
-       if (count > len)
-               count = len;
-
-       if (count == 0)
-               return 0;
-
-       len = gb->buf_buf + gb->buf_size - gb->buf_put;
-       if (count > len) {
-               memcpy(gb->buf_put, buf, len);
-               memcpy(gb->buf_buf, buf+len, count - len);
-               gb->buf_put = gb->buf_buf + count - len;
-       } else {
-               memcpy(gb->buf_put, buf, count);
-               if (count < len)
-                       gb->buf_put += count;
-               else /* count == len */
-                       gb->buf_put = gb->buf_buf;
-       }
-
-       return count;
-}
-
-/*
- * gs_buf_get
- *
- * Get data from the circular buffer and copy to the given buffer.
- * Restrict to the amount of data available.
- *
- * Return the number of bytes copied.
- */
-static unsigned
-gs_buf_get(struct gs_buf *gb, char *buf, unsigned count)
-{
-       unsigned len;
-
-       len = gs_buf_data_avail(gb);
-       if (count > len)
-               count = len;
-
-       if (count == 0)
-               return 0;
-
-       len = gb->buf_buf + gb->buf_size - gb->buf_get;
-       if (count > len) {
-               memcpy(buf, gb->buf_get, len);
-               memcpy(buf+len, gb->buf_buf, count - len);
-               gb->buf_get = gb->buf_buf + count - len;
-       } else {
-               memcpy(buf, gb->buf_get, count);
-               if (count < len)
-                       gb->buf_get += count;
-               else /* count == len */
-                       gb->buf_get = gb->buf_buf;
-       }
-
-       return count;
-}
-
-/*-------------------------------------------------------------------------*/
-
-/* I/O glue between TTY (upper) and USB function (lower) driver layers */
-
-/*
- * gs_alloc_req
- *
- * Allocate a usb_request and its buffer.  Returns a pointer to the
- * usb_request or NULL if there is an error.
- */
-struct usb_request *
-gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t kmalloc_flags)
-{
-       struct usb_request *req;
-
-       req = usb_ep_alloc_request(ep, kmalloc_flags);
-
-       if (req != NULL) {
-               req->length = len;
-               req->buf = kmalloc(len, kmalloc_flags);
-               if (req->buf == NULL) {
-                       usb_ep_free_request(ep, req);
-                       return NULL;
-               }
-       }
-
-       return req;
-}
-
-/*
- * gs_free_req
- *
- * Free a usb_request and its buffer.
- */
-void gs_free_req(struct usb_ep *ep, struct usb_request *req)
-{
-       kfree(req->buf);
-       usb_ep_free_request(ep, req);
-}
-
-/*
- * gs_send_packet
- *
- * If there is data to send, a packet is built in the given
- * buffer and the size is returned.  If there is no data to
- * send, 0 is returned.
- *
- * Called with port_lock held.
- */
-static unsigned
-gs_send_packet(struct gs_port *port, char *packet, unsigned size)
-{
-       unsigned len;
-
-       len = gs_buf_data_avail(&port->port_write_buf);
-       if (len < size)
-               size = len;
-       if (size != 0)
-               size = gs_buf_get(&port->port_write_buf, packet, size);
-       return size;
-}
-
-/*
- * gs_start_tx
- *
- * This function finds available write requests, calls
- * gs_send_packet to fill these packets with data, and
- * continues until either there are no more write requests
- * available or no more data to send.  This function is
- * run whenever data arrives or write requests are available.
- *
- * Context: caller owns port_lock; port_usb is non-null.
- */
-static int gs_start_tx(struct gs_port *port)
-/*
-__releases(&port->port_lock)
-__acquires(&port->port_lock)
-*/
-{
-       struct list_head        *pool = &port->write_pool;
-       struct usb_ep           *in = port->port_usb->in;
-       int                     status = 0;
-       bool                    do_tty_wake = false;
-
-       while (!list_empty(pool)) {
-               struct usb_request      *req;
-               int                     len;
-
-               if (port->write_started >= QUEUE_SIZE)
-                       break;
-
-               req = list_entry(pool->next, struct usb_request, list);
-               len = gs_send_packet(port, req->buf, in->maxpacket);
-               if (len == 0) {
-                       wake_up_interruptible(&port->drain_wait);
-                       break;
-               }
-               do_tty_wake = true;
-
-               req->length = len;
-               list_del(&req->list);
-               req->zero = (gs_buf_data_avail(&port->port_write_buf) == 0);
-
-               pr_vdebug(PREFIX "%d: tx len=%d, 0x%02x 0x%02x 0x%02x ...\n",
-                               port->port_num, len, *((u8 *)req->buf),
-                               *((u8 *)req->buf+1), *((u8 *)req->buf+2));
-
-               /* Drop lock while we call out of driver; completions
-                * could be issued while we do so.  Disconnection may
-                * happen too; maybe immediately before we queue this!
-                *
-                * NOTE that we may keep sending data for a while after
-                * the TTY closed (dev->ioport->port_tty is NULL).
-                */
-               spin_unlock(&port->port_lock);
-               status = usb_ep_queue(in, req, GFP_ATOMIC);
-               spin_lock(&port->port_lock);
-
-               if (status) {
-                       pr_debug("%s: %s %s err %d\n",
-                                       __func__, "queue", in->name, status);
-                       list_add(&req->list, pool);
-                       break;
-               }
-
-               port->write_started++;
-
-               /* abort immediately after disconnect */
-               if (!port->port_usb)
-                       break;
-       }
-
-       if (do_tty_wake && port->port.tty)
-               tty_wakeup(port->port.tty);
-       return status;
-}
-
-/*
- * Context: caller owns port_lock, and port_usb is set
- */
-static unsigned gs_start_rx(struct gs_port *port)
-/*
-__releases(&port->port_lock)
-__acquires(&port->port_lock)
-*/
-{
-       struct list_head        *pool = &port->read_pool;
-       struct usb_ep           *out = port->port_usb->out;
-
-       while (!list_empty(pool)) {
-               struct usb_request      *req;
-               int                     status;
-               struct tty_struct       *tty;
-
-               /* no more rx if closed */
-               tty = port->port.tty;
-               if (!tty)
-                       break;
-
-               if (port->read_started >= QUEUE_SIZE)
-                       break;
-
-               req = list_entry(pool->next, struct usb_request, list);
-               list_del(&req->list);
-               req->length = out->maxpacket;
-
-               /* drop lock while we call out; the controller driver
-                * may need to call us back (e.g. for disconnect)
-                */
-               spin_unlock(&port->port_lock);
-               status = usb_ep_queue(out, req, GFP_ATOMIC);
-               spin_lock(&port->port_lock);
-
-               if (status) {
-                       pr_debug("%s: %s %s err %d\n",
-                                       __func__, "queue", out->name, status);
-                       list_add(&req->list, pool);
-                       break;
-               }
-               port->read_started++;
-
-               /* abort immediately after disconnect */
-               if (!port->port_usb)
-                       break;
-       }
-       return port->read_started;
-}
-
-/*
- * RX tasklet takes data out of the RX queue and hands it up to the TTY
- * layer until it refuses to take any more data (or is throttled back).
- * Then it issues reads for any further data.
- *
- * If the RX queue becomes full enough that no usb_request is queued,
- * the OUT endpoint may begin NAKing as soon as its FIFO fills up.
- * So QUEUE_SIZE packets plus however many the FIFO holds (usually two)
- * can be buffered before the TTY layer's buffers (currently 64 KB).
- */
-static void gs_rx_push(unsigned long _port)
-{
-       struct gs_port          *port = (void *)_port;
-       struct tty_struct       *tty;
-       struct list_head        *queue = &port->read_queue;
-       bool                    disconnect = false;
-       bool                    do_push = false;
-
-       /* hand any queued data to the tty */
-       spin_lock_irq(&port->port_lock);
-       tty = port->port.tty;
-       while (!list_empty(queue)) {
-               struct usb_request      *req;
-
-               req = list_first_entry(queue, struct usb_request, list);
-
-               /* leave data queued if tty was rx throttled */
-               if (tty && test_bit(TTY_THROTTLED, &tty->flags))
-                       break;
-
-               switch (req->status) {
-               case -ESHUTDOWN:
-                       disconnect = true;
-                       pr_vdebug(PREFIX "%d: shutdown\n", port->port_num);
-                       break;
-
-               default:
-                       /* presumably a transient fault */
-                       pr_warning(PREFIX "%d: unexpected RX status %d\n",
-                                       port->port_num, req->status);
-                       /* FALLTHROUGH */
-               case 0:
-                       /* normal completion */
-                       break;
-               }
-
-               /* push data to (open) tty */
-               if (req->actual) {
-                       char            *packet = req->buf;
-                       unsigned        size = req->actual;
-                       unsigned        n;
-                       int             count;
-
-                       /* we may have pushed part of this packet already... */
-                       n = port->n_read;
-                       if (n) {
-                               packet += n;
-                               size -= n;
-                       }
-
-                       count = tty_insert_flip_string(&port->port, packet, size);
-                       if (count)
-                               do_push = true;
-                       if (count != size) {
-                               /* stop pushing; TTY layer can't handle more */
-                               port->n_read += count;
-                               pr_vdebug(PREFIX "%d: rx block %d/%d\n",
-                                               port->port_num,
-                                               count, req->actual);
-                               break;
-                       }
-                       port->n_read = 0;
-               }
-               list_move(&req->list, &port->read_pool);
-               port->read_started--;
-       }
-
-       /* Push from tty to ldisc; without low_latency set this is handled by
-        * a workqueue, so we won't get callbacks and can hold port_lock
-        */
-       if (do_push)
-               tty_flip_buffer_push(&port->port);
-
-
-       /* We want our data queue to become empty ASAP, keeping data
-        * in the tty and ldisc (not here).  If we couldn't push any
-        * this time around, there may be trouble unless there's an
-        * implicit tty_unthrottle() call on its way...
-        *
-        * REVISIT we should probably add a timer to keep the tasklet
-        * from starving ... but it's not clear that case ever happens.
-        */
-       if (!list_empty(queue) && tty) {
-               if (!test_bit(TTY_THROTTLED, &tty->flags)) {
-                       if (do_push)
-                               tasklet_schedule(&port->push);
-                       else
-                               pr_warning(PREFIX "%d: RX not scheduled?\n",
-                                       port->port_num);
-               }
-       }
-
-       /* If we're still connected, refill the USB RX queue. */
-       if (!disconnect && port->port_usb)
-               gs_start_rx(port);
-
-       spin_unlock_irq(&port->port_lock);
-}
-
-static void gs_read_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       struct gs_port  *port = ep->driver_data;
-
-       /* Queue all received data until the tty layer is ready for it. */
-       spin_lock(&port->port_lock);
-       list_add_tail(&req->list, &port->read_queue);
-       tasklet_schedule(&port->push);
-       spin_unlock(&port->port_lock);
-}
-
-static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       struct gs_port  *port = ep->driver_data;
-
-       spin_lock(&port->port_lock);
-       list_add(&req->list, &port->write_pool);
-       port->write_started--;
-
-       switch (req->status) {
-       default:
-               /* presumably a transient fault */
-               pr_warning("%s: unexpected %s status %d\n",
-                               __func__, ep->name, req->status);
-               /* FALL THROUGH */
-       case 0:
-               /* normal completion */
-               gs_start_tx(port);
-               break;
-
-       case -ESHUTDOWN:
-               /* disconnect */
-               pr_vdebug("%s: %s shutdown\n", __func__, ep->name);
-               break;
-       }
-
-       spin_unlock(&port->port_lock);
-}
-
-static void gs_free_requests(struct usb_ep *ep, struct list_head *head,
-                                                        int *allocated)
-{
-       struct usb_request      *req;
-
-       while (!list_empty(head)) {
-               req = list_entry(head->next, struct usb_request, list);
-               list_del(&req->list);
-               gs_free_req(ep, req);
-               if (allocated)
-                       (*allocated)--;
-       }
-}
-
-static int gs_alloc_requests(struct usb_ep *ep, struct list_head *head,
-               void (*fn)(struct usb_ep *, struct usb_request *),
-               int *allocated)
-{
-       int                     i;
-       struct usb_request      *req;
-       int n = allocated ? QUEUE_SIZE - *allocated : QUEUE_SIZE;
-
-       /* Pre-allocate up to QUEUE_SIZE transfers, but if we can't
-        * do quite that many this time, don't fail ... we just won't
-        * be as speedy as we might otherwise be.
-        */
-       for (i = 0; i < n; i++) {
-               req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC);
-               if (!req)
-                       return list_empty(head) ? -ENOMEM : 0;
-               req->complete = fn;
-               list_add_tail(&req->list, head);
-               if (allocated)
-                       (*allocated)++;
-       }
-       return 0;
-}
-
-/**
- * gs_start_io - start USB I/O streams
- * @dev: encapsulates endpoints to use
- * Context: holding port_lock; port_tty and port_usb are non-null
- *
- * We only start I/O when something is connected to both sides of
- * this port.  If nothing is listening on the host side, we may
- * be pointlessly filling up our TX buffers and FIFO.
- */
-static int gs_start_io(struct gs_port *port)
-{
-       struct list_head        *head = &port->read_pool;
-       struct usb_ep           *ep = port->port_usb->out;
-       int                     status;
-       unsigned                started;
-
-       /* Allocate RX and TX I/O buffers.  We can't easily do this much
-        * earlier (with GFP_KERNEL) because the requests are coupled to
-        * endpoints, as are the packet sizes we'll be using.  Different
-        * configurations may use different endpoints with a given port;
-        * and high speed vs full speed changes packet sizes too.
-        */
-       status = gs_alloc_requests(ep, head, gs_read_complete,
-               &port->read_allocated);
-       if (status)
-               return status;
-
-       status = gs_alloc_requests(port->port_usb->in, &port->write_pool,
-                       gs_write_complete, &port->write_allocated);
-       if (status) {
-               gs_free_requests(ep, head, &port->read_allocated);
-               return status;
-       }
-
-       /* queue read requests */
-       port->n_read = 0;
-       started = gs_start_rx(port);
-
-       /* unblock any pending writes into our circular buffer */
-       if (started) {
-               tty_wakeup(port->port.tty);
-       } else {
-               gs_free_requests(ep, head, &port->read_allocated);
-               gs_free_requests(port->port_usb->in, &port->write_pool,
-                       &port->write_allocated);
-               status = -EIO;
-       }
-
-       return status;
-}
-
-/*-------------------------------------------------------------------------*/
-
-/* TTY Driver */
-
-/*
- * gs_open sets up the link between a gs_port and its associated TTY.
- * That link is broken *only* by TTY close(), and all driver methods
- * know that.
- */
-static int gs_open(struct tty_struct *tty, struct file *file)
-{
-       int             port_num = tty->index;
-       struct gs_port  *port;
-       int             status;
-
-       do {
-               mutex_lock(&ports[port_num].lock);
-               port = ports[port_num].port;
-               if (!port)
-                       status = -ENODEV;
-               else {
-                       spin_lock_irq(&port->port_lock);
-
-                       /* already open?  Great. */
-                       if (port->port.count) {
-                               status = 0;
-                               port->port.count++;
-
-                       /* currently opening/closing? wait ... */
-                       } else if (port->openclose) {
-                               status = -EBUSY;
-
-                       /* ... else we do the work */
-                       } else {
-                               status = -EAGAIN;
-                               port->openclose = true;
-                       }
-                       spin_unlock_irq(&port->port_lock);
-               }
-               mutex_unlock(&ports[port_num].lock);
-
-               switch (status) {
-               default:
-                       /* fully handled */
-                       return status;
-               case -EAGAIN:
-                       /* must do the work */
-                       break;
-               case -EBUSY:
-                       /* wait for EAGAIN task to finish */
-                       msleep(1);
-                       /* REVISIT could have a waitchannel here, if
-                        * concurrent open performance is important
-                        */
-                       break;
-               }
-       } while (status != -EAGAIN);
-
-       /* Do the "real open" */
-       spin_lock_irq(&port->port_lock);
-
-       /* allocate circular buffer on first open */
-       if (port->port_write_buf.buf_buf == NULL) {
-
-               spin_unlock_irq(&port->port_lock);
-               status = gs_buf_alloc(&port->port_write_buf, WRITE_BUF_SIZE);
-               spin_lock_irq(&port->port_lock);
-
-               if (status) {
-                       pr_debug("gs_open: ttyGS%d (%p,%p) no buffer\n",
-                               port->port_num, tty, file);
-                       port->openclose = false;
-                       goto exit_unlock_port;
-               }
-       }
-
-       /* REVISIT if REMOVED (ports[].port NULL), abort the open
-        * to let rmmod work faster (but this way isn't wrong).
-        */
-
-       /* REVISIT maybe wait for "carrier detect" */
-
-       tty->driver_data = port;
-       port->port.tty = tty;
-
-       port->port.count = 1;
-       port->openclose = false;
-
-       /* if connected, start the I/O stream */
-       if (port->port_usb) {
-               struct gserial  *gser = port->port_usb;
-
-               pr_debug("gs_open: start ttyGS%d\n", port->port_num);
-               gs_start_io(port);
-
-               if (gser->connect)
-                       gser->connect(gser);
-       }
-
-       pr_debug("gs_open: ttyGS%d (%p,%p)\n", port->port_num, tty, file);
-
-       status = 0;
-
-exit_unlock_port:
-       spin_unlock_irq(&port->port_lock);
-       return status;
-}
-
-static int gs_writes_finished(struct gs_port *p)
-{
-       int cond;
-
-       /* return true on disconnect or empty buffer */
-       spin_lock_irq(&p->port_lock);
-       cond = (p->port_usb == NULL) || !gs_buf_data_avail(&p->port_write_buf);
-       spin_unlock_irq(&p->port_lock);
-
-       return cond;
-}
-
-static void gs_close(struct tty_struct *tty, struct file *file)
-{
-       struct gs_port *port = tty->driver_data;
-       struct gserial  *gser;
-
-       spin_lock_irq(&port->port_lock);
-
-       if (port->port.count != 1) {
-               if (port->port.count == 0)
-                       WARN_ON(1);
-               else
-                       --port->port.count;
-               goto exit;
-       }
-
-       pr_debug("gs_close: ttyGS%d (%p,%p) ...\n", port->port_num, tty, file);
-
-       /* mark port as closing but in use; we can drop port lock
-        * and sleep if necessary
-        */
-       port->openclose = true;
-       port->port.count = 0;
-
-       gser = port->port_usb;
-       if (gser && gser->disconnect)
-               gser->disconnect(gser);
-
-       /* wait for circular write buffer to drain, disconnect, or at
-        * most GS_CLOSE_TIMEOUT seconds; then discard the rest
-        */
-       if (gs_buf_data_avail(&port->port_write_buf) > 0 && gser) {
-               spin_unlock_irq(&port->port_lock);
-               wait_event_interruptible_timeout(port->drain_wait,
-                                       gs_writes_finished(port),
-                                       GS_CLOSE_TIMEOUT * HZ);
-               spin_lock_irq(&port->port_lock);
-               gser = port->port_usb;
-       }
-
-       /* Iff we're disconnected, there can be no I/O in flight so it's
-        * ok to free the circular buffer; else just scrub it.  And don't
-        * let the push tasklet fire again until we're re-opened.
-        */
-       if (gser == NULL)
-               gs_buf_free(&port->port_write_buf);
-       else
-               gs_buf_clear(&port->port_write_buf);
-
-       tty->driver_data = NULL;
-       port->port.tty = NULL;
-
-       port->openclose = false;
-
-       pr_debug("gs_close: ttyGS%d (%p,%p) done!\n",
-                       port->port_num, tty, file);
-
-       wake_up_interruptible(&port->port.close_wait);
-exit:
-       spin_unlock_irq(&port->port_lock);
-}
-
-static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count)
-{
-       struct gs_port  *port = tty->driver_data;
-       unsigned long   flags;
-       int             status;
-
-       pr_vdebug("gs_write: ttyGS%d (%p) writing %d bytes\n",
-                       port->port_num, tty, count);
-
-       spin_lock_irqsave(&port->port_lock, flags);
-       if (count)
-               count = gs_buf_put(&port->port_write_buf, buf, count);
-       /* treat count == 0 as flush_chars() */
-       if (port->port_usb)
-               status = gs_start_tx(port);
-       spin_unlock_irqrestore(&port->port_lock, flags);
-
-       return count;
-}
-
-static int gs_put_char(struct tty_struct *tty, unsigned char ch)
-{
-       struct gs_port  *port = tty->driver_data;
-       unsigned long   flags;
-       int             status;
-
-       pr_vdebug("gs_put_char: (%d,%p) char=0x%x, called from %pf\n",
-               port->port_num, tty, ch, __builtin_return_address(0));
-
-       spin_lock_irqsave(&port->port_lock, flags);
-       status = gs_buf_put(&port->port_write_buf, &ch, 1);
-       spin_unlock_irqrestore(&port->port_lock, flags);
-
-       return status;
-}
-
-static void gs_flush_chars(struct tty_struct *tty)
-{
-       struct gs_port  *port = tty->driver_data;
-       unsigned long   flags;
-
-       pr_vdebug("gs_flush_chars: (%d,%p)\n", port->port_num, tty);
-
-       spin_lock_irqsave(&port->port_lock, flags);
-       if (port->port_usb)
-               gs_start_tx(port);
-       spin_unlock_irqrestore(&port->port_lock, flags);
-}
-
-static int gs_write_room(struct tty_struct *tty)
-{
-       struct gs_port  *port = tty->driver_data;
-       unsigned long   flags;
-       int             room = 0;
-
-       spin_lock_irqsave(&port->port_lock, flags);
-       if (port->port_usb)
-               room = gs_buf_space_avail(&port->port_write_buf);
-       spin_unlock_irqrestore(&port->port_lock, flags);
-
-       pr_vdebug("gs_write_room: (%d,%p) room=%d\n",
-               port->port_num, tty, room);
-
-       return room;
-}
-
-static int gs_chars_in_buffer(struct tty_struct *tty)
-{
-       struct gs_port  *port = tty->driver_data;
-       unsigned long   flags;
-       int             chars = 0;
-
-       spin_lock_irqsave(&port->port_lock, flags);
-       chars = gs_buf_data_avail(&port->port_write_buf);
-       spin_unlock_irqrestore(&port->port_lock, flags);
-
-       pr_vdebug("gs_chars_in_buffer: (%d,%p) chars=%d\n",
-               port->port_num, tty, chars);
-
-       return chars;
-}
-
-/* undo side effects of setting TTY_THROTTLED */
-static void gs_unthrottle(struct tty_struct *tty)
-{
-       struct gs_port          *port = tty->driver_data;
-       unsigned long           flags;
-
-       spin_lock_irqsave(&port->port_lock, flags);
-       if (port->port_usb) {
-               /* Kickstart read queue processing.  We don't do xon/xoff,
-                * rts/cts, or other handshaking with the host, but if the
-                * read queue backs up enough we'll be NAKing OUT packets.
-                */
-               tasklet_schedule(&port->push);
-               pr_vdebug(PREFIX "%d: unthrottle\n", port->port_num);
-       }
-       spin_unlock_irqrestore(&port->port_lock, flags);
-}
-
-static int gs_break_ctl(struct tty_struct *tty, int duration)
-{
-       struct gs_port  *port = tty->driver_data;
-       int             status = 0;
-       struct gserial  *gser;
-
-       pr_vdebug("gs_break_ctl: ttyGS%d, send break (%d) \n",
-                       port->port_num, duration);
-
-       spin_lock_irq(&port->port_lock);
-       gser = port->port_usb;
-       if (gser && gser->send_break)
-               status = gser->send_break(gser, duration);
-       spin_unlock_irq(&port->port_lock);
-
-       return status;
-}
-
-static const struct tty_operations gs_tty_ops = {
-       .open =                 gs_open,
-       .close =                gs_close,
-       .write =                gs_write,
-       .put_char =             gs_put_char,
-       .flush_chars =          gs_flush_chars,
-       .write_room =           gs_write_room,
-       .chars_in_buffer =      gs_chars_in_buffer,
-       .unthrottle =           gs_unthrottle,
-       .break_ctl =            gs_break_ctl,
-};
-
-/*-------------------------------------------------------------------------*/
-
-static struct tty_driver *gs_tty_driver;
-
-static int
-gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
-{
-       struct gs_port  *port;
-
-       port = kzalloc(sizeof(struct gs_port), GFP_KERNEL);
-       if (port == NULL)
-               return -ENOMEM;
-
-       tty_port_init(&port->port);
-       spin_lock_init(&port->port_lock);
-       init_waitqueue_head(&port->drain_wait);
-
-       tasklet_init(&port->push, gs_rx_push, (unsigned long) port);
-
-       INIT_LIST_HEAD(&port->read_pool);
-       INIT_LIST_HEAD(&port->read_queue);
-       INIT_LIST_HEAD(&port->write_pool);
-
-       port->port_num = port_num;
-       port->port_line_coding = *coding;
-
-       ports[port_num].port = port;
-
-       return 0;
-}
-
-/**
- * gserial_setup - initialize TTY driver for one or more ports
- * @g: gadget to associate with these ports
- * @count: how many ports to support
- * Context: may sleep
- *
- * The TTY stack needs to know in advance how many devices it should
- * plan to manage.  Use this call to set up the ports you will be
- * exporting through USB.  Later, connect them to functions based
- * on what configuration is activated by the USB host; and disconnect
- * them as appropriate.
- *
- * An example would be a two-configuration device in which both
- * configurations expose port 0, but through different functions.
- * One configuration could even expose port 1 while the other
- * one doesn't.
- *
- * Returns negative errno or zero.
- */
-int gserial_setup(struct usb_gadget *g, unsigned count)
-{
-       unsigned                        i;
-       struct usb_cdc_line_coding      coding;
-       int                             status;
-
-       if (count == 0 || count > N_PORTS)
-               return -EINVAL;
-
-       gs_tty_driver = alloc_tty_driver(count);
-       if (!gs_tty_driver)
-               return -ENOMEM;
-
-       gs_tty_driver->driver_name = "g_serial";
-       gs_tty_driver->name = PREFIX;
-       /* uses dynamically assigned dev_t values */
-
-       gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
-       gs_tty_driver->subtype = SERIAL_TYPE_NORMAL;
-       gs_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
-       gs_tty_driver->init_termios = tty_std_termios;
-
-       /* 9600-8-N-1 ... matches defaults expected by "usbser.sys" on
-        * MS-Windows.  Otherwise, most of these flags shouldn't affect
-        * anything unless we were to actually hook up to a serial line.
-        */
-       gs_tty_driver->init_termios.c_cflag =
-                       B9600 | CS8 | CREAD | HUPCL | CLOCAL;
-       gs_tty_driver->init_termios.c_ispeed = 9600;
-       gs_tty_driver->init_termios.c_ospeed = 9600;
-
-       coding.dwDTERate = cpu_to_le32(9600);
-       coding.bCharFormat = 8;
-       coding.bParityType = USB_CDC_NO_PARITY;
-       coding.bDataBits = USB_CDC_1_STOP_BITS;
-
-       tty_set_operations(gs_tty_driver, &gs_tty_ops);
-
-       /* make devices be openable */
-       for (i = 0; i < count; i++) {
-               mutex_init(&ports[i].lock);
-               status = gs_port_alloc(i, &coding);
-               if (status) {
-                       count = i;
-                       goto fail;
-               }
-       }
-       n_ports = count;
-
-       /* export the driver ... */
-       status = tty_register_driver(gs_tty_driver);
-       if (status) {
-               pr_err("%s: cannot register, err %d\n",
-                               __func__, status);
-               goto fail;
-       }
-
-       /* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */
-       for (i = 0; i < count; i++) {
-               struct device   *tty_dev;
-
-               tty_dev = tty_register_device(gs_tty_driver, i, &g->dev);
-               if (IS_ERR(tty_dev))
-                       pr_warning("%s: no classdev for port %d, err %ld\n",
-                               __func__, i, PTR_ERR(tty_dev));
-       }
-
-       pr_debug("%s: registered %d ttyGS* device%s\n", __func__,
-                       count, (count == 1) ? "" : "s");
-
-       return status;
-fail:
-       while (count--) {
-               tty_port_destroy(&ports[count].port->port);
-               kfree(ports[count].port);
-       }
-       put_tty_driver(gs_tty_driver);
-       gs_tty_driver = NULL;
-       return status;
-}
-
-static int gs_closed(struct gs_port *port)
-{
-       int cond;
-
-       spin_lock_irq(&port->port_lock);
-       cond = (port->port.count == 0) && !port->openclose;
-       spin_unlock_irq(&port->port_lock);
-       return cond;
-}
-
-/**
- * gserial_cleanup - remove TTY-over-USB driver and devices
- * Context: may sleep
- *
- * This is called to free all resources allocated by @gserial_setup().
- * Accordingly, it may need to wait until some open /dev/ files have
- * closed.
- *
- * The caller must have issued @gserial_disconnect() for any ports
- * that had previously been connected, so that there is never any
- * I/O pending when it's called.
- */
-void gserial_cleanup(void)
-{
-       unsigned        i;
-       struct gs_port  *port;
-
-       if (!gs_tty_driver)
-               return;
-
-       /* start sysfs and /dev/ttyGS* node removal */
-       for (i = 0; i < n_ports; i++)
-               tty_unregister_device(gs_tty_driver, i);
-
-       for (i = 0; i < n_ports; i++) {
-               /* prevent new opens */
-               mutex_lock(&ports[i].lock);
-               port = ports[i].port;
-               ports[i].port = NULL;
-               mutex_unlock(&ports[i].lock);
-
-               tasklet_kill(&port->push);
-
-               /* wait for old opens to finish */
-               wait_event(port->port.close_wait, gs_closed(port));
-
-               WARN_ON(port->port_usb != NULL);
-
-               tty_port_destroy(&port->port);
-               kfree(port);
-       }
-       n_ports = 0;
-
-       tty_unregister_driver(gs_tty_driver);
-       put_tty_driver(gs_tty_driver);
-       gs_tty_driver = NULL;
-
-       pr_debug("%s: cleaned up ttyGS* support\n", __func__);
-}
-
-/**
- * gserial_connect - notify TTY I/O glue that USB link is active
- * @gser: the function, set up with endpoints and descriptors
- * @port_num: which port is active
- * Context: any (usually from irq)
- *
- * This is called activate endpoints and let the TTY layer know that
- * the connection is active ... not unlike "carrier detect".  It won't
- * necessarily start I/O queues; unless the TTY is held open by any
- * task, there would be no point.  However, the endpoints will be
- * activated so the USB host can perform I/O, subject to basic USB
- * hardware flow control.
- *
- * Caller needs to have set up the endpoints and USB function in @dev
- * before calling this, as well as the appropriate (speed-specific)
- * endpoint descriptors, and also have set up the TTY driver by calling
- * @gserial_setup().
- *
- * Returns negative errno or zero.
- * On success, ep->driver_data will be overwritten.
- */
-int gserial_connect(struct gserial *gser, u8 port_num)
-{
-       struct gs_port  *port;
-       unsigned long   flags;
-       int             status;
-
-       if (!gs_tty_driver || port_num >= n_ports)
-               return -ENXIO;
-
-       /* we "know" gserial_cleanup() hasn't been called */
-       port = ports[port_num].port;
-
-       /* activate the endpoints */
-       status = usb_ep_enable(gser->in);
-       if (status < 0)
-               return status;
-       gser->in->driver_data = port;
-
-       status = usb_ep_enable(gser->out);
-       if (status < 0)
-               goto fail_out;
-       gser->out->driver_data = port;
-
-       /* then tell the tty glue that I/O can work */
-       spin_lock_irqsave(&port->port_lock, flags);
-       gser->ioport = port;
-       port->port_usb = gser;
-
-       /* REVISIT unclear how best to handle this state...
-        * we don't really couple it with the Linux TTY.
-        */
-       gser->port_line_coding = port->port_line_coding;
-
-       /* REVISIT if waiting on "carrier detect", signal. */
-
-       /* if it's already open, start I/O ... and notify the serial
-        * protocol about open/close status (connect/disconnect).
-        */
-       if (port->port.count) {
-               pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
-               gs_start_io(port);
-               if (gser->connect)
-                       gser->connect(gser);
-       } else {
-               if (gser->disconnect)
-                       gser->disconnect(gser);
-       }
-
-       spin_unlock_irqrestore(&port->port_lock, flags);
-
-       return status;
-
-fail_out:
-       usb_ep_disable(gser->in);
-       gser->in->driver_data = NULL;
-       return status;
-}
-
-/**
- * gserial_disconnect - notify TTY I/O glue that USB link is inactive
- * @gser: the function, on which gserial_connect() was called
- * Context: any (usually from irq)
- *
- * This is called to deactivate endpoints and let the TTY layer know
- * that the connection went inactive ... not unlike "hangup".
- *
- * On return, the state is as if gserial_connect() had never been called;
- * there is no active USB I/O on these endpoints.
- */
-void gserial_disconnect(struct gserial *gser)
-{
-       struct gs_port  *port = gser->ioport;
-       unsigned long   flags;
-
-       if (!port)
-               return;
-
-       /* tell the TTY glue not to do I/O here any more */
-       spin_lock_irqsave(&port->port_lock, flags);
-
-       /* REVISIT as above: how best to track this? */
-       port->port_line_coding = gser->port_line_coding;
-
-       port->port_usb = NULL;
-       gser->ioport = NULL;
-       if (port->port.count > 0 || port->openclose) {
-               wake_up_interruptible(&port->drain_wait);
-               if (port->port.tty)
-                       tty_hangup(port->port.tty);
-       }
-       spin_unlock_irqrestore(&port->port_lock, flags);
-
-       /* disable endpoints, aborting down any active I/O */
-       usb_ep_disable(gser->out);
-       gser->out->driver_data = NULL;
-
-       usb_ep_disable(gser->in);
-       gser->in->driver_data = NULL;
-
-       /* finally, free any unused/unusable I/O buffers */
-       spin_lock_irqsave(&port->port_lock, flags);
-       if (port->port.count == 0 && !port->openclose)
-               gs_buf_free(&port->port_write_buf);
-       gs_free_requests(gser->out, &port->read_pool, NULL);
-       gs_free_requests(gser->out, &port->read_queue, NULL);
-       gs_free_requests(gser->in, &port->write_pool, NULL);
-
-       port->read_allocated = port->read_started =
-               port->write_allocated = port->write_started = 0;
-
-       spin_unlock_irqrestore(&port->port_lock, flags);
-}
diff --git a/drivers/staging/ccg/u_serial.h b/drivers/staging/ccg/u_serial.h
deleted file mode 100644 (file)
index 9b0fe64..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * u_serial.h - interface to USB gadget "serial port"/TTY utilities
- *
- * Copyright (C) 2008 David Brownell
- * Copyright (C) 2008 by Nokia Corporation
- *
- * This software is 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.
- */
-
-#ifndef __U_SERIAL_H
-#define __U_SERIAL_H
-
-#include <linux/usb/composite.h>
-#include <linux/usb/cdc.h>
-
-/*
- * One non-multiplexed "serial" I/O port ... there can be several of these
- * on any given USB peripheral device, if it provides enough endpoints.
- *
- * The "u_serial" utility component exists to do one thing:  manage TTY
- * style I/O using the USB peripheral endpoints listed here, including
- * hookups to sysfs and /dev for each logical "tty" device.
- *
- * REVISIT at least ACM could support tiocmget() if needed.
- *
- * REVISIT someday, allow multiplexing several TTYs over these endpoints.
- */
-struct gserial {
-       struct usb_function             func;
-
-       /* port is managed by gserial_{connect,disconnect} */
-       struct gs_port                  *ioport;
-
-       struct usb_ep                   *in;
-       struct usb_ep                   *out;
-
-       /* REVISIT avoid this CDC-ACM support harder ... */
-       struct usb_cdc_line_coding port_line_coding;    /* 9600-8-N-1 etc */
-
-       /* notification callbacks */
-       void (*connect)(struct gserial *p);
-       void (*disconnect)(struct gserial *p);
-       int (*send_break)(struct gserial *p, int duration);
-};
-
-/* utilities to allocate/free request and buffer */
-struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned len, gfp_t flags);
-void gs_free_req(struct usb_ep *, struct usb_request *req);
-
-/* port setup/teardown is handled by gadget driver */
-int gserial_setup(struct usb_gadget *g, unsigned n_ports);
-void gserial_cleanup(void);
-
-/* connect/disconnect is handled by individual functions */
-int gserial_connect(struct gserial *, u8 port_num);
-void gserial_disconnect(struct gserial *);
-
-/* functions are bound to configurations by a config or gadget driver */
-int acm_bind_config(struct usb_configuration *c, u8 port_num);
-int gser_bind_config(struct usb_configuration *c, u8 port_num);
-int obex_bind_config(struct usb_configuration *c, u8 port_num);
-
-#endif /* __U_SERIAL_H */
diff --git a/drivers/staging/ccg/usbstring.c b/drivers/staging/ccg/usbstring.c
deleted file mode 100644 (file)
index 4d25b90..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2003 David Brownell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- */
-
-#include <linux/errno.h>
-#include <linux/kernel.h>
-#include <linux/list.h>
-#include <linux/string.h>
-#include <linux/device.h>
-#include <linux/init.h>
-#include <linux/nls.h>
-
-#include <linux/usb/ch9.h>
-#include <linux/usb/gadget.h>
-
-
-/**
- * usb_gadget_get_string - fill out a string descriptor 
- * @table: of c strings encoded using UTF-8
- * @id: string id, from low byte of wValue in get string descriptor
- * @buf: at least 256 bytes, must be 16-bit aligned
- *
- * Finds the UTF-8 string matching the ID, and converts it into a
- * string descriptor in utf16-le.
- * Returns length of descriptor (always even) or negative errno
- *
- * If your driver needs stings in multiple languages, you'll probably
- * "switch (wIndex) { ... }"  in your ep0 string descriptor logic,
- * using this routine after choosing which set of UTF-8 strings to use.
- * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
- * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
- * characters (which are also widely used in C strings).
- */
-int
-usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
-{
-       struct usb_string       *s;
-       int                     len;
-
-       /* descriptor 0 has the language id */
-       if (id == 0) {
-               buf [0] = 4;
-               buf [1] = USB_DT_STRING;
-               buf [2] = (u8) table->language;
-               buf [3] = (u8) (table->language >> 8);
-               return 4;
-       }
-       for (s = table->strings; s && s->s; s++)
-               if (s->id == id)
-                       break;
-
-       /* unrecognized: stall. */
-       if (!s || !s->s)
-               return -EINVAL;
-
-       /* string descriptors have length, tag, then UTF16-LE text */
-       len = min ((size_t) 126, strlen (s->s));
-       len = utf8s_to_utf16s(s->s, len, UTF16_LITTLE_ENDIAN,
-                       (wchar_t *) &buf[2], 126);
-       if (len < 0)
-               return -EINVAL;
-       buf [0] = (len + 1) * 2;
-       buf [1] = USB_DT_STRING;
-       return buf [0];
-}
-
index 1967852eeb1779c12ea4c8b126acb37d6a657d45..67993c069a68773d890b6fa855ff2a28a7a2eca7 100644 (file)
@@ -728,6 +728,16 @@ config COMEDI_ADV_PCI1723
          To compile this driver as a module, choose M here: the module will be
          called adv_pci1723.
 
+config COMEDI_ADV_PCI1724
+       tristate "Advantech PCI-1724U support"
+       ---help---
+         Enable support for Advantech PCI-1724U cards.  These are 32-channel
+         analog output cards with voltage and current loop output ranges and
+         14-bit resolution.
+
+         To compile this driver as a module, choose M here: the module will be
+         called adv_pci1724.
+
 config COMEDI_ADV_PCI_DIO
        tristate "Advantech PCI DIO card support"
        select COMEDI_8255
@@ -748,7 +758,7 @@ config COMEDI_AMPLC_DIO200_PCI
          and PCIe296 DIO boards.
 
          To compile this driver as a module, choose M here: the module will be
-         called amplc_dio200.
+         called amplc_dio200_pci.
 
 config COMEDI_AMPLC_PC236_PCI
        tristate "Amplicon PCI236 DIO board support"
@@ -983,7 +993,7 @@ config COMEDI_NI_660X
        select COMEDI_NI_TIOCMD
        ---help---
          Enable support for National Instruments PCI-6601 (ni_660x), PCI-6602,
-         PXI-6602 and PXI-6608.
+         PXI-6602, PXI-6608 and PXI-6624.
 
          To compile this driver as a module, choose M here: the module will be
          called ni_660x.
index e336b281b847768053198e9350d862a59555ee8d..6bcbb52510ef9e2b82ffd8c6cb1b329e40e78ae2 100644 (file)
@@ -2067,12 +2067,12 @@ static int comedi_open(struct inode *inode, struct file *file)
        /* This is slightly hacky, but we want module autoloading
         * to work for root.
         * case: user opens device, attached -> ok
-        * case: user opens device, unattached, in_request_module=0 -> autoload
-        * case: user opens device, unattached, in_request_module=1 -> fail
+        * case: user opens device, unattached, !in_request_module -> autoload
+        * case: user opens device, unattached, in_request_module -> fail
         * case: root opens device, attached -> ok
-        * case: root opens device, unattached, in_request_module=1 -> ok
+        * case: root opens device, unattached, in_request_module -> ok
         *   (typically called from modprobe)
-        * case: root opens device, unattached, in_request_module=0 -> autoload
+        * case: root opens device, unattached, !in_request_module -> autoload
         *
         * The last could be changed to "-> ok", which would deny root
         * autoloading.
@@ -2088,7 +2088,7 @@ static int comedi_open(struct inode *inode, struct file *file)
        if (capable(CAP_NET_ADMIN) && dev->in_request_module)
                goto ok;
 
-       dev->in_request_module = 1;
+       dev->in_request_module = true;
 
 #ifdef CONFIG_KMOD
        mutex_unlock(&dev->mutex);
@@ -2096,7 +2096,7 @@ static int comedi_open(struct inode *inode, struct file *file)
        mutex_lock(&dev->mutex);
 #endif
 
-       dev->in_request_module = 0;
+       dev->in_request_module = false;
 
        if (!dev->attached && !capable(CAP_NET_ADMIN)) {
                DPRINTK("not attached and not CAP_NET_ADMIN\n");
index 37d2e467736038e3a9be94d58e141321da74e59e..6f3cdf88f05ec3a745acd1dd21ffa51f5e85fbc3 100644 (file)
@@ -36,20 +36,27 @@ EXPORT_SYMBOL_GPL(comedi_to_pci_dev);
 
 /**
  * comedi_pci_enable() - Enable the PCI device and request the regions.
- * @pcidev: pci_dev struct
- * @res_name: name for the requested reqource
+ * @dev: comedi_device struct
  */
-int comedi_pci_enable(struct pci_dev *pcidev, const char *res_name)
+int comedi_pci_enable(struct comedi_device *dev)
 {
+       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        int rc;
 
+       if (!pcidev)
+               return -ENODEV;
+
        rc = pci_enable_device(pcidev);
        if (rc < 0)
                return rc;
 
-       rc = pci_request_regions(pcidev, res_name);
+       rc = pci_request_regions(pcidev, dev->board_name
+                                               ? dev->board_name
+                                               : dev->driver->driver_name);
        if (rc < 0)
                pci_disable_device(pcidev);
+       else
+               dev->ioenabled = true;
 
        return rc;
 }
@@ -57,14 +64,17 @@ EXPORT_SYMBOL_GPL(comedi_pci_enable);
 
 /**
  * comedi_pci_disable() - Release the regions and disable the PCI device.
- * @pcidev: pci_dev struct
- *
- * This must be matched with a previous successful call to comedi_pci_enable().
+ * @dev: comedi_device struct
  */
-void comedi_pci_disable(struct pci_dev *pcidev)
+void comedi_pci_disable(struct comedi_device *dev)
 {
-       pci_release_regions(pcidev);
-       pci_disable_device(pcidev);
+       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+       if (pcidev && dev->ioenabled) {
+               pci_release_regions(pcidev);
+               pci_disable_device(pcidev);
+       }
+       dev->ioenabled = false;
 }
 EXPORT_SYMBOL_GPL(comedi_pci_disable);
 
@@ -72,13 +82,15 @@ EXPORT_SYMBOL_GPL(comedi_pci_disable);
  * 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()
  *
  * Typically called from the pci_driver (*probe) function.
  */
 int comedi_pci_auto_config(struct pci_dev *pcidev,
-                          struct comedi_driver *driver)
+                          struct comedi_driver *driver,
+                          unsigned long context)
 {
-       return comedi_auto_config(&pcidev->dev, driver, 0);
+       return comedi_auto_config(&pcidev->dev, driver, context);
 }
 EXPORT_SYMBOL_GPL(comedi_pci_auto_config);
 
index f3a990b45df5f9dce3f564c4f475016af87f44d1..9c8662a051dccde2a5d2f6c90d9664a0a590f2cb 100644 (file)
@@ -207,10 +207,11 @@ struct comedi_device {
 
        const char *board_name;
        const void *board_ptr;
-       int attached;
+       bool attached:1;
+       bool in_request_module:1;
+       bool ioenabled:1;
        spinlock_t spinlock;
        struct mutex mutex;
-       int in_request_module;
 
        int n_subdevices;
        struct comedi_subdevice *subdevices;
@@ -384,10 +385,11 @@ struct pci_driver;
 
 struct pci_dev *comedi_to_pci_dev(struct comedi_device *);
 
-int comedi_pci_enable(struct pci_dev *, const char *);
-void comedi_pci_disable(struct pci_dev *);
+int comedi_pci_enable(struct comedi_device *);
+void comedi_pci_disable(struct comedi_device *);
 
-int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *);
+int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *,
+                          unsigned long context);
 void comedi_pci_auto_unconfig(struct pci_dev *);
 
 int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *);
@@ -420,12 +422,12 @@ static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
        return NULL;
 }
 
-static inline int comedi_pci_enable(struct pci_dev *dev, const char *name)
+static inline int comedi_pci_enable(struct comedi_device *dev)
 {
        return -ENOSYS;
 }
 
-static inline void comedi_pci_disable(struct pci_dev *dev)
+static inline void comedi_pci_disable(struct comedi_device *dev)
 {
 }
 
index 64be7c5e891e77855d99c7ec46fa1c85742378bf..4724f275830cfe216a0dbde50d91bf60a6758ced 100644 (file)
@@ -110,6 +110,7 @@ static void cleanup_device(struct comedi_device *dev)
        dev->board_name = NULL;
        dev->board_ptr = NULL;
        dev->iobase = 0;
+       dev->ioenabled = false;
        dev->irq = 0;
        dev->read_subdev = NULL;
        dev->write_subdev = NULL;
@@ -120,7 +121,7 @@ static void cleanup_device(struct comedi_device *dev)
 
 static void __comedi_device_detach(struct comedi_device *dev)
 {
-       dev->attached = 0;
+       dev->attached = false;
        if (dev->driver)
                dev->driver->detach(dev);
        else
@@ -290,7 +291,7 @@ static int comedi_device_postconfig(struct comedi_device *dev)
                dev->board_name = "BUG";
        }
        smp_wmb();
-       dev->attached = 1;
+       dev->attached = true;
        return 0;
 }
 
index 0ae356ae56ea3b3937e1ee3599063b2790c2460c..808460bbd32ea1e2a29119bd0da34542a6c3c17e 100644 (file)
@@ -60,124 +60,104 @@ Configuration Options: not applicable, uses PCI auto config
 
 #include "8255.h"
 
-/*
- * PCI Device ID's supported by this driver
- */
-#define PCI_DEVICE_ID_ADLINK_PCI7224   0x7224
-#define PCI_DEVICE_ID_ADLINK_PCI7248   0x7248
-#define PCI_DEVICE_ID_ADLINK_PCI7296   0x7296
-
-#define PCI_DEVICE_ID_CB_PCIDIO48H     0x000b
-#define PCI_DEVICE_ID_CB_PCIDIO24H     0x0014
-#define PCI_DEVICE_ID_CB_PCIDIO96H     0x0017
-#define PCI_DEVICE_ID_CB_PCIDIO24      0x0028
-
-#define PCI_DEVICE_ID_NI_PCIDIO96      0x0160
-#define PCI_DEVICE_ID_NI_PCI6503       0x0400
-#define PCI_DEVICE_ID_NI_PCI6503B      0x1250
-#define PCI_DEVICE_ID_NI_PXI6508       0x13c0
-#define PCI_DEVICE_ID_NI_PCIDIO96B     0x1630
-#define PCI_DEVICE_ID_NI_PCI6503X      0x17d0
-#define PCI_DEVICE_ID_NI_PXI_6503      0x1800
+enum pci_8255_boardid {
+       BOARD_ADLINK_PCI7224,
+       BOARD_ADLINK_PCI7248,
+       BOARD_ADLINK_PCI7296,
+       BOARD_CB_PCIDIO24,
+       BOARD_CB_PCIDIO24H,
+       BOARD_CB_PCIDIO48H,
+       BOARD_CB_PCIDIO96H,
+       BOARD_NI_PCIDIO96,
+       BOARD_NI_PCIDIO96B,
+       BOARD_NI_PXI6508,
+       BOARD_NI_PCI6503,
+       BOARD_NI_PCI6503B,
+       BOARD_NI_PCI6503X,
+       BOARD_NI_PXI_6503,
+};
 
 struct pci_8255_boardinfo {
        const char *name;
-       unsigned short vendor;
-       unsigned short device;
        int dio_badr;
        int is_mmio;
        int n_8255;
 };
 
 static const struct pci_8255_boardinfo pci_8255_boards[] = {
-       {
+       [BOARD_ADLINK_PCI7224] = {
                .name           = "adl_pci-7224",
-               .vendor         = PCI_VENDOR_ID_ADLINK,
-               .device         = PCI_DEVICE_ID_ADLINK_PCI7224,
                .dio_badr       = 2,
                .n_8255         = 1,
-       }, {
+       },
+       [BOARD_ADLINK_PCI7248] = {
                .name           = "adl_pci-7248",
-               .vendor         = PCI_VENDOR_ID_ADLINK,
-               .device         = PCI_DEVICE_ID_ADLINK_PCI7248,
                .dio_badr       = 2,
                .n_8255         = 2,
-       }, {
+       },
+       [BOARD_ADLINK_PCI7296] = {
                .name           = "adl_pci-7296",
-               .vendor         = PCI_VENDOR_ID_ADLINK,
-               .device         = PCI_DEVICE_ID_ADLINK_PCI7296,
                .dio_badr       = 2,
                .n_8255         = 4,
-       }, {
+       },
+       [BOARD_CB_PCIDIO24] = {
                .name           = "cb_pci-dio24",
-               .vendor         = PCI_VENDOR_ID_CB,
-               .device         = PCI_DEVICE_ID_CB_PCIDIO24,
                .dio_badr       = 2,
                .n_8255         = 1,
-       }, {
+       },
+       [BOARD_CB_PCIDIO24H] = {
                .name           = "cb_pci-dio24h",
-               .vendor         = PCI_VENDOR_ID_CB,
-               .device         = PCI_DEVICE_ID_CB_PCIDIO24H,
                .dio_badr       = 2,
                .n_8255         = 1,
-       }, {
+       },
+       [BOARD_CB_PCIDIO48H] = {
                .name           = "cb_pci-dio48h",
-               .vendor         = PCI_VENDOR_ID_CB,
-               .device         = PCI_DEVICE_ID_CB_PCIDIO48H,
                .dio_badr       = 1,
                .n_8255         = 2,
-       }, {
+       },
+       [BOARD_CB_PCIDIO96H] = {
                .name           = "cb_pci-dio96h",
-               .vendor         = PCI_VENDOR_ID_CB,
-               .device         = PCI_DEVICE_ID_CB_PCIDIO96H,
                .dio_badr       = 2,
                .n_8255         = 4,
-       }, {
+       },
+       [BOARD_NI_PCIDIO96] = {
                .name           = "ni_pci-dio-96",
-               .vendor         = PCI_VENDOR_ID_NI,
-               .device         = PCI_DEVICE_ID_NI_PCIDIO96,
                .dio_badr       = 1,
                .is_mmio        = 1,
                .n_8255         = 4,
-       }, {
+       },
+       [BOARD_NI_PCIDIO96B] = {
                .name           = "ni_pci-dio-96b",
-               .vendor         = PCI_VENDOR_ID_NI,
-               .device         = PCI_DEVICE_ID_NI_PCIDIO96B,
                .dio_badr       = 1,
                .is_mmio        = 1,
                .n_8255         = 4,
-       }, {
+       },
+       [BOARD_NI_PXI6508] = {
                .name           = "ni_pxi-6508",
-               .vendor         = PCI_VENDOR_ID_NI,
-               .device         = PCI_DEVICE_ID_NI_PXI6508,
                .dio_badr       = 1,
                .is_mmio        = 1,
                .n_8255         = 4,
-       }, {
+       },
+       [BOARD_NI_PCI6503] = {
                .name           = "ni_pci-6503",
-               .vendor         = PCI_VENDOR_ID_NI,
-               .device         = PCI_DEVICE_ID_NI_PCI6503,
                .dio_badr       = 1,
                .is_mmio        = 1,
                .n_8255         = 1,
-       }, {
+       },
+       [BOARD_NI_PCI6503B] = {
                .name           = "ni_pci-6503b",
-               .vendor         = PCI_VENDOR_ID_NI,
-               .device         = PCI_DEVICE_ID_NI_PCI6503B,
                .dio_badr       = 1,
                .is_mmio        = 1,
                .n_8255         = 1,
-       }, {
+       },
+       [BOARD_NI_PCI6503X] = {
                .name           = "ni_pci-6503x",
-               .vendor         = PCI_VENDOR_ID_NI,
-               .device         = PCI_DEVICE_ID_NI_PCI6503X,
                .dio_badr       = 1,
                .is_mmio        = 1,
                .n_8255         = 1,
-       }, {
+       },
+       [BOARD_NI_PXI_6503] = {
                .name           = "ni_pxi-6503",
-               .vendor         = PCI_VENDOR_ID_NI,
-               .device         = PCI_DEVICE_ID_NI_PXI_6503,
                .dio_badr       = 1,
                .is_mmio        = 1,
                .n_8255         = 1,
@@ -200,26 +180,11 @@ static int pci_8255_mmio(int dir, int port, int data, unsigned long iobase)
        }
 }
 
-static const void *pci_8255_find_boardinfo(struct comedi_device *dev,
-                                             struct pci_dev *pcidev)
-{
-       const struct pci_8255_boardinfo *board;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(pci_8255_boards); i++) {
-               board = &pci_8255_boards[i];
-               if (pcidev->vendor == board->vendor &&
-                   pcidev->device == board->device)
-                       return board;
-       }
-       return NULL;
-}
-
 static int pci_8255_auto_attach(struct comedi_device *dev,
-                                         unsigned long context_unused)
+                               unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct pci_8255_boardinfo *board;
+       const struct pci_8255_boardinfo *board = NULL;
        struct pci_8255_private *devpriv;
        struct comedi_subdevice *s;
        resource_size_t iobase;
@@ -227,7 +192,8 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
        int ret;
        int i;
 
-       board = pci_8255_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(pci_8255_boards))
+               board = &pci_8255_boards[context];
        if (!board)
                return -ENODEV;
        dev->board_ptr = board;
@@ -238,7 +204,7 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        iobase = pci_resource_start(pcidev, board->dio_badr);
@@ -281,7 +247,6 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
 
 static void pci_8255_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        const struct pci_8255_boardinfo *board = comedi_board(dev);
        struct pci_8255_private *devpriv = dev->private;
        struct comedi_subdevice *s;
@@ -295,12 +260,9 @@ static void pci_8255_detach(struct comedi_device *dev)
                        subdev_8255_cleanup(dev, s);
                }
        }
-       if (pcidev) {
-               if (devpriv->mmio_base)
-                       iounmap(devpriv->mmio_base);
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       if (devpriv->mmio_base)
+               iounmap(devpriv->mmio_base);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver pci_8255_driver = {
@@ -311,26 +273,26 @@ static struct comedi_driver pci_8255_driver = {
 };
 
 static int pci_8255_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &pci_8255_driver);
+       return comedi_pci_auto_config(dev, &pci_8255_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(pci_8255_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_ADLINK_PCI7224) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_ADLINK_PCI7248) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_ADLINK_PCI7296) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_CB_PCIDIO24) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_CB_PCIDIO24H) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_CB_PCIDIO48H) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_CB_PCIDIO96H) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCIDIO96) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCIDIO96B) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI6508) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI6503) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI6503B) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PCI6503X) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, PCI_DEVICE_ID_NI_PXI_6503) },
+       { PCI_VDEVICE(ADLINK, 0x7224), BOARD_ADLINK_PCI7224 },
+       { PCI_VDEVICE(ADLINK, 0x7248), BOARD_ADLINK_PCI7248 },
+       { PCI_VDEVICE(ADLINK, 0x7296), BOARD_ADLINK_PCI7296 },
+       { PCI_VDEVICE(CB, 0x0028), BOARD_CB_PCIDIO24 },
+       { PCI_VDEVICE(CB, 0x0014), BOARD_CB_PCIDIO24H },
+       { PCI_VDEVICE(CB, 0x000b), BOARD_CB_PCIDIO48H },
+       { PCI_VDEVICE(CB, 0x0017), BOARD_CB_PCIDIO96H },
+       { PCI_VDEVICE(NI, 0x0160), BOARD_NI_PCIDIO96 },
+       { PCI_VDEVICE(NI, 0x1630), BOARD_NI_PCIDIO96B },
+       { PCI_VDEVICE(NI, 0x13c0), BOARD_NI_PXI6508 },
+       { PCI_VDEVICE(NI, 0x0400), BOARD_NI_PCI6503 },
+       { PCI_VDEVICE(NI, 0x1250), BOARD_NI_PCI6503B },
+       { PCI_VDEVICE(NI, 0x17d0), BOARD_NI_PCI6503X },
+       { PCI_VDEVICE(NI, 0x1800), BOARD_NI_PXI_6503 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, pci_8255_pci_table);
index 315e836ff99b9d635ad1e7ac1990750899aa2ed9..4857d46d684ae60356eef91a719a08872b31e144 100644 (file)
@@ -12,6 +12,7 @@ obj-$(CONFIG_COMEDI_SKEL)             += skel.o
 
 # Comedi ISA drivers
 obj-$(CONFIG_COMEDI_ACL7225B)          += acl7225b.o
+obj-$(CONFIG_COMEDI_AMPLC_DIO200_ISA)  += amplc_dio200.o
 obj-$(CONFIG_COMEDI_PCL711)            += pcl711.o
 obj-$(CONFIG_COMEDI_PCL724)            += pcl724.o
 obj-$(CONFIG_COMEDI_PCL725)            += pcl725.o
@@ -75,8 +76,9 @@ obj-$(CONFIG_COMEDI_ADL_PCI9111)      += adl_pci9111.o
 obj-$(CONFIG_COMEDI_ADL_PCI9118)       += adl_pci9118.o
 obj-$(CONFIG_COMEDI_ADV_PCI1710)       += adv_pci1710.o
 obj-$(CONFIG_COMEDI_ADV_PCI1723)       += adv_pci1723.o
+obj-$(CONFIG_COMEDI_ADV_PCI1724)       += adv_pci1724.o
 obj-$(CONFIG_COMEDI_ADV_PCI_DIO)       += adv_pci_dio.o
-obj-$(CONFIG_COMEDI_AMPLC_DIO200)      += amplc_dio200.o
+obj-$(CONFIG_COMEDI_AMPLC_DIO200_PCI)  += amplc_dio200_pci.o
 obj-$(CONFIG_COMEDI_AMPLC_PC236)       += amplc_pc236.o
 obj-$(CONFIG_COMEDI_AMPLC_PC263)       += amplc_pc263.o
 obj-$(CONFIG_COMEDI_AMPLC_PCI224)      += amplc_pci224.o
@@ -133,5 +135,6 @@ obj-$(CONFIG_COMEDI_NI_TIOCMD)              += ni_tiocmd.o
 obj-$(CONFIG_COMEDI_NI_LABPC)          += ni_labpc.o
 
 obj-$(CONFIG_COMEDI_8255)              += 8255.o
+obj-$(CONFIG_COMEDI_AMPLC_DIO200)      += amplc_dio200_common.o
 obj-$(CONFIG_COMEDI_DAS08)             += das08.o
 obj-$(CONFIG_COMEDI_FC)                        += comedi_fc.o
index 1e05732e9f3d52d9aac5b499d93d6b68128327be..97e7eec343d776d2610fcaf71c52357ccb91ca64 100644 (file)
@@ -704,9 +704,9 @@ static int i_APCI1710_InsnReadSSIValue(struct comedi_device *dev,
 |                                        unsigned char *_   pb_ChannelStatus)          |
 +----------------------------------------------------------------------------+
 | Task              :
-                                       (0) Set the digital output from selected SSI moule         |
+                                       (0) Set the digital output from selected SSI module         |
 |                     (b_ModuleNbr) ON
-                    (1) Set the digital output from selected SSI moule         |
+                    (1) Set the digital output from selected SSI module         |
 |                     (b_ModuleNbr) OFF
                                        (2)Read the status from selected SSI digital input        |
 |                     (b_InputChannel)
index 1051fa5ce8f7e571c810d7f0b602a40f712df1f6..cb9b590f63b923a976366534275f18380db73ca1 100644 (file)
@@ -84,37 +84,16 @@ static int i_ADDI_Reset(struct comedi_device *dev)
        return 0;
 }
 
-static const void *addi_find_boardinfo(struct comedi_device *dev,
-                                      struct pci_dev *pcidev)
-{
-       const void *p = dev->driver->board_name;
-       const struct addi_board *this_board;
-       int i;
-
-       for (i = 0; i < dev->driver->num_names; i++) {
-               this_board = p;
-               if (this_board->i_VendorId == pcidev->vendor &&
-                   this_board->i_DeviceId == pcidev->device)
-                       return this_board;
-               p += dev->driver->offset;
-       }
-       return NULL;
-}
-
 static int addi_auto_attach(struct comedi_device *dev,
                                      unsigned long context_unused)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct addi_board *this_board;
+       const struct addi_board *this_board = comedi_board(dev);
        struct addi_private *devpriv;
        struct comedi_subdevice *s;
        int ret, n_subdevices;
        unsigned int dw_Dummy;
 
-       this_board = addi_find_boardinfo(dev, pcidev);
-       if (!this_board)
-               return -ENODEV;
-       dev->board_ptr = this_board;
        dev->board_name = this_board->pc_DriverName;
 
        devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
@@ -122,7 +101,7 @@ static int addi_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
 
@@ -338,7 +317,6 @@ static int addi_auto_attach(struct comedi_device *dev,
 
 static void i_ADDI_Detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct addi_private *devpriv = dev->private;
 
        if (devpriv) {
@@ -349,8 +327,5 @@ static void i_ADDI_Detach(struct comedi_device *dev)
                if (devpriv->dw_AiBase)
                        iounmap(devpriv->dw_AiBase);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
index 6d8b29f945d5b7a1dd77be99fe3bcfb6ebe317bd..19da977fef8290e8fc831407bed0db1ea66329e6 100644 (file)
@@ -45,8 +45,6 @@
 /* structure for the boardtype */
 struct addi_board {
        const char *pc_DriverName;      /*  driver name */
-       int i_VendorId;         /* PCI vendor a device ID of card */
-       int i_DeviceId;
        int i_IorangeBase0;
        int i_IorangeBase1;
        int i_IorangeBase2;     /*   base 2 range */
index 5a53e58258a08616aafc1962aa9519f22be06752..2f4e2948a9f2494708c8d0e4056f87cdf6075ff5 100644 (file)
@@ -15,8 +15,6 @@
 static const struct addi_board apci035_boardtypes[] = {
        {
                .pc_DriverName          = "apci035",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x0300,
                .i_IorangeBase0         = 127,
                .i_IorangeBase1         = APCI035_ADDRESS_RANGE,
                .i_PCIEeprom            = 1,
@@ -39,20 +37,25 @@ static const struct addi_board apci035_boardtypes[] = {
        },
 };
 
+static int apci035_auto_attach(struct comedi_device *dev,
+                              unsigned long context)
+{
+       dev->board_ptr = &apci035_boardtypes[0];
+
+       return addi_auto_attach(dev, context);
+}
+
 static struct comedi_driver apci035_driver = {
        .driver_name    = "addi_apci_035",
        .module         = THIS_MODULE,
-       .auto_attach    = addi_auto_attach,
+       .auto_attach    = apci035_auto_attach,
        .detach         = i_ADDI_Detach,
-       .num_names      = ARRAY_SIZE(apci035_boardtypes),
-       .board_name     = &apci035_boardtypes[0].pc_DriverName,
-       .offset         = sizeof(struct addi_board),
 };
 
 static int apci035_pci_probe(struct pci_dev *dev,
-                                      const struct pci_device_id *ent)
+                            const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci035_driver);
+       return comedi_pci_auto_config(dev, &apci035_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci035_pci_table) = {
index c0d0429c35c8faac7e8b1a9616dac49a8554cf80..3d32448e4e69f555f49ba02cac630269dbfb7c0a 100644 (file)
@@ -303,7 +303,7 @@ static int apci1032_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
 
@@ -353,16 +353,11 @@ static int apci1032_auto_attach(struct comedi_device *dev,
 
 static void apci1032_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                apci1032_reset(dev);
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci1032_driver = {
@@ -373,9 +368,9 @@ static struct comedi_driver apci1032_driver = {
 };
 
 static int apci1032_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci1032_driver);
+       return comedi_pci_auto_config(dev, &apci1032_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci1032_pci_table) = {
index 9c2f8eeb7977b1e62628a7e1058b14507a5df9d2..1170e7688f399ce077f3226f6edf1424248865db 100644 (file)
@@ -13,8 +13,6 @@
 static const struct addi_board apci1500_boardtypes[] = {
        {
                .pc_DriverName          = "apci1500",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA_OLD,
-               .i_DeviceId             = 0x80fc,
                .i_IorangeBase0         = 128,
                .i_IorangeBase1         = APCI1500_ADDRESS_RANGE,
                .i_IorangeBase2         = 4,
@@ -39,20 +37,25 @@ static const struct addi_board apci1500_boardtypes[] = {
        },
 };
 
+static int apci1500_auto_attach(struct comedi_device *dev,
+                               unsigned long context)
+{
+       dev->board_ptr = &apci1500_boardtypes[0];
+
+       return addi_auto_attach(dev, context);
+}
+
 static struct comedi_driver apci1500_driver = {
        .driver_name    = "addi_apci_1500",
        .module         = THIS_MODULE,
-       .auto_attach    = addi_auto_attach,
+       .auto_attach    = apci1500_auto_attach,
        .detach         = i_ADDI_Detach,
-       .num_names      = ARRAY_SIZE(apci1500_boardtypes),
-       .board_name     = &apci1500_boardtypes[0].pc_DriverName,
-       .offset         = sizeof(struct addi_board),
 };
 
 static int apci1500_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci1500_driver);
+       return comedi_pci_auto_config(dev, &apci1500_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci1500_pci_table) = {
index 69e3996384196669bc5c057e51f3dd1ad87544c8..e66ff4e05cdb75ed384f51395cc53c187f10bc09 100644 (file)
 #include "addi_watchdog.h"
 #include "comedi_fc.h"
 
-/*
- * PCI device ids supported by this driver
- */
-#define PCI_DEVICE_ID_APCI1016         0x1000
-#define PCI_DEVICE_ID_APCI1516         0x1001
-#define PCI_DEVICE_ID_APCI2016         0x1002
-
 /*
  * PCI bar 1 I/O Register map - Digital input/output
  */
  */
 #define APCI1516_WDOG_REG              0x00
 
+enum apci1516_boardid {
+       BOARD_APCI1016,
+       BOARD_APCI1516,
+       BOARD_APCI2016,
+};
+
 struct apci1516_boardinfo {
        const char *name;
-       unsigned short device;
        int di_nchan;
        int do_nchan;
        int has_wdog;
 };
 
 static const struct apci1516_boardinfo apci1516_boardtypes[] = {
-       {
+       [BOARD_APCI1016] = {
                .name           = "apci1016",
-               .device         = PCI_DEVICE_ID_APCI1016,
                .di_nchan       = 16,
-       }, {
+       },
+       [BOARD_APCI1516] = {
                .name           = "apci1516",
-               .device         = PCI_DEVICE_ID_APCI1516,
                .di_nchan       = 8,
                .do_nchan       = 8,
                .has_wdog       = 1,
-       }, {
+       },
+       [BOARD_APCI2016] = {
                .name           = "apci2016",
-               .device         = PCI_DEVICE_ID_APCI2016,
                .do_nchan       = 16,
                .has_wdog       = 1,
        },
@@ -130,30 +127,17 @@ static int apci1516_reset(struct comedi_device *dev)
        return 0;
 }
 
-static const void *apci1516_find_boardinfo(struct comedi_device *dev,
-                                          struct pci_dev *pcidev)
-{
-       const struct apci1516_boardinfo *this_board;
-       int i;
-
-       for (i = 0; i < dev->driver->num_names; i++) {
-               this_board = &apci1516_boardtypes[i];
-               if (this_board->device == pcidev->device)
-                       return this_board;
-       }
-       return NULL;
-}
-
 static int apci1516_auto_attach(struct comedi_device *dev,
-                                         unsigned long context_unused)
+                               unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct apci1516_boardinfo *this_board;
+       const struct apci1516_boardinfo *this_board = NULL;
        struct apci1516_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
 
-       this_board = apci1516_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(apci1516_boardtypes))
+               this_board = &apci1516_boardtypes[context];
        if (!this_board)
                return -ENODEV;
        dev->board_ptr = this_board;
@@ -164,7 +148,7 @@ static int apci1516_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
 
@@ -217,14 +201,11 @@ static int apci1516_auto_attach(struct comedi_device *dev,
 
 static void apci1516_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                apci1516_reset(dev);
        if (dev->subdevices)
                addi_watchdog_cleanup(&dev->subdevices[2]);
-       if (dev->iobase)
-               comedi_pci_disable(pcidev);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci1516_driver = {
@@ -235,15 +216,15 @@ static struct comedi_driver apci1516_driver = {
 };
 
 static int apci1516_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci1516_driver);
+       return comedi_pci_auto_config(dev, &apci1516_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci1516_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1016) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1516) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI2016) },
+       { PCI_VDEVICE(ADDIDATA, 0x1000), BOARD_APCI1016 },
+       { PCI_VDEVICE(ADDIDATA, 0x1001), BOARD_APCI1516 },
+       { PCI_VDEVICE(ADDIDATA, 0x1002), BOARD_APCI2016 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, apci1516_pci_table);
index ddea64df9180cc6934de9303f91bc24843d64925..8de7b4875b0d5b3107c1a255698ec13cd0e713fa 100644 (file)
@@ -13,8 +13,6 @@
 static const struct addi_board apci1564_boardtypes[] = {
        {
                .pc_DriverName          = "apci1564",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x1006,
                .i_IorangeBase0         = 128,
                .i_IorangeBase1         = APCI1564_ADDRESS_RANGE,
                .i_PCIEeprom            = ADDIDATA_EEPROM,
@@ -36,20 +34,25 @@ static const struct addi_board apci1564_boardtypes[] = {
        },
 };
 
+static int apci1564_auto_attach(struct comedi_device *dev,
+                               unsigned long context)
+{
+       dev->board_ptr = &apci1564_boardtypes[0];
+
+       return addi_auto_attach(dev, context);
+}
+
 static struct comedi_driver apci1564_driver = {
        .driver_name    = "addi_apci_1564",
        .module         = THIS_MODULE,
-       .auto_attach    = addi_auto_attach,
+       .auto_attach    = apci1564_auto_attach,
        .detach         = i_ADDI_Detach,
-       .num_names      = ARRAY_SIZE(apci1564_boardtypes),
-       .board_name     = &apci1564_boardtypes[0].pc_DriverName,
-       .offset         = sizeof(struct addi_board),
 };
 
 static int apci1564_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci1564_driver);
+       return comedi_pci_auto_config(dev, &apci1564_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci1564_pci_table) = {
index e51f80001363dff438adaae4d0c9262f0cb50e11..4c6a9b5a06aeeb31c29f54031e163d261dfb82dd 100644 (file)
 
 #include "../comedidev.h"
 
-/*
- * PCI device ids supported by this driver
- */
-#define PCI_DEVICE_ID_APCI1648         0x1009
-#define PCI_DEVICE_ID_APCI1696         0x100a
-
 /*
  * Register I/O map
  */
 #define APCI16XX_OUT_REG(x)            (((x) * 4) + 0x14)
 #define APCI16XX_DIR_REG(x)            (((x) * 4) + 0x20)
 
+enum apci16xx_boardid {
+       BOARD_APCI1648,
+       BOARD_APCI1696,
+};
+
 struct apci16xx_boardinfo {
        const char *name;
-       unsigned short vendor;
-       unsigned short device;
        int n_chan;
 };
 
 static const struct apci16xx_boardinfo apci16xx_boardtypes[] = {
-       {
+       [BOARD_APCI1648] = {
                .name           = "apci1648",
-               .vendor         = PCI_VENDOR_ID_ADDIDATA,
-               .device         = PCI_DEVICE_ID_APCI1648,
                .n_chan         = 48,           /* 2 subdevices */
-       }, {
+       },
+       [BOARD_APCI1696] = {
                .name           = "apci1696",
-               .vendor         = PCI_VENDOR_ID_ADDIDATA,
-               .device         = PCI_DEVICE_ID_APCI1696,
                .n_chan         = 96,           /* 3 subdevices */
        },
 };
@@ -130,39 +124,25 @@ static int apci16xx_dio_insn_bits(struct comedi_device *dev,
        return insn->n;
 }
 
-static const void *apci16xx_find_boardinfo(struct comedi_device *dev,
-                                          struct pci_dev *pcidev)
-{
-       const struct apci16xx_boardinfo *board;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(apci16xx_boardtypes); i++) {
-               board = &apci16xx_boardtypes[i];
-               if (board->vendor == pcidev->vendor &&
-                   board->device == pcidev->device)
-                       return board;
-       }
-       return NULL;
-}
-
 static int apci16xx_auto_attach(struct comedi_device *dev,
-                               unsigned long context_unused)
+                               unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct apci16xx_boardinfo *board;
+       const struct apci16xx_boardinfo *board = NULL;
        struct comedi_subdevice *s;
        unsigned int n_subdevs;
        unsigned int last;
        int i;
        int ret;
 
-       board = apci16xx_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(apci16xx_boardtypes))
+               board = &apci16xx_boardtypes[context];
        if (!board)
                return -ENODEV;
        dev->board_ptr = board;
        dev->board_name = board->name;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
 
@@ -204,35 +184,22 @@ static int apci16xx_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void apci16xx_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver apci16xx_driver = {
        .driver_name    = "addi_apci_16xx",
        .module         = THIS_MODULE,
        .auto_attach    = apci16xx_auto_attach,
-       .detach         = apci16xx_detach,
-       .num_names      = ARRAY_SIZE(apci16xx_boardtypes),
-       .board_name     = &apci16xx_boardtypes[0].name,
-       .offset         = sizeof(struct apci16xx_boardinfo),
+       .detach         = comedi_pci_disable,
 };
 
 static int apci16xx_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci16xx_driver);
+       return comedi_pci_auto_config(dev, &apci16xx_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci16xx_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1648) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1696) },
+       { PCI_VDEVICE(ADDIDATA, 0x1009), BOARD_APCI1648 },
+       { PCI_VDEVICE(ADDIDATA, 0x100a), BOARD_APCI1696 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, apci16xx_pci_table);
index e83e829831b006316fab913db848c9199f4f9c04..3640c50f2cb0d0cc6e4ce0cf21b553a7c4b47fa1 100644 (file)
@@ -21,72 +21,31 @@ static void fpu_end(void)
 #include "addi-data/addi_eeprom.c"
 #include "addi-data/hwdrv_APCI1710.c"
 
-static const struct addi_board apci1710_boardtypes[] = {
-       {
-               .pc_DriverName          = "apci1710",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA_OLD,
-               .i_DeviceId             = APCI1710_BOARD_DEVICE_ID,
-               .interrupt              = v_APCI1710_Interrupt,
-       },
-};
-
 static irqreturn_t v_ADDI_Interrupt(int irq, void *d)
 {
-       struct comedi_device *dev = d;
-       const struct addi_board *this_board = comedi_board(dev);
-
-       this_board->interrupt(irq, d);
+       v_APCI1710_Interrupt(irq, d);
        return IRQ_RETVAL(1);
 }
 
-static const void *apci1710_find_boardinfo(struct comedi_device *dev,
-                                          struct pci_dev *pcidev)
-{
-       const struct addi_board *this_board;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(apci1710_boardtypes); i++) {
-               this_board = &apci1710_boardtypes[i];
-               if (this_board->i_VendorId == pcidev->vendor &&
-                   this_board->i_DeviceId == pcidev->device)
-                       return this_board;
-       }
-       return NULL;
-}
-
 static int apci1710_auto_attach(struct comedi_device *dev,
                                          unsigned long context_unused)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct addi_board *this_board;
        struct addi_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
 
-       this_board = apci1710_find_boardinfo(dev, pcidev);
-       if (!this_board)
-               return -ENODEV;
-       dev->board_ptr = this_board;
-       dev->board_name = this_board->pc_DriverName;
+       dev->board_name = dev->driver->driver_name;
 
        devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
        if (!devpriv)
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
-
-       if (this_board->i_IorangeBase1)
-               dev->iobase = pci_resource_start(pcidev, 1);
-       else
-               dev->iobase = pci_resource_start(pcidev, 0);
-
-       devpriv->iobase = dev->iobase;
-       devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0);
-       devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2);
-       devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3);
+       devpriv->s_BoardInfos.ui_Address = pci_resource_start(pcidev, 2);
 
        if (pcidev->irq > 0) {
                ret = request_irq(pcidev->irq, v_ADDI_Interrupt, IRQF_SHARED,
@@ -97,24 +56,17 @@ static int apci1710_auto_attach(struct comedi_device *dev,
 
        i_ADDI_AttachPCI1710(dev);
 
-       devpriv->s_BoardInfos.ui_Address = pci_resource_start(pcidev, 2);
-
        i_APCI1710_Reset(dev);
        return 0;
 }
 
 static void apci1710_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                i_APCI1710_Reset(dev);
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci1710_driver = {
@@ -125,9 +77,9 @@ static struct comedi_driver apci1710_driver = {
 };
 
 static int apci1710_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci1710_driver);
+       return comedi_pci_auto_config(dev, &apci1710_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci1710_pci_table) = {
index 9ce1d26aff2fd67fabc147862c57e47f568a2469..59e092eab9f3455b723eb151314f9d84a32c235a 100644 (file)
@@ -289,7 +289,7 @@ static int apci2032_auto_attach(struct comedi_device *dev,
 
        dev->board_name = dev->driver->driver_name;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 1);
@@ -350,8 +350,6 @@ static int apci2032_auto_attach(struct comedi_device *dev,
 
 static void apci2032_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                apci2032_reset(dev);
        if (dev->irq)
@@ -360,10 +358,7 @@ static void apci2032_detach(struct comedi_device *dev)
                kfree(dev->read_subdev->private);
        if (dev->subdevices)
                addi_watchdog_cleanup(&dev->subdevices[1]);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci2032_driver = {
@@ -374,9 +369,9 @@ static struct comedi_driver apci2032_driver = {
 };
 
 static int apci2032_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci2032_driver);
+       return comedi_pci_auto_config(dev, &apci2032_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci2032_pci_table) = {
index b1c4226902e14c4376ae467b83982a67d1b4086a..0953f65ab0ad67f5a8f370f003856ffe732d139a 100644 (file)
@@ -90,7 +90,7 @@ static int apci2200_auto_attach(struct comedi_device *dev,
 
        dev->board_name = dev->driver->driver_name;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
 
@@ -130,16 +130,11 @@ static int apci2200_auto_attach(struct comedi_device *dev,
 
 static void apci2200_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                apci2200_reset(dev);
        if (dev->subdevices)
                addi_watchdog_cleanup(&dev->subdevices[2]);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci2200_driver = {
@@ -150,9 +145,9 @@ static struct comedi_driver apci2200_driver = {
 };
 
 static int apci2200_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci2200_driver);
+       return comedi_pci_auto_config(dev, &apci2200_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci2200_pci_table) = {
index 917234d24e9929c7c9c055cf896288d770152111..1c5ac16aad156226b1b928aec6508d074279a6eb 100644 (file)
@@ -8,11 +8,14 @@
 
 #include "addi-data/hwdrv_apci3120.c"
 
+enum apci3120_boardid {
+       BOARD_APCI3120,
+       BOARD_APCI3001,
+};
+
 static const struct addi_board apci3120_boardtypes[] = {
-       {
+       [BOARD_APCI3120] = {
                .pc_DriverName          = "apci3120",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA_OLD,
-               .i_DeviceId             = 0x818D,
                .i_NbrAiChannel         = 16,
                .i_NbrAiChannelDiff     = 8,
                .i_AiChannelList        = 16,
@@ -23,10 +26,9 @@ static const struct addi_board apci3120_boardtypes[] = {
                .i_NbrDoChannel         = 4,
                .i_DoMaxdata            = 0x0f,
                .interrupt              = v_APCI3120_Interrupt,
-       }, {
+       },
+       [BOARD_APCI3001] = {
                .pc_DriverName          = "apci3001",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA_OLD,
-               .i_DeviceId             = 0x828D,
                .i_NbrAiChannel         = 16,
                .i_NbrAiChannelDiff     = 8,
                .i_AiChannelList        = 16,
@@ -47,31 +49,17 @@ static irqreturn_t v_ADDI_Interrupt(int irq, void *d)
        return IRQ_RETVAL(1);
 }
 
-static const void *apci3120_find_boardinfo(struct comedi_device *dev,
-                                          struct pci_dev *pcidev)
-{
-       const struct addi_board *this_board;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(apci3120_boardtypes); i++) {
-               this_board = &apci3120_boardtypes[i];
-               if (this_board->i_VendorId == pcidev->vendor &&
-                   this_board->i_DeviceId == pcidev->device)
-                       return this_board;
-       }
-       return NULL;
-}
-
 static int apci3120_auto_attach(struct comedi_device *dev,
-                                         unsigned long context_unused)
+                               unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct addi_board *this_board;
+       const struct addi_board *this_board = NULL;
        struct addi_private *devpriv;
        struct comedi_subdevice *s;
        int ret, pages, i;
 
-       this_board = apci3120_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(apci3120_boardtypes))
+               this_board = &apci3120_boardtypes[context];
        if (!this_board)
                return -ENODEV;
        dev->board_ptr = this_board;
@@ -82,7 +70,7 @@ static int apci3120_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        pci_set_master(pcidev);
@@ -215,7 +203,6 @@ static int apci3120_auto_attach(struct comedi_device *dev,
 
 static void apci3120_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct addi_private *devpriv = dev->private;
 
        if (devpriv) {
@@ -234,10 +221,7 @@ static void apci3120_detach(struct comedi_device *dev)
                                devpriv->ui_DmaBufferPages[1]);
                }
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci3120_driver = {
@@ -248,14 +232,14 @@ static struct comedi_driver apci3120_driver = {
 };
 
 static int apci3120_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci3120_driver);
+       return comedi_pci_auto_config(dev, &apci3120_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci3120_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, 0x818d) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, 0x828d) },
+       { PCI_VDEVICE(ADDIDATA_OLD, 0x818d), BOARD_APCI3120 },
+       { PCI_VDEVICE(ADDIDATA_OLD, 0x828d), BOARD_APCI3001 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, apci3120_pci_table);
index 90ee4f844f914a2884520ca209b174bf4a886054..4b492a0897b8bc11a97310056844286a85921fbf 100644 (file)
@@ -22,11 +22,14 @@ static void fpu_end(void)
 #include "addi-data/hwdrv_apci3200.c"
 #include "addi-data/addi_common.c"
 
+enum apci3200_boardid {
+       BOARD_APCI3200,
+       BOARD_APCI3300,
+};
+
 static const struct addi_board apci3200_boardtypes[] = {
-       {
+       [BOARD_APCI3200] = {
                .pc_DriverName          = "apci3200",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3000,
                .i_IorangeBase0         = 128,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 4,
@@ -53,10 +56,9 @@ static const struct addi_board apci3200_boardtypes[] = {
                .ai_cancel              = i_APCI3200_StopCyclicAcquisition,
                .di_bits                = apci3200_di_insn_bits,
                .do_bits                = apci3200_do_insn_bits,
-       }, {
+       },
+       [BOARD_APCI3300] = {
                .pc_DriverName          = "apci3300",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3007,
                .i_IorangeBase0         = 128,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 4,
@@ -85,29 +87,40 @@ static const struct addi_board apci3200_boardtypes[] = {
        },
 };
 
-static DEFINE_PCI_DEVICE_TABLE(apci3200_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3000) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3007) },
-       { 0 }
-};
-MODULE_DEVICE_TABLE(pci, apci3200_pci_table);
+static int apci3200_auto_attach(struct comedi_device *dev,
+                               unsigned long context)
+{
+       const struct addi_board *board = NULL;
+
+       if (context < ARRAY_SIZE(apci3200_boardtypes))
+               board = &apci3200_boardtypes[context];
+       if (!board)
+               return -ENODEV;
+       dev->board_ptr = board;
+
+       return addi_auto_attach(dev, context);
+}
 
 static struct comedi_driver apci3200_driver = {
        .driver_name    = "addi_apci_3200",
        .module         = THIS_MODULE,
-       .auto_attach    = addi_auto_attach,
+       .auto_attach    = apci3200_auto_attach,
        .detach         = i_ADDI_Detach,
-       .num_names      = ARRAY_SIZE(apci3200_boardtypes),
-       .board_name     = &apci3200_boardtypes[0].pc_DriverName,
-       .offset         = sizeof(struct addi_board),
 };
 
 static int apci3200_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci3200_driver);
+       return comedi_pci_auto_config(dev, &apci3200_driver, id->driver_data);
 }
 
+static DEFINE_PCI_DEVICE_TABLE(apci3200_pci_table) = {
+       { PCI_VDEVICE(ADDIDATA, 0x3000), BOARD_APCI3200 },
+       { PCI_VDEVICE(ADDIDATA, 0x3007), BOARD_APCI3300 },
+       { 0 }
+};
+MODULE_DEVICE_TABLE(pci, apci3200_pci_table);
+
 static struct pci_driver apci3200_pci_driver = {
        .name           = "addi_apci_3200",
        .id_table       = apci3200_pci_table,
index 786fcaf82c324ef428e5721ce34348df9885b22f..75a36e364932fd094102b87b0dc61b6c8ddf20d2 100644 (file)
@@ -346,7 +346,7 @@ static int apci3501_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
 
@@ -423,16 +423,11 @@ static int apci3501_auto_attach(struct comedi_device *dev,
 
 static void apci3501_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                apci3501_reset(dev);
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci3501_driver = {
@@ -443,9 +438,9 @@ static struct comedi_driver apci3501_driver = {
 };
 
 static int apci3501_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci3501_driver);
+       return comedi_pci_auto_config(dev, &apci3501_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci3501_pci_table) = {
index 09d4b21fce23703f034be264404cfa1f8ca583ec..1afc62cb07c587135b4ecffea2df0ad5cb5d5dc8 100644 (file)
 #include "addi-data/hwdrv_apci3xxx.c"
 #include "addi-data/addi_common.c"
 
+enum apci3xxx_boardid {
+       BOARD_APCI3000_16,
+       BOARD_APCI3000_8,
+       BOARD_APCI3000_4,
+       BOARD_APCI3006_16,
+       BOARD_APCI3006_8,
+       BOARD_APCI3006_4,
+       BOARD_APCI3010_16,
+       BOARD_APCI3010_8,
+       BOARD_APCI3010_4,
+       BOARD_APCI3016_16,
+       BOARD_APCI3016_8,
+       BOARD_APCI3016_4,
+       BOARD_APCI3100_16_4,
+       BOARD_APCI3100_8_4,
+       BOARD_APCI3106_16_4,
+       BOARD_APCI3106_8_4,
+       BOARD_APCI3110_16_4,
+       BOARD_APCI3110_8_4,
+       BOARD_APCI3116_16_4,
+       BOARD_APCI3116_8_4,
+       BOARD_APCI3003,
+       BOARD_APCI3002_16,
+       BOARD_APCI3002_8,
+       BOARD_APCI3002_4,
+       BOARD_APCI3500,
+};
+
 static const struct addi_board apci3xxx_boardtypes[] = {
-       {
+       [BOARD_APCI3000_16] = {
                .pc_DriverName          = "apci3000-16",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3010,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -37,10 +63,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3000_8] = {
                .pc_DriverName          = "apci3000-8",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x300F,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -63,10 +88,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3000_4] = {
                .pc_DriverName          = "apci3000-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x300E,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -89,10 +113,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3006_16] = {
                .pc_DriverName          = "apci3006-16",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3013,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -115,10 +138,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3006_8] = {
                .pc_DriverName          = "apci3006-8",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3014,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -141,10 +163,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3006_4] = {
                .pc_DriverName          = "apci3006-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3015,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -167,10 +188,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3010_16] = {
                .pc_DriverName          = "apci3010-16",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3016,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -198,10 +218,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3010_8] = {
                .pc_DriverName          = "apci3010-8",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3017,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -229,10 +248,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3010_4] = {
                .pc_DriverName          = "apci3010-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3018,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -260,10 +278,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3016_16] = {
                .pc_DriverName          = "apci3016-16",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3019,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -291,10 +308,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3016_8] = {
                .pc_DriverName          = "apci3016-8",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x301A,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -322,10 +338,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3016_4] = {
                .pc_DriverName          = "apci3016-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x301B,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -353,10 +368,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3100_16_4] = {
                .pc_DriverName          = "apci3100-16-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x301C,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -383,10 +397,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3100_8_4] = {
                .pc_DriverName          = "apci3100-8-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x301D,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -413,10 +426,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3106_16_4] = {
                .pc_DriverName          = "apci3106-16-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x301E,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -443,10 +455,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3106_8_4] = {
                .pc_DriverName          = "apci3106-8-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x301F,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -473,10 +484,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3110_16_4] = {
                .pc_DriverName          = "apci3110-16-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3020,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -508,10 +518,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3110_8_4] = {
                .pc_DriverName          = "apci3110-8-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3021,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -543,10 +552,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3116_16_4] = {
                .pc_DriverName          = "apci3116-16-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3022,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -578,10 +586,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3116_8_4] = {
                .pc_DriverName          = "apci3116-8-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3023,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -613,10 +620,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ttl_bits               = i_APCI3XXX_InsnBitsTTLIO,
                .ttl_read               = i_APCI3XXX_InsnReadTTLIO,
                .ttl_write              = i_APCI3XXX_InsnWriteTTLIO,
-       }, {
+       },
+       [BOARD_APCI3003] = {
                .pc_DriverName          = "apci3003",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x300B,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -638,10 +644,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ai_read                = i_APCI3XXX_InsnReadAnalogInput,
                .di_bits                = apci3xxx_di_insn_bits,
                .do_bits                = apci3xxx_do_insn_bits,
-       }, {
+       },
+       [BOARD_APCI3002_16] = {
                .pc_DriverName          = "apci3002-16",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3002,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -663,10 +668,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ai_read                = i_APCI3XXX_InsnReadAnalogInput,
                .di_bits                = apci3xxx_di_insn_bits,
                .do_bits                = apci3xxx_do_insn_bits,
-       }, {
+       },
+       [BOARD_APCI3002_8] = {
                .pc_DriverName          = "apci3002-8",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3003,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -688,10 +692,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ai_read                = i_APCI3XXX_InsnReadAnalogInput,
                .di_bits                = apci3xxx_di_insn_bits,
                .do_bits                = apci3xxx_do_insn_bits,
-       }, {
+       },
+       [BOARD_APCI3002_4] = {
                .pc_DriverName          = "apci3002-4",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3004,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -713,10 +716,9 @@ static const struct addi_board apci3xxx_boardtypes[] = {
                .ai_read                = i_APCI3XXX_InsnReadAnalogInput,
                .di_bits                = apci3xxx_di_insn_bits,
                .do_bits                = apci3xxx_do_insn_bits,
-       }, {
+       },
+       [BOARD_APCI3500] = {
                .pc_DriverName          = "apci3500",
-               .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
-               .i_DeviceId             = 0x3024,
                .i_IorangeBase0         = 256,
                .i_IorangeBase1         = 256,
                .i_IorangeBase2         = 256,
@@ -737,48 +739,59 @@ static const struct addi_board apci3xxx_boardtypes[] = {
        },
 };
 
+static int apci3xxx_auto_attach(struct comedi_device *dev,
+                               unsigned long context)
+{
+       const struct addi_board *board = NULL;
+
+       if (context < ARRAY_SIZE(apci3xxx_boardtypes))
+               board = &apci3xxx_boardtypes[context];
+       if (!board)
+               return -ENODEV;
+       dev->board_ptr = board;
+
+       return addi_auto_attach(dev, context);
+}
+
 static struct comedi_driver apci3xxx_driver = {
        .driver_name    = "addi_apci_3xxx",
        .module         = THIS_MODULE,
-       .auto_attach    = addi_auto_attach,
+       .auto_attach    = apci3xxx_auto_attach,
        .detach         = i_ADDI_Detach,
-       .num_names      = ARRAY_SIZE(apci3xxx_boardtypes),
-       .board_name     = &apci3xxx_boardtypes[0].pc_DriverName,
-       .offset         = sizeof(struct addi_board),
 };
 
 static int apci3xxx_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci3xxx_driver);
+       return comedi_pci_auto_config(dev, &apci3xxx_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci3xxx_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3010) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x300f) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x300e) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3013) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3014) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3015) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3016) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3017) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3018) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3019) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x301a) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x301b) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x301c) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x301d) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x301e) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x301f) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3020) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3021) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3022) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3023) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x300B) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3002) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3003) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3004) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3024) },
+       { PCI_VDEVICE(ADDIDATA, 0x3010), BOARD_APCI3000_16 },
+       { PCI_VDEVICE(ADDIDATA, 0x300f), BOARD_APCI3000_8 },
+       { PCI_VDEVICE(ADDIDATA, 0x300e), BOARD_APCI3000_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x3013), BOARD_APCI3006_16 },
+       { PCI_VDEVICE(ADDIDATA, 0x3014), BOARD_APCI3006_8 },
+       { PCI_VDEVICE(ADDIDATA, 0x3015), BOARD_APCI3006_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x3016), BOARD_APCI3010_16 },
+       { PCI_VDEVICE(ADDIDATA, 0x3017), BOARD_APCI3010_8 },
+       { PCI_VDEVICE(ADDIDATA, 0x3018), BOARD_APCI3010_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x3019), BOARD_APCI3016_16 },
+       { PCI_VDEVICE(ADDIDATA, 0x301a), BOARD_APCI3016_8 },
+       { PCI_VDEVICE(ADDIDATA, 0x301b), BOARD_APCI3016_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x301c), BOARD_APCI3100_16_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x301d), BOARD_APCI3100_8_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x301e), BOARD_APCI3106_16_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x301f), BOARD_APCI3106_8_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x3020), BOARD_APCI3110_16_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x3021), BOARD_APCI3110_8_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x3022), BOARD_APCI3116_16_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x3023), BOARD_APCI3116_8_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x300B), BOARD_APCI3003 },
+       { PCI_VDEVICE(ADDIDATA, 0x3002), BOARD_APCI3002_16 },
+       { PCI_VDEVICE(ADDIDATA, 0x3003), BOARD_APCI3002_8 },
+       { PCI_VDEVICE(ADDIDATA, 0x3004), BOARD_APCI3002_4 },
+       { PCI_VDEVICE(ADDIDATA, 0x3024), BOARD_APCI3500 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, apci3xxx_pci_table);
index 7b3e331616ed13866cb7f3af5a7573fcf156369a..8a438ff1bd45979f7ec391b0a9d88e5d58221f81 100644 (file)
@@ -46,12 +46,6 @@ References:
 
 #include "../comedidev.h"
 
-/*
- * ADLINK PCI Device ID's supported by this driver
- */
-#define PCI_DEVICE_ID_PCI6208          0x6208
-#define PCI_DEVICE_ID_PCI6216          0x6216
-
 /*
  * PCI-6208/6216-GL register map
  */
@@ -66,20 +60,23 @@ References:
 
 #define PCI6208_MAX_AO_CHANNELS                16
 
+enum pci6208_boardid {
+       BOARD_PCI6208,
+       BOARD_PCI6216,
+};
+
 struct pci6208_board {
        const char *name;
-       unsigned short dev_id;
        int ao_chans;
 };
 
 static const struct pci6208_board pci6208_boards[] = {
-       {
+       [BOARD_PCI6208] = {
                .name           = "adl_pci6208",
-               .dev_id         = PCI_DEVICE_ID_PCI6208,
                .ao_chans       = 8,
-       }, {
+       },
+       [BOARD_PCI6216] = {
                .name           = "adl_pci6216",
-               .dev_id         = PCI_DEVICE_ID_PCI6216,
                .ao_chans       = 16,
        },
 };
@@ -162,31 +159,18 @@ static int pci6208_do_insn_bits(struct comedi_device *dev,
        return insn->n;
 }
 
-static const void *pci6208_find_boardinfo(struct comedi_device *dev,
-                                         struct pci_dev *pcidev)
-{
-       const struct pci6208_board *boardinfo;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(pci6208_boards); i++) {
-               boardinfo = &pci6208_boards[i];
-               if (boardinfo->dev_id == pcidev->device)
-                       return boardinfo;
-       }
-       return NULL;
-}
-
 static int pci6208_auto_attach(struct comedi_device *dev,
-                                        unsigned long context_unused)
+                              unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct pci6208_board *boardinfo;
+       const struct pci6208_board *boardinfo = NULL;
        struct pci6208_private *devpriv;
        struct comedi_subdevice *s;
        unsigned int val;
        int ret;
 
-       boardinfo = pci6208_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(pci6208_boards))
+               boardinfo = &pci6208_boards[context];
        if (!boardinfo)
                return -ENODEV;
        dev->board_ptr = boardinfo;
@@ -197,7 +181,7 @@ static int pci6208_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 2);
@@ -249,32 +233,23 @@ static int pci6208_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void pci6208_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver adl_pci6208_driver = {
        .driver_name    = "adl_pci6208",
        .module         = THIS_MODULE,
        .auto_attach    = pci6208_auto_attach,
-       .detach         = pci6208_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int adl_pci6208_pci_probe(struct pci_dev *dev,
-                                          const struct pci_device_id *ent)
+                                const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &adl_pci6208_driver);
+       return comedi_pci_auto_config(dev, &adl_pci6208_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(adl_pci6208_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI6208) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI6216) },
+       { PCI_VDEVICE(ADLINK, 0x6208), BOARD_PCI6208 },
+       { PCI_VDEVICE(ADLINK, 0x6216), BOARD_PCI6216 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
index f27f48e6e70231cdff244a51c98e7fb7e62e52c6..e3960745f506ed671041b86ebbf48bb8353a7db3 100644 (file)
@@ -52,61 +52,58 @@ Configuration Options: not applicable, uses comedi PCI auto config
 
 #include "../comedidev.h"
 
-/*
- * PCI Device ID's supported by this driver
- */
-#define PCI_DEVICE_ID_PCI7230  0x7230
-#define PCI_DEVICE_ID_PCI7233  0x7233
-#define PCI_DEVICE_ID_PCI7234  0x7234
-#define PCI_DEVICE_ID_PCI7432  0x7432
-#define PCI_DEVICE_ID_PCI7433  0x7433
-#define PCI_DEVICE_ID_PCI7434  0x7434
-
 /*
  * Register I/O map (32-bit access only)
  */
 #define PCI7X3X_DIO_REG                0x00
 #define PCI743X_DIO_REG                0x04
 
+enum apci1516_boardid {
+       BOARD_PCI7230,
+       BOARD_PCI7233,
+       BOARD_PCI7234,
+       BOARD_PCI7432,
+       BOARD_PCI7433,
+       BOARD_PCI7434,
+};
+
 struct adl_pci7x3x_boardinfo {
        const char *name;
-       unsigned short device;
        int nsubdevs;
        int di_nchan;
        int do_nchan;
 };
 
 static const struct adl_pci7x3x_boardinfo adl_pci7x3x_boards[] = {
-       {
+       [BOARD_PCI7230] = {
                .name           = "adl_pci7230",
-               .device         = PCI_DEVICE_ID_PCI7230,
                .nsubdevs       = 2,
                .di_nchan       = 16,
                .do_nchan       = 16,
-       }, {
+       },
+       [BOARD_PCI7233] = {
                .name           = "adl_pci7233",
-               .device         = PCI_DEVICE_ID_PCI7233,
                .nsubdevs       = 1,
                .di_nchan       = 32,
-       }, {
+       },
+       [BOARD_PCI7234] = {
                .name           = "adl_pci7234",
-               .device         = PCI_DEVICE_ID_PCI7234,
                .nsubdevs       = 1,
                .do_nchan       = 32,
-       }, {
+       },
+       [BOARD_PCI7432] = {
                .name           = "adl_pci7432",
-               .device         = PCI_DEVICE_ID_PCI7432,
                .nsubdevs       = 2,
                .di_nchan       = 32,
                .do_nchan       = 32,
-       }, {
+       },
+       [BOARD_PCI7433] = {
                .name           = "adl_pci7433",
-               .device         = PCI_DEVICE_ID_PCI7433,
                .nsubdevs       = 2,
                .di_nchan       = 64,
-       }, {
+       },
+       [BOARD_PCI7434] = {
                .name           = "adl_pci7434",
-               .device         = PCI_DEVICE_ID_PCI7434,
                .nsubdevs       = 2,
                .do_nchan       = 64,
        }
@@ -150,37 +147,24 @@ static int adl_pci7x3x_di_insn_bits(struct comedi_device *dev,
        return insn->n;
 }
 
-static const void *adl_pci7x3x_find_boardinfo(struct comedi_device *dev,
-                                             struct pci_dev *pcidev)
-{
-       const struct adl_pci7x3x_boardinfo *board;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(adl_pci7x3x_boards); i++) {
-               board = &adl_pci7x3x_boards[i];
-               if (pcidev->device == board->device)
-                       return board;
-       }
-       return NULL;
-}
-
 static int adl_pci7x3x_auto_attach(struct comedi_device *dev,
-                                            unsigned long context_unused)
+                                  unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct adl_pci7x3x_boardinfo *board;
+       const struct adl_pci7x3x_boardinfo *board = NULL;
        struct comedi_subdevice *s;
        int subdev;
        int nchan;
        int ret;
 
-       board = adl_pci7x3x_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(adl_pci7x3x_boards))
+               board = &adl_pci7x3x_boards[context];
        if (!board)
                return -ENODEV;
        dev->board_ptr = board;
        dev->board_name = board->name;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 2);
@@ -275,36 +259,27 @@ static int adl_pci7x3x_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void adl_pci7x3x_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver adl_pci7x3x_driver = {
        .driver_name    = "adl_pci7x3x",
        .module         = THIS_MODULE,
        .auto_attach    = adl_pci7x3x_auto_attach,
-       .detach         = adl_pci7x3x_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int adl_pci7x3x_pci_probe(struct pci_dev *dev,
-                                          const struct pci_device_id *ent)
+                                const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &adl_pci7x3x_driver);
+       return comedi_pci_auto_config(dev, &adl_pci7x3x_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(adl_pci7x3x_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7230) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7233) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7234) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7432) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7433) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7434) },
+       { PCI_VDEVICE(ADLINK, 0x7230), BOARD_PCI7230 },
+       { PCI_VDEVICE(ADLINK, 0x7233), BOARD_PCI7233 },
+       { PCI_VDEVICE(ADLINK, 0x7234), BOARD_PCI7234 },
+       { PCI_VDEVICE(ADLINK, 0x7432), BOARD_PCI7432 },
+       { PCI_VDEVICE(ADLINK, 0x7433), BOARD_PCI7433 },
+       { PCI_VDEVICE(ADLINK, 0x7434), BOARD_PCI7434 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, adl_pci7x3x_pci_table);
index d06b83f38653ba3a981559c98977be386acc027b..469a51d97b82cc407078cec01fbaef229b6e3dd0 100644 (file)
 /*
-    comedi/drivers/adl_pci8164.c
-
-    Hardware comedi driver fot PCI-8164 Adlink card
-    Copyright (C) 2004 Michel Lachine <mike@mikelachaine.ca>
-
-    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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * comedi/drivers/adl_pci8164.c
+ *
+ * Hardware comedi driver for PCI-8164 Adlink card
+ * Copyright (C) 2004 Michel Lachine <mike@mikelachaine.ca>
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 
-*/
 /*
-Driver: adl_pci8164
-Description: Driver for the Adlink PCI-8164 4 Axes Motion Control board
-Devices: [ADLink] PCI-8164 (adl_pci8164)
-Author: Michel Lachaine <mike@mikelachaine.ca>
-Status: experimental
-Updated: Mon, 14 Apr 2008 15:10:32 +0100
-
-Configuration Options: not applicable, uses PCI auto config
-*/
+ * Driver: adl_pci8164
+ * Description: Driver for the Adlink PCI-8164 4 Axes Motion Control board
+ * Devices: (ADLink) PCI-8164 [adl_pci8164]
+ * Author: Michel Lachaine <mike@mikelachaine.ca>
+ * Status: experimental
+ * Updated: Mon, 14 Apr 2008 15:10:32 +0100
+ *
+ * Configuration Options: not applicable, uses PCI auto config
+ */
 
 #include <linux/kernel.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 
 #include "../comedidev.h"
-#include "comedi_fc.h"
-#include "8253.h"
-
-#define PCI8164_AXIS_X  0x00
-#define PCI8164_AXIS_Y  0x08
-#define PCI8164_AXIS_Z  0x10
-#define PCI8164_AXIS_U  0x18
-
-#define PCI8164_MSTS   0x00
-#define PCI8164_SSTS    0x02
-#define PCI8164_BUF0    0x04
-#define PCI8164_BUF1    0x06
-
-#define PCI8164_CMD     0x00
-#define PCI8164_OTP     0x02
-
-#define PCI_DEVICE_ID_PCI8164 0x8164
-
-/*
- all the read commands are the same except for the addition a constant
- * const to the data for inw()
- */
-static void adl_pci8164_insn_read(struct comedi_device *dev,
-                                 struct comedi_subdevice *s,
-                                 struct comedi_insn *insn,
-                                 unsigned int *data,
-                                 char *action, unsigned short offset)
-{
-       int axis, axis_reg;
-       char axisname;
-
-       axis = CR_CHAN(insn->chanspec);
-
-       switch (axis) {
-       case 0:
-               axis_reg = PCI8164_AXIS_X;
-               axisname = 'X';
-               break;
-       case 1:
-               axis_reg = PCI8164_AXIS_Y;
-               axisname = 'Y';
-               break;
-       case 2:
-               axis_reg = PCI8164_AXIS_Z;
-               axisname = 'Z';
-               break;
-       case 3:
-               axis_reg = PCI8164_AXIS_U;
-               axisname = 'U';
-               break;
-       default:
-               axis_reg = PCI8164_AXIS_X;
-               axisname = 'X';
-       }
-
-       data[0] = inw(dev->iobase + axis_reg + offset);
-       dev_dbg(dev->class_dev,
-               "pci8164 %s read -> %04X:%04X on axis %c\n",
-               action, data[0], data[1], axisname);
-}
-
-static int adl_pci8164_insn_read_msts(struct comedi_device *dev,
-                                     struct comedi_subdevice *s,
-                                     struct comedi_insn *insn,
-                                     unsigned int *data)
-{
-       adl_pci8164_insn_read(dev, s, insn, data, "MSTS", PCI8164_MSTS);
-       return 2;
-}
-
-static int adl_pci8164_insn_read_ssts(struct comedi_device *dev,
-                                     struct comedi_subdevice *s,
-                                     struct comedi_insn *insn,
-                                     unsigned int *data)
-{
-       adl_pci8164_insn_read(dev, s, insn, data, "SSTS", PCI8164_SSTS);
-       return 2;
-}
-
-static int adl_pci8164_insn_read_buf0(struct comedi_device *dev,
-                                     struct comedi_subdevice *s,
-                                     struct comedi_insn *insn,
-                                     unsigned int *data)
-{
-       adl_pci8164_insn_read(dev, s, insn, data, "BUF0", PCI8164_BUF0);
-       return 2;
-}
 
-static int adl_pci8164_insn_read_buf1(struct comedi_device *dev,
-                                     struct comedi_subdevice *s,
-                                     struct comedi_insn *insn,
-                                     unsigned int *data)
-{
-       adl_pci8164_insn_read(dev, s, insn, data, "BUF1", PCI8164_BUF1);
-       return 2;
-}
+#define PCI8164_AXIS(x)                ((x) * 0x08)
+#define PCI8164_CMD_MSTS_REG   0x00
+#define PCI8164_OTP_SSTS_REG   0x02
+#define PCI8164_BUF0_REG       0x04
+#define PCI8164_BUF1_REG       0x06
 
-/*
- all the write commands are the same except for the addition a constant
- * const to the data for outw()
- */
-static void adl_pci8164_insn_out(struct comedi_device *dev,
+static int adl_pci8164_insn_read(struct comedi_device *dev,
                                 struct comedi_subdevice *s,
                                 struct comedi_insn *insn,
-                                unsigned int *data,
-                                char *action, unsigned short offset)
+                                unsigned int *data)
 {
-       unsigned int axis, axis_reg;
-
-       char axisname;
+       unsigned long offset = (unsigned long)s->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       int i;
 
-       axis = CR_CHAN(insn->chanspec);
-
-       switch (axis) {
-       case 0:
-               axis_reg = PCI8164_AXIS_X;
-               axisname = 'X';
-               break;
-       case 1:
-               axis_reg = PCI8164_AXIS_Y;
-               axisname = 'Y';
-               break;
-       case 2:
-               axis_reg = PCI8164_AXIS_Z;
-               axisname = 'Z';
-               break;
-       case 3:
-               axis_reg = PCI8164_AXIS_U;
-               axisname = 'U';
-               break;
-       default:
-               axis_reg = PCI8164_AXIS_X;
-               axisname = 'X';
-       }
-
-       outw(data[0], dev->iobase + axis_reg + offset);
-
-       dev_dbg(dev->class_dev,
-               "pci8164 %s write -> %04X:%04X on axis %c\n",
-               action, data[0], data[1], axisname);
+       for (i = 0; i < insn->n; i++)
+               data[i] = inw(dev->iobase + PCI8164_AXIS(chan) + offset);
 
+       return insn->n;
 }
 
-static int adl_pci8164_insn_write_cmd(struct comedi_device *dev,
-                                     struct comedi_subdevice *s,
-                                     struct comedi_insn *insn,
-                                     unsigned int *data)
-{
-       adl_pci8164_insn_out(dev, s, insn, data, "CMD", PCI8164_CMD);
-       return 2;
-}
-
-static int adl_pci8164_insn_write_otp(struct comedi_device *dev,
-                                     struct comedi_subdevice *s,
-                                     struct comedi_insn *insn,
-                                     unsigned int *data)
+static int adl_pci8164_insn_write(struct comedi_device *dev,
+                                 struct comedi_subdevice *s,
+                                 struct comedi_insn *insn,
+                                 unsigned int *data)
 {
-       adl_pci8164_insn_out(dev, s, insn, data, "OTP", PCI8164_OTP);
-       return 2;
-}
+       unsigned long offset = (unsigned long)s->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       int i;
 
-static int adl_pci8164_insn_write_buf0(struct comedi_device *dev,
-                                      struct comedi_subdevice *s,
-                                      struct comedi_insn *insn,
-                                      unsigned int *data)
-{
-       adl_pci8164_insn_out(dev, s, insn, data, "BUF0", PCI8164_BUF0);
-       return 2;
-}
+       for (i = 0; i < insn->n; i++)
+               outw(data[i], dev->iobase + PCI8164_AXIS(chan) + offset);
 
-static int adl_pci8164_insn_write_buf1(struct comedi_device *dev,
-                                      struct comedi_subdevice *s,
-                                      struct comedi_insn *insn,
-                                      unsigned int *data)
-{
-       adl_pci8164_insn_out(dev, s, insn, data, "BUF1", PCI8164_BUF1);
-       return 2;
+       return insn->n;
 }
 
 static int adl_pci8164_auto_attach(struct comedi_device *dev,
@@ -223,7 +80,7 @@ static int adl_pci8164_auto_attach(struct comedi_device *dev,
 
        dev->board_name = dev->driver->driver_name;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 2);
@@ -232,77 +89,70 @@ static int adl_pci8164_auto_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
+       /* read MSTS register / write CMD register for each axis (channel) */
        s = &dev->subdevices[0];
-       s->type = COMEDI_SUBD_PROC;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-       s->n_chan = 4;
-       s->maxdata = 0xffff;
-       s->len_chanlist = 4;
-       /* s->range_table = &range_axis; */
-       s->insn_read = adl_pci8164_insn_read_msts;
-       s->insn_write = adl_pci8164_insn_write_cmd;
-
+       s->type         = COMEDI_SUBD_PROC;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
+       s->n_chan       = 4;
+       s->maxdata      = 0xffff;
+       s->len_chanlist = 4;
+       s->insn_read    = adl_pci8164_insn_read;
+       s->insn_write   = adl_pci8164_insn_write;
+       s->private      = (void *)PCI8164_CMD_MSTS_REG;
+
+       /* read SSTS register / write OTP register for each axis (channel) */
        s = &dev->subdevices[1];
-       s->type = COMEDI_SUBD_PROC;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-       s->n_chan = 4;
-       s->maxdata = 0xffff;
-       s->len_chanlist = 4;
-       /* s->range_table = &range_axis; */
-       s->insn_read = adl_pci8164_insn_read_ssts;
-       s->insn_write = adl_pci8164_insn_write_otp;
-
+       s->type         = COMEDI_SUBD_PROC;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
+       s->n_chan       = 4;
+       s->maxdata      = 0xffff;
+       s->len_chanlist = 4;
+       s->insn_read    = adl_pci8164_insn_read;
+       s->insn_write   = adl_pci8164_insn_write;
+       s->private      = (void *)PCI8164_OTP_SSTS_REG;
+
+       /* read/write BUF0 register for each axis (channel) */
        s = &dev->subdevices[2];
-       s->type = COMEDI_SUBD_PROC;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-       s->n_chan = 4;
-       s->maxdata = 0xffff;
-       s->len_chanlist = 4;
-       /* s->range_table = &range_axis; */
-       s->insn_read = adl_pci8164_insn_read_buf0;
-       s->insn_write = adl_pci8164_insn_write_buf0;
-
+       s->type         = COMEDI_SUBD_PROC;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
+       s->n_chan       = 4;
+       s->maxdata      = 0xffff;
+       s->len_chanlist = 4;
+       s->insn_read    = adl_pci8164_insn_read;
+       s->insn_write   = adl_pci8164_insn_write;
+       s->private      = (void *)PCI8164_BUF0_REG;
+
+       /* read/write BUF1 register for each axis (channel) */
        s = &dev->subdevices[3];
-       s->type = COMEDI_SUBD_PROC;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-       s->n_chan = 4;
-       s->maxdata = 0xffff;
-       s->len_chanlist = 4;
-       /* s->range_table = &range_axis; */
-       s->insn_read = adl_pci8164_insn_read_buf1;
-       s->insn_write = adl_pci8164_insn_write_buf1;
-
-       dev_info(dev->class_dev, "%s attached\n", dev->board_name);
+       s->type         = COMEDI_SUBD_PROC;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
+       s->n_chan       = 4;
+       s->maxdata      = 0xffff;
+       s->len_chanlist = 4;
+       s->insn_read    = adl_pci8164_insn_read;
+       s->insn_write   = adl_pci8164_insn_write;
+       s->private      = (void *)PCI8164_BUF1_REG;
 
        return 0;
 }
 
-static void adl_pci8164_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver adl_pci8164_driver = {
        .driver_name    = "adl_pci8164",
        .module         = THIS_MODULE,
        .auto_attach    = adl_pci8164_auto_attach,
-       .detach         = adl_pci8164_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int adl_pci8164_pci_probe(struct pci_dev *dev,
-                                          const struct pci_device_id *ent)
+                                const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &adl_pci8164_driver);
+       return comedi_pci_auto_config(dev, &adl_pci8164_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(adl_pci8164_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164) },
-       {0}
+       { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, 0x8164) },
+       { 0 }
 };
 MODULE_DEVICE_TABLE(pci, adl_pci8164_pci_table);
 
index eeb10ec7f178ed02728bc3f75403cb17dfe59829..9c27e981db0c5255f545cf63bfc3c2b8b0b3857c 100644 (file)
@@ -872,7 +872,7 @@ static int pci9111_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = dev_private;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev_private->lcr_io_base = pci_resource_start(pcidev, 1);
@@ -939,16 +939,11 @@ static int pci9111_auto_attach(struct comedi_device *dev,
 
 static void pci9111_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                pci9111_reset(dev);
        if (dev->irq != 0)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver adl_pci9111_driver = {
@@ -959,9 +954,10 @@ static struct comedi_driver adl_pci9111_driver = {
 };
 
 static int pci9111_pci_probe(struct pci_dev *dev,
-                                      const struct pci_device_id *ent)
+                            const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &adl_pci9111_driver);
+       return comedi_pci_auto_config(dev, &adl_pci9111_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(pci9111_pci_table) = {
index 4dbac7459a4890b6c75350bac4943d30b848855c..cb4ef2dcbf020133bd78580ee33faf62b074a7bc 100644 (file)
@@ -1970,12 +1970,9 @@ static int pci9118_common_attach(struct comedi_device *dev, int disable_irq,
        u16 u16w;
 
        dev->board_name = this_board->name;
-       ret = comedi_pci_enable(pcidev, dev->board_name);
-       if (ret) {
-               dev_err(dev->class_dev,
-                       "cannot enable PCI device %s\n", pci_name(pcidev));
+       ret = comedi_pci_enable(dev);
+       if (ret)
                return ret;
-       }
        if (master)
                pci_set_master(pcidev);
 
@@ -2202,12 +2199,9 @@ static void pci9118_detach(struct comedi_device *dev)
                        free_pages((unsigned long)devpriv->dmabuf_virt[1],
                                   devpriv->dmabuf_pages[1]);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-
+       comedi_pci_disable(dev);
+       if (pcidev)
                pci_dev_put(pcidev);
-       }
 }
 
 static struct comedi_driver adl_pci9118_driver = {
@@ -2222,9 +2216,10 @@ static struct comedi_driver adl_pci9118_driver = {
 };
 
 static int adl_pci9118_pci_probe(struct pci_dev *dev,
-                                          const struct pci_device_id *ent)
+                                const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &adl_pci9118_driver);
+       return comedi_pci_auto_config(dev, &adl_pci9118_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(adl_pci9118_pci_table) = {
index 3d788c76d6484964af503e9e96788c1b8590efc9..f847bbc175e72103a59d528a0e026e98f5db44d4 100644 (file)
@@ -59,9 +59,6 @@ Configuration options:
 #define TYPE_PCI1713   2
 #define TYPE_PCI1720   3
 
-#define IORANGE_171x   32
-#define IORANGE_1720   16
-
 #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 */
@@ -178,10 +175,17 @@ static const struct comedi_lrange range_pci171x_da = { 2, {
                                                           }
 };
 
+enum pci1710_boardid {
+       BOARD_PCI1710,
+       BOARD_PCI1710HG,
+       BOARD_PCI1711,
+       BOARD_PCI1713,
+       BOARD_PCI1720,
+       BOARD_PCI1731,
+};
+
 struct boardtype {
        const char *name;       /*  board name */
-       int device_id;
-       int iorange;            /*  I/O range len */
        char have_irq;          /*  1=card support IRQ */
        char cardtype;          /*  0=1710& co. 2=1713, ... */
        int n_aichan;           /*  num of A/D chans */
@@ -200,10 +204,8 @@ struct boardtype {
 };
 
 static const struct boardtype boardtypes[] = {
-       {
+       [BOARD_PCI1710] = {
                .name           = "pci1710",
-               .device_id      = 0x1710,
-               .iorange        = IORANGE_171x,
                .have_irq       = 1,
                .cardtype       = TYPE_PCI171X,
                .n_aichan       = 16,
@@ -219,10 +221,9 @@ static const struct boardtype boardtypes[] = {
                .rangelist_ao   = &range_pci171x_da,
                .ai_ns_min      = 10000,
                .fifo_half_size = 2048,
-       }, {
+       },
+       [BOARD_PCI1710HG] = {
                .name           = "pci1710hg",
-               .device_id      = 0x1710,
-               .iorange        = IORANGE_171x,
                .have_irq       = 1,
                .cardtype       = TYPE_PCI171X,
                .n_aichan       = 16,
@@ -238,10 +239,9 @@ static const struct boardtype boardtypes[] = {
                .rangelist_ao   = &range_pci171x_da,
                .ai_ns_min      = 10000,
                .fifo_half_size = 2048,
-       }, {
+       },
+       [BOARD_PCI1711] = {
                .name           = "pci1711",
-               .device_id      = 0x1711,
-               .iorange        = IORANGE_171x,
                .have_irq       = 1,
                .cardtype       = TYPE_PCI171X,
                .n_aichan       = 16,
@@ -256,10 +256,9 @@ static const struct boardtype boardtypes[] = {
                .rangelist_ao   = &range_pci171x_da,
                .ai_ns_min      = 10000,
                .fifo_half_size = 512,
-       }, {
+       },
+       [BOARD_PCI1713] = {
                .name           = "pci1713",
-               .device_id      = 0x1713,
-               .iorange        = IORANGE_171x,
                .have_irq       = 1,
                .cardtype       = TYPE_PCI1713,
                .n_aichan       = 32,
@@ -269,18 +268,16 @@ static const struct boardtype boardtypes[] = {
                .rangecode_ai   = range_codes_pci1710_3,
                .ai_ns_min      = 10000,
                .fifo_half_size = 2048,
-       }, {
+       },
+       [BOARD_PCI1720] = {
                .name           = "pci1720",
-               .device_id      = 0x1720,
-               .iorange        = IORANGE_1720,
                .cardtype       = TYPE_PCI1720,
                .n_aochan       = 4,
                .ao_maxdata     = 0x0fff,
                .rangelist_ao   = &range_pci1720,
-       }, {
+       },
+       [BOARD_PCI1731] = {
                .name           = "pci1731",
-               .device_id      = 0x1731,
-               .iorange        = IORANGE_171x,
                .have_irq       = 1,
                .cardtype       = TYPE_PCI171X,
                .n_aichan       = 16,
@@ -307,7 +304,7 @@ struct pci1710_private {
        unsigned int ai_et_CntrlReg;
        unsigned int ai_et_MuxVal;
        unsigned int ai_et_div1, ai_et_div2;
-       unsigned int act_chanlist[32];  /*  list of scaned channel */
+       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 char da_ranges;        /*  copy of D/A outpit range register */
@@ -334,7 +331,7 @@ static const unsigned int muxonechan[] = {
 
 /*
 ==============================================================================
- Check if channel list from user is builded correctly
+ Check if channel list from user is built correctly
  If it's ok, then program scan/gain logic.
  This works for all cards.
 */
@@ -1220,30 +1217,17 @@ static int pci1710_reset(struct comedi_device *dev)
        }
 }
 
-static const void *pci1710_find_boardinfo(struct comedi_device *dev,
-                                         struct pci_dev *pcidev)
-{
-       const struct boardtype *this_board;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(boardtypes); i++) {
-               this_board = &boardtypes[i];
-               if (pcidev->device == this_board->device_id)
-                       return this_board;
-       }
-       return NULL;
-}
-
 static int pci1710_auto_attach(struct comedi_device *dev,
-                                        unsigned long context_unused)
+                              unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct boardtype *this_board;
+       const struct boardtype *this_board = NULL;
        struct pci1710_private *devpriv;
        struct comedi_subdevice *s;
        int ret, subdev, n_subdevices;
 
-       this_board = pci1710_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(boardtypes))
+               this_board = &boardtypes[context];
        if (!this_board)
                return -ENODEV;
        dev->board_ptr = this_board;
@@ -1254,7 +1238,7 @@ static int pci1710_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 2);
@@ -1378,16 +1362,11 @@ static int pci1710_auto_attach(struct comedi_device *dev,
 
 static void pci1710_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                pci1710_reset(dev);
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver adv_pci1710_driver = {
@@ -1398,17 +1377,68 @@ static struct comedi_driver adv_pci1710_driver = {
 };
 
 static int adv_pci1710_pci_probe(struct pci_dev *dev,
-                                          const struct pci_device_id *ent)
+                                const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &adv_pci1710_driver);
+       return comedi_pci_auto_config(dev, &adv_pci1710_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(adv_pci1710_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1710) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1711) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1713) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1720) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1731) },
+       {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710,
+                              PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050),
+               .driver_data = BOARD_PCI1710,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710,
+                              PCI_VENDOR_ID_ADVANTECH, 0x0000),
+               .driver_data = BOARD_PCI1710,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710,
+                              PCI_VENDOR_ID_ADVANTECH, 0xb100),
+               .driver_data = BOARD_PCI1710,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710,
+                              PCI_VENDOR_ID_ADVANTECH, 0xb200),
+               .driver_data = BOARD_PCI1710,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710,
+                              PCI_VENDOR_ID_ADVANTECH, 0xc100),
+               .driver_data = BOARD_PCI1710,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710,
+                              PCI_VENDOR_ID_ADVANTECH, 0xc200),
+               .driver_data = BOARD_PCI1710,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710, 0x1000, 0xd100),
+               .driver_data = BOARD_PCI1710,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710,
+                              PCI_VENDOR_ID_ADVANTECH, 0x0002),
+               .driver_data = BOARD_PCI1710HG,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710,
+                              PCI_VENDOR_ID_ADVANTECH, 0xb102),
+               .driver_data = BOARD_PCI1710HG,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710,
+                              PCI_VENDOR_ID_ADVANTECH, 0xb202),
+               .driver_data = BOARD_PCI1710HG,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710,
+                              PCI_VENDOR_ID_ADVANTECH, 0xc102),
+               .driver_data = BOARD_PCI1710HG,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710,
+                              PCI_VENDOR_ID_ADVANTECH, 0xc202),
+               .driver_data = BOARD_PCI1710HG,
+       }, {
+               PCI_DEVICE_SUB(PCI_VENDOR_ID_ADVANTECH, 0x1710, 0x1000, 0xd102),
+               .driver_data = BOARD_PCI1710HG,
+       },
+       { PCI_VDEVICE(ADVANTECH, 0x1711), BOARD_PCI1711 },
+       { PCI_VDEVICE(ADVANTECH, 0x1713), BOARD_PCI1713 },
+       { PCI_VDEVICE(ADVANTECH, 0x1720), BOARD_PCI1720 },
+       { PCI_VDEVICE(ADVANTECH, 0x1731), BOARD_PCI1731 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, adv_pci1710_pci_table);
index 02ce55a01d2a502b52fde17464fa682f79920303..9e81e58a6e695d4a3f4ebc4f691aa121427c4f15 100644 (file)
@@ -249,7 +249,7 @@ static int pci1723_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 2);
@@ -306,14 +306,9 @@ static int pci1723_auto_attach(struct comedi_device *dev,
 
 static void pci1723_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase) {
-                       pci1723_reset(dev);
-                       comedi_pci_disable(pcidev);
-               }
-       }
+       if (dev->iobase)
+               pci1723_reset(dev);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver adv_pci1723_driver = {
@@ -324,9 +319,10 @@ static struct comedi_driver adv_pci1723_driver = {
 };
 
 static int adv_pci1723_pci_probe(struct pci_dev *dev,
-                                          const struct pci_device_id *ent)
+                                const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &adv_pci1723_driver);
+       return comedi_pci_auto_config(dev, &adv_pci1723_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(adv_pci1723_pci_table) = {
diff --git a/drivers/staging/comedi/drivers/adv_pci1724.c b/drivers/staging/comedi/drivers/adv_pci1724.c
new file mode 100644 (file)
index 0000000..a33929e
--- /dev/null
@@ -0,0 +1,411 @@
+/*
+    comedi/drivers/adv_pci1724.c
+    This is a driver for the Advantech PCI-1724U card.
+
+    Author:  Frank Mori Hess <fmh6jj@gmail.com>
+    Copyright (C) 2013 GnuBIO Inc
+
+    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.
+
+    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.
+
+************************************************************************/
+
+/*
+
+Driver: adv_1724
+Description: Advantech PCI-1724U
+Author: Frank Mori Hess <fmh6jj@gmail.com>
+Status: works
+Updated: 2013-02-09
+Devices: [Advantech] PCI-1724U (adv_pci1724)
+
+Subdevice 0 is the analog output.
+Subdevice 1 is the offset calibration for the analog output.
+Subdevice 2 is the gain calibration for the analog output.
+
+The calibration offset and gains have quite a large effect
+on the analog output, so it is possible to adjust the analog output to
+have an output range significantly different from the board's
+nominal output ranges.  For a calibrated +/- 10V range, the analog
+output's offset will be set somewhere near mid-range (0x2000) and its
+gain will be near maximum (0x3fff).
+
+There is really no difference between the board's documented 0-20mA
+versus 4-20mA output ranges.  To pick one or the other is simply a matter
+of adjusting the offset and gain calibration until the board outputs in
+the desired range.
+
+Configuration options:
+   None
+
+Manual configuration of comedi devices is not supported by this driver;
+supported PCI devices are configured as comedi devices automatically.
+
+*/
+
+#include <linux/pci.h>
+
+#include "../comedidev.h"
+
+#define PCI_VENDOR_ID_ADVANTECH        0x13fe
+
+#define NUM_AO_CHANNELS 32
+
+/* register offsets */
+enum board_registers {
+       DAC_CONTROL_REG = 0x0,
+       SYNC_OUTPUT_REG = 0x4,
+       EEPROM_CONTROL_REG = 0x8,
+       SYNC_OUTPUT_TRIGGER_REG = 0xc,
+       BOARD_ID_REG = 0x10
+};
+
+/* bit definitions for registers */
+enum dac_control_contents {
+       DAC_DATA_MASK = 0x3fff,
+       DAC_DESTINATION_MASK = 0xc000,
+       DAC_NORMAL_MODE = 0xc000,
+       DAC_OFFSET_MODE = 0x8000,
+       DAC_GAIN_MODE = 0x4000,
+       DAC_CHANNEL_SELECT_MASK = 0xf0000,
+       DAC_GROUP_SELECT_MASK = 0xf00000
+};
+
+static uint32_t dac_data_bits(uint16_t dac_data)
+{
+       return dac_data & DAC_DATA_MASK;
+}
+
+static uint32_t dac_channel_select_bits(unsigned channel)
+{
+       return (channel << 16) & DAC_CHANNEL_SELECT_MASK;
+}
+
+static uint32_t dac_group_select_bits(unsigned group)
+{
+       return (1 << (20 + group)) & DAC_GROUP_SELECT_MASK;
+}
+
+static uint32_t dac_channel_and_group_select_bits(unsigned comedi_channel)
+{
+       return dac_channel_select_bits(comedi_channel % 8) |
+               dac_group_select_bits(comedi_channel / 8);
+}
+
+enum sync_output_contents {
+       SYNC_MODE = 0x1,
+       DAC_BUSY = 0x2, /* dac state machine is not ready */
+};
+
+enum sync_output_trigger_contents {
+       SYNC_TRIGGER_BITS = 0x0 /* any value works */
+};
+
+enum board_id_contents {
+       BOARD_ID_MASK = 0xf
+};
+
+static const struct comedi_lrange ao_ranges_1724 = { 4,
+       {
+               BIP_RANGE(10),
+               RANGE_mA(0, 20),
+               RANGE_mA(4, 20),
+               RANGE_unitless(0, 1)
+       }
+};
+
+static const struct comedi_lrange *const ao_range_list_1724[NUM_AO_CHANNELS] = {
+       [0 ... NUM_AO_CHANNELS - 1] = &ao_ranges_1724,
+};
+
+/* this structure is for data unique to this hardware driver. */
+struct adv_pci1724_private {
+       int ao_value[NUM_AO_CHANNELS];
+       int offset_value[NUM_AO_CHANNELS];
+       int gain_value[NUM_AO_CHANNELS];
+};
+
+static int wait_for_dac_idle(struct comedi_device *dev)
+{
+       static const int timeout = 10000;
+       int i;
+
+       for (i = 0; i < timeout; ++i) {
+               if ((inl(dev->iobase + SYNC_OUTPUT_REG) & DAC_BUSY) == 0)
+                       break;
+               udelay(1);
+       }
+       if (i == timeout) {
+               comedi_error(dev, "Timed out waiting for dac to become idle.");
+               return -EIO;
+       }
+       return 0;
+}
+
+static int set_dac(struct comedi_device *dev, unsigned mode, unsigned channel,
+                  unsigned data)
+{
+       int retval;
+       unsigned control_bits;
+
+       retval = wait_for_dac_idle(dev);
+       if (retval < 0)
+               return retval;
+
+       control_bits = mode;
+       control_bits |= dac_channel_and_group_select_bits(channel);
+       control_bits |= dac_data_bits(data);
+       outl(control_bits, dev->iobase + DAC_CONTROL_REG);
+       return 0;
+}
+
+static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
+                   struct comedi_insn *insn, unsigned int *data)
+{
+       struct adv_pci1724_private *devpriv = dev->private;
+       int channel = CR_CHAN(insn->chanspec);
+       int retval;
+       int i;
+
+       /* turn off synchronous mode */
+       outl(0, dev->iobase + SYNC_OUTPUT_REG);
+
+       for (i = 0; i < insn->n; ++i) {
+               retval = set_dac(dev, DAC_NORMAL_MODE, channel, data[i]);
+               if (retval < 0)
+                       return retval;
+               devpriv->ao_value[channel] = data[i];
+       }
+       return insn->n;
+}
+
+static int ao_readback_insn(struct comedi_device *dev,
+                           struct comedi_subdevice *s,
+                           struct comedi_insn *insn, unsigned int *data)
+{
+       struct adv_pci1724_private *devpriv = dev->private;
+       int channel = CR_CHAN(insn->chanspec);
+       int i;
+
+       if (devpriv->ao_value[channel] < 0) {
+               comedi_error(dev,
+                            "Cannot read back channels which have not yet been written to.");
+               return -EIO;
+       }
+       for (i = 0; i < insn->n; i++)
+               data[i] = devpriv->ao_value[channel];
+
+       return insn->n;
+}
+
+static int offset_write_insn(struct comedi_device *dev,
+                            struct comedi_subdevice *s,
+                            struct comedi_insn *insn, unsigned int *data)
+{
+       struct adv_pci1724_private *devpriv = dev->private;
+       int channel = CR_CHAN(insn->chanspec);
+       int retval;
+       int i;
+
+       /* turn off synchronous mode */
+       outl(0, dev->iobase + SYNC_OUTPUT_REG);
+
+       for (i = 0; i < insn->n; ++i) {
+               retval = set_dac(dev, DAC_OFFSET_MODE, channel, data[i]);
+               if (retval < 0)
+                       return retval;
+               devpriv->offset_value[channel] = data[i];
+       }
+
+       return insn->n;
+}
+
+static int offset_read_insn(struct comedi_device *dev,
+                           struct comedi_subdevice *s,
+                           struct comedi_insn *insn, unsigned int *data)
+{
+       struct adv_pci1724_private *devpriv = dev->private;
+       unsigned int channel = CR_CHAN(insn->chanspec);
+       int i;
+
+       if (devpriv->offset_value[channel] < 0) {
+               comedi_error(dev,
+                            "Cannot read back channels which have not yet been written to.");
+               return -EIO;
+       }
+       for (i = 0; i < insn->n; i++)
+               data[i] = devpriv->offset_value[channel];
+
+       return insn->n;
+}
+
+static int gain_write_insn(struct comedi_device *dev,
+                          struct comedi_subdevice *s,
+                          struct comedi_insn *insn, unsigned int *data)
+{
+       struct adv_pci1724_private *devpriv = dev->private;
+       int channel = CR_CHAN(insn->chanspec);
+       int retval;
+       int i;
+
+       /* turn off synchronous mode */
+       outl(0, dev->iobase + SYNC_OUTPUT_REG);
+
+       for (i = 0; i < insn->n; ++i) {
+               retval = set_dac(dev, DAC_GAIN_MODE, channel, data[i]);
+               if (retval < 0)
+                       return retval;
+               devpriv->gain_value[channel] = data[i];
+       }
+
+       return insn->n;
+}
+
+static int gain_read_insn(struct comedi_device *dev,
+                         struct comedi_subdevice *s, struct comedi_insn *insn,
+                         unsigned int *data)
+{
+       struct adv_pci1724_private *devpriv = dev->private;
+       unsigned int channel = CR_CHAN(insn->chanspec);
+       int i;
+
+       if (devpriv->gain_value[channel] < 0) {
+               comedi_error(dev,
+                            "Cannot read back channels which have not yet been written to.");
+               return -EIO;
+       }
+       for (i = 0; i < insn->n; i++)
+               data[i] = devpriv->gain_value[channel];
+
+       return insn->n;
+}
+
+/* Allocate and initialize the subdevice structures.
+ */
+static int setup_subdevices(struct comedi_device *dev)
+{
+       struct comedi_subdevice *s;
+       int ret;
+
+       ret = comedi_alloc_subdevices(dev, 3);
+       if (ret)
+               return ret;
+
+       /* analog output subdevice */
+       s = &dev->subdevices[0];
+       s->type = COMEDI_SUBD_AO;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND;
+       s->n_chan = NUM_AO_CHANNELS;
+       s->maxdata = 0x3fff;
+       s->range_table_list = ao_range_list_1724;
+       s->insn_read = ao_readback_insn;
+       s->insn_write = ao_winsn;
+
+       /* offset calibration */
+       s = &dev->subdevices[1];
+       s->type = COMEDI_SUBD_CALIB;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
+       s->n_chan = NUM_AO_CHANNELS;
+       s->insn_read = offset_read_insn;
+       s->insn_write = offset_write_insn;
+       s->maxdata = 0x3fff;
+
+       /* gain calibration */
+       s = &dev->subdevices[2];
+       s->type = COMEDI_SUBD_CALIB;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
+       s->n_chan = NUM_AO_CHANNELS;
+       s->insn_read = gain_read_insn;
+       s->insn_write = gain_write_insn;
+       s->maxdata = 0x3fff;
+
+       return 0;
+}
+
+static int adv_pci1724_auto_attach(struct comedi_device *dev,
+                                  unsigned long context_unused)
+{
+       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+       struct adv_pci1724_private *devpriv;
+       int i;
+       int retval;
+       unsigned int board_id;
+
+       devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
+       if (!devpriv)
+               return -ENOMEM;
+       dev->private = devpriv;
+
+       /* init software copies of output values to indicate we don't know
+        * what the output value is since it has never been written. */
+       for (i = 0; i < NUM_AO_CHANNELS; ++i) {
+               devpriv->ao_value[i] = -1;
+               devpriv->offset_value[i] = -1;
+               devpriv->gain_value[i] = -1;
+       }
+
+       dev->board_name = dev->driver->driver_name;
+
+       retval = comedi_pci_enable(dev);
+       if (retval)
+               return retval;
+
+       dev->iobase = pci_resource_start(pcidev, 2);
+       board_id = inl(dev->iobase + BOARD_ID_REG) & BOARD_ID_MASK;
+       dev_info(dev->class_dev, "board id: %d\n", board_id);
+
+       retval = setup_subdevices(dev);
+       if (retval < 0)
+               return retval;
+
+       dev_info(dev->class_dev, "%s (pci %s) attached, board id: %u\n",
+                dev->board_name, pci_name(pcidev), board_id);
+       return 0;
+}
+
+static struct comedi_driver adv_pci1724_driver = {
+       .driver_name = "adv_pci1724",
+       .module = THIS_MODULE,
+       .auto_attach = adv_pci1724_auto_attach,
+       .detach = comedi_pci_disable,
+};
+
+static int adv_pci1724_pci_probe(struct pci_dev *dev,
+                                const struct pci_device_id *id)
+{
+       return comedi_pci_auto_config(dev, &adv_pci1724_driver,
+                                     id->driver_data);
+}
+
+static DEFINE_PCI_DEVICE_TABLE(adv_pci1724_pci_table) = {
+       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1724) },
+       { 0 }
+};
+MODULE_DEVICE_TABLE(pci, adv_pci1724_pci_table);
+
+static struct pci_driver adv_pci1724_pci_driver = {
+       .name = "adv_pci1724",
+       .id_table = adv_pci1724_pci_table,
+       .probe = adv_pci1724_pci_probe,
+       .remove = comedi_pci_auto_unconfig,
+};
+
+module_comedi_pci_driver(adv_pci1724_driver, adv_pci1724_pci_driver);
+
+MODULE_AUTHOR("Frank Mori Hess <fmh6jj@gmail.com>");
+MODULE_DESCRIPTION("Advantech PCI-1724U Comedi driver");
+MODULE_LICENSE("GPL");
index 338c43e716bae1fc7d504b7e86ee598974e9e11d..e98ddcc6ecfa44563a618657f12924cc89cf1872 100644 (file)
@@ -236,8 +236,6 @@ struct diosubd_data {
 
 struct dio_boardtype {
        const char *name;       /*  board name */
-       int vendor_id;          /*  vendor/device PCI ID */
-       int device_id;
        int main_pci_region;    /*  main I/O PCI region */
        enum hw_cards_id cardtype;
        int nsubdevs;
@@ -250,10 +248,8 @@ struct dio_boardtype {
 };
 
 static const struct dio_boardtype boardtypes[] = {
-       {
+       [TYPE_PCI1730] = {
                .name           = "pci1730",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1730,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1730,
                .nsubdevs       = 5,
@@ -263,30 +259,27 @@ static const struct dio_boardtype boardtypes[] = {
                .sdo[1]         = { 16, PCI1730_IDO, 2, 0, },
                .boardid        = { 4, PCI173x_BOARDID, 1, SDF_INTERNAL, },
                .io_access      = IO_8b,
-       }, {
+       },
+       [TYPE_PCI1733] = {
                .name           = "pci1733",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1733,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1733,
                .nsubdevs       = 2,
                .sdi[1]         = { 32, PCI1733_IDI, 4, 0, },
                .boardid        = { 4, PCI173x_BOARDID, 1, SDF_INTERNAL, },
                .io_access      = IO_8b,
-       }, {
+       },
+       [TYPE_PCI1734] = {
                .name           = "pci1734",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1734,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1734,
                .nsubdevs       = 2,
                .sdo[1]         = { 32, PCI1734_IDO, 4, 0, },
                .boardid        = { 4, PCI173x_BOARDID, 1, SDF_INTERNAL, },
                .io_access      = IO_8b,
-       }, {
+       },
+       [TYPE_PCI1735] = {
                .name           = "pci1735",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1735,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1735,
                .nsubdevs       = 4,
@@ -295,10 +288,9 @@ static const struct dio_boardtype boardtypes[] = {
                .boardid        = { 4, PCI1735_BOARDID, 1, SDF_INTERNAL, },
                .s8254[0]       = { 3, PCI1735_C8254, 1, 0, },
                .io_access      = IO_8b,
-       }, {
+       },
+       [TYPE_PCI1736] = {
                .name           = "pci1736",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1736,
                .main_pci_region = PCI1736_MAINREG,
                .cardtype       = TYPE_PCI1736,
                .nsubdevs       = 3,
@@ -306,39 +298,35 @@ static const struct dio_boardtype boardtypes[] = {
                .sdo[1]         = { 16, PCI1736_IDO, 2, 0, },
                .boardid        = { 4, PCI1736_BOARDID, 1, SDF_INTERNAL, },
                .io_access      = IO_8b,
-       }, {
+       },
+       [TYPE_PCI1739] = {
                .name           = "pci1739",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1739,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1739,
                .nsubdevs       = 2,
                .sdio[0]        = { 48, PCI1739_DIO, 2, 0, },
                .io_access      = IO_8b,
-       }, {
+       },
+       [TYPE_PCI1750] = {
                .name           = "pci1750",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1750,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1750,
                .nsubdevs       = 2,
                .sdi[1]         = { 16, PCI1750_IDI, 2, 0, },
                .sdo[1]         = { 16, PCI1750_IDO, 2, 0, },
                .io_access      = IO_8b,
-       }, {
+       },
+       [TYPE_PCI1751] = {
                .name           = "pci1751",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1751,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1751,
                .nsubdevs       = 3,
                .sdio[0]        = { 48, PCI1751_DIO, 2, 0, },
                .s8254[0]       = { 3, PCI1751_CNT, 1, 0, },
                .io_access      = IO_8b,
-       }, {
+       },
+       [TYPE_PCI1752] = {
                .name           = "pci1752",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1752,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1752,
                .nsubdevs       = 3,
@@ -346,29 +334,26 @@ static const struct dio_boardtype boardtypes[] = {
                .sdo[1]         = { 32, PCI1752_IDO2, 2, 0, },
                .boardid        = { 4, PCI175x_BOARDID, 1, SDF_INTERNAL, },
                .io_access      = IO_16b,
-       }, {
+       },
+       [TYPE_PCI1753] = {
                .name           = "pci1753",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1753,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1753,
                .nsubdevs       = 4,
                .sdio[0]        = { 96, PCI1753_DIO, 4, 0, },
                .io_access      = IO_8b,
-       }, {
+       },
+       [TYPE_PCI1753E] = {
                .name           = "pci1753e",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1753,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1753E,
                .nsubdevs       = 8,
                .sdio[0]        = { 96, PCI1753_DIO, 4, 0, },
                .sdio[1]        = { 96, PCI1753E_DIO, 4, 0, },
                .io_access      = IO_8b,
-       }, {
+       },
+       [TYPE_PCI1754] = {
                .name           = "pci1754",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1754,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1754,
                .nsubdevs       = 3,
@@ -376,10 +361,9 @@ static const struct dio_boardtype boardtypes[] = {
                .sdi[1]         = { 32, PCI1754_IDI2, 2, 0, },
                .boardid        = { 4, PCI175x_BOARDID, 1, SDF_INTERNAL, },
                .io_access      = IO_16b,
-       }, {
+       },
+       [TYPE_PCI1756] = {
                .name           = "pci1756",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1756,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1756,
                .nsubdevs       = 3,
@@ -387,19 +371,17 @@ static const struct dio_boardtype boardtypes[] = {
                .sdo[1]         = { 32, PCI1756_IDO, 2, 0, },
                .boardid        = { 4, PCI175x_BOARDID, 1, SDF_INTERNAL, },
                .io_access      = IO_16b,
-       }, {
+       },
+       [TYPE_PCI1760] = {
                /* This card has its own 'attach' */
                .name           = "pci1760",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1760,
                .main_pci_region = 0,
                .cardtype       = TYPE_PCI1760,
                .nsubdevs       = 4,
                .io_access      = IO_8b,
-       }, {
+       },
+       [TYPE_PCI1762] = {
                .name           = "pci1762",
-               .vendor_id      = PCI_VENDOR_ID_ADVANTECH,
-               .device_id      = 0x1762,
                .main_pci_region = PCIDIO_MAINREG,
                .cardtype       = TYPE_PCI1762,
                .nsubdevs       = 3,
@@ -1076,31 +1058,50 @@ static int pci_dio_add_8254(struct comedi_device *dev,
        return 0;
 }
 
-static const void *pci_dio_find_boardinfo(struct comedi_device *dev,
-                                         struct pci_dev *pcidev)
+static unsigned long pci_dio_override_cardtype(struct pci_dev *pcidev,
+                                              unsigned long cardtype)
 {
-       const struct dio_boardtype *this_board;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(boardtypes); ++i) {
-               this_board = &boardtypes[i];
-               if (this_board->vendor_id == pcidev->vendor &&
-                   this_board->device_id == pcidev->device)
-                       return this_board;
+       /*
+        * Change cardtype from TYPE_PCI1753 to TYPE_PCI1753E if expansion
+        * board available.  Need to enable PCI device and request the main
+        * registers PCI BAR temporarily to perform the test.
+        */
+       if (cardtype != TYPE_PCI1753)
+               return cardtype;
+       if (pci_enable_device(pcidev) < 0)
+               return cardtype;
+       if (pci_request_region(pcidev, PCIDIO_MAINREG, "adv_pci_dio") == 0) {
+               /*
+                * This test is based on Advantech's "advdaq" driver source
+                * (which declares its module licence as "GPL" although the
+                * driver source does not include a "COPYING" file).
+                */
+               unsigned long reg =
+                       pci_resource_start(pcidev, PCIDIO_MAINREG) + 53;
+
+               outb(0x05, reg);
+               if ((inb(reg) & 0x07) == 0x02) {
+                       outb(0x02, reg);
+                       if ((inb(reg) & 0x07) == 0x05)
+                               cardtype = TYPE_PCI1753E;
+               }
+               pci_release_region(pcidev, PCIDIO_MAINREG);
        }
-       return NULL;
+       pci_disable_device(pcidev);
+       return cardtype;
 }
 
 static int pci_dio_auto_attach(struct comedi_device *dev,
-                                        unsigned long context_unused)
+                              unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct dio_boardtype *this_board;
+       const struct dio_boardtype *this_board = NULL;
        struct pci_dio_private *devpriv;
        struct comedi_subdevice *s;
        int ret, subdev, i, j;
 
-       this_board = pci_dio_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(boardtypes))
+               this_board = &boardtypes[context];
        if (!this_board)
                return -ENODEV;
        dev->board_ptr = this_board;
@@ -1111,7 +1112,7 @@ static int pci_dio_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, this_board->main_pci_region);
@@ -1172,7 +1173,6 @@ static int pci_dio_auto_attach(struct comedi_device *dev,
 static void pci_dio_detach(struct comedi_device *dev)
 {
        struct pci_dio_private *devpriv = dev->private;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct comedi_subdevice *s;
        int i;
 
@@ -1188,10 +1188,7 @@ static void pci_dio_detach(struct comedi_device *dev)
                        s->private = NULL;
                }
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver adv_pci_dio_driver = {
@@ -1202,26 +1199,29 @@ static struct comedi_driver adv_pci_dio_driver = {
 };
 
 static int adv_pci_dio_pci_probe(struct pci_dev *dev,
-                                          const struct pci_device_id *ent)
+                                const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &adv_pci_dio_driver);
+       unsigned long cardtype;
+
+       cardtype = pci_dio_override_cardtype(dev, id->driver_data);
+       return comedi_pci_auto_config(dev, &adv_pci_dio_driver, cardtype);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(adv_pci_dio_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1730) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1733) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1734) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1735) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1736) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1739) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1750) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1751) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1752) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1753) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1754) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1756) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1760) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1762) },
+       { PCI_VDEVICE(ADVANTECH, 0x1730), TYPE_PCI1730 },
+       { PCI_VDEVICE(ADVANTECH, 0x1733), TYPE_PCI1733 },
+       { PCI_VDEVICE(ADVANTECH, 0x1734), TYPE_PCI1734 },
+       { PCI_VDEVICE(ADVANTECH, 0x1735), TYPE_PCI1735 },
+       { PCI_VDEVICE(ADVANTECH, 0x1736), TYPE_PCI1736 },
+       { PCI_VDEVICE(ADVANTECH, 0x1739), TYPE_PCI1739 },
+       { PCI_VDEVICE(ADVANTECH, 0x1750), TYPE_PCI1750 },
+       { PCI_VDEVICE(ADVANTECH, 0x1751), TYPE_PCI1751 },
+       { PCI_VDEVICE(ADVANTECH, 0x1752), TYPE_PCI1752 },
+       { PCI_VDEVICE(ADVANTECH, 0x1753), TYPE_PCI1753 },
+       { PCI_VDEVICE(ADVANTECH, 0x1754), TYPE_PCI1754 },
+       { PCI_VDEVICE(ADVANTECH, 0x1756), TYPE_PCI1756 },
+       { PCI_VDEVICE(ADVANTECH, 0x1760), TYPE_PCI1760 },
+       { PCI_VDEVICE(ADVANTECH, 0x1762), TYPE_PCI1762 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, adv_pci_dio_pci_table);
index 7c53dea12c7670fa015b0bf2b5ff1782606b5c3e..1a562e8e58426573c79a1f1af4e7357b4dca52b5 100644 (file)
@@ -1,10 +1,9 @@
 /*
     comedi/drivers/amplc_dio200.c
-    Driver for Amplicon PC272E and PCI272 DIO boards.
-    (Support for other boards in Amplicon 200 series may be added at
-    a later date, e.g. PCI215.)
 
-    Copyright (C) 2005 MEV Ltd. <http://www.mev.co.uk/>
+    Driver for Amplicon PC212E, PC214E, PC215E, PC218E, PC272E.
+
+    Copyright (C) 2005-2013 MEV Ltd. <http://www.mev.co.uk/>
 
     COMEDI - Linux Control and Measurement Device Interface
     Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org>
 */
 /*
  * Driver: amplc_dio200
- * Description: Amplicon 200 Series Digital I/O
+ * Description: Amplicon 200 Series ISA Digital I/O
  * Author: Ian Abbott <abbotti@mev.co.uk>
  * Devices: [Amplicon] PC212E (pc212e), PC214E (pc214e), PC215E (pc215e),
- *   PCI215 (pci215), PCIe215 (pcie215), PC218E (pc218e), PCIe236 (pcie236),
- *   PC272E (pc272e), PCI272 (pci272), PCIe296 (pcie296)
- * Updated: Wed, 24 Oct 2012 16:22:34 +0100
+ *   PC218E (pc218e), PC272E (pc272e)
+ * Updated: Mon, 18 Mar 2013 14:40:41 +0000
+ *
  * Status: works
  *
- * Configuration options - PC212E, PC214E, PC215E, PC218E, PC272E:
+ * Configuration options:
  *   [0] - I/O port base address
  *   [1] - IRQ (optional, but commands won't work without it)
  *
- * Manual configuration of PCI(e) cards is not supported; they are configured
- * automatically.
- *
  * Passing a zero for an option is the same as leaving it unspecified.
  *
  * SUBDEVICES
  *
- *                     PC212E         PC214E      PC215E/PCI215
+ *                     PC212E         PC214E         PC215E
  *                  -------------  -------------  -------------
  *   Subdevices           6              4              5
  *    0                 PPI-X          PPI-X          PPI-X
  *    4                 CTR-Z2                      INTERRUPT
  *    5               INTERRUPT
  *
- *                     PCIe215        PC218E         PCIe236
- *                  -------------  -------------  -------------
- *   Subdevices           8              7              8
- *    0                 PPI-X          CTR-X1         PPI-X
- *    1                 UNUSED         CTR-X2         UNUSED
- *    2                 PPI-Y          CTR-Y1         UNUSED
- *    3                 UNUSED         CTR-Y2         UNUSED
- *    4                 CTR-Z1         CTR-Z1         CTR-Z1
- *    5                 CTR-Z2         CTR-Z2         CTR-Z2
- *    6                 TIMER        INTERRUPT        TIMER
- *    7               INTERRUPT                     INTERRUPT
- *
- *                  PC272E/PCI272     PCIe296
+ *                     PC218E         PC272E
  *                  -------------  -------------
- *   Subdevices           4              8
- *    0                 PPI-X          PPI-X1
- *    1                 PPI-Y          PPI-X2
- *    2                 PPI-Z          PPI-Y1
- *    3               INTERRUPT        PPI-Y2
- *    4                                CTR-Z1
- *    5                                CTR-Z2
- *    6                                TIMER
- *    7                              INTERRUPT
+ *   Subdevices           7              4
+ *    0                 CTR-X1         PPI-X
+ *    1                 CTR-X2         PPI-Y
+ *    2                 CTR-Y1         PPI-Z
+ *    3                 CTR-Y2       INTERRUPT
+ *    4                 CTR-Z1
+ *    5                 CTR-Z2
+ *    6               INTERRUPT
  *
  * Each PPI is a 8255 chip providing 24 DIO channels.  The DIO channels
  * are configurable as inputs or outputs in four groups:
  *         the SK1 connector.  This pin is shared by all three counter
  *         channels on the chip.
  *
- *     For the PCIe boards, clock sources in the range 0 to 31 are allowed
- *     and the following additional clock sources are defined:
- *
- *       8.  HIGH logic level.
- *       9.  LOW logic level.
- *      10.  "Pattern present" signal.
- *      11.  Internal 20 MHz clock.
- *
  *   INSN_CONFIG_GET_CLOCK_SRC.  Returns the counter channel's current
  *     clock source in data[1].  For internal clock sources, data[2] is set
  *     to the period in ns.
  *       6.  Reserved.
  *       7.  Reserved.
  *
- *     For the PCIe boards, gate sources in the range 0 to 31 are allowed;
- *     the following additional clock sources and clock sources 6 and 7 are
- *     (re)defined:
- *
- *       6.  /GAT n, negated version of the counter channel's dedicated
- *         GAT input (negated version of gate source 2).
- *       7.  OUT n-2, the non-inverted output of counter channel n-2
- *         (negated version of gate source 3).
- *       8.  "Pattern present" signal, HIGH while pattern present.
- *       9.  "Pattern occurred" latched signal, latches HIGH when pattern
- *         occurs.
- *      10.  "Pattern gone away" latched signal, latches LOW when pattern
- *         goes away after it occurred.
- *      11.  Negated "pattern present" signal, LOW while pattern present
- *         (negated version of gate source 8).
- *      12.  Negated "pattern occurred" latched signal, latches LOW when
- *         pattern occurs (negated version of gate source 9).
- *      13.  Negated "pattern gone away" latched signal, latches LOW when
- *         pattern goes away after it occurred (negated version of gate
- *         source 10).
- *
  *   INSN_CONFIG_GET_GATE_SRC.  Returns the counter channel's current gate
  *     source in data[2].
  *
  *   3.  The counter subdevices are connected in a ring, so the highest
  *   counter subdevice precedes the lowest.
  *
- * The 'TIMER' subdevice is a free-running 32-bit timer subdevice.
- *
  * The 'INTERRUPT' subdevice pretends to be a digital input subdevice.  The
  * digital inputs come from the interrupt status register.  The number of
  * channels matches the number of interrupt sources.  The PC214E does not
  *
  * INTERRUPT SOURCES
  *
- *                     PC212E         PC214E      PC215E/PCI215
+ *                     PC212E         PC214E         PC215E
  *                  -------------  -------------  -------------
  *   Sources              6              1              6
  *    0               PPI-X-C0       JUMPER-J5      PPI-X-C0
  *    4              CTR-Z1-OUT1                   CTR-Z1-OUT1
  *    5              CTR-Z2-OUT1                   CTR-Z2-OUT1
  *
- *                     PCIe215        PC218E         PCIe236
- *                  -------------  -------------  -------------
- *   Sources              6              6              6
- *    0               PPI-X-C0      CTR-X1-OUT1     PPI-X-C0
- *    1               PPI-X-C3      CTR-X2-OUT1     PPI-X-C3
- *    2               PPI-Y-C0      CTR-Y1-OUT1      unused
- *    3               PPI-Y-C3      CTR-Y2-OUT1      unused
- *    4              CTR-Z1-OUT1    CTR-Z1-OUT1    CTR-Z1-OUT1
- *    5              CTR-Z2-OUT1    CTR-Z2-OUT1    CTR-Z2-OUT1
- *
- *                  PC272E/PCI272     PCIe296
+ *                     PC218E         PC272E
  *                  -------------  -------------
  *   Sources              6              6
- *    0               PPI-X-C0       PPI-X1-C0
- *    1               PPI-X-C3       PPI-X1-C3
- *    2               PPI-Y-C0       PPI-Y1-C0
- *    3               PPI-Y-C3       PPI-Y1-C3
- *    4               PPI-Z-C0      CTR-Z1-OUT1
- *    5               PPI-Z-C3      CTR-Z2-OUT1
+ *    0              CTR-X1-OUT1     PPI-X-C0
+ *    1              CTR-X2-OUT1     PPI-X-C3
+ *    2              CTR-Y1-OUT1     PPI-Y-C0
+ *    3              CTR-Y2-OUT1     PPI-Y-C3
+ *    4              CTR-Z1-OUT1     PPI-Z-C0
+ *    5              CTR-Z2-OUT1     PPI-Z-C3
  *
  * When an interrupt source is enabled in the interrupt source enable
  * register, a rising edge on the source signal latches the corresponding
  *
  * When the interrupt status register value as a whole (actually, just the
  * 6 least significant bits) goes from zero to non-zero, the board will
- * generate an interrupt.  For level-triggered hardware interrupts (PCI
- * card), the interrupt will remain asserted until the interrupt status
- * register is cleared to zero.  For edge-triggered hardware interrupts
- * (ISA card), no further interrupts will occur until the interrupt status
- * register is cleared to zero.  To clear a bit to zero in the interrupt
- * status register, the corresponding interrupt source must be disabled
- * in the interrupt source enable register (there is no separate interrupt
- * clear register).
+ * generate an interrupt.  No further interrupts will occur until the
+ * interrupt status register is cleared to zero.  To clear a bit to zero in
+ * the interrupt status register, the corresponding interrupt source must
+ * be disabled in the interrupt source enable register (there is no
+ * separate interrupt clear register).
  *
  * The PC214E does not have an interrupt source enable register or an
  * interrupt status register; its 'INTERRUPT' subdevice has a single
  * order they appear in the channel list.
  */
 
-#include <linux/pci.h>
-#include <linux/interrupt.h>
 #include <linux/slab.h>
 
 #include "../comedidev.h"
 
-#include "comedi_fc.h"
-#include "8253.h"
-
-#define DIO200_DRIVER_NAME     "amplc_dio200"
-
-#define DO_ISA IS_ENABLED(CONFIG_COMEDI_AMPLC_DIO200_ISA)
-#define DO_PCI IS_ENABLED(CONFIG_COMEDI_AMPLC_DIO200_PCI)
-
-/* PCI IDs */
-#define PCI_DEVICE_ID_AMPLICON_PCI272 0x000a
-#define PCI_DEVICE_ID_AMPLICON_PCI215 0x000b
-#define PCI_DEVICE_ID_AMPLICON_PCIE236 0x0011
-#define PCI_DEVICE_ID_AMPLICON_PCIE215 0x0012
-#define PCI_DEVICE_ID_AMPLICON_PCIE296 0x0014
-
-/* 8255 control register bits */
-#define CR_C_LO_IO     0x01
-#define CR_B_IO                0x02
-#define CR_B_MODE      0x04
-#define CR_C_HI_IO     0x08
-#define CR_A_IO                0x10
-#define CR_A_MODE(a)   ((a)<<5)
-#define CR_CW          0x80
-
-/* 200 series registers */
-#define DIO200_IO_SIZE         0x20
-#define DIO200_PCIE_IO_SIZE    0x4000
-#define DIO200_XCLK_SCE                0x18    /* Group X clock selection register */
-#define DIO200_YCLK_SCE                0x19    /* Group Y clock selection register */
-#define DIO200_ZCLK_SCE                0x1a    /* Group Z clock selection register */
-#define DIO200_XGAT_SCE                0x1b    /* Group X gate selection register */
-#define DIO200_YGAT_SCE                0x1c    /* Group Y gate selection register */
-#define DIO200_ZGAT_SCE                0x1d    /* Group Z gate selection register */
-#define DIO200_INT_SCE         0x1e    /* Interrupt enable/status register */
-/* Extra registers for new PCIe boards */
-#define DIO200_ENHANCE         0x20    /* 1 to enable enhanced features */
-#define DIO200_VERSION         0x24    /* Hardware version register */
-#define DIO200_TS_CONFIG       0x600   /* Timestamp timer config register */
-#define DIO200_TS_COUNT                0x602   /* Timestamp timer count register */
-
-/*
- * Functions for constructing value for DIO_200_?CLK_SCE and
- * DIO_200_?GAT_SCE registers:
- *
- * 'which' is: 0 for CTR-X1, CTR-Y1, CTR-Z1; 1 for CTR-X2, CTR-Y2 or CTR-Z2.
- * 'chan' is the channel: 0, 1 or 2.
- * 'source' is the signal source: 0 to 7, or 0 to 31 for "enhanced" boards.
- */
-static unsigned char clk_gat_sce(unsigned int which, unsigned int chan,
-                                unsigned int source)
-{
-       return (which << 5) | (chan << 3) |
-              ((source & 030) << 3) | (source & 007);
-}
-
-static unsigned char clk_sce(unsigned int which, unsigned int chan,
-                            unsigned int source)
-{
-       return clk_gat_sce(which, chan, source);
-}
-
-static unsigned char gat_sce(unsigned int which, unsigned int chan,
-                            unsigned int source)
-{
-       return clk_gat_sce(which, chan, source);
-}
-
-/*
- * Periods of the internal clock sources in nanoseconds.
- */
-static const unsigned int clock_period[32] = {
-       [1] = 100,              /* 10 MHz */
-       [2] = 1000,             /* 1 MHz */
-       [3] = 10000,            /* 100 kHz */
-       [4] = 100000,           /* 10 kHz */
-       [5] = 1000000,          /* 1 kHz */
-       [11] = 50,              /* 20 MHz (enhanced boards) */
-       /* clock sources 12 and later reserved for enhanced boards */
-};
-
-/*
- * Timestamp timer configuration register (for new PCIe boards).
- */
-#define TS_CONFIG_RESET                0x100   /* Reset counter to zero. */
-#define TS_CONFIG_CLK_SRC_MASK 0x0FF   /* Clock source. */
-#define TS_CONFIG_MAX_CLK_SRC  2       /* Maximum clock source value. */
-
-/*
- * Periods of the timestamp timer clock sources in nanoseconds.
- */
-static const unsigned int ts_clock_period[TS_CONFIG_MAX_CLK_SRC + 1] = {
-       1,                      /* 1 nanosecond (but with 20 ns granularity). */
-       1000,                   /* 1 microsecond. */
-       1000000,                /* 1 millisecond. */
-};
-
-/*
- * Register region.
- */
-enum dio200_regtype { no_regtype = 0, io_regtype, mmio_regtype };
-struct dio200_region {
-       union {
-               unsigned long iobase;           /* I/O base address */
-               unsigned char __iomem *membase; /* mapped MMIO base address */
-       } u;
-       enum dio200_regtype regtype;
-};
+#include "amplc_dio200.h"
 
 /*
  * Board descriptions.
  */
-
-enum dio200_bustype { isa_bustype, pci_bustype };
-
-enum dio200_model {
-       pc212e_model,
-       pc214e_model,
-       pc215e_model, pci215_model, pcie215_model,
-       pc218e_model,
-       pcie236_model,
-       pc272e_model, pci272_model,
-       pcie296_model,
-};
-
-enum dio200_layout_idx {
-#if DO_ISA
-       pc212_layout,
-       pc214_layout,
-#endif
-       pc215_layout,
-#if DO_ISA
-       pc218_layout,
-#endif
-       pc272_layout,
-#if DO_PCI
-       pcie215_layout,
-       pcie236_layout,
-       pcie296_layout,
-#endif
-};
-
-struct dio200_board {
-       const char *name;
-       unsigned short devid;
-       enum dio200_bustype bustype;
-       enum dio200_model model;
-       enum dio200_layout_idx layout;
-       unsigned char mainbar;
-       unsigned char mainshift;
-       unsigned int mainsize;
-};
-
-static const struct dio200_board dio200_boards[] = {
-#if DO_ISA
-       {
-        .name = "pc212e",
-        .bustype = isa_bustype,
-        .model = pc212e_model,
-        .layout = pc212_layout,
-        .mainsize = DIO200_IO_SIZE,
-        },
-       {
-        .name = "pc214e",
-        .bustype = isa_bustype,
-        .model = pc214e_model,
-        .layout = pc214_layout,
-        .mainsize = DIO200_IO_SIZE,
-        },
-       {
-        .name = "pc215e",
-        .bustype = isa_bustype,
-        .model = pc215e_model,
-        .layout = pc215_layout,
-        .mainsize = DIO200_IO_SIZE,
-        },
-       {
-        .name = "pc218e",
-        .bustype = isa_bustype,
-        .model = pc218e_model,
-        .layout = pc218_layout,
-        .mainsize = DIO200_IO_SIZE,
-        },
+static const struct dio200_board dio200_isa_boards[] = {
        {
-        .name = "pc272e",
-        .bustype = isa_bustype,
-        .model = pc272e_model,
-        .layout = pc272_layout,
-        .mainsize = DIO200_IO_SIZE,
-        },
-#endif
-#if DO_PCI
+               .name = "pc212e",
+               .bustype = isa_bustype,
+               .mainsize = DIO200_IO_SIZE,
+               .layout = {
+                       .n_subdevs = 6,
+                       .sdtype = {sd_8255, sd_8254, sd_8254, sd_8254, sd_8254,
+                                  sd_intr},
+                       .sdinfo = {0x00, 0x08, 0x0C, 0x10, 0x14, 0x3F},
+                       .has_int_sce = true,
+                       .has_clk_gat_sce = true,
+               },
+       },
        {
-        .name = "pci215",
-        .devid = PCI_DEVICE_ID_AMPLICON_PCI215,
-        .bustype = pci_bustype,
-        .model = pci215_model,
-        .layout = pc215_layout,
-        .mainbar = 2,
-        .mainsize = DIO200_IO_SIZE,
-        },
+               .name = "pc214e",
+               .bustype = isa_bustype,
+               .mainsize = DIO200_IO_SIZE,
+               .layout = {
+                       .n_subdevs = 4,
+                       .sdtype = {sd_8255, sd_8255, sd_8254, sd_intr},
+                       .sdinfo = {0x00, 0x08, 0x10, 0x01},
+               },
+       },
        {
-        .name = "pci272",
-        .devid = PCI_DEVICE_ID_AMPLICON_PCI272,
-        .bustype = pci_bustype,
-        .model = pci272_model,
-        .layout = pc272_layout,
-        .mainbar = 2,
-        .mainsize = DIO200_IO_SIZE,
-        },
+               .name = "pc215e",
+               .bustype = isa_bustype,
+               .mainsize = DIO200_IO_SIZE,
+               .layout = {
+                       .n_subdevs = 5,
+                       .sdtype = {sd_8255, sd_8255, sd_8254, sd_8254, sd_intr},
+                       .sdinfo = {0x00, 0x08, 0x10, 0x14, 0x3F},
+                       .has_int_sce = true,
+                       .has_clk_gat_sce = true,
+               },
+       },
        {
-        .name = "pcie215",
-        .devid = PCI_DEVICE_ID_AMPLICON_PCIE215,
-        .bustype = pci_bustype,
-        .model = pcie215_model,
-        .layout = pcie215_layout,
-        .mainbar = 1,
-        .mainshift = 3,
-        .mainsize = DIO200_PCIE_IO_SIZE,
-        },
+               .name = "pc218e",
+               .bustype = isa_bustype,
+               .mainsize = DIO200_IO_SIZE,
+               .layout = {
+                       .n_subdevs = 7,
+                       .sdtype = {sd_8254, sd_8254, sd_8255, sd_8254, sd_8254,
+                                  sd_intr},
+                       .sdinfo = {0x00, 0x04, 0x08, 0x0C, 0x10, 0x14, 0x3F},
+                       .has_int_sce = true,
+                       .has_clk_gat_sce = true,
+               },
+       },
        {
-        .name = "pcie236",
-        .devid = PCI_DEVICE_ID_AMPLICON_PCIE236,
-        .bustype = pci_bustype,
-        .model = pcie236_model,
-        .layout = pcie236_layout,
-        .mainbar = 1,
-        .mainshift = 3,
-        .mainsize = DIO200_PCIE_IO_SIZE,
-        },
-       {
-        .name = "pcie296",
-        .devid = PCI_DEVICE_ID_AMPLICON_PCIE296,
-        .bustype = pci_bustype,
-        .model = pcie296_model,
-        .layout = pcie296_layout,
-        .mainbar = 1,
-        .mainshift = 3,
-        .mainsize = DIO200_PCIE_IO_SIZE,
-        },
-#endif
-};
-
-/*
- * Layout descriptions - some ISA and PCI board descriptions share the same
- * layout.
- */
-
-enum dio200_sdtype { sd_none, sd_intr, sd_8255, sd_8254, sd_timer };
-
-#define DIO200_MAX_SUBDEVS     8
-#define DIO200_MAX_ISNS                6
-
-struct dio200_layout {
-       unsigned short n_subdevs;       /* number of subdevices */
-       unsigned char sdtype[DIO200_MAX_SUBDEVS];       /* enum dio200_sdtype */
-       unsigned char sdinfo[DIO200_MAX_SUBDEVS];       /* depends on sdtype */
-       char has_int_sce;       /* has interrupt enable/status register */
-       char has_clk_gat_sce;   /* has clock/gate selection registers */
-       char has_enhancements;  /* has enhanced features */
-};
-
-static const struct dio200_layout dio200_layouts[] = {
-#if DO_ISA
-       [pc212_layout] = {
-                         .n_subdevs = 6,
-                         .sdtype = {sd_8255, sd_8254, sd_8254, sd_8254,
-                                    sd_8254,
-                                    sd_intr},
-                         .sdinfo = {0x00, 0x08, 0x0C, 0x10, 0x14,
-                                    0x3F},
-                         .has_int_sce = 1,
-                         .has_clk_gat_sce = 1,
-                         },
-       [pc214_layout] = {
-                         .n_subdevs = 4,
-                         .sdtype = {sd_8255, sd_8255, sd_8254,
-                                    sd_intr},
-                         .sdinfo = {0x00, 0x08, 0x10, 0x01},
-                         .has_int_sce = 0,
-                         .has_clk_gat_sce = 0,
-                         },
-#endif
-       [pc215_layout] = {
-                         .n_subdevs = 5,
-                         .sdtype = {sd_8255, sd_8255, sd_8254,
-                                    sd_8254,
-                                    sd_intr},
-                         .sdinfo = {0x00, 0x08, 0x10, 0x14, 0x3F},
-                         .has_int_sce = 1,
-                         .has_clk_gat_sce = 1,
-                         },
-#if DO_ISA
-       [pc218_layout] = {
-                         .n_subdevs = 7,
-                         .sdtype = {sd_8254, sd_8254, sd_8255, sd_8254,
-                                    sd_8254,
-                                    sd_intr},
-                         .sdinfo = {0x00, 0x04, 0x08, 0x0C, 0x10,
-                                    0x14,
-                                    0x3F},
-                         .has_int_sce = 1,
-                         .has_clk_gat_sce = 1,
-                         },
-#endif
-       [pc272_layout] = {
-                         .n_subdevs = 4,
-                         .sdtype = {sd_8255, sd_8255, sd_8255,
-                                    sd_intr},
-                         .sdinfo = {0x00, 0x08, 0x10, 0x3F},
-                         .has_int_sce = 1,
-                         .has_clk_gat_sce = 0,
-                         },
-#if DO_PCI
-       [pcie215_layout] = {
-                         .n_subdevs = 8,
-                         .sdtype = {sd_8255, sd_none, sd_8255, sd_none,
-                                    sd_8254, sd_8254, sd_timer, sd_intr},
-                         .sdinfo = {0x00, 0x00, 0x08, 0x00,
-                                    0x10, 0x14, 0x00, 0x3F},
-                         .has_int_sce = 1,
-                         .has_clk_gat_sce = 1,
-                         .has_enhancements = 1,
-                         },
-       [pcie236_layout] = {
-                         .n_subdevs = 8,
-                         .sdtype = {sd_8255, sd_none, sd_none, sd_none,
-                                    sd_8254, sd_8254, sd_timer, sd_intr},
-                         .sdinfo = {0x00, 0x00, 0x00, 0x00,
-                                    0x10, 0x14, 0x00, 0x3F},
-                         .has_int_sce = 1,
-                         .has_clk_gat_sce = 1,
-                         .has_enhancements = 1,
-                         },
-       [pcie296_layout] = {
-                         .n_subdevs = 8,
-                         .sdtype = {sd_8255, sd_8255, sd_8255, sd_8255,
-                                    sd_8254, sd_8254, sd_timer, sd_intr},
-                         .sdinfo = {0x00, 0x04, 0x08, 0x0C,
-                                    0x10, 0x14, 0x00, 0x3F},
-                         .has_int_sce = 1,
-                         .has_clk_gat_sce = 1,
-                         .has_enhancements = 1,
-                         },
-#endif
-};
-
-/* this structure is for data unique to this hardware driver.  If
-   several hardware drivers keep similar information in this structure,
-   feel free to suggest moving the variable to the struct comedi_device struct.
- */
-struct dio200_private {
-       struct dio200_region io;        /* Register region */
-       int intr_sd;
-};
-
-struct dio200_subdev_8254 {
-       unsigned int ofs;               /* Counter base offset */
-       unsigned int clk_sce_ofs;       /* CLK_SCE base address */
-       unsigned int gat_sce_ofs;       /* GAT_SCE base address */
-       int which;                      /* Bit 5 of CLK_SCE or GAT_SCE */
-       unsigned int clock_src[3];      /* Current clock sources */
-       unsigned int gate_src[3];       /* Current gate sources */
-       spinlock_t spinlock;
+               .name = "pc272e",
+               .bustype = isa_bustype,
+               .mainsize = DIO200_IO_SIZE,
+               .layout = {
+                       .n_subdevs = 4,
+                       .sdtype = {sd_8255, sd_8255, sd_8255, sd_intr},
+                       .sdinfo = {0x00, 0x08, 0x10, 0x3F},
+                       .has_int_sce = true,
+               },
+       },
 };
 
-struct dio200_subdev_8255 {
-       unsigned int ofs;               /* DIO base offset */
-};
-
-struct dio200_subdev_intr {
-       unsigned int ofs;
-       spinlock_t spinlock;
-       int active;
-       unsigned int valid_isns;
-       unsigned int enabled_isns;
-       unsigned int stopcount;
-       int continuous;
-};
-
-static inline const struct dio200_layout *
-dio200_board_layout(const struct dio200_board *board)
-{
-       return &dio200_layouts[board->layout];
-}
-
-static inline const struct dio200_layout *
-dio200_dev_layout(struct comedi_device *dev)
-{
-       return dio200_board_layout(comedi_board(dev));
-}
-
-static inline bool is_pci_board(const struct dio200_board *board)
-{
-       return DO_PCI && board->bustype == pci_bustype;
-}
-
-static inline bool is_isa_board(const struct dio200_board *board)
-{
-       return DO_ISA && board->bustype == isa_bustype;
-}
-
-/*
- * Read 8-bit register.
- */
-static unsigned char dio200_read8(struct comedi_device *dev,
-                                 unsigned int offset)
-{
-       const struct dio200_board *thisboard = comedi_board(dev);
-       struct dio200_private *devpriv = dev->private;
-
-       offset <<= thisboard->mainshift;
-       if (devpriv->io.regtype == io_regtype)
-               return inb(devpriv->io.u.iobase + offset);
-       else
-               return readb(devpriv->io.u.membase + offset);
-}
-
-/*
- * Write 8-bit register.
- */
-static void dio200_write8(struct comedi_device *dev, unsigned int offset,
-                         unsigned char val)
-{
-       const struct dio200_board *thisboard = comedi_board(dev);
-       struct dio200_private *devpriv = dev->private;
-
-       offset <<= thisboard->mainshift;
-       if (devpriv->io.regtype == io_regtype)
-               outb(val, devpriv->io.u.iobase + offset);
-       else
-               writeb(val, devpriv->io.u.membase + offset);
-}
-
-/*
- * Read 32-bit register.
- */
-static unsigned int dio200_read32(struct comedi_device *dev,
-                                 unsigned int offset)
-{
-       const struct dio200_board *thisboard = comedi_board(dev);
-       struct dio200_private *devpriv = dev->private;
-
-       offset <<= thisboard->mainshift;
-       if (devpriv->io.regtype == io_regtype)
-               return inl(devpriv->io.u.iobase + offset);
-       else
-               return readl(devpriv->io.u.membase + offset);
-}
-
-/*
- * Write 32-bit register.
- */
-static void dio200_write32(struct comedi_device *dev, unsigned int offset,
-                          unsigned int val)
-{
-       const struct dio200_board *thisboard = comedi_board(dev);
-       struct dio200_private *devpriv = dev->private;
-
-       offset <<= thisboard->mainshift;
-       if (devpriv->io.regtype == io_regtype)
-               outl(val, devpriv->io.u.iobase + offset);
-       else
-               writel(val, devpriv->io.u.membase + offset);
-}
-
-/*
- * This function looks for a board matching the supplied PCI device.
- */
-static const struct dio200_board *
-dio200_find_pci_board(struct pci_dev *pci_dev)
-{
-       unsigned int i;
-
-       for (i = 0; i < ARRAY_SIZE(dio200_boards); i++)
-               if (is_pci_board(&dio200_boards[i]) &&
-                   pci_dev->device == dio200_boards[i].devid)
-                       return &dio200_boards[i];
-       return NULL;
-}
-
 /*
  * This function checks and requests an I/O region, reporting an error
  * if there is a conflict.
@@ -752,7 +276,7 @@ static int
 dio200_request_region(struct comedi_device *dev,
                      unsigned long from, unsigned long extent)
 {
-       if (!from || !request_region(from, extent, DIO200_DRIVER_NAME)) {
+       if (!from || !request_region(from, extent, dev->board_name)) {
                dev_err(dev->class_dev, "I/O port conflict (%#lx,%lu)!\n",
                        from, extent);
                return -EIO;
@@ -760,1333 +284,56 @@ dio200_request_region(struct comedi_device *dev,
        return 0;
 }
 
-/*
- * 'insn_bits' function for an 'INTERRUPT' subdevice.
- */
-static int
-dio200_subdev_intr_insn_bits(struct comedi_device *dev,
-                            struct comedi_subdevice *s,
-                            struct comedi_insn *insn, unsigned int *data)
-{
-       const struct dio200_layout *layout = dio200_dev_layout(dev);
-       struct dio200_subdev_intr *subpriv = s->private;
-
-       if (layout->has_int_sce) {
-               /* Just read the interrupt status register.  */
-               data[1] = dio200_read8(dev, subpriv->ofs) & subpriv->valid_isns;
-       } else {
-               /* No interrupt status register. */
-               data[0] = 0;
-       }
-
-       return insn->n;
-}
-
-/*
- * Called to stop acquisition for an 'INTERRUPT' subdevice.
- */
-static void dio200_stop_intr(struct comedi_device *dev,
-                            struct comedi_subdevice *s)
-{
-       const struct dio200_layout *layout = dio200_dev_layout(dev);
-       struct dio200_subdev_intr *subpriv = s->private;
-
-       subpriv->active = 0;
-       subpriv->enabled_isns = 0;
-       if (layout->has_int_sce)
-               dio200_write8(dev, subpriv->ofs, 0);
-}
-
-/*
- * Called to start acquisition for an 'INTERRUPT' subdevice.
- */
-static int dio200_start_intr(struct comedi_device *dev,
-                            struct comedi_subdevice *s)
-{
-       unsigned int n;
-       unsigned isn_bits;
-       const struct dio200_layout *layout = dio200_dev_layout(dev);
-       struct dio200_subdev_intr *subpriv = s->private;
-       struct comedi_cmd *cmd = &s->async->cmd;
-       int retval = 0;
-
-       if (!subpriv->continuous && subpriv->stopcount == 0) {
-               /* An empty acquisition! */
-               s->async->events |= COMEDI_CB_EOA;
-               subpriv->active = 0;
-               retval = 1;
-       } else {
-               /* Determine interrupt sources to enable. */
-               isn_bits = 0;
-               if (cmd->chanlist) {
-                       for (n = 0; n < cmd->chanlist_len; n++)
-                               isn_bits |= (1U << CR_CHAN(cmd->chanlist[n]));
-               }
-               isn_bits &= subpriv->valid_isns;
-               /* Enable interrupt sources. */
-               subpriv->enabled_isns = isn_bits;
-               if (layout->has_int_sce)
-                       dio200_write8(dev, subpriv->ofs, isn_bits);
-       }
-
-       return retval;
-}
-
-/*
- * Internal trigger function to start acquisition for an 'INTERRUPT' subdevice.
- */
-static int
-dio200_inttrig_start_intr(struct comedi_device *dev, struct comedi_subdevice *s,
-                         unsigned int trignum)
-{
-       struct dio200_subdev_intr *subpriv;
-       unsigned long flags;
-       int event = 0;
-
-       if (trignum != 0)
-               return -EINVAL;
-
-       subpriv = s->private;
-
-       spin_lock_irqsave(&subpriv->spinlock, flags);
-       s->async->inttrig = NULL;
-       if (subpriv->active)
-               event = dio200_start_intr(dev, s);
-
-       spin_unlock_irqrestore(&subpriv->spinlock, flags);
-
-       if (event)
-               comedi_event(dev, s);
-
-       return 1;
-}
-
-/*
- * This is called from the interrupt service routine to handle a read
- * scan on an 'INTERRUPT' subdevice.
- */
-static int dio200_handle_read_intr(struct comedi_device *dev,
-                                  struct comedi_subdevice *s)
-{
-       const struct dio200_layout *layout = dio200_dev_layout(dev);
-       struct dio200_subdev_intr *subpriv = s->private;
-       unsigned triggered;
-       unsigned intstat;
-       unsigned cur_enabled;
-       unsigned int oldevents;
-       unsigned long flags;
-
-       triggered = 0;
-
-       spin_lock_irqsave(&subpriv->spinlock, flags);
-       oldevents = s->async->events;
-       if (layout->has_int_sce) {
-               /*
-                * Collect interrupt sources that have triggered and disable
-                * them temporarily.  Loop around until no extra interrupt
-                * sources have triggered, at which point, the valid part of
-                * the interrupt status register will read zero, clearing the
-                * cause of the interrupt.
-                *
-                * Mask off interrupt sources already seen to avoid infinite
-                * loop in case of misconfiguration.
-                */
-               cur_enabled = subpriv->enabled_isns;
-               while ((intstat = (dio200_read8(dev, subpriv->ofs) &
-                                  subpriv->valid_isns & ~triggered)) != 0) {
-                       triggered |= intstat;
-                       cur_enabled &= ~triggered;
-                       dio200_write8(dev, subpriv->ofs, cur_enabled);
-               }
-       } else {
-               /*
-                * No interrupt status register.  Assume the single interrupt
-                * source has triggered.
-                */
-               triggered = subpriv->enabled_isns;
-       }
-
-       if (triggered) {
-               /*
-                * Some interrupt sources have triggered and have been
-                * temporarily disabled to clear the cause of the interrupt.
-                *
-                * Reenable them NOW to minimize the time they are disabled.
-                */
-               cur_enabled = subpriv->enabled_isns;
-               if (layout->has_int_sce)
-                       dio200_write8(dev, subpriv->ofs, cur_enabled);
-
-               if (subpriv->active) {
-                       /*
-                        * The command is still active.
-                        *
-                        * Ignore interrupt sources that the command isn't
-                        * interested in (just in case there's a race
-                        * condition).
-                        */
-                       if (triggered & subpriv->enabled_isns) {
-                               /* Collect scan data. */
-                               short val;
-                               unsigned int n, ch, len;
-
-                               val = 0;
-                               len = s->async->cmd.chanlist_len;
-                               for (n = 0; n < len; n++) {
-                                       ch = CR_CHAN(s->async->cmd.chanlist[n]);
-                                       if (triggered & (1U << ch))
-                                               val |= (1U << n);
-                               }
-                               /* Write the scan to the buffer. */
-                               if (comedi_buf_put(s->async, val)) {
-                                       s->async->events |= (COMEDI_CB_BLOCK |
-                                                            COMEDI_CB_EOS);
-                               } else {
-                                       /* Error!  Stop acquisition.  */
-                                       dio200_stop_intr(dev, s);
-                                       s->async->events |= COMEDI_CB_ERROR
-                                           | COMEDI_CB_OVERFLOW;
-                                       comedi_error(dev, "buffer overflow");
-                               }
-
-                               /* Check for end of acquisition. */
-                               if (!subpriv->continuous) {
-                                       /* stop_src == TRIG_COUNT */
-                                       if (subpriv->stopcount > 0) {
-                                               subpriv->stopcount--;
-                                               if (subpriv->stopcount == 0) {
-                                                       s->async->events |=
-                                                           COMEDI_CB_EOA;
-                                                       dio200_stop_intr(dev,
-                                                                        s);
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-       spin_unlock_irqrestore(&subpriv->spinlock, flags);
-
-       if (oldevents != s->async->events)
-               comedi_event(dev, s);
-
-       return (triggered != 0);
-}
-
-/*
- * 'cancel' function for an 'INTERRUPT' subdevice.
- */
-static int dio200_subdev_intr_cancel(struct comedi_device *dev,
-                                    struct comedi_subdevice *s)
-{
-       struct dio200_subdev_intr *subpriv = s->private;
-       unsigned long flags;
-
-       spin_lock_irqsave(&subpriv->spinlock, flags);
-       if (subpriv->active)
-               dio200_stop_intr(dev, s);
-
-       spin_unlock_irqrestore(&subpriv->spinlock, flags);
-
-       return 0;
-}
-
-/*
- * 'do_cmdtest' function for an 'INTERRUPT' subdevice.
- */
-static int
-dio200_subdev_intr_cmdtest(struct comedi_device *dev,
-                          struct comedi_subdevice *s, struct comedi_cmd *cmd)
-{
-       int err = 0;
-
-       /* Step 1 : check if triggers are trivially valid */
-
-       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
-       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
-       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
-       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
-       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
-
-       if (err)
-               return 1;
-
-       /* Step 2a : make sure trigger sources are unique */
-
-       err |= cfc_check_trigger_is_unique(cmd->start_src);
-       err |= cfc_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 |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
-       err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
-       err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
-       err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
-
-       switch (cmd->stop_src) {
-       case TRIG_COUNT:
-               /* any count allowed */
-               break;
-       case TRIG_NONE:
-               err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
-               break;
-       default:
-               break;
-       }
-
-       if (err)
-               return 3;
-
-       /* step 4: fix up any arguments */
-
-       /* if (err) return 4; */
-
-       return 0;
-}
-
-/*
- * 'do_cmd' function for an 'INTERRUPT' subdevice.
- */
-static int dio200_subdev_intr_cmd(struct comedi_device *dev,
-                                 struct comedi_subdevice *s)
-{
-       struct comedi_cmd *cmd = &s->async->cmd;
-       struct dio200_subdev_intr *subpriv = s->private;
-       unsigned long flags;
-       int event = 0;
-
-       spin_lock_irqsave(&subpriv->spinlock, flags);
-       subpriv->active = 1;
-
-       /* Set up end of acquisition. */
-       switch (cmd->stop_src) {
-       case TRIG_COUNT:
-               subpriv->continuous = 0;
-               subpriv->stopcount = cmd->stop_arg;
-               break;
-       default:
-               /* TRIG_NONE */
-               subpriv->continuous = 1;
-               subpriv->stopcount = 0;
-               break;
-       }
-
-       /* Set up start of acquisition. */
-       switch (cmd->start_src) {
-       case TRIG_INT:
-               s->async->inttrig = dio200_inttrig_start_intr;
-               break;
-       default:
-               /* TRIG_NOW */
-               event = dio200_start_intr(dev, s);
-               break;
-       }
-       spin_unlock_irqrestore(&subpriv->spinlock, flags);
-
-       if (event)
-               comedi_event(dev, s);
-
-       return 0;
-}
-
-/*
- * This function initializes an 'INTERRUPT' subdevice.
- */
-static int
-dio200_subdev_intr_init(struct comedi_device *dev, struct comedi_subdevice *s,
-                       unsigned int offset, unsigned valid_isns)
-{
-       const struct dio200_layout *layout = dio200_dev_layout(dev);
-       struct dio200_subdev_intr *subpriv;
-
-       subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
-       if (!subpriv)
-               return -ENOMEM;
-
-       subpriv->ofs = offset;
-       subpriv->valid_isns = valid_isns;
-       spin_lock_init(&subpriv->spinlock);
-
-       if (layout->has_int_sce)
-               /* Disable interrupt sources. */
-               dio200_write8(dev, subpriv->ofs, 0);
-
-       s->private = subpriv;
-       s->type = COMEDI_SUBD_DI;
-       s->subdev_flags = SDF_READABLE | SDF_CMD_READ;
-       if (layout->has_int_sce) {
-               s->n_chan = DIO200_MAX_ISNS;
-               s->len_chanlist = DIO200_MAX_ISNS;
-       } else {
-               /* No interrupt source register.  Support single channel. */
-               s->n_chan = 1;
-               s->len_chanlist = 1;
-       }
-       s->range_table = &range_digital;
-       s->maxdata = 1;
-       s->insn_bits = dio200_subdev_intr_insn_bits;
-       s->do_cmdtest = dio200_subdev_intr_cmdtest;
-       s->do_cmd = dio200_subdev_intr_cmd;
-       s->cancel = dio200_subdev_intr_cancel;
-
-       return 0;
-}
-
-/*
- * This function cleans up an 'INTERRUPT' subdevice.
- */
-static void
-dio200_subdev_intr_cleanup(struct comedi_device *dev,
-                          struct comedi_subdevice *s)
-{
-       struct dio200_subdev_intr *subpriv = s->private;
-       kfree(subpriv);
-}
-
-/*
- * Interrupt service routine.
- */
-static irqreturn_t dio200_interrupt(int irq, void *d)
-{
-       struct comedi_device *dev = d;
-       struct dio200_private *devpriv = dev->private;
-       struct comedi_subdevice *s;
-       int handled;
-
-       if (!dev->attached)
-               return IRQ_NONE;
-
-       if (devpriv->intr_sd >= 0) {
-               s = &dev->subdevices[devpriv->intr_sd];
-               handled = dio200_handle_read_intr(dev, s);
-       } else {
-               handled = 0;
-       }
-
-       return IRQ_RETVAL(handled);
-}
-
-/*
- * Read an '8254' counter subdevice channel.
- */
-static unsigned int
-dio200_subdev_8254_read_chan(struct comedi_device *dev,
-                            struct comedi_subdevice *s, unsigned int chan)
-{
-       struct dio200_subdev_8254 *subpriv = s->private;
-       unsigned int val;
-
-       /* latch counter */
-       val = chan << 6;
-       dio200_write8(dev, subpriv->ofs + i8254_control_reg, val);
-       /* read lsb, msb */
-       val = dio200_read8(dev, subpriv->ofs + chan);
-       val += dio200_read8(dev, subpriv->ofs + chan) << 8;
-       return val;
-}
-
-/*
- * Write an '8254' subdevice channel.
- */
-static void
-dio200_subdev_8254_write_chan(struct comedi_device *dev,
-                             struct comedi_subdevice *s, unsigned int chan,
-                             unsigned int count)
-{
-       struct dio200_subdev_8254 *subpriv = s->private;
-
-       /* write lsb, msb */
-       dio200_write8(dev, subpriv->ofs + chan, count & 0xff);
-       dio200_write8(dev, subpriv->ofs + chan, (count >> 8) & 0xff);
-}
-
-/*
- * Set mode of an '8254' subdevice channel.
- */
-static void
-dio200_subdev_8254_set_mode(struct comedi_device *dev,
-                           struct comedi_subdevice *s, unsigned int chan,
-                           unsigned int mode)
-{
-       struct dio200_subdev_8254 *subpriv = s->private;
-       unsigned int byte;
-
-       byte = chan << 6;
-       byte |= 0x30;           /* access order: lsb, msb */
-       byte |= (mode & 0xf);   /* counter mode and BCD|binary */
-       dio200_write8(dev, subpriv->ofs + i8254_control_reg, byte);
-}
-
-/*
- * Read status byte of an '8254' counter subdevice channel.
- */
-static unsigned int
-dio200_subdev_8254_status(struct comedi_device *dev,
-                         struct comedi_subdevice *s, unsigned int chan)
-{
-       struct dio200_subdev_8254 *subpriv = s->private;
-
-       /* latch status */
-       dio200_write8(dev, subpriv->ofs + i8254_control_reg,
-                     0xe0 | (2 << chan));
-       /* read status */
-       return dio200_read8(dev, subpriv->ofs + chan);
-}
-
-/*
- * Handle 'insn_read' for an '8254' counter subdevice.
- */
-static int
-dio200_subdev_8254_read(struct comedi_device *dev, struct comedi_subdevice *s,
-                       struct comedi_insn *insn, unsigned int *data)
-{
-       struct dio200_subdev_8254 *subpriv = s->private;
-       int chan = CR_CHAN(insn->chanspec);
-       unsigned int n;
-       unsigned long flags;
-
-       for (n = 0; n < insn->n; n++) {
-               spin_lock_irqsave(&subpriv->spinlock, flags);
-               data[n] = dio200_subdev_8254_read_chan(dev, s, chan);
-               spin_unlock_irqrestore(&subpriv->spinlock, flags);
-       }
-       return insn->n;
-}
-
-/*
- * Handle 'insn_write' for an '8254' counter subdevice.
- */
-static int
-dio200_subdev_8254_write(struct comedi_device *dev, struct comedi_subdevice *s,
-                        struct comedi_insn *insn, unsigned int *data)
-{
-       struct dio200_subdev_8254 *subpriv = s->private;
-       int chan = CR_CHAN(insn->chanspec);
-       unsigned int n;
-       unsigned long flags;
-
-       for (n = 0; n < insn->n; n++) {
-               spin_lock_irqsave(&subpriv->spinlock, flags);
-               dio200_subdev_8254_write_chan(dev, s, chan, data[n]);
-               spin_unlock_irqrestore(&subpriv->spinlock, flags);
-       }
-       return insn->n;
-}
-
-/*
- * Set gate source for an '8254' counter subdevice channel.
- */
-static int
-dio200_subdev_8254_set_gate_src(struct comedi_device *dev,
-                               struct comedi_subdevice *s,
-                               unsigned int counter_number,
-                               unsigned int gate_src)
-{
-       const struct dio200_layout *layout = dio200_dev_layout(dev);
-       struct dio200_subdev_8254 *subpriv = s->private;
-       unsigned char byte;
-
-       if (!layout->has_clk_gat_sce)
-               return -1;
-       if (counter_number > 2)
-               return -1;
-       if (gate_src > (layout->has_enhancements ? 31 : 7))
-               return -1;
-
-       subpriv->gate_src[counter_number] = gate_src;
-       byte = gat_sce(subpriv->which, counter_number, gate_src);
-       dio200_write8(dev, subpriv->gat_sce_ofs, byte);
-
-       return 0;
-}
-
-/*
- * Get gate source for an '8254' counter subdevice channel.
- */
-static int
-dio200_subdev_8254_get_gate_src(struct comedi_device *dev,
-                               struct comedi_subdevice *s,
-                               unsigned int counter_number)
-{
-       const struct dio200_layout *layout = dio200_dev_layout(dev);
-       struct dio200_subdev_8254 *subpriv = s->private;
-
-       if (!layout->has_clk_gat_sce)
-               return -1;
-       if (counter_number > 2)
-               return -1;
-
-       return subpriv->gate_src[counter_number];
-}
-
-/*
- * Set clock source for an '8254' counter subdevice channel.
- */
-static int
-dio200_subdev_8254_set_clock_src(struct comedi_device *dev,
-                                struct comedi_subdevice *s,
-                                unsigned int counter_number,
-                                unsigned int clock_src)
-{
-       const struct dio200_layout *layout = dio200_dev_layout(dev);
-       struct dio200_subdev_8254 *subpriv = s->private;
-       unsigned char byte;
-
-       if (!layout->has_clk_gat_sce)
-               return -1;
-       if (counter_number > 2)
-               return -1;
-       if (clock_src > (layout->has_enhancements ? 31 : 7))
-               return -1;
-
-       subpriv->clock_src[counter_number] = clock_src;
-       byte = clk_sce(subpriv->which, counter_number, clock_src);
-       dio200_write8(dev, subpriv->clk_sce_ofs, byte);
-
-       return 0;
-}
-
-/*
- * Get clock source for an '8254' counter subdevice channel.
- */
-static int
-dio200_subdev_8254_get_clock_src(struct comedi_device *dev,
-                                struct comedi_subdevice *s,
-                                unsigned int counter_number,
-                                unsigned int *period_ns)
-{
-       const struct dio200_layout *layout = dio200_dev_layout(dev);
-       struct dio200_subdev_8254 *subpriv = s->private;
-       unsigned clock_src;
-
-       if (!layout->has_clk_gat_sce)
-               return -1;
-       if (counter_number > 2)
-               return -1;
-
-       clock_src = subpriv->clock_src[counter_number];
-       *period_ns = clock_period[clock_src];
-       return clock_src;
-}
-
-/*
- * Handle 'insn_config' for an '8254' counter subdevice.
- */
-static int
-dio200_subdev_8254_config(struct comedi_device *dev, struct comedi_subdevice *s,
-                         struct comedi_insn *insn, unsigned int *data)
-{
-       struct dio200_subdev_8254 *subpriv = s->private;
-       int ret = 0;
-       int chan = CR_CHAN(insn->chanspec);
-       unsigned long flags;
-
-       spin_lock_irqsave(&subpriv->spinlock, flags);
-       switch (data[0]) {
-       case INSN_CONFIG_SET_COUNTER_MODE:
-               if (data[1] > (I8254_MODE5 | I8254_BINARY))
-                       ret = -EINVAL;
-               else
-                       dio200_subdev_8254_set_mode(dev, s, chan, data[1]);
-               break;
-       case INSN_CONFIG_8254_READ_STATUS:
-               data[1] = dio200_subdev_8254_status(dev, s, chan);
-               break;
-       case INSN_CONFIG_SET_GATE_SRC:
-               ret = dio200_subdev_8254_set_gate_src(dev, s, chan, data[2]);
-               if (ret < 0)
-                       ret = -EINVAL;
-               break;
-       case INSN_CONFIG_GET_GATE_SRC:
-               ret = dio200_subdev_8254_get_gate_src(dev, s, chan);
-               if (ret < 0) {
-                       ret = -EINVAL;
-                       break;
-               }
-               data[2] = ret;
-               break;
-       case INSN_CONFIG_SET_CLOCK_SRC:
-               ret = dio200_subdev_8254_set_clock_src(dev, s, chan, data[1]);
-               if (ret < 0)
-                       ret = -EINVAL;
-               break;
-       case INSN_CONFIG_GET_CLOCK_SRC:
-               ret = dio200_subdev_8254_get_clock_src(dev, s, chan, &data[2]);
-               if (ret < 0) {
-                       ret = -EINVAL;
-                       break;
-               }
-               data[1] = ret;
-               break;
-       default:
-               ret = -EINVAL;
-               break;
-       }
-       spin_unlock_irqrestore(&subpriv->spinlock, flags);
-       return ret < 0 ? ret : insn->n;
-}
-
-/*
- * This function initializes an '8254' counter subdevice.
- */
-static int
-dio200_subdev_8254_init(struct comedi_device *dev, struct comedi_subdevice *s,
-                       unsigned int offset)
-{
-       const struct dio200_layout *layout = dio200_dev_layout(dev);
-       struct dio200_subdev_8254 *subpriv;
-       unsigned int chan;
-
-       subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
-       if (!subpriv)
-               return -ENOMEM;
-
-       s->private = subpriv;
-       s->type = COMEDI_SUBD_COUNTER;
-       s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
-       s->n_chan = 3;
-       s->maxdata = 0xFFFF;
-       s->insn_read = dio200_subdev_8254_read;
-       s->insn_write = dio200_subdev_8254_write;
-       s->insn_config = dio200_subdev_8254_config;
-
-       spin_lock_init(&subpriv->spinlock);
-       subpriv->ofs = offset;
-       if (layout->has_clk_gat_sce) {
-               /* Derive CLK_SCE and GAT_SCE register offsets from
-                * 8254 offset. */
-               subpriv->clk_sce_ofs = DIO200_XCLK_SCE + (offset >> 3);
-               subpriv->gat_sce_ofs = DIO200_XGAT_SCE + (offset >> 3);
-               subpriv->which = (offset >> 2) & 1;
-       }
-
-       /* Initialize channels. */
-       for (chan = 0; chan < 3; chan++) {
-               dio200_subdev_8254_set_mode(dev, s, chan,
-                                           I8254_MODE0 | I8254_BINARY);
-               if (layout->has_clk_gat_sce) {
-                       /* Gate source 0 is VCC (logic 1). */
-                       dio200_subdev_8254_set_gate_src(dev, s, chan, 0);
-                       /* Clock source 0 is the dedicated clock input. */
-                       dio200_subdev_8254_set_clock_src(dev, s, chan, 0);
-               }
-       }
-
-       return 0;
-}
-
-/*
- * This function cleans up an '8254' counter subdevice.
- */
-static void
-dio200_subdev_8254_cleanup(struct comedi_device *dev,
-                          struct comedi_subdevice *s)
-{
-       struct dio200_subdev_intr *subpriv = s->private;
-       kfree(subpriv);
-}
-
-/*
- * This function sets I/O directions for an '8255' DIO subdevice.
- */
-static void dio200_subdev_8255_set_dir(struct comedi_device *dev,
-                                      struct comedi_subdevice *s)
-{
-       struct dio200_subdev_8255 *subpriv = s->private;
-       int config;
-
-       config = CR_CW;
-       /* 1 in io_bits indicates output, 1 in config indicates input */
-       if (!(s->io_bits & 0x0000ff))
-               config |= CR_A_IO;
-       if (!(s->io_bits & 0x00ff00))
-               config |= CR_B_IO;
-       if (!(s->io_bits & 0x0f0000))
-               config |= CR_C_LO_IO;
-       if (!(s->io_bits & 0xf00000))
-               config |= CR_C_HI_IO;
-       dio200_write8(dev, subpriv->ofs + 3, config);
-}
-
-/*
- * Handle 'insn_bits' for an '8255' DIO subdevice.
- */
-static int dio200_subdev_8255_bits(struct comedi_device *dev,
-                                  struct comedi_subdevice *s,
-                                  struct comedi_insn *insn, unsigned int *data)
-{
-       struct dio200_subdev_8255 *subpriv = s->private;
-
-       if (data[0]) {
-               s->state &= ~data[0];
-               s->state |= (data[0] & data[1]);
-               if (data[0] & 0xff)
-                       dio200_write8(dev, subpriv->ofs, s->state & 0xff);
-               if (data[0] & 0xff00)
-                       dio200_write8(dev, subpriv->ofs + 1,
-                                     (s->state >> 8) & 0xff);
-               if (data[0] & 0xff0000)
-                       dio200_write8(dev, subpriv->ofs + 2,
-                                     (s->state >> 16) & 0xff);
-       }
-       data[1] = dio200_read8(dev, subpriv->ofs);
-       data[1] |= dio200_read8(dev, subpriv->ofs + 1) << 8;
-       data[1] |= dio200_read8(dev, subpriv->ofs + 2) << 16;
-       return 2;
-}
-
-/*
- * Handle 'insn_config' for an '8255' DIO subdevice.
- */
-static int dio200_subdev_8255_config(struct comedi_device *dev,
-                                    struct comedi_subdevice *s,
-                                    struct comedi_insn *insn,
-                                    unsigned int *data)
-{
-       unsigned int mask;
-       unsigned int bits;
-
-       mask = 1 << CR_CHAN(insn->chanspec);
-       if (mask & 0x0000ff)
-               bits = 0x0000ff;
-       else if (mask & 0x00ff00)
-               bits = 0x00ff00;
-       else if (mask & 0x0f0000)
-               bits = 0x0f0000;
-       else
-               bits = 0xf00000;
-       switch (data[0]) {
-       case INSN_CONFIG_DIO_INPUT:
-               s->io_bits &= ~bits;
-               break;
-       case INSN_CONFIG_DIO_OUTPUT:
-               s->io_bits |= bits;
-               break;
-       case INSN_CONFIG_DIO_QUERY:
-               data[1] = (s->io_bits & bits) ? COMEDI_OUTPUT : COMEDI_INPUT;
-               return insn->n;
-               break;
-       default:
-               return -EINVAL;
-       }
-       dio200_subdev_8255_set_dir(dev, s);
-       return 1;
-}
-
-/*
- * This function initializes an '8255' DIO subdevice.
- *
- * offset is the offset to the 8255 chip.
- */
-static int dio200_subdev_8255_init(struct comedi_device *dev,
-                                  struct comedi_subdevice *s,
-                                  unsigned int offset)
-{
-       struct dio200_subdev_8255 *subpriv;
-
-       subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
-       if (!subpriv)
-               return -ENOMEM;
-       subpriv->ofs = offset;
-       s->private = subpriv;
-       s->type = COMEDI_SUBD_DIO;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-       s->n_chan = 24;
-       s->range_table = &range_digital;
-       s->maxdata = 1;
-       s->insn_bits = dio200_subdev_8255_bits;
-       s->insn_config = dio200_subdev_8255_config;
-       s->state = 0;
-       s->io_bits = 0;
-       dio200_subdev_8255_set_dir(dev, s);
-       return 0;
-}
-
-/*
- * This function cleans up an '8255' DIO subdevice.
- */
-static void dio200_subdev_8255_cleanup(struct comedi_device *dev,
-                                      struct comedi_subdevice *s)
-{
-       struct dio200_subdev_8255 *subpriv = s->private;
-
-       kfree(subpriv);
-}
-
-/*
- * Handle 'insn_read' for a timer subdevice.
- */
-static int dio200_subdev_timer_read(struct comedi_device *dev,
-                                   struct comedi_subdevice *s,
-                                   struct comedi_insn *insn,
-                                   unsigned int *data)
-{
-       unsigned int n;
-
-       for (n = 0; n < insn->n; n++)
-               data[n] = dio200_read32(dev, DIO200_TS_COUNT);
-       return n;
-}
-
-/*
- * Reset timer subdevice.
- */
-static void dio200_subdev_timer_reset(struct comedi_device *dev,
-                                     struct comedi_subdevice *s)
-{
-       unsigned int clock;
-
-       clock = dio200_read32(dev, DIO200_TS_CONFIG) & TS_CONFIG_CLK_SRC_MASK;
-       dio200_write32(dev, DIO200_TS_CONFIG, clock | TS_CONFIG_RESET);
-       dio200_write32(dev, DIO200_TS_CONFIG, clock);
-}
-
-/*
- * Get timer subdevice clock source and period.
- */
-static void dio200_subdev_timer_get_clock_src(struct comedi_device *dev,
-                                             struct comedi_subdevice *s,
-                                             unsigned int *src,
-                                             unsigned int *period)
-{
-       unsigned int clk;
-
-       clk = dio200_read32(dev, DIO200_TS_CONFIG) & TS_CONFIG_CLK_SRC_MASK;
-       *src = clk;
-       *period = (clk < ARRAY_SIZE(ts_clock_period)) ?
-                 ts_clock_period[clk] : 0;
-}
-
-/*
- * Set timer subdevice clock source.
- */
-static int dio200_subdev_timer_set_clock_src(struct comedi_device *dev,
-                                            struct comedi_subdevice *s,
-                                            unsigned int src)
-{
-       if (src > TS_CONFIG_MAX_CLK_SRC)
-               return -EINVAL;
-       dio200_write32(dev, DIO200_TS_CONFIG, src);
-       return 0;
-}
-
-/*
- * Handle 'insn_config' for a timer subdevice.
- */
-static int dio200_subdev_timer_config(struct comedi_device *dev,
-                                     struct comedi_subdevice *s,
-                                     struct comedi_insn *insn,
-                                     unsigned int *data)
-{
-       int ret = 0;
-
-       switch (data[0]) {
-       case INSN_CONFIG_RESET:
-               dio200_subdev_timer_reset(dev, s);
-               break;
-       case INSN_CONFIG_SET_CLOCK_SRC:
-               ret = dio200_subdev_timer_set_clock_src(dev, s, data[1]);
-               if (ret < 0)
-                       ret = -EINVAL;
-               break;
-       case INSN_CONFIG_GET_CLOCK_SRC:
-               dio200_subdev_timer_get_clock_src(dev, s, &data[1], &data[2]);
-               break;
-       default:
-               ret = -EINVAL;
-               break;
-       }
-       return ret < 0 ? ret : insn->n;
-}
-
-/*
- * This function initializes a timer subdevice.
- *
- * Uses the timestamp timer registers.  There is only one timestamp timer.
- */
-static int dio200_subdev_timer_init(struct comedi_device *dev,
-                                   struct comedi_subdevice *s)
-{
-       s->type = COMEDI_SUBD_TIMER;
-       s->subdev_flags = SDF_READABLE | SDF_LSAMPL;
-       s->n_chan = 1;
-       s->maxdata = 0xFFFFFFFF;
-       s->insn_read = dio200_subdev_timer_read;
-       s->insn_config = dio200_subdev_timer_config;
-       return 0;
-}
-
-/*
- * This function cleans up a timer subdevice.
- */
-static void dio200_subdev_timer_cleanup(struct comedi_device *dev,
-                                       struct comedi_subdevice *s)
-{
-       /* Nothing to do. */
-}
-
-/*
- * This function does some special set-up for the PCIe boards
- * PCIe215, PCIe236, PCIe296.
- */
-static int dio200_pcie_board_setup(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       void __iomem *brbase;
-       resource_size_t brlen;
-
-       /*
-        * The board uses Altera Cyclone IV with PCI-Express hard IP.
-        * The FPGA configuration has the PCI-Express Avalon-MM Bridge
-        * Control registers in PCI BAR 0, offset 0, and the length of
-        * these registers is 0x4000.
-        *
-        * We need to write 0x80 to the "Avalon-MM to PCI-Express Interrupt
-        * Enable" register at offset 0x50 to allow generation of PCIe
-        * interrupts when RXmlrq_i is asserted in the SOPC Builder system.
-        */
-       brlen = pci_resource_len(pcidev, 0);
-       if (brlen < 0x4000 ||
-                       !(pci_resource_flags(pcidev, 0) & IORESOURCE_MEM)) {
-               dev_err(dev->class_dev, "error! bad PCI region!\n");
-               return -EINVAL;
-       }
-       brbase = ioremap_nocache(pci_resource_start(pcidev, 0), brlen);
-       if (!brbase) {
-               dev_err(dev->class_dev, "error! failed to map registers!\n");
-               return -ENOMEM;
-       }
-       writel(0x80, brbase + 0x50);
-       iounmap(brbase);
-       /* Enable "enhanced" features of board. */
-       dio200_write8(dev, DIO200_ENHANCE, 1);
-       return 0;
-}
-
-static void dio200_report_attach(struct comedi_device *dev, unsigned int irq)
-{
-       const struct dio200_board *thisboard = comedi_board(dev);
-       struct dio200_private *devpriv = dev->private;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       char tmpbuf[60];
-       int tmplen;
-
-       if (is_isa_board(thisboard))
-               tmplen = scnprintf(tmpbuf, sizeof(tmpbuf),
-                                  "(base %#lx) ", devpriv->io.u.iobase);
-       else if (is_pci_board(thisboard))
-               tmplen = scnprintf(tmpbuf, sizeof(tmpbuf),
-                                  "(pci %s) ", pci_name(pcidev));
-       else
-               tmplen = 0;
-       if (irq)
-               tmplen += scnprintf(&tmpbuf[tmplen], sizeof(tmpbuf) - tmplen,
-                                   "(irq %u%s) ", irq,
-                                   (dev->irq ? "" : " UNAVAILABLE"));
-       else
-               tmplen += scnprintf(&tmpbuf[tmplen], sizeof(tmpbuf) - tmplen,
-                                   "(no irq) ");
-       dev_info(dev->class_dev, "%s %sattached\n", dev->board_name, tmpbuf);
-}
-
-static int dio200_common_attach(struct comedi_device *dev, unsigned int irq,
-                               unsigned long req_irq_flags)
-{
-       const struct dio200_board *thisboard = comedi_board(dev);
-       struct dio200_private *devpriv = dev->private;
-       const struct dio200_layout *layout = dio200_board_layout(thisboard);
-       struct comedi_subdevice *s;
-       int sdx;
-       unsigned int n;
-       int ret;
-
-       devpriv->intr_sd = -1;
-       dev->board_name = thisboard->name;
-
-       ret = comedi_alloc_subdevices(dev, layout->n_subdevs);
-       if (ret)
-               return ret;
-
-       for (n = 0; n < dev->n_subdevices; n++) {
-               s = &dev->subdevices[n];
-               switch (layout->sdtype[n]) {
-               case sd_8254:
-                       /* counter subdevice (8254) */
-                       ret = dio200_subdev_8254_init(dev, s,
-                                                     layout->sdinfo[n]);
-                       if (ret < 0)
-                               return ret;
-                       break;
-               case sd_8255:
-                       /* digital i/o subdevice (8255) */
-                       ret = dio200_subdev_8255_init(dev, s,
-                                                     layout->sdinfo[n]);
-                       if (ret < 0)
-                               return ret;
-                       break;
-               case sd_intr:
-                       /* 'INTERRUPT' subdevice */
-                       if (irq) {
-                               ret = dio200_subdev_intr_init(dev, s,
-                                                             DIO200_INT_SCE,
-                                                             layout->sdinfo[n]
-                                                            );
-                               if (ret < 0)
-                                       return ret;
-                               devpriv->intr_sd = n;
-                       } else {
-                               s->type = COMEDI_SUBD_UNUSED;
-                       }
-                       break;
-               case sd_timer:
-                       /* Only on PCIe boards. */
-                       if (DO_PCI) {
-                               ret = dio200_subdev_timer_init(dev, s);
-                               if (ret < 0)
-                                       return ret;
-                       } else {
-                               s->type = COMEDI_SUBD_UNUSED;
-                       }
-                       break;
-               default:
-                       s->type = COMEDI_SUBD_UNUSED;
-                       break;
-               }
-       }
-       sdx = devpriv->intr_sd;
-       if (sdx >= 0 && sdx < dev->n_subdevices)
-               dev->read_subdev = &dev->subdevices[sdx];
-       if (irq) {
-               if (request_irq(irq, dio200_interrupt, req_irq_flags,
-                               DIO200_DRIVER_NAME, dev) >= 0) {
-                       dev->irq = irq;
-               } else {
-                       dev_warn(dev->class_dev,
-                                "warning! irq %u unavailable!\n", irq);
-               }
-       }
-       dio200_report_attach(dev, irq);
-       return 1;
-}
-
-/*
- * Attach is called by the Comedi core to configure the driver
- * for a particular board.  If you specified a board_name array
- * in the driver structure, dev->board_ptr contains that
- * address.
- */
 static int dio200_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 {
        const struct dio200_board *thisboard = comedi_board(dev);
        struct dio200_private *devpriv;
+       unsigned long iobase;
+       unsigned int irq;
        int ret;
 
-       dev_info(dev->class_dev, DIO200_DRIVER_NAME ": attach\n");
-
-       devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
-       if (!devpriv)
-               return -ENOMEM;
-       dev->private = devpriv;
-
-       /* Process options and reserve resources according to bus type. */
-       if (is_isa_board(thisboard)) {
-               unsigned long iobase;
-               unsigned int irq;
-
-               iobase = it->options[0];
-               irq = it->options[1];
-               ret = dio200_request_region(dev, iobase, thisboard->mainsize);
-               if (ret < 0)
-                       return ret;
-               devpriv->io.u.iobase = iobase;
-               devpriv->io.regtype = io_regtype;
-               return dio200_common_attach(dev, irq, 0);
-       } else if (is_pci_board(thisboard)) {
-               dev_err(dev->class_dev,
-                       "Manual configuration of PCI board '%s' is not supported\n",
-                       thisboard->name);
-               return -EIO;
-       } else {
-               dev_err(dev->class_dev, DIO200_DRIVER_NAME
-                       ": BUG! cannot determine board type!\n");
-               return -EINVAL;
-       }
-}
-
-/*
- * The auto_attach hook is called at PCI probe time via
- * comedi_pci_auto_config().  dev->board_ptr is NULL on entry.
- * There should be a board entry matching the supplied PCI device.
- */
-static int dio200_auto_attach(struct comedi_device *dev,
-                                       unsigned long context_unused)
-{
-       struct pci_dev *pci_dev = comedi_to_pci_dev(dev);
-       const struct dio200_board *thisboard;
-       struct dio200_private *devpriv;
-       resource_size_t base, len;
-       unsigned int bar;
-       int ret;
-
-       if (!DO_PCI)
-               return -EINVAL;
-
-       dev_info(dev->class_dev, DIO200_DRIVER_NAME ": attach pci %s\n",
-                pci_name(pci_dev));
+       dev->board_name = thisboard->name;
+       iobase = it->options[0];
+       irq = it->options[1];
+       dev_info(dev->class_dev, "%s: attach %s 0x%lX,%u\n",
+                dev->driver->driver_name, dev->board_name, iobase, irq);
 
        devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
        if (!devpriv)
                return -ENOMEM;
        dev->private = devpriv;
 
-       dev->board_ptr = dio200_find_pci_board(pci_dev);
-       if (dev->board_ptr == NULL) {
-               dev_err(dev->class_dev, "BUG! cannot determine board type!\n");
-               return -EINVAL;
-       }
-       thisboard = comedi_board(dev);
-       ret = comedi_pci_enable(pci_dev, DIO200_DRIVER_NAME);
-       if (ret < 0) {
-               dev_err(dev->class_dev,
-                       "error! cannot enable PCI device and request regions!\n");
+       ret = dio200_request_region(dev, iobase, thisboard->mainsize);
+       if (ret < 0)
                return ret;
-       }
-       bar = thisboard->mainbar;
-       base = pci_resource_start(pci_dev, bar);
-       len = pci_resource_len(pci_dev, bar);
-       if (len < thisboard->mainsize) {
-               dev_err(dev->class_dev, "error! PCI region size too small!\n");
-               return -EINVAL;
-       }
-       if ((pci_resource_flags(pci_dev, bar) & IORESOURCE_MEM) != 0) {
-               devpriv->io.u.membase = ioremap_nocache(base, len);
-               if (!devpriv->io.u.membase) {
-                       dev_err(dev->class_dev,
-                               "error! cannot remap registers\n");
-                       return -ENOMEM;
-               }
-               devpriv->io.regtype = mmio_regtype;
-       } else {
-               devpriv->io.u.iobase = (unsigned long)base;
-               devpriv->io.regtype = io_regtype;
-       }
-       switch (thisboard->model) {
-       case pcie215_model:
-       case pcie236_model:
-       case pcie296_model:
-               ret = dio200_pcie_board_setup(dev);
-               if (ret < 0)
-                       return ret;
-               break;
-       default:
-               break;
-       }
-       return dio200_common_attach(dev, pci_dev->irq, IRQF_SHARED);
+       devpriv->io.u.iobase = iobase;
+       devpriv->io.regtype = io_regtype;
+       return amplc_dio200_common_attach(dev, irq, 0);
 }
 
 static void dio200_detach(struct comedi_device *dev)
 {
        const struct dio200_board *thisboard = comedi_board(dev);
        struct dio200_private *devpriv = dev->private;
-       const struct dio200_layout *layout;
-       unsigned n;
 
        if (!thisboard || !devpriv)
                return;
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       if (dev->subdevices) {
-               layout = dio200_board_layout(thisboard);
-               for (n = 0; n < dev->n_subdevices; n++) {
-                       struct comedi_subdevice *s = &dev->subdevices[n];
-                       switch (layout->sdtype[n]) {
-                       case sd_8254:
-                               dio200_subdev_8254_cleanup(dev, s);
-                               break;
-                       case sd_8255:
-                               dio200_subdev_8255_cleanup(dev, s);
-                               break;
-                       case sd_intr:
-                               dio200_subdev_intr_cleanup(dev, s);
-                               break;
-                       case sd_timer:
-                               /* Only on PCIe boards. */
-                               if (DO_PCI)
-                                       dio200_subdev_timer_cleanup(dev, s);
-                               break;
-                       default:
-                               break;
-                       }
-               }
-       }
-       if (is_isa_board(thisboard)) {
-               if (devpriv->io.regtype == io_regtype)
-                       release_region(devpriv->io.u.iobase,
-                                      thisboard->mainsize);
-       } else if (is_pci_board(thisboard)) {
-               struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-               if (pcidev) {
-                       if (devpriv->io.regtype != no_regtype) {
-                               if (devpriv->io.regtype == mmio_regtype)
-                                       iounmap(devpriv->io.u.membase);
-                               comedi_pci_disable(pcidev);
-                       }
-               }
-       }
+       amplc_dio200_common_detach(dev);
+       if (devpriv->io.regtype == io_regtype)
+               release_region(devpriv->io.u.iobase, thisboard->mainsize);
 }
 
-/*
- * The struct comedi_driver structure tells the Comedi core module
- * which functions to call to configure/deconfigure (attach/detach)
- * the board, and also about the kernel module that contains
- * the device code.
- */
 static struct comedi_driver amplc_dio200_driver = {
-       .driver_name = DIO200_DRIVER_NAME,
+       .driver_name = "amplc_dio200",
        .module = THIS_MODULE,
        .attach = dio200_attach,
-       .auto_attach = dio200_auto_attach,
        .detach = dio200_detach,
-       .board_name = &dio200_boards[0].name,
+       .board_name = &dio200_isa_boards[0].name,
        .offset = sizeof(struct dio200_board),
-       .num_names = ARRAY_SIZE(dio200_boards),
-};
-
-#if DO_PCI
-static DEFINE_PCI_DEVICE_TABLE(dio200_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI215) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI272) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCIE236) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCIE215) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCIE296) },
-       {0}
-};
-
-MODULE_DEVICE_TABLE(pci, dio200_pci_table);
-
-static int amplc_dio200_pci_probe(struct pci_dev *dev,
-                                                  const struct pci_device_id
-                                                  *ent)
-{
-       return comedi_pci_auto_config(dev, &amplc_dio200_driver);
-}
-
-static struct pci_driver amplc_dio200_pci_driver = {
-       .name = DIO200_DRIVER_NAME,
-       .id_table = dio200_pci_table,
-       .probe = &amplc_dio200_pci_probe,
-       .remove         = comedi_pci_auto_unconfig,
+       .num_names = ARRAY_SIZE(dio200_isa_boards),
 };
-module_comedi_pci_driver(amplc_dio200_driver, amplc_dio200_pci_driver);
-#else
 module_comedi_driver(amplc_dio200_driver);
-#endif
 
 MODULE_AUTHOR("Comedi http://www.comedi.org");
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for Amplicon 200 Series ISA DIO boards");
 MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/amplc_dio200.h b/drivers/staging/comedi/drivers/amplc_dio200.h
new file mode 100644 (file)
index 0000000..cf2e726
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+    comedi/drivers/amplc_dio.h
+
+    Header for amplc_dio200.c, amplc_dio200_common.c and
+    amplc_dio200_pci.c.
+
+    Copyright (C) 2005-2013 MEV Ltd. <http://www.mev.co.uk/>
+
+    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.
+
+    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 AMPLC_DIO200_H_INCLUDED
+#define AMPLC_DIO200_H_INCLUDED
+
+/* 200 series register area sizes */
+#define DIO200_IO_SIZE         0x20
+#define DIO200_PCIE_IO_SIZE    0x4000
+
+/*
+ * Register region.
+ */
+enum dio200_regtype { no_regtype = 0, io_regtype, mmio_regtype };
+struct dio200_region {
+       union {
+               unsigned long iobase;           /* I/O base address */
+               unsigned char __iomem *membase; /* mapped MMIO base address */
+       } u;
+       enum dio200_regtype regtype;
+};
+
+/*
+ * Subdevice types.
+ */
+enum dio200_sdtype { sd_none, sd_intr, sd_8255, sd_8254, sd_timer };
+
+#define DIO200_MAX_SUBDEVS     8
+#define DIO200_MAX_ISNS                6
+
+/*
+ * Board descriptions.
+ */
+
+struct dio200_layout {
+       unsigned short n_subdevs;       /* number of subdevices */
+       unsigned char sdtype[DIO200_MAX_SUBDEVS];       /* enum dio200_sdtype */
+       unsigned char sdinfo[DIO200_MAX_SUBDEVS];       /* depends on sdtype */
+       bool has_int_sce:1;             /* has interrupt enable/status reg */
+       bool has_clk_gat_sce:1;         /* has clock/gate selection registers */
+       bool has_enhancements:1;        /* has enhanced features */
+};
+
+enum dio200_bustype { isa_bustype, pci_bustype };
+
+struct dio200_board {
+       const char *name;
+       struct dio200_layout layout;
+       enum dio200_bustype bustype;
+       unsigned char mainbar;
+       unsigned char mainshift;
+       unsigned int mainsize;
+};
+
+/*
+ * Comedi device private data.
+ */
+struct dio200_private {
+       struct dio200_region io;        /* Register region */
+       int intr_sd;
+};
+
+int amplc_dio200_common_attach(struct comedi_device *dev, unsigned int irq,
+                              unsigned long req_irq_flags);
+
+void amplc_dio200_common_detach(struct comedi_device *dev);
+
+/* Used by initialization of PCIe boards. */
+void amplc_dio200_set_enhance(struct comedi_device *dev, unsigned char val);
+
+#endif
diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c
new file mode 100644 (file)
index 0000000..04a798e
--- /dev/null
@@ -0,0 +1,1320 @@
+/*
+    comedi/drivers/amplc_dio200_common.c
+
+    Common support code for "amplc_dio200" and "amplc_dio200_pci".
+
+    Copyright (C) 2005-2013 MEV Ltd. <http://www.mev.co.uk/>
+
+    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.
+
+    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/interrupt.h>
+#include <linux/slab.h>
+
+#include "../comedidev.h"
+
+#include "amplc_dio200.h"
+#include "comedi_fc.h"
+#include "8253.h"
+
+/* 8255 control register bits */
+#define CR_C_LO_IO     0x01
+#define CR_B_IO                0x02
+#define CR_B_MODE      0x04
+#define CR_C_HI_IO     0x08
+#define CR_A_IO                0x10
+#define CR_A_MODE(a)   ((a)<<5)
+#define CR_CW          0x80
+
+/* 200 series registers */
+#define DIO200_IO_SIZE         0x20
+#define DIO200_PCIE_IO_SIZE    0x4000
+#define DIO200_XCLK_SCE                0x18    /* Group X clock selection register */
+#define DIO200_YCLK_SCE                0x19    /* Group Y clock selection register */
+#define DIO200_ZCLK_SCE                0x1a    /* Group Z clock selection register */
+#define DIO200_XGAT_SCE                0x1b    /* Group X gate selection register */
+#define DIO200_YGAT_SCE                0x1c    /* Group Y gate selection register */
+#define DIO200_ZGAT_SCE                0x1d    /* Group Z gate selection register */
+#define DIO200_INT_SCE         0x1e    /* Interrupt enable/status register */
+/* Extra registers for new PCIe boards */
+#define DIO200_ENHANCE         0x20    /* 1 to enable enhanced features */
+#define DIO200_VERSION         0x24    /* Hardware version register */
+#define DIO200_TS_CONFIG       0x600   /* Timestamp timer config register */
+#define DIO200_TS_COUNT                0x602   /* Timestamp timer count register */
+
+/*
+ * Functions for constructing value for DIO_200_?CLK_SCE and
+ * DIO_200_?GAT_SCE registers:
+ *
+ * 'which' is: 0 for CTR-X1, CTR-Y1, CTR-Z1; 1 for CTR-X2, CTR-Y2 or CTR-Z2.
+ * 'chan' is the channel: 0, 1 or 2.
+ * 'source' is the signal source: 0 to 7, or 0 to 31 for "enhanced" boards.
+ */
+static unsigned char clk_gat_sce(unsigned int which, unsigned int chan,
+                                unsigned int source)
+{
+       return (which << 5) | (chan << 3) |
+              ((source & 030) << 3) | (source & 007);
+}
+
+static unsigned char clk_sce(unsigned int which, unsigned int chan,
+                            unsigned int source)
+{
+       return clk_gat_sce(which, chan, source);
+}
+
+static unsigned char gat_sce(unsigned int which, unsigned int chan,
+                            unsigned int source)
+{
+       return clk_gat_sce(which, chan, source);
+}
+
+/*
+ * Periods of the internal clock sources in nanoseconds.
+ */
+static const unsigned int clock_period[32] = {
+       [1] = 100,              /* 10 MHz */
+       [2] = 1000,             /* 1 MHz */
+       [3] = 10000,            /* 100 kHz */
+       [4] = 100000,           /* 10 kHz */
+       [5] = 1000000,          /* 1 kHz */
+       [11] = 50,              /* 20 MHz (enhanced boards) */
+       /* clock sources 12 and later reserved for enhanced boards */
+};
+
+/*
+ * Timestamp timer configuration register (for new PCIe boards).
+ */
+#define TS_CONFIG_RESET                0x100   /* Reset counter to zero. */
+#define TS_CONFIG_CLK_SRC_MASK 0x0FF   /* Clock source. */
+#define TS_CONFIG_MAX_CLK_SRC  2       /* Maximum clock source value. */
+
+/*
+ * Periods of the timestamp timer clock sources in nanoseconds.
+ */
+static const unsigned int ts_clock_period[TS_CONFIG_MAX_CLK_SRC + 1] = {
+       1,                      /* 1 nanosecond (but with 20 ns granularity). */
+       1000,                   /* 1 microsecond. */
+       1000000,                /* 1 millisecond. */
+};
+
+struct dio200_subdev_8254 {
+       unsigned int ofs;               /* Counter base offset */
+       unsigned int clk_sce_ofs;       /* CLK_SCE base address */
+       unsigned int gat_sce_ofs;       /* GAT_SCE base address */
+       int which;                      /* Bit 5 of CLK_SCE or GAT_SCE */
+       unsigned int clock_src[3];      /* Current clock sources */
+       unsigned int gate_src[3];       /* Current gate sources */
+       spinlock_t spinlock;
+};
+
+struct dio200_subdev_8255 {
+       unsigned int ofs;               /* DIO base offset */
+};
+
+struct dio200_subdev_intr {
+       spinlock_t spinlock;
+       unsigned int ofs;
+       unsigned int valid_isns;
+       unsigned int enabled_isns;
+       unsigned int stopcount;
+       bool active:1;
+       bool continuous:1;
+};
+
+static inline const struct dio200_layout *
+dio200_board_layout(const struct dio200_board *board)
+{
+       return &board->layout;
+}
+
+static inline const struct dio200_layout *
+dio200_dev_layout(struct comedi_device *dev)
+{
+       return dio200_board_layout(comedi_board(dev));
+}
+
+/*
+ * Read 8-bit register.
+ */
+static unsigned char dio200_read8(struct comedi_device *dev,
+                                 unsigned int offset)
+{
+       const struct dio200_board *thisboard = comedi_board(dev);
+       struct dio200_private *devpriv = dev->private;
+
+       offset <<= thisboard->mainshift;
+       if (devpriv->io.regtype == io_regtype)
+               return inb(devpriv->io.u.iobase + offset);
+       else
+               return readb(devpriv->io.u.membase + offset);
+}
+
+/*
+ * Write 8-bit register.
+ */
+static void dio200_write8(struct comedi_device *dev, unsigned int offset,
+                         unsigned char val)
+{
+       const struct dio200_board *thisboard = comedi_board(dev);
+       struct dio200_private *devpriv = dev->private;
+
+       offset <<= thisboard->mainshift;
+       if (devpriv->io.regtype == io_regtype)
+               outb(val, devpriv->io.u.iobase + offset);
+       else
+               writeb(val, devpriv->io.u.membase + offset);
+}
+
+/*
+ * Read 32-bit register.
+ */
+static unsigned int dio200_read32(struct comedi_device *dev,
+                                 unsigned int offset)
+{
+       const struct dio200_board *thisboard = comedi_board(dev);
+       struct dio200_private *devpriv = dev->private;
+
+       offset <<= thisboard->mainshift;
+       if (devpriv->io.regtype == io_regtype)
+               return inl(devpriv->io.u.iobase + offset);
+       else
+               return readl(devpriv->io.u.membase + offset);
+}
+
+/*
+ * Write 32-bit register.
+ */
+static void dio200_write32(struct comedi_device *dev, unsigned int offset,
+                          unsigned int val)
+{
+       const struct dio200_board *thisboard = comedi_board(dev);
+       struct dio200_private *devpriv = dev->private;
+
+       offset <<= thisboard->mainshift;
+       if (devpriv->io.regtype == io_regtype)
+               outl(val, devpriv->io.u.iobase + offset);
+       else
+               writel(val, devpriv->io.u.membase + offset);
+}
+
+/*
+ * 'insn_bits' function for an 'INTERRUPT' subdevice.
+ */
+static int
+dio200_subdev_intr_insn_bits(struct comedi_device *dev,
+                            struct comedi_subdevice *s,
+                            struct comedi_insn *insn, unsigned int *data)
+{
+       const struct dio200_layout *layout = dio200_dev_layout(dev);
+       struct dio200_subdev_intr *subpriv = s->private;
+
+       if (layout->has_int_sce) {
+               /* Just read the interrupt status register.  */
+               data[1] = dio200_read8(dev, subpriv->ofs) & subpriv->valid_isns;
+       } else {
+               /* No interrupt status register. */
+               data[0] = 0;
+       }
+
+       return insn->n;
+}
+
+/*
+ * Called to stop acquisition for an 'INTERRUPT' subdevice.
+ */
+static void dio200_stop_intr(struct comedi_device *dev,
+                            struct comedi_subdevice *s)
+{
+       const struct dio200_layout *layout = dio200_dev_layout(dev);
+       struct dio200_subdev_intr *subpriv = s->private;
+
+       subpriv->active = false;
+       subpriv->enabled_isns = 0;
+       if (layout->has_int_sce)
+               dio200_write8(dev, subpriv->ofs, 0);
+}
+
+/*
+ * Called to start acquisition for an 'INTERRUPT' subdevice.
+ */
+static int dio200_start_intr(struct comedi_device *dev,
+                            struct comedi_subdevice *s)
+{
+       unsigned int n;
+       unsigned isn_bits;
+       const struct dio200_layout *layout = dio200_dev_layout(dev);
+       struct dio200_subdev_intr *subpriv = s->private;
+       struct comedi_cmd *cmd = &s->async->cmd;
+       int retval = 0;
+
+       if (!subpriv->continuous && subpriv->stopcount == 0) {
+               /* An empty acquisition! */
+               s->async->events |= COMEDI_CB_EOA;
+               subpriv->active = false;
+               retval = 1;
+       } else {
+               /* Determine interrupt sources to enable. */
+               isn_bits = 0;
+               if (cmd->chanlist) {
+                       for (n = 0; n < cmd->chanlist_len; n++)
+                               isn_bits |= (1U << CR_CHAN(cmd->chanlist[n]));
+               }
+               isn_bits &= subpriv->valid_isns;
+               /* Enable interrupt sources. */
+               subpriv->enabled_isns = isn_bits;
+               if (layout->has_int_sce)
+                       dio200_write8(dev, subpriv->ofs, isn_bits);
+       }
+
+       return retval;
+}
+
+/*
+ * Internal trigger function to start acquisition for an 'INTERRUPT' subdevice.
+ */
+static int
+dio200_inttrig_start_intr(struct comedi_device *dev, struct comedi_subdevice *s,
+                         unsigned int trignum)
+{
+       struct dio200_subdev_intr *subpriv;
+       unsigned long flags;
+       int event = 0;
+
+       if (trignum != 0)
+               return -EINVAL;
+
+       subpriv = s->private;
+
+       spin_lock_irqsave(&subpriv->spinlock, flags);
+       s->async->inttrig = NULL;
+       if (subpriv->active)
+               event = dio200_start_intr(dev, s);
+
+       spin_unlock_irqrestore(&subpriv->spinlock, flags);
+
+       if (event)
+               comedi_event(dev, s);
+
+       return 1;
+}
+
+static void dio200_read_scan_intr(struct comedi_device *dev,
+                                 struct comedi_subdevice *s,
+                                 unsigned int triggered)
+{
+       struct dio200_subdev_intr *subpriv = s->private;
+       unsigned short val;
+       unsigned int n, ch, len;
+
+       val = 0;
+       len = s->async->cmd.chanlist_len;
+       for (n = 0; n < len; n++) {
+               ch = CR_CHAN(s->async->cmd.chanlist[n]);
+               if (triggered & (1U << ch))
+                       val |= (1U << n);
+       }
+       /* Write the scan to the buffer. */
+       if (comedi_buf_put(s->async, val)) {
+               s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS);
+       } else {
+               /* Error!  Stop acquisition.  */
+               dio200_stop_intr(dev, s);
+               s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW;
+               comedi_error(dev, "buffer overflow");
+       }
+
+       /* Check for end of acquisition. */
+       if (!subpriv->continuous) {
+               /* stop_src == TRIG_COUNT */
+               if (subpriv->stopcount > 0) {
+                       subpriv->stopcount--;
+                       if (subpriv->stopcount == 0) {
+                               s->async->events |= COMEDI_CB_EOA;
+                               dio200_stop_intr(dev, s);
+                       }
+               }
+       }
+}
+
+/*
+ * This is called from the interrupt service routine to handle a read
+ * scan on an 'INTERRUPT' subdevice.
+ */
+static int dio200_handle_read_intr(struct comedi_device *dev,
+                                  struct comedi_subdevice *s)
+{
+       const struct dio200_layout *layout = dio200_dev_layout(dev);
+       struct dio200_subdev_intr *subpriv = s->private;
+       unsigned triggered;
+       unsigned intstat;
+       unsigned cur_enabled;
+       unsigned int oldevents;
+       unsigned long flags;
+
+       triggered = 0;
+
+       spin_lock_irqsave(&subpriv->spinlock, flags);
+       oldevents = s->async->events;
+       if (layout->has_int_sce) {
+               /*
+                * Collect interrupt sources that have triggered and disable
+                * them temporarily.  Loop around until no extra interrupt
+                * sources have triggered, at which point, the valid part of
+                * the interrupt status register will read zero, clearing the
+                * cause of the interrupt.
+                *
+                * Mask off interrupt sources already seen to avoid infinite
+                * loop in case of misconfiguration.
+                */
+               cur_enabled = subpriv->enabled_isns;
+               while ((intstat = (dio200_read8(dev, subpriv->ofs) &
+                                  subpriv->valid_isns & ~triggered)) != 0) {
+                       triggered |= intstat;
+                       cur_enabled &= ~triggered;
+                       dio200_write8(dev, subpriv->ofs, cur_enabled);
+               }
+       } else {
+               /*
+                * No interrupt status register.  Assume the single interrupt
+                * source has triggered.
+                */
+               triggered = subpriv->enabled_isns;
+       }
+
+       if (triggered) {
+               /*
+                * Some interrupt sources have triggered and have been
+                * temporarily disabled to clear the cause of the interrupt.
+                *
+                * Reenable them NOW to minimize the time they are disabled.
+                */
+               cur_enabled = subpriv->enabled_isns;
+               if (layout->has_int_sce)
+                       dio200_write8(dev, subpriv->ofs, cur_enabled);
+
+               if (subpriv->active) {
+                       /*
+                        * The command is still active.
+                        *
+                        * Ignore interrupt sources that the command isn't
+                        * interested in (just in case there's a race
+                        * condition).
+                        */
+                       if (triggered & subpriv->enabled_isns)
+                               /* Collect scan data. */
+                               dio200_read_scan_intr(dev, s, triggered);
+               }
+       }
+       spin_unlock_irqrestore(&subpriv->spinlock, flags);
+
+       if (oldevents != s->async->events)
+               comedi_event(dev, s);
+
+       return (triggered != 0);
+}
+
+/*
+ * 'cancel' function for an 'INTERRUPT' subdevice.
+ */
+static int dio200_subdev_intr_cancel(struct comedi_device *dev,
+                                    struct comedi_subdevice *s)
+{
+       struct dio200_subdev_intr *subpriv = s->private;
+       unsigned long flags;
+
+       spin_lock_irqsave(&subpriv->spinlock, flags);
+       if (subpriv->active)
+               dio200_stop_intr(dev, s);
+
+       spin_unlock_irqrestore(&subpriv->spinlock, flags);
+
+       return 0;
+}
+
+/*
+ * 'do_cmdtest' function for an 'INTERRUPT' subdevice.
+ */
+static int
+dio200_subdev_intr_cmdtest(struct comedi_device *dev,
+                          struct comedi_subdevice *s, struct comedi_cmd *cmd)
+{
+       int err = 0;
+
+       /* Step 1 : check if triggers are trivially valid */
+
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
+
+       if (err)
+               return 1;
+
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_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 |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
+       err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
+       err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
+       err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
+
+       switch (cmd->stop_src) {
+       case TRIG_COUNT:
+               /* any count allowed */
+               break;
+       case TRIG_NONE:
+               err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
+               break;
+       default:
+               break;
+       }
+
+       if (err)
+               return 3;
+
+       /* step 4: fix up any arguments */
+
+       /* if (err) return 4; */
+
+       return 0;
+}
+
+/*
+ * 'do_cmd' function for an 'INTERRUPT' subdevice.
+ */
+static int dio200_subdev_intr_cmd(struct comedi_device *dev,
+                                 struct comedi_subdevice *s)
+{
+       struct comedi_cmd *cmd = &s->async->cmd;
+       struct dio200_subdev_intr *subpriv = s->private;
+       unsigned long flags;
+       int event = 0;
+
+       spin_lock_irqsave(&subpriv->spinlock, flags);
+       subpriv->active = 1;
+
+       /* Set up end of acquisition. */
+       switch (cmd->stop_src) {
+       case TRIG_COUNT:
+               subpriv->continuous = false;
+               subpriv->stopcount = cmd->stop_arg;
+               break;
+       default:
+               /* TRIG_NONE */
+               subpriv->continuous = true;
+               subpriv->stopcount = 0;
+               break;
+       }
+
+       /* Set up start of acquisition. */
+       switch (cmd->start_src) {
+       case TRIG_INT:
+               s->async->inttrig = dio200_inttrig_start_intr;
+               break;
+       default:
+               /* TRIG_NOW */
+               event = dio200_start_intr(dev, s);
+               break;
+       }
+       spin_unlock_irqrestore(&subpriv->spinlock, flags);
+
+       if (event)
+               comedi_event(dev, s);
+
+       return 0;
+}
+
+/*
+ * This function initializes an 'INTERRUPT' subdevice.
+ */
+static int
+dio200_subdev_intr_init(struct comedi_device *dev, struct comedi_subdevice *s,
+                       unsigned int offset, unsigned valid_isns)
+{
+       const struct dio200_layout *layout = dio200_dev_layout(dev);
+       struct dio200_subdev_intr *subpriv;
+
+       subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
+       if (!subpriv)
+               return -ENOMEM;
+
+       subpriv->ofs = offset;
+       subpriv->valid_isns = valid_isns;
+       spin_lock_init(&subpriv->spinlock);
+
+       if (layout->has_int_sce)
+               /* Disable interrupt sources. */
+               dio200_write8(dev, subpriv->ofs, 0);
+
+       s->private = subpriv;
+       s->type = COMEDI_SUBD_DI;
+       s->subdev_flags = SDF_READABLE | SDF_CMD_READ;
+       if (layout->has_int_sce) {
+               s->n_chan = DIO200_MAX_ISNS;
+               s->len_chanlist = DIO200_MAX_ISNS;
+       } else {
+               /* No interrupt source register.  Support single channel. */
+               s->n_chan = 1;
+               s->len_chanlist = 1;
+       }
+       s->range_table = &range_digital;
+       s->maxdata = 1;
+       s->insn_bits = dio200_subdev_intr_insn_bits;
+       s->do_cmdtest = dio200_subdev_intr_cmdtest;
+       s->do_cmd = dio200_subdev_intr_cmd;
+       s->cancel = dio200_subdev_intr_cancel;
+
+       return 0;
+}
+
+/*
+ * This function cleans up an 'INTERRUPT' subdevice.
+ */
+static void
+dio200_subdev_intr_cleanup(struct comedi_device *dev,
+                          struct comedi_subdevice *s)
+{
+       struct dio200_subdev_intr *subpriv = s->private;
+       kfree(subpriv);
+}
+
+/*
+ * Interrupt service routine.
+ */
+static irqreturn_t dio200_interrupt(int irq, void *d)
+{
+       struct comedi_device *dev = d;
+       struct dio200_private *devpriv = dev->private;
+       struct comedi_subdevice *s;
+       int handled;
+
+       if (!dev->attached)
+               return IRQ_NONE;
+
+       if (devpriv->intr_sd >= 0) {
+               s = &dev->subdevices[devpriv->intr_sd];
+               handled = dio200_handle_read_intr(dev, s);
+       } else {
+               handled = 0;
+       }
+
+       return IRQ_RETVAL(handled);
+}
+
+/*
+ * Read an '8254' counter subdevice channel.
+ */
+static unsigned int
+dio200_subdev_8254_read_chan(struct comedi_device *dev,
+                            struct comedi_subdevice *s, unsigned int chan)
+{
+       struct dio200_subdev_8254 *subpriv = s->private;
+       unsigned int val;
+
+       /* latch counter */
+       val = chan << 6;
+       dio200_write8(dev, subpriv->ofs + i8254_control_reg, val);
+       /* read lsb, msb */
+       val = dio200_read8(dev, subpriv->ofs + chan);
+       val += dio200_read8(dev, subpriv->ofs + chan) << 8;
+       return val;
+}
+
+/*
+ * Write an '8254' subdevice channel.
+ */
+static void
+dio200_subdev_8254_write_chan(struct comedi_device *dev,
+                             struct comedi_subdevice *s, unsigned int chan,
+                             unsigned int count)
+{
+       struct dio200_subdev_8254 *subpriv = s->private;
+
+       /* write lsb, msb */
+       dio200_write8(dev, subpriv->ofs + chan, count & 0xff);
+       dio200_write8(dev, subpriv->ofs + chan, (count >> 8) & 0xff);
+}
+
+/*
+ * Set mode of an '8254' subdevice channel.
+ */
+static void
+dio200_subdev_8254_set_mode(struct comedi_device *dev,
+                           struct comedi_subdevice *s, unsigned int chan,
+                           unsigned int mode)
+{
+       struct dio200_subdev_8254 *subpriv = s->private;
+       unsigned int byte;
+
+       byte = chan << 6;
+       byte |= 0x30;           /* access order: lsb, msb */
+       byte |= (mode & 0xf);   /* counter mode and BCD|binary */
+       dio200_write8(dev, subpriv->ofs + i8254_control_reg, byte);
+}
+
+/*
+ * Read status byte of an '8254' counter subdevice channel.
+ */
+static unsigned int
+dio200_subdev_8254_status(struct comedi_device *dev,
+                         struct comedi_subdevice *s, unsigned int chan)
+{
+       struct dio200_subdev_8254 *subpriv = s->private;
+
+       /* latch status */
+       dio200_write8(dev, subpriv->ofs + i8254_control_reg,
+                     0xe0 | (2 << chan));
+       /* read status */
+       return dio200_read8(dev, subpriv->ofs + chan);
+}
+
+/*
+ * Handle 'insn_read' for an '8254' counter subdevice.
+ */
+static int
+dio200_subdev_8254_read(struct comedi_device *dev, struct comedi_subdevice *s,
+                       struct comedi_insn *insn, unsigned int *data)
+{
+       struct dio200_subdev_8254 *subpriv = s->private;
+       int chan = CR_CHAN(insn->chanspec);
+       unsigned int n;
+       unsigned long flags;
+
+       for (n = 0; n < insn->n; n++) {
+               spin_lock_irqsave(&subpriv->spinlock, flags);
+               data[n] = dio200_subdev_8254_read_chan(dev, s, chan);
+               spin_unlock_irqrestore(&subpriv->spinlock, flags);
+       }
+       return insn->n;
+}
+
+/*
+ * Handle 'insn_write' for an '8254' counter subdevice.
+ */
+static int
+dio200_subdev_8254_write(struct comedi_device *dev, struct comedi_subdevice *s,
+                        struct comedi_insn *insn, unsigned int *data)
+{
+       struct dio200_subdev_8254 *subpriv = s->private;
+       int chan = CR_CHAN(insn->chanspec);
+       unsigned int n;
+       unsigned long flags;
+
+       for (n = 0; n < insn->n; n++) {
+               spin_lock_irqsave(&subpriv->spinlock, flags);
+               dio200_subdev_8254_write_chan(dev, s, chan, data[n]);
+               spin_unlock_irqrestore(&subpriv->spinlock, flags);
+       }
+       return insn->n;
+}
+
+/*
+ * Set gate source for an '8254' counter subdevice channel.
+ */
+static int
+dio200_subdev_8254_set_gate_src(struct comedi_device *dev,
+                               struct comedi_subdevice *s,
+                               unsigned int counter_number,
+                               unsigned int gate_src)
+{
+       const struct dio200_layout *layout = dio200_dev_layout(dev);
+       struct dio200_subdev_8254 *subpriv = s->private;
+       unsigned char byte;
+
+       if (!layout->has_clk_gat_sce)
+               return -1;
+       if (counter_number > 2)
+               return -1;
+       if (gate_src > (layout->has_enhancements ? 31 : 7))
+               return -1;
+
+       subpriv->gate_src[counter_number] = gate_src;
+       byte = gat_sce(subpriv->which, counter_number, gate_src);
+       dio200_write8(dev, subpriv->gat_sce_ofs, byte);
+
+       return 0;
+}
+
+/*
+ * Get gate source for an '8254' counter subdevice channel.
+ */
+static int
+dio200_subdev_8254_get_gate_src(struct comedi_device *dev,
+                               struct comedi_subdevice *s,
+                               unsigned int counter_number)
+{
+       const struct dio200_layout *layout = dio200_dev_layout(dev);
+       struct dio200_subdev_8254 *subpriv = s->private;
+
+       if (!layout->has_clk_gat_sce)
+               return -1;
+       if (counter_number > 2)
+               return -1;
+
+       return subpriv->gate_src[counter_number];
+}
+
+/*
+ * Set clock source for an '8254' counter subdevice channel.
+ */
+static int
+dio200_subdev_8254_set_clock_src(struct comedi_device *dev,
+                                struct comedi_subdevice *s,
+                                unsigned int counter_number,
+                                unsigned int clock_src)
+{
+       const struct dio200_layout *layout = dio200_dev_layout(dev);
+       struct dio200_subdev_8254 *subpriv = s->private;
+       unsigned char byte;
+
+       if (!layout->has_clk_gat_sce)
+               return -1;
+       if (counter_number > 2)
+               return -1;
+       if (clock_src > (layout->has_enhancements ? 31 : 7))
+               return -1;
+
+       subpriv->clock_src[counter_number] = clock_src;
+       byte = clk_sce(subpriv->which, counter_number, clock_src);
+       dio200_write8(dev, subpriv->clk_sce_ofs, byte);
+
+       return 0;
+}
+
+/*
+ * Get clock source for an '8254' counter subdevice channel.
+ */
+static int
+dio200_subdev_8254_get_clock_src(struct comedi_device *dev,
+                                struct comedi_subdevice *s,
+                                unsigned int counter_number,
+                                unsigned int *period_ns)
+{
+       const struct dio200_layout *layout = dio200_dev_layout(dev);
+       struct dio200_subdev_8254 *subpriv = s->private;
+       unsigned clock_src;
+
+       if (!layout->has_clk_gat_sce)
+               return -1;
+       if (counter_number > 2)
+               return -1;
+
+       clock_src = subpriv->clock_src[counter_number];
+       *period_ns = clock_period[clock_src];
+       return clock_src;
+}
+
+/*
+ * Handle 'insn_config' for an '8254' counter subdevice.
+ */
+static int
+dio200_subdev_8254_config(struct comedi_device *dev, struct comedi_subdevice *s,
+                         struct comedi_insn *insn, unsigned int *data)
+{
+       struct dio200_subdev_8254 *subpriv = s->private;
+       int ret = 0;
+       int chan = CR_CHAN(insn->chanspec);
+       unsigned long flags;
+
+       spin_lock_irqsave(&subpriv->spinlock, flags);
+       switch (data[0]) {
+       case INSN_CONFIG_SET_COUNTER_MODE:
+               if (data[1] > (I8254_MODE5 | I8254_BINARY))
+                       ret = -EINVAL;
+               else
+                       dio200_subdev_8254_set_mode(dev, s, chan, data[1]);
+               break;
+       case INSN_CONFIG_8254_READ_STATUS:
+               data[1] = dio200_subdev_8254_status(dev, s, chan);
+               break;
+       case INSN_CONFIG_SET_GATE_SRC:
+               ret = dio200_subdev_8254_set_gate_src(dev, s, chan, data[2]);
+               if (ret < 0)
+                       ret = -EINVAL;
+               break;
+       case INSN_CONFIG_GET_GATE_SRC:
+               ret = dio200_subdev_8254_get_gate_src(dev, s, chan);
+               if (ret < 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               data[2] = ret;
+               break;
+       case INSN_CONFIG_SET_CLOCK_SRC:
+               ret = dio200_subdev_8254_set_clock_src(dev, s, chan, data[1]);
+               if (ret < 0)
+                       ret = -EINVAL;
+               break;
+       case INSN_CONFIG_GET_CLOCK_SRC:
+               ret = dio200_subdev_8254_get_clock_src(dev, s, chan, &data[2]);
+               if (ret < 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               data[1] = ret;
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+       spin_unlock_irqrestore(&subpriv->spinlock, flags);
+       return ret < 0 ? ret : insn->n;
+}
+
+/*
+ * This function initializes an '8254' counter subdevice.
+ */
+static int
+dio200_subdev_8254_init(struct comedi_device *dev, struct comedi_subdevice *s,
+                       unsigned int offset)
+{
+       const struct dio200_layout *layout = dio200_dev_layout(dev);
+       struct dio200_subdev_8254 *subpriv;
+       unsigned int chan;
+
+       subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
+       if (!subpriv)
+               return -ENOMEM;
+
+       s->private = subpriv;
+       s->type = COMEDI_SUBD_COUNTER;
+       s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
+       s->n_chan = 3;
+       s->maxdata = 0xFFFF;
+       s->insn_read = dio200_subdev_8254_read;
+       s->insn_write = dio200_subdev_8254_write;
+       s->insn_config = dio200_subdev_8254_config;
+
+       spin_lock_init(&subpriv->spinlock);
+       subpriv->ofs = offset;
+       if (layout->has_clk_gat_sce) {
+               /* Derive CLK_SCE and GAT_SCE register offsets from
+                * 8254 offset. */
+               subpriv->clk_sce_ofs = DIO200_XCLK_SCE + (offset >> 3);
+               subpriv->gat_sce_ofs = DIO200_XGAT_SCE + (offset >> 3);
+               subpriv->which = (offset >> 2) & 1;
+       }
+
+       /* Initialize channels. */
+       for (chan = 0; chan < 3; chan++) {
+               dio200_subdev_8254_set_mode(dev, s, chan,
+                                           I8254_MODE0 | I8254_BINARY);
+               if (layout->has_clk_gat_sce) {
+                       /* Gate source 0 is VCC (logic 1). */
+                       dio200_subdev_8254_set_gate_src(dev, s, chan, 0);
+                       /* Clock source 0 is the dedicated clock input. */
+                       dio200_subdev_8254_set_clock_src(dev, s, chan, 0);
+               }
+       }
+
+       return 0;
+}
+
+/*
+ * This function cleans up an '8254' counter subdevice.
+ */
+static void
+dio200_subdev_8254_cleanup(struct comedi_device *dev,
+                          struct comedi_subdevice *s)
+{
+       struct dio200_subdev_intr *subpriv = s->private;
+       kfree(subpriv);
+}
+
+/*
+ * This function sets I/O directions for an '8255' DIO subdevice.
+ */
+static void dio200_subdev_8255_set_dir(struct comedi_device *dev,
+                                      struct comedi_subdevice *s)
+{
+       struct dio200_subdev_8255 *subpriv = s->private;
+       int config;
+
+       config = CR_CW;
+       /* 1 in io_bits indicates output, 1 in config indicates input */
+       if (!(s->io_bits & 0x0000ff))
+               config |= CR_A_IO;
+       if (!(s->io_bits & 0x00ff00))
+               config |= CR_B_IO;
+       if (!(s->io_bits & 0x0f0000))
+               config |= CR_C_LO_IO;
+       if (!(s->io_bits & 0xf00000))
+               config |= CR_C_HI_IO;
+       dio200_write8(dev, subpriv->ofs + 3, config);
+}
+
+/*
+ * Handle 'insn_bits' for an '8255' DIO subdevice.
+ */
+static int dio200_subdev_8255_bits(struct comedi_device *dev,
+                                  struct comedi_subdevice *s,
+                                  struct comedi_insn *insn, unsigned int *data)
+{
+       struct dio200_subdev_8255 *subpriv = s->private;
+
+       if (data[0]) {
+               s->state &= ~data[0];
+               s->state |= (data[0] & data[1]);
+               if (data[0] & 0xff)
+                       dio200_write8(dev, subpriv->ofs, s->state & 0xff);
+               if (data[0] & 0xff00)
+                       dio200_write8(dev, subpriv->ofs + 1,
+                                     (s->state >> 8) & 0xff);
+               if (data[0] & 0xff0000)
+                       dio200_write8(dev, subpriv->ofs + 2,
+                                     (s->state >> 16) & 0xff);
+       }
+       data[1] = dio200_read8(dev, subpriv->ofs);
+       data[1] |= dio200_read8(dev, subpriv->ofs + 1) << 8;
+       data[1] |= dio200_read8(dev, subpriv->ofs + 2) << 16;
+       return 2;
+}
+
+/*
+ * Handle 'insn_config' for an '8255' DIO subdevice.
+ */
+static int dio200_subdev_8255_config(struct comedi_device *dev,
+                                    struct comedi_subdevice *s,
+                                    struct comedi_insn *insn,
+                                    unsigned int *data)
+{
+       unsigned int mask;
+       unsigned int bits;
+
+       mask = 1 << CR_CHAN(insn->chanspec);
+       if (mask & 0x0000ff)
+               bits = 0x0000ff;
+       else if (mask & 0x00ff00)
+               bits = 0x00ff00;
+       else if (mask & 0x0f0000)
+               bits = 0x0f0000;
+       else
+               bits = 0xf00000;
+       switch (data[0]) {
+       case INSN_CONFIG_DIO_INPUT:
+               s->io_bits &= ~bits;
+               break;
+       case INSN_CONFIG_DIO_OUTPUT:
+               s->io_bits |= bits;
+               break;
+       case INSN_CONFIG_DIO_QUERY:
+               data[1] = (s->io_bits & bits) ? COMEDI_OUTPUT : COMEDI_INPUT;
+               return insn->n;
+               break;
+       default:
+               return -EINVAL;
+       }
+       dio200_subdev_8255_set_dir(dev, s);
+       return 1;
+}
+
+/*
+ * This function initializes an '8255' DIO subdevice.
+ *
+ * offset is the offset to the 8255 chip.
+ */
+static int dio200_subdev_8255_init(struct comedi_device *dev,
+                                  struct comedi_subdevice *s,
+                                  unsigned int offset)
+{
+       struct dio200_subdev_8255 *subpriv;
+
+       subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
+       if (!subpriv)
+               return -ENOMEM;
+       subpriv->ofs = offset;
+       s->private = subpriv;
+       s->type = COMEDI_SUBD_DIO;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
+       s->n_chan = 24;
+       s->range_table = &range_digital;
+       s->maxdata = 1;
+       s->insn_bits = dio200_subdev_8255_bits;
+       s->insn_config = dio200_subdev_8255_config;
+       s->state = 0;
+       s->io_bits = 0;
+       dio200_subdev_8255_set_dir(dev, s);
+       return 0;
+}
+
+/*
+ * This function cleans up an '8255' DIO subdevice.
+ */
+static void dio200_subdev_8255_cleanup(struct comedi_device *dev,
+                                      struct comedi_subdevice *s)
+{
+       struct dio200_subdev_8255 *subpriv = s->private;
+
+       kfree(subpriv);
+}
+
+/*
+ * Handle 'insn_read' for a timer subdevice.
+ */
+static int dio200_subdev_timer_read(struct comedi_device *dev,
+                                   struct comedi_subdevice *s,
+                                   struct comedi_insn *insn,
+                                   unsigned int *data)
+{
+       unsigned int n;
+
+       for (n = 0; n < insn->n; n++)
+               data[n] = dio200_read32(dev, DIO200_TS_COUNT);
+       return n;
+}
+
+/*
+ * Reset timer subdevice.
+ */
+static void dio200_subdev_timer_reset(struct comedi_device *dev,
+                                     struct comedi_subdevice *s)
+{
+       unsigned int clock;
+
+       clock = dio200_read32(dev, DIO200_TS_CONFIG) & TS_CONFIG_CLK_SRC_MASK;
+       dio200_write32(dev, DIO200_TS_CONFIG, clock | TS_CONFIG_RESET);
+       dio200_write32(dev, DIO200_TS_CONFIG, clock);
+}
+
+/*
+ * Get timer subdevice clock source and period.
+ */
+static void dio200_subdev_timer_get_clock_src(struct comedi_device *dev,
+                                             struct comedi_subdevice *s,
+                                             unsigned int *src,
+                                             unsigned int *period)
+{
+       unsigned int clk;
+
+       clk = dio200_read32(dev, DIO200_TS_CONFIG) & TS_CONFIG_CLK_SRC_MASK;
+       *src = clk;
+       *period = (clk < ARRAY_SIZE(ts_clock_period)) ?
+                 ts_clock_period[clk] : 0;
+}
+
+/*
+ * Set timer subdevice clock source.
+ */
+static int dio200_subdev_timer_set_clock_src(struct comedi_device *dev,
+                                            struct comedi_subdevice *s,
+                                            unsigned int src)
+{
+       if (src > TS_CONFIG_MAX_CLK_SRC)
+               return -EINVAL;
+       dio200_write32(dev, DIO200_TS_CONFIG, src);
+       return 0;
+}
+
+/*
+ * Handle 'insn_config' for a timer subdevice.
+ */
+static int dio200_subdev_timer_config(struct comedi_device *dev,
+                                     struct comedi_subdevice *s,
+                                     struct comedi_insn *insn,
+                                     unsigned int *data)
+{
+       int ret = 0;
+
+       switch (data[0]) {
+       case INSN_CONFIG_RESET:
+               dio200_subdev_timer_reset(dev, s);
+               break;
+       case INSN_CONFIG_SET_CLOCK_SRC:
+               ret = dio200_subdev_timer_set_clock_src(dev, s, data[1]);
+               if (ret < 0)
+                       ret = -EINVAL;
+               break;
+       case INSN_CONFIG_GET_CLOCK_SRC:
+               dio200_subdev_timer_get_clock_src(dev, s, &data[1], &data[2]);
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+       return ret < 0 ? ret : insn->n;
+}
+
+/*
+ * This function initializes a timer subdevice.
+ *
+ * Uses the timestamp timer registers.  There is only one timestamp timer.
+ */
+static int dio200_subdev_timer_init(struct comedi_device *dev,
+                                   struct comedi_subdevice *s)
+{
+       s->type = COMEDI_SUBD_TIMER;
+       s->subdev_flags = SDF_READABLE | SDF_LSAMPL;
+       s->n_chan = 1;
+       s->maxdata = 0xFFFFFFFF;
+       s->insn_read = dio200_subdev_timer_read;
+       s->insn_config = dio200_subdev_timer_config;
+       return 0;
+}
+
+/*
+ * This function cleans up a timer subdevice.
+ */
+static void dio200_subdev_timer_cleanup(struct comedi_device *dev,
+                                       struct comedi_subdevice *s)
+{
+       /* Nothing to do. */
+}
+
+void amplc_dio200_set_enhance(struct comedi_device *dev, unsigned char val)
+{
+       dio200_write8(dev, DIO200_ENHANCE, val);
+}
+EXPORT_SYMBOL_GPL(amplc_dio200_set_enhance);
+
+int amplc_dio200_common_attach(struct comedi_device *dev, unsigned int irq,
+                              unsigned long req_irq_flags)
+{
+       const struct dio200_board *thisboard = comedi_board(dev);
+       struct dio200_private *devpriv = dev->private;
+       const struct dio200_layout *layout = dio200_board_layout(thisboard);
+       struct comedi_subdevice *s;
+       int sdx;
+       unsigned int n;
+       int ret;
+
+       devpriv->intr_sd = -1;
+
+       ret = comedi_alloc_subdevices(dev, layout->n_subdevs);
+       if (ret)
+               return ret;
+
+       for (n = 0; n < dev->n_subdevices; n++) {
+               s = &dev->subdevices[n];
+               switch (layout->sdtype[n]) {
+               case sd_8254:
+                       /* counter subdevice (8254) */
+                       ret = dio200_subdev_8254_init(dev, s,
+                                                     layout->sdinfo[n]);
+                       if (ret < 0)
+                               return ret;
+                       break;
+               case sd_8255:
+                       /* digital i/o subdevice (8255) */
+                       ret = dio200_subdev_8255_init(dev, s,
+                                                     layout->sdinfo[n]);
+                       if (ret < 0)
+                               return ret;
+                       break;
+               case sd_intr:
+                       /* 'INTERRUPT' subdevice */
+                       if (irq) {
+                               ret = dio200_subdev_intr_init(dev, s,
+                                                             DIO200_INT_SCE,
+                                                             layout->sdinfo[n]
+                                                            );
+                               if (ret < 0)
+                                       return ret;
+                               devpriv->intr_sd = n;
+                       } else {
+                               s->type = COMEDI_SUBD_UNUSED;
+                       }
+                       break;
+               case sd_timer:
+                       ret = dio200_subdev_timer_init(dev, s);
+                       if (ret < 0)
+                               return ret;
+                       break;
+               default:
+                       s->type = COMEDI_SUBD_UNUSED;
+                       break;
+               }
+       }
+       sdx = devpriv->intr_sd;
+       if (sdx >= 0 && sdx < dev->n_subdevices)
+               dev->read_subdev = &dev->subdevices[sdx];
+       if (irq) {
+               if (request_irq(irq, dio200_interrupt, req_irq_flags,
+                               dev->board_name, dev) >= 0) {
+                       dev->irq = irq;
+               } else {
+                       dev_warn(dev->class_dev,
+                                "warning! irq %u unavailable!\n", irq);
+               }
+       }
+       dev_info(dev->class_dev, "attached\n");
+       return 0;
+}
+EXPORT_SYMBOL_GPL(amplc_dio200_common_attach);
+
+void amplc_dio200_common_detach(struct comedi_device *dev)
+{
+       const struct dio200_board *thisboard = comedi_board(dev);
+       struct dio200_private *devpriv = dev->private;
+       const struct dio200_layout *layout;
+       unsigned n;
+
+       if (!thisboard || !devpriv)
+               return;
+       if (dev->irq)
+               free_irq(dev->irq, dev);
+       if (dev->subdevices) {
+               layout = dio200_board_layout(thisboard);
+               for (n = 0; n < dev->n_subdevices; n++) {
+                       struct comedi_subdevice *s = &dev->subdevices[n];
+                       switch (layout->sdtype[n]) {
+                       case sd_8254:
+                               dio200_subdev_8254_cleanup(dev, s);
+                               break;
+                       case sd_8255:
+                               dio200_subdev_8255_cleanup(dev, s);
+                               break;
+                       case sd_intr:
+                               dio200_subdev_intr_cleanup(dev, s);
+                               break;
+                       case sd_timer:
+                               dio200_subdev_timer_cleanup(dev, s);
+                               break;
+                       default:
+                               break;
+                       }
+               }
+       }
+}
+EXPORT_SYMBOL_GPL(amplc_dio200_common_detach);
+
+static int __init amplc_dio200_common_init(void)
+{
+       return 0;
+}
+module_init(amplc_dio200_common_init);
+
+static void __exit amplc_dio200_common_exit(void)
+{
+}
+module_exit(amplc_dio200_common_exit);
+
+MODULE_AUTHOR("Comedi http://www.comedi.org");
+MODULE_DESCRIPTION("Comedi helper for amplc_dio200 and amplc_dio200_pci");
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/amplc_dio200_pci.c b/drivers/staging/comedi/drivers/amplc_dio200_pci.c
new file mode 100644 (file)
index 0000000..232620c
--- /dev/null
@@ -0,0 +1,492 @@
+/* comedi/drivers/amplc_dio200_pci.c
+
+    Driver for Amplicon PCI215, PCI272, PCIe215, PCIe236, PCIe296.
+
+    Copyright (C) 2005-2013 MEV Ltd. <http://www.mev.co.uk/>
+
+    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.
+
+    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.
+
+*/
+/*
+ * Driver: amplc_dio200_pci
+ * Description: Amplicon 200 Series PCI Digital I/O
+ * Author: Ian Abbott <abbotti@mev.co.uk>
+ * Devices: [Amplicon] PCI215 (amplc_dio200_pci), PCIe215, PCIe236,
+ *   PCI272, PCIe296
+ * Updated: Mon, 18 Mar 2013 15:03:50 +0000
+ * Status: works
+ *
+ * Configuration options:
+ *   none
+ *
+ * Manual configuration of PCI(e) cards is not supported; they are configured
+ * automatically.
+ *
+ * SUBDEVICES
+ *
+ *                     PCI215         PCIe215        PCIe236
+ *                  -------------  -------------  -------------
+ *   Subdevices           5              8              8
+ *    0                 PPI-X          PPI-X          PPI-X
+ *    1                 PPI-Y          UNUSED         UNUSED
+ *    2                 CTR-Z1         PPI-Y          UNUSED
+ *    3                 CTR-Z2         UNUSED         UNUSED
+ *    4               INTERRUPT        CTR-Z1         CTR-Z1
+ *    5                                CTR-Z2         CTR-Z2
+ *    6                                TIMER          TIMER
+ *    7                              INTERRUPT      INTERRUPT
+ *
+ *
+ *                     PCI272         PCIe296
+ *                  -------------  -------------
+ *   Subdevices           4              8
+ *    0                 PPI-X          PPI-X1
+ *    1                 PPI-Y          PPI-X2
+ *    2                 PPI-Z          PPI-Y1
+ *    3               INTERRUPT        PPI-Y2
+ *    4                                CTR-Z1
+ *    5                                CTR-Z2
+ *    6                                TIMER
+ *    7                              INTERRUPT
+ *
+ * Each PPI is a 8255 chip providing 24 DIO channels.  The DIO channels
+ * are configurable as inputs or outputs in four groups:
+ *
+ *   Port A  - channels  0 to  7
+ *   Port B  - channels  8 to 15
+ *   Port CL - channels 16 to 19
+ *   Port CH - channels 20 to 23
+ *
+ * Only mode 0 of the 8255 chips is supported.
+ *
+ * Each CTR is a 8254 chip providing 3 16-bit counter channels.  Each
+ * channel is configured individually with INSN_CONFIG instructions.  The
+ * specific type of configuration instruction is specified in data[0].
+ * Some configuration instructions expect an additional parameter in
+ * data[1]; others return a value in data[1].  The following configuration
+ * instructions are supported:
+ *
+ *   INSN_CONFIG_SET_COUNTER_MODE.  Sets the counter channel's mode and
+ *     BCD/binary setting specified in data[1].
+ *
+ *   INSN_CONFIG_8254_READ_STATUS.  Reads the status register value for the
+ *     counter channel into data[1].
+ *
+ *   INSN_CONFIG_SET_CLOCK_SRC.  Sets the counter channel's clock source as
+ *     specified in data[1] (this is a hardware-specific value).  Not
+ *     supported on PC214E.  For the other boards, valid clock sources are
+ *     0 to 7 as follows:
+ *
+ *       0.  CLK n, the counter channel's dedicated CLK input from the SK1
+ *         connector.  (N.B. for other values, the counter channel's CLKn
+ *         pin on the SK1 connector is an output!)
+ *       1.  Internal 10 MHz clock.
+ *       2.  Internal 1 MHz clock.
+ *       3.  Internal 100 kHz clock.
+ *       4.  Internal 10 kHz clock.
+ *       5.  Internal 1 kHz clock.
+ *       6.  OUT n-1, the output of counter channel n-1 (see note 1 below).
+ *       7.  Ext Clock, the counter chip's dedicated Ext Clock input from
+ *         the SK1 connector.  This pin is shared by all three counter
+ *         channels on the chip.
+ *
+ *     For the PCIe boards, clock sources in the range 0 to 31 are allowed
+ *     and the following additional clock sources are defined:
+ *
+ *       8.  HIGH logic level.
+ *       9.  LOW logic level.
+ *      10.  "Pattern present" signal.
+ *      11.  Internal 20 MHz clock.
+ *
+ *   INSN_CONFIG_GET_CLOCK_SRC.  Returns the counter channel's current
+ *     clock source in data[1].  For internal clock sources, data[2] is set
+ *     to the period in ns.
+ *
+ *   INSN_CONFIG_SET_GATE_SRC.  Sets the counter channel's gate source as
+ *     specified in data[2] (this is a hardware-specific value).  Not
+ *     supported on PC214E.  For the other boards, valid gate sources are 0
+ *     to 7 as follows:
+ *
+ *       0.  VCC (internal +5V d.c.), i.e. gate permanently enabled.
+ *       1.  GND (internal 0V d.c.), i.e. gate permanently disabled.
+ *       2.  GAT n, the counter channel's dedicated GAT input from the SK1
+ *         connector.  (N.B. for other values, the counter channel's GATn
+ *         pin on the SK1 connector is an output!)
+ *       3.  /OUT n-2, the inverted output of counter channel n-2 (see note
+ *         2 below).
+ *       4.  Reserved.
+ *       5.  Reserved.
+ *       6.  Reserved.
+ *       7.  Reserved.
+ *
+ *     For the PCIe boards, gate sources in the range 0 to 31 are allowed;
+ *     the following additional clock sources and clock sources 6 and 7 are
+ *     (re)defined:
+ *
+ *       6.  /GAT n, negated version of the counter channel's dedicated
+ *         GAT input (negated version of gate source 2).
+ *       7.  OUT n-2, the non-inverted output of counter channel n-2
+ *         (negated version of gate source 3).
+ *       8.  "Pattern present" signal, HIGH while pattern present.
+ *       9.  "Pattern occurred" latched signal, latches HIGH when pattern
+ *         occurs.
+ *      10.  "Pattern gone away" latched signal, latches LOW when pattern
+ *         goes away after it occurred.
+ *      11.  Negated "pattern present" signal, LOW while pattern present
+ *         (negated version of gate source 8).
+ *      12.  Negated "pattern occurred" latched signal, latches LOW when
+ *         pattern occurs (negated version of gate source 9).
+ *      13.  Negated "pattern gone away" latched signal, latches LOW when
+ *         pattern goes away after it occurred (negated version of gate
+ *         source 10).
+ *
+ *   INSN_CONFIG_GET_GATE_SRC.  Returns the counter channel's current gate
+ *     source in data[2].
+ *
+ * Clock and gate interconnection notes:
+ *
+ *   1.  Clock source OUT n-1 is the output of the preceding channel on the
+ *   same counter subdevice if n > 0, or the output of channel 2 on the
+ *   preceding counter subdevice (see note 3) if n = 0.
+ *
+ *   2.  Gate source /OUT n-2 is the inverted output of channel 0 on the
+ *   same counter subdevice if n = 2, or the inverted output of channel n+1
+ *   on the preceding counter subdevice (see note 3) if n < 2.
+ *
+ *   3.  The counter subdevices are connected in a ring, so the highest
+ *   counter subdevice precedes the lowest.
+ *
+ * The 'TIMER' subdevice is a free-running 32-bit timer subdevice.
+ *
+ * The 'INTERRUPT' subdevice pretends to be a digital input subdevice.  The
+ * digital inputs come from the interrupt status register.  The number of
+ * channels matches the number of interrupt sources.  The PC214E does not
+ * have an interrupt status register; see notes on 'INTERRUPT SOURCES'
+ * below.
+ *
+ * INTERRUPT SOURCES
+ *
+ *                     PCI215         PCIe215        PCIe236
+ *                  -------------  -------------  -------------
+ *   Sources              6              6              6
+ *    0               PPI-X-C0       PPI-X-C0       PPI-X-C0
+ *    1               PPI-X-C3       PPI-X-C3       PPI-X-C3
+ *    2               PPI-Y-C0       PPI-Y-C0        unused
+ *    3               PPI-Y-C3       PPI-Y-C3        unused
+ *    4              CTR-Z1-OUT1    CTR-Z1-OUT1    CTR-Z1-OUT1
+ *    5              CTR-Z2-OUT1    CTR-Z2-OUT1    CTR-Z2-OUT1
+ *
+ *                     PCI272         PCIe296
+ *                  -------------  -------------
+ *   Sources              6              6
+ *    0               PPI-X-C0       PPI-X1-C0
+ *    1               PPI-X-C3       PPI-X1-C3
+ *    2               PPI-Y-C0       PPI-Y1-C0
+ *    3               PPI-Y-C3       PPI-Y1-C3
+ *    4               PPI-Z-C0      CTR-Z1-OUT1
+ *    5               PPI-Z-C3      CTR-Z2-OUT1
+ *
+ * When an interrupt source is enabled in the interrupt source enable
+ * register, a rising edge on the source signal latches the corresponding
+ * bit to 1 in the interrupt status register.
+ *
+ * When the interrupt status register value as a whole (actually, just the
+ * 6 least significant bits) goes from zero to non-zero, the board will
+ * generate an interrupt.  The interrupt will remain asserted until the
+ * interrupt status register is cleared to zero.  To clear a bit to zero in
+ * the interrupt status register, the corresponding interrupt source must
+ * be disabled in the interrupt source enable register (there is no
+ * separate interrupt clear register).
+ *
+ * COMMANDS
+ *
+ * The driver supports a read streaming acquisition command on the
+ * 'INTERRUPT' subdevice.  The channel list selects the interrupt sources
+ * to be enabled.  All channels will be sampled together (convert_src ==
+ * TRIG_NOW).  The scan begins a short time after the hardware interrupt
+ * occurs, subject to interrupt latencies (scan_begin_src == TRIG_EXT,
+ * scan_begin_arg == 0).  The value read from the interrupt status register
+ * is packed into a short value, one bit per requested channel, in the
+ * order they appear in the channel list.
+ */
+
+#include <linux/pci.h>
+#include <linux/interrupt.h>
+#include <linux/slab.h>
+
+#include "../comedidev.h"
+
+#include "amplc_dio200.h"
+
+/* PCI IDs */
+#define PCI_DEVICE_ID_AMPLICON_PCI272 0x000a
+#define PCI_DEVICE_ID_AMPLICON_PCI215 0x000b
+#define PCI_DEVICE_ID_AMPLICON_PCIE236 0x0011
+#define PCI_DEVICE_ID_AMPLICON_PCIE215 0x0012
+#define PCI_DEVICE_ID_AMPLICON_PCIE296 0x0014
+
+/*
+ * Board descriptions.
+ */
+
+enum dio200_pci_model {
+       pci215_model,
+       pci272_model,
+       pcie215_model,
+       pcie236_model,
+       pcie296_model
+};
+
+static const struct dio200_board dio200_pci_boards[] = {
+       [pci215_model] = {
+               .name = "pci215",
+               .bustype = pci_bustype,
+               .mainbar = 2,
+               .mainsize = DIO200_IO_SIZE,
+               .layout = {
+                       .n_subdevs = 5,
+                       .sdtype = {sd_8255, sd_8255, sd_8254, sd_8254, sd_intr},
+                       .sdinfo = {0x00, 0x08, 0x10, 0x14, 0x3F},
+                       .has_int_sce = true,
+                       .has_clk_gat_sce = true,
+               },
+       },
+       [pci272_model] = {
+               .name = "pci272",
+               .bustype = pci_bustype,
+               .mainbar = 2,
+               .mainsize = DIO200_IO_SIZE,
+               .layout = {
+                       .n_subdevs = 4,
+                       .sdtype = {sd_8255, sd_8255, sd_8255, sd_intr},
+                       .sdinfo = {0x00, 0x08, 0x10, 0x3F},
+                       .has_int_sce = true,
+               },
+       },
+       [pcie215_model] = {
+               .name = "pcie215",
+               .bustype = pci_bustype,
+               .mainbar = 1,
+               .mainshift = 3,
+               .mainsize = DIO200_PCIE_IO_SIZE,
+               .layout = {
+                       .n_subdevs = 8,
+                       .sdtype = {sd_8255, sd_none, sd_8255, sd_none,
+                                  sd_8254, sd_8254, sd_timer, sd_intr},
+                       .sdinfo = {0x00, 0x00, 0x08, 0x00,
+                                  0x10, 0x14, 0x00, 0x3F},
+                       .has_int_sce = true,
+                       .has_clk_gat_sce = true,
+                       .has_enhancements = true,
+               },
+       },
+       [pcie236_model] = {
+               .name = "pcie236",
+               .bustype = pci_bustype,
+               .mainbar = 1,
+               .mainshift = 3,
+               .mainsize = DIO200_PCIE_IO_SIZE,
+               .layout = {
+                       .n_subdevs = 8,
+                       .sdtype = {sd_8255, sd_none, sd_none, sd_none,
+                                  sd_8254, sd_8254, sd_timer, sd_intr},
+                       .sdinfo = {0x00, 0x00, 0x00, 0x00,
+                                  0x10, 0x14, 0x00, 0x3F},
+                       .has_int_sce = true,
+                       .has_clk_gat_sce = true,
+                       .has_enhancements = true,
+               },
+       },
+       [pcie296_model] = {
+               .name = "pcie296",
+               .bustype = pci_bustype,
+               .mainbar = 1,
+               .mainshift = 3,
+               .mainsize = DIO200_PCIE_IO_SIZE,
+               .layout = {
+                       .n_subdevs = 8,
+                       .sdtype = {sd_8255, sd_8255, sd_8255, sd_8255,
+                                  sd_8254, sd_8254, sd_timer, sd_intr},
+                       .sdinfo = {0x00, 0x04, 0x08, 0x0C,
+                                  0x10, 0x14, 0x00, 0x3F},
+                       .has_int_sce = true,
+                       .has_clk_gat_sce = true,
+                       .has_enhancements = true,
+               },
+       },
+};
+
+/*
+ * This function does some special set-up for the PCIe boards
+ * PCIe215, PCIe236, PCIe296.
+ */
+static int dio200_pcie_board_setup(struct comedi_device *dev)
+{
+       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+       void __iomem *brbase;
+       resource_size_t brlen;
+
+       /*
+        * The board uses Altera Cyclone IV with PCI-Express hard IP.
+        * The FPGA configuration has the PCI-Express Avalon-MM Bridge
+        * Control registers in PCI BAR 0, offset 0, and the length of
+        * these registers is 0x4000.
+        *
+        * We need to write 0x80 to the "Avalon-MM to PCI-Express Interrupt
+        * Enable" register at offset 0x50 to allow generation of PCIe
+        * interrupts when RXmlrq_i is asserted in the SOPC Builder system.
+        */
+       brlen = pci_resource_len(pcidev, 0);
+       if (brlen < 0x4000 ||
+                       !(pci_resource_flags(pcidev, 0) & IORESOURCE_MEM)) {
+               dev_err(dev->class_dev, "error! bad PCI region!\n");
+               return -EINVAL;
+       }
+       brbase = ioremap_nocache(pci_resource_start(pcidev, 0), brlen);
+       if (!brbase) {
+               dev_err(dev->class_dev, "error! failed to map registers!\n");
+               return -ENOMEM;
+       }
+       writel(0x80, brbase + 0x50);
+       iounmap(brbase);
+       /* Enable "enhanced" features of board. */
+       amplc_dio200_set_enhance(dev, 1);
+       return 0;
+}
+
+static int dio200_pci_auto_attach(struct comedi_device *dev,
+                                 unsigned long context_model)
+{
+       struct pci_dev *pci_dev = comedi_to_pci_dev(dev);
+       const struct dio200_board *thisboard = NULL;
+       struct dio200_private *devpriv;
+       resource_size_t base, len;
+       unsigned int bar;
+       int ret;
+
+       if (context_model < ARRAY_SIZE(dio200_pci_boards))
+               thisboard = &dio200_pci_boards[context_model];
+       if (!thisboard)
+               return -EINVAL;
+       dev->board_ptr = thisboard;
+       dev->board_name = thisboard->name;
+
+       dev_info(dev->class_dev, "%s: attach pci %s (%s)\n",
+                dev->driver->driver_name, pci_name(pci_dev), dev->board_name);
+
+       devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
+       if (!devpriv)
+               return -ENOMEM;
+       dev->private = devpriv;
+
+       ret = comedi_pci_enable(dev);
+       if (ret)
+               return ret;
+
+       bar = thisboard->mainbar;
+       base = pci_resource_start(pci_dev, bar);
+       len = pci_resource_len(pci_dev, bar);
+       if (len < thisboard->mainsize) {
+               dev_err(dev->class_dev, "error! PCI region size too small!\n");
+               return -EINVAL;
+       }
+       if (pci_resource_flags(pci_dev, bar) & IORESOURCE_MEM) {
+               devpriv->io.u.membase = ioremap_nocache(base, len);
+               if (!devpriv->io.u.membase) {
+                       dev_err(dev->class_dev,
+                               "error! cannot remap registers\n");
+                       return -ENOMEM;
+               }
+               devpriv->io.regtype = mmio_regtype;
+       } else {
+               devpriv->io.u.iobase = (unsigned long)base;
+               devpriv->io.regtype = io_regtype;
+       }
+       switch (context_model) {
+       case pcie215_model:
+       case pcie236_model:
+       case pcie296_model:
+               ret = dio200_pcie_board_setup(dev);
+               if (ret < 0)
+                       return ret;
+               break;
+       default:
+               break;
+       }
+       return amplc_dio200_common_attach(dev, pci_dev->irq, IRQF_SHARED);
+}
+
+static void dio200_pci_detach(struct comedi_device *dev)
+{
+       const struct dio200_board *thisboard = comedi_board(dev);
+       struct dio200_private *devpriv = dev->private;
+
+       if (!thisboard || !devpriv)
+               return;
+       amplc_dio200_common_detach(dev);
+       if (devpriv->io.regtype == mmio_regtype)
+               iounmap(devpriv->io.u.membase);
+       comedi_pci_disable(dev);
+}
+
+static struct comedi_driver dio200_pci_comedi_driver = {
+       .driver_name = "amplc_dio200_pci",
+       .module = THIS_MODULE,
+       .auto_attach = dio200_pci_auto_attach,
+       .detach = dio200_pci_detach,
+};
+
+static DEFINE_PCI_DEVICE_TABLE(dio200_pci_table) = {
+       {
+               PCI_VDEVICE(AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI215),
+               pci215_model
+       }, {
+               PCI_VDEVICE(AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI272),
+               pci272_model
+       }, {
+               PCI_VDEVICE(AMPLICON, PCI_DEVICE_ID_AMPLICON_PCIE236),
+               pcie236_model
+       }, {
+               PCI_VDEVICE(AMPLICON, PCI_DEVICE_ID_AMPLICON_PCIE215),
+               pcie215_model
+       }, {
+               PCI_VDEVICE(AMPLICON, PCI_DEVICE_ID_AMPLICON_PCIE296),
+               pcie296_model
+       },
+       {0}
+};
+
+MODULE_DEVICE_TABLE(pci, dio200_pci_table);
+
+static int dio200_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
+{
+       return comedi_pci_auto_config(dev, &dio200_pci_comedi_driver,
+                                     id->driver_data);
+}
+
+static struct pci_driver dio200_pci_pci_driver = {
+       .name = "amplc_dio200_pci",
+       .id_table = dio200_pci_table,
+       .probe = dio200_pci_probe,
+       .remove = comedi_pci_auto_unconfig,
+};
+module_comedi_pci_driver(dio200_pci_comedi_driver, dio200_pci_pci_driver);
+
+MODULE_AUTHOR("Comedi http://www.comedi.org");
+MODULE_DESCRIPTION("Comedi driver for Amplicon 200 Series PCI(e) DIO boards");
+MODULE_LICENSE("GPL");
index 479e10fddd22e128115f1a5afdf24126c40cbb34..4507f92e15795b344a2a125734885de139bebe91 100644 (file)
@@ -470,12 +470,10 @@ static int pc236_pci_common_attach(struct comedi_device *dev,
 
        comedi_set_hw_dev(dev, &pci_dev->dev);
 
-       ret = comedi_pci_enable(pci_dev, PC236_DRIVER_NAME);
-       if (ret < 0) {
-               dev_err(dev->class_dev,
-                       "error! cannot enable PCI device and request regions!\n");
+       ret = comedi_pci_enable(dev);
+       if (ret)
                return ret;
-       }
+
        devpriv->lcr_iobase = pci_resource_start(pci_dev, 1);
        iobase = pci_resource_start(pci_dev, 2);
        return pc236_common_attach(dev, iobase, pci_dev->irq, IRQF_SHARED);
@@ -576,11 +574,9 @@ static void pc236_detach(struct comedi_device *dev)
                        release_region(dev->iobase, PC236_IO_SIZE);
        } else if (is_pci_board(thisboard)) {
                struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-               if (pcidev) {
-                       if (dev->iobase)
-                               comedi_pci_disable(pcidev);
+               comedi_pci_disable(dev);
+               if (pcidev)
                        pci_dev_put(pcidev);
-               }
        }
 }
 
@@ -610,9 +606,10 @@ static DEFINE_PCI_DEVICE_TABLE(pc236_pci_table) = {
 MODULE_DEVICE_TABLE(pci, pc236_pci_table);
 
 static int amplc_pc236_pci_probe(struct pci_dev *dev,
-                                          const struct pci_device_id *ent)
+                                const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &amplc_pc236_driver);
+       return comedi_pci_auto_config(dev, &amplc_pc236_driver,
+                                     id->driver_data);
 }
 
 static struct pci_driver amplc_pc236_pci_driver = {
index 11c1f4764eacde047a9241755583541675a18575..b8449433eee755111d5f4af93aabecaadc702537 100644 (file)
@@ -249,13 +249,11 @@ static int pc263_pci_common_attach(struct comedi_device *dev,
 
        comedi_set_hw_dev(dev, &pci_dev->dev);
 
-       ret = comedi_pci_enable(pci_dev, PC263_DRIVER_NAME);
-       if (ret < 0) {
-               dev_err(dev->class_dev,
-                       "error! cannot enable PCI device and request regions!\n");
+       ret = comedi_pci_enable(dev);
+       if (ret)
                return ret;
-       }
        iobase = pci_resource_start(pci_dev, 2);
+
        return pc263_common_attach(dev, iobase);
 }
 
@@ -335,11 +333,9 @@ static void pc263_detach(struct comedi_device *dev)
                        release_region(dev->iobase, PC263_IO_SIZE);
        } else if (is_pci_board(thisboard)) {
                struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-               if (pcidev) {
-                       if (dev->iobase)
-                               comedi_pci_disable(pcidev);
+               comedi_pci_disable(dev);
+               if (pcidev)
                        pci_dev_put(pcidev);
-               }
        }
 }
 
@@ -368,10 +364,10 @@ static DEFINE_PCI_DEVICE_TABLE(pc263_pci_table) = {
 MODULE_DEVICE_TABLE(pci, pc263_pci_table);
 
 static int amplc_pc263_pci_probe(struct pci_dev *dev,
-                                                 const struct pci_device_id
-                                                 *ent)
+                                const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &amplc_pc263_driver);
+       return comedi_pci_auto_config(dev, &amplc_pc263_driver,
+                                     id->driver_data);
 }
 
 static struct pci_driver amplc_pc263_pci_driver = {
index c9da4cd74baac16aaec58d6213851157ec9f51e1..4d7eab9b55658c0866a1b2be54d2213be0632a39 100644 (file)
@@ -1280,13 +1280,10 @@ static int pci224_attach_common(struct comedi_device *dev,
 
        comedi_set_hw_dev(dev, &pci_dev->dev);
 
-       ret = comedi_pci_enable(pci_dev, DRIVER_NAME);
-       if (ret < 0) {
-               dev_err(dev->class_dev,
-                       "error! cannot enable PCI device and request regions!\n"
-                       );
+       ret = comedi_pci_enable(dev);
+       if (ret)
                return ret;
-       }
+
        spin_lock_init(&devpriv->ao_spinlock);
 
        devpriv->iobase1 = pci_resource_start(pci_dev, 2);
@@ -1488,11 +1485,9 @@ static void pci224_detach(struct comedi_device *dev)
                kfree(devpriv->ao_scan_vals);
                kfree(devpriv->ao_scan_order);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
+       comedi_pci_disable(dev);
+       if (pcidev)
                pci_dev_put(pcidev);
-       }
 }
 
 static struct comedi_driver amplc_pci224_driver = {
@@ -1507,10 +1502,10 @@ static struct comedi_driver amplc_pci224_driver = {
 };
 
 static int amplc_pci224_pci_probe(struct pci_dev *dev,
-                                                  const struct pci_device_id
-                                                  *ent)
+                                 const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &amplc_pci224_driver);
+       return comedi_pci_auto_config(dev, &amplc_pci224_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(amplc_pci224_pci_table) = {
index e2244c6e536bc27a65d95016f11da3411a576d57..b6e4af444ef5718588178048acc591eb04af75b7 100644 (file)
@@ -2645,12 +2645,11 @@ static int pci230_attach_common(struct comedi_device *dev,
        comedi_set_hw_dev(dev, &pci_dev->dev);
 
        dev->board_name = thisboard->name;
-       /* Enable PCI device and reserve I/O spaces. */
-       if (comedi_pci_enable(pci_dev, "amplc_pci230") < 0) {
-               dev_err(dev->class_dev,
-                       "failed to enable PCI device and request regions\n");
-               return -EIO;
-       }
+
+       rc = comedi_pci_enable(dev);
+       if (rc)
+               return rc;
+
        /* Read base addresses of the PCI230's two I/O regions from PCI
         * configuration register. */
        iobase1 = pci_resource_start(pci_dev, 2);
@@ -2840,11 +2839,9 @@ static void pci230_detach(struct comedi_device *dev)
                subdev_8255_cleanup(dev, &dev->subdevices[2]);
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
+       comedi_pci_disable(dev);
+       if (pcidev)
                pci_dev_put(pcidev);
-       }
 }
 
 static struct comedi_driver amplc_pci230_driver = {
@@ -2859,9 +2856,10 @@ static struct comedi_driver amplc_pci230_driver = {
 };
 
 static int amplc_pci230_pci_probe(struct pci_dev *dev,
-                                           const struct pci_device_id *ent)
+                                 const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &amplc_pci230_driver);
+       return comedi_pci_auto_config(dev, &amplc_pci230_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(amplc_pci230_pci_table) = {
index 79c72118a090bee6f9c96441eb204792e1f40bd0..cdbeb0833d0b8e8e4aad86248c8972326b6732de 100644 (file)
@@ -231,9 +231,19 @@ enum trimpot_model {
        AD8402,
 };
 
+enum cb_pcidas_boardid {
+       BOARD_PCIDAS1602_16,
+       BOARD_PCIDAS1200,
+       BOARD_PCIDAS1602_12,
+       BOARD_PCIDAS1200_JR,
+       BOARD_PCIDAS1602_16_JR,
+       BOARD_PCIDAS1000,
+       BOARD_PCIDAS1001,
+       BOARD_PCIDAS1002,
+};
+
 struct cb_pcidas_board {
        const char *name;
-       unsigned short device_id;
        int ai_nchan;           /*  Inputs in single-ended mode */
        int ai_bits;            /*  analog input resolution */
        int ai_speed;           /*  fastest conversion period in ns */
@@ -248,9 +258,8 @@ struct cb_pcidas_board {
 };
 
 static const struct cb_pcidas_board cb_pcidas_boards[] = {
-       {
+       [BOARD_PCIDAS1602_16] = {
                .name           = "pci-das1602/16",
-               .device_id      = 0x1,
                .ai_nchan       = 16,
                .ai_bits        = 16,
                .ai_speed       = 5000,
@@ -262,9 +271,9 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
                .trimpot        = AD8402,
                .has_dac08      = 1,
                .is_1602        = 1,
-       }, {
+       },
+       [BOARD_PCIDAS1200] = {
                .name           = "pci-das1200",
-               .device_id      = 0xF,
                .ai_nchan       = 16,
                .ai_bits        = 12,
                .ai_speed       = 3200,
@@ -272,9 +281,9 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
                .fifo_size      = 1024,
                .ranges         = &cb_pcidas_ranges,
                .trimpot        = AD7376,
-       }, {
+       },
+       [BOARD_PCIDAS1602_12] = {
                .name           = "pci-das1602/12",
-               .device_id      = 0x10,
                .ai_nchan       = 16,
                .ai_bits        = 12,
                .ai_speed       = 3200,
@@ -285,18 +294,18 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
                .ranges         = &cb_pcidas_ranges,
                .trimpot        = AD7376,
                .is_1602        = 1,
-       }, {
+       },
+       [BOARD_PCIDAS1200_JR] = {
                .name           = "pci-das1200/jr",
-               .device_id      = 0x19,
                .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",
-               .device_id      = 0x1C,
                .ai_nchan       = 16,
                .ai_bits        = 16,
                .ai_speed       = 5000,
@@ -305,18 +314,18 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
                .trimpot        = AD8402,
                .has_dac08      = 1,
                .is_1602        = 1,
-       }, {
+       },
+       [BOARD_PCIDAS1000] = {
                .name           = "pci-das1000",
-               .device_id      = 0x4C,
                .ai_nchan       = 16,
                .ai_bits        = 12,
                .ai_speed       = 4000,
                .fifo_size      = 1024,
                .ranges         = &cb_pcidas_ranges,
                .trimpot        = AD7376,
-       }, {
+       },
+       [BOARD_PCIDAS1001] = {
                .name           = "pci-das1001",
-               .device_id      = 0x1a,
                .ai_nchan       = 16,
                .ai_bits        = 12,
                .ai_speed       = 6800,
@@ -324,9 +333,9 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
                .fifo_size      = 1024,
                .ranges         = &cb_pcidas_alt_ranges,
                .trimpot        = AD7376,
-       }, {
+       },
+       [BOARD_PCIDAS1002] = {
                .name           = "pci-das1002",
-               .device_id      = 0x1b,
                .ai_nchan       = 16,
                .ai_bits        = 12,
                .ai_speed       = 6800,
@@ -1332,7 +1341,7 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
        static const int timeout = 10000;
        unsigned long flags;
 
-       if (dev->attached == 0)
+       if (!dev->attached)
                return IRQ_NONE;
 
        async = s->async;
@@ -1424,31 +1433,18 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
        return IRQ_HANDLED;
 }
 
-static const void *cb_pcidas_find_boardinfo(struct comedi_device *dev,
-                                           struct pci_dev *pcidev)
-{
-       const struct cb_pcidas_board *thisboard;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(cb_pcidas_boards); i++) {
-               thisboard = &cb_pcidas_boards[i];
-               if (thisboard->device_id == pcidev->device)
-                       return thisboard;
-       }
-       return NULL;
-}
-
 static int cb_pcidas_auto_attach(struct comedi_device *dev,
-                                          unsigned long context_unused)
+                                unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct cb_pcidas_board *thisboard;
+       const struct cb_pcidas_board *thisboard = NULL;
        struct cb_pcidas_private *devpriv;
        struct comedi_subdevice *s;
        int i;
        int ret;
 
-       thisboard = cb_pcidas_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(cb_pcidas_boards))
+               thisboard = &cb_pcidas_boards[context];
        if (!thisboard)
                return -ENODEV;
        dev->board_ptr  = thisboard;
@@ -1459,7 +1455,7 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
 
@@ -1603,7 +1599,6 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
 static void cb_pcidas_detach(struct comedi_device *dev)
 {
        struct cb_pcidas_private *devpriv = dev->private;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
        if (devpriv) {
                if (devpriv->s5933_config) {
@@ -1615,10 +1610,7 @@ static void cb_pcidas_detach(struct comedi_device *dev)
                free_irq(dev->irq, dev);
        if (dev->subdevices)
                subdev_8255_cleanup(dev, &dev->subdevices[2]);
-       if (pcidev) {
-               if (devpriv->s5933_config)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver cb_pcidas_driver = {
@@ -1629,20 +1621,21 @@ static struct comedi_driver cb_pcidas_driver = {
 };
 
 static int cb_pcidas_pci_probe(struct pci_dev *dev,
-                                        const struct pci_device_id *ent)
+                              const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &cb_pcidas_driver);
+       return comedi_pci_auto_config(dev, &cb_pcidas_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(cb_pcidas_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0001) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x000f) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0010) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0019) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001c) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x004c) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001a) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001b) },
+       { PCI_VDEVICE(CB, 0x0001), BOARD_PCIDAS1602_16 },
+       { PCI_VDEVICE(CB, 0x000f), BOARD_PCIDAS1200 },
+       { PCI_VDEVICE(CB, 0x0010), BOARD_PCIDAS1602_12 },
+       { PCI_VDEVICE(CB, 0x0019), BOARD_PCIDAS1200_JR },
+       { PCI_VDEVICE(CB, 0x001c), BOARD_PCIDAS1602_16_JR },
+       { PCI_VDEVICE(CB, 0x004c), BOARD_PCIDAS1000 },
+       { PCI_VDEVICE(CB, 0x001a), BOARD_PCIDAS1001 },
+       { PCI_VDEVICE(CB, 0x001b), BOARD_PCIDAS1002 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, cb_pcidas_pci_table);
index 9f3112cb7a21108ad6c18ca2babd0045b491ecb3..6988f5b7fd701996da418929d4ca1809cd88bbc7 100644 (file)
@@ -593,9 +593,39 @@ struct hw_fifo_info {
        uint16_t fifo_size_reg_mask;
 };
 
+enum pcidas64_boardid {
+       BOARD_PCIDAS6402_16,
+       BOARD_PCIDAS6402_12,
+       BOARD_PCIDAS64_M1_16,
+       BOARD_PCIDAS64_M2_16,
+       BOARD_PCIDAS64_M3_16,
+       BOARD_PCIDAS6013,
+       BOARD_PCIDAS6014,
+       BOARD_PCIDAS6023,
+       BOARD_PCIDAS6025,
+       BOARD_PCIDAS6030,
+       BOARD_PCIDAS6031,
+       BOARD_PCIDAS6032,
+       BOARD_PCIDAS6033,
+       BOARD_PCIDAS6034,
+       BOARD_PCIDAS6035,
+       BOARD_PCIDAS6036,
+       BOARD_PCIDAS6040,
+       BOARD_PCIDAS6052,
+       BOARD_PCIDAS6070,
+       BOARD_PCIDAS6071,
+       BOARD_PCIDAS4020_12,
+       BOARD_PCIDAS6402_16_JR,
+       BOARD_PCIDAS64_M1_16_JR,
+       BOARD_PCIDAS64_M2_16_JR,
+       BOARD_PCIDAS64_M3_16_JR,
+       BOARD_PCIDAS64_M1_14,
+       BOARD_PCIDAS64_M2_14,
+       BOARD_PCIDAS64_M3_14,
+};
+
 struct pcidas64_board {
        const char *name;
-       int device_id;          /*  pci device id */
        int ai_se_chans;        /*  number of ai inputs in single-ended mode */
        int ai_bits;            /*  analog input resolution */
        int ai_speed;           /*  fastest conversion period in ns */
@@ -648,421 +678,397 @@ static inline unsigned int ai_dma_ring_count(const struct pcidas64_board *board)
 static const int bytes_in_sample = 2;
 
 static const struct pcidas64_board pcidas64_boards[] = {
-       {
-        .name = "pci-das6402/16",
-        .device_id = 0x1d,
-        .ai_se_chans = 64,
-        .ai_bits = 16,
-        .ai_speed = 5000,
-        .ao_nchan = 2,
-        .ao_bits = 16,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ao_range_table = &ao_ranges_64xx,
-        .ao_range_code = ao_range_code_64xx,
-        .ai_fifo = &ai_fifo_64xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das6402/12",      /*  XXX check */
-        .device_id = 0x1e,
-        .ai_se_chans = 64,
-        .ai_bits = 12,
-        .ai_speed = 5000,
-        .ao_nchan = 2,
-        .ao_bits = 12,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ao_range_table = &ao_ranges_64xx,
-        .ao_range_code = ao_range_code_64xx,
-        .ai_fifo = &ai_fifo_64xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das64/m1/16",
-        .device_id = 0x35,
-        .ai_se_chans = 64,
-        .ai_bits = 16,
-        .ai_speed = 1000,
-        .ao_nchan = 2,
-        .ao_bits = 16,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ao_range_table = &ao_ranges_64xx,
-        .ao_range_code = ao_range_code_64xx,
-        .ai_fifo = &ai_fifo_64xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das64/m2/16",
-        .device_id = 0x36,
-        .ai_se_chans = 64,
-        .ai_bits = 16,
-        .ai_speed = 500,
-        .ao_nchan = 2,
-        .ao_bits = 16,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ao_range_table = &ao_ranges_64xx,
-        .ao_range_code = ao_range_code_64xx,
-        .ai_fifo = &ai_fifo_64xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das64/m3/16",
-        .device_id = 0x37,
-        .ai_se_chans = 64,
-        .ai_bits = 16,
-        .ai_speed = 333,
-        .ao_nchan = 2,
-        .ao_bits = 16,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ao_range_table = &ao_ranges_64xx,
-        .ao_range_code = ao_range_code_64xx,
-        .ai_fifo = &ai_fifo_64xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das6013",
-        .device_id = 0x78,
-        .ai_se_chans = 16,
-        .ai_bits = 16,
-        .ai_speed = 5000,
-        .ao_nchan = 0,
-        .ao_bits = 16,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_60xx,
-        .ao_range_table = &ao_ranges_60xx,
-        .ao_range_code = ao_range_code_60xx,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6014",
-        .device_id = 0x79,
-        .ai_se_chans = 16,
-        .ai_bits = 16,
-        .ai_speed = 5000,
-        .ao_nchan = 2,
-        .ao_bits = 16,
-        .ao_scan_speed = 100000,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_60xx,
-        .ao_range_table = &ao_ranges_60xx,
-        .ao_range_code = ao_range_code_60xx,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6023",
-        .device_id = 0x5d,
-        .ai_se_chans = 16,
-        .ai_bits = 12,
-        .ai_speed = 5000,
-        .ao_nchan = 0,
-        .ao_scan_speed = 100000,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_60xx,
-        .ao_range_table = &ao_ranges_60xx,
-        .ao_range_code = ao_range_code_60xx,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das6025",
-        .device_id = 0x5e,
-        .ai_se_chans = 16,
-        .ai_bits = 12,
-        .ai_speed = 5000,
-        .ao_nchan = 2,
-        .ao_bits = 12,
-        .ao_scan_speed = 100000,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_60xx,
-        .ao_range_table = &ao_ranges_60xx,
-        .ao_range_code = ao_range_code_60xx,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das6030",
-        .device_id = 0x5f,
-        .ai_se_chans = 16,
-        .ai_bits = 16,
-        .ai_speed = 10000,
-        .ao_nchan = 2,
-        .ao_bits = 16,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_6030,
-        .ao_range_table = &ao_ranges_6030,
-        .ao_range_code = ao_range_code_6030,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6031",
-        .device_id = 0x60,
-        .ai_se_chans = 64,
-        .ai_bits = 16,
-        .ai_speed = 10000,
-        .ao_nchan = 2,
-        .ao_bits = 16,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_6030,
-        .ao_range_table = &ao_ranges_6030,
-        .ao_range_code = ao_range_code_6030,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6032",
-        .device_id = 0x61,
-        .ai_se_chans = 16,
-        .ai_bits = 16,
-        .ai_speed = 10000,
-        .ao_nchan = 0,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_6030,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6033",
-        .device_id = 0x62,
-        .ai_se_chans = 64,
-        .ai_bits = 16,
-        .ai_speed = 10000,
-        .ao_nchan = 0,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_6030,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6034",
-        .device_id = 0x63,
-        .ai_se_chans = 16,
-        .ai_bits = 16,
-        .ai_speed = 5000,
-        .ao_nchan = 0,
-        .ao_scan_speed = 0,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_60xx,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6035",
-        .device_id = 0x64,
-        .ai_se_chans = 16,
-        .ai_bits = 16,
-        .ai_speed = 5000,
-        .ao_nchan = 2,
-        .ao_bits = 12,
-        .ao_scan_speed = 100000,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_60xx,
-        .ao_range_table = &ao_ranges_60xx,
-        .ao_range_code = ao_range_code_60xx,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6036",
-        .device_id = 0x6f,
-        .ai_se_chans = 16,
-        .ai_bits = 16,
-        .ai_speed = 5000,
-        .ao_nchan = 2,
-        .ao_bits = 16,
-        .ao_scan_speed = 100000,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_60xx,
-        .ao_range_table = &ao_ranges_60xx,
-        .ao_range_code = ao_range_code_60xx,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6040",
-        .device_id = 0x65,
-        .ai_se_chans = 16,
-        .ai_bits = 12,
-        .ai_speed = 2000,
-        .ao_nchan = 2,
-        .ao_bits = 12,
-        .ao_scan_speed = 1000,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_6052,
-        .ao_range_table = &ao_ranges_6030,
-        .ao_range_code = ao_range_code_6030,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6052",
-        .device_id = 0x66,
-        .ai_se_chans = 16,
-        .ai_bits = 16,
-        .ai_speed = 3333,
-        .ao_nchan = 2,
-        .ao_bits = 16,
-        .ao_scan_speed = 3333,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_6052,
-        .ao_range_table = &ao_ranges_6030,
-        .ao_range_code = ao_range_code_6030,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6070",
-        .device_id = 0x67,
-        .ai_se_chans = 16,
-        .ai_bits = 12,
-        .ai_speed = 800,
-        .ao_nchan = 2,
-        .ao_bits = 12,
-        .ao_scan_speed = 1000,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_6052,
-        .ao_range_table = &ao_ranges_6030,
-        .ao_range_code = ao_range_code_6030,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das6071",
-        .device_id = 0x68,
-        .ai_se_chans = 64,
-        .ai_bits = 12,
-        .ai_speed = 800,
-        .ao_nchan = 2,
-        .ao_bits = 12,
-        .ao_scan_speed = 1000,
-        .layout = LAYOUT_60XX,
-        .ai_range_table = &ai_ranges_6052,
-        .ao_range_table = &ao_ranges_6030,
-        .ao_range_code = ao_range_code_6030,
-        .ai_fifo = &ai_fifo_60xx,
-        .has_8255 = 0,
-        },
-       {
-        .name = "pci-das4020/12",
-        .device_id = 0x52,
-        .ai_se_chans = 4,
-        .ai_bits = 12,
-        .ai_speed = 50,
-        .ao_bits = 12,
-        .ao_nchan = 2,
-        .ao_scan_speed = 0,    /*  no hardware pacing on ao */
-        .layout = LAYOUT_4020,
-        .ai_range_table = &ai_ranges_4020,
-        .ao_range_table = &ao_ranges_4020,
-        .ao_range_code = ao_range_code_4020,
-        .ai_fifo = &ai_fifo_4020,
-        .has_8255 = 1,
-        },
+       [BOARD_PCIDAS6402_16] = {
+               .name           = "pci-das6402/16",
+               .ai_se_chans    = 64,
+               .ai_bits        = 16,
+               .ai_speed       = 5000,
+               .ao_nchan       = 2,
+               .ao_bits        = 16,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ao_range_table = &ao_ranges_64xx,
+               .ao_range_code  = ao_range_code_64xx,
+               .ai_fifo        = &ai_fifo_64xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS6402_12] = {
+               .name           = "pci-das6402/12",     /*  XXX check */
+               .ai_se_chans    = 64,
+               .ai_bits        = 12,
+               .ai_speed       = 5000,
+               .ao_nchan       = 2,
+               .ao_bits        = 12,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ao_range_table = &ao_ranges_64xx,
+               .ao_range_code  = ao_range_code_64xx,
+               .ai_fifo        = &ai_fifo_64xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS64_M1_16] = {
+               .name           = "pci-das64/m1/16",
+               .ai_se_chans    = 64,
+               .ai_bits        = 16,
+               .ai_speed       = 1000,
+               .ao_nchan       = 2,
+               .ao_bits        = 16,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ao_range_table = &ao_ranges_64xx,
+               .ao_range_code  = ao_range_code_64xx,
+               .ai_fifo        = &ai_fifo_64xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS64_M2_16] = {
+               .name = "pci-das64/m2/16",
+               .ai_se_chans    = 64,
+               .ai_bits        = 16,
+               .ai_speed       = 500,
+               .ao_nchan       = 2,
+               .ao_bits        = 16,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ao_range_table = &ao_ranges_64xx,
+               .ao_range_code  = ao_range_code_64xx,
+               .ai_fifo        = &ai_fifo_64xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS64_M3_16] = {
+               .name           = "pci-das64/m3/16",
+               .ai_se_chans    = 64,
+               .ai_bits        = 16,
+               .ai_speed       = 333,
+               .ao_nchan       = 2,
+               .ao_bits        = 16,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ao_range_table = &ao_ranges_64xx,
+               .ao_range_code  = ao_range_code_64xx,
+               .ai_fifo        = &ai_fifo_64xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS6013] = {
+               .name           = "pci-das6013",
+               .ai_se_chans    = 16,
+               .ai_bits        = 16,
+               .ai_speed       = 5000,
+               .ao_nchan       = 0,
+               .ao_bits        = 16,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_60xx,
+               .ao_range_table = &ao_ranges_60xx,
+               .ao_range_code  = ao_range_code_60xx,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6014] = {
+               .name           = "pci-das6014",
+               .ai_se_chans    = 16,
+               .ai_bits        = 16,
+               .ai_speed       = 5000,
+               .ao_nchan       = 2,
+               .ao_bits        = 16,
+               .ao_scan_speed  = 100000,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_60xx,
+               .ao_range_table = &ao_ranges_60xx,
+               .ao_range_code  = ao_range_code_60xx,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6023] = {
+               .name           = "pci-das6023",
+               .ai_se_chans    = 16,
+               .ai_bits        = 12,
+               .ai_speed       = 5000,
+               .ao_nchan       = 0,
+               .ao_scan_speed  = 100000,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_60xx,
+               .ao_range_table = &ao_ranges_60xx,
+               .ao_range_code  = ao_range_code_60xx,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS6025] = {
+               .name           = "pci-das6025",
+               .ai_se_chans    = 16,
+               .ai_bits        = 12,
+               .ai_speed       = 5000,
+               .ao_nchan       = 2,
+               .ao_bits        = 12,
+               .ao_scan_speed  = 100000,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_60xx,
+               .ao_range_table = &ao_ranges_60xx,
+               .ao_range_code  = ao_range_code_60xx,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS6030] = {
+               .name           = "pci-das6030",
+               .ai_se_chans    = 16,
+               .ai_bits        = 16,
+               .ai_speed       = 10000,
+               .ao_nchan       = 2,
+               .ao_bits        = 16,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_6030,
+               .ao_range_table = &ao_ranges_6030,
+               .ao_range_code  = ao_range_code_6030,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6031] = {
+               .name           = "pci-das6031",
+               .ai_se_chans    = 64,
+               .ai_bits        = 16,
+               .ai_speed       = 10000,
+               .ao_nchan       = 2,
+               .ao_bits        = 16,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_6030,
+               .ao_range_table = &ao_ranges_6030,
+               .ao_range_code  = ao_range_code_6030,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6032] = {
+               .name           = "pci-das6032",
+               .ai_se_chans    = 16,
+               .ai_bits        = 16,
+               .ai_speed       = 10000,
+               .ao_nchan       = 0,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_6030,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6033] = {
+               .name           = "pci-das6033",
+               .ai_se_chans    = 64,
+               .ai_bits        = 16,
+               .ai_speed       = 10000,
+               .ao_nchan       = 0,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_6030,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6034] = {
+               .name           = "pci-das6034",
+               .ai_se_chans    = 16,
+               .ai_bits        = 16,
+               .ai_speed       = 5000,
+               .ao_nchan       = 0,
+               .ao_scan_speed  = 0,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_60xx,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6035] = {
+               .name           = "pci-das6035",
+               .ai_se_chans    = 16,
+               .ai_bits        = 16,
+               .ai_speed       = 5000,
+               .ao_nchan       = 2,
+               .ao_bits        = 12,
+               .ao_scan_speed  = 100000,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_60xx,
+               .ao_range_table = &ao_ranges_60xx,
+               .ao_range_code  = ao_range_code_60xx,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6036] = {
+               .name           = "pci-das6036",
+               .ai_se_chans    = 16,
+               .ai_bits        = 16,
+               .ai_speed       = 5000,
+               .ao_nchan       = 2,
+               .ao_bits        = 16,
+               .ao_scan_speed  = 100000,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_60xx,
+               .ao_range_table = &ao_ranges_60xx,
+               .ao_range_code  = ao_range_code_60xx,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6040] = {
+               .name           = "pci-das6040",
+               .ai_se_chans    = 16,
+               .ai_bits        = 12,
+               .ai_speed       = 2000,
+               .ao_nchan       = 2,
+               .ao_bits        = 12,
+               .ao_scan_speed  = 1000,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_6052,
+               .ao_range_table = &ao_ranges_6030,
+               .ao_range_code  = ao_range_code_6030,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6052] = {
+               .name           = "pci-das6052",
+               .ai_se_chans    = 16,
+               .ai_bits        = 16,
+               .ai_speed       = 3333,
+               .ao_nchan       = 2,
+               .ao_bits        = 16,
+               .ao_scan_speed  = 3333,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_6052,
+               .ao_range_table = &ao_ranges_6030,
+               .ao_range_code  = ao_range_code_6030,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6070] = {
+               .name           = "pci-das6070",
+               .ai_se_chans    = 16,
+               .ai_bits        = 12,
+               .ai_speed       = 800,
+               .ao_nchan       = 2,
+               .ao_bits        = 12,
+               .ao_scan_speed  = 1000,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_6052,
+               .ao_range_table = &ao_ranges_6030,
+               .ao_range_code  = ao_range_code_6030,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS6071] = {
+               .name           = "pci-das6071",
+               .ai_se_chans    = 64,
+               .ai_bits        = 12,
+               .ai_speed       = 800,
+               .ao_nchan       = 2,
+               .ao_bits        = 12,
+               .ao_scan_speed  = 1000,
+               .layout         = LAYOUT_60XX,
+               .ai_range_table = &ai_ranges_6052,
+               .ao_range_table = &ao_ranges_6030,
+               .ao_range_code  = ao_range_code_6030,
+               .ai_fifo        = &ai_fifo_60xx,
+               .has_8255       = 0,
+       },
+       [BOARD_PCIDAS4020_12] = {
+               .name           = "pci-das4020/12",
+               .ai_se_chans    = 4,
+               .ai_bits        = 12,
+               .ai_speed       = 50,
+               .ao_bits        = 12,
+               .ao_nchan       = 2,
+               .ao_scan_speed  = 0,    /*  no hardware pacing on ao */
+               .layout         = LAYOUT_4020,
+               .ai_range_table = &ai_ranges_4020,
+               .ao_range_table = &ao_ranges_4020,
+               .ao_range_code  = ao_range_code_4020,
+               .ai_fifo        = &ai_fifo_4020,
+               .has_8255       = 1,
+       },
 #if 0
-       {
-        .name = "pci-das6402/16/jr",
-        .device_id = 0         /*  XXX, */
-        .ai_se_chans = 64,
-        .ai_bits = 16,
-        .ai_speed = 5000,
-        .ao_nchan = 0,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ai_fifo = ai_fifo_64xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das64/m1/16/jr",
-        .device_id = 0         /*  XXX, */
-        .ai_se_chans = 64,
-        .ai_bits = 16,
-        .ai_speed = 1000,
-        .ao_nchan = 0,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ai_fifo = ai_fifo_64xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das64/m2/16/jr",
-        .device_id = 0         /*  XXX, */
-        .ai_se_chans = 64,
-        .ai_bits = 16,
-        .ai_speed = 500,
-        .ao_nchan = 0,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ai_fifo = ai_fifo_64xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das64/m3/16/jr",
-        .device_id = 0         /*  XXX, */
-        .ai_se_chans = 64,
-        .ai_bits = 16,
-        .ai_speed = 333,
-        .ao_nchan = 0,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ai_fifo = ai_fifo_64xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das64/m1/14",
-        .device_id = 0,        /*  XXX */
-        .ai_se_chans = 64,
-        .ai_bits = 14,
-        .ai_speed = 1000,
-        .ao_nchan = 2,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ai_fifo = ai_fifo_64xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das64/m2/14",
-        .device_id = 0,        /*  XXX */
-        .ai_se_chans = 64,
-        .ai_bits = 14,
-        .ai_speed = 500,
-        .ao_nchan = 2,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ai_fifo = ai_fifo_64xx,
-        .has_8255 = 1,
-        },
-       {
-        .name = "pci-das64/m3/14",
-        .device_id = 0,        /*  XXX */
-        .ai_se_chans = 64,
-        .ai_bits = 14,
-        .ai_speed = 333,
-        .ao_nchan = 2,
-        .ao_scan_speed = 10000,
-        .layout = LAYOUT_64XX,
-        .ai_range_table = &ai_ranges_64xx,
-        .ai_fifo = ai_fifo_64xx,
-        .has_8255 = 1,
-        },
+       /*
+        * The device id for these boards is unknown
+        */
+
+       [BOARD_PCIDAS6402_16_JR] = {
+               .name           = "pci-das6402/16/jr",
+               .ai_se_chans    = 64,
+               .ai_bits        = 16,
+               .ai_speed       = 5000,
+               .ao_nchan       = 0,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ai_fifo        = ai_fifo_64xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS64_M1_16_JR] = {
+               .name           = "pci-das64/m1/16/jr",
+               .ai_se_chans    = 64,
+               .ai_bits        = 16,
+               .ai_speed       = 1000,
+               .ao_nchan       = 0,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ai_fifo        = ai_fifo_64xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS64_M2_16_JR] = {
+               .name = "pci-das64/m2/16/jr",
+               .ai_se_chans    = 64,
+               .ai_bits        = 16,
+               .ai_speed       = 500,
+               .ao_nchan       = 0,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ai_fifo        = ai_fifo_64xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS64_M3_16_JR] = {
+               .name           = "pci-das64/m3/16/jr",
+               .ai_se_chans    = 64,
+               .ai_bits        = 16,
+               .ai_speed       = 333,
+               .ao_nchan       = 0,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ai_fifo        = ai_fifo_64xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS64_M1_14] = {
+               .name           = "pci-das64/m1/14",
+               .ai_se_chans    = 64,
+               .ai_bits        = 14,
+               .ai_speed       = 1000,
+               .ao_nchan       = 2,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ai_fifo        = ai_fifo_64xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS64_M2_14] = {
+               .name           = "pci-das64/m2/14",
+               .ai_se_chans    = 64,
+               .ai_bits        = 14,
+               .ai_speed       = 500,
+               .ao_nchan       = 2,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ai_fifo        = ai_fifo_64xx,
+               .has_8255       = 1,
+       },
+       [BOARD_PCIDAS64_M3_14] = {
+               .name           = "pci-das64/m3/14",
+               .ai_se_chans    = 64,
+               .ai_bits        = 14,
+               .ai_speed       = 333,
+               .ao_nchan       = 2,
+               .ao_scan_speed  = 10000,
+               .layout         = LAYOUT_64XX,
+               .ai_range_table = &ai_ranges_64xx,
+               .ai_fifo        = ai_fifo_64xx,
+               .has_8255       = 1,
+       },
 #endif
 };
 
@@ -1523,7 +1529,7 @@ static int alloc_and_init_dma_members(struct comedi_device *dev)
        struct pcidas64_private *devpriv = dev->private;
        int i;
 
-       /*  alocate pci dma buffers */
+       /*  allocate pci dma buffers */
        for (i = 0; i < ai_dma_ring_count(thisboard); i++) {
                devpriv->ai_buffer[i] =
                        pci_alloc_consistent(pcidev, DMA_BUFFER_SIZE,
@@ -3107,7 +3113,7 @@ static irqreturn_t handle_interrupt(int irq, void *d)
        /* an interrupt before all the postconfig stuff gets done could
         * cause a NULL dereference if we continue through the
         * interrupt handler */
-       if (dev->attached == 0) {
+       if (!dev->attached) {
                DEBUG_PRINT("premature interrupt, ignoring\n");
                return IRQ_HANDLED;
        }
@@ -4033,45 +4039,29 @@ static int setup_subdevices(struct comedi_device *dev)
        return 0;
 }
 
-static const struct pcidas64_board
-*cb_pcidas64_find_pci_board(struct pci_dev *pcidev)
-{
-       unsigned int i;
-
-       for (i = 0; i < ARRAY_SIZE(pcidas64_boards); i++)
-               if (pcidev->device == pcidas64_boards[i].device_id)
-                       return &pcidas64_boards[i];
-       return NULL;
-}
-
 static int auto_attach(struct comedi_device *dev,
-                                unsigned long context_unused)
+                      unsigned long context)
 {
-       const struct pcidas64_board *thisboard;
-       struct pcidas64_private *devpriv;
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+       const struct pcidas64_board *thisboard = NULL;
+       struct pcidas64_private *devpriv;
        uint32_t local_range, local_decode;
        int retval;
 
-       dev->board_ptr = cb_pcidas64_find_pci_board(pcidev);
-       if (!dev->board_ptr) {
-               dev_err(dev->class_dev,
-                       "cb_pcidas64: does not support pci %s\n",
-                       pci_name(pcidev));
-               return -EINVAL;
-       }
-       thisboard = comedi_board(dev);
+       if (context < ARRAY_SIZE(pcidas64_boards))
+               thisboard = &pcidas64_boards[context];
+       if (!thisboard)
+               return -ENODEV;
+       dev->board_ptr = thisboard;
 
        devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
        if (!devpriv)
                return -ENOMEM;
        dev->private = devpriv;
 
-       if (comedi_pci_enable(pcidev, dev->driver->driver_name)) {
-               dev_warn(dev->class_dev,
-                        "failed to enable PCI device and request regions\n");
-               return -EIO;
-       }
+       retval = comedi_pci_enable(dev);
+       if (retval)
+               return retval;
        pci_set_master(pcidev);
 
        /* Initialize dev->board_name */
@@ -4202,10 +4192,7 @@ static void detach(struct comedi_device *dev)
        }
        if (dev->subdevices)
                subdev_8255_cleanup(dev, &dev->subdevices[4]);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver cb_pcidas64_driver = {
@@ -4216,31 +4203,34 @@ static struct comedi_driver cb_pcidas64_driver = {
 };
 
 static int cb_pcidas64_pci_probe(struct pci_dev *dev,
-                                          const struct pci_device_id *ent)
+                                const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &cb_pcidas64_driver);
+       return comedi_pci_auto_config(dev, &cb_pcidas64_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(cb_pcidas64_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001d) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001e) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0035) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0036) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0037) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0052) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x005d) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x005e) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x005f) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0061) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0062) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0063) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0064) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0066) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0067) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0068) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x006f) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0078) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0079) },
+       { PCI_VDEVICE(CB, 0x001d), BOARD_PCIDAS6402_16 },
+       { PCI_VDEVICE(CB, 0x001e), BOARD_PCIDAS6402_12 },
+       { PCI_VDEVICE(CB, 0x0035), BOARD_PCIDAS64_M1_16 },
+       { PCI_VDEVICE(CB, 0x0036), BOARD_PCIDAS64_M2_16 },
+       { PCI_VDEVICE(CB, 0x0037), BOARD_PCIDAS64_M3_16 },
+       { PCI_VDEVICE(CB, 0x0052), BOARD_PCIDAS4020_12 },
+       { PCI_VDEVICE(CB, 0x005d), BOARD_PCIDAS6023 },
+       { PCI_VDEVICE(CB, 0x005e), BOARD_PCIDAS6025 },
+       { PCI_VDEVICE(CB, 0x005f), BOARD_PCIDAS6030 },
+       { PCI_VDEVICE(CB, 0x0060), BOARD_PCIDAS6031 },
+       { PCI_VDEVICE(CB, 0x0061), BOARD_PCIDAS6032 },
+       { PCI_VDEVICE(CB, 0x0062), BOARD_PCIDAS6033 },
+       { PCI_VDEVICE(CB, 0x0063), BOARD_PCIDAS6034 },
+       { PCI_VDEVICE(CB, 0x0064), BOARD_PCIDAS6035 },
+       { PCI_VDEVICE(CB, 0x0065), BOARD_PCIDAS6040 },
+       { PCI_VDEVICE(CB, 0x0066), BOARD_PCIDAS6052 },
+       { PCI_VDEVICE(CB, 0x0067), BOARD_PCIDAS6070 },
+       { PCI_VDEVICE(CB, 0x0068), BOARD_PCIDAS6071 },
+       { PCI_VDEVICE(CB, 0x006f), BOARD_PCIDAS6036 },
+       { PCI_VDEVICE(CB, 0x0078), BOARD_PCIDAS6013 },
+       { PCI_VDEVICE(CB, 0x0079), BOARD_PCIDAS6014 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, cb_pcidas64_pci_table);
index e2cadc728455def81c67ed5cbf717d04d85ae29d..2da6bd663affc4869e4118331c3c46e892792f4e 100644 (file)
 #include "comedi_fc.h"
 #include "8255.h"
 
-/*
- * ComputerBoards PCI Device ID's supported by this driver
- */
-#define PCI_DEVICE_ID_DDA02_12         0x0020
-#define PCI_DEVICE_ID_DDA04_12         0x0021
-#define PCI_DEVICE_ID_DDA08_12         0x0022
-#define PCI_DEVICE_ID_DDA02_16         0x0023
-#define PCI_DEVICE_ID_DDA04_16         0x0024
-#define PCI_DEVICE_ID_DDA08_16         0x0025
-
 #define EEPROM_SIZE    128     /*  number of entries in eeprom */
 /* maximum number of ao channels for supported boards */
 #define MAX_AO_CHANNELS 8
@@ -118,42 +108,49 @@ static const struct comedi_lrange cb_pcidda_ranges = {
        }
 };
 
+enum cb_pcidda_boardid {
+       BOARD_DDA02_12,
+       BOARD_DDA04_12,
+       BOARD_DDA08_12,
+       BOARD_DDA02_16,
+       BOARD_DDA04_16,
+       BOARD_DDA08_16,
+};
+
 struct cb_pcidda_board {
        const char *name;
-       unsigned short device_id;
        int ao_chans;
        int ao_bits;
 };
 
 static const struct cb_pcidda_board cb_pcidda_boards[] = {
-       {
+       [BOARD_DDA02_12] = {
                .name           = "pci-dda02/12",
-               .device_id      = PCI_DEVICE_ID_DDA02_12,
                .ao_chans       = 2,
                .ao_bits        = 12,
-       }, {
+       },
+       [BOARD_DDA04_12] = {
                .name           = "pci-dda04/12",
-               .device_id      = PCI_DEVICE_ID_DDA04_12,
                .ao_chans       = 4,
                .ao_bits        = 12,
-       }, {
+       },
+       [BOARD_DDA08_12] = {
                .name           = "pci-dda08/12",
-               .device_id      = PCI_DEVICE_ID_DDA08_12,
                .ao_chans       = 8,
                .ao_bits        = 12,
-       }, {
+       },
+       [BOARD_DDA02_16] = {
                .name           = "pci-dda02/16",
-               .device_id      = PCI_DEVICE_ID_DDA02_16,
                .ao_chans       = 2,
                .ao_bits        = 16,
-       }, {
+       },
+       [BOARD_DDA04_16] = {
                .name           = "pci-dda04/16",
-               .device_id      = PCI_DEVICE_ID_DDA04_16,
                .ao_chans       = 4,
                .ao_bits        = 16,
-       }, {
+       },
+       [BOARD_DDA08_16] = {
                .name           = "pci-dda08/16",
-               .device_id      = PCI_DEVICE_ID_DDA08_16,
                .ao_chans       = 8,
                .ao_bits        = 16,
        },
@@ -337,32 +334,19 @@ static int cb_pcidda_ao_insn_write(struct comedi_device *dev,
        return insn->n;
 }
 
-static const void *cb_pcidda_find_boardinfo(struct comedi_device *dev,
-                                           struct pci_dev *pcidev)
-{
-       const struct cb_pcidda_board *thisboard;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(cb_pcidda_boards); i++) {
-               thisboard = &cb_pcidda_boards[i];
-               if (thisboard->device_id != pcidev->device)
-                       return thisboard;
-       }
-       return NULL;
-}
-
 static int cb_pcidda_auto_attach(struct comedi_device *dev,
-                                          unsigned long context_unused)
+                                unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct cb_pcidda_board *thisboard;
+       const struct cb_pcidda_board *thisboard = NULL;
        struct cb_pcidda_private *devpriv;
        struct comedi_subdevice *s;
        unsigned long iobase_8255;
        int i;
        int ret;
 
-       thisboard = cb_pcidda_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(cb_pcidda_boards))
+               thisboard = &cb_pcidda_boards[context];
        if (!thisboard)
                return -ENODEV;
        dev->board_ptr = thisboard;
@@ -373,7 +357,7 @@ static int cb_pcidda_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 3);
@@ -415,16 +399,11 @@ static int cb_pcidda_auto_attach(struct comedi_device *dev,
 
 static void cb_pcidda_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->subdevices) {
                subdev_8255_cleanup(dev, &dev->subdevices[1]);
                subdev_8255_cleanup(dev, &dev->subdevices[2]);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver cb_pcidda_driver = {
@@ -435,18 +414,19 @@ static struct comedi_driver cb_pcidda_driver = {
 };
 
 static int cb_pcidda_pci_probe(struct pci_dev *dev,
-                                        const struct pci_device_id *ent)
+                              const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &cb_pcidda_driver);
+       return comedi_pci_auto_config(dev, &cb_pcidda_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(cb_pcidda_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA02_12) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA04_12) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA08_12) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA02_16) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA04_16) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA08_16) },
+       { PCI_VDEVICE(CB, 0x0020), BOARD_DDA02_12 },
+       { PCI_VDEVICE(CB, 0x0021), BOARD_DDA04_12 },
+       { PCI_VDEVICE(CB, 0x0022), BOARD_DDA08_12 },
+       { PCI_VDEVICE(CB, 0x0023), BOARD_DDA02_16 },
+       { PCI_VDEVICE(CB, 0x0024), BOARD_DDA04_16 },
+       { PCI_VDEVICE(CB, 0x0025), BOARD_DDA08_16 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, cb_pcidda_pci_table);
index aae063ca85a0d6e93c7489a4e48ff91dc4a6a865..f6d99a3a972e404b4c4dde01999f60fa5a43e9ce 100644 (file)
@@ -222,7 +222,7 @@ static int cb_pcimdas_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
 
@@ -277,14 +277,9 @@ static int cb_pcimdas_auto_attach(struct comedi_device *dev,
 
 static void cb_pcimdas_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver cb_pcimdas_driver = {
@@ -295,9 +290,10 @@ static struct comedi_driver cb_pcimdas_driver = {
 };
 
 static int cb_pcimdas_pci_probe(struct pci_dev *dev,
-                                         const struct pci_device_id *ent)
+                               const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &cb_pcimdas_driver);
+       return comedi_pci_auto_config(dev, &cb_pcimdas_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(cb_pcimdas_pci_table) = {
index 63cfbaf3a3fe7086992776f3ddb4c83060dc4fae..d00f7f629d36fc8ab7f5d203792f8eb5b5344e10 100644 (file)
@@ -168,7 +168,7 @@ static int cb_pcimdda_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 3);
@@ -201,14 +201,9 @@ static int cb_pcimdda_auto_attach(struct comedi_device *dev,
 
 static void cb_pcimdda_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->subdevices)
                subdev_8255_cleanup(dev, &dev->subdevices[1]);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver cb_pcimdda_driver = {
@@ -219,9 +214,10 @@ static struct comedi_driver cb_pcimdda_driver = {
 };
 
 static int cb_pcimdda_pci_probe(struct pci_dev *dev,
-                                         const struct pci_device_id *ent)
+                               const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &cb_pcimdda_driver);
+       return comedi_pci_auto_config(dev, &cb_pcimdda_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(cb_pcimdda_pci_table) = {
index 182dea669ef2a9e15ab394cd4628577410bf60c7..da0be62aef600097abd09d0efe983eeb31a52b60 100644 (file)
@@ -79,7 +79,7 @@ static int contec_auto_attach(struct comedi_device *dev,
 
        dev->board_name = dev->driver->driver_name;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 0);
@@ -109,27 +109,18 @@ static int contec_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void contec_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver contec_pci_dio_driver = {
        .driver_name    = "contec_pci_dio",
        .module         = THIS_MODULE,
        .auto_attach    = contec_auto_attach,
-       .detach         = contec_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int contec_pci_dio_pci_probe(struct pci_dev *dev,
-                                             const struct pci_device_id *ent)
+                                   const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &contec_pci_dio_driver);
+       return comedi_pci_auto_config(dev, &contec_pci_dio_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(contec_pci_dio_pci_table) = {
index 50b450f09c65af41008f4dd2485cada668371010..a0ec8bd5c01d32d725db63bea3f966b9156ae80f 100644 (file)
@@ -709,10 +709,9 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       result = comedi_pci_enable(pcidev, dev->driver->driver_name);
-       if (result < 0)
+       result = comedi_pci_enable(dev);
+       if (result)
                return result;
-       dev->iobase = 1;        /* the "detach" needs this */
 
        devpriv->plx = ioremap(pci_resource_start(pcidev, 0),
                               pci_resource_len(pcidev, 0));
@@ -767,7 +766,6 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
 
 static void daqboard2000_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct daqboard2000_private *devpriv = dev->private;
 
        if (dev->subdevices)
@@ -780,11 +778,7 @@ static void daqboard2000_detach(struct comedi_device *dev)
                if (devpriv->plx)
                        iounmap(devpriv->plx);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-               pci_dev_put(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver daqboard2000_driver = {
@@ -795,9 +789,10 @@ static struct comedi_driver daqboard2000_driver = {
 };
 
 static int daqboard2000_pci_probe(struct pci_dev *dev,
-                                           const struct pci_device_id *ent)
+                                 const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &daqboard2000_driver);
+       return comedi_pci_auto_config(dev, &daqboard2000_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(daqboard2000_pci_table) = {
index b102ad4918c465627d513db9d4e50cdcdcec506e..89bb8d6fdfc66fdd5816d4e357a2e3bcabc3fb4e 100644 (file)
@@ -32,7 +32,6 @@ enum das08_lrange { das08_pg_none, das08_bipolar5, das08_pgh, das08_pgl,
 
 struct das08_board_struct {
        const char *name;
-       unsigned int id;        /*  id for pci/pcmcia boards */
        bool is_jr;             /* true for 'JR' boards */
        unsigned int ai_nbits;
        enum das08_lrange ai_pg;
index cfeebe4d1ddda851136250231f5f398d89037e99..d9f3e92317d3a2b5f1f318089b0f0d38a8d9e59a 100644 (file)
@@ -59,7 +59,6 @@ Command support does not exist, but could be added for this board.
 static const struct das08_board_struct das08_cs_boards[] = {
        {
                .name           = "pcm-das08",
-               .id             = 0x0,  /*  XXX */
                .ai_nbits       = 12,
                .ai_pg          = das08_bipolar5,
                .ai_encoding    = das08_pcm_encode12,
index c405876ddcf7e21d25d93c6de196592261e099e8..53fa943dd0b7038393c6d58bbe81754c32a892f5 100644 (file)
@@ -46,7 +46,6 @@
 static const struct das08_board_struct das08_pci_boards[] = {
        {
                .name           = "pci-das08",
-               .id             = PCI_DEVICE_ID_PCIDAS08,
                .ai_nbits       = 12,
                .ai_pg          = das08_bipolar5,
                .ai_encoding    = das08_encode12,
@@ -72,7 +71,7 @@ static int das08_pci_auto_attach(struct comedi_device *dev,
        /* The das08 driver needs the board_ptr */
        dev->board_ptr = &das08_pci_boards[0];
 
-       ret = comedi_pci_enable(pdev, dev->driver->driver_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pdev, 2);
@@ -82,11 +81,8 @@ static int das08_pci_auto_attach(struct comedi_device *dev,
 
 static void das08_pci_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pdev = comedi_to_pci_dev(dev);
-
        das08_common_detach(dev);
-       if (dev->iobase)
-               comedi_pci_disable(pdev);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver das08_pci_comedi_driver = {
@@ -97,9 +93,10 @@ static struct comedi_driver das08_pci_comedi_driver = {
 };
 
 static int das08_pci_probe(struct pci_dev *dev,
-                          const struct pci_device_id *ent)
+                          const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &das08_pci_comedi_driver);
+       return comedi_pci_auto_config(dev, &das08_pci_comedi_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(das08_pci_table) = {
index f238a1fbccbf7ac246e2e8e441846ae88cf5a846..caeaee8d4840fd3f1d70e3411118f50c13c1d716 100644 (file)
@@ -876,7 +876,7 @@ static void das16_interrupt(struct comedi_device *dev)
        int num_bytes, residue;
        int buffer_index;
 
-       if (dev->attached == 0) {
+       if (!dev->attached) {
                comedi_error(dev, "premature interrupt");
                return;
        }
index b0a861a779bdc10576c55c686341c15050103d2b..7ba8fc7a02f697590b565d0e4b66244487045cbd 100644 (file)
@@ -499,7 +499,7 @@ static irqreturn_t das16m1_interrupt(int irq, void *d)
        int status;
        struct comedi_device *dev = d;
 
-       if (dev->attached == 0) {
+       if (!dev->attached) {
                comedi_error(dev, "premature interrupt");
                return IRQ_HANDLED;
        }
index 7900f959555d71e2ed82e47f0b3004838e98a57b..d01e140885d8ebaf79c0bd6898c8a2d47decbde6 100644 (file)
@@ -731,7 +731,7 @@ static irqreturn_t das1800_interrupt(int irq, void *d)
        struct comedi_device *dev = d;
        unsigned int status;
 
-       if (dev->attached == 0) {
+       if (!dev->attached) {
                comedi_error(dev, "premature interrupt");
                return IRQ_HANDLED;
        }
index 3ce499fa5dbf775d8962e29efdd3e4bc9e5f5dc2..909656ba51b526fa8e9217361d445df9e0d352dc 100644 (file)
@@ -63,17 +63,6 @@ AO commands are not supported.
 
 #include "comedi_fc.h"
 
-/*
- * PCI device id's supported by this driver
- */
-#define PCI_DEVICE_ID_DT3001           0x0022
-#define PCI_DEVICE_ID_DT3002           0x0023
-#define PCI_DEVICE_ID_DT3003           0x0024
-#define PCI_DEVICE_ID_DT3004           0x0025
-#define PCI_DEVICE_ID_DT3005           0x0026
-#define PCI_DEVICE_ID_DT3001_PGL       0x0027
-#define PCI_DEVICE_ID_DT3003_PGL       0x0028
-
 static const struct comedi_lrange range_dt3000_ai = {
        4, {
                BIP_RANGE(10),
@@ -92,9 +81,18 @@ static const struct comedi_lrange range_dt3000_ai_pgl = {
        }
 };
 
+enum dt3k_boardid {
+       BOARD_DT3001,
+       BOARD_DT3001_PGL,
+       BOARD_DT3002,
+       BOARD_DT3003,
+       BOARD_DT3003_PGL,
+       BOARD_DT3004,
+       BOARD_DT3005,
+};
+
 struct dt3k_boardtype {
        const char *name;
-       unsigned int device_id;
        int adchan;
        int adbits;
        int ai_speed;
@@ -104,61 +102,60 @@ struct dt3k_boardtype {
 };
 
 static const struct dt3k_boardtype dt3k_boardtypes[] = {
-       {
+       [BOARD_DT3001] = {
                .name           = "dt3001",
-               .device_id      = PCI_DEVICE_ID_DT3001,
                .adchan         = 16,
                .adbits         = 12,
                .adrange        = &range_dt3000_ai,
                .ai_speed       = 3000,
                .dachan         = 2,
                .dabits         = 12,
-       }, {
+       },
+       [BOARD_DT3001_PGL] = {
                .name           = "dt3001-pgl",
-               .device_id      = PCI_DEVICE_ID_DT3001_PGL,
                .adchan         = 16,
                .adbits         = 12,
                .adrange        = &range_dt3000_ai_pgl,
                .ai_speed       = 3000,
                .dachan         = 2,
                .dabits         = 12,
-       }, {
+       },
+       [BOARD_DT3002] = {
                .name           = "dt3002",
-               .device_id      = PCI_DEVICE_ID_DT3002,
                .adchan         = 32,
                .adbits         = 12,
                .adrange        = &range_dt3000_ai,
                .ai_speed       = 3000,
-       }, {
+       },
+       [BOARD_DT3003] = {
                .name           = "dt3003",
-               .device_id      = PCI_DEVICE_ID_DT3003,
                .adchan         = 64,
                .adbits         = 12,
                .adrange        = &range_dt3000_ai,
                .ai_speed       = 3000,
                .dachan         = 2,
                .dabits         = 12,
-       }, {
+       },
+       [BOARD_DT3003_PGL] = {
                .name           = "dt3003-pgl",
-               .device_id      = PCI_DEVICE_ID_DT3003_PGL,
                .adchan         = 64,
                .adbits         = 12,
                .adrange        = &range_dt3000_ai_pgl,
                .ai_speed       = 3000,
                .dachan         = 2,
                .dabits         = 12,
-       }, {
+       },
+       [BOARD_DT3004] = {
                .name           = "dt3004",
-               .device_id      = PCI_DEVICE_ID_DT3004,
                .adchan         = 16,
                .adbits         = 16,
                .adrange        = &range_dt3000_ai,
                .ai_speed       = 10000,
                .dachan         = 2,
                .dabits         = 12,
-       }, {
+       },
+       [BOARD_DT3005] = {
                .name           = "dt3005",     /* a.k.a. 3004-200 */
-               .device_id      = PCI_DEVICE_ID_DT3005,
                .adchan         = 16,
                .adbits         = 16,
                .adrange        = &range_dt3000_ai,
@@ -716,31 +713,18 @@ static int dt3k_mem_insn_read(struct comedi_device *dev,
        return i;
 }
 
-static const void *dt3000_find_boardinfo(struct comedi_device *dev,
-                                        struct pci_dev *pcidev)
-{
-       const struct dt3k_boardtype *this_board;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(dt3k_boardtypes); i++) {
-               this_board = &dt3k_boardtypes[i];
-               if (this_board->device_id == pcidev->device)
-                       return this_board;
-       }
-       return NULL;
-}
-
 static int dt3000_auto_attach(struct comedi_device *dev,
-                                       unsigned long context_unused)
+                             unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct dt3k_boardtype *this_board;
+       const struct dt3k_boardtype *this_board = NULL;
        struct dt3k_private *devpriv;
        struct comedi_subdevice *s;
        resource_size_t pci_base;
        int ret = 0;
 
-       this_board = dt3000_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(dt3k_boardtypes))
+               this_board = &dt3k_boardtypes[context];
        if (!this_board)
                return -ENODEV;
        dev->board_ptr = this_board;
@@ -751,10 +735,9 @@ static int dt3000_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret < 0)
                return ret;
-       dev->iobase = 1;        /* the "detach" needs this */
 
        pci_base  = pci_resource_start(pcidev, 0);
        devpriv->io_addr = ioremap(pci_base, DT3000_SIZE);
@@ -830,7 +813,6 @@ static int dt3000_auto_attach(struct comedi_device *dev,
 
 static void dt3000_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct dt3k_private *devpriv = dev->private;
 
        if (dev->irq)
@@ -839,10 +821,7 @@ static void dt3000_detach(struct comedi_device *dev)
                if (devpriv->io_addr)
                        iounmap(devpriv->io_addr);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver dt3000_driver = {
@@ -853,19 +832,19 @@ static struct comedi_driver dt3000_driver = {
 };
 
 static int dt3000_pci_probe(struct pci_dev *dev,
-                                     const struct pci_device_id *ent)
+                           const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &dt3000_driver);
+       return comedi_pci_auto_config(dev, &dt3000_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(dt3000_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3001) },
-       { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3001_PGL) },
-       { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3002) },
-       { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3003) },
-       { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3003_PGL) },
-       { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3004) },
-       { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3005) },
+       { PCI_VDEVICE(DT, 0x0022), BOARD_DT3001 },
+       { PCI_VDEVICE(DT, 0x0023), BOARD_DT3002 },
+       { PCI_VDEVICE(DT, 0x0024), BOARD_DT3003 },
+       { PCI_VDEVICE(DT, 0x0025), BOARD_DT3004 },
+       { PCI_VDEVICE(DT, 0x0026), BOARD_DT3005 },
+       { PCI_VDEVICE(DT, 0x0027), BOARD_DT3001_PGL },
+       { PCI_VDEVICE(DT, 0x0028), BOARD_DT3003_PGL },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, dt3000_pci_table);
index decc17f1867e495fe254f4c24b7c06e76a6314fe..17f9ec2a9072fc6b7358a762fb66645297192d18 100644 (file)
@@ -194,7 +194,7 @@ static int dyna_pci10xx_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 2);
@@ -254,15 +254,11 @@ static int dyna_pci10xx_auto_attach(struct comedi_device *dev,
 
 static void dyna_pci10xx_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct dyna_pci10xx_private *devpriv = dev->private;
 
        if (devpriv)
                mutex_destroy(&devpriv->mutex);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver dyna_pci10xx_driver = {
@@ -273,9 +269,10 @@ static struct comedi_driver dyna_pci10xx_driver = {
 };
 
 static int dyna_pci10xx_pci_probe(struct pci_dev *dev,
-                                           const struct pci_device_id *ent)
+                                 const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &dyna_pci10xx_driver);
+       return comedi_pci_auto_config(dev, &dyna_pci10xx_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(dyna_pci10xx_pci_table) = {
index b60c975626760d97a1cb5cd0bdace78f47ed63e7..ba44d0375c20b5fd4dae62d8070771eec4c6d78f 100644 (file)
@@ -499,12 +499,9 @@ static int hpdi_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       if (comedi_pci_enable(pcidev, dev->board_name)) {
-               dev_warn(dev->class_dev,
-                        "failed enable PCI device and request regions\n");
-               return -EIO;
-       }
-       dev->iobase = 1;        /* the "detach" needs this */
+       retval = comedi_pci_enable(dev);
+       if (retval)
+               return retval;
        pci_set_master(pcidev);
 
        devpriv->plx9080_iobase =
@@ -596,9 +593,8 @@ static void hpdi_detach(struct comedi_device *dev)
                                            NUM_DMA_DESCRIPTORS,
                                            devpriv->dma_desc,
                                            devpriv->dma_desc_phys_addr);
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
        }
+       comedi_pci_disable(dev);
 }
 
 static int dio_config_block_size(struct comedi_device *dev, unsigned int *data)
@@ -943,9 +939,9 @@ static struct comedi_driver gsc_hpdi_driver = {
 };
 
 static int gsc_hpdi_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &gsc_hpdi_driver);
+       return comedi_pci_auto_config(dev, &gsc_hpdi_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(gsc_hpdi_pci_table) = {
index 1e08f9141fadd09980f51d0f6b7e7aac533cb973..f29a797fd9d5741da712f1532f7e55cb89b41ed1 100644 (file)
@@ -120,7 +120,7 @@ struct icp_multi_private {
        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 scaned channel */
+       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 */
@@ -510,7 +510,7 @@ static int icp_multi_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        iobase = pci_resource_start(pcidev, 2);
@@ -594,7 +594,6 @@ static int icp_multi_auto_attach(struct comedi_device *dev,
 
 static void icp_multi_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct icp_multi_private *devpriv = dev->private;
 
        if (devpriv)
@@ -604,10 +603,7 @@ static void icp_multi_detach(struct comedi_device *dev)
                free_irq(dev->irq, dev);
        if (devpriv && devpriv->io_addr)
                iounmap(devpriv->io_addr);
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver icp_multi_driver = {
@@ -618,9 +614,9 @@ static struct comedi_driver icp_multi_driver = {
 };
 
 static int icp_multi_pci_probe(struct pci_dev *dev,
-                                          const struct pci_device_id *ent)
+                              const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &icp_multi_driver);
+       return comedi_pci_auto_config(dev, &icp_multi_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(icp_multi_pci_table) = {
index 17ba75e0ab89260cdc9545843452a915b1579e85..f21ebb536a2d8fb97be68bd03510a6347cc3fab9 100644 (file)
@@ -702,11 +702,10 @@ static int jr3_pci_auto_attach(struct comedi_device *dev,
        }
        dev->board_name = "jr3_pci";
 
-       result = comedi_pci_enable(pcidev, "jr3_pci");
-       if (result < 0)
+       result = comedi_pci_enable(dev);
+       if (result)
                return result;
 
-       dev->iobase = 1;        /* the "detach" needs this */
        devpriv->iobase = ioremap(pci_resource_start(pcidev, 0),
                                  offsetof(struct jr3_t,
                                           channel[devpriv->n_channels]));
@@ -816,7 +815,6 @@ static int jr3_pci_auto_attach(struct comedi_device *dev,
 static void jr3_pci_detach(struct comedi_device *dev)
 {
        int i;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct jr3_pci_dev_private *devpriv = dev->private;
 
        if (devpriv) {
@@ -828,9 +826,8 @@ static void jr3_pci_detach(struct comedi_device *dev)
                }
                if (devpriv->iobase)
                        iounmap(devpriv->iobase);
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver jr3_pci_driver = {
@@ -841,9 +838,9 @@ static struct comedi_driver jr3_pci_driver = {
 };
 
 static int jr3_pci_pci_probe(struct pci_dev *dev,
-                                      const struct pci_device_id *ent)
+                            const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &jr3_pci_driver);
+       return comedi_pci_auto_config(dev, &jr3_pci_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(jr3_pci_pci_table) = {
index 8c09c026508a228930576e58e3eeba4de9ba5d69..bca29e5f4fc5e798b01aab348c5b300a96c91a1d 100644 (file)
@@ -98,7 +98,7 @@ static int cnt_auto_attach(struct comedi_device *dev,
 
        dev->board_name = dev->driver->driver_name;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
        dev->iobase = pci_resource_start(pcidev, 0);
@@ -131,27 +131,18 @@ static int cnt_auto_attach(struct comedi_device *dev,
        return 0;
 }
 
-static void cnt_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
-}
-
 static struct comedi_driver ke_counter_driver = {
        .driver_name    = "ke_counter",
        .module         = THIS_MODULE,
        .auto_attach    = cnt_auto_attach,
-       .detach         = cnt_detach,
+       .detach         = comedi_pci_disable,
 };
 
 static int ke_counter_pci_probe(struct pci_dev *dev,
-                                         const struct pci_device_id *ent)
+                               const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &ke_counter_driver);
+       return comedi_pci_auto_config(dev, &ke_counter_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(ke_counter_pci_table) = {
index b766bb93efd6f599f5ebc3c52ff375f0df9270c1..e415db2d069eb69706049144290e21056b094cae 100644 (file)
@@ -61,20 +61,6 @@ broken.
 #include "me4000_fw.h"
 #endif
 
-#define PCI_DEVICE_ID_MEILHAUS_ME4650  0x4650
-#define PCI_DEVICE_ID_MEILHAUS_ME4660  0x4660
-#define PCI_DEVICE_ID_MEILHAUS_ME4660I 0x4661
-#define PCI_DEVICE_ID_MEILHAUS_ME4660S 0x4662
-#define PCI_DEVICE_ID_MEILHAUS_ME4660IS        0x4663
-#define PCI_DEVICE_ID_MEILHAUS_ME4670  0x4670
-#define PCI_DEVICE_ID_MEILHAUS_ME4670I 0x4671
-#define PCI_DEVICE_ID_MEILHAUS_ME4670S 0x4672
-#define PCI_DEVICE_ID_MEILHAUS_ME4670IS        0x4673
-#define PCI_DEVICE_ID_MEILHAUS_ME4680  0x4680
-#define PCI_DEVICE_ID_MEILHAUS_ME4680I 0x4681
-#define PCI_DEVICE_ID_MEILHAUS_ME4680S 0x4682
-#define PCI_DEVICE_ID_MEILHAUS_ME4680IS        0x4683
-
 /*
  * ME4000 Register map and bit defines
  */
@@ -220,9 +206,24 @@ struct me4000_info {
        unsigned int ao_readback[4];
 };
 
+enum me4000_boardid {
+       BOARD_ME4650,
+       BOARD_ME4660,
+       BOARD_ME4660I,
+       BOARD_ME4660S,
+       BOARD_ME4660IS,
+       BOARD_ME4670,
+       BOARD_ME4670I,
+       BOARD_ME4670S,
+       BOARD_ME4670IS,
+       BOARD_ME4680,
+       BOARD_ME4680I,
+       BOARD_ME4680S,
+       BOARD_ME4680IS,
+};
+
 struct me4000_board {
        const char *name;
-       unsigned short device_id;
        int ao_nchan;
        int ao_fifo;
        int ai_nchan;
@@ -234,62 +235,61 @@ struct me4000_board {
 };
 
 static const struct me4000_board me4000_boards[] = {
-       {
+       [BOARD_ME4650] = {
                .name           = "ME-4650",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4650,
                .ai_nchan       = 16,
                .dio_nchan      = 32,
-       }, {
+       },
+       [BOARD_ME4660] = {
                .name           = "ME-4660",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4660,
                .ai_nchan       = 32,
                .ai_diff_nchan  = 16,
                .dio_nchan      = 32,
                .has_counter    = 1,
-       }, {
+       },
+       [BOARD_ME4660I] = {
                .name           = "ME-4660i",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4660I,
                .ai_nchan       = 32,
                .ai_diff_nchan  = 16,
                .dio_nchan      = 32,
                .has_counter    = 1,
-       }, {
+       },
+       [BOARD_ME4660S] = {
                .name           = "ME-4660s",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4660S,
                .ai_nchan       = 32,
                .ai_diff_nchan  = 16,
                .ai_sh_nchan    = 8,
                .dio_nchan      = 32,
                .has_counter    = 1,
-       }, {
+       },
+       [BOARD_ME4660IS] = {
                .name           = "ME-4660is",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4660IS,
                .ai_nchan       = 32,
                .ai_diff_nchan  = 16,
                .ai_sh_nchan    = 8,
                .dio_nchan      = 32,
                .has_counter    = 1,
-       }, {
+       },
+       [BOARD_ME4670] = {
                .name           = "ME-4670",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4670,
                .ao_nchan       = 4,
                .ai_nchan       = 32,
                .ai_diff_nchan  = 16,
                .ex_trig_analog = 1,
                .dio_nchan      = 32,
                .has_counter    = 1,
-       }, {
+       },
+       [BOARD_ME4670I] = {
                .name           = "ME-4670i",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4670I,
                .ao_nchan       = 4,
                .ai_nchan       = 32,
                .ai_diff_nchan  = 16,
                .ex_trig_analog = 1,
                .dio_nchan      = 32,
                .has_counter    = 1,
-       }, {
+       },
+       [BOARD_ME4670S] = {
                .name           = "ME-4670s",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4670S,
                .ao_nchan       = 4,
                .ai_nchan       = 32,
                .ai_diff_nchan  = 16,
@@ -297,9 +297,9 @@ static const struct me4000_board me4000_boards[] = {
                .ex_trig_analog = 1,
                .dio_nchan      = 32,
                .has_counter    = 1,
-       }, {
+       },
+       [BOARD_ME4670IS] = {
                .name           = "ME-4670is",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4670IS,
                .ao_nchan       = 4,
                .ai_nchan       = 32,
                .ai_diff_nchan  = 16,
@@ -307,9 +307,9 @@ static const struct me4000_board me4000_boards[] = {
                .ex_trig_analog = 1,
                .dio_nchan      = 32,
                .has_counter    = 1,
-       }, {
+       },
+       [BOARD_ME4680] = {
                .name           = "ME-4680",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4680,
                .ao_nchan       = 4,
                .ao_fifo        = 4,
                .ai_nchan       = 32,
@@ -317,9 +317,9 @@ static const struct me4000_board me4000_boards[] = {
                .ex_trig_analog = 1,
                .dio_nchan      = 32,
                .has_counter    = 1,
-       }, {
+       },
+       [BOARD_ME4680I] = {
                .name           = "ME-4680i",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4680I,
                .ao_nchan       = 4,
                .ao_fifo        = 4,
                .ai_nchan       = 32,
@@ -327,9 +327,9 @@ static const struct me4000_board me4000_boards[] = {
                .ex_trig_analog = 1,
                .dio_nchan      = 32,
                .has_counter    = 1,
-       }, {
+       },
+       [BOARD_ME4680S] = {
                .name           = "ME-4680s",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4680S,
                .ao_nchan       = 4,
                .ao_fifo        = 4,
                .ai_nchan       = 32,
@@ -338,9 +338,9 @@ static const struct me4000_board me4000_boards[] = {
                .ex_trig_analog = 1,
                .dio_nchan      = 32,
                .has_counter    = 1,
-       }, {
+       },
+       [BOARD_ME4680IS] = {
                .name           = "ME-4680is",
-               .device_id      = PCI_DEVICE_ID_MEILHAUS_ME4680IS,
                .ao_nchan       = 4,
                .ao_fifo        = 4,
                .ai_nchan       = 32,
@@ -1550,30 +1550,17 @@ static int me4000_cnt_insn_write(struct comedi_device *dev,
        return 1;
 }
 
-static const void *me4000_find_boardinfo(struct comedi_device *dev,
-                                        struct pci_dev *pcidev)
-{
-       const struct me4000_board *thisboard;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(me4000_boards); i++) {
-               thisboard = &me4000_boards[i];
-               if (thisboard->device_id == pcidev->device)
-                       return thisboard;
-       }
-       return NULL;
-}
-
 static int me4000_auto_attach(struct comedi_device *dev,
-                                       unsigned long context_unused)
+                             unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct me4000_board *thisboard;
+       const struct me4000_board *thisboard = NULL;
        struct me4000_info *info;
        struct comedi_subdevice *s;
        int result;
 
-       thisboard = me4000_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(me4000_boards))
+               thisboard = &me4000_boards[context];
        if (!thisboard)
                return -ENODEV;
        dev->board_ptr = thisboard;
@@ -1584,7 +1571,7 @@ static int me4000_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = info;
 
-       result = comedi_pci_enable(pcidev, dev->board_name);
+       result = comedi_pci_enable(dev);
        if (result)
                return result;
 
@@ -1710,16 +1697,11 @@ static int me4000_auto_attach(struct comedi_device *dev,
 
 static void me4000_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (pcidev) {
-               if (dev->iobase) {
-                       me4000_reset(dev);
-                       comedi_pci_disable(pcidev);
-               }
-       }
+       if (dev->iobase)
+               me4000_reset(dev);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver me4000_driver = {
@@ -1730,26 +1712,26 @@ static struct comedi_driver me4000_driver = {
 };
 
 static int me4000_pci_probe(struct pci_dev *dev,
-                                     const struct pci_device_id *ent)
+                           const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &me4000_driver);
+       return comedi_pci_auto_config(dev, &me4000_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(me4000_pci_table) = {
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4650)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4660)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4660I)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4660S)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4660IS)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4670)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4670I)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4670S)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4670IS)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4680)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4680I)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4680S)},
-       {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4680IS)},
-       {0}
+       { PCI_VDEVICE(MEILHAUS, 0x4650), BOARD_ME4650 },
+       { PCI_VDEVICE(MEILHAUS, 0x4660), BOARD_ME4660 },
+       { PCI_VDEVICE(MEILHAUS, 0x4661), BOARD_ME4660I },
+       { PCI_VDEVICE(MEILHAUS, 0x4662), BOARD_ME4660S },
+       { PCI_VDEVICE(MEILHAUS, 0x4663), BOARD_ME4660IS },
+       { PCI_VDEVICE(MEILHAUS, 0x4670), BOARD_ME4670 },
+       { PCI_VDEVICE(MEILHAUS, 0x4671), BOARD_ME4670I },
+       { PCI_VDEVICE(MEILHAUS, 0x4672), BOARD_ME4670S },
+       { PCI_VDEVICE(MEILHAUS, 0x4673), BOARD_ME4670IS },
+       { PCI_VDEVICE(MEILHAUS, 0x4680), BOARD_ME4680 },
+       { PCI_VDEVICE(MEILHAUS, 0x4681), BOARD_ME4680I },
+       { PCI_VDEVICE(MEILHAUS, 0x4682), BOARD_ME4680S },
+       { PCI_VDEVICE(MEILHAUS, 0x4683), BOARD_ME4680IS },
+       { 0 }
 };
 MODULE_DEVICE_TABLE(pci, me4000_pci_table);
 
index 06490ebc8cc802ea94574fcd0c53e2b496716db8..5df4f55dbaead65fe476e98c2c71d6c54edfa753 100644 (file)
@@ -43,9 +43,6 @@
 
 #define ME2600_FIRMWARE                "me2600_firmware.bin"
 
-#define ME2000_DEVICE_ID       0x2000
-#define ME2600_DEVICE_ID       0x2600
-
 #define PLX_INTCSR             0x4C    /* PLX interrupt status register */
 #define XILINX_DOWNLOAD_RESET  0x42    /* Xilinx registers */
 
@@ -149,21 +146,26 @@ static const struct comedi_lrange me_ao_range = {
        }
 };
 
+enum me_boardid {
+       BOARD_ME2600,
+       BOARD_ME2000,
+};
+
 struct me_board {
        const char *name;
-       int device_id;
+       int needs_firmware;
        int has_ao;
 };
 
 static const struct me_board me_boards[] = {
-       {
+       [BOARD_ME2600] = {
                .name           = "me-2600i",
-               .device_id      = ME2600_DEVICE_ID,
+               .needs_firmware = 1,
                .has_ao         = 1,
-       }, {
+       },
+       [BOARD_ME2000] = {
                .name           = "me-2000i",
-               .device_id      = ME2000_DEVICE_ID,
-       }
+       },
 };
 
 struct me_private_data {
@@ -426,7 +428,7 @@ static int me2600_xilinx_download(struct comedi_device *dev,
 
        /*
         * Loop for writing firmware byte by byte to xilinx
-        * Firmware data start at offfset 16
+        * Firmware data start at offset 16
         */
        for (i = 0; i < file_length; i++)
                writeb((data[16 + i] & 0xff),
@@ -488,30 +490,17 @@ static int me_reset(struct comedi_device *dev)
        return 0;
 }
 
-static const void *me_find_boardinfo(struct comedi_device *dev,
-                                    struct pci_dev *pcidev)
-{
-       const struct me_board *board;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(me_boards); i++) {
-               board = &me_boards[i];
-               if (board->device_id == pcidev->device)
-                       return board;
-       }
-       return NULL;
-}
-
 static int me_auto_attach(struct comedi_device *dev,
-                                   unsigned long context_unused)
+                         unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct me_board *board;
+       const struct me_board *board = NULL;
        struct me_private_data *dev_private;
        struct comedi_subdevice *s;
        int ret;
 
-       board = me_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(me_boards))
+               board = &me_boards[context];
        if (!board)
                return -ENODEV;
        dev->board_ptr = board;
@@ -522,10 +511,9 @@ static int me_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = dev_private;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
-       dev->iobase = 1;        /* detach needs this */
 
        dev_private->plx_regbase = ioremap(pci_resource_start(pcidev, 0),
                                           pci_resource_len(pcidev, 0));
@@ -538,7 +526,7 @@ static int me_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
 
        /* Download firmware and reset card */
-       if (board->device_id == ME2600_DEVICE_ID) {
+       if (board->needs_firmware) {
                ret = me2600_upload_firmware(dev);
                if (ret < 0)
                        return ret;
@@ -591,7 +579,6 @@ static int me_auto_attach(struct comedi_device *dev,
 
 static void me_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct me_private_data *dev_private = dev->private;
 
        if (dev_private) {
@@ -602,10 +589,7 @@ static void me_detach(struct comedi_device *dev)
                if (dev_private->plx_regbase)
                        iounmap(dev_private->plx_regbase);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver me_daq_driver = {
@@ -616,14 +600,14 @@ static struct comedi_driver me_daq_driver = {
 };
 
 static int me_daq_pci_probe(struct pci_dev *dev,
-                                     const struct pci_device_id *ent)
+                           const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &me_daq_driver);
+       return comedi_pci_auto_config(dev, &me_daq_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(me_daq_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2600_DEVICE_ID) },
-       { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2000_DEVICE_ID) },
+       { PCI_VDEVICE(MEILHAUS, 0x2600), BOARD_ME2600 },
+       { PCI_VDEVICE(MEILHAUS, 0x2000), BOARD_ME2000 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, me_daq_pci_table);
index be2c15f84614400fc1b43cf552bbecdbf06c683f..9a456624ab4e1bb3b7c73f0957371c26949454b9 100644 (file)
@@ -109,11 +109,6 @@ int mite_setup2(struct mite_struct *mite, unsigned use_iodwbsr_1)
        u32 csigr_bits;
        unsigned unknown_dma_burst_bits;
 
-       if (comedi_pci_enable(mite->pcidev, "mite")) {
-               dev_err(&mite->pcidev->dev,
-                       "error enabling mite and requesting io regions\n");
-               return -EIO;
-       }
        pci_set_master(mite->pcidev);
 
        addr = pci_resource_start(mite->pcidev, 0);
@@ -208,10 +203,8 @@ void mite_unsetup(struct mite_struct *mite)
                iounmap(mite->daq_io_addr);
                mite->daq_io_addr = NULL;
        }
-       if (mite->mite_phys_addr) {
-               comedi_pci_disable(mite->pcidev);
+       if (mite->mite_phys_addr)
                mite->mite_phys_addr = 0;
-       }
 }
 EXPORT_SYMBOL(mite_unsetup);
 
index bcd4df290ec47913e422780972b261bac71300ab..d10f777b7f179f5da2e540dbc39d0008b3a0c024 100644 (file)
@@ -81,33 +81,24 @@ Updated: Sat, 25 Jan 2003 13:24:40 -0800
 #define Rising_Edge_Detection_Enable(x)                (0x018+(x))
 #define Falling_Edge_Detection_Enable(x)       (0x020+(x))
 
-struct ni6527_board {
+enum ni6527_boardid {
+       BOARD_PCI6527,
+       BOARD_PXI6527,
+};
 
-       int dev_id;
+struct ni6527_board {
        const char *name;
 };
 
 static const struct ni6527_board ni6527_boards[] = {
-       {
-        .dev_id = 0x2b20,
-        .name = "pci-6527",
-        },
-       {
-        .dev_id = 0x2b10,
-        .name = "pxi-6527",
-        },
-};
-
-#define this_board ((const struct ni6527_board *)dev->board_ptr)
-
-static DEFINE_PCI_DEVICE_TABLE(ni6527_pci_table) = {
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b10)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b20)},
-       {0}
+       [BOARD_PCI6527] = {
+               .name           = "pci-6527",
+       },
+       [BOARD_PXI6527] = {
+               .name           = "pxi-6527",
+       },
 };
 
-MODULE_DEVICE_TABLE(pci, ni6527_pci_table);
-
 struct ni6527_private {
        struct mite_struct *mite;
        unsigned int filter_interval;
@@ -329,37 +320,31 @@ static int ni6527_intr_insn_config(struct comedi_device *dev,
        return 2;
 }
 
-static const struct ni6527_board *
-ni6527_find_boardinfo(struct pci_dev *pcidev)
-{
-       unsigned int dev_id = pcidev->device;
-       unsigned int n;
-
-       for (n = 0; n < ARRAY_SIZE(ni6527_boards); n++) {
-               const struct ni6527_board *board = &ni6527_boards[n];
-               if (board->dev_id == dev_id)
-                       return board;
-       }
-       return NULL;
-}
-
 static int ni6527_auto_attach(struct comedi_device *dev,
-                                       unsigned long context_unused)
+                             unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+       const struct ni6527_board *board = NULL;
        struct ni6527_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
 
+       if (context < ARRAY_SIZE(ni6527_boards))
+               board = &ni6527_boards[context];
+       if (!board)
+               return -ENODEV;
+       dev->board_ptr = board;
+       dev->board_name = board->name;
+
+       ret = comedi_pci_enable(dev);
+       if (ret)
+               return ret;
+
        devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
        if (!devpriv)
                return -ENOMEM;
        dev->private = devpriv;
 
-       dev->board_ptr = ni6527_find_boardinfo(pcidev);
-       if (!dev->board_ptr)
-               return -ENODEV;
-
        devpriv->mite = mite_alloc(pcidev);
        if (!devpriv->mite)
                return -ENOMEM;
@@ -370,7 +355,6 @@ static int ni6527_auto_attach(struct comedi_device *dev,
                return ret;
        }
 
-       dev->board_name = this_board->name;
        dev_info(dev->class_dev, "board: %s, ID=0x%02x\n", dev->board_name,
                 readb(devpriv->mite->daq_io_addr + ID_Register));
 
@@ -439,6 +423,7 @@ static void ni6527_detach(struct comedi_device *dev)
                mite_unsetup(devpriv->mite);
                mite_free(devpriv->mite);
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver ni6527_driver = {
@@ -449,15 +434,22 @@ static struct comedi_driver ni6527_driver = {
 };
 
 static int ni6527_pci_probe(struct pci_dev *dev,
-                                     const struct pci_device_id *ent)
+                           const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &ni6527_driver);
+       return comedi_pci_auto_config(dev, &ni6527_driver, id->driver_data);
 }
 
+static DEFINE_PCI_DEVICE_TABLE(ni6527_pci_table) = {
+       { PCI_VDEVICE(NI, 0x2b10), BOARD_PXI6527 },
+       { PCI_VDEVICE(NI, 0x2b20), BOARD_PCI6527 },
+       { 0 }
+};
+MODULE_DEVICE_TABLE(pci, ni6527_pci_table);
+
 static struct pci_driver ni6527_pci_driver = {
-       .name = DRIVER_NAME,
-       .id_table = ni6527_pci_table,
-       .probe = ni6527_pci_probe,
+       .name           = DRIVER_NAME,
+       .id_table       = ni6527_pci_table,
+       .probe          = ni6527_pci_probe,
        .remove         = comedi_pci_auto_unconfig,
 };
 module_comedi_pci_driver(ni6527_driver, ni6527_pci_driver);
index bfa790ecf41d9fe7fbcab2b0797b5a6ef96c30ca..013392cfe2a1abe84d2b442e92faa85cd8dea455 100644 (file)
@@ -112,8 +112,32 @@ static inline unsigned Filter_Enable(unsigned port)
 #define OverflowIntEnable              0x02
 #define EdgeIntEnable                  0x01
 
+enum ni_65xx_boardid {
+       BOARD_PCI6509,
+       BOARD_PXI6509,
+       BOARD_PCI6510,
+       BOARD_PCI6511,
+       BOARD_PXI6511,
+       BOARD_PCI6512,
+       BOARD_PXI6512,
+       BOARD_PCI6513,
+       BOARD_PXI6513,
+       BOARD_PCI6514,
+       BOARD_PXI6514,
+       BOARD_PCI6515,
+       BOARD_PXI6515,
+       BOARD_PCI6516,
+       BOARD_PCI6517,
+       BOARD_PCI6518,
+       BOARD_PCI6519,
+       BOARD_PCI6520,
+       BOARD_PCI6521,
+       BOARD_PXI6521,
+       BOARD_PCI6528,
+       BOARD_PXI6528,
+};
+
 struct ni_65xx_board {
-       int dev_id;
        const char *name;
        unsigned num_dio_ports;
        unsigned num_di_ports;
@@ -122,130 +146,117 @@ struct ni_65xx_board {
 };
 
 static const struct ni_65xx_board ni_65xx_boards[] = {
-       {
-        .dev_id = 0x7085,
-        .name = "pci-6509",
-        .num_dio_ports = 12,
-        .invert_outputs = 0},
-       {
-        .dev_id = 0x1710,
-        .name = "pxi-6509",
-        .num_dio_ports = 12,
-        .invert_outputs = 0},
-       {
-        .dev_id = 0x7124,
-        .name = "pci-6510",
-        .num_di_ports = 4},
-       {
-        .dev_id = 0x70c3,
-        .name = "pci-6511",
-        .num_di_ports = 8},
-       {
-        .dev_id = 0x70d3,
-        .name = "pxi-6511",
-        .num_di_ports = 8},
-       {
-        .dev_id = 0x70cc,
-        .name = "pci-6512",
-        .num_do_ports = 8},
-       {
-        .dev_id = 0x70d2,
-        .name = "pxi-6512",
-        .num_do_ports = 8},
-       {
-        .dev_id = 0x70c8,
-        .name = "pci-6513",
-        .num_do_ports = 8,
-        .invert_outputs = 1},
-       {
-        .dev_id = 0x70d1,
-        .name = "pxi-6513",
-        .num_do_ports = 8,
-        .invert_outputs = 1},
-       {
-        .dev_id = 0x7088,
-        .name = "pci-6514",
-        .num_di_ports = 4,
-        .num_do_ports = 4,
-        .invert_outputs = 1},
-       {
-        .dev_id = 0x70CD,
-        .name = "pxi-6514",
-        .num_di_ports = 4,
-        .num_do_ports = 4,
-        .invert_outputs = 1},
-       {
-        .dev_id = 0x7087,
-        .name = "pci-6515",
-        .num_di_ports = 4,
-        .num_do_ports = 4,
-        .invert_outputs = 1},
-       {
-        .dev_id = 0x70c9,
-        .name = "pxi-6515",
-        .num_di_ports = 4,
-        .num_do_ports = 4,
-        .invert_outputs = 1},
-       {
-        .dev_id = 0x7125,
-        .name = "pci-6516",
-        .num_do_ports = 4,
-        .invert_outputs = 1},
-       {
-        .dev_id = 0x7126,
-        .name = "pci-6517",
-        .num_do_ports = 4,
-        .invert_outputs = 1},
-       {
-        .dev_id = 0x7127,
-        .name = "pci-6518",
-        .num_di_ports = 2,
-        .num_do_ports = 2,
-        .invert_outputs = 1},
-       {
-        .dev_id = 0x7128,
-        .name = "pci-6519",
-        .num_di_ports = 2,
-        .num_do_ports = 2,
-        .invert_outputs = 1},
-       {
-        .dev_id = 0x71c5,
-        .name = "pci-6520",
-        .num_di_ports = 1,
-        .num_do_ports = 1,
-        },
-       {
-        .dev_id = 0x718b,
-        .name = "pci-6521",
-        .num_di_ports = 1,
-        .num_do_ports = 1,
-        },
-       {
-        .dev_id = 0x718c,
-        .name = "pxi-6521",
-        .num_di_ports = 1,
-        .num_do_ports = 1,
-        },
-       {
-        .dev_id = 0x70a9,
-        .name = "pci-6528",
-        .num_di_ports = 3,
-        .num_do_ports = 3,
-        },
-       {
-        .dev_id = 0x7086,
-        .name = "pxi-6528",
-        .num_di_ports = 3,
-        .num_do_ports = 3,
-        },
+       [BOARD_PCI6509] = {
+               .name           = "pci-6509",
+               .num_dio_ports  = 12,
+       },
+       [BOARD_PXI6509] = {
+               .name           = "pxi-6509",
+               .num_dio_ports  = 12,
+       },
+       [BOARD_PCI6510] = {
+               .name           = "pci-6510",
+               .num_di_ports   = 4,
+       },
+       [BOARD_PCI6511] = {
+               .name           = "pci-6511",
+               .num_di_ports   = 8,
+       },
+       [BOARD_PXI6511] = {
+               .name           = "pxi-6511",
+               .num_di_ports   = 8,
+       },
+       [BOARD_PCI6512] = {
+               .name           = "pci-6512",
+               .num_do_ports   = 8,
+       },
+       [BOARD_PXI6512] = {
+               .name           = "pxi-6512",
+               .num_do_ports   = 8,
+       },
+       [BOARD_PCI6513] = {
+               .name           = "pci-6513",
+               .num_do_ports   = 8,
+               .invert_outputs = 1,
+       },
+       [BOARD_PXI6513] = {
+               .name           = "pxi-6513",
+               .num_do_ports   = 8,
+               .invert_outputs = 1,
+       },
+       [BOARD_PCI6514] = {
+               .name           = "pci-6514",
+               .num_di_ports   = 4,
+               .num_do_ports   = 4,
+               .invert_outputs = 1,
+       },
+       [BOARD_PXI6514] = {
+               .name           = "pxi-6514",
+               .num_di_ports   = 4,
+               .num_do_ports   = 4,
+               .invert_outputs = 1,
+       },
+       [BOARD_PCI6515] = {
+               .name           = "pci-6515",
+               .num_di_ports   = 4,
+               .num_do_ports   = 4,
+               .invert_outputs = 1,
+       },
+       [BOARD_PXI6515] = {
+               .name           = "pxi-6515",
+               .num_di_ports   = 4,
+               .num_do_ports   = 4,
+               .invert_outputs = 1,
+       },
+       [BOARD_PCI6516] = {
+               .name           = "pci-6516",
+               .num_do_ports   = 4,
+               .invert_outputs = 1,
+       },
+       [BOARD_PCI6517] = {
+               .name           = "pci-6517",
+               .num_do_ports   = 4,
+               .invert_outputs = 1,
+       },
+       [BOARD_PCI6518] = {
+               .name           = "pci-6518",
+               .num_di_ports   = 2,
+               .num_do_ports   = 2,
+               .invert_outputs = 1,
+       },
+       [BOARD_PCI6519] = {
+               .name           = "pci-6519",
+               .num_di_ports   = 2,
+               .num_do_ports   = 2,
+               .invert_outputs = 1,
+       },
+       [BOARD_PCI6520] = {
+               .name           = "pci-6520",
+               .num_di_ports   = 1,
+               .num_do_ports   = 1,
+       },
+       [BOARD_PCI6521] = {
+               .name           = "pci-6521",
+               .num_di_ports   = 1,
+               .num_do_ports   = 1,
+       },
+       [BOARD_PXI6521] = {
+               .name           = "pxi-6521",
+               .num_di_ports   = 1,
+               .num_do_ports   = 1,
+       },
+       [BOARD_PCI6528] = {
+               .name           = "pci-6528",
+               .num_di_ports   = 3,
+               .num_do_ports   = 3,
+       },
+       [BOARD_PXI6528] = {
+               .name           = "pxi-6528",
+               .num_di_ports   = 3,
+               .num_do_ports   = 3,
+       },
 };
 
-#define n_ni_65xx_boards ARRAY_SIZE(ni_65xx_boards)
-static inline const struct ni_65xx_board *board(struct comedi_device *dev)
-{
-       return dev->board_ptr;
-}
-
 static inline unsigned ni_65xx_port_by_channel(unsigned channel)
 {
        return channel / ni_65xx_channels_per_port;
@@ -257,34 +268,6 @@ static inline unsigned ni_65xx_total_num_ports(const struct ni_65xx_board
        return board->num_dio_ports + board->num_di_ports + board->num_do_ports;
 }
 
-static DEFINE_PCI_DEVICE_TABLE(ni_65xx_pci_table) = {
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1710)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x7085)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x7086)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x7087)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x7088)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70a9)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70c3)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70c8)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70c9)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70cc)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70CD)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70d1)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70d2)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70d3)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x7124)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x7125)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x7126)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x7127)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x7128)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x718b)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x718c)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x71c5)},
-       {0}
-};
-
-MODULE_DEVICE_TABLE(pci, ni_65xx_pci_table);
-
 struct ni_65xx_private {
        struct mite_struct *mite;
        unsigned int filter_interval;
@@ -398,6 +381,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
                                 struct comedi_subdevice *s,
                                 struct comedi_insn *insn, unsigned int *data)
 {
+       const struct ni_65xx_board *board = comedi_board(dev);
        struct ni_65xx_private *devpriv = dev->private;
        unsigned base_bitfield_channel;
        const unsigned max_ports_per_bitfield = 5;
@@ -413,7 +397,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
                unsigned base_port_channel;
                unsigned port_mask, port_data, port_read_bits;
                int bitshift;
-               if (port >= ni_65xx_total_num_ports(board(dev)))
+               if (port >= ni_65xx_total_num_ports(board))
                        break;
                base_port_channel = port_offset * ni_65xx_channels_per_port;
                port_mask = data[0];
@@ -436,7 +420,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
                        devpriv->output_bits[port] |=
                            port_data & port_mask;
                        bits = devpriv->output_bits[port];
-                       if (board(dev)->invert_outputs)
+                       if (board->invert_outputs)
                                bits = ~bits;
                        writeb(bits,
                               devpriv->mite->daq_io_addr +
@@ -444,7 +428,7 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
                }
                port_read_bits =
                    readb(devpriv->mite->daq_io_addr + Port_Data(port));
-               if (s->type == COMEDI_SUBD_DO && board(dev)->invert_outputs) {
+               if (s->type == COMEDI_SUBD_DO && board->invert_outputs) {
                        /* Outputs inverted, so invert value read back from
                         * DO subdevice.  (Does not apply to boards with DIO
                         * subdevice.) */
@@ -599,38 +583,32 @@ static int ni_65xx_intr_insn_config(struct comedi_device *dev,
        return 2;
 }
 
-static const struct ni_65xx_board *
-ni_65xx_find_boardinfo(struct pci_dev *pcidev)
-{
-       unsigned int dev_id = pcidev->device;
-       unsigned int n;
-
-       for (n = 0; n < ARRAY_SIZE(ni_65xx_boards); n++) {
-               const struct ni_65xx_board *board = &ni_65xx_boards[n];
-               if (board->dev_id == dev_id)
-                       return board;
-       }
-       return NULL;
-}
-
 static int ni_65xx_auto_attach(struct comedi_device *dev,
-                                        unsigned long context_unused)
+                              unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+       const struct ni_65xx_board *board = NULL;
        struct ni_65xx_private *devpriv;
        struct comedi_subdevice *s;
        unsigned i;
        int ret;
 
+       if (context < ARRAY_SIZE(ni_65xx_boards))
+               board = &ni_65xx_boards[context];
+       if (!board)
+               return -ENODEV;
+       dev->board_ptr = board;
+       dev->board_name = board->name;
+
+       ret = comedi_pci_enable(dev);
+       if (ret)
+               return ret;
+
        devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
        if (!devpriv)
                return -ENOMEM;
        dev->private = devpriv;
 
-       dev->board_ptr = ni_65xx_find_boardinfo(pcidev);
-       if (!dev->board_ptr)
-               return -ENODEV;
-
        devpriv->mite = mite_alloc(pcidev);
        if (!devpriv->mite)
                return -ENOMEM;
@@ -641,7 +619,6 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
                return ret;
        }
 
-       dev->board_name = board(dev)->name;
        dev->irq = mite_irq(devpriv->mite);
        dev_info(dev->class_dev, "board: %s, ID=0x%02x", dev->board_name,
               readb(devpriv->mite->daq_io_addr + ID_Register));
@@ -651,11 +628,11 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
                return ret;
 
        s = &dev->subdevices[0];
-       if (board(dev)->num_di_ports) {
+       if (board->num_di_ports) {
                s->type = COMEDI_SUBD_DI;
                s->subdev_flags = SDF_READABLE;
                s->n_chan =
-                   board(dev)->num_di_ports * ni_65xx_channels_per_port;
+                   board->num_di_ports * ni_65xx_channels_per_port;
                s->range_table = &range_digital;
                s->maxdata = 1;
                s->insn_config = ni_65xx_dio_insn_config;
@@ -669,28 +646,28 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
        }
 
        s = &dev->subdevices[1];
-       if (board(dev)->num_do_ports) {
+       if (board->num_do_ports) {
                s->type = COMEDI_SUBD_DO;
                s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
                s->n_chan =
-                   board(dev)->num_do_ports * ni_65xx_channels_per_port;
+                   board->num_do_ports * ni_65xx_channels_per_port;
                s->range_table = &range_digital;
                s->maxdata = 1;
                s->insn_bits = ni_65xx_dio_insn_bits;
                s->private = ni_65xx_alloc_subdevice_private();
                if (s->private == NULL)
                        return -ENOMEM;
-               sprivate(s)->base_port = board(dev)->num_di_ports;
+               sprivate(s)->base_port = board->num_di_ports;
        } else {
                s->type = COMEDI_SUBD_UNUSED;
        }
 
        s = &dev->subdevices[2];
-       if (board(dev)->num_dio_ports) {
+       if (board->num_dio_ports) {
                s->type = COMEDI_SUBD_DIO;
                s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
                s->n_chan =
-                   board(dev)->num_dio_ports * ni_65xx_channels_per_port;
+                   board->num_dio_ports * ni_65xx_channels_per_port;
                s->range_table = &range_digital;
                s->maxdata = 1;
                s->insn_config = ni_65xx_dio_insn_config;
@@ -699,7 +676,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
                if (s->private == NULL)
                        return -ENOMEM;
                sprivate(s)->base_port = 0;
-               for (i = 0; i < board(dev)->num_dio_ports; ++i) {
+               for (i = 0; i < board->num_dio_ports; ++i) {
                        /*  configure all ports for input */
                        writeb(0x1,
                               devpriv->mite->daq_io_addr +
@@ -722,10 +699,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
        s->insn_bits = ni_65xx_intr_insn_bits;
        s->insn_config = ni_65xx_intr_insn_config;
 
-       for (i = 0; i < ni_65xx_total_num_ports(board(dev)); ++i) {
+       for (i = 0; i < ni_65xx_total_num_ports(board); ++i) {
                writeb(0x00,
                       devpriv->mite->daq_io_addr + Filter_Enable(i));
-               if (board(dev)->invert_outputs)
+               if (board->invert_outputs)
                        writeb(0x01,
                               devpriv->mite->daq_io_addr + Port_Data(i));
                else
@@ -775,6 +752,7 @@ static void ni_65xx_detach(struct comedi_device *dev)
                        mite_free(devpriv->mite);
                }
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver ni_65xx_driver = {
@@ -785,15 +763,42 @@ static struct comedi_driver ni_65xx_driver = {
 };
 
 static int ni_65xx_pci_probe(struct pci_dev *dev,
-                                      const struct pci_device_id *ent)
+                            const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &ni_65xx_driver);
+       return comedi_pci_auto_config(dev, &ni_65xx_driver, id->driver_data);
 }
 
+static DEFINE_PCI_DEVICE_TABLE(ni_65xx_pci_table) = {
+       { PCI_VDEVICE(NI, 0x1710), BOARD_PXI6509 },
+       { PCI_VDEVICE(NI, 0x7085), BOARD_PCI6509 },
+       { PCI_VDEVICE(NI, 0x7086), BOARD_PXI6528 },
+       { PCI_VDEVICE(NI, 0x7087), BOARD_PCI6515 },
+       { PCI_VDEVICE(NI, 0x7088), BOARD_PCI6514 },
+       { PCI_VDEVICE(NI, 0x70a9), BOARD_PCI6528 },
+       { PCI_VDEVICE(NI, 0x70c3), BOARD_PCI6511 },
+       { PCI_VDEVICE(NI, 0x70c8), BOARD_PCI6513 },
+       { PCI_VDEVICE(NI, 0x70c9), BOARD_PXI6515 },
+       { PCI_VDEVICE(NI, 0x70cc), BOARD_PCI6512 },
+       { PCI_VDEVICE(NI, 0x70cd), BOARD_PXI6514 },
+       { PCI_VDEVICE(NI, 0x70d1), BOARD_PXI6513 },
+       { PCI_VDEVICE(NI, 0x70d2), BOARD_PXI6512 },
+       { PCI_VDEVICE(NI, 0x70d3), BOARD_PXI6511 },
+       { PCI_VDEVICE(NI, 0x7124), BOARD_PCI6510 },
+       { PCI_VDEVICE(NI, 0x7125), BOARD_PCI6516 },
+       { PCI_VDEVICE(NI, 0x7126), BOARD_PCI6517 },
+       { PCI_VDEVICE(NI, 0x7127), BOARD_PCI6518 },
+       { PCI_VDEVICE(NI, 0x7128), BOARD_PCI6519 },
+       { PCI_VDEVICE(NI, 0x718b), BOARD_PCI6521 },
+       { PCI_VDEVICE(NI, 0x718c), BOARD_PXI6521 },
+       { PCI_VDEVICE(NI, 0x71c5), BOARD_PCI6520 },
+       { 0 }
+};
+MODULE_DEVICE_TABLE(pci, ni_65xx_pci_table);
+
 static struct pci_driver ni_65xx_pci_driver = {
-       .name = "ni_65xx",
-       .id_table = ni_65xx_pci_table,
-       .probe = ni_65xx_pci_probe,
+       .name           = "ni_65xx",
+       .id_table       = ni_65xx_pci_table,
+       .probe          = ni_65xx_pci_probe,
        .remove         = comedi_pci_auto_unconfig,
 };
 module_comedi_pci_driver(ni_65xx_driver, ni_65xx_pci_driver);
index e46dd7a1a72453068b1883fd78b32e44124c7a6e..5cdda7fe97a71fd463ff8d04aeaf5ca1ac826f56 100644 (file)
 */
 
 /*
-Driver: ni_660x
-Description: National Instruments 660x counter/timer boards
-Devices:
-[National Instruments] PCI-6601 (ni_660x), PCI-6602, PXI-6602,
-       PXI-6608
-Author: J.P. Mellor <jpmellor@rose-hulman.edu>,
-       Herman.Bruyninckx@mech.kuleuven.ac.be,
-       Wim.Meeussen@mech.kuleuven.ac.be,
-       Klaas.Gadeyne@mech.kuleuven.ac.be,
-       Frank Mori Hess <fmhess@users.sourceforge.net>
-Updated: Thu Oct 18 12:56:06 EDT 2007
-Status: experimental
-
-Encoders work.  PulseGeneration (both single pulse and pulse train)
-works. Buffered commands work for input but not output.
-
-References:
-DAQ 660x Register-Level Programmer Manual  (NI 370505A-01)
-DAQ 6601/6602 User Manual (NI 322137B-01)
-
-*/
+ * Driver: ni_660x
+ * Description: National Instruments 660x counter/timer boards
+ * Devices: [National Instruments] PCI-6601 (ni_660x), PCI-6602, PXI-6602,
+ *   PXI-6608, PXI-6624
+ * Author: J.P. Mellor <jpmellor@rose-hulman.edu>,
+ *   Herman.Bruyninckx@mech.kuleuven.ac.be,
+ *   Wim.Meeussen@mech.kuleuven.ac.be,
+ *   Klaas.Gadeyne@mech.kuleuven.ac.be,
+ *   Frank Mori Hess <fmhess@users.sourceforge.net>
+ * Updated: Fri, 15 Mar 2013 10:47:56 +0000
+ * Status: experimental
+ *
+ * Encoders work.  PulseGeneration (both single pulse and pulse train)
+ * works.  Buffered commands work for input but not output.
+ * 
+ * References:
+ * DAQ 660x Register-Level Programmer Manual  (NI 370505A-01)
+ * DAQ 6601/6602 User Manual (NI 322137B-01)
+ */
 
 #include <linux/pci.h>
 #include <linux/interrupt.h>
@@ -389,34 +387,40 @@ enum global_interrupt_config_register_bits {
 /* First chip is at base-address + 0x00, etc. */
 static const unsigned GPCT_OFFSET[2] = { 0x0, 0x800 };
 
-/* Board description*/
+enum ni_660x_boardid {
+       BOARD_PCI6601,
+       BOARD_PCI6602,
+       BOARD_PXI6602,
+       BOARD_PXI6608,
+       BOARD_PXI6624
+};
+
 struct ni_660x_board {
-       unsigned short dev_id;  /* `lspci` will show you this */
        const char *name;
        unsigned n_chips;       /* total number of TIO chips */
 };
 
 static const struct ni_660x_board ni_660x_boards[] = {
-       {
-        .dev_id = 0x2c60,
-        .name = "PCI-6601",
-        .n_chips = 1,
-        },
-       {
-        .dev_id = 0x1310,
-        .name = "PCI-6602",
-        .n_chips = 2,
-        },
-       {
-        .dev_id = 0x1360,
-        .name = "PXI-6602",
-        .n_chips = 2,
-        },
-       {
-        .dev_id = 0x2cc0,
-        .name = "PXI-6608",
-        .n_chips = 2,
-        },
+       [BOARD_PCI6601] = {
+               .name           = "PCI-6601",
+               .n_chips        = 1,
+       },
+       [BOARD_PCI6602] = {
+               .name           = "PCI-6602",
+               .n_chips        = 2,
+       },
+       [BOARD_PXI6602] = {
+               .name           = "PXI-6602",
+               .n_chips        = 2,
+       },
+       [BOARD_PXI6608] = {
+               .name           = "PXI-6608",
+               .n_chips        = 2,
+       },
+       [BOARD_PXI6624] = {
+               .name           = "PXI-6624",
+               .n_chips        = 2,
+       },
 };
 
 #define NI_660X_MAX_NUM_CHIPS 2
@@ -883,7 +887,7 @@ static irqreturn_t ni_660x_interrupt(int irq, void *d)
        unsigned i;
        unsigned long flags;
 
-       if (dev->attached == 0)
+       if (!dev->attached)
                return IRQ_NONE;
        /* lock to avoid race with comedi_poll */
        spin_lock_irqsave(&devpriv->interrupt_lock, flags);
@@ -974,20 +978,6 @@ static void ni_660x_free_mite_rings(struct comedi_device *dev)
        }
 }
 
-static const struct ni_660x_board *
-ni_660x_find_boardinfo(struct pci_dev *pcidev)
-{
-       unsigned int dev_id = pcidev->device;
-       unsigned int n;
-
-       for (n = 0; n < ARRAY_SIZE(ni_660x_boards); n++) {
-               const struct ni_660x_board *board = &ni_660x_boards[n];
-               if (board->dev_id == dev_id)
-                       return board;
-       }
-       return NULL;
-}
-
 static int
 ni_660x_GPCT_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
                   struct comedi_insn *insn, unsigned int *data)
@@ -1170,32 +1160,36 @@ static int ni_660x_dio_insn_config(struct comedi_device *dev,
 }
 
 static int ni_660x_auto_attach(struct comedi_device *dev,
-                                        unsigned long context_unused)
+                              unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct ni_660x_board *board;
+       const struct ni_660x_board *board = NULL;
        struct ni_660x_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
        unsigned i;
        unsigned global_interrupt_config_bits;
 
+       if (context < ARRAY_SIZE(ni_660x_boards))
+               board = &ni_660x_boards[context];
+       if (!board)
+               return -ENODEV;
+       dev->board_ptr = board;
+       dev->board_name = board->name;
+
+       ret = comedi_pci_enable(dev);
+       if (ret)
+               return ret;
+
        ret = ni_660x_allocate_private(dev);
        if (ret < 0)
                return ret;
        devpriv = dev->private;
 
-       dev->board_ptr = ni_660x_find_boardinfo(pcidev);
-       if (!dev->board_ptr)
-               return -ENODEV;
-       board = comedi_board(dev);
-
        devpriv->mite = mite_alloc(pcidev);
        if (!devpriv->mite)
                return -ENOMEM;
 
-       dev->board_name = board->name;
-
        ret = mite_setup2(devpriv->mite, 1);
        if (ret < 0) {
                dev_warn(dev->class_dev, "error setting up mite\n");
@@ -1315,6 +1309,7 @@ static void ni_660x_detach(struct comedi_device *dev)
                        mite_free(devpriv->mite);
                }
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver ni_660x_driver = {
@@ -1325,17 +1320,18 @@ static struct comedi_driver ni_660x_driver = {
 };
 
 static int ni_660x_pci_probe(struct pci_dev *dev,
-                                      const struct pci_device_id *ent)
+                            const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &ni_660x_driver);
+       return comedi_pci_auto_config(dev, &ni_660x_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(ni_660x_pci_table) = {
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c60)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1310)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1360)},
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2cc0)},
-       {0}
+       { PCI_VDEVICE(NI, 0x1310), BOARD_PCI6602 },
+       { PCI_VDEVICE(NI, 0x1360), BOARD_PXI6602 },
+       { PCI_VDEVICE(NI, 0x2c60), BOARD_PCI6601 },
+       { PCI_VDEVICE(NI, 0x2cc0), BOARD_PXI6608 },
+       { PCI_VDEVICE(NI, 0x1e40), BOARD_PXI6624 },
+       { 0 }
 };
 MODULE_DEVICE_TABLE(pci, ni_660x_pci_table);
 
index 2faf86c83dc5be3190df82a04d50e738a5e5e557..e9d486238c85e92e1c119c0979bb6a9d21bcb060 100644 (file)
@@ -60,26 +60,28 @@ Commands are not supported.
 #define        MISC_STATUS_OFFSET              0x14
 #define        MISC_CONTROL_OFFSET             0x14
 
-/* Board description*/
+enum ni_670x_boardid {
+       BOARD_PCI6703,
+       BOARD_PXI6704,
+       BOARD_PCI6704,
+};
 
 struct ni_670x_board {
        const char *name;
-       unsigned short dev_id;
        unsigned short ao_chans;
 };
 
 static const struct ni_670x_board ni_670x_boards[] = {
-       {
+       [BOARD_PCI6703] = {
                .name           = "PCI-6703",
-               .dev_id         = 0x2c90,
                .ao_chans       = 16,
-       }, {
+       },
+       [BOARD_PXI6704] = {
                .name           = "PXI-6704",
-               .dev_id         = 0x1920,
                .ao_chans       = 32,
-       }, {
+       },
+       [BOARD_PCI6704] = {
                .name           = "PCI-6704",
-               .dev_id         = 0x1290,
                .ao_chans       = 32,
        },
 };
@@ -189,49 +191,41 @@ static int ni_670x_dio_insn_config(struct comedi_device *dev,
        return insn->n;
 }
 
-static const struct ni_670x_board *
-ni_670x_find_boardinfo(struct pci_dev *pcidev)
-{
-       unsigned int dev_id = pcidev->device;
-       unsigned int n;
-
-       for (n = 0; n < ARRAY_SIZE(ni_670x_boards); n++) {
-               const struct ni_670x_board *board = &ni_670x_boards[n];
-               if (board->dev_id == dev_id)
-                       return board;
-       }
-       return NULL;
-}
-
 static int ni_670x_auto_attach(struct comedi_device *dev,
-                                        unsigned long context_unused)
+                              unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct ni_670x_board *thisboard;
+       const struct ni_670x_board *thisboard = NULL;
        struct ni_670x_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
        int i;
 
+       if (context < ARRAY_SIZE(ni_670x_boards))
+               thisboard = &ni_670x_boards[context];
+       if (!thisboard)
+               return -ENODEV;
+       dev->board_ptr = thisboard;
+       dev->board_name = thisboard->name;
+
+       ret = comedi_pci_enable(dev);
+       if (ret)
+               return ret;
+
        devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
        if (!devpriv)
                return -ENOMEM;
        dev->private = devpriv;
 
-       dev->board_ptr = ni_670x_find_boardinfo(pcidev);
-       if (!dev->board_ptr)
-               return -ENODEV;
        devpriv->mite = mite_alloc(pcidev);
        if (!devpriv->mite)
                return -ENOMEM;
-       thisboard = comedi_board(dev);
 
        ret = mite_setup(devpriv->mite);
        if (ret < 0) {
                dev_warn(dev->class_dev, "error setting up mite\n");
                return ret;
        }
-       dev->board_name = thisboard->name;
 
        ret = comedi_alloc_subdevices(dev, 2);
        if (ret)
@@ -296,6 +290,7 @@ static void ni_670x_detach(struct comedi_device *dev)
                mite_unsetup(devpriv->mite);
                mite_free(devpriv->mite);
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver ni_670x_driver = {
@@ -306,14 +301,15 @@ static struct comedi_driver ni_670x_driver = {
 };
 
 static int ni_670x_pci_probe(struct pci_dev *dev,
-                                      const struct pci_device_id *ent)
+                            const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &ni_670x_driver);
+       return comedi_pci_auto_config(dev, &ni_670x_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(ni_670x_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c90) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1920) },
+       { PCI_VDEVICE(NI, 0x1290), BOARD_PCI6704 },
+       { PCI_VDEVICE(NI, 0x1920), BOARD_PXI6704 },
+       { PCI_VDEVICE(NI, 0x2c90), BOARD_PCI6703 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, ni_670x_pci_table);
index 06de25bb2f56fc3e7fa821945a39bfaf0def21ff..2a4a7a47214222148287cc3c81d9cbb5964d775c 100644 (file)
@@ -204,7 +204,7 @@ static irqreturn_t a2150_interrupt(int irq, void *d)
        short dpnt;
        static const int sample_size = sizeof(devpriv->dma_buffer[0]);
 
-       if (dev->attached == 0) {
+       if (!dev->attached) {
                comedi_error(dev, "premature interrupt");
                return IRQ_HANDLED;
        }
index 2cc29965e157c44a28aed0aac14e0cc0ae73ca7c..37372a1f9ed98a193ce1ec9209f254d572e2709c 100644 (file)
@@ -350,7 +350,7 @@ static int ni_isapnp_find_board(struct pnp_dev **dev)
        struct pnp_dev *isapnp_dev = NULL;
        int i;
 
-       for (i = 0; i < n_ni_boards; i++) {
+       for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
                isapnp_dev = pnp_find_dev(NULL,
                                          ISAPNP_VENDOR('N', 'I', 'C'),
                                          ISAPNP_FUNCTION(ni_boards[i].
@@ -377,7 +377,7 @@ static int ni_isapnp_find_board(struct pnp_dev **dev)
                }
                break;
        }
-       if (i == n_ni_boards)
+       if (i == ARRAY_SIZE(ni_boards))
                return -ENODEV;
        *dev = isapnp_dev;
        return 0;
@@ -388,7 +388,7 @@ static int ni_getboardtype(struct comedi_device *dev)
        int device_id = ni_read_eeprom(dev, 511);
        int i;
 
-       for (i = 0; i < n_ni_boards; i++) {
+       for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
                if (ni_boards[i].device_id == device_id)
                        return i;
 
@@ -406,6 +406,7 @@ static int ni_getboardtype(struct comedi_device *dev)
 static int ni_atmio_attach(struct comedi_device *dev,
                           struct comedi_devconfig *it)
 {
+       const struct ni_board_struct *boardtype;
        struct ni_private *devpriv;
        struct pnp_dev *isapnp_dev;
        int ret;
@@ -466,9 +467,10 @@ static int ni_atmio_attach(struct comedi_device *dev,
                return -EIO;
 
        dev->board_ptr = ni_boards + board;
+       boardtype = comedi_board(dev);
 
-       printk(" %s", boardtype.name);
-       dev->board_name = boardtype.name;
+       printk(" %s", boardtype->name);
+       dev->board_name = boardtype->name;
 
        /* irq stuff */
 
index f957b8859b3d05873305e053a25cce3f8ed3aed7..22f8d45ae6d520ee03da5a979f44b83a1fc5b73b 100644 (file)
@@ -1,77 +1,70 @@
 /*
-    comedi/drivers/ni_labpc.c
-    Driver for National Instruments Lab-PC series boards and compatibles
-    Copyright (C) 2001, 2002, 2003 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.
-
-    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.
-
-************************************************************************
-*/
-/*
-Driver: ni_labpc
-Description: National Instruments Lab-PC (& compatibles)
-Author: Frank Mori Hess <fmhess@users.sourceforge.net>
-Devices: [National Instruments] Lab-PC-1200 (labpc-1200),
-  Lab-PC-1200AI (labpc-1200ai), Lab-PC+ (lab-pc+), PCI-1200 (ni_labpc)
-Status: works
-
-Tested with lab-pc-1200.  For the older Lab-PC+, not all input ranges
-and analog references will work, the available ranges/arefs will
-depend on how you have configured the jumpers on your board
-(see your owner's manual).
-
-Kernel-level ISA plug-and-play support for the lab-pc-1200
-boards has not
-yet been added to the driver, mainly due to the fact that
-I don't know the device id numbers.  If you have one
-of these boards,
-please file a bug report at http://comedi.org/ 
-so I can get the necessary information from you.
-
-The 1200 series boards have onboard calibration dacs for correcting
-analog input/output offsets and gains.  The proper settings for these
-caldacs are stored on the board's eeprom.  To read the caldac values
-from the eeprom and store them into a file that can be then be used by
-comedilib, use the comedi_calibrate program.
-
-Configuration options - ISA boards:
-  [0] - I/O port base address
-  [1] - IRQ (optional, required for timed or externally triggered conversions)
-  [2] - DMA channel (optional)
-
-Configuration options - PCI boards:
-  [0] - bus (optional)
-  [1] - slot (optional)
-
-The Lab-pc+ has quirky chanlist requirements
-when scanning multiple channels.  Multiple channel scan
-sequence must start at highest channel, then decrement down to
-channel 0.  The rest of the cards can scan down like lab-pc+ or scan
-up from channel zero.  Chanlists consisting of all one channel
-are also legal, and allow you to pace conversions in bursts.
-
-*/
+ * comedi/drivers/ni_labpc.c
+ * Driver for National Instruments Lab-PC series boards and compatibles
+ * Copyright (C) 2001-2003 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.
+ *
+ * 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.
+ */
 
 /*
-
-NI manuals:
-341309a (labpc-1200 register manual)
-340914a (pci-1200)
-320502b (lab-pc+)
-
-*/
+ * Driver: ni_labpc
+ * Description: National Instruments Lab-PC (& compatibles)
+ * Devices: (National Instruments) Lab-PC-1200 [lab-pc-1200]
+ *         (National Instruments) Lab-PC-1200AI [lab-pc-1200ai]
+ *         (National Instruments) Lab-PC+ [lab-pc+]
+ *         (National Instruments) PCI-1200 [pci-1200]
+ * Author: Frank Mori Hess <fmhess@users.sourceforge.net>
+ * Status: works
+ *
+ * Configuration options - ISA boards:
+ *   [0] - I/O port base address
+ *   [1] - IRQ (optional, required for timed or externally triggered
+ *             conversions)
+ *   [2] - DMA channel (optional)
+ *
+ * Configuration options - PCI boards:
+ *    not applicable, uses PCI auto config
+ *
+ * Tested with lab-pc-1200.  For the older Lab-PC+, not all input
+ * ranges and analog references will work, the available ranges/arefs
+ * will depend on how you have configured the jumpers on your board
+ * (see your owner's manual).
+ *
+ * Kernel-level ISA plug-and-play support for the lab-pc-1200 boards
+ * has not yet been added to the driver, mainly due to the fact that
+ * I don't know the device id numbers. If you have one of these boards,
+ * please file a bug report at http://comedi.org/ so I can get the
+ * necessary information from you.
+ *
+ * The 1200 series boards have onboard calibration dacs for correcting
+ * analog input/output offsets and gains. The proper settings for these
+ * caldacs are stored on the board's eeprom. To read the caldac values
+ * from the eeprom and store them into a file that can be then be used
+ * by comedilib, use the comedi_calibrate program.
+ *
+ * The Lab-pc+ has quirky chanlist requirements when scanning multiple
+ * channels. Multiple channel scan sequence must start at highest channel,
+ * then decrement down to channel 0. The rest of the cards can scan down
+ * like lab-pc+ or scan up from channel zero. Chanlists consisting of all
+ * one channel are also legal, and allow you to pace conversions in bursts.
+ *
+ * NI manuals:
+ * 341309a (labpc-1200 register manual)
+ * 340914a (pci-1200)
+ * 320502b (lab-pc+)
+ */
 
 #include <linux/pci.h>
 #include <linux/interrupt.h>
@@ -89,124 +82,76 @@ NI manuals:
 #include "comedi_fc.h"
 #include "ni_labpc.h"
 
-#define DRV_NAME "ni_labpc"
-
-/* size of io region used by board */
-#define LABPC_SIZE           32
-/* 2 MHz master clock */
-#define LABPC_TIMER_BASE            500
-
-/* Registers for the lab-pc+ */
-
-/* write-only registers */
-#define COMMAND1_REG   0x0
-#define   ADC_GAIN_MASK        (0x7 << 4)
-#define   ADC_CHAN_BITS(x)     ((x) & 0x7)
-/* enables multi channel scans */
-#define   ADC_SCAN_EN_BIT      0x80
-#define COMMAND2_REG   0x1
-/* enable pretriggering (used in conjunction with SWTRIG) */
-#define   PRETRIG_BIT  0x1
-/* enable paced conversions on external trigger */
-#define   HWTRIG_BIT   0x2
-/* enable paced conversions */
-#define   SWTRIG_BIT   0x4
-/* use two cascaded counters for pacing */
-#define   CASCADE_BIT  0x8
-#define   DAC_PACED_BIT(channel)       (0x40 << ((channel) & 0x1))
-#define COMMAND3_REG   0x2
-/* enable dma transfers */
-#define   DMA_EN_BIT   0x1
-/* enable interrupts for 8255 */
-#define   DIO_INTR_EN_BIT      0x2
-/* enable dma terminal count interrupt */
-#define   DMATC_INTR_EN_BIT    0x4
-/* enable timer interrupt */
-#define   TIMER_INTR_EN_BIT    0x8
-/* enable error interrupt */
-#define   ERR_INTR_EN_BIT      0x10
-/* enable fifo not empty interrupt */
-#define   ADC_FNE_INTR_EN_BIT  0x20
-#define ADC_CONVERT_REG        0x3
-#define DAC_LSB_REG(channel)   (0x4 + 2 * ((channel) & 0x1))
-#define DAC_MSB_REG(channel)   (0x5 + 2 * ((channel) & 0x1))
-#define ADC_CLEAR_REG  0x8
-#define DMATC_CLEAR_REG        0xa
-#define TIMER_CLEAR_REG        0xc
-/* 1200 boards only */
-#define COMMAND6_REG   0xe
-/* select ground or common-mode reference */
-#define   ADC_COMMON_BIT       0x1
-/*  adc unipolar */
-#define   ADC_UNIP_BIT 0x2
-/*  dac unipolar */
-#define   DAC_UNIP_BIT(channel)        (0x4 << ((channel) & 0x1))
-/* enable fifo half full interrupt */
-#define   ADC_FHF_INTR_EN_BIT  0x20
-/* enable interrupt on end of hardware count */
-#define   A1_INTR_EN_BIT       0x40
-/* scan up from channel zero instead of down to zero */
-#define   ADC_SCAN_UP_BIT 0x80
-#define COMMAND4_REG   0xf
-/* enables 'interval' scanning */
-#define   INTERVAL_SCAN_EN_BIT 0x1
-/* enables external signal on counter b1 output to trigger scan */
-#define   EXT_SCAN_EN_BIT      0x2
-/* chooses direction (output or input) for EXTCONV* line */
-#define   EXT_CONVERT_OUT_BIT  0x4
-/* chooses differential inputs for adc (in conjunction with board jumper) */
-#define   ADC_DIFF_BIT 0x8
-#define   EXT_CONVERT_DISABLE_BIT      0x10
-/* 1200 boards only, calibration stuff */
-#define COMMAND5_REG   0x1c
-/* enable eeprom for write */
-#define   EEPROM_WRITE_UNPROTECT_BIT   0x4
-/* enable dithering */
-#define   DITHER_EN_BIT        0x8
-/* load calibration dac */
-#define   CALDAC_LOAD_BIT      0x10
-/* serial clock - rising edge writes, falling edge reads */
-#define   SCLOCK_BIT   0x20
-/* serial data bit for writing to eeprom or calibration dacs */
-#define   SDATA_BIT    0x40
-/* enable eeprom for read/write */
-#define   EEPROM_EN_BIT        0x80
-#define INTERVAL_COUNT_REG     0x1e
-#define INTERVAL_LOAD_REG      0x1f
-#define   INTERVAL_LOAD_BITS   0x1
-
-/* read-only registers */
-#define STATUS1_REG    0x0
-/* data is available in fifo */
-#define   DATA_AVAIL_BIT       0x1
-/* overrun has occurred */
-#define   OVERRUN_BIT  0x2
-/* fifo overflow */
-#define   OVERFLOW_BIT 0x4
-/* timer interrupt has occurred */
-#define   TIMER_BIT    0x8
-/* dma terminal count has occurred */
-#define   DMATC_BIT    0x10
-/* external trigger has occurred */
-#define   EXT_TRIG_BIT 0x40
-/* 1200 boards only */
-#define STATUS2_REG    0x1d
-/* programmable eeprom serial output */
-#define   EEPROM_OUT_BIT       0x1
-/* counter A1 terminal count */
-#define   A1_TC_BIT    0x2
-/* fifo not half full */
-#define   FNHF_BIT     0x4
-#define ADC_FIFO_REG   0xa
-
-#define DIO_BASE_REG   0x10
-#define COUNTER_A_BASE_REG     0x14
-#define COUNTER_A_CONTROL_REG  (COUNTER_A_BASE_REG + 0x3)
-/* check modes put conversion pacer output in harmless state (a0 mode 2) */
-#define   INIT_A0_BITS 0x14
-/* put hardware conversion counter output in harmless state (a1 mode 0) */
-#define   INIT_A1_BITS 0x70
-#define COUNTER_B_BASE_REG     0x18
+/*
+ * Register map (all registers are 8-bit)
+ */
+#define STAT1_REG              0x00    /* R: Status 1 reg */
+#define STAT1_DAVAIL           (1 << 0)
+#define STAT1_OVERRUN          (1 << 1)
+#define STAT1_OVERFLOW         (1 << 2)
+#define STAT1_CNTINT           (1 << 3)
+#define STAT1_GATA0            (1 << 5)
+#define STAT1_EXTGATA0         (1 << 6)
+#define CMD1_REG               0x00    /* W: Command 1 reg */
+#define CMD1_MA(x)             (((x) & 0x7) << 0)
+#define CMD1_TWOSCMP           (1 << 3)
+#define CMD1_GAIN_MASK         (7 << 4)
+#define CMD1_SCANEN            (1 << 7)
+#define CMD2_REG               0x01    /* W: Command 2 reg */
+#define CMD2_PRETRIG           (1 << 0)
+#define CMD2_HWTRIG            (1 << 1)
+#define CMD2_SWTRIG            (1 << 2)
+#define CMD2_TBSEL             (1 << 3)
+#define CMD2_2SDAC0            (1 << 4)
+#define CMD2_2SDAC1            (1 << 5)
+#define CMD2_LDAC(x)           (1 << (6 + (x)))
+#define CMD3_REG               0x02    /* W: Command 3 reg */
+#define CMD3_DMAEN             (1 << 0)
+#define CMD3_DIOINTEN          (1 << 1)
+#define CMD3_DMATCINTEN                (1 << 2)
+#define CMD3_CNTINTEN          (1 << 3)
+#define CMD3_ERRINTEN          (1 << 4)
+#define CMD3_FIFOINTEN         (1 << 5)
+#define ADC_START_CONVERT_REG  0x03    /* W: Start Convert reg */
+#define DAC_LSB_REG(x)         (0x04 + 2 * (x)) /* W: DAC0/1 LSB reg */
+#define DAC_MSB_REG(x)         (0x05 + 2 * (x)) /* W: DAC0/1 MSB reg */
+#define ADC_FIFO_CLEAR_REG     0x08    /* W: A/D FIFO Clear reg */
+#define ADC_FIFO_REG           0x0a    /* R: A/D FIFO reg */
+#define DMATC_CLEAR_REG                0x0a    /* W: DMA Interrupt Clear reg */
+#define TIMER_CLEAR_REG                0x0c    /* W: Timer Interrupt Clear reg */
+#define CMD6_REG               0x0e    /* W: Command 6 reg */
+#define CMD6_NRSE              (1 << 0)
+#define CMD6_ADCUNI            (1 << 1)
+#define CMD6_DACUNI(x)         (1 << (2 + (x)))
+#define CMD6_HFINTEN           (1 << 5)
+#define CMD6_DQINTEN           (1 << 6)
+#define CMD6_SCANUP            (1 << 7)
+#define CMD4_REG               0x0f    /* W: Command 3 reg */
+#define CMD4_INTSCAN           (1 << 0)
+#define CMD4_EOIRCV            (1 << 1)
+#define CMD4_ECLKDRV           (1 << 2)
+#define CMD4_SEDIFF            (1 << 3)
+#define CMD4_ECLKRCV           (1 << 4)
+#define DIO_BASE_REG           0x10    /* R/W: 8255 DIO base reg */
+#define COUNTER_A_BASE_REG     0x14    /* R/W: 8253 Counter A base reg */
+#define COUNTER_B_BASE_REG     0x18    /* R/W: 8253 Counter B base reg */
+#define CMD5_REG               0x1c    /* W: Command 5 reg */
+#define CMD5_WRTPRT            (1 << 2)
+#define CMD5_DITHEREN          (1 << 3)
+#define CMD5_CALDACLD          (1 << 4)
+#define CMD5_SCLK              (1 << 5)
+#define CMD5_SDATA             (1 << 6)
+#define CMD5_EEPROMCS          (1 << 7)
+#define STAT2_REG              0x1d    /* R: Status 2 reg */
+#define STAT2_PROMOUT          (1 << 0)
+#define STAT2_OUTA1            (1 << 1)
+#define STAT2_FIFONHF          (1 << 2)
+#define INTERVAL_COUNT_REG     0x1e    /* W: Interval Counter Data reg */
+#define INTERVAL_STROBE_REG    0x1f    /* W: Interval Counter Strobe reg */
+
+#define LABPC_SIZE             0x20    /* size of ISA io region */
+#define LABPC_TIMER_BASE       500     /* 2 MHz master clock */
+#define LABPC_ADC_TIMEOUT      1000
 
 enum scan_mode {
        MODE_SINGLE_CHAN,
@@ -215,187 +160,63 @@ enum scan_mode {
        MODE_MULT_CHAN_DOWN,
 };
 
-static int labpc_cancel(struct comedi_device *dev, struct comedi_subdevice *s);
-static irqreturn_t labpc_interrupt(int irq, void *d);
-static int labpc_drain_fifo(struct comedi_device *dev);
-#ifdef CONFIG_ISA_DMA_API
-static void labpc_drain_dma(struct comedi_device *dev);
-static void handle_isa_dma(struct comedi_device *dev);
-#endif
-static void labpc_drain_dregs(struct comedi_device *dev);
-static int labpc_ai_cmdtest(struct comedi_device *dev,
-                           struct comedi_subdevice *s, struct comedi_cmd *cmd);
-static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s);
-static int labpc_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
-                         struct comedi_insn *insn, unsigned int *data);
-static int labpc_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
-                         struct comedi_insn *insn, unsigned int *data);
-static int labpc_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
-                         struct comedi_insn *insn, unsigned int *data);
-static int labpc_calib_read_insn(struct comedi_device *dev,
-                                struct comedi_subdevice *s,
-                                struct comedi_insn *insn, unsigned int *data);
-static int labpc_calib_write_insn(struct comedi_device *dev,
-                                 struct comedi_subdevice *s,
-                                 struct comedi_insn *insn, unsigned int *data);
-static int labpc_eeprom_read_insn(struct comedi_device *dev,
-                                 struct comedi_subdevice *s,
-                                 struct comedi_insn *insn, unsigned int *data);
-static int labpc_eeprom_write_insn(struct comedi_device *dev,
-                                  struct comedi_subdevice *s,
-                                  struct comedi_insn *insn,
-                                  unsigned int *data);
-static void labpc_adc_timing(struct comedi_device *dev, struct comedi_cmd *cmd,
-                            enum scan_mode scan_mode);
-#ifdef CONFIG_ISA_DMA_API
-static unsigned int labpc_suggest_transfer_size(const struct comedi_cmd *cmd);
-#endif
-static int labpc_dio_mem_callback(int dir, int port, int data,
-                                 unsigned long arg);
-static void labpc_serial_out(struct comedi_device *dev, unsigned int value,
-                            unsigned int num_bits);
-static unsigned int labpc_serial_in(struct comedi_device *dev);
-static unsigned int labpc_eeprom_read(struct comedi_device *dev,
-                                     unsigned int address);
-static unsigned int labpc_eeprom_read_status(struct comedi_device *dev);
-static int labpc_eeprom_write(struct comedi_device *dev,
-                                      unsigned int address,
-                                      unsigned int value);
-static void write_caldac(struct comedi_device *dev, unsigned int channel,
-                        unsigned int value);
-
-/* analog input ranges */
-#define NUM_LABPC_PLUS_AI_RANGES 16
-/* indicates unipolar ranges */
-static const int labpc_plus_is_unipolar[NUM_LABPC_PLUS_AI_RANGES] = {
-       0,
-       0,
-       0,
-       0,
-       0,
-       0,
-       0,
-       0,
-       1,
-       1,
-       1,
-       1,
-       1,
-       1,
-       1,
-       1,
-};
-
-/* map range index to gain bits */
-static const int labpc_plus_ai_gain_bits[NUM_LABPC_PLUS_AI_RANGES] = {
-       0x00,
-       0x10,
-       0x20,
-       0x30,
-       0x40,
-       0x50,
-       0x60,
-       0x70,
-       0x00,
-       0x10,
-       0x20,
-       0x30,
-       0x40,
-       0x50,
-       0x60,
-       0x70,
+static const int labpc_plus_ai_gain_bits[] = {
+       0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
+       0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
 };
 
 static const struct comedi_lrange range_labpc_plus_ai = {
-       NUM_LABPC_PLUS_AI_RANGES,
-       {
-        BIP_RANGE(5),
-        BIP_RANGE(4),
-        BIP_RANGE(2.5),
-        BIP_RANGE(1),
-        BIP_RANGE(0.5),
-        BIP_RANGE(0.25),
-        BIP_RANGE(0.1),
-        BIP_RANGE(0.05),
-        UNI_RANGE(10),
-        UNI_RANGE(8),
-        UNI_RANGE(5),
-        UNI_RANGE(2),
-        UNI_RANGE(1),
-        UNI_RANGE(0.5),
-        UNI_RANGE(0.2),
-        UNI_RANGE(0.1),
-        }
+       16, {
+               BIP_RANGE(5),
+               BIP_RANGE(4),
+               BIP_RANGE(2.5),
+               BIP_RANGE(1),
+               BIP_RANGE(0.5),
+               BIP_RANGE(0.25),
+               BIP_RANGE(0.1),
+               BIP_RANGE(0.05),
+               UNI_RANGE(10),
+               UNI_RANGE(8),
+               UNI_RANGE(5),
+               UNI_RANGE(2),
+               UNI_RANGE(1),
+               UNI_RANGE(0.5),
+               UNI_RANGE(0.2),
+               UNI_RANGE(0.1)
+       }
 };
 
-#define NUM_LABPC_1200_AI_RANGES 14
-/* indicates unipolar ranges */
-const int labpc_1200_is_unipolar[NUM_LABPC_1200_AI_RANGES] = {
-       0,
-       0,
-       0,
-       0,
-       0,
-       0,
-       0,
-       1,
-       1,
-       1,
-       1,
-       1,
-       1,
-       1,
-};
-EXPORT_SYMBOL_GPL(labpc_1200_is_unipolar);
-
-/* map range index to gain bits */
-const int labpc_1200_ai_gain_bits[NUM_LABPC_1200_AI_RANGES] = {
-       0x00,
-       0x20,
-       0x30,
-       0x40,
-       0x50,
-       0x60,
-       0x70,
-       0x00,
-       0x20,
-       0x30,
-       0x40,
-       0x50,
-       0x60,
-       0x70,
+const int labpc_1200_ai_gain_bits[] = {
+       0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
+       0x00, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
 };
 EXPORT_SYMBOL_GPL(labpc_1200_ai_gain_bits);
 
 const struct comedi_lrange range_labpc_1200_ai = {
-       NUM_LABPC_1200_AI_RANGES,
-       {
-        BIP_RANGE(5),
-        BIP_RANGE(2.5),
-        BIP_RANGE(1),
-        BIP_RANGE(0.5),
-        BIP_RANGE(0.25),
-        BIP_RANGE(0.1),
-        BIP_RANGE(0.05),
-        UNI_RANGE(10),
-        UNI_RANGE(5),
-        UNI_RANGE(2),
-        UNI_RANGE(1),
-        UNI_RANGE(0.5),
-        UNI_RANGE(0.2),
-        UNI_RANGE(0.1),
-        }
+       14, {
+               BIP_RANGE(5),
+               BIP_RANGE(2.5),
+               BIP_RANGE(1),
+               BIP_RANGE(0.5),
+               BIP_RANGE(0.25),
+               BIP_RANGE(0.1),
+               BIP_RANGE(0.05),
+               UNI_RANGE(10),
+               UNI_RANGE(5),
+               UNI_RANGE(2),
+               UNI_RANGE(1),
+               UNI_RANGE(0.5),
+               UNI_RANGE(0.2),
+               UNI_RANGE(0.1)
+       }
 };
 EXPORT_SYMBOL_GPL(range_labpc_1200_ai);
 
-/* analog output ranges */
-#define AO_RANGE_IS_UNIPOLAR 0x1
 static const struct comedi_lrange range_labpc_ao = {
-       2,
-       {
-        BIP_RANGE(5),
-        UNI_RANGE(10),
-        }
+       2, {
+               BIP_RANGE(5),
+               UNI_RANGE(10)
+       }
 };
 
 /* functions that do inb/outb and readb/writeb so we can use
@@ -420,421 +241,440 @@ static inline void labpc_writeb(unsigned int byte, unsigned long address)
        writeb(byte, (void __iomem *)address);
 }
 
-static const struct labpc_board_struct labpc_boards[] = {
-       {
-        .name = "lab-pc-1200",
-        .ai_speed = 10000,
-        .bustype = isa_bustype,
-        .register_layout = labpc_1200_layout,
-        .has_ao = 1,
-        .ai_range_table = &range_labpc_1200_ai,
-        .ai_range_code = labpc_1200_ai_gain_bits,
-        .ai_range_is_unipolar = labpc_1200_is_unipolar,
-        .ai_scan_up = 1,
-        .memory_mapped_io = 0,
-        },
+static const struct labpc_boardinfo labpc_boards[] = {
        {
-        .name = "lab-pc-1200ai",
-        .ai_speed = 10000,
-        .bustype = isa_bustype,
-        .register_layout = labpc_1200_layout,
-        .has_ao = 0,
-        .ai_range_table = &range_labpc_1200_ai,
-        .ai_range_code = labpc_1200_ai_gain_bits,
-        .ai_range_is_unipolar = labpc_1200_is_unipolar,
-        .ai_scan_up = 1,
-        .memory_mapped_io = 0,
-        },
-       {
-        .name = "lab-pc+",
-        .ai_speed = 12000,
-        .bustype = isa_bustype,
-        .register_layout = labpc_plus_layout,
-        .has_ao = 1,
-        .ai_range_table = &range_labpc_plus_ai,
-        .ai_range_code = labpc_plus_ai_gain_bits,
-        .ai_range_is_unipolar = labpc_plus_is_unipolar,
-        .ai_scan_up = 0,
-        .memory_mapped_io = 0,
-        },
+               .name                   = "lab-pc-1200",
+               .ai_speed               = 10000,
+               .bustype                = isa_bustype,
+               .register_layout        = labpc_1200_layout,
+               .has_ao                 = 1,
+               .ai_range_table         = &range_labpc_1200_ai,
+               .ai_range_code          = labpc_1200_ai_gain_bits,
+               .ai_scan_up             = 1,
+       }, {
+               .name                   = "lab-pc-1200ai",
+               .ai_speed               = 10000,
+               .bustype                = isa_bustype,
+               .register_layout        = labpc_1200_layout,
+               .ai_range_table         = &range_labpc_1200_ai,
+               .ai_range_code          = labpc_1200_ai_gain_bits,
+               .ai_scan_up             = 1,
+       }, {
+               .name                   = "lab-pc+",
+               .ai_speed               = 12000,
+               .bustype                = isa_bustype,
+               .register_layout        = labpc_plus_layout,
+               .has_ao                 = 1,
+               .ai_range_table         = &range_labpc_plus_ai,
+               .ai_range_code          = labpc_plus_ai_gain_bits,
+       },
 #ifdef CONFIG_COMEDI_PCI_DRIVERS
        {
-        .name = "pci-1200",
-        .device_id = 0x161,
-        .ai_speed = 10000,
-        .bustype = pci_bustype,
-        .register_layout = labpc_1200_layout,
-        .has_ao = 1,
-        .ai_range_table = &range_labpc_1200_ai,
-        .ai_range_code = labpc_1200_ai_gain_bits,
-        .ai_range_is_unipolar = labpc_1200_is_unipolar,
-        .ai_scan_up = 1,
-        .memory_mapped_io = 1,
-        },
-/* dummy entry so pci board works when comedi_config is passed driver name */
-       {
-        .name = DRV_NAME,
-        .bustype = pci_bustype,
-        },
+               .name                   = "pci-1200",
+               .device_id              = 0x161,
+               .ai_speed               = 10000,
+               .bustype                = pci_bustype,
+               .register_layout        = labpc_1200_layout,
+               .has_ao                 = 1,
+               .ai_range_table         = &range_labpc_1200_ai,
+               .ai_range_code          = labpc_1200_ai_gain_bits,
+               .ai_scan_up             = 1,
+               .has_mmio               = 1,
+       },
 #endif
 };
 
-/*
- * Useful for shorthand access to the particular board structure
- */
-#define thisboard ((struct labpc_board_struct *)dev->board_ptr)
-
 /* size in bytes of dma buffer */
 static const int dma_buffer_size = 0xff00;
 /* 2 bytes per sample */
 static const int sample_size = 2;
 
-static inline int labpc_counter_load(struct comedi_device *dev,
-                                    unsigned long base_address,
-                                    unsigned int counter_number,
-                                    unsigned int count, unsigned int mode)
+static int labpc_counter_load(struct comedi_device *dev,
+                             unsigned long base_address,
+                             unsigned int counter_number,
+                             unsigned int count, unsigned int mode)
 {
-       if (thisboard->memory_mapped_io)
+       const struct labpc_boardinfo *board = comedi_board(dev);
+
+       if (board->has_mmio)
                return i8254_mm_load((void __iomem *)base_address, 0,
                                     counter_number, count, mode);
        else
                return i8254_load(base_address, 0, counter_number, count, mode);
 }
 
-int labpc_common_attach(struct comedi_device *dev, unsigned long iobase,
-                       unsigned int irq, unsigned int dma_chan)
+static int labpc_counter_set_mode(struct comedi_device *dev,
+                                 unsigned long base_address,
+                                 unsigned int counter_number,
+                                 unsigned int mode)
 {
-       struct labpc_private *devpriv = dev->private;
-       struct comedi_subdevice *s;
-       int i;
-       unsigned long isr_flags;
-#ifdef CONFIG_ISA_DMA_API
-       unsigned long dma_flags;
-#endif
-       short lsb, msb;
-       int ret;
-
-       dev_info(dev->class_dev, "ni_labpc: %s\n", thisboard->name);
-       if (iobase == 0) {
-               dev_err(dev->class_dev, "io base address is zero!\n");
-               return -EINVAL;
-       }
-       /*  request io regions for isa boards */
-       if (thisboard->bustype == isa_bustype) {
-               /* check if io addresses are available */
-               if (!request_region(iobase, LABPC_SIZE, DRV_NAME)) {
-                       dev_err(dev->class_dev, "I/O port conflict\n");
-                       return -EIO;
-               }
-       }
-       dev->iobase = iobase;
-
-       if (thisboard->memory_mapped_io) {
-               devpriv->read_byte = labpc_readb;
-               devpriv->write_byte = labpc_writeb;
-       } else {
-               devpriv->read_byte = labpc_inb;
-               devpriv->write_byte = labpc_outb;
-       }
-       /* initialize board's command registers */
-       devpriv->write_byte(devpriv->command1_bits, dev->iobase + COMMAND1_REG);
-       devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG);
-       devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG);
-       devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG);
-       if (thisboard->register_layout == labpc_1200_layout) {
-               devpriv->write_byte(devpriv->command5_bits,
-                                   dev->iobase + COMMAND5_REG);
-               devpriv->write_byte(devpriv->command6_bits,
-                                   dev->iobase + COMMAND6_REG);
-       }
-
-       /* grab our IRQ */
-       if (irq) {
-               isr_flags = 0;
-               if (thisboard->bustype == pci_bustype
-                   || thisboard->bustype == pcmcia_bustype)
-                       isr_flags |= IRQF_SHARED;
-               if (request_irq(irq, labpc_interrupt, isr_flags,
-                               DRV_NAME, dev)) {
-                       dev_err(dev->class_dev, "unable to allocate irq %u\n",
-                               irq);
-                       return -EINVAL;
-               }
-       }
-       dev->irq = irq;
-
-#ifdef CONFIG_ISA_DMA_API
-       /* grab dma channel */
-       if (dma_chan > 3) {
-               dev_err(dev->class_dev, "invalid dma channel %u\n", dma_chan);
-               return -EINVAL;
-       } else if (dma_chan) {
-               /* allocate dma buffer */
-               devpriv->dma_buffer = kmalloc(dma_buffer_size,
-                                             GFP_KERNEL | GFP_DMA);
-               if (devpriv->dma_buffer == NULL)
-                       return -ENOMEM;
-
-               if (request_dma(dma_chan, DRV_NAME)) {
-                       dev_err(dev->class_dev,
-                               "failed to allocate dma channel %u\n",
-                               dma_chan);
-                       return -EINVAL;
-               }
-               devpriv->dma_chan = dma_chan;
-               dma_flags = claim_dma_lock();
-               disable_dma(devpriv->dma_chan);
-               set_dma_mode(devpriv->dma_chan, DMA_MODE_READ);
-               release_dma_lock(dma_flags);
-       }
-#endif
-
-       dev->board_name = thisboard->name;
-
-       ret = comedi_alloc_subdevices(dev, 5);
-       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_COMMON | SDF_DIFF | SDF_CMD_READ;
-       s->n_chan = 8;
-       s->len_chanlist = 8;
-       s->maxdata = (1 << 12) - 1;     /* 12 bit resolution */
-       s->range_table = thisboard->ai_range_table;
-       s->do_cmd = labpc_ai_cmd;
-       s->do_cmdtest = labpc_ai_cmdtest;
-       s->insn_read = labpc_ai_rinsn;
-       s->cancel = labpc_cancel;
-
-       /* analog output */
-       s = &dev->subdevices[1];
-       if (thisboard->has_ao) {
-               /*
-                * Could provide command support, except it only has a
-                * one sample hardware buffer for analog output and no
-                * underrun flag.
-                */
-               s->type = COMEDI_SUBD_AO;
-               s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND;
-               s->n_chan = NUM_AO_CHAN;
-               s->maxdata = (1 << 12) - 1;     /*  12 bit resolution */
-               s->range_table = &range_labpc_ao;
-               s->insn_read = labpc_ao_rinsn;
-               s->insn_write = labpc_ao_winsn;
-               /* initialize analog outputs to a known value */
-               for (i = 0; i < s->n_chan; i++) {
-                       devpriv->ao_value[i] = s->maxdata / 2;
-                       lsb = devpriv->ao_value[i] & 0xff;
-                       msb = (devpriv->ao_value[i] >> 8) & 0xff;
-                       devpriv->write_byte(lsb, dev->iobase + DAC_LSB_REG(i));
-                       devpriv->write_byte(msb, dev->iobase + DAC_MSB_REG(i));
-               }
-       } else {
-               s->type = COMEDI_SUBD_UNUSED;
-       }
+       const struct labpc_boardinfo *board = comedi_board(dev);
 
-       /* 8255 dio */
-       s = &dev->subdevices[2];
-       /*  if board uses io memory we have to give a custom callback
-        * function to the 8255 driver */
-       if (thisboard->memory_mapped_io)
-               subdev_8255_init(dev, s, labpc_dio_mem_callback,
-                                (unsigned long)(dev->iobase + DIO_BASE_REG));
+       if (board->has_mmio)
+               return i8254_mm_set_mode((void __iomem *)base_address, 0,
+                                        counter_number, mode);
        else
-               subdev_8255_init(dev, s, NULL, dev->iobase + DIO_BASE_REG);
+               return i8254_set_mode(base_address, 0, counter_number, mode);
+}
 
-       /*  calibration subdevices for boards that have one */
-       s = &dev->subdevices[3];
-       if (thisboard->register_layout == labpc_1200_layout) {
-               s->type = COMEDI_SUBD_CALIB;
-               s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
-               s->n_chan = 16;
-               s->maxdata = 0xff;
-               s->insn_read = labpc_calib_read_insn;
-               s->insn_write = labpc_calib_write_insn;
+static bool labpc_range_is_unipolar(struct comedi_subdevice *s,
+                                   unsigned int range)
+{
+       return s->range_table->range[range].min >= 0;
+}
 
-               for (i = 0; i < s->n_chan; i++)
-                       write_caldac(dev, i, s->maxdata / 2);
-       } else
-               s->type = COMEDI_SUBD_UNUSED;
+static int labpc_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
+{
+       struct labpc_private *devpriv = dev->private;
+       unsigned long flags;
 
-       /* EEPROM */
-       s = &dev->subdevices[4];
-       if (thisboard->register_layout == labpc_1200_layout) {
-               s->type = COMEDI_SUBD_MEMORY;
-               s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
-               s->n_chan = EEPROM_SIZE;
-               s->maxdata = 0xff;
-               s->insn_read = labpc_eeprom_read_insn;
-               s->insn_write = labpc_eeprom_write_insn;
-
-               for (i = 0; i < EEPROM_SIZE; i++)
-                       devpriv->eeprom_data[i] = labpc_eeprom_read(dev, i);
-       } else
-               s->type = COMEDI_SUBD_UNUSED;
+       spin_lock_irqsave(&dev->spinlock, flags);
+       devpriv->cmd2 &= ~(CMD2_SWTRIG | CMD2_HWTRIG | CMD2_PRETRIG);
+       devpriv->write_byte(devpriv->cmd2, dev->iobase + CMD2_REG);
+       spin_unlock_irqrestore(&dev->spinlock, flags);
+
+       devpriv->cmd3 = 0;
+       devpriv->write_byte(devpriv->cmd3, dev->iobase + CMD3_REG);
 
        return 0;
 }
-EXPORT_SYMBOL_GPL(labpc_common_attach);
 
-static const struct labpc_board_struct *
-labpc_pci_find_boardinfo(struct pci_dev *pcidev)
+static void labpc_ai_set_chan_and_gain(struct comedi_device *dev,
+                                      enum scan_mode mode,
+                                      unsigned int chan,
+                                      unsigned int range,
+                                      unsigned int aref)
 {
-       unsigned int device_id = pcidev->device;
-       unsigned int n;
+       const struct labpc_boardinfo *board = comedi_board(dev);
+       struct labpc_private *devpriv = dev->private;
 
-       for (n = 0; n < ARRAY_SIZE(labpc_boards); n++) {
-               const struct labpc_board_struct *board = &labpc_boards[n];
-               if (board->bustype == pci_bustype &&
-                   board->device_id == device_id)
-                       return board;
-       }
-       return NULL;
+       /* munge channel bits for differential/scan disabled mode */
+       if ((mode == MODE_SINGLE_CHAN || mode == MODE_SINGLE_CHAN_INTERVAL) &&
+           aref == AREF_DIFF)
+               chan *= 2;
+       devpriv->cmd1 = CMD1_MA(chan);
+       devpriv->cmd1 |= board->ai_range_code[range];
+
+       devpriv->write_byte(devpriv->cmd1, dev->iobase + CMD1_REG);
 }
 
-static int labpc_auto_attach(struct comedi_device *dev,
-                                      unsigned long context_unused)
+static void labpc_setup_cmd6_reg(struct comedi_device *dev,
+                                struct comedi_subdevice *s,
+                                enum scan_mode mode,
+                                enum transfer_type xfer,
+                                unsigned int range,
+                                unsigned int aref,
+                                bool ena_intr)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       struct labpc_private *devpriv;
-       unsigned long iobase;
-       unsigned int irq;
-       int ret;
+       const struct labpc_boardinfo *board = comedi_board(dev);
+       struct labpc_private *devpriv = dev->private;
 
-       if (!IS_ENABLED(CONFIG_COMEDI_PCI_DRIVERS))
-               return -ENODEV;
+       if (board->register_layout != labpc_1200_layout)
+               return;
 
-       devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
-       if (!devpriv)
-               return -ENOMEM;
-       dev->private = devpriv;
+       /* reference inputs to ground or common? */
+       if (aref != AREF_GROUND)
+               devpriv->cmd6 |= CMD6_NRSE;
+       else
+               devpriv->cmd6 &= ~CMD6_NRSE;
 
-       dev->board_ptr = labpc_pci_find_boardinfo(pcidev);
-       if (!dev->board_ptr)
-               return -ENODEV;
-       devpriv->mite = mite_alloc(pcidev);
-       if (!devpriv->mite)
-               return -ENOMEM;
-       ret = mite_setup(devpriv->mite);
-       if (ret < 0)
-               return ret;
-       iobase = (unsigned long)devpriv->mite->daq_io_addr;
-       irq = mite_irq(devpriv->mite);
-       return labpc_common_attach(dev, iobase, irq, 0);
-}
+       /* bipolar or unipolar range? */
+       if (labpc_range_is_unipolar(s, range))
+               devpriv->cmd6 |= CMD6_ADCUNI;
+       else
+               devpriv->cmd6 &= ~CMD6_ADCUNI;
 
-static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
-{
-       struct labpc_private *devpriv;
-       unsigned long iobase = 0;
-       unsigned int irq = 0;
-       unsigned int dma_chan = 0;
+       /*  interrupt on fifo half full? */
+       if (xfer == fifo_half_full_transfer)
+               devpriv->cmd6 |= CMD6_HFINTEN;
+       else
+               devpriv->cmd6 &= ~CMD6_HFINTEN;
 
-       devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
-       if (!devpriv)
-               return -ENOMEM;
-       dev->private = devpriv;
+       /* enable interrupt on counter a1 terminal count? */
+       if (ena_intr)
+               devpriv->cmd6 |= CMD6_DQINTEN;
+       else
+               devpriv->cmd6 &= ~CMD6_DQINTEN;
 
-       /* get base address, irq etc. based on bustype */
-       switch (thisboard->bustype) {
-       case isa_bustype:
-#ifdef CONFIG_ISA_DMA_API
-               iobase = it->options[0];
-               irq = it->options[1];
-               dma_chan = it->options[2];
-#else
-               dev_err(dev->class_dev,
-                       "ni_labpc driver has not been built with ISA DMA support.\n");
-               return -EINVAL;
-#endif
-               break;
-       case pci_bustype:
-#ifdef CONFIG_COMEDI_PCI_DRIVERS
-               dev_err(dev->class_dev,
-                       "manual configuration of PCI board '%s' is not supported\n",
-                       thisboard->name);
-               return -EINVAL;
-#else
-               dev_err(dev->class_dev,
-                       "ni_labpc driver has not been built with PCI support.\n");
-               return -EINVAL;
-#endif
-               break;
-       default:
-               dev_err(dev->class_dev,
-                       "ni_labpc: bug! couldn't determine board type\n");
-               return -EINVAL;
-               break;
-       }
+       /* are we scanning up or down through channels? */
+       if (mode == MODE_MULT_CHAN_UP)
+               devpriv->cmd6 |= CMD6_SCANUP;
+       else
+               devpriv->cmd6 &= ~CMD6_SCANUP;
 
-       return labpc_common_attach(dev, iobase, irq, dma_chan);
+       devpriv->write_byte(devpriv->cmd6, dev->iobase + CMD6_REG);
 }
 
-void labpc_common_detach(struct comedi_device *dev)
+static unsigned int labpc_read_adc_fifo(struct comedi_device *dev)
 {
        struct labpc_private *devpriv = dev->private;
-       struct comedi_subdevice *s;
+       unsigned int lsb = devpriv->read_byte(dev->iobase + ADC_FIFO_REG);
+       unsigned int msb = devpriv->read_byte(dev->iobase + ADC_FIFO_REG);
 
-       if (!thisboard)
-               return;
-       if (dev->subdevices) {
-               s = &dev->subdevices[2];
-               subdev_8255_cleanup(dev, s);
-       }
-#ifdef CONFIG_ISA_DMA_API
-       /* only free stuff if it has been allocated by _attach */
-       kfree(devpriv->dma_buffer);
-       if (devpriv->dma_chan)
-               free_dma(devpriv->dma_chan);
-#endif
-       if (dev->irq)
-               free_irq(dev->irq, dev);
-       if (thisboard->bustype == isa_bustype && dev->iobase)
-               release_region(dev->iobase, LABPC_SIZE);
-#ifdef CONFIG_COMEDI_PCI_DRIVERS
-       if (devpriv->mite) {
-               mite_unsetup(devpriv->mite);
-               mite_free(devpriv->mite);
-       }
-#endif
-};
-EXPORT_SYMBOL_GPL(labpc_common_detach);
+       return (msb << 8) | lsb;
+}
 
-static void labpc_clear_adc_fifo(const struct comedi_device *dev)
+static void labpc_clear_adc_fifo(struct comedi_device *dev)
 {
        struct labpc_private *devpriv = dev->private;
 
-       devpriv->write_byte(0x1, dev->iobase + ADC_CLEAR_REG);
-       devpriv->read_byte(dev->iobase + ADC_FIFO_REG);
-       devpriv->read_byte(dev->iobase + ADC_FIFO_REG);
+       devpriv->write_byte(0x1, dev->iobase + ADC_FIFO_CLEAR_REG);
+       labpc_read_adc_fifo(dev);
 }
 
-static int labpc_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
+static int labpc_ai_wait_for_data(struct comedi_device *dev,
+                                 int timeout)
 {
        struct labpc_private *devpriv = dev->private;
-       unsigned long flags;
-
-       spin_lock_irqsave(&dev->spinlock, flags);
-       devpriv->command2_bits &= ~SWTRIG_BIT & ~HWTRIG_BIT & ~PRETRIG_BIT;
-       devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG);
-       spin_unlock_irqrestore(&dev->spinlock, flags);
-
-       devpriv->command3_bits = 0;
-       devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG);
+       int i;
 
-       return 0;
+       for (i = 0; i < timeout; i++) {
+               devpriv->stat1 = devpriv->read_byte(dev->iobase + STAT1_REG);
+               if (devpriv->stat1 & STAT1_DAVAIL)
+                       return 0;
+               udelay(1);
+       }
+       return -ETIME;
 }
 
-static enum scan_mode labpc_ai_scan_mode(const struct comedi_cmd *cmd)
+static int labpc_ai_insn_read(struct comedi_device *dev,
+                             struct comedi_subdevice *s,
+                             struct comedi_insn *insn,
+                             unsigned int *data)
 {
-       if (cmd->chanlist_len == 1)
-               return MODE_SINGLE_CHAN;
-
-       /* chanlist may be NULL during cmdtest. */
+       struct labpc_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);
+       int ret;
+       int i;
+
+       /* disable timed conversions, interrupt generation and dma */
+       labpc_cancel(dev, s);
+
+       labpc_ai_set_chan_and_gain(dev, MODE_SINGLE_CHAN, chan, range, aref);
+
+       labpc_setup_cmd6_reg(dev, s, MODE_SINGLE_CHAN, fifo_not_empty_transfer,
+                            range, aref, false);
+
+       /* setup cmd4 register */
+       devpriv->cmd4 = 0;
+       devpriv->cmd4 |= CMD4_ECLKRCV;
+       /* single-ended/differential */
+       if (aref == AREF_DIFF)
+               devpriv->cmd4 |= CMD4_SEDIFF;
+       devpriv->write_byte(devpriv->cmd4, dev->iobase + CMD4_REG);
+
+       /* initialize pacer counter to prevent any problems */
+       ret = labpc_counter_set_mode(dev, dev->iobase + COUNTER_A_BASE_REG,
+                                    0, I8254_MODE2);
+       if (ret)
+               return ret;
+
+       labpc_clear_adc_fifo(dev);
+
+       for (i = 0; i < insn->n; i++) {
+               /* trigger conversion */
+               devpriv->write_byte(0x1, dev->iobase + ADC_START_CONVERT_REG);
+
+               ret = labpc_ai_wait_for_data(dev, LABPC_ADC_TIMEOUT);
+               if (ret)
+                       return ret;
+
+               data[i] = labpc_read_adc_fifo(dev);
+       }
+
+       return insn->n;
+}
+
+#ifdef CONFIG_ISA_DMA_API
+/* utility function that suggests a dma transfer size in bytes */
+static unsigned int labpc_suggest_transfer_size(const struct comedi_cmd *cmd)
+{
+       unsigned int size;
+       unsigned int freq;
+
+       if (cmd->convert_src == TRIG_TIMER)
+               freq = 1000000000 / cmd->convert_arg;
+       /* return some default value */
+       else
+               freq = 0xffffffff;
+
+       /* make buffer fill in no more than 1/3 second */
+       size = (freq / 3) * sample_size;
+
+       /* set a minimum and maximum size allowed */
+       if (size > dma_buffer_size)
+               size = dma_buffer_size - dma_buffer_size % sample_size;
+       else if (size < sample_size)
+               size = sample_size;
+
+       return size;
+}
+#endif
+
+static bool labpc_use_continuous_mode(const struct comedi_cmd *cmd,
+                                     enum scan_mode mode)
+{
+       if (mode == MODE_SINGLE_CHAN || cmd->scan_begin_src == TRIG_FOLLOW)
+               return true;
+
+       return false;
+}
+
+static unsigned int labpc_ai_convert_period(const struct comedi_cmd *cmd,
+                                           enum scan_mode mode)
+{
+       if (cmd->convert_src != TRIG_TIMER)
+               return 0;
+
+       if (mode == MODE_SINGLE_CHAN && cmd->scan_begin_src == TRIG_TIMER)
+               return cmd->scan_begin_arg;
+
+       return cmd->convert_arg;
+}
+
+static void labpc_set_ai_convert_period(struct comedi_cmd *cmd,
+                                       enum scan_mode mode, unsigned int ns)
+{
+       if (cmd->convert_src != TRIG_TIMER)
+               return;
+
+       if (mode == MODE_SINGLE_CHAN &&
+           cmd->scan_begin_src == TRIG_TIMER) {
+               cmd->scan_begin_arg = ns;
+               if (cmd->convert_arg > cmd->scan_begin_arg)
+                       cmd->convert_arg = cmd->scan_begin_arg;
+       } else
+               cmd->convert_arg = ns;
+}
+
+static unsigned int labpc_ai_scan_period(const struct comedi_cmd *cmd,
+                                       enum scan_mode mode)
+{
+       if (cmd->scan_begin_src != TRIG_TIMER)
+               return 0;
+
+       if (mode == MODE_SINGLE_CHAN && cmd->convert_src == TRIG_TIMER)
+               return 0;
+
+       return cmd->scan_begin_arg;
+}
+
+static void labpc_set_ai_scan_period(struct comedi_cmd *cmd,
+                                    enum scan_mode mode, unsigned int ns)
+{
+       if (cmd->scan_begin_src != TRIG_TIMER)
+               return;
+
+       if (mode == MODE_SINGLE_CHAN && cmd->convert_src == TRIG_TIMER)
+               return;
+
+       cmd->scan_begin_arg = ns;
+}
+
+/* figures out what counter values to use based on command */
+static void labpc_adc_timing(struct comedi_device *dev, struct comedi_cmd *cmd,
+                            enum scan_mode mode)
+{
+       struct labpc_private *devpriv = dev->private;
+       /* max value for 16 bit counter in mode 2 */
+       const int max_counter_value = 0x10000;
+       /* min value for 16 bit counter in mode 2 */
+       const int min_counter_value = 2;
+       unsigned int base_period;
+       unsigned int scan_period;
+       unsigned int convert_period;
+
+       /*
+        * if both convert and scan triggers are TRIG_TIMER, then they
+        * both rely on counter b0
+        */
+       convert_period = labpc_ai_convert_period(cmd, mode);
+       scan_period = labpc_ai_scan_period(cmd, mode);
+       if (convert_period && scan_period) {
+               /*
+                * pick the lowest b0 divisor value we can (for maximum input
+                * clock speed on convert and scan counters)
+                */
+               devpriv->divisor_b0 = (scan_period - 1) /
+                   (LABPC_TIMER_BASE * max_counter_value) + 1;
+               if (devpriv->divisor_b0 < min_counter_value)
+                       devpriv->divisor_b0 = min_counter_value;
+               if (devpriv->divisor_b0 > max_counter_value)
+                       devpriv->divisor_b0 = max_counter_value;
+
+               base_period = LABPC_TIMER_BASE * devpriv->divisor_b0;
+
+               /*  set a0 for conversion frequency and b1 for scan frequency */
+               switch (cmd->flags & TRIG_ROUND_MASK) {
+               default:
+               case TRIG_ROUND_NEAREST:
+                       devpriv->divisor_a0 =
+                           (convert_period + (base_period / 2)) / base_period;
+                       devpriv->divisor_b1 =
+                           (scan_period + (base_period / 2)) / base_period;
+                       break;
+               case TRIG_ROUND_UP:
+                       devpriv->divisor_a0 =
+                           (convert_period + (base_period - 1)) / base_period;
+                       devpriv->divisor_b1 =
+                           (scan_period + (base_period - 1)) / base_period;
+                       break;
+               case TRIG_ROUND_DOWN:
+                       devpriv->divisor_a0 = convert_period / base_period;
+                       devpriv->divisor_b1 = scan_period / base_period;
+                       break;
+               }
+               /*  make sure a0 and b1 values are acceptable */
+               if (devpriv->divisor_a0 < min_counter_value)
+                       devpriv->divisor_a0 = min_counter_value;
+               if (devpriv->divisor_a0 > max_counter_value)
+                       devpriv->divisor_a0 = max_counter_value;
+               if (devpriv->divisor_b1 < min_counter_value)
+                       devpriv->divisor_b1 = min_counter_value;
+               if (devpriv->divisor_b1 > max_counter_value)
+                       devpriv->divisor_b1 = max_counter_value;
+               /*  write corrected timings to command */
+               labpc_set_ai_convert_period(cmd, mode,
+                                           base_period * devpriv->divisor_a0);
+               labpc_set_ai_scan_period(cmd, mode,
+                                        base_period * devpriv->divisor_b1);
+               /*
+                * if only one TRIG_TIMER is used, we can employ the generic
+                * cascaded timing functions
+                */
+       } else if (scan_period) {
+               /*
+                * calculate cascaded counter values
+                * that give desired scan timing
+                */
+               i8253_cascade_ns_to_timer_2div(LABPC_TIMER_BASE,
+                                              &(devpriv->divisor_b1),
+                                              &(devpriv->divisor_b0),
+                                              &scan_period,
+                                              cmd->flags & TRIG_ROUND_MASK);
+               labpc_set_ai_scan_period(cmd, mode, scan_period);
+       } else if (convert_period) {
+               /*
+                * calculate cascaded counter values
+                * that give desired conversion timing
+                */
+               i8253_cascade_ns_to_timer_2div(LABPC_TIMER_BASE,
+                                              &(devpriv->divisor_a0),
+                                              &(devpriv->divisor_b0),
+                                              &convert_period,
+                                              cmd->flags & TRIG_ROUND_MASK);
+               labpc_set_ai_convert_period(cmd, mode, convert_period);
+       }
+}
+
+static enum scan_mode labpc_ai_scan_mode(const struct comedi_cmd *cmd)
+{
+       if (cmd->chanlist_len == 1)
+               return MODE_SINGLE_CHAN;
+
+       /* chanlist may be NULL during cmdtest. */
        if (cmd->chanlist == NULL)
                return MODE_MULT_CHAN_UP;
 
@@ -923,101 +763,39 @@ static int labpc_ai_chanlist_invalid(const struct comedi_device *dev,
        return 0;
 }
 
-static int labpc_use_continuous_mode(const struct comedi_cmd *cmd,
-                                    enum scan_mode mode)
+static int labpc_ai_cmdtest(struct comedi_device *dev,
+                           struct comedi_subdevice *s, struct comedi_cmd *cmd)
 {
-       if (mode == MODE_SINGLE_CHAN)
-               return 1;
+       const struct labpc_boardinfo *board = comedi_board(dev);
+       int err = 0;
+       int tmp, tmp2;
+       unsigned int stop_mask;
+       enum scan_mode mode;
 
-       if (cmd->scan_begin_src == TRIG_FOLLOW)
-               return 1;
+       /* Step 1 : check if triggers are trivially valid */
 
-       return 0;
-}
+       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
+       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
 
-static unsigned int labpc_ai_convert_period(const struct comedi_cmd *cmd,
-                                           enum scan_mode mode)
-{
-       if (cmd->convert_src != TRIG_TIMER)
-               return 0;
+       stop_mask = TRIG_COUNT | TRIG_NONE;
+       if (board->register_layout == labpc_1200_layout)
+               stop_mask |= TRIG_EXT;
+       err |= cfc_check_trigger_src(&cmd->stop_src, stop_mask);
 
-       if (mode == MODE_SINGLE_CHAN && cmd->scan_begin_src == TRIG_TIMER)
-               return cmd->scan_begin_arg;
+       if (err)
+               return 1;
 
-       return cmd->convert_arg;
-}
+       /* Step 2a : make sure trigger sources are unique */
 
-static void labpc_set_ai_convert_period(struct comedi_cmd *cmd,
-                                       enum scan_mode mode, unsigned int ns)
-{
-       if (cmd->convert_src != TRIG_TIMER)
-               return;
+       err |= cfc_check_trigger_is_unique(cmd->start_src);
+       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
+       err |= cfc_check_trigger_is_unique(cmd->convert_src);
+       err |= cfc_check_trigger_is_unique(cmd->stop_src);
 
-       if (mode == MODE_SINGLE_CHAN &&
-           cmd->scan_begin_src == TRIG_TIMER) {
-               cmd->scan_begin_arg = ns;
-               if (cmd->convert_arg > cmd->scan_begin_arg)
-                       cmd->convert_arg = cmd->scan_begin_arg;
-       } else
-               cmd->convert_arg = ns;
-}
-
-static unsigned int labpc_ai_scan_period(const struct comedi_cmd *cmd,
-                                       enum scan_mode mode)
-{
-       if (cmd->scan_begin_src != TRIG_TIMER)
-               return 0;
-
-       if (mode == MODE_SINGLE_CHAN && cmd->convert_src == TRIG_TIMER)
-               return 0;
-
-       return cmd->scan_begin_arg;
-}
-
-static void labpc_set_ai_scan_period(struct comedi_cmd *cmd,
-                                    enum scan_mode mode, unsigned int ns)
-{
-       if (cmd->scan_begin_src != TRIG_TIMER)
-               return;
-
-       if (mode == MODE_SINGLE_CHAN && cmd->convert_src == TRIG_TIMER)
-               return;
-
-       cmd->scan_begin_arg = ns;
-}
-
-static int labpc_ai_cmdtest(struct comedi_device *dev,
-                           struct comedi_subdevice *s, struct comedi_cmd *cmd)
-{
-       int err = 0;
-       int tmp, tmp2;
-       unsigned int stop_mask;
-       enum scan_mode mode;
-
-       /* Step 1 : check if triggers are trivially valid */
-
-       err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
-       err |= cfc_check_trigger_src(&cmd->scan_begin_src,
-                                       TRIG_TIMER | TRIG_FOLLOW | TRIG_EXT);
-       err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER | TRIG_EXT);
-       err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
-
-       stop_mask = TRIG_COUNT | TRIG_NONE;
-       if (thisboard->register_layout == labpc_1200_layout)
-               stop_mask |= TRIG_EXT;
-       err |= cfc_check_trigger_src(&cmd->stop_src, stop_mask);
-
-       if (err)
-               return 1;
-
-       /* Step 2a : make sure trigger sources are unique */
-
-       err |= cfc_check_trigger_is_unique(cmd->start_src);
-       err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
-       err |= cfc_check_trigger_is_unique(cmd->convert_src);
-       err |= cfc_check_trigger_is_unique(cmd->stop_src);
-
-       /* Step 2b : and mutually compatible */
+       /* 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)
@@ -1037,7 +815,7 @@ static int labpc_ai_cmdtest(struct comedi_device *dev,
 
        if (cmd->convert_src == TRIG_TIMER)
                err |= cfc_check_trigger_arg_min(&cmd->convert_arg,
-                                                thisboard->ai_speed);
+                                                board->ai_speed);
 
        /* make sure scan timing is not too fast */
        if (cmd->scan_begin_src == TRIG_TIMER) {
@@ -1045,7 +823,7 @@ static int labpc_ai_cmdtest(struct comedi_device *dev,
                        err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
                                        cmd->convert_arg * cmd->chanlist_len);
                err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
-                               thisboard->ai_speed * cmd->chanlist_len);
+                               board->ai_speed * cmd->chanlist_len);
        }
 
        switch (cmd->stop_src) {
@@ -1086,34 +864,23 @@ static int labpc_ai_cmdtest(struct comedi_device *dev,
 
 static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 {
+       const struct labpc_boardinfo *board = comedi_board(dev);
        struct labpc_private *devpriv = dev->private;
-       int channel, range, aref;
-#ifdef CONFIG_ISA_DMA_API
-       unsigned long irq_flags;
-#endif
-       int ret;
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
+       enum scan_mode mode = labpc_ai_scan_mode(cmd);
+       unsigned int chanspec = (mode == MODE_MULT_CHAN_UP)
+                               ? cmd->chanlist[cmd->chanlist_len - 1]
+                               : cmd->chanlist[0];
+       unsigned int chan = CR_CHAN(chanspec);
+       unsigned int range = CR_RANGE(chanspec);
+       unsigned int aref = CR_AREF(chanspec);
        enum transfer_type xfer;
-       enum scan_mode mode;
        unsigned long flags;
-
-       if (!dev->irq) {
-               comedi_error(dev, "no irq assigned, cannot perform command");
-               return -1;
-       }
-
-       range = CR_RANGE(cmd->chanlist[0]);
-       aref = CR_AREF(cmd->chanlist[0]);
+       int ret;
 
        /* make sure board is disabled before setting up acquisition */
-       spin_lock_irqsave(&dev->spinlock, flags);
-       devpriv->command2_bits &= ~SWTRIG_BIT & ~HWTRIG_BIT & ~PRETRIG_BIT;
-       devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG);
-       spin_unlock_irqrestore(&dev->spinlock, flags);
-
-       devpriv->command3_bits = 0;
-       devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG);
+       labpc_cancel(dev, s);
 
        /*  initialize software conversion count */
        if (cmd->stop_src == TRIG_COUNT)
@@ -1126,17 +893,17 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                 * (pc+ manual says this is minimum allowed) using mode 0
                 */
                ret = labpc_counter_load(dev, dev->iobase + COUNTER_A_BASE_REG,
-                                        1, 3, 0);
-               if (ret < 0) {
-                       comedi_error(dev, "error loading counter a1");
-                       return -1;
-               }
-       } else                  /*
-                                * otherwise, just put a1 in mode 0
-                                * with no count to set its output low
-                                */
-               devpriv->write_byte(INIT_A1_BITS,
-                                   dev->iobase + COUNTER_A_CONTROL_REG);
+                                        1, 3, I8254_MODE0);
+       } else  {
+               /* just put counter a1 in mode 0 to set its output low */
+               ret = labpc_counter_set_mode(dev,
+                                            dev->iobase + COUNTER_A_BASE_REG,
+                                            1, I8254_MODE0);
+       }
+       if (ret) {
+               comedi_error(dev, "error loading counter a1");
+               return ret;
+       }
 
 #ifdef CONFIG_ISA_DMA_API
        /*  figure out what method we will use to transfer data */
@@ -1147,12 +914,12 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                 */
            (cmd->flags & (TRIG_WAKE_EOS | TRIG_RT)) == 0 &&
            /*  only available on the isa boards */
-           thisboard->bustype == isa_bustype) {
+           board->bustype == isa_bustype) {
                xfer = isa_dma_transfer;
                /* pc-plus has no fifo-half full interrupt */
        } else
 #endif
-       if (thisboard->register_layout == labpc_1200_layout &&
+       if (board->register_layout == labpc_1200_layout &&
                   /*  wake-end-of-scan should interrupt on fifo not empty */
                   (cmd->flags & TRIG_WAKE_EOS) == 0 &&
                   /*  make sure we are taking more than just a few points */
@@ -1161,76 +928,34 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        } else
                xfer = fifo_not_empty_transfer;
        devpriv->current_transfer = xfer;
-       mode = labpc_ai_scan_mode(cmd);
 
-       /*  setup command6 register for 1200 boards */
-       if (thisboard->register_layout == labpc_1200_layout) {
-               /*  reference inputs to ground or common? */
-               if (aref != AREF_GROUND)
-                       devpriv->command6_bits |= ADC_COMMON_BIT;
-               else
-                       devpriv->command6_bits &= ~ADC_COMMON_BIT;
-               /*  bipolar or unipolar range? */
-               if (thisboard->ai_range_is_unipolar[range])
-                       devpriv->command6_bits |= ADC_UNIP_BIT;
-               else
-                       devpriv->command6_bits &= ~ADC_UNIP_BIT;
-               /*  interrupt on fifo half full? */
-               if (xfer == fifo_half_full_transfer)
-                       devpriv->command6_bits |= ADC_FHF_INTR_EN_BIT;
-               else
-                       devpriv->command6_bits &= ~ADC_FHF_INTR_EN_BIT;
-               /*  enable interrupt on counter a1 terminal count? */
-               if (cmd->stop_src == TRIG_EXT)
-                       devpriv->command6_bits |= A1_INTR_EN_BIT;
-               else
-                       devpriv->command6_bits &= ~A1_INTR_EN_BIT;
-               /*  are we scanning up or down through channels? */
-               if (mode == MODE_MULT_CHAN_UP)
-                       devpriv->command6_bits |= ADC_SCAN_UP_BIT;
-               else
-                       devpriv->command6_bits &= ~ADC_SCAN_UP_BIT;
-               /*  write to register */
-               devpriv->write_byte(devpriv->command6_bits,
-                                   dev->iobase + COMMAND6_REG);
-       }
+       labpc_ai_set_chan_and_gain(dev, mode, chan, range, aref);
+
+       labpc_setup_cmd6_reg(dev, s, mode, xfer, range, aref,
+                            (cmd->stop_src == TRIG_EXT));
 
-       /* setup channel list, etc (command1 register) */
-       devpriv->command1_bits = 0;
-       if (mode == MODE_MULT_CHAN_UP)
-               channel = CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]);
-       else
-               channel = CR_CHAN(cmd->chanlist[0]);
-       /* munge channel bits for differential / scan disabled mode */
-       if ((mode == MODE_SINGLE_CHAN || mode == MODE_SINGLE_CHAN_INTERVAL) &&
-           aref == AREF_DIFF)
-               channel *= 2;
-       devpriv->command1_bits |= ADC_CHAN_BITS(channel);
-       devpriv->command1_bits |= thisboard->ai_range_code[range];
-       devpriv->write_byte(devpriv->command1_bits, dev->iobase + COMMAND1_REG);
        /* manual says to set scan enable bit on second pass */
        if (mode == MODE_MULT_CHAN_UP || mode == MODE_MULT_CHAN_DOWN) {
-               devpriv->command1_bits |= ADC_SCAN_EN_BIT;
+               devpriv->cmd1 |= CMD1_SCANEN;
                /* need a brief delay before enabling scan, or scan
                 * list will get screwed when you switch
                 * between scan up to scan down mode - dunno why */
                udelay(1);
-               devpriv->write_byte(devpriv->command1_bits,
-                                   dev->iobase + COMMAND1_REG);
+               devpriv->write_byte(devpriv->cmd1, dev->iobase + CMD1_REG);
        }
 
        devpriv->write_byte(cmd->chanlist_len,
                            dev->iobase + INTERVAL_COUNT_REG);
        /*  load count */
-       devpriv->write_byte(INTERVAL_LOAD_BITS,
-                           dev->iobase + INTERVAL_LOAD_REG);
+       devpriv->write_byte(0x1, dev->iobase + INTERVAL_STROBE_REG);
 
-       if (cmd->convert_src == TRIG_TIMER || cmd->scan_begin_src == TRIG_TIMER) {
+       if (cmd->convert_src == TRIG_TIMER ||
+           cmd->scan_begin_src == TRIG_TIMER) {
                /*  set up pacing */
                labpc_adc_timing(dev, cmd, mode);
                /*  load counter b0 in mode 3 */
                ret = labpc_counter_load(dev, dev->iobase + COUNTER_B_BASE_REG,
-                                        0, devpriv->divisor_b0, 3);
+                                        0, devpriv->divisor_b0, I8254_MODE3);
                if (ret < 0) {
                        comedi_error(dev, "error loading counter b0");
                        return -1;
@@ -1240,20 +965,23 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        if (labpc_ai_convert_period(cmd, mode)) {
                /*  load counter a0 in mode 2 */
                ret = labpc_counter_load(dev, dev->iobase + COUNTER_A_BASE_REG,
-                                        0, devpriv->divisor_a0, 2);
-               if (ret < 0) {
-                       comedi_error(dev, "error loading counter a0");
-                       return -1;
-               }
-       } else
-               devpriv->write_byte(INIT_A0_BITS,
-                                   dev->iobase + COUNTER_A_CONTROL_REG);
+                                        0, devpriv->divisor_a0, I8254_MODE2);
+       } else {
+               /* initialize pacer counter to prevent any problems */
+               ret = labpc_counter_set_mode(dev,
+                                            dev->iobase + COUNTER_A_BASE_REG,
+                                            0, I8254_MODE2);
+       }
+       if (ret) {
+               comedi_error(dev, "error loading counter a0");
+               return ret;
+       }
 
        /*  set up scan pacing */
        if (labpc_ai_scan_period(cmd, mode)) {
                /*  load counter b1 in mode 2 */
                ret = labpc_counter_load(dev, dev->iobase + COUNTER_B_BASE_REG,
-                                        1, devpriv->divisor_b1, 2);
+                                        1, devpriv->divisor_b1, I8254_MODE2);
                if (ret < 0) {
                        comedi_error(dev, "error loading counter b1");
                        return -1;
@@ -1265,6 +993,8 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 #ifdef CONFIG_ISA_DMA_API
        /*  set up dma transfer */
        if (xfer == isa_dma_transfer) {
+               unsigned long irq_flags;
+
                irq_flags = claim_dma_lock();
                disable_dma(devpriv->dma_chan);
                /* clear flip-flop to make sure 2-byte registers for
@@ -1283,197 +1013,54 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                enable_dma(devpriv->dma_chan);
                release_dma_lock(irq_flags);
                /*  enable board's dma */
-               devpriv->command3_bits |= DMA_EN_BIT | DMATC_INTR_EN_BIT;
+               devpriv->cmd3 |= (CMD3_DMAEN | CMD3_DMATCINTEN);
        } else
-               devpriv->command3_bits &= ~DMA_EN_BIT & ~DMATC_INTR_EN_BIT;
+               devpriv->cmd3 &= ~(CMD3_DMAEN | CMD3_DMATCINTEN);
 #endif
 
        /*  enable error interrupts */
-       devpriv->command3_bits |= ERR_INTR_EN_BIT;
+       devpriv->cmd3 |= CMD3_ERRINTEN;
        /*  enable fifo not empty interrupt? */
        if (xfer == fifo_not_empty_transfer)
-               devpriv->command3_bits |= ADC_FNE_INTR_EN_BIT;
+               devpriv->cmd3 |= CMD3_FIFOINTEN;
        else
-               devpriv->command3_bits &= ~ADC_FNE_INTR_EN_BIT;
-       devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG);
+               devpriv->cmd3 &= ~CMD3_FIFOINTEN;
+       devpriv->write_byte(devpriv->cmd3, dev->iobase + CMD3_REG);
 
-       /*  setup any external triggering/pacing (command4 register) */
-       devpriv->command4_bits = 0;
+       /*  setup any external triggering/pacing (cmd4 register) */
+       devpriv->cmd4 = 0;
        if (cmd->convert_src != TRIG_EXT)
-               devpriv->command4_bits |= EXT_CONVERT_DISABLE_BIT;
+               devpriv->cmd4 |= CMD4_ECLKRCV;
        /* XXX should discard first scan when using interval scanning
         * since manual says it is not synced with scan clock */
-       if (labpc_use_continuous_mode(cmd, mode) == 0) {
-               devpriv->command4_bits |= INTERVAL_SCAN_EN_BIT;
+       if (!labpc_use_continuous_mode(cmd, mode)) {
+               devpriv->cmd4 |= CMD4_INTSCAN;
                if (cmd->scan_begin_src == TRIG_EXT)
-                       devpriv->command4_bits |= EXT_SCAN_EN_BIT;
+                       devpriv->cmd4 |= CMD4_EOIRCV;
        }
        /*  single-ended/differential */
        if (aref == AREF_DIFF)
-               devpriv->command4_bits |= ADC_DIFF_BIT;
-       devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG);
+               devpriv->cmd4 |= CMD4_SEDIFF;
+       devpriv->write_byte(devpriv->cmd4, dev->iobase + CMD4_REG);
 
        /*  startup acquisition */
 
-       /*  command2 reg */
-       /*  use 2 cascaded counters for pacing */
        spin_lock_irqsave(&dev->spinlock, flags);
-       devpriv->command2_bits |= CASCADE_BIT;
-       switch (cmd->start_src) {
-       case TRIG_EXT:
-               devpriv->command2_bits |= HWTRIG_BIT;
-               devpriv->command2_bits &= ~PRETRIG_BIT & ~SWTRIG_BIT;
-               break;
-       case TRIG_NOW:
-               devpriv->command2_bits |= SWTRIG_BIT;
-               devpriv->command2_bits &= ~PRETRIG_BIT & ~HWTRIG_BIT;
-               break;
-       default:
-               comedi_error(dev, "bug with start_src");
-               spin_unlock_irqrestore(&dev->spinlock, flags);
-               return -1;
-               break;
-       }
-       switch (cmd->stop_src) {
-       case TRIG_EXT:
-               devpriv->command2_bits |= HWTRIG_BIT | PRETRIG_BIT;
-               break;
-       case TRIG_COUNT:
-       case TRIG_NONE:
-               break;
-       default:
-               comedi_error(dev, "bug with stop_src");
-               spin_unlock_irqrestore(&dev->spinlock, flags);
-               return -1;
-       }
-       devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG);
-       spin_unlock_irqrestore(&dev->spinlock, flags);
-
-       return 0;
-}
-
-/* interrupt service routine */
-static irqreturn_t labpc_interrupt(int irq, void *d)
-{
-       struct comedi_device *dev = d;
-       struct labpc_private *devpriv = dev->private;
-       struct comedi_subdevice *s = dev->read_subdev;
-       struct comedi_async *async;
-       struct comedi_cmd *cmd;
-
-       if (dev->attached == 0) {
-               comedi_error(dev, "premature interrupt");
-               return IRQ_HANDLED;
-       }
-
-       async = s->async;
-       cmd = &async->cmd;
-       async->events = 0;
-
-       /* read board status */
-       devpriv->status1_bits = devpriv->read_byte(dev->iobase + STATUS1_REG);
-       if (thisboard->register_layout == labpc_1200_layout)
-               devpriv->status2_bits =
-                   devpriv->read_byte(dev->iobase + STATUS2_REG);
-
-       if ((devpriv->status1_bits & (DMATC_BIT | TIMER_BIT | OVERFLOW_BIT |
-                                     OVERRUN_BIT | DATA_AVAIL_BIT)) == 0
-           && (devpriv->status2_bits & A1_TC_BIT) == 0
-           && (devpriv->status2_bits & FNHF_BIT)) {
-               return IRQ_NONE;
-       }
-
-       if (devpriv->status1_bits & OVERRUN_BIT) {
-               /* clear error interrupt */
-               devpriv->write_byte(0x1, dev->iobase + ADC_CLEAR_REG);
-               async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
-               comedi_event(dev, s);
-               comedi_error(dev, "overrun");
-               return IRQ_HANDLED;
-       }
-
-#ifdef CONFIG_ISA_DMA_API
-       if (devpriv->current_transfer == isa_dma_transfer) {
-               /*
-                * if a dma terminal count of external stop trigger
-                * has occurred
-                */
-               if (devpriv->status1_bits & DMATC_BIT ||
-                   (thisboard->register_layout == labpc_1200_layout
-                    && devpriv->status2_bits & A1_TC_BIT)) {
-                       handle_isa_dma(dev);
-               }
-       } else
-#endif
-               labpc_drain_fifo(dev);
-
-       if (devpriv->status1_bits & TIMER_BIT) {
-               comedi_error(dev, "handled timer interrupt?");
-               /*  clear it */
-               devpriv->write_byte(0x1, dev->iobase + TIMER_CLEAR_REG);
-       }
-
-       if (devpriv->status1_bits & OVERFLOW_BIT) {
-               /*  clear error interrupt */
-               devpriv->write_byte(0x1, dev->iobase + ADC_CLEAR_REG);
-               async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
-               comedi_event(dev, s);
-               comedi_error(dev, "overflow");
-               return IRQ_HANDLED;
-       }
-       /*  handle external stop trigger */
-       if (cmd->stop_src == TRIG_EXT) {
-               if (devpriv->status2_bits & A1_TC_BIT) {
-                       labpc_drain_dregs(dev);
-                       labpc_cancel(dev, s);
-                       async->events |= COMEDI_CB_EOA;
-               }
-       }
 
-       /* TRIG_COUNT end of acquisition */
-       if (cmd->stop_src == TRIG_COUNT) {
-               if (devpriv->count == 0) {
-                       labpc_cancel(dev, s);
-                       async->events |= COMEDI_CB_EOA;
-               }
-       }
-
-       comedi_event(dev, s);
-       return IRQ_HANDLED;
-}
+       /* use 2 cascaded counters for pacing */
+       devpriv->cmd2 |= CMD2_TBSEL;
 
-/* read all available samples from ai fifo */
-static int labpc_drain_fifo(struct comedi_device *dev)
-{
-       struct labpc_private *devpriv = dev->private;
-       unsigned int lsb, msb;
-       short data;
-       struct comedi_async *async = dev->read_subdev->async;
-       const int timeout = 10000;
-       unsigned int i;
+       devpriv->cmd2 &= ~(CMD2_SWTRIG | CMD2_HWTRIG | CMD2_PRETRIG);
+       if (cmd->start_src == TRIG_EXT)
+               devpriv->cmd2 |= CMD2_HWTRIG;
+       else
+               devpriv->cmd2 |= CMD2_SWTRIG;
+       if (cmd->stop_src == TRIG_EXT)
+               devpriv->cmd2 |= (CMD2_HWTRIG | CMD2_PRETRIG);
 
-       devpriv->status1_bits = devpriv->read_byte(dev->iobase + STATUS1_REG);
+       devpriv->write_byte(devpriv->cmd2, dev->iobase + CMD2_REG);
 
-       for (i = 0; (devpriv->status1_bits & DATA_AVAIL_BIT) && i < timeout;
-            i++) {
-               /*  quit if we have all the data we want */
-               if (async->cmd.stop_src == TRIG_COUNT) {
-                       if (devpriv->count == 0)
-                               break;
-                       devpriv->count--;
-               }
-               lsb = devpriv->read_byte(dev->iobase + ADC_FIFO_REG);
-               msb = devpriv->read_byte(dev->iobase + ADC_FIFO_REG);
-               data = (msb << 8) | lsb;
-               cfc_write_to_buffer(dev->read_subdev, data);
-               devpriv->status1_bits =
-                   devpriv->read_byte(dev->iobase + STATUS1_REG);
-       }
-       if (i == timeout) {
-               comedi_error(dev, "ai timeout, fifo never empties");
-               async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
-               return -1;
-       }
+       spin_unlock_irqrestore(&dev->spinlock, flags);
 
        return 0;
 }
@@ -1489,7 +1076,7 @@ static void labpc_drain_dma(struct comedi_device *dev)
        unsigned int max_points, num_points, residue, leftover;
        int i;
 
-       status = devpriv->status1_bits;
+       status = devpriv->stat1;
 
        flags = claim_dma_lock();
        disable_dma(devpriv->dma_chan);
@@ -1546,6 +1133,38 @@ static void handle_isa_dma(struct comedi_device *dev)
 }
 #endif
 
+/* read all available samples from ai fifo */
+static int labpc_drain_fifo(struct comedi_device *dev)
+{
+       struct labpc_private *devpriv = dev->private;
+       short data;
+       struct comedi_async *async = dev->read_subdev->async;
+       const int timeout = 10000;
+       unsigned int i;
+
+       devpriv->stat1 = devpriv->read_byte(dev->iobase + STAT1_REG);
+
+       for (i = 0; (devpriv->stat1 & STAT1_DAVAIL) && i < timeout;
+            i++) {
+               /*  quit if we have all the data we want */
+               if (async->cmd.stop_src == TRIG_COUNT) {
+                       if (devpriv->count == 0)
+                               break;
+                       devpriv->count--;
+               }
+               data = labpc_read_adc_fifo(dev);
+               cfc_write_to_buffer(dev->read_subdev, data);
+               devpriv->stat1 = devpriv->read_byte(dev->iobase + STAT1_REG);
+       }
+       if (i == timeout) {
+               comedi_error(dev, "ai timeout, fifo never empties");
+               async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
+               return -1;
+       }
+
+       return 0;
+}
+
 /* makes sure all data acquired by board is transferred to comedi (used
  * when acquisition is terminated by stop_src == TRIG_EXT). */
 static void labpc_drain_dregs(struct comedi_device *dev)
@@ -1560,99 +1179,102 @@ static void labpc_drain_dregs(struct comedi_device *dev)
        labpc_drain_fifo(dev);
 }
 
-static int labpc_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
-                         struct comedi_insn *insn, unsigned int *data)
+/* interrupt service routine */
+static irqreturn_t labpc_interrupt(int irq, void *d)
 {
+       struct comedi_device *dev = d;
+       const struct labpc_boardinfo *board = comedi_board(dev);
        struct labpc_private *devpriv = dev->private;
-       int i, n;
-       int chan, range;
-       int lsb, msb;
-       int timeout = 1000;
-       unsigned long flags;
+       struct comedi_subdevice *s = dev->read_subdev;
+       struct comedi_async *async;
+       struct comedi_cmd *cmd;
 
-       /*  disable timed conversions */
-       spin_lock_irqsave(&dev->spinlock, flags);
-       devpriv->command2_bits &= ~SWTRIG_BIT & ~HWTRIG_BIT & ~PRETRIG_BIT;
-       devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG);
-       spin_unlock_irqrestore(&dev->spinlock, flags);
+       if (!dev->attached) {
+               comedi_error(dev, "premature interrupt");
+               return IRQ_HANDLED;
+       }
 
-       /*  disable interrupt generation and dma */
-       devpriv->command3_bits = 0;
-       devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG);
+       async = s->async;
+       cmd = &async->cmd;
+       async->events = 0;
 
-       /* set gain and channel */
-       devpriv->command1_bits = 0;
-       chan = CR_CHAN(insn->chanspec);
-       range = CR_RANGE(insn->chanspec);
-       devpriv->command1_bits |= thisboard->ai_range_code[range];
-       /* munge channel bits for differential/scan disabled mode */
-       if (CR_AREF(insn->chanspec) == AREF_DIFF)
-               chan *= 2;
-       devpriv->command1_bits |= ADC_CHAN_BITS(chan);
-       devpriv->write_byte(devpriv->command1_bits, dev->iobase + COMMAND1_REG);
-
-       /* setup command6 register for 1200 boards */
-       if (thisboard->register_layout == labpc_1200_layout) {
-               /*  reference inputs to ground or common? */
-               if (CR_AREF(insn->chanspec) != AREF_GROUND)
-                       devpriv->command6_bits |= ADC_COMMON_BIT;
-               else
-                       devpriv->command6_bits &= ~ADC_COMMON_BIT;
-               /* bipolar or unipolar range? */
-               if (thisboard->ai_range_is_unipolar[range])
-                       devpriv->command6_bits |= ADC_UNIP_BIT;
-               else
-                       devpriv->command6_bits &= ~ADC_UNIP_BIT;
-               /* don't interrupt on fifo half full */
-               devpriv->command6_bits &= ~ADC_FHF_INTR_EN_BIT;
-               /* don't enable interrupt on counter a1 terminal count? */
-               devpriv->command6_bits &= ~A1_INTR_EN_BIT;
-               /* write to register */
-               devpriv->write_byte(devpriv->command6_bits,
-                                   dev->iobase + COMMAND6_REG);
+       /* read board status */
+       devpriv->stat1 = devpriv->read_byte(dev->iobase + STAT1_REG);
+       if (board->register_layout == labpc_1200_layout)
+               devpriv->stat2 = devpriv->read_byte(dev->iobase + STAT2_REG);
+
+       if ((devpriv->stat1 & (STAT1_GATA0 | STAT1_CNTINT | STAT1_OVERFLOW |
+                              STAT1_OVERRUN | STAT1_DAVAIL)) == 0
+           && (devpriv->stat2 & STAT2_OUTA1) == 0
+           && (devpriv->stat2 & STAT2_FIFONHF)) {
+               return IRQ_NONE;
        }
-       /* setup command4 register */
-       devpriv->command4_bits = 0;
-       devpriv->command4_bits |= EXT_CONVERT_DISABLE_BIT;
-       /* single-ended/differential */
-       if (CR_AREF(insn->chanspec) == AREF_DIFF)
-               devpriv->command4_bits |= ADC_DIFF_BIT;
-       devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG);
 
-       /*
-        * initialize pacer counter output to make sure it doesn't
-        * cause any problems
-        */
-       devpriv->write_byte(INIT_A0_BITS, dev->iobase + COUNTER_A_CONTROL_REG);
+       if (devpriv->stat1 & STAT1_OVERRUN) {
+               /* clear error interrupt */
+               devpriv->write_byte(0x1, dev->iobase + ADC_FIFO_CLEAR_REG);
+               async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
+               comedi_event(dev, s);
+               comedi_error(dev, "overrun");
+               return IRQ_HANDLED;
+       }
 
-       labpc_clear_adc_fifo(dev);
+#ifdef CONFIG_ISA_DMA_API
+       if (devpriv->current_transfer == isa_dma_transfer) {
+               /*
+                * if a dma terminal count of external stop trigger
+                * has occurred
+                */
+               if (devpriv->stat1 & STAT1_GATA0 ||
+                   (board->register_layout == labpc_1200_layout
+                    && devpriv->stat2 & STAT2_OUTA1)) {
+                       handle_isa_dma(dev);
+               }
+       } else
+#endif
+               labpc_drain_fifo(dev);
 
-       for (n = 0; n < insn->n; n++) {
-               /* trigger conversion */
-               devpriv->write_byte(0x1, dev->iobase + ADC_CONVERT_REG);
+       if (devpriv->stat1 & STAT1_CNTINT) {
+               comedi_error(dev, "handled timer interrupt?");
+               /*  clear it */
+               devpriv->write_byte(0x1, dev->iobase + TIMER_CLEAR_REG);
+       }
 
-               for (i = 0; i < timeout; i++) {
-                       if (devpriv->read_byte(dev->iobase +
-                                              STATUS1_REG) & DATA_AVAIL_BIT)
-                               break;
-                       udelay(1);
+       if (devpriv->stat1 & STAT1_OVERFLOW) {
+               /*  clear error interrupt */
+               devpriv->write_byte(0x1, dev->iobase + ADC_FIFO_CLEAR_REG);
+               async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
+               comedi_event(dev, s);
+               comedi_error(dev, "overflow");
+               return IRQ_HANDLED;
+       }
+       /*  handle external stop trigger */
+       if (cmd->stop_src == TRIG_EXT) {
+               if (devpriv->stat2 & STAT2_OUTA1) {
+                       labpc_drain_dregs(dev);
+                       labpc_cancel(dev, s);
+                       async->events |= COMEDI_CB_EOA;
                }
-               if (i == timeout) {
-                       comedi_error(dev, "timeout");
-                       return -ETIME;
+       }
+
+       /* TRIG_COUNT end of acquisition */
+       if (cmd->stop_src == TRIG_COUNT) {
+               if (devpriv->count == 0) {
+                       labpc_cancel(dev, s);
+                       async->events |= COMEDI_CB_EOA;
                }
-               lsb = devpriv->read_byte(dev->iobase + ADC_FIFO_REG);
-               msb = devpriv->read_byte(dev->iobase + ADC_FIFO_REG);
-               data[n] = (msb << 8) | lsb;
        }
 
-       return n;
+       comedi_event(dev, s);
+       return IRQ_HANDLED;
 }
 
-/* analog output insn */
-static int labpc_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
-                         struct comedi_insn *insn, unsigned int *data)
+static int labpc_ao_insn_write(struct comedi_device *dev,
+                              struct comedi_subdevice *s,
+                              struct comedi_insn *insn,
+                              unsigned int *data)
 {
+       const struct labpc_boardinfo *board = comedi_board(dev);
        struct labpc_private *devpriv = dev->private;
        int channel, range;
        unsigned long flags;
@@ -1664,20 +1286,19 @@ static int labpc_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
        /* note: hardware bug in daqcard-1200 means pacing cannot
         * be independently enabled/disabled for its the two channels */
        spin_lock_irqsave(&dev->spinlock, flags);
-       devpriv->command2_bits &= ~DAC_PACED_BIT(channel);
-       devpriv->write_byte(devpriv->command2_bits, dev->iobase + COMMAND2_REG);
+       devpriv->cmd2 &= ~CMD2_LDAC(channel);
+       devpriv->write_byte(devpriv->cmd2, dev->iobase + CMD2_REG);
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
        /* set range */
-       if (thisboard->register_layout == labpc_1200_layout) {
+       if (board->register_layout == labpc_1200_layout) {
                range = CR_RANGE(insn->chanspec);
-               if (range & AO_RANGE_IS_UNIPOLAR)
-                       devpriv->command6_bits |= DAC_UNIP_BIT(channel);
+               if (labpc_range_is_unipolar(s, range))
+                       devpriv->cmd6 |= CMD6_DACUNI(channel);
                else
-                       devpriv->command6_bits &= ~DAC_UNIP_BIT(channel);
+                       devpriv->cmd6 &= ~CMD6_DACUNI(channel);
                /*  write to register */
-               devpriv->write_byte(devpriv->command6_bits,
-                                   dev->iobase + COMMAND6_REG);
+               devpriv->write_byte(devpriv->cmd6, dev->iobase + CMD6_REG);
        }
        /* send data */
        lsb = data[0] & 0xff;
@@ -1691,9 +1312,10 @@ static int labpc_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
        return 1;
 }
 
-/* analog output readback insn */
-static int labpc_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
-                         struct comedi_insn *insn, unsigned int *data)
+static int labpc_ao_insn_read(struct comedi_device *dev,
+                             struct comedi_subdevice *s,
+                             struct comedi_insn *insn,
+                             unsigned int *data)
 {
        struct labpc_private *devpriv = dev->private;
 
@@ -1702,183 +1324,7 @@ static int labpc_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
        return 1;
 }
 
-static int labpc_calib_read_insn(struct comedi_device *dev,
-                                struct comedi_subdevice *s,
-                                struct comedi_insn *insn, unsigned int *data)
-{
-       struct labpc_private *devpriv = dev->private;
-
-       data[0] = devpriv->caldac[CR_CHAN(insn->chanspec)];
-
-       return 1;
-}
-
-static int labpc_calib_write_insn(struct comedi_device *dev,
-                                 struct comedi_subdevice *s,
-                                 struct comedi_insn *insn, unsigned int *data)
-{
-       int channel = CR_CHAN(insn->chanspec);
-
-       write_caldac(dev, channel, data[0]);
-       return 1;
-}
-
-static int labpc_eeprom_read_insn(struct comedi_device *dev,
-                                 struct comedi_subdevice *s,
-                                 struct comedi_insn *insn, unsigned int *data)
-{
-       struct labpc_private *devpriv = dev->private;
-
-       data[0] = devpriv->eeprom_data[CR_CHAN(insn->chanspec)];
-
-       return 1;
-}
-
-static int labpc_eeprom_write_insn(struct comedi_device *dev,
-                                  struct comedi_subdevice *s,
-                                  struct comedi_insn *insn, unsigned int *data)
-{
-       int channel = CR_CHAN(insn->chanspec);
-       int ret;
-
-       /*  only allow writes to user area of eeprom */
-       if (channel < 16 || channel > 127) {
-               dev_dbg(dev->class_dev,
-                       "eeprom writes are only allowed to channels 16 through 127 (the pointer and user areas)\n");
-               return -EINVAL;
-       }
-
-       ret = labpc_eeprom_write(dev, channel, data[0]);
-       if (ret < 0)
-               return ret;
-
-       return 1;
-}
-
-#ifdef CONFIG_ISA_DMA_API
-/* utility function that suggests a dma transfer size in bytes */
-static unsigned int labpc_suggest_transfer_size(const struct comedi_cmd *cmd)
-{
-       unsigned int size;
-       unsigned int freq;
-
-       if (cmd->convert_src == TRIG_TIMER)
-               freq = 1000000000 / cmd->convert_arg;
-       /* return some default value */
-       else
-               freq = 0xffffffff;
-
-       /* make buffer fill in no more than 1/3 second */
-       size = (freq / 3) * sample_size;
-
-       /* set a minimum and maximum size allowed */
-       if (size > dma_buffer_size)
-               size = dma_buffer_size - dma_buffer_size % sample_size;
-       else if (size < sample_size)
-               size = sample_size;
-
-       return size;
-}
-#endif
-
-/* figures out what counter values to use based on command */
-static void labpc_adc_timing(struct comedi_device *dev, struct comedi_cmd *cmd,
-                            enum scan_mode mode)
-{
-       struct labpc_private *devpriv = dev->private;
-       /* max value for 16 bit counter in mode 2 */
-       const int max_counter_value = 0x10000;
-       /* min value for 16 bit counter in mode 2 */
-       const int min_counter_value = 2;
-       unsigned int base_period;
-       unsigned int scan_period;
-       unsigned int convert_period;
-
-       /*
-        * if both convert and scan triggers are TRIG_TIMER, then they
-        * both rely on counter b0
-        */
-       convert_period = labpc_ai_convert_period(cmd, mode);
-       scan_period = labpc_ai_scan_period(cmd, mode);
-       if (convert_period && scan_period) {
-               /*
-                * pick the lowest b0 divisor value we can (for maximum input
-                * clock speed on convert and scan counters)
-                */
-               devpriv->divisor_b0 = (scan_period - 1) /
-                   (LABPC_TIMER_BASE * max_counter_value) + 1;
-               if (devpriv->divisor_b0 < min_counter_value)
-                       devpriv->divisor_b0 = min_counter_value;
-               if (devpriv->divisor_b0 > max_counter_value)
-                       devpriv->divisor_b0 = max_counter_value;
-
-               base_period = LABPC_TIMER_BASE * devpriv->divisor_b0;
-
-               /*  set a0 for conversion frequency and b1 for scan frequency */
-               switch (cmd->flags & TRIG_ROUND_MASK) {
-               default:
-               case TRIG_ROUND_NEAREST:
-                       devpriv->divisor_a0 =
-                           (convert_period + (base_period / 2)) / base_period;
-                       devpriv->divisor_b1 =
-                           (scan_period + (base_period / 2)) / base_period;
-                       break;
-               case TRIG_ROUND_UP:
-                       devpriv->divisor_a0 =
-                           (convert_period + (base_period - 1)) / base_period;
-                       devpriv->divisor_b1 =
-                           (scan_period + (base_period - 1)) / base_period;
-                       break;
-               case TRIG_ROUND_DOWN:
-                       devpriv->divisor_a0 = convert_period / base_period;
-                       devpriv->divisor_b1 = scan_period / base_period;
-                       break;
-               }
-               /*  make sure a0 and b1 values are acceptable */
-               if (devpriv->divisor_a0 < min_counter_value)
-                       devpriv->divisor_a0 = min_counter_value;
-               if (devpriv->divisor_a0 > max_counter_value)
-                       devpriv->divisor_a0 = max_counter_value;
-               if (devpriv->divisor_b1 < min_counter_value)
-                       devpriv->divisor_b1 = min_counter_value;
-               if (devpriv->divisor_b1 > max_counter_value)
-                       devpriv->divisor_b1 = max_counter_value;
-               /*  write corrected timings to command */
-               labpc_set_ai_convert_period(cmd, mode,
-                                           base_period * devpriv->divisor_a0);
-               labpc_set_ai_scan_period(cmd, mode,
-                                        base_period * devpriv->divisor_b1);
-               /*
-                * if only one TRIG_TIMER is used, we can employ the generic
-                * cascaded timing functions
-                */
-       } else if (scan_period) {
-               /*
-                * calculate cascaded counter values
-                * that give desired scan timing
-                */
-               i8253_cascade_ns_to_timer_2div(LABPC_TIMER_BASE,
-                                              &(devpriv->divisor_b1),
-                                              &(devpriv->divisor_b0),
-                                              &scan_period,
-                                              cmd->flags & TRIG_ROUND_MASK);
-               labpc_set_ai_scan_period(cmd, mode, scan_period);
-       } else if (convert_period) {
-               /*
-                * calculate cascaded counter values
-                * that give desired conversion timing
-                */
-               i8253_cascade_ns_to_timer_2div(LABPC_TIMER_BASE,
-                                              &(devpriv->divisor_a0),
-                                              &(devpriv->divisor_b0),
-                                              &convert_period,
-                                              cmd->flags & TRIG_ROUND_MASK);
-               labpc_set_ai_convert_period(cmd, mode, convert_period);
-       }
-}
-
-static int labpc_dio_mem_callback(int dir, int port, int data,
-                                 unsigned long iobase)
+static int labpc_8255_mmio(int dir, int port, int data, unsigned long iobase)
 {
        if (dir) {
                writeb(data, (void __iomem *)(iobase + port));
@@ -1897,20 +1343,18 @@ static void labpc_serial_out(struct comedi_device *dev, unsigned int value,
 
        for (i = 1; i <= value_width; i++) {
                /*  clear serial clock */
-               devpriv->command5_bits &= ~SCLOCK_BIT;
+               devpriv->cmd5 &= ~CMD5_SCLK;
                /*  send bits most significant bit first */
                if (value & (1 << (value_width - i)))
-                       devpriv->command5_bits |= SDATA_BIT;
+                       devpriv->cmd5 |= CMD5_SDATA;
                else
-                       devpriv->command5_bits &= ~SDATA_BIT;
+                       devpriv->cmd5 &= ~CMD5_SDATA;
                udelay(1);
-               devpriv->write_byte(devpriv->command5_bits,
-                                   dev->iobase + COMMAND5_REG);
+               devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
                /*  set clock to load bit */
-               devpriv->command5_bits |= SCLOCK_BIT;
+               devpriv->cmd5 |= CMD5_SCLK;
                udelay(1);
-               devpriv->write_byte(devpriv->command5_bits,
-                                   dev->iobase + COMMAND5_REG);
+               devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
        }
 }
 
@@ -1924,20 +1368,17 @@ static unsigned int labpc_serial_in(struct comedi_device *dev)
 
        for (i = 1; i <= value_width; i++) {
                /*  set serial clock */
-               devpriv->command5_bits |= SCLOCK_BIT;
+               devpriv->cmd5 |= CMD5_SCLK;
                udelay(1);
-               devpriv->write_byte(devpriv->command5_bits,
-                                   dev->iobase + COMMAND5_REG);
+               devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
                /*  clear clock bit */
-               devpriv->command5_bits &= ~SCLOCK_BIT;
+               devpriv->cmd5 &= ~CMD5_SCLK;
                udelay(1);
-               devpriv->write_byte(devpriv->command5_bits,
-                                   dev->iobase + COMMAND5_REG);
+               devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
                /*  read bits most significant bit first */
                udelay(1);
-               devpriv->status2_bits =
-                   devpriv->read_byte(dev->iobase + STATUS2_REG);
-               if (devpriv->status2_bits & EEPROM_OUT_BIT)
+               devpriv->stat2 = devpriv->read_byte(dev->iobase + STAT2_REG);
+               if (devpriv->stat2 & STAT2_PROMOUT)
                        value |= 1 << (value_width - i);
        }
 
@@ -1955,12 +1396,12 @@ static unsigned int labpc_eeprom_read(struct comedi_device *dev,
        const int write_length = 8;
 
        /*  enable read/write to eeprom */
-       devpriv->command5_bits &= ~EEPROM_EN_BIT;
+       devpriv->cmd5 &= ~CMD5_EEPROMCS;
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
-       devpriv->command5_bits |= EEPROM_EN_BIT | EEPROM_WRITE_UNPROTECT_BIT;
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
+       devpriv->cmd5 |= (CMD5_EEPROMCS | CMD5_WRTPRT);
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
 
        /*  send read instruction */
        labpc_serial_out(dev, read_instruction, write_length);
@@ -1970,9 +1411,37 @@ static unsigned int labpc_eeprom_read(struct comedi_device *dev,
        value = labpc_serial_in(dev);
 
        /*  disable read/write to eeprom */
-       devpriv->command5_bits &= ~EEPROM_EN_BIT & ~EEPROM_WRITE_UNPROTECT_BIT;
+       devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT);
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
+
+       return value;
+}
+
+static unsigned int labpc_eeprom_read_status(struct comedi_device *dev)
+{
+       struct labpc_private *devpriv = dev->private;
+       unsigned int value;
+       const int read_status_instruction = 0x5;
+       const int write_length = 8;     /*  8 bit write lengths to eeprom */
+
+       /*  enable read/write to eeprom */
+       devpriv->cmd5 &= ~CMD5_EEPROMCS;
+       udelay(1);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
+       devpriv->cmd5 |= (CMD5_EEPROMCS | CMD5_WRTPRT);
+       udelay(1);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
+
+       /*  send read status instruction */
+       labpc_serial_out(dev, read_status_instruction, write_length);
+       /*  read result */
+       value = labpc_serial_in(dev);
+
+       /*  disable read/write to eeprom */
+       devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT);
+       udelay(1);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
 
        return value;
 }
@@ -2002,68 +1471,40 @@ static int labpc_eeprom_write(struct comedi_device *dev,
        devpriv->eeprom_data[address] = value;
 
        /*  enable read/write to eeprom */
-       devpriv->command5_bits &= ~EEPROM_EN_BIT;
+       devpriv->cmd5 &= ~CMD5_EEPROMCS;
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
-       devpriv->command5_bits |= EEPROM_EN_BIT | EEPROM_WRITE_UNPROTECT_BIT;
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
+       devpriv->cmd5 |= (CMD5_EEPROMCS | CMD5_WRTPRT);
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
 
        /*  send write_enable instruction */
        labpc_serial_out(dev, write_enable_instruction, write_length);
-       devpriv->command5_bits &= ~EEPROM_EN_BIT;
+       devpriv->cmd5 &= ~CMD5_EEPROMCS;
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
 
        /*  send write instruction */
-       devpriv->command5_bits |= EEPROM_EN_BIT;
+       devpriv->cmd5 |= CMD5_EEPROMCS;
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
        labpc_serial_out(dev, write_instruction, write_length);
        /*  send 8 bit address to write to */
        labpc_serial_out(dev, address, write_length);
        /*  write value */
        labpc_serial_out(dev, value, write_length);
-       devpriv->command5_bits &= ~EEPROM_EN_BIT;
+       devpriv->cmd5 &= ~CMD5_EEPROMCS;
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
 
        /*  disable read/write to eeprom */
-       devpriv->command5_bits &= ~EEPROM_EN_BIT & ~EEPROM_WRITE_UNPROTECT_BIT;
+       devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT);
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
 
        return 0;
 }
 
-static unsigned int labpc_eeprom_read_status(struct comedi_device *dev)
-{
-       struct labpc_private *devpriv = dev->private;
-       unsigned int value;
-       const int read_status_instruction = 0x5;
-       const int write_length = 8;     /*  8 bit write lengths to eeprom */
-
-       /*  enable read/write to eeprom */
-       devpriv->command5_bits &= ~EEPROM_EN_BIT;
-       udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
-       devpriv->command5_bits |= EEPROM_EN_BIT | EEPROM_WRITE_UNPROTECT_BIT;
-       udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
-
-       /*  send read status instruction */
-       labpc_serial_out(dev, read_status_instruction, write_length);
-       /*  read result */
-       value = labpc_serial_in(dev);
-
-       /*  disable read/write to eeprom */
-       devpriv->command5_bits &= ~EEPROM_EN_BIT & ~EEPROM_WRITE_UNPROTECT_BIT;
-       udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
-
-       return value;
-}
-
 /* writes to 8 bit calibration dacs */
 static void write_caldac(struct comedi_device *dev, unsigned int channel,
                         unsigned int value)
@@ -2075,10 +1516,9 @@ static void write_caldac(struct comedi_device *dev, unsigned int channel,
        devpriv->caldac[channel] = value;
 
        /*  clear caldac load bit and make sure we don't write to eeprom */
-       devpriv->command5_bits &=
-           ~CALDAC_LOAD_BIT & ~EEPROM_EN_BIT & ~EEPROM_WRITE_UNPROTECT_BIT;
+       devpriv->cmd5 &= ~(CMD5_CALDACLD | CMD5_EEPROMCS | CMD5_WRTPRT);
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
 
        /*  write 4 bit channel */
        labpc_serial_out(dev, channel, 4);
@@ -2086,42 +1526,403 @@ static void write_caldac(struct comedi_device *dev, unsigned int channel,
        labpc_serial_out(dev, value, 8);
 
        /*  set and clear caldac bit to load caldac value */
-       devpriv->command5_bits |= CALDAC_LOAD_BIT;
+       devpriv->cmd5 |= CMD5_CALDACLD;
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
-       devpriv->command5_bits &= ~CALDAC_LOAD_BIT;
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
+       devpriv->cmd5 &= ~CMD5_CALDACLD;
        udelay(1);
-       devpriv->write_byte(devpriv->command5_bits, dev->iobase + COMMAND5_REG);
+       devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
+}
+
+static int labpc_calib_insn_write(struct comedi_device *dev,
+                                 struct comedi_subdevice *s,
+                                 struct comedi_insn *insn,
+                                 unsigned int *data)
+{
+       unsigned int chan = CR_CHAN(insn->chanspec);
+
+       /*
+        * Only write the last data value to the caldac. Preceding
+        * data would be overwritten anyway.
+        */
+       if (insn->n > 0)
+               write_caldac(dev, chan, data[insn->n - 1]);
+
+       return insn->n;
+}
+
+static int labpc_calib_insn_read(struct comedi_device *dev,
+                                struct comedi_subdevice *s,
+                                struct comedi_insn *insn,
+                                unsigned int *data)
+{
+       struct labpc_private *devpriv = dev->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       int i;
+
+       for (i = 0; i < insn->n; i++)
+               data[i] = devpriv->caldac[chan];
+
+       return insn->n;
+}
+
+static int labpc_eeprom_insn_write(struct comedi_device *dev,
+                                  struct comedi_subdevice *s,
+                                  struct comedi_insn *insn,
+                                  unsigned int *data)
+{
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       int ret;
+
+       /* only allow writes to user area of eeprom */
+       if (chan < 16 || chan > 127)
+               return -EINVAL;
+
+       /*
+        * Only write the last data value to the eeprom. Preceding
+        * data would be overwritten anyway.
+        */
+       if (insn->n > 0) {
+               ret = labpc_eeprom_write(dev, chan, data[insn->n - 1]);
+               if (ret)
+                       return ret;
+       }
+
+       return insn->n;
+}
+
+static int labpc_eeprom_insn_read(struct comedi_device *dev,
+                                 struct comedi_subdevice *s,
+                                 struct comedi_insn *insn,
+                                 unsigned int *data)
+{
+       struct labpc_private *devpriv = dev->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       int i;
+
+       for (i = 0; i < insn->n; i++)
+               data[i] = devpriv->eeprom_data[chan];
+
+       return insn->n;
 }
 
+int labpc_common_attach(struct comedi_device *dev, unsigned long iobase,
+                       unsigned int irq, unsigned int dma_chan)
+{
+       const struct labpc_boardinfo *board = comedi_board(dev);
+       struct labpc_private *devpriv = dev->private;
+       struct comedi_subdevice *s;
+       unsigned long isr_flags;
+       int ret;
+       int i;
+
+       dev->board_name = board->name;
+
+       if (iobase == 0)
+               return -EINVAL;
+       if (board->bustype == isa_bustype) {
+               if (!request_region(iobase, LABPC_SIZE, dev->board_name))
+                       return -EIO;
+       }
+       dev->iobase = iobase;
+
+       if (board->has_mmio) {
+               devpriv->read_byte = labpc_readb;
+               devpriv->write_byte = labpc_writeb;
+       } else {
+               devpriv->read_byte = labpc_inb;
+               devpriv->write_byte = labpc_outb;
+       }
+
+       /* initialize board's command registers */
+       devpriv->write_byte(devpriv->cmd1, dev->iobase + CMD1_REG);
+       devpriv->write_byte(devpriv->cmd2, dev->iobase + CMD2_REG);
+       devpriv->write_byte(devpriv->cmd3, dev->iobase + CMD3_REG);
+       devpriv->write_byte(devpriv->cmd4, dev->iobase + CMD4_REG);
+       if (board->register_layout == labpc_1200_layout) {
+               devpriv->write_byte(devpriv->cmd5, dev->iobase + CMD5_REG);
+               devpriv->write_byte(devpriv->cmd6, dev->iobase + CMD6_REG);
+       }
+
+       if (irq) {
+               isr_flags = 0;
+               if (board->bustype == pci_bustype ||
+                   board->bustype == pcmcia_bustype)
+                       isr_flags |= IRQF_SHARED;
+               ret = request_irq(irq, labpc_interrupt, isr_flags,
+                                 dev->board_name, dev);
+               if (ret == 0)
+                       dev->irq = irq;
+       }
+
+#ifdef CONFIG_ISA_DMA_API
+       if (dev->irq && (dma_chan == 1 || dma_chan == 3)) {
+               devpriv->dma_buffer = kmalloc(dma_buffer_size,
+                                             GFP_KERNEL | GFP_DMA);
+               if (devpriv->dma_buffer) {
+                       ret = request_dma(dma_chan, dev->board_name);
+                       if (ret == 0) {
+                               unsigned long dma_flags;
+
+                               devpriv->dma_chan = dma_chan;
+                               dma_flags = claim_dma_lock();
+                               disable_dma(devpriv->dma_chan);
+                               set_dma_mode(devpriv->dma_chan, DMA_MODE_READ);
+                               release_dma_lock(dma_flags);
+                       } else {
+                               kfree(devpriv->dma_buffer);
+                       }
+               }
+       }
+#endif
+
+       ret = comedi_alloc_subdevices(dev, 5);
+       if (ret)
+               return ret;
+
+       /* analog input subdevice */
+       s = &dev->subdevices[0];
+       s->type         = COMEDI_SUBD_AI;
+       s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON | SDF_DIFF;
+       s->n_chan       = 8;
+       s->len_chanlist = 8;
+       s->maxdata      = 0x0fff;
+       s->range_table  = board->ai_range_table;
+       s->insn_read    = labpc_ai_insn_read;
+       if (dev->irq) {
+               dev->read_subdev = s;
+               s->subdev_flags |= SDF_CMD_READ;
+               s->do_cmd       = labpc_ai_cmd;
+               s->do_cmdtest   = labpc_ai_cmdtest;
+               s->cancel       = labpc_cancel;
+       }
+
+       /* analog output */
+       s = &dev->subdevices[1];
+       if (board->has_ao) {
+               s->type         = COMEDI_SUBD_AO;
+               s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND;
+               s->n_chan       = NUM_AO_CHAN;
+               s->maxdata      = 0x0fff;
+               s->range_table  = &range_labpc_ao;
+               s->insn_read    = labpc_ao_insn_read;
+               s->insn_write   = labpc_ao_insn_write;
+
+               /* initialize analog outputs to a known value */
+               for (i = 0; i < s->n_chan; i++) {
+                       short lsb, msb;
+
+                       devpriv->ao_value[i] = s->maxdata / 2;
+                       lsb = devpriv->ao_value[i] & 0xff;
+                       msb = (devpriv->ao_value[i] >> 8) & 0xff;
+                       devpriv->write_byte(lsb, dev->iobase + DAC_LSB_REG(i));
+                       devpriv->write_byte(msb, dev->iobase + DAC_MSB_REG(i));
+               }
+       } else {
+               s->type         = COMEDI_SUBD_UNUSED;
+       }
+
+       /* 8255 dio */
+       s = &dev->subdevices[2];
+       ret = subdev_8255_init(dev, s,
+                              (board->has_mmio) ? labpc_8255_mmio : NULL,
+                              dev->iobase + DIO_BASE_REG);
+       if (ret)
+               return ret;
+
+       /*  calibration subdevices for boards that have one */
+       s = &dev->subdevices[3];
+       if (board->register_layout == labpc_1200_layout) {
+               s->type         = COMEDI_SUBD_CALIB;
+               s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
+               s->n_chan       = 16;
+               s->maxdata      = 0xff;
+               s->insn_read    = labpc_calib_insn_read;
+               s->insn_write   = labpc_calib_insn_write;
+
+               for (i = 0; i < s->n_chan; i++)
+                       write_caldac(dev, i, s->maxdata / 2);
+       } else
+               s->type         = COMEDI_SUBD_UNUSED;
+
+       /* EEPROM */
+       s = &dev->subdevices[4];
+       if (board->register_layout == labpc_1200_layout) {
+               s->type         = COMEDI_SUBD_MEMORY;
+               s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
+               s->n_chan       = EEPROM_SIZE;
+               s->maxdata      = 0xff;
+               s->insn_read    = labpc_eeprom_insn_read;
+               s->insn_write   = labpc_eeprom_insn_write;
+
+               for (i = 0; i < s->n_chan; i++)
+                       devpriv->eeprom_data[i] = labpc_eeprom_read(dev, i);
+       } else
+               s->type         = COMEDI_SUBD_UNUSED;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(labpc_common_attach);
+
+static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
+{
+       const struct labpc_boardinfo *board = comedi_board(dev);
+       struct labpc_private *devpriv;
+       unsigned long iobase = 0;
+       unsigned int irq = 0;
+       unsigned int dma_chan = 0;
+
+       devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
+       if (!devpriv)
+               return -ENOMEM;
+       dev->private = devpriv;
+
+       /* get base address, irq etc. based on bustype */
+       switch (board->bustype) {
+       case isa_bustype:
+#ifdef CONFIG_ISA_DMA_API
+               iobase = it->options[0];
+               irq = it->options[1];
+               dma_chan = it->options[2];
+#else
+               dev_err(dev->class_dev,
+                       "ni_labpc driver has not been built with ISA DMA support.\n");
+               return -EINVAL;
+#endif
+               break;
+       case pci_bustype:
+#ifdef CONFIG_COMEDI_PCI_DRIVERS
+               dev_err(dev->class_dev,
+                       "manual configuration of PCI board '%s' is not supported\n",
+                       board->name);
+               return -EINVAL;
+#else
+               dev_err(dev->class_dev,
+                       "ni_labpc driver has not been built with PCI support.\n");
+               return -EINVAL;
+#endif
+               break;
+       default:
+               dev_err(dev->class_dev,
+                       "ni_labpc: bug! couldn't determine board type\n");
+               return -EINVAL;
+               break;
+       }
+
+       return labpc_common_attach(dev, iobase, irq, dma_chan);
+}
+
+static const struct labpc_boardinfo *
+labpc_pci_find_boardinfo(struct pci_dev *pcidev)
+{
+       unsigned int device_id = pcidev->device;
+       unsigned int n;
+
+       for (n = 0; n < ARRAY_SIZE(labpc_boards); n++) {
+               const struct labpc_boardinfo *board = &labpc_boards[n];
+               if (board->bustype == pci_bustype &&
+                   board->device_id == device_id)
+                       return board;
+       }
+       return NULL;
+}
+
+static int labpc_auto_attach(struct comedi_device *dev,
+                                      unsigned long context_unused)
+{
+       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+       struct labpc_private *devpriv;
+       unsigned long iobase;
+       unsigned int irq;
+       int ret;
+
+       if (!IS_ENABLED(CONFIG_COMEDI_PCI_DRIVERS))
+               return -ENODEV;
+
+       ret = comedi_pci_enable(dev);
+       if (ret)
+               return ret;
+
+       devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
+       if (!devpriv)
+               return -ENOMEM;
+       dev->private = devpriv;
+
+       dev->board_ptr = labpc_pci_find_boardinfo(pcidev);
+       if (!dev->board_ptr)
+               return -ENODEV;
+       devpriv->mite = mite_alloc(pcidev);
+       if (!devpriv->mite)
+               return -ENOMEM;
+       ret = mite_setup(devpriv->mite);
+       if (ret < 0)
+               return ret;
+       iobase = (unsigned long)devpriv->mite->daq_io_addr;
+       irq = mite_irq(devpriv->mite);
+       return labpc_common_attach(dev, iobase, irq, 0);
+}
+
+void labpc_common_detach(struct comedi_device *dev)
+{
+       const struct labpc_boardinfo *board = comedi_board(dev);
+       struct labpc_private *devpriv = dev->private;
+       struct comedi_subdevice *s;
+
+       if (!board)
+               return;
+       if (dev->subdevices) {
+               s = &dev->subdevices[2];
+               subdev_8255_cleanup(dev, s);
+       }
+#ifdef CONFIG_ISA_DMA_API
+       /* only free stuff if it has been allocated by _attach */
+       kfree(devpriv->dma_buffer);
+       if (devpriv->dma_chan)
+               free_dma(devpriv->dma_chan);
+#endif
+       if (dev->irq)
+               free_irq(dev->irq, dev);
+       if (board->bustype == isa_bustype && dev->iobase)
+               release_region(dev->iobase, LABPC_SIZE);
+#ifdef CONFIG_COMEDI_PCI_DRIVERS
+       if (devpriv->mite) {
+               mite_unsetup(devpriv->mite);
+               mite_free(devpriv->mite);
+       }
+       if (board->bustype == pci_bustype)
+               comedi_pci_disable(dev);
+#endif
+}
+EXPORT_SYMBOL_GPL(labpc_common_detach);
+
 static struct comedi_driver labpc_driver = {
-       .driver_name = DRV_NAME,
-       .module = THIS_MODULE,
-       .attach = labpc_attach,
-       .auto_attach = labpc_auto_attach,
-       .detach = labpc_common_detach,
-       .num_names = ARRAY_SIZE(labpc_boards),
-       .board_name = &labpc_boards[0].name,
-       .offset = sizeof(struct labpc_board_struct),
+       .driver_name    = "ni_labpc",
+       .module         = THIS_MODULE,
+       .attach         = labpc_attach,
+       .auto_attach    = labpc_auto_attach,
+       .detach         = labpc_common_detach,
+       .num_names      = ARRAY_SIZE(labpc_boards),
+       .board_name     = &labpc_boards[0].name,
+       .offset         = sizeof(struct labpc_boardinfo),
 };
 
 #ifdef CONFIG_COMEDI_PCI_DRIVERS
 static DEFINE_PCI_DEVICE_TABLE(labpc_pci_table) = {
-       {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x161)},
-       {0}
+       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x161) },
+       { 0 }
 };
 MODULE_DEVICE_TABLE(pci, labpc_pci_table);
 
 static int labpc_pci_probe(struct pci_dev *dev,
-                                    const struct pci_device_id *ent)
+                          const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &labpc_driver);
+       return comedi_pci_auto_config(dev, &labpc_driver, id->driver_data);
 }
 
 static struct pci_driver labpc_pci_driver = {
-       .name = DRV_NAME,
-       .id_table = labpc_pci_table,
-       .probe = labpc_pci_probe,
+       .name           = "ni_labpc",
+       .id_table       = labpc_pci_table,
+       .probe          = labpc_pci_probe,
        .remove         = comedi_pci_auto_unconfig,
 };
 module_comedi_pci_driver(labpc_driver, labpc_pci_driver);
index e052ed3ba544cc258a04fab5e1228e46b82e7546..0bf2ca13c827a993eca792308a6aa18e37ef9123 100644 (file)
@@ -33,7 +33,7 @@ enum transfer_type { fifo_not_empty_transfer, fifo_half_full_transfer,
        isa_dma_transfer
 };
 
-struct labpc_board_struct {
+struct labpc_boardinfo {
        const char *name;
        int device_id;          /*  device id for pci and pcmcia boards */
        int ai_speed;           /*  maximum input speed in nanoseconds */
@@ -44,31 +44,30 @@ struct labpc_board_struct {
        int has_ao;             /*  has analog output true/false */
        const struct comedi_lrange *ai_range_table;
        const int *ai_range_code;
-       const int *ai_range_is_unipolar;
 
        /*  board can auto scan up in ai channels, not just down */
        unsigned ai_scan_up:1;
 
        /* uses memory mapped io instead of ioports */
-       unsigned memory_mapped_io:1;
+       unsigned has_mmio:1;
 };
 
 struct labpc_private {
        struct mite_struct *mite;       /*  for mite chip on pci-1200 */
        /*  number of data points left to be taken */
-       volatile unsigned long long count;
+       unsigned long long count;
        /*  software copy of analog output values */
        unsigned int ao_value[NUM_AO_CHAN];
        /*  software copys of bits written to command registers */
-       volatile unsigned int command1_bits;
-       volatile unsigned int command2_bits;
-       volatile unsigned int command3_bits;
-       volatile unsigned int command4_bits;
-       volatile unsigned int command5_bits;
-       volatile unsigned int command6_bits;
+       unsigned int cmd1;
+       unsigned int cmd2;
+       unsigned int cmd3;
+       unsigned int cmd4;
+       unsigned int cmd5;
+       unsigned int cmd6;
        /*  store last read of board status registers */
-       volatile unsigned int status1_bits;
-       volatile unsigned int status2_bits;
+       unsigned int stat1;
+       unsigned int stat2;
        /*
         * value to load into board's counter a0 (conversion pacing) for timed
         * conversions
@@ -105,7 +104,6 @@ int labpc_common_attach(struct comedi_device *dev, unsigned long iobase,
                        unsigned int irq, unsigned int dma);
 void labpc_common_detach(struct comedi_device *dev);
 
-extern const int labpc_1200_is_unipolar[];
 extern const int labpc_1200_ai_gain_bits[];
 extern const struct comedi_lrange range_labpc_1200_ai;
 
index be7d1413b2e513a5b4bf4f8af553eae9de117be2..4e1deed99a210cd6f0ba6febb8585c0a01e1d11e 100644 (file)
@@ -73,7 +73,7 @@ NI manuals:
 #include <pcmcia/cisreg.h>
 #include <pcmcia/ds.h>
 
-static const struct labpc_board_struct labpc_cs_boards[] = {
+static const struct labpc_boardinfo labpc_cs_boards[] = {
        {
                .name                   = "daqcard-1200",
                .device_id              = 0x103,
@@ -83,7 +83,6 @@ static const struct labpc_board_struct labpc_cs_boards[] = {
                .has_ao                 = 1,
                .ai_range_table         = &range_labpc_1200_ai,
                .ai_range_code          = labpc_1200_ai_gain_bits,
-               .ai_range_is_unipolar   = labpc_1200_is_unipolar,
        },
 };
 
index b7403597e9050e1f96a32b2d6592d092e6d120e8..ca52b759fb9e96f8326e89477154c6f5173226d0 100644 (file)
@@ -696,9 +696,10 @@ static void ni_release_cdo_mite_channel(struct comedi_device *dev)
 static void ni_e_series_enable_second_irq(struct comedi_device *dev,
                                          unsigned gpct_index, short enable)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
 
-       if (boardtype.reg_type & ni_reg_m_series_mask)
+       if (board->reg_type & ni_reg_m_series_mask)
                return;
        switch (gpct_index) {
        case 0:
@@ -728,16 +729,17 @@ static void ni_e_series_enable_second_irq(struct comedi_device *dev,
 
 static void ni_clear_ai_fifo(struct comedi_device *dev)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
 
-       if (boardtype.reg_type == ni_reg_6143) {
+       if (board->reg_type == ni_reg_6143) {
                /*  Flush the 6143 data FIFO */
                ni_writel(0x10, AIFIFO_Control_6143);   /*  Flush fifo */
                ni_writel(0x00, AIFIFO_Control_6143);   /*  Flush fifo */
                while (ni_readl(AIFIFO_Status_6143) & 0x10) ;   /*  Wait for complete */
        } else {
                devpriv->stc_writew(dev, 1, ADC_FIFO_Clear);
-               if (boardtype.reg_type == ni_reg_625x) {
+               if (board->reg_type == ni_reg_625x) {
                        ni_writeb(0, M_Offset_Static_AI_Control(0));
                        ni_writeb(1, M_Offset_Static_AI_Control(0));
 #if 0
@@ -845,7 +847,7 @@ static irqreturn_t ni_E_interrupt(int irq, void *d)
        struct mite_struct *mite = devpriv->mite;
 #endif
 
-       if (dev->attached == 0)
+       if (!dev->attached)
                return IRQ_NONE;
        smp_mb();               /*  make sure dev->attached is checked before handler does anything else. */
 
@@ -1292,6 +1294,7 @@ static void ni_mio_print_status_b(int status)
 static void ni_ao_fifo_load(struct comedi_device *dev,
                            struct comedi_subdevice *s, int n)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
        int chan;
@@ -1309,10 +1312,10 @@ static void ni_ao_fifo_load(struct comedi_device *dev,
 
                range = CR_RANGE(cmd->chanlist[chan]);
 
-               if (boardtype.reg_type & ni_reg_6xxx_mask) {
+               if (board->reg_type & ni_reg_6xxx_mask) {
                        packed_data = d & 0xffff;
                        /* 6711 only has 16 bit wide ao fifo */
-                       if (boardtype.reg_type != ni_reg_6711) {
+                       if (board->reg_type != ni_reg_6711) {
                                err &= comedi_buf_get(async, &d);
                                if (err == 0)
                                        break;
@@ -1352,6 +1355,7 @@ static void ni_ao_fifo_load(struct comedi_device *dev,
 static int ni_ao_fifo_half_empty(struct comedi_device *dev,
                                 struct comedi_subdevice *s)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        int n;
 
        n = comedi_buf_read_n_available(s->async);
@@ -1361,8 +1365,8 @@ static int ni_ao_fifo_half_empty(struct comedi_device *dev,
        }
 
        n /= sizeof(short);
-       if (n > boardtype.ao_fifo_depth / 2)
-               n = boardtype.ao_fifo_depth / 2;
+       if (n > board->ao_fifo_depth / 2)
+               n = board->ao_fifo_depth / 2;
 
        ni_ao_fifo_load(dev, s, n);
 
@@ -1374,12 +1378,13 @@ static int ni_ao_fifo_half_empty(struct comedi_device *dev,
 static int ni_ao_prep_fifo(struct comedi_device *dev,
                           struct comedi_subdevice *s)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        int n;
 
        /* reset fifo */
        devpriv->stc_writew(dev, 1, DAC_FIFO_Clear);
-       if (boardtype.reg_type & ni_reg_6xxx_mask)
+       if (board->reg_type & ni_reg_6xxx_mask)
                ni_ao_win_outl(dev, 0x6, AO_FIFO_Offset_Load_611x);
 
        /* load some data */
@@ -1388,8 +1393,8 @@ static int ni_ao_prep_fifo(struct comedi_device *dev,
                return 0;
 
        n /= sizeof(short);
-       if (n > boardtype.ao_fifo_depth)
-               n = boardtype.ao_fifo_depth;
+       if (n > board->ao_fifo_depth)
+               n = board->ao_fifo_depth;
 
        ni_ao_fifo_load(dev, s, n);
 
@@ -1399,11 +1404,12 @@ static int ni_ao_prep_fifo(struct comedi_device *dev,
 static void ni_ai_fifo_read(struct comedi_device *dev,
                            struct comedi_subdevice *s, int n)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        struct comedi_async *async = s->async;
        int i;
 
-       if (boardtype.reg_type == ni_reg_611x) {
+       if (board->reg_type == ni_reg_611x) {
                short data[2];
                u32 dl;
 
@@ -1420,7 +1426,7 @@ static void ni_ai_fifo_read(struct comedi_device *dev,
                        data[0] = dl & 0xffff;
                        cfc_write_to_buffer(s, data[0]);
                }
-       } else if (boardtype.reg_type == ni_reg_6143) {
+       } else if (board->reg_type == ni_reg_6143) {
                short data[2];
                u32 dl;
 
@@ -1458,10 +1464,11 @@ static void ni_ai_fifo_read(struct comedi_device *dev,
 
 static void ni_handle_fifo_half_full(struct comedi_device *dev)
 {
-       int n;
+       const struct ni_board_struct *board = comedi_board(dev);
        struct comedi_subdevice *s = &dev->subdevices[NI_AI_SUBDEV];
+       int n;
 
-       n = boardtype.ai_fifo_depth / 2;
+       n = board->ai_fifo_depth / 2;
 
        ni_ai_fifo_read(dev, s, n);
 }
@@ -1508,6 +1515,7 @@ static int ni_ai_drain_dma(struct comedi_device *dev)
 */
 static void ni_handle_fifo_dregs(struct comedi_device *dev)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        struct comedi_subdevice *s = &dev->subdevices[NI_AI_SUBDEV];
        short data[2];
@@ -1515,7 +1523,7 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev)
        short fifo_empty;
        int i;
 
-       if (boardtype.reg_type == ni_reg_611x) {
+       if (board->reg_type == ni_reg_611x) {
                while ((devpriv->stc_readw(dev,
                                           AI_Status_1_Register) &
                        AI_FIFO_Empty_St) == 0) {
@@ -1526,7 +1534,7 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev)
                        data[1] = (dl & 0xffff);
                        cfc_write_array_to_buffer(s, data, sizeof(data));
                }
-       } else if (boardtype.reg_type == ni_reg_6143) {
+       } else if (board->reg_type == ni_reg_6143) {
                i = 0;
                while (ni_readl(AIFIFO_Status_6143) & 0x04) {
                        dl = ni_readl(AIFIFO_Data_6143);
@@ -1573,12 +1581,13 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev)
 
 static void get_last_sample_611x(struct comedi_device *dev)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv __maybe_unused = dev->private;
        struct comedi_subdevice *s = &dev->subdevices[NI_AI_SUBDEV];
        short data;
        u32 dl;
 
-       if (boardtype.reg_type != ni_reg_611x)
+       if (board->reg_type != ni_reg_611x)
                return;
 
        /* Check if there's a single sample stuck in the FIFO */
@@ -1591,12 +1600,13 @@ static void get_last_sample_611x(struct comedi_device *dev)
 
 static void get_last_sample_6143(struct comedi_device *dev)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv __maybe_unused = dev->private;
        struct comedi_subdevice *s = &dev->subdevices[NI_AI_SUBDEV];
        short data;
        u32 dl;
 
-       if (boardtype.reg_type != ni_reg_6143)
+       if (board->reg_type != ni_reg_6143)
                return;
 
        /* Check if there's a single sample stuck in the FIFO */
@@ -1641,6 +1651,7 @@ static void ni_ai_munge(struct comedi_device *dev, struct comedi_subdevice *s,
 
 static int ni_ai_setup_MITE_dma(struct comedi_device *dev)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        struct comedi_subdevice *s = &dev->subdevices[NI_AI_SUBDEV];
        int retval;
@@ -1660,7 +1671,7 @@ static int ni_ai_setup_MITE_dma(struct comedi_device *dev)
                return -EIO;
        }
 
-       switch (boardtype.reg_type) {
+       switch (board->reg_type) {
        case ni_reg_611x:
        case ni_reg_6143:
                mite_prep_dma(devpriv->ai_mite_chan, 32, 16);
@@ -1681,6 +1692,7 @@ static int ni_ai_setup_MITE_dma(struct comedi_device *dev)
 
 static int ni_ao_setup_MITE_dma(struct comedi_device *dev)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        struct comedi_subdevice *s = &dev->subdevices[NI_AO_SUBDEV];
        int retval;
@@ -1695,7 +1707,7 @@ static int ni_ao_setup_MITE_dma(struct comedi_device *dev)
 
        spin_lock_irqsave(&devpriv->mite_channel_lock, flags);
        if (devpriv->ao_mite_chan) {
-               if (boardtype.reg_type & (ni_reg_611x | ni_reg_6713)) {
+               if (board->reg_type & (ni_reg_611x | ni_reg_6713)) {
                        mite_prep_dma(devpriv->ao_mite_chan, 32, 32);
                } else {
                        /* doing 32 instead of 16 bit wide transfers from memory
@@ -1720,6 +1732,7 @@ static int ni_ao_setup_MITE_dma(struct comedi_device *dev)
 
 static int ni_ai_reset(struct comedi_device *dev, struct comedi_subdevice *s)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
 
        ni_release_ai_mite_channel(dev);
@@ -1735,7 +1748,7 @@ static int ni_ai_reset(struct comedi_device *dev, struct comedi_subdevice *s)
 
        ni_clear_ai_fifo(dev);
 
-       if (boardtype.reg_type != ni_reg_6143)
+       if (board->reg_type != ni_reg_6143)
                ni_writeb(0, Misc_Command);
 
        devpriv->stc_writew(dev, AI_Disarm, AI_Command_1_Register);     /* reset pulses */
@@ -1746,7 +1759,7 @@ static int ni_ai_reset(struct comedi_device *dev, struct comedi_subdevice *s)
        devpriv->stc_writew(dev, 0x0000, AI_Mode_2_Register);
        /* generate FIFO interrupts on non-empty */
        devpriv->stc_writew(dev, (0 << 6) | 0x0000, AI_Mode_3_Register);
-       if (boardtype.reg_type == ni_reg_611x) {
+       if (board->reg_type == ni_reg_611x) {
                devpriv->stc_writew(dev, AI_SHIFTIN_Pulse_Width |
                                    AI_SOC_Polarity |
                                    AI_LOCALMUX_CLK_Pulse_Width,
@@ -1759,7 +1772,7 @@ static int ni_ai_reset(struct comedi_device *dev, struct comedi_subdevice *s)
                                    AI_CONVERT_Output_Select
                                    (AI_CONVERT_Output_Enable_High),
                                    AI_Output_Control_Register);
-       } else if (boardtype.reg_type == ni_reg_6143) {
+       } else if (board->reg_type == ni_reg_6143) {
                devpriv->stc_writew(dev, AI_SHIFTIN_Pulse_Width |
                                    AI_SOC_Polarity |
                                    AI_LOCALMUX_CLK_Pulse_Width,
@@ -1784,7 +1797,7 @@ static int ni_ai_reset(struct comedi_device *dev, struct comedi_subdevice *s)
                    AI_EXTMUX_CLK_Output_Select(0) |
                    AI_LOCALMUX_CLK_Output_Select(2) |
                    AI_SC_TC_Output_Select(3);
-               if (boardtype.reg_type == ni_reg_622x)
+               if (board->reg_type == ni_reg_622x)
                        ai_output_control_bits |=
                            AI_CONVERT_Output_Select
                            (AI_CONVERT_Output_Enable_High);
@@ -1832,9 +1845,10 @@ static int ni_ai_insn_read(struct comedi_device *dev,
                           struct comedi_subdevice *s, struct comedi_insn *insn,
                           unsigned int *data)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        int i, n;
-       const unsigned int mask = (1 << boardtype.adbits) - 1;
+       const unsigned int mask = (1 << board->adbits) - 1;
        unsigned signbits;
        unsigned short d;
        unsigned long dl;
@@ -1844,7 +1858,7 @@ static int ni_ai_insn_read(struct comedi_device *dev,
        ni_clear_ai_fifo(dev);
 
        signbits = devpriv->ai_offset[0];
-       if (boardtype.reg_type == ni_reg_611x) {
+       if (board->reg_type == ni_reg_611x) {
                for (n = 0; n < num_adc_stages_611x; n++) {
                        devpriv->stc_writew(dev, AI_CONVERT_Pulse,
                                            AI_Command_1_Register);
@@ -1877,7 +1891,7 @@ static int ni_ai_insn_read(struct comedi_device *dev,
                        d += signbits;
                        data[n] = d;
                }
-       } else if (boardtype.reg_type == ni_reg_6143) {
+       } else if (board->reg_type == ni_reg_6143) {
                for (n = 0; n < insn->n; n++) {
                        devpriv->stc_writew(dev, AI_CONVERT_Pulse,
                                            AI_Command_1_Register);
@@ -1913,7 +1927,7 @@ static int ni_ai_insn_read(struct comedi_device *dev,
                                    ("ni_mio_common: timeout in ni_ai_insn_read\n");
                                return -ETIME;
                        }
-                       if (boardtype.reg_type & ni_reg_m_series_mask) {
+                       if (board->reg_type & ni_reg_m_series_mask) {
                                data[n] =
                                    ni_readl(M_Offset_AI_FIFO_Data) & mask;
                        } else {
@@ -1948,6 +1962,7 @@ static void ni_m_series_load_channelgain_list(struct comedi_device *dev,
                                              unsigned int n_chan,
                                              unsigned int *list)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        unsigned int chan, range, aref;
        unsigned int i;
@@ -1957,12 +1972,12 @@ static void ni_m_series_load_channelgain_list(struct comedi_device *dev,
 
        devpriv->stc_writew(dev, 1, Configuration_Memory_Clear);
 
-/* offset = 1 << (boardtype.adbits - 1); */
+/* offset = 1 << (board->adbits - 1); */
        if ((list[0] & CR_ALT_SOURCE)) {
                unsigned bypass_bits;
                chan = CR_CHAN(list[0]);
                range = CR_RANGE(list[0]);
-               range_code = ni_gainlkup[boardtype.gainlkup][range];
+               range_code = ni_gainlkup[board->gainlkup][range];
                dither = ((list[0] & CR_ALT_FILTER) != 0);
                bypass_bits = MSeries_AI_Bypass_Config_FIFO_Bit;
                bypass_bits |= chan;
@@ -1989,7 +2004,7 @@ static void ni_m_series_load_channelgain_list(struct comedi_device *dev,
                range = CR_RANGE(list[i]);
                dither = ((list[i] & CR_ALT_FILTER) != 0);
 
-               range_code = ni_gainlkup[boardtype.gainlkup][range];
+               range_code = ni_gainlkup[board->gainlkup][range];
                devpriv->ai_offset[i] = offset;
                switch (aref) {
                case AREF_DIFF:
@@ -2009,7 +2024,7 @@ static void ni_m_series_load_channelgain_list(struct comedi_device *dev,
                }
                config_bits |= MSeries_AI_Config_Channel_Bits(chan);
                config_bits |=
-                   MSeries_AI_Config_Bank_Bits(boardtype.reg_type, chan);
+                   MSeries_AI_Config_Bank_Bits(board->reg_type, chan);
                config_bits |= MSeries_AI_Config_Gain_Bits(range_code);
                if (i == n_chan - 1)
                        config_bits |= MSeries_AI_Config_Last_Channel_Bit;
@@ -2054,6 +2069,7 @@ static void ni_m_series_load_channelgain_list(struct comedi_device *dev,
 static void ni_load_channelgain_list(struct comedi_device *dev,
                                     unsigned int n_chan, unsigned int *list)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        unsigned int chan, range, aref;
        unsigned int i;
@@ -2061,12 +2077,12 @@ static void ni_load_channelgain_list(struct comedi_device *dev,
        unsigned offset;
        unsigned int dither;
 
-       if (boardtype.reg_type & ni_reg_m_series_mask) {
+       if (board->reg_type & ni_reg_m_series_mask) {
                ni_m_series_load_channelgain_list(dev, n_chan, list);
                return;
        }
-       if (n_chan == 1 && (boardtype.reg_type != ni_reg_611x)
-           && (boardtype.reg_type != ni_reg_6143)) {
+       if (n_chan == 1 && (board->reg_type != ni_reg_611x)
+           && (board->reg_type != ni_reg_6143)) {
                if (devpriv->changain_state
                    && devpriv->changain_spec == list[0]) {
                        /*  ready to go. */
@@ -2081,7 +2097,7 @@ static void ni_load_channelgain_list(struct comedi_device *dev,
        devpriv->stc_writew(dev, 1, Configuration_Memory_Clear);
 
        /*  Set up Calibration mode if required */
-       if (boardtype.reg_type == ni_reg_6143) {
+       if (board->reg_type == ni_reg_6143) {
                if ((list[0] & CR_ALT_SOURCE)
                    && !devpriv->ai_calib_source_enabled) {
                        /*  Strobe Relay enable bit */
@@ -2105,9 +2121,9 @@ static void ni_load_channelgain_list(struct comedi_device *dev,
                }
        }
 
-       offset = 1 << (boardtype.adbits - 1);
+       offset = 1 << (board->adbits - 1);
        for (i = 0; i < n_chan; i++) {
-               if ((boardtype.reg_type != ni_reg_6143)
+               if ((board->reg_type != ni_reg_6143)
                    && (list[i] & CR_ALT_SOURCE)) {
                        chan = devpriv->ai_calib_source;
                } else {
@@ -2118,21 +2134,21 @@ static void ni_load_channelgain_list(struct comedi_device *dev,
                dither = ((list[i] & CR_ALT_FILTER) != 0);
 
                /* fix the external/internal range differences */
-               range = ni_gainlkup[boardtype.gainlkup][range];
-               if (boardtype.reg_type == ni_reg_611x)
+               range = ni_gainlkup[board->gainlkup][range];
+               if (board->reg_type == ni_reg_611x)
                        devpriv->ai_offset[i] = offset;
                else
                        devpriv->ai_offset[i] = (range & 0x100) ? 0 : offset;
 
                hi = 0;
                if ((list[i] & CR_ALT_SOURCE)) {
-                       if (boardtype.reg_type == ni_reg_611x)
+                       if (board->reg_type == ni_reg_611x)
                                ni_writew(CR_CHAN(list[i]) & 0x0003,
                                          Calibration_Channel_Select_611x);
                } else {
-                       if (boardtype.reg_type == ni_reg_611x)
+                       if (board->reg_type == ni_reg_611x)
                                aref = AREF_DIFF;
-                       else if (boardtype.reg_type == ni_reg_6143)
+                       else if (board->reg_type == ni_reg_6143)
                                aref = AREF_OTHER;
                        switch (aref) {
                        case AREF_DIFF:
@@ -2152,7 +2168,7 @@ static void ni_load_channelgain_list(struct comedi_device *dev,
 
                ni_writew(hi, Configuration_Memory_High);
 
-               if (boardtype.reg_type != ni_reg_6143) {
+               if (board->reg_type != ni_reg_6143) {
                        lo = range;
                        if (i == n_chan - 1)
                                lo |= AI_LAST_CHANNEL;
@@ -2164,8 +2180,8 @@ static void ni_load_channelgain_list(struct comedi_device *dev,
        }
 
        /* prime the channel/gain list */
-       if ((boardtype.reg_type != ni_reg_611x)
-           && (boardtype.reg_type != ni_reg_6143)) {
+       if ((board->reg_type != ni_reg_611x)
+           && (board->reg_type != ni_reg_6143)) {
                ni_prime_channelgain_list(dev);
        }
 }
@@ -2201,22 +2217,25 @@ static unsigned ni_timer_to_ns(const struct comedi_device *dev, int timer)
 static unsigned ni_min_ai_scan_period_ns(struct comedi_device *dev,
                                         unsigned num_channels)
 {
-       switch (boardtype.reg_type) {
+       const struct ni_board_struct *board = comedi_board(dev);
+
+       switch (board->reg_type) {
        case ni_reg_611x:
        case ni_reg_6143:
                /*  simultaneously-sampled inputs */
-               return boardtype.ai_speed;
+               return board->ai_speed;
                break;
        default:
                /*  multiplexed inputs */
                break;
        }
-       return boardtype.ai_speed * num_channels;
+       return board->ai_speed * num_channels;
 }
 
 static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
                         struct comedi_cmd *cmd)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        int err = 0;
        int tmp;
@@ -2233,8 +2252,8 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
                                        TRIG_TIMER | TRIG_EXT);
 
        sources = TRIG_TIMER | TRIG_EXT;
-       if (boardtype.reg_type == ni_reg_611x ||
-           boardtype.reg_type == ni_reg_6143)
+       if (board->reg_type == ni_reg_611x ||
+           board->reg_type == ni_reg_6143)
                sources |= TRIG_NOW;
        err |= cfc_check_trigger_src(&cmd->convert_src, sources);
 
@@ -2289,12 +2308,12 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
        }
 
        if (cmd->convert_src == TRIG_TIMER) {
-               if ((boardtype.reg_type == ni_reg_611x)
-                   || (boardtype.reg_type == ni_reg_6143)) {
+               if ((board->reg_type == ni_reg_611x)
+                   || (board->reg_type == ni_reg_6143)) {
                        err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
                } else {
                        err |= cfc_check_trigger_arg_min(&cmd->convert_arg,
-                                                        boardtype.ai_speed);
+                                                        board->ai_speed);
                        err |= cfc_check_trigger_arg_max(&cmd->convert_arg,
                                                devpriv->clock_ns * 0xffff);
                }
@@ -2315,7 +2334,7 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
        if (cmd->stop_src == TRIG_COUNT) {
                unsigned int max_count = 0x01000000;
 
-               if (boardtype.reg_type == ni_reg_611x)
+               if (board->reg_type == ni_reg_611x)
                        max_count -= num_adc_stages_611x;
                err |= cfc_check_trigger_arg_max(&cmd->stop_arg, max_count);
                err |= cfc_check_trigger_arg_min(&cmd->stop_arg, 1);
@@ -2341,8 +2360,8 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
                        err++;
        }
        if (cmd->convert_src == TRIG_TIMER) {
-               if ((boardtype.reg_type != ni_reg_611x)
-                   && (boardtype.reg_type != ni_reg_6143)) {
+               if ((board->reg_type != ni_reg_611x)
+                   && (board->reg_type != ni_reg_6143)) {
                        tmp = cmd->convert_arg;
                        cmd->convert_arg =
                            ni_timer_to_ns(dev, ni_ns_to_timer(dev,
@@ -2370,6 +2389,7 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
 
 static int ni_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        const struct comedi_cmd *cmd = &s->async->cmd;
        int timer;
@@ -2426,8 +2446,8 @@ static int ni_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        mode2 &= ~AI_SC_Reload_Mode;
        devpriv->stc_writew(dev, mode2, AI_Mode_2_Register);
 
-       if (cmd->chanlist_len == 1 || (boardtype.reg_type == ni_reg_611x)
-           || (boardtype.reg_type == ni_reg_6143)) {
+       if (cmd->chanlist_len == 1 || (board->reg_type == ni_reg_611x)
+           || (board->reg_type == ni_reg_6143)) {
                start_stop_select |= AI_STOP_Polarity;
                start_stop_select |= AI_STOP_Select(31);        /*  logic low */
                start_stop_select |= AI_STOP_Sync;
@@ -2442,7 +2462,7 @@ static int ni_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        case TRIG_COUNT:
                stop_count = cmd->stop_arg - 1;
 
-               if (boardtype.reg_type == ni_reg_611x) {
+               if (board->reg_type == ni_reg_611x) {
                        /*  have to take 3 stage adc pipeline into account */
                        stop_count += num_adc_stages_611x;
                }
@@ -2698,6 +2718,7 @@ static int ni_ai_insn_config(struct comedi_device *dev,
                             struct comedi_subdevice *s,
                             struct comedi_insn *insn, unsigned int *data)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
 
        if (insn->n < 1)
@@ -2707,7 +2728,7 @@ static int ni_ai_insn_config(struct comedi_device *dev,
        case INSN_CONFIG_ANALOG_TRIG:
                return ni_ai_config_analog_trig(dev, s, insn, data);
        case INSN_CONFIG_ALT_SOURCE:
-               if (boardtype.reg_type & ni_reg_m_series_mask) {
+               if (board->reg_type & ni_reg_m_series_mask) {
                        if (data[1] & ~(MSeries_AI_Bypass_Cal_Sel_Pos_Mask |
                                        MSeries_AI_Bypass_Cal_Sel_Neg_Mask |
                                        MSeries_AI_Bypass_Mode_Mux_Mask |
@@ -2715,7 +2736,7 @@ static int ni_ai_insn_config(struct comedi_device *dev,
                                return -EINVAL;
                        }
                        devpriv->ai_calib_source = data[1];
-               } else if (boardtype.reg_type == ni_reg_6143) {
+               } else if (board->reg_type == ni_reg_6143) {
                        unsigned int calib_source;
 
                        calib_source = data[1] & 0xf;
@@ -2735,7 +2756,7 @@ static int ni_ai_insn_config(struct comedi_device *dev,
                        if (calib_source >= 8)
                                return -EINVAL;
                        devpriv->ai_calib_source = calib_source;
-                       if (boardtype.reg_type == ni_reg_611x) {
+                       if (board->reg_type == ni_reg_611x) {
                                ni_writeb(calib_source_adjust,
                                          Cal_Gain_Select_611x);
                        }
@@ -2753,6 +2774,7 @@ static int ni_ai_config_analog_trig(struct comedi_device *dev,
                                    struct comedi_insn *insn,
                                    unsigned int *data)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        unsigned int a, b, modebits;
        int err = 0;
@@ -2761,14 +2783,14 @@ static int ni_ai_config_analog_trig(struct comedi_device *dev,
         * data[2] is analog line
         * data[3] is set level
         * data[4] is reset level */
-       if (!boardtype.has_analog_trig)
+       if (!board->has_analog_trig)
                return -EINVAL;
        if ((data[1] & 0xffff0000) != COMEDI_EV_SCAN_BEGIN) {
                data[1] &= (COMEDI_EV_SCAN_BEGIN | 0xffff);
                err++;
        }
-       if (data[2] >= boardtype.n_adchan) {
-               data[2] = boardtype.n_adchan - 1;
+       if (data[2] >= board->n_adchan) {
+               data[2] = board->n_adchan - 1;
                err++;
        }
        if (data[3] > 255) {    /* a */
@@ -2852,6 +2874,7 @@ static void ni_ao_munge(struct comedi_device *dev, struct comedi_subdevice *s,
                        void *data, unsigned int num_bytes,
                        unsigned int chan_index)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct comedi_async *async = s->async;
        unsigned int range;
        unsigned int i;
@@ -2859,10 +2882,10 @@ static void ni_ao_munge(struct comedi_device *dev, struct comedi_subdevice *s,
        unsigned int length = num_bytes / sizeof(short);
        short *array = data;
 
-       offset = 1 << (boardtype.aobits - 1);
+       offset = 1 << (board->aobits - 1);
        for (i = 0; i < length; i++) {
                range = CR_RANGE(async->cmd.chanlist[chan_index]);
-               if (boardtype.ao_unipolar == 0 || (range & 1) == 0)
+               if (board->ao_unipolar == 0 || (range & 1) == 0)
                        array[i] -= offset;
 #ifdef PCIDMA
                array[i] = cpu_to_le16(array[i]);
@@ -2877,6 +2900,7 @@ static int ni_m_series_ao_config_chanlist(struct comedi_device *dev,
                                          unsigned int chanspec[],
                                          unsigned int n_chans, int timed)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        unsigned int range;
        unsigned int chan;
@@ -2885,7 +2909,7 @@ static int ni_m_series_ao_config_chanlist(struct comedi_device *dev,
        int invert = 0;
 
        if (timed) {
-               for (i = 0; i < boardtype.n_aochan; ++i) {
+               for (i = 0; i < board->n_aochan; ++i) {
                        devpriv->ao_conf[i] &= ~MSeries_AO_Update_Timed_Bit;
                        ni_writeb(devpriv->ao_conf[i],
                                  M_Offset_AO_Config_Bank(i));
@@ -2949,6 +2973,7 @@ static int ni_old_ao_config_chanlist(struct comedi_device *dev,
                                     unsigned int chanspec[],
                                     unsigned int n_chans)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        unsigned int range;
        unsigned int chan;
@@ -2961,10 +2986,10 @@ static int ni_old_ao_config_chanlist(struct comedi_device *dev,
                range = CR_RANGE(chanspec[i]);
                conf = AO_Channel(chan);
 
-               if (boardtype.ao_unipolar) {
+               if (board->ao_unipolar) {
                        if ((range & 1) == 0) {
                                conf |= AO_Bipolar;
-                               invert = (1 << (boardtype.aobits - 1));
+                               invert = (1 << (board->aobits - 1));
                        } else {
                                invert = 0;
                        }
@@ -2972,7 +2997,7 @@ static int ni_old_ao_config_chanlist(struct comedi_device *dev,
                                conf |= AO_Ext_Ref;
                } else {
                        conf |= AO_Bipolar;
-                       invert = (1 << (boardtype.aobits - 1));
+                       invert = (1 << (board->aobits - 1));
                }
 
                /* not all boards can deglitch, but this shouldn't hurt */
@@ -2995,7 +3020,9 @@ static int ni_ao_config_chanlist(struct comedi_device *dev,
                                 unsigned int chanspec[], unsigned int n_chans,
                                 int timed)
 {
-       if (boardtype.reg_type & ni_reg_m_series_mask)
+       const struct ni_board_struct *board = comedi_board(dev);
+
+       if (board->reg_type & ni_reg_m_series_mask)
                return ni_m_series_ao_config_chanlist(dev, s, chanspec, n_chans,
                                                      timed);
        else
@@ -3017,6 +3044,7 @@ static int ni_ao_insn_write(struct comedi_device *dev,
                            struct comedi_subdevice *s,
                            struct comedi_insn *insn, unsigned int *data)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int invert;
@@ -3025,7 +3053,7 @@ static int ni_ao_insn_write(struct comedi_device *dev,
 
        devpriv->ao[chan] = data[0];
 
-       if (boardtype.reg_type & ni_reg_m_series_mask) {
+       if (board->reg_type & ni_reg_m_series_mask) {
                ni_writew(data[0], M_Offset_DAC_Direct_Data(chan));
        } else
                ni_writew(data[0] ^ invert,
@@ -3038,12 +3066,13 @@ static int ni_ao_insn_write_671x(struct comedi_device *dev,
                                 struct comedi_subdevice *s,
                                 struct comedi_insn *insn, unsigned int *data)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int invert;
 
        ao_win_out(1 << chan, AO_Immediate_671x);
-       invert = 1 << (boardtype.aobits - 1);
+       invert = 1 << (board->aobits - 1);
 
        ni_ao_config_chanlist(dev, s, &insn->chanspec, 1, 0);
 
@@ -3057,13 +3086,14 @@ static int ni_ao_insn_config(struct comedi_device *dev,
                             struct comedi_subdevice *s,
                             struct comedi_insn *insn, unsigned int *data)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
 
        switch (data[0]) {
        case INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE:
                switch (data[1]) {
                case COMEDI_OUTPUT:
-                       data[2] = 1 + boardtype.ao_fifo_depth * sizeof(short);
+                       data[2] = 1 + board->ao_fifo_depth * sizeof(short);
                        if (devpriv->mite)
                                data[2] += devpriv->mite->fifo_size;
                        break;
@@ -3085,6 +3115,7 @@ static int ni_ao_insn_config(struct comedi_device *dev,
 static int ni_ao_inttrig(struct comedi_device *dev, struct comedi_subdevice *s,
                         unsigned int trignum)
 {
+       const struct ni_board_struct *board __maybe_unused = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        int ret;
        int interrupt_b_bits;
@@ -3104,7 +3135,7 @@ static int ni_ao_inttrig(struct comedi_device *dev, struct comedi_subdevice *s,
        interrupt_b_bits = AO_Error_Interrupt_Enable;
 #ifdef PCIDMA
        devpriv->stc_writew(dev, 1, DAC_FIFO_Clear);
-       if (boardtype.reg_type & ni_reg_6xxx_mask)
+       if (board->reg_type & ni_reg_6xxx_mask)
                ni_ao_win_outl(dev, 0x6, AO_FIFO_Offset_Load_611x);
        ret = ni_ao_setup_MITE_dma(dev);
        if (ret)
@@ -3155,6 +3186,7 @@ static int ni_ao_inttrig(struct comedi_device *dev, struct comedi_subdevice *s,
 
 static int ni_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        const struct comedi_cmd *cmd = &s->async->cmd;
        int bits;
@@ -3170,7 +3202,7 @@ static int ni_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 
        devpriv->stc_writew(dev, AO_Disarm, AO_Command_1_Register);
 
-       if (boardtype.reg_type & ni_reg_6xxx_mask) {
+       if (board->reg_type & ni_reg_6xxx_mask) {
                ao_win_out(CLEAR_WG, AO_Misc_611x);
 
                bits = 0;
@@ -3233,7 +3265,7 @@ static int ni_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        devpriv->stc_writew(dev, devpriv->ao_mode2, AO_Mode_2_Register);
        switch (cmd->stop_src) {
        case TRIG_COUNT:
-               if (boardtype.reg_type & ni_reg_m_series_mask) {
+               if (board->reg_type & ni_reg_m_series_mask) {
                        /*  this is how the NI example code does it for m-series boards, verified correct with 6259 */
                        devpriv->stc_writel(dev, cmd->stop_arg - 1,
                                            AO_UC_Load_A_Register);
@@ -3301,8 +3333,8 @@ static int ni_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                unsigned bits;
                devpriv->ao_mode1 &= ~AO_Multiple_Channels;
                bits = AO_UPDATE_Output_Select(AO_Update_Output_High_Z);
-               if (boardtype.
-                   reg_type & (ni_reg_m_series_mask | ni_reg_6xxx_mask)) {
+               if (board->reg_type &
+                   (ni_reg_m_series_mask | ni_reg_6xxx_mask)) {
                        bits |= AO_Number_Of_Channels(0);
                } else {
                        bits |=
@@ -3329,14 +3361,14 @@ static int ni_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 
        bits = AO_BC_Source_Select | AO_UPDATE_Pulse_Width |
            AO_TMRDACWR_Pulse_Width;
-       if (boardtype.ao_fifo_depth)
+       if (board->ao_fifo_depth)
                bits |= AO_FIFO_Enable;
        else
                bits |= AO_DMA_PIO_Control;
 #if 0
        /* F Hess: windows driver does not set AO_Number_Of_DAC_Packages bit for 6281,
           verified with bus analyzer. */
-       if (boardtype.reg_type & ni_reg_m_series_mask)
+       if (board->reg_type & ni_reg_m_series_mask)
                bits |= AO_Number_Of_DAC_Packages;
 #endif
        devpriv->stc_writew(dev, bits, AO_Personal_Register);
@@ -3360,6 +3392,7 @@ static int ni_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
                         struct comedi_cmd *cmd)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        int err = 0;
        int tmp;
@@ -3407,7 +3440,7 @@ static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
 
        if (cmd->scan_begin_src == TRIG_TIMER) {
                err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
-                                                boardtype.ao_speed);
+                                                board->ao_speed);
                err |= cfc_check_trigger_arg_max(&cmd->scan_begin_arg,
                                                 devpriv->clock_ns * 0xffffff);
        }
@@ -3448,6 +3481,7 @@ static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
 
 static int ni_ao_reset(struct comedi_device *dev, struct comedi_subdevice *s)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
 
        /* devpriv->ao0p=0x0000; */
@@ -3475,7 +3509,7 @@ static int ni_ao_reset(struct comedi_device *dev, struct comedi_subdevice *s)
        devpriv->stc_writew(dev, devpriv->ao_mode1, AO_Mode_1_Register);
        devpriv->ao_mode2 = 0;
        devpriv->stc_writew(dev, devpriv->ao_mode2, AO_Mode_2_Register);
-       if (boardtype.reg_type & ni_reg_m_series_mask)
+       if (board->reg_type & ni_reg_m_series_mask)
                devpriv->ao_mode3 = AO_Last_Gate_Disable;
        else
                devpriv->ao_mode3 = 0;
@@ -3483,7 +3517,7 @@ static int ni_ao_reset(struct comedi_device *dev, struct comedi_subdevice *s)
        devpriv->ao_trigger_select = 0;
        devpriv->stc_writew(dev, devpriv->ao_trigger_select,
                            AO_Trigger_Select_Register);
-       if (boardtype.reg_type & ni_reg_6xxx_mask) {
+       if (board->reg_type & ni_reg_6xxx_mask) {
                unsigned immediate_bits = 0;
                unsigned i;
                for (i = 0; i < s->n_chan; ++i) {
@@ -3784,6 +3818,7 @@ static int ni_cdio_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
 
 static void handle_cdio_interrupt(struct comedi_device *dev)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv __maybe_unused = dev->private;
        unsigned cdio_status;
        struct comedi_subdevice *s = &dev->subdevices[NI_DIO_SUBDEV];
@@ -3791,7 +3826,7 @@ static void handle_cdio_interrupt(struct comedi_device *dev)
        unsigned long flags;
 #endif
 
-       if ((boardtype.reg_type & ni_reg_m_series_mask) == 0) {
+       if ((board->reg_type & ni_reg_m_series_mask) == 0) {
                return;
        }
 #ifdef PCIDMA
@@ -4038,6 +4073,7 @@ static int ni_serial_sw_readwrite8(struct comedi_device *dev,
 
 static void mio_common_detach(struct comedi_device *dev)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        struct comedi_subdevice *s;
 
@@ -4046,7 +4082,7 @@ static void mio_common_detach(struct comedi_device *dev)
                        ni_gpct_device_destroy(devpriv->counter_dev);
                }
        }
-       if (dev->subdevices && boardtype.has_8255) {
+       if (dev->subdevices && board->has_8255) {
                s = &dev->subdevices[NI_8255_DIO_SUBDEV];
                subdev_8255_cleanup(dev, s);
        }
@@ -4355,14 +4391,15 @@ static int ni_alloc_private(struct comedi_device *dev)
 
 static int ni_E_init(struct comedi_device *dev)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        struct comedi_subdevice *s;
        unsigned j;
        enum ni_gpct_variant counter_variant;
        int ret;
 
-       if (boardtype.n_aochan > MAX_N_AO_CHAN) {
-               printk("bug! boardtype.n_aochan > MAX_N_AO_CHAN\n");
+       if (board->n_aochan > MAX_N_AO_CHAN) {
+               printk("bug! n_aochan > MAX_N_AO_CHAN\n");
                return -EINVAL;
        }
 
@@ -4374,20 +4411,20 @@ static int ni_E_init(struct comedi_device *dev)
 
        s = &dev->subdevices[NI_AI_SUBDEV];
        dev->read_subdev = s;
-       if (boardtype.n_adchan) {
+       if (board->n_adchan) {
                s->type = COMEDI_SUBD_AI;
                s->subdev_flags =
                    SDF_READABLE | SDF_DIFF | SDF_DITHER | SDF_CMD_READ;
-               if (boardtype.reg_type != ni_reg_611x)
+               if (board->reg_type != ni_reg_611x)
                        s->subdev_flags |= SDF_GROUND | SDF_COMMON | SDF_OTHER;
-               if (boardtype.adbits > 16)
+               if (board->adbits > 16)
                        s->subdev_flags |= SDF_LSAMPL;
-               if (boardtype.reg_type & ni_reg_m_series_mask)
+               if (board->reg_type & ni_reg_m_series_mask)
                        s->subdev_flags |= SDF_SOFT_CALIBRATED;
-               s->n_chan = boardtype.n_adchan;
+               s->n_chan = board->n_adchan;
                s->len_chanlist = 512;
-               s->maxdata = (1 << boardtype.adbits) - 1;
-               s->range_table = ni_range_lkup[boardtype.gainlkup];
+               s->maxdata = (1 << board->adbits) - 1;
+               s->range_table = ni_range_lkup[board->gainlkup];
                s->insn_read = &ni_ai_insn_read;
                s->insn_config = &ni_ai_insn_config;
                s->do_cmdtest = &ni_ai_cmdtest;
@@ -4405,40 +4442,40 @@ static int ni_E_init(struct comedi_device *dev)
        /* analog output subdevice */
 
        s = &dev->subdevices[NI_AO_SUBDEV];
-       if (boardtype.n_aochan) {
+       if (board->n_aochan) {
                s->type = COMEDI_SUBD_AO;
                s->subdev_flags = SDF_WRITABLE | SDF_DEGLITCH | SDF_GROUND;
-               if (boardtype.reg_type & ni_reg_m_series_mask)
+               if (board->reg_type & ni_reg_m_series_mask)
                        s->subdev_flags |= SDF_SOFT_CALIBRATED;
-               s->n_chan = boardtype.n_aochan;
-               s->maxdata = (1 << boardtype.aobits) - 1;
-               s->range_table = boardtype.ao_range_table;
+               s->n_chan = board->n_aochan;
+               s->maxdata = (1 << board->aobits) - 1;
+               s->range_table = board->ao_range_table;
                s->insn_read = &ni_ao_insn_read;
-               if (boardtype.reg_type & ni_reg_6xxx_mask) {
+               if (board->reg_type & ni_reg_6xxx_mask) {
                        s->insn_write = &ni_ao_insn_write_671x;
                } else {
                        s->insn_write = &ni_ao_insn_write;
                }
                s->insn_config = &ni_ao_insn_config;
 #ifdef PCIDMA
-               if (boardtype.n_aochan) {
+               if (board->n_aochan) {
                        s->async_dma_dir = DMA_TO_DEVICE;
 #else
-               if (boardtype.ao_fifo_depth) {
+               if (board->ao_fifo_depth) {
 #endif
                        dev->write_subdev = s;
                        s->subdev_flags |= SDF_CMD_WRITE;
                        s->do_cmd = &ni_ao_cmd;
                        s->do_cmdtest = &ni_ao_cmdtest;
-                       s->len_chanlist = boardtype.n_aochan;
-                       if ((boardtype.reg_type & ni_reg_m_series_mask) == 0)
+                       s->len_chanlist = board->n_aochan;
+                       if ((board->reg_type & ni_reg_m_series_mask) == 0)
                                s->munge = ni_ao_munge;
                }
                s->cancel = &ni_ao_reset;
        } else {
                s->type = COMEDI_SUBD_UNUSED;
        }
-       if ((boardtype.reg_type & ni_reg_67xx_mask))
+       if ((board->reg_type & ni_reg_67xx_mask))
                init_ao_67xx(dev, s);
 
        /* digital i/o subdevice */
@@ -4449,8 +4486,8 @@ static int ni_E_init(struct comedi_device *dev)
        s->maxdata = 1;
        s->io_bits = 0;         /* all bits input */
        s->range_table = &range_digital;
-       s->n_chan = boardtype.num_p0_dio_channels;
-       if (boardtype.reg_type & ni_reg_m_series_mask) {
+       s->n_chan = board->num_p0_dio_channels;
+       if (board->reg_type & ni_reg_m_series_mask) {
                s->subdev_flags |=
                    SDF_LSAMPL | SDF_CMD_WRITE /* | SDF_CMD_READ */ ;
                s->insn_bits = &ni_m_series_dio_insn_bits;
@@ -4472,7 +4509,7 @@ static int ni_E_init(struct comedi_device *dev)
 
        /* 8255 device */
        s = &dev->subdevices[NI_8255_DIO_SUBDEV];
-       if (boardtype.has_8255) {
+       if (board->has_8255) {
                subdev_8255_init(dev, s, ni_8255_callback, (unsigned long)dev);
        } else {
                s->type = COMEDI_SUBD_UNUSED;
@@ -4485,14 +4522,14 @@ static int ni_E_init(struct comedi_device *dev)
        /* calibration subdevice -- ai and ao */
        s = &dev->subdevices[NI_CALIBRATION_SUBDEV];
        s->type = COMEDI_SUBD_CALIB;
-       if (boardtype.reg_type & ni_reg_m_series_mask) {
+       if (board->reg_type & ni_reg_m_series_mask) {
                /*  internal PWM analog output used for AI nonlinearity calibration */
                s->subdev_flags = SDF_INTERNAL;
                s->insn_config = &ni_m_series_pwm_config;
                s->n_chan = 1;
                s->maxdata = 0;
                ni_writel(0x0, M_Offset_Cal_PWM);
-       } else if (boardtype.reg_type == ni_reg_6143) {
+       } else if (board->reg_type == ni_reg_6143) {
                /*  internal PWM analog output used for AI nonlinearity calibration */
                s->subdev_flags = SDF_INTERNAL;
                s->insn_config = &ni_6143_pwm_config;
@@ -4510,7 +4547,7 @@ static int ni_E_init(struct comedi_device *dev)
        s->type = COMEDI_SUBD_MEMORY;
        s->subdev_flags = SDF_READABLE | SDF_INTERNAL;
        s->maxdata = 0xff;
-       if (boardtype.reg_type & ni_reg_m_series_mask) {
+       if (board->reg_type & ni_reg_m_series_mask) {
                s->n_chan = M_SERIES_EEPROM_SIZE;
                s->insn_read = &ni_m_series_eeprom_insn_read;
        } else {
@@ -4522,7 +4559,7 @@ static int ni_E_init(struct comedi_device *dev)
        s = &dev->subdevices[NI_PFI_DIO_SUBDEV];
        s->type = COMEDI_SUBD_DIO;
        s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
-       if (boardtype.reg_type & ni_reg_m_series_mask) {
+       if (board->reg_type & ni_reg_m_series_mask) {
                unsigned i;
                s->n_chan = 16;
                ni_writew(s->state, M_Offset_PFI_DO);
@@ -4534,7 +4571,7 @@ static int ni_E_init(struct comedi_device *dev)
                s->n_chan = 10;
        }
        s->maxdata = 1;
-       if (boardtype.reg_type & ni_reg_m_series_mask) {
+       if (board->reg_type & ni_reg_m_series_mask) {
                s->insn_bits = &ni_pfi_insn_bits;
        }
        s->insn_config = &ni_pfi_insn_config;
@@ -4542,11 +4579,11 @@ static int ni_E_init(struct comedi_device *dev)
 
        /* cs5529 calibration adc */
        s = &dev->subdevices[NI_CS5529_CALIBRATION_SUBDEV];
-       if (boardtype.reg_type & ni_reg_67xx_mask) {
+       if (board->reg_type & ni_reg_67xx_mask) {
                s->type = COMEDI_SUBD_AI;
                s->subdev_flags = SDF_READABLE | SDF_DIFF | SDF_INTERNAL;
                /*  one channel for each analog output channel */
-               s->n_chan = boardtype.n_aochan;
+               s->n_chan = board->n_aochan;
                s->maxdata = (1 << 16) - 1;
                s->range_table = &range_unknown;        /* XXX */
                s->insn_read = cs5529_ai_insn_read;
@@ -4576,7 +4613,7 @@ static int ni_E_init(struct comedi_device *dev)
        s->insn_config = ni_rtsi_insn_config;
        ni_rtsi_init(dev);
 
-       if (boardtype.reg_type & ni_reg_m_series_mask) {
+       if (board->reg_type & ni_reg_m_series_mask) {
                counter_variant = ni_gpct_variant_m_series;
        } else {
                counter_variant = ni_gpct_variant_e_series;
@@ -4594,7 +4631,7 @@ static int ni_E_init(struct comedi_device *dev)
                    SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL | SDF_CMD_READ
                    /* | SDF_CMD_WRITE */ ;
                s->n_chan = 3;
-               if (boardtype.reg_type & ni_reg_m_series_mask)
+               if (board->reg_type & ni_reg_m_series_mask)
                        s->maxdata = 0xffffffff;
                else
                        s->maxdata = 0xffffff;
@@ -4626,7 +4663,7 @@ static int ni_E_init(struct comedi_device *dev)
        /* ai configuration */
        s = &dev->subdevices[NI_AI_SUBDEV];
        ni_ai_reset(dev, s);
-       if ((boardtype.reg_type & ni_reg_6xxx_mask) == 0) {
+       if ((board->reg_type & ni_reg_6xxx_mask) == 0) {
                /*  BEAM is this needed for PCI-6143 ?? */
                devpriv->clock_and_fout =
                    Slow_Internal_Time_Divide_By_2 |
@@ -4663,11 +4700,11 @@ static int ni_E_init(struct comedi_device *dev)
        ni_writeb(devpriv->ai_ao_select_reg, AI_AO_Select);
        ni_writeb(devpriv->g0_g1_select_reg, G0_G1_Select);
 
-       if (boardtype.reg_type & ni_reg_6xxx_mask) {
+       if (board->reg_type & ni_reg_6xxx_mask) {
                ni_writeb(0, Magic_611x);
-       } else if (boardtype.reg_type & ni_reg_m_series_mask) {
+       } else if (board->reg_type & ni_reg_m_series_mask) {
                int channel;
-               for (channel = 0; channel < boardtype.n_aochan; ++channel) {
+               for (channel = 0; channel < board->n_aochan; ++channel) {
                        ni_writeb(0xf, M_Offset_AO_Waveform_Order(channel));
                        ni_writeb(0x0,
                                  M_Offset_AO_Reference_Attenuation(channel));
@@ -4938,6 +4975,7 @@ static struct caldac_struct caldacs[] = {
 
 static void caldac_setup(struct comedi_device *dev, struct comedi_subdevice *s)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        int i, j;
        int n_dacs;
@@ -4947,12 +4985,12 @@ static void caldac_setup(struct comedi_device *dev, struct comedi_subdevice *s)
        int type;
        int chan;
 
-       type = boardtype.caldac[0];
+       type = board->caldac[0];
        if (type == caldac_none)
                return;
        n_bits = caldacs[type].n_bits;
        for (i = 0; i < 3; i++) {
-               type = boardtype.caldac[i];
+               type = board->caldac[i];
                if (type == caldac_none)
                        break;
                if (caldacs[type].n_bits != n_bits)
@@ -4971,7 +5009,7 @@ static void caldac_setup(struct comedi_device *dev, struct comedi_subdevice *s)
                s->maxdata_list = maxdata_list = devpriv->caldac_maxdata_list;
                chan = 0;
                for (i = 0; i < n_dacs; i++) {
-                       type = boardtype.caldac[i];
+                       type = board->caldac[i];
                        for (j = 0; j < caldacs[type].n_chans; j++) {
                                maxdata_list[chan] =
                                    (1 << caldacs[type].n_bits) - 1;
@@ -4982,7 +5020,7 @@ static void caldac_setup(struct comedi_device *dev, struct comedi_subdevice *s)
                for (chan = 0; chan < s->n_chan; chan++)
                        ni_write_caldac(dev, i, s->maxdata_list[i] / 2);
        } else {
-               type = boardtype.caldac[0];
+               type = board->caldac[0];
                s->maxdata = (1 << caldacs[type].n_bits) - 1;
 
                for (chan = 0; chan < s->n_chan; chan++)
@@ -4992,6 +5030,7 @@ static void caldac_setup(struct comedi_device *dev, struct comedi_subdevice *s)
 
 static void ni_write_caldac(struct comedi_device *dev, int addr, int val)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        unsigned int loadbit = 0, bits = 0, bit, bitstring = 0;
        int i;
@@ -5003,7 +5042,7 @@ static void ni_write_caldac(struct comedi_device *dev, int addr, int val)
        devpriv->caldacs[addr] = val;
 
        for (i = 0; i < 3; i++) {
-               type = boardtype.caldac[i];
+               type = board->caldac[i];
                if (type == caldac_none)
                        break;
                if (addr < caldacs[type].n_chans) {
@@ -5275,7 +5314,9 @@ static int ni_old_set_pfi_routing(struct comedi_device *dev, unsigned chan,
 static int ni_set_pfi_routing(struct comedi_device *dev, unsigned chan,
                              unsigned source)
 {
-       if (boardtype.reg_type & ni_reg_m_series_mask)
+       const struct ni_board_struct *board = comedi_board(dev);
+
+       if (board->reg_type & ni_reg_m_series_mask)
                return ni_m_series_set_pfi_routing(dev, chan, source);
        else
                return ni_old_set_pfi_routing(dev, chan, source);
@@ -5336,7 +5377,9 @@ static unsigned ni_old_get_pfi_routing(struct comedi_device *dev, unsigned chan)
 
 static unsigned ni_get_pfi_routing(struct comedi_device *dev, unsigned chan)
 {
-       if (boardtype.reg_type & ni_reg_m_series_mask)
+       const struct ni_board_struct *board = comedi_board(dev);
+
+       if (board->reg_type & ni_reg_m_series_mask)
                return ni_m_series_get_pfi_routing(dev, chan);
        else
                return ni_old_get_pfi_routing(dev, chan);
@@ -5345,10 +5388,11 @@ static unsigned ni_get_pfi_routing(struct comedi_device *dev, unsigned chan)
 static int ni_config_filter(struct comedi_device *dev, unsigned pfi_channel,
                            enum ni_pfi_filter_select filter)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv __maybe_unused = dev->private;
        unsigned bits;
 
-       if ((boardtype.reg_type & ni_reg_m_series_mask) == 0) {
+       if ((board->reg_type & ni_reg_m_series_mask) == 0) {
                return -ENOTSUPP;
        }
        bits = ni_readl(M_Offset_PFI_Filter);
@@ -5362,9 +5406,10 @@ static int ni_pfi_insn_bits(struct comedi_device *dev,
                            struct comedi_subdevice *s,
                            struct comedi_insn *insn, unsigned int *data)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv __maybe_unused = dev->private;
 
-       if ((boardtype.reg_type & ni_reg_m_series_mask) == 0) {
+       if ((board->reg_type & ni_reg_m_series_mask) == 0) {
                return -ENOTSUPP;
        }
        if (data[0]) {
@@ -5423,6 +5468,7 @@ static int ni_pfi_insn_config(struct comedi_device *dev,
  */
 static void ni_rtsi_init(struct comedi_device *dev)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
 
        /*  Initialises the RTSI bus signal switch to a default state */
@@ -5449,7 +5495,7 @@ static void ni_rtsi_init(struct comedi_device *dev)
            RTSI_Trig_Output_Bits(5,
                                  NI_RTSI_OUTPUT_G_SRC0) |
            RTSI_Trig_Output_Bits(6, NI_RTSI_OUTPUT_G_GATE0);
-       if (boardtype.reg_type & ni_reg_m_series_mask)
+       if (board->reg_type & ni_reg_m_series_mask)
                devpriv->rtsi_trig_b_output_reg |=
                    RTSI_Trig_Output_Bits(7, NI_RTSI_OUTPUT_RTSI_OSC);
        devpriv->stc_writew(dev, devpriv->rtsi_trig_b_output_reg,
@@ -5517,7 +5563,9 @@ static int ni_mseries_get_pll_parameters(unsigned reference_period_ns,
 
 static inline unsigned num_configurable_rtsi_channels(struct comedi_device *dev)
 {
-       if (boardtype.reg_type & ni_reg_m_series_mask)
+       const struct ni_board_struct *board = comedi_board(dev);
+
+       if (board->reg_type & ni_reg_m_series_mask)
                return 8;
        else
                return 7;
@@ -5629,6 +5677,7 @@ static int ni_mseries_set_pll_master_clock(struct comedi_device *dev,
 static int ni_set_master_clock(struct comedi_device *dev, unsigned source,
                               unsigned period_ns)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
 
        if (source == NI_MIO_INTERNAL_CLOCK) {
@@ -5636,7 +5685,7 @@ static int ni_set_master_clock(struct comedi_device *dev, unsigned source,
                devpriv->stc_writew(dev, devpriv->rtsi_trig_direction_reg,
                                    RTSI_Trig_Direction_Register);
                devpriv->clock_ns = TIMEBASE_1_NS;
-               if (boardtype.reg_type & ni_reg_m_series_mask) {
+               if (board->reg_type & ni_reg_m_series_mask) {
                        devpriv->clock_and_fout2 &=
                            ~(MSeries_Timebase1_Select_Bit |
                              MSeries_Timebase3_Select_Bit);
@@ -5646,7 +5695,7 @@ static int ni_set_master_clock(struct comedi_device *dev, unsigned source,
                }
                devpriv->clock_source = source;
        } else {
-               if (boardtype.reg_type & ni_reg_m_series_mask) {
+               if (board->reg_type & ni_reg_m_series_mask) {
                        return ni_mseries_set_pll_master_clock(dev, source,
                                                               period_ns);
                } else {
@@ -5676,6 +5725,8 @@ static int ni_set_master_clock(struct comedi_device *dev, unsigned source,
 static int ni_valid_rtsi_output_source(struct comedi_device *dev, unsigned chan,
                                       unsigned source)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
+
        if (chan >= num_configurable_rtsi_channels(dev)) {
                if (chan == old_RTSI_clock_channel) {
                        if (source == NI_RTSI_OUTPUT_RTSI_OSC)
@@ -5702,7 +5753,7 @@ static int ni_valid_rtsi_output_source(struct comedi_device *dev, unsigned chan,
                return 1;
                break;
        case NI_RTSI_OUTPUT_RTSI_OSC:
-               if (boardtype.reg_type & ni_reg_m_series_mask)
+               if (board->reg_type & ni_reg_m_series_mask)
                        return 1;
                else
                        return 0;
@@ -5758,6 +5809,7 @@ static int ni_rtsi_insn_config(struct comedi_device *dev,
                               struct comedi_subdevice *s,
                               struct comedi_insn *insn, unsigned int *data)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
 
@@ -5766,9 +5818,7 @@ static int ni_rtsi_insn_config(struct comedi_device *dev,
                if (chan < num_configurable_rtsi_channels(dev)) {
                        devpriv->rtsi_trig_direction_reg |=
                            RTSI_Output_Bit(chan,
-                                           (boardtype.
-                                            reg_type & ni_reg_m_series_mask) !=
-                                           0);
+                               (board->reg_type & ni_reg_m_series_mask) != 0);
                } else if (chan == old_RTSI_clock_channel) {
                        devpriv->rtsi_trig_direction_reg |=
                            Drive_RTSI_Clock_Bit;
@@ -5780,9 +5830,7 @@ static int ni_rtsi_insn_config(struct comedi_device *dev,
                if (chan < num_configurable_rtsi_channels(dev)) {
                        devpriv->rtsi_trig_direction_reg &=
                            ~RTSI_Output_Bit(chan,
-                                            (boardtype.
-                                             reg_type & ni_reg_m_series_mask)
-                                            != 0);
+                               (board->reg_type & ni_reg_m_series_mask) != 0);
                } else if (chan == old_RTSI_clock_channel) {
                        devpriv->rtsi_trig_direction_reg &=
                            ~Drive_RTSI_Clock_Bit;
@@ -5795,10 +5843,9 @@ static int ni_rtsi_insn_config(struct comedi_device *dev,
                        data[1] =
                            (devpriv->rtsi_trig_direction_reg &
                             RTSI_Output_Bit(chan,
-                                            (boardtype.reg_type &
-                                             ni_reg_m_series_mask)
-                                            != 0)) ? INSN_CONFIG_DIO_OUTPUT :
-                           INSN_CONFIG_DIO_INPUT;
+                               (board->reg_type & ni_reg_m_series_mask) != 0))
+                               ? INSN_CONFIG_DIO_OUTPUT
+                               : INSN_CONFIG_DIO_INPUT;
                } else if (chan == old_RTSI_clock_channel) {
                        data[1] =
                            (devpriv->rtsi_trig_direction_reg &
index 0a00260d11f317a18ce85ef0e66bb7759b40bc7f..b5f340c186ec74e839d894288e02b96803d8e1b9 100644 (file)
@@ -280,29 +280,30 @@ enum FPGA_Control_Bits {
 static int ni_pcidio_cancel(struct comedi_device *dev,
                            struct comedi_subdevice *s);
 
+enum nidio_boardid {
+       BOARD_PCIDIO_32HS,
+       BOARD_PXI6533,
+       BOARD_PCI6534,
+};
+
 struct nidio_board {
-       int dev_id;
        const char *name;
        unsigned int uses_firmware:1;
 };
 
 static const struct nidio_board nidio_boards[] = {
-       {
-               .dev_id         = 0x1150,
+       [BOARD_PCIDIO_32HS] = {
                .name           = "pci-dio-32hs",
-       }, {
-               .dev_id         = 0x1320,
+       },
+       [BOARD_PXI6533] = {
                .name           = "pxi-6533",
-       }, {
-               .dev_id         = 0x12b0,
+       },
+       [BOARD_PCI6534] = {
                .name           = "pci-6534",
                .uses_firmware  = 1,
        },
 };
 
-#define n_nidio_boards ARRAY_SIZE(nidio_boards)
-#define this_board ((const struct nidio_board *)dev->board_ptr)
-
 struct nidio96_private {
        struct mite_struct *mite;
        int boardtype;
@@ -419,7 +420,7 @@ static irqreturn_t nidio_interrupt(int irq, void *d)
        unsigned int m_status = 0;
 
        /* interrupcions parasites */
-       if (dev->attached == 0) {
+       if (!dev->attached) {
                /* assume it's from another card */
                return IRQ_NONE;
        }
@@ -1094,29 +1095,27 @@ static int pci_6534_upload_firmware(struct comedi_device *dev)
        return ret;
 }
 
-static const struct nidio_board *
-nidio_find_boardinfo(struct pci_dev *pcidev)
-{
-       unsigned int dev_id = pcidev->device;
-       unsigned int n;
-
-       for (n = 0; n < ARRAY_SIZE(nidio_boards); n++) {
-               const struct nidio_board *board = &nidio_boards[n];
-               if (board->dev_id == dev_id)
-                       return board;
-       }
-       return NULL;
-}
-
 static int nidio_auto_attach(struct comedi_device *dev,
-                                      unsigned long context_unused)
+                            unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+       const struct nidio_board *board = NULL;
        struct nidio96_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
        unsigned int irq;
 
+       if (context < ARRAY_SIZE(nidio_boards))
+               board = &nidio_boards[context];
+       if (!board)
+               return -ENODEV;
+       dev->board_ptr = board;
+       dev->board_name = board->name;
+
+       ret = comedi_pci_enable(dev);
+       if (ret)
+               return ret;
+
        devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
        if (!devpriv)
                return -ENOMEM;
@@ -1124,9 +1123,6 @@ static int nidio_auto_attach(struct comedi_device *dev,
 
        spin_lock_init(&devpriv->mite_channel_lock);
 
-       dev->board_ptr = nidio_find_boardinfo(pcidev);
-       if (!dev->board_ptr)
-               return -ENODEV;
        devpriv->mite = mite_alloc(pcidev);
        if (!devpriv->mite)
                return -ENOMEM;
@@ -1141,9 +1137,8 @@ static int nidio_auto_attach(struct comedi_device *dev,
        if (devpriv->di_mite_ring == NULL)
                return -ENOMEM;
 
-       dev->board_name = this_board->name;
        irq = mite_irq(devpriv->mite);
-       if (this_board->uses_firmware) {
+       if (board->uses_firmware) {
                ret = pci_6534_upload_firmware(dev);
                if (ret < 0)
                        return ret;
@@ -1211,6 +1206,7 @@ static void nidio_detach(struct comedi_device *dev)
                        mite_free(devpriv->mite);
                }
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver ni_pcidio_driver = {
@@ -1221,15 +1217,15 @@ static struct comedi_driver ni_pcidio_driver = {
 };
 
 static int ni_pcidio_pci_probe(struct pci_dev *dev,
-                                        const struct pci_device_id *ent)
+                              const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &ni_pcidio_driver);
+       return comedi_pci_auto_config(dev, &ni_pcidio_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(ni_pcidio_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1150) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1320) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x12b0) },
+       { PCI_VDEVICE(NI, 0x1150), BOARD_PCIDIO_32HS },
+       { PCI_VDEVICE(NI, 0x12b0), BOARD_PCI6534 },
+       { PCI_VDEVICE(NI, 0x1320), BOARD_PXI6533 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, ni_pcidio_pci_table);
index 98b43f2fc65d4dae5511b8cee4490668d5922e71..bc83df53872e13c34c58dac45e8624a539b1f25c 100644 (file)
@@ -110,7 +110,6 @@ Bugs:
 
 */
 
-#include <linux/delay.h>
 #include <linux/delay.h>
 
 #include "../comedidev.h"
@@ -163,1031 +162,894 @@ static const struct comedi_lrange range_ni_M_622x_ao = { 1, {
                                                             }
 };
 
+enum ni_pcimio_boardid {
+       BOARD_PCIMIO_16XE_50,
+       BOARD_PCIMIO_16XE_10,
+       BOARD_PCI6014,
+       BOARD_PXI6030E,
+       BOARD_PCIMIO_16E_1,
+       BOARD_PCIMIO_16E_4,
+       BOARD_PXI6040E,
+       BOARD_PCI6031E,
+       BOARD_PCI6032E,
+       BOARD_PCI6033E,
+       BOARD_PCI6071E,
+       BOARD_PCI6023E,
+       BOARD_PCI6024E,
+       BOARD_PCI6025E,
+       BOARD_PXI6025E,
+       BOARD_PCI6034E,
+       BOARD_PCI6035E,
+       BOARD_PCI6052E,
+       BOARD_PCI6110,
+       BOARD_PCI6111,
+       /* BOARD_PCI6115, */
+       /* BOARD_PXI6115, */
+       BOARD_PCI6711,
+       BOARD_PXI6711,
+       BOARD_PCI6713,
+       BOARD_PXI6713,
+       BOARD_PCI6731,
+       /* BOARD_PXI6731, */
+       BOARD_PCI6733,
+       BOARD_PXI6733,
+       BOARD_PXI6071E,
+       BOARD_PXI6070E,
+       BOARD_PXI6052E,
+       BOARD_PXI6031E,
+       BOARD_PCI6036E,
+       BOARD_PCI6220,
+       BOARD_PCI6221,
+       BOARD_PCI6221_37PIN,
+       BOARD_PCI6224,
+       BOARD_PXI6224,
+       BOARD_PCI6225,
+       BOARD_PXI6225,
+       BOARD_PCI6229,
+       BOARD_PCI6250,
+       BOARD_PCI6251,
+       BOARD_PCIE6251,
+       BOARD_PXIE6251,
+       BOARD_PCI6254,
+       BOARD_PCI6259,
+       BOARD_PCIE6259,
+       BOARD_PCI6280,
+       BOARD_PCI6281,
+       BOARD_PXI6281,
+       BOARD_PCI6284,
+       BOARD_PCI6289,
+       BOARD_PCI6143,
+       BOARD_PXI6143,
+};
+
 static const struct ni_board_struct ni_boards[] = {
-       {
-        .device_id = 0x0162,   /*  NI also says 0x1620.  typo? */
-        .name = "pci-mio-16xe-50",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 2048,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_8,
-        .ai_speed = 50000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 0,
-        .ao_range_table = &range_bipolar10,
-        .ao_unipolar = 0,
-        .ao_speed = 50000,
-        .num_p0_dio_channels = 8,
-        .caldac = {dac8800, dac8043},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x1170,
-        .name = "pci-mio-16xe-10",     /*  aka pci-6030E */
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_14,
-        .ai_speed = 10000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 10000,
-        .num_p0_dio_channels = 8,
-        .caldac = {dac8800, dac8043, ad8522},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x28c0,
-        .name = "pci-6014",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_4,
-        .ai_speed = 5000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 0,
-        .ao_range_table = &range_bipolar10,
-        .ao_unipolar = 0,
-        .ao_speed = 100000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x11d0,
-        .name = "pxi-6030e",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_14,
-        .ai_speed = 10000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 10000,
-        .num_p0_dio_channels = 8,
-        .caldac = {dac8800, dac8043, ad8522},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x1180,
-        .name = "pci-mio-16e-1",       /* aka pci-6070e */
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 800,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .caldac = {mb88341},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x1190,
-        .name = "pci-mio-16e-4",       /* aka pci-6040e */
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_16,
-        /*      .Note = there have been reported problems with full speed
-         * on this board */
-        .ai_speed = 2000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 512,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},      /*  doc says mb88341 */
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x11c0,
-        .name = "pxi-6040e",
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 2000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 512,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .caldac = {mb88341},
-        .has_8255 = 0,
-        },
-
-       {
-        .device_id = 0x1330,
-        .name = "pci-6031e",
-        .n_adchan = 64,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_14,
-        .ai_speed = 10000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 10000,
-        .num_p0_dio_channels = 8,
-        .caldac = {dac8800, dac8043, ad8522},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x1270,
-        .name = "pci-6032e",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_14,
-        .ai_speed = 10000,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_fifo_depth = 0,
-        .ao_unipolar = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {dac8800, dac8043, ad8522},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x1340,
-        .name = "pci-6033e",
-        .n_adchan = 64,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_14,
-        .ai_speed = 10000,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_fifo_depth = 0,
-        .ao_unipolar = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {dac8800, dac8043, ad8522},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x1350,
-        .name = "pci-6071e",
-        .n_adchan = 64,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 800,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x2a60,
-        .name = "pci-6023e",
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_4,
-        .ai_speed = 5000,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_unipolar = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},      /* manual is wrong */
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x2a70,
-        .name = "pci-6024e",
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_4,
-        .ai_speed = 5000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 0,
-        .ao_range_table = &range_bipolar10,
-        .ao_unipolar = 0,
-        .ao_speed = 100000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},      /* manual is wrong */
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x2a80,
-        .name = "pci-6025e",
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_4,
-        .ai_speed = 5000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 0,
-        .ao_range_table = &range_bipolar10,
-        .ao_unipolar = 0,
-        .ao_speed = 100000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},      /* manual is wrong */
-        .has_8255 = 1,
-        },
-       {
-        .device_id = 0x2ab0,
-        .name = "pxi-6025e",
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_4,
-        .ai_speed = 5000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 0,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 100000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},      /* manual is wrong */
-        .has_8255 = 1,
-        },
-
-       {
-        .device_id = 0x2ca0,
-        .name = "pci-6034e",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_4,
-        .ai_speed = 5000,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_fifo_depth = 0,
-        .ao_unipolar = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x2c80,
-        .name = "pci-6035e",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_4,
-        .ai_speed = 5000,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 0,
-        .ao_range_table = &range_bipolar10,
-        .ao_unipolar = 0,
-        .ao_speed = 100000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x18b0,
-        .name = "pci-6052e",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 3000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_unipolar = 1,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_speed = 3000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug, ad8804_debug, ad8522},        /* manual is wrong */
-        },
-       {.device_id = 0x14e0,
-        .name = "pci-6110",
-        .n_adchan = 4,
-        .adbits = 12,
-        .ai_fifo_depth = 8192,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_611x,
-        .ai_speed = 200,
-        .n_aochan = 2,
-        .aobits = 16,
-        .reg_type = ni_reg_611x,
-        .ao_range_table = &range_bipolar10,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 2048,
-        .ao_speed = 250,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804, ad8804},
-        },
-       {
-        .device_id = 0x14f0,
-        .name = "pci-6111",
-        .n_adchan = 2,
-        .adbits = 12,
-        .ai_fifo_depth = 8192,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_611x,
-        .ai_speed = 200,
-        .n_aochan = 2,
-        .aobits = 16,
-        .reg_type = ni_reg_611x,
-        .ao_range_table = &range_bipolar10,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 2048,
-        .ao_speed = 250,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804, ad8804},
-        },
+       [BOARD_PCIMIO_16XE_50] = {
+               .name           = "pci-mio-16xe-50",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 2048,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_8,
+               .ai_speed       = 50000,
+               .n_aochan       = 2,
+               .aobits         = 12,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 50000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { dac8800, dac8043 },
+       },
+       [BOARD_PCIMIO_16XE_10] = {
+               .name           = "pci-mio-16xe-10",    /*  aka pci-6030E */
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_14,
+               .ai_speed       = 10000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_unipolar    = 1,
+               .ao_speed       = 10000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { dac8800, dac8043, ad8522 },
+       },
+       [BOARD_PCI6014] = {
+               .name           = "pci-6014",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_4,
+               .ai_speed       = 5000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 100000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },
+       },
+       [BOARD_PXI6030E] = {
+               .name           = "pxi-6030e",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_14,
+               .ai_speed       = 10000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_unipolar    = 1,
+               .ao_speed       = 10000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { dac8800, dac8043, ad8522 },
+       },
+       [BOARD_PCIMIO_16E_1] = {
+               .name           = "pci-mio-16e-1",      /* aka pci-6070e */
+               .n_adchan       = 16,
+               .adbits         = 12,
+               .ai_fifo_depth  = 512,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 800,
+               .n_aochan       = 2,
+               .aobits         = 12,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_unipolar    = 1,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { mb88341 },
+       },
+       [BOARD_PCIMIO_16E_4] = {
+               .name           = "pci-mio-16e-4",      /* aka pci-6040e */
+               .n_adchan       = 16,
+               .adbits         = 12,
+               .ai_fifo_depth  = 512,
+               .gainlkup       = ai_gain_16,
+               /*
+                * there have been reported problems with
+                * full speed on this board
+                */
+               .ai_speed       = 2000,
+               .n_aochan       = 2,
+               .aobits         = 12,
+               .ao_fifo_depth  = 512,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_unipolar    = 1,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },     /* doc says mb88341 */
+       },
+       [BOARD_PXI6040E] = {
+               .name           = "pxi-6040e",
+               .n_adchan       = 16,
+               .adbits         = 12,
+               .ai_fifo_depth  = 512,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 2000,
+               .n_aochan       = 2,
+               .aobits         = 12,
+               .ao_fifo_depth  = 512,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_unipolar    = 1,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { mb88341 },
+       },
+       [BOARD_PCI6031E] = {
+               .name           = "pci-6031e",
+               .n_adchan       = 64,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_14,
+               .ai_speed       = 10000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_unipolar    = 1,
+               .ao_speed       = 10000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { dac8800, dac8043, ad8522 },
+       },
+       [BOARD_PCI6032E] = {
+               .name           = "pci-6032e",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_14,
+               .ai_speed       = 10000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { dac8800, dac8043, ad8522 },
+       },
+       [BOARD_PCI6033E] = {
+               .name           = "pci-6033e",
+               .n_adchan       = 64,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_14,
+               .ai_speed       = 10000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { dac8800, dac8043, ad8522 },
+       },
+       [BOARD_PCI6071E] = {
+               .name           = "pci-6071e",
+               .n_adchan       = 64,
+               .adbits         = 12,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 800,
+               .n_aochan       = 2,
+               .aobits         = 12,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_unipolar    = 1,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },
+       },
+       [BOARD_PCI6023E] = {
+               .name           = "pci-6023e",
+               .n_adchan       = 16,
+               .adbits         = 12,
+               .ai_fifo_depth  = 512,
+               .gainlkup       = ai_gain_4,
+               .ai_speed       = 5000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },     /* manual is wrong */
+       },
+       [BOARD_PCI6024E] = {
+               .name           = "pci-6024e",
+               .n_adchan       = 16,
+               .adbits         = 12,
+               .ai_fifo_depth  = 512,
+               .gainlkup       = ai_gain_4,
+               .ai_speed       = 5000,
+               .n_aochan       = 2,
+               .aobits         = 12,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 100000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },     /* manual is wrong */
+       },
+       [BOARD_PCI6025E] = {
+               .name           = "pci-6025e",
+               .n_adchan       = 16,
+               .adbits         = 12,
+               .ai_fifo_depth  = 512,
+               .gainlkup       = ai_gain_4,
+               .ai_speed       = 5000,
+               .n_aochan       = 2,
+               .aobits         = 12,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 100000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },     /* manual is wrong */
+               .has_8255       = 1,
+       },
+       [BOARD_PXI6025E] = {
+               .name           = "pxi-6025e",
+               .n_adchan       = 16,
+               .adbits         = 12,
+               .ai_fifo_depth  = 512,
+               .gainlkup       = ai_gain_4,
+               .ai_speed       = 5000,
+               .n_aochan       = 2,
+               .aobits         = 12,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_unipolar    = 1,
+               .ao_speed       = 100000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },     /* manual is wrong */
+               .has_8255       = 1,
+       },
+       [BOARD_PCI6034E] = {
+               .name           = "pci-6034e",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_4,
+               .ai_speed       = 5000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },
+       },
+       [BOARD_PCI6035E] = {
+               .name           = "pci-6035e",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_4,
+               .ai_speed       = 5000,
+               .n_aochan       = 2,
+               .aobits         = 12,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 100000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },
+       },
+       [BOARD_PCI6052E] = {
+               .name           = "pci-6052e",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 3000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_unipolar    = 1,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_speed       = 3000,
+               .num_p0_dio_channels = 8,
+               /* manual is wrong */
+               .caldac         = { ad8804_debug, ad8804_debug, ad8522 },
+       },
+       [BOARD_PCI6110] = {
+               .name           = "pci-6110",
+               .n_adchan       = 4,
+               .adbits         = 12,
+               .ai_fifo_depth  = 8192,
+               .alwaysdither   = 0,
+               .gainlkup       = ai_gain_611x,
+               .ai_speed       = 200,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .reg_type       = ni_reg_611x,
+               .ao_range_table = &range_bipolar10,
+               .ao_fifo_depth  = 2048,
+               .ao_speed       = 250,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804, ad8804 },
+       },
+       [BOARD_PCI6111] = {
+               .name           = "pci-6111",
+               .n_adchan       = 2,
+               .adbits         = 12,
+               .ai_fifo_depth  = 8192,
+               .gainlkup       = ai_gain_611x,
+               .ai_speed       = 200,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .reg_type       = ni_reg_611x,
+               .ao_range_table = &range_bipolar10,
+               .ao_fifo_depth  = 2048,
+               .ao_speed       = 250,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804, ad8804 },
+       },
 #if 0
        /* The 6115 boards probably need their own driver */
-       {
-        .device_id = 0x2ed0,
-        .name = "pci-6115",
-        .n_adchan = 4,
-        .adbits = 12,
-        .ai_fifo_depth = 8192,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_611x,
-        .ai_speed = 100,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_671x = 1,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 2048,
-        .ao_speed = 250,
-        .num_p0_dio_channels = 8,
-        .reg_611x = 1,
-        .caldac = {ad8804_debug, ad8804_debug, ad8804_debug},  /* XXX */
-        },
+       [BOARD_PCI6115] = {     /* .device_id = 0x2ed0, */
+               .name           = "pci-6115",
+               .n_adchan       = 4,
+               .adbits         = 12,
+               .ai_fifo_depth  = 8192,
+               .gainlkup       = ai_gain_611x,
+               .ai_speed       = 100,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_671x        = 1,
+               .ao_fifo_depth  = 2048,
+               .ao_speed       = 250,
+               .num_p0_dio_channels = 8,
+               .reg_611x       = 1,
+               /* XXX */
+               .caldac         = { ad8804_debug, ad8804_debug, ad8804_debug },
+       },
 #endif
 #if 0
-       {
-        .device_id = 0x0000,
-        .name = "pxi-6115",
-        .n_adchan = 4,
-        .adbits = 12,
-        .ai_fifo_depth = 8192,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_611x,
-        .ai_speed = 100,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_671x = 1,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 2048,
-        .ao_speed = 250,
-        .reg_611x = 1,
-        .num_p0_dio_channels = 8,
-        caldac = {ad8804_debug, ad8804_debug, ad8804_debug},   /* XXX */
-        },
+       [BOARD_PXI6115] = {     /* .device_id = ????, */
+               .name           = "pxi-6115",
+               .n_adchan       = 4,
+               .adbits         = 12,
+               .ai_fifo_depth  = 8192,
+               .gainlkup       = ai_gain_611x,
+               .ai_speed       = 100,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_671x        = 1,
+               .ao_fifo_depth  = 2048,
+               .ao_speed       = 250,
+               .reg_611x       = 1,
+               .num_p0_dio_channels = 8,
+               /* XXX */
+               .caldac         = { ad8804_debug, ad8804_debug, ad8804_debug },
+       },
 #endif
-       {
-        .device_id = 0x1880,
-        .name = "pci-6711",
-        .n_adchan = 0,         /* no analog input */
-        .n_aochan = 4,
-        .aobits = 12,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 16384,
-        /* data sheet says 8192, but fifo really holds 16384 samples */
-        .ao_range_table = &range_bipolar10,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .reg_type = ni_reg_6711,
-        .caldac = {ad8804_debug},
-        },
-       {
-        .device_id = 0x2b90,
-        .name = "pxi-6711",
-        .n_adchan = 0,         /* no analog input */
-        .n_aochan = 4,
-        .aobits = 12,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 16384,
-        .ao_range_table = &range_bipolar10,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .reg_type = ni_reg_6711,
-        .caldac = {ad8804_debug},
-        },
-       {
-        .device_id = 0x1870,
-        .name = "pci-6713",
-        .n_adchan = 0,         /* no analog input */
-        .n_aochan = 8,
-        .aobits = 12,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 16384,
-        .ao_range_table = &range_bipolar10,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .reg_type = ni_reg_6713,
-        .caldac = {ad8804_debug, ad8804_debug},
-        },
-       {
-        .device_id = 0x2b80,
-        .name = "pxi-6713",
-        .n_adchan = 0,         /* no analog input */
-        .n_aochan = 8,
-        .aobits = 12,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 16384,
-        .ao_range_table = &range_bipolar10,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .reg_type = ni_reg_6713,
-        .caldac = {ad8804_debug, ad8804_debug},
-        },
-       {
-        .device_id = 0x2430,
-        .name = "pci-6731",
-        .n_adchan = 0,         /* no analog input */
-        .n_aochan = 4,
-        .aobits = 16,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 8192,
-        .ao_range_table = &range_bipolar10,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .reg_type = ni_reg_6711,
-        .caldac = {ad8804_debug},
-        },
-#if 0                          /* need device ids */
-       {
-        .device_id = 0x0,
-        .name = "pxi-6731",
-        .n_adchan = 0,         /* no analog input */
-        .n_aochan = 4,
-        .aobits = 16,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 8192,
-        .ao_range_table = &range_bipolar10,
-        .num_p0_dio_channels = 8,
-        .reg_type = ni_reg_6711,
-        .caldac = {ad8804_debug},
-        },
+       [BOARD_PCI6711] = {
+               .name = "pci-6711",
+               .n_aochan       = 4,
+               .aobits         = 12,
+               /* data sheet says 8192, but fifo really holds 16384 samples */
+               .ao_fifo_depth  = 16384,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .reg_type       = ni_reg_6711,
+               .caldac         = { ad8804_debug },
+       },
+       [BOARD_PXI6711] = {
+               .name           = "pxi-6711",
+               .n_aochan       = 4,
+               .aobits         = 12,
+               .ao_fifo_depth  = 16384,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .reg_type       = ni_reg_6711,
+               .caldac         = { ad8804_debug },
+       },
+       [BOARD_PCI6713] = {
+               .name           = "pci-6713",
+               .n_aochan       = 8,
+               .aobits         = 12,
+               .ao_fifo_depth  = 16384,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .reg_type       = ni_reg_6713,
+               .caldac         = { ad8804_debug, ad8804_debug },
+       },
+       [BOARD_PXI6713] = {
+               .name           = "pxi-6713",
+               .n_aochan       = 8,
+               .aobits         = 12,
+               .ao_fifo_depth  = 16384,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .reg_type       = ni_reg_6713,
+               .caldac         = { ad8804_debug, ad8804_debug },
+       },
+       [BOARD_PCI6731] = {
+               .name           = "pci-6731",
+               .n_aochan       = 4,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8192,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .reg_type       = ni_reg_6711,
+               .caldac         = { ad8804_debug },
+       },
+#if 0
+       [BOARD_PXI6731] = {     /* .device_id = ????, */
+               .name           = "pxi-6731",
+               .n_aochan       = 4,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8192,
+               .ao_range_table = &range_bipolar10,
+               .num_p0_dio_channels = 8,
+               .reg_type       = ni_reg_6711,
+               .caldac         = { ad8804_debug },
+       },
 #endif
-       {
-        .device_id = 0x2410,
-        .name = "pci-6733",
-        .n_adchan = 0,         /* no analog input */
-        .n_aochan = 8,
-        .aobits = 16,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 16384,
-        .ao_range_table = &range_bipolar10,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .reg_type = ni_reg_6713,
-        .caldac = {ad8804_debug, ad8804_debug},
-        },
-       {
-        .device_id = 0x2420,
-        .name = "pxi-6733",
-        .n_adchan = 0,         /* no analog input */
-        .n_aochan = 8,
-        .aobits = 16,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 16384,
-        .ao_range_table = &range_bipolar10,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .reg_type = ni_reg_6713,
-        .caldac = {ad8804_debug, ad8804_debug},
-        },
-       {
-        .device_id = 0x15b0,
-        .name = "pxi-6071e",
-        .n_adchan = 64,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 800,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x11b0,
-        .name = "pxi-6070e",
-        .n_adchan = 16,
-        .adbits = 12,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 800,
-        .n_aochan = 2,
-        .aobits = 12,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 1000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x18c0,
-        .name = "pxi-6052e",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_16,
-        .ai_speed = 3000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_unipolar = 1,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_speed = 3000,
-        .num_p0_dio_channels = 8,
-        .caldac = {mb88341, mb88341, ad8522},
-        },
-       {
-        .device_id = 0x1580,
-        .name = "pxi-6031e",
-        .n_adchan = 64,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_14,
-        .ai_speed = 10000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 2048,
-        .ao_range_table = &range_ni_E_ao_ext,
-        .ao_unipolar = 1,
-        .ao_speed = 10000,
-        .num_p0_dio_channels = 8,
-        .caldac = {dac8800, dac8043, ad8522},
-        },
-       {
-        .device_id = 0x2890,
-        .name = "pci-6036e",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        .alwaysdither = 1,
-        .gainlkup = ai_gain_4,
-        .ai_speed = 5000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 0,
-        .ao_range_table = &range_bipolar10,
-        .ao_unipolar = 0,
-        .ao_speed = 100000,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70b0,
-        .name = "pci-6220",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 512,
-        /*      .FIXME = guess */
-        .gainlkup = ai_gain_622x,
-        .ai_speed = 4000,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_fifo_depth = 0,
-        .num_p0_dio_channels = 8,
-        .reg_type = ni_reg_622x,
-        .ao_unipolar = 0,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70af,
-        .name = "pci-6221",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_622x,
-        .ai_speed = 4000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_622x_ao,
-        .reg_type = ni_reg_622x,
-        .ao_unipolar = 0,
-        .ao_speed = 1200,
-        .num_p0_dio_channels = 8,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x71bc,
-        .name = "pci-6221_37pin",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_622x,
-        .ai_speed = 4000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_622x_ao,
-        .reg_type = ni_reg_622x,
-        .ao_unipolar = 0,
-        .ao_speed = 1200,
-        .num_p0_dio_channels = 8,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70f2,
-        .name = "pci-6224",
-        .n_adchan = 32,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_622x,
-        .ai_speed = 4000,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_fifo_depth = 0,
-        .reg_type = ni_reg_622x,
-        .ao_unipolar = 0,
-        .num_p0_dio_channels = 32,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70f3,
-        .name = "pxi-6224",
-        .n_adchan = 32,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_622x,
-        .ai_speed = 4000,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_fifo_depth = 0,
-        .reg_type = ni_reg_622x,
-        .ao_unipolar = 0,
-        .num_p0_dio_channels = 32,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x716c,
-        .name = "pci-6225",
-        .n_adchan = 80,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_622x,
-        .ai_speed = 4000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_622x_ao,
-        .reg_type = ni_reg_622x,
-        .ao_unipolar = 0,
-        .ao_speed = 1200,
-        .num_p0_dio_channels = 32,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x716d,
-        .name = "pxi-6225",
-        .n_adchan = 80,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_622x,
-        .ai_speed = 4000,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_622x_ao,
-        .reg_type = ni_reg_622x,
-        .ao_unipolar = 0,
-        .ao_speed = 1200,
-        .num_p0_dio_channels = 32,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
+       [BOARD_PCI6733] = {
+               .name           = "pci-6733",
+               .n_aochan       = 8,
+               .aobits         = 16,
+               .ao_fifo_depth  = 16384,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .reg_type       = ni_reg_6713,
+               .caldac         = { ad8804_debug, ad8804_debug },
+       },
+       [BOARD_PXI6733] = {
+               .name           = "pxi-6733",
+               .n_aochan       = 8,
+               .aobits         = 16,
+               .ao_fifo_depth  = 16384,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .reg_type       = ni_reg_6713,
+               .caldac         = { ad8804_debug, ad8804_debug },
+       },
+       [BOARD_PXI6071E] = {
+               .name           = "pxi-6071e",
+               .n_adchan       = 64,
+               .adbits         = 12,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 800,
+               .n_aochan       = 2,
+               .aobits         = 12,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_unipolar    = 1,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },
+       },
+       [BOARD_PXI6070E] = {
+               .name           = "pxi-6070e",
+               .n_adchan       = 16,
+               .adbits         = 12,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 800,
+               .n_aochan       = 2,
+               .aobits         = 12,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_unipolar    = 1,
+               .ao_speed       = 1000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },
+       },
+       [BOARD_PXI6052E] = {
+               .name           = "pxi-6052e",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_16,
+               .ai_speed       = 3000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_unipolar    = 1,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_speed       = 3000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { mb88341, mb88341, ad8522 },
+       },
+       [BOARD_PXI6031E] = {
+               .name           = "pxi-6031e",
+               .n_adchan       = 64,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_14,
+               .ai_speed       = 10000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 2048,
+               .ao_range_table = &range_ni_E_ao_ext,
+               .ao_unipolar    = 1,
+               .ao_speed       = 10000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { dac8800, dac8043, ad8522 },
+       },
+       [BOARD_PCI6036E] = {
+               .name = "pci-6036e",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,
+               .alwaysdither   = 1,
+               .gainlkup       = ai_gain_4,
+               .ai_speed       = 5000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_range_table = &range_bipolar10,
+               .ao_speed       = 100000,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug },
+       },
+       [BOARD_PCI6220] = {
+               .name           = "pci-6220",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 512,          /* FIXME: guess */
+               .gainlkup       = ai_gain_622x,
+               .ai_speed       = 4000,
+               .num_p0_dio_channels = 8,
+               .reg_type       = ni_reg_622x,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6221] = {
+               .name           = "pci-6221",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_622x,
+               .ai_speed       = 4000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_622x_ao,
+               .reg_type       = ni_reg_622x,
+               .ao_speed       = 1200,
+               .num_p0_dio_channels = 8,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6221_37PIN] = {
+               .name           = "pci-6221_37pin",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_622x,
+               .ai_speed       = 4000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_622x_ao,
+               .reg_type       = ni_reg_622x,
+               .ao_speed       = 1200,
+               .num_p0_dio_channels = 8,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6224] = {
+               .name           = "pci-6224",
+               .n_adchan       = 32,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_622x,
+               .ai_speed       = 4000,
+               .reg_type       = ni_reg_622x,
+               .num_p0_dio_channels = 32,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PXI6224] = {
+               .name           = "pxi-6224",
+               .n_adchan       = 32,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_622x,
+               .ai_speed       = 4000,
+               .reg_type       = ni_reg_622x,
+               .num_p0_dio_channels = 32,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6225] = {
+               .name           = "pci-6225",
+               .n_adchan       = 80,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_622x,
+               .ai_speed       = 4000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_622x_ao,
+               .reg_type       = ni_reg_622x,
+               .ao_speed       = 1200,
+               .num_p0_dio_channels = 32,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PXI6225] = {
+               .name           = "pxi-6225",
+               .n_adchan       = 80,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_622x,
+               .ai_speed       = 4000,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_622x_ao,
+               .reg_type       = ni_reg_622x,
+               .ao_speed       = 1200,
+               .num_p0_dio_channels = 32,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6229] = {
+               .name           = "pci-6229",
+               .n_adchan       = 32,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_622x,
+               .ai_speed       = 4000,
+               .n_aochan       = 4,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_622x_ao,
+               .reg_type       = ni_reg_622x,
+               .ao_speed       = 1200,
+               .num_p0_dio_channels = 32,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6250] = {
+               .name           = "pci-6250",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 800,
+               .reg_type       = ni_reg_625x,
+               .num_p0_dio_channels = 8,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6251] = {
+               .name           = "pci-6251",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 800,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_625x_ao,
+               .reg_type       = ni_reg_625x,
+               .ao_speed       = 350,
+               .num_p0_dio_channels = 8,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCIE6251] = {
+               .name           = "pcie-6251",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 800,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_625x_ao,
+               .reg_type       = ni_reg_625x,
+               .ao_speed       = 350,
+               .num_p0_dio_channels = 8,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PXIE6251] = {
+               .name           = "pxie-6251",
+               .n_adchan       = 16,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 800,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_625x_ao,
+               .reg_type       = ni_reg_625x,
+               .ao_speed       = 350,
+               .num_p0_dio_channels = 8,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6254] = {
+               .name           = "pci-6254",
+               .n_adchan       = 32,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 800,
+               .reg_type       = ni_reg_625x,
+               .num_p0_dio_channels = 32,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6259] = {
+               .name           = "pci-6259",
+               .n_adchan       = 32,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 800,
+               .n_aochan       = 4,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_625x_ao,
+               .reg_type       = ni_reg_625x,
+               .ao_speed       = 350,
+               .num_p0_dio_channels = 32,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCIE6259] = {
+               .name           = "pcie-6259",
+               .n_adchan       = 32,
+               .adbits         = 16,
+               .ai_fifo_depth  = 4095,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 800,
+               .n_aochan       = 4,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_625x_ao,
+               .reg_type       = ni_reg_625x,
+               .ao_speed       = 350,
+               .num_p0_dio_channels = 32,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6280] = {
+               .name           = "pci-6280",
+               .n_adchan       = 16,
+               .adbits         = 18,
+               .ai_fifo_depth  = 2047,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 1600,
+               .ao_fifo_depth  = 8191,
+               .reg_type       = ni_reg_628x,
+               .num_p0_dio_channels = 8,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6281] = {
+               .name           = "pci-6281",
+               .n_adchan       = 16,
+               .adbits         = 18,
+               .ai_fifo_depth  = 2047,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 1600,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_628x_ao,
+               .reg_type       = ni_reg_628x,
+               .ao_unipolar    = 1,
+               .ao_speed       = 350,
+               .num_p0_dio_channels = 8,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PXI6281] = {
+               .name           = "pxi-6281",
+               .n_adchan       = 16,
+               .adbits         = 18,
+               .ai_fifo_depth  = 2047,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 1600,
+               .n_aochan       = 2,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_628x_ao,
+               .reg_type       = ni_reg_628x,
+               .ao_unipolar    = 1,
+               .ao_speed       = 350,
+               .num_p0_dio_channels = 8,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6284] = {
+               .name           = "pci-6284",
+               .n_adchan       = 32,
+               .adbits         = 18,
+               .ai_fifo_depth  = 2047,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 1600,
+               .reg_type       = ni_reg_628x,
+               .num_p0_dio_channels = 32,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6289] = {
+               .name           = "pci-6289",
+               .n_adchan       = 32,
+               .adbits         = 18,
+               .ai_fifo_depth  = 2047,
+               .gainlkup       = ai_gain_628x,
+               .ai_speed       = 1600,
+               .n_aochan       = 4,
+               .aobits         = 16,
+               .ao_fifo_depth  = 8191,
+               .ao_range_table = &range_ni_M_628x_ao,
+               .reg_type       = ni_reg_628x,
+               .ao_unipolar    = 1,
+               .ao_speed       = 350,
+               .num_p0_dio_channels = 32,
+               .caldac         = { caldac_none },
+       },
+       [BOARD_PCI6143] = {
+               .name           = "pci-6143",
+               .n_adchan       = 8,
+               .adbits         = 16,
+               .ai_fifo_depth  = 1024,
+               .gainlkup       = ai_gain_6143,
+               .ai_speed       = 4000,
+               .reg_type       = ni_reg_6143,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug, ad8804_debug },
+       },
+       [BOARD_PXI6143] = {
+               .name           = "pxi-6143",
+               .n_adchan       = 8,
+               .adbits         = 16,
+               .ai_fifo_depth  = 1024,
+               .gainlkup       = ai_gain_6143,
+               .ai_speed       = 4000,
+               .reg_type       = ni_reg_6143,
+               .num_p0_dio_channels = 8,
+               .caldac         = { ad8804_debug, ad8804_debug },
        },
-       {
-        .device_id = 0x70aa,
-        .name = "pci-6229",
-        .n_adchan = 32,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_622x,
-        .ai_speed = 4000,
-        .n_aochan = 4,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_622x_ao,
-        .reg_type = ni_reg_622x,
-        .ao_unipolar = 0,
-        .ao_speed = 1200,
-        .num_p0_dio_channels = 32,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70b4,
-        .name = "pci-6250",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 800,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_fifo_depth = 0,
-        .reg_type = ni_reg_625x,
-        .ao_unipolar = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70b8,
-        .name = "pci-6251",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 800,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_625x_ao,
-        .reg_type = ni_reg_625x,
-        .ao_unipolar = 0,
-        .ao_speed = 350,
-        .num_p0_dio_channels = 8,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x717d,
-        .name = "pcie-6251",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 800,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_625x_ao,
-        .reg_type = ni_reg_625x,
-        .ao_unipolar = 0,
-        .ao_speed = 350,
-        .num_p0_dio_channels = 8,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x72e8,
-        .name = "pxie-6251",
-        .n_adchan = 16,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 800,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_625x_ao,
-        .reg_type = ni_reg_625x,
-        .ao_unipolar = 0,
-        .ao_speed = 350,
-        .num_p0_dio_channels = 8,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70b7,
-        .name = "pci-6254",
-        .n_adchan = 32,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 800,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_fifo_depth = 0,
-        .reg_type = ni_reg_625x,
-        .ao_unipolar = 0,
-        .num_p0_dio_channels = 32,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70ab,
-        .name = "pci-6259",
-        .n_adchan = 32,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 800,
-        .n_aochan = 4,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_625x_ao,
-        .reg_type = ni_reg_625x,
-        .ao_unipolar = 0,
-        .ao_speed = 350,
-        .num_p0_dio_channels = 32,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x717f,
-        .name = "pcie-6259",
-        .n_adchan = 32,
-        .adbits = 16,
-        .ai_fifo_depth = 4095,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 800,
-        .n_aochan = 4,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_625x_ao,
-        .reg_type = ni_reg_625x,
-        .ao_unipolar = 0,
-        .ao_speed = 350,
-        .num_p0_dio_channels = 32,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70b6,
-        .name = "pci-6280",
-        .n_adchan = 16,
-        .adbits = 18,
-        .ai_fifo_depth = 2047,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 1600,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_fifo_depth = 8191,
-        .reg_type = ni_reg_628x,
-        .ao_unipolar = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70bd,
-        .name = "pci-6281",
-        .n_adchan = 16,
-        .adbits = 18,
-        .ai_fifo_depth = 2047,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 1600,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_628x_ao,
-        .reg_type = ni_reg_628x,
-        .ao_unipolar = 1,
-        .ao_speed = 350,
-        .num_p0_dio_channels = 8,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70bf,
-        .name = "pxi-6281",
-        .n_adchan = 16,
-        .adbits = 18,
-        .ai_fifo_depth = 2047,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 1600,
-        .n_aochan = 2,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_628x_ao,
-        .reg_type = ni_reg_628x,
-        .ao_unipolar = 1,
-        .ao_speed = 350,
-        .num_p0_dio_channels = 8,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70bc,
-        .name = "pci-6284",
-        .n_adchan = 32,
-        .adbits = 18,
-        .ai_fifo_depth = 2047,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 1600,
-        .n_aochan = 0,
-        .aobits = 0,
-        .ao_fifo_depth = 0,
-        .reg_type = ni_reg_628x,
-        .ao_unipolar = 0,
-        .num_p0_dio_channels = 32,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70ac,
-        .name = "pci-6289",
-        .n_adchan = 32,
-        .adbits = 18,
-        .ai_fifo_depth = 2047,
-        .gainlkup = ai_gain_628x,
-        .ai_speed = 1600,
-        .n_aochan = 4,
-        .aobits = 16,
-        .ao_fifo_depth = 8191,
-        .ao_range_table = &range_ni_M_628x_ao,
-        .reg_type = ni_reg_628x,
-        .ao_unipolar = 1,
-        .ao_speed = 350,
-        .num_p0_dio_channels = 32,
-        .caldac = {caldac_none},
-        .has_8255 = 0,
-        },
-       {
-        .device_id = 0x70C0,
-        .name = "pci-6143",
-        .n_adchan = 8,
-        .adbits = 16,
-        .ai_fifo_depth = 1024,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_6143,
-        .ai_speed = 4000,
-        .n_aochan = 0,
-        .aobits = 0,
-        .reg_type = ni_reg_6143,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug, ad8804_debug},
-        },
-       {
-        .device_id = 0x710D,
-        .name = "pxi-6143",
-        .n_adchan = 8,
-        .adbits = 16,
-        .ai_fifo_depth = 1024,
-        .alwaysdither = 0,
-        .gainlkup = ai_gain_6143,
-        .ai_speed = 4000,
-        .n_aochan = 0,
-        .aobits = 0,
-        .reg_type = ni_reg_6143,
-        .ao_unipolar = 0,
-        .ao_fifo_depth = 0,
-        .num_p0_dio_channels = 8,
-        .caldac = {ad8804_debug, ad8804_debug},
-        },
 };
 
 struct ni_private {
@@ -1569,6 +1431,7 @@ static void m_series_init_eeprom_buffer(struct comedi_device *dev)
 
 static void init_6143(struct comedi_device *dev)
 {
+       const struct ni_board_struct *board = comedi_board(dev);
        struct ni_private *devpriv = dev->private;
 
        /*  Disable interrupts */
@@ -1579,7 +1442,8 @@ static void init_6143(struct comedi_device *dev)
        ni_writeb(0x80, PipelineDelay_6143);    /*  Set EOCMode, ADCMode and pipelinedelay */
        ni_writeb(0x00, EOC_Set_6143);  /*  Set EOC Delay */
 
-       ni_writel(boardtype.ai_fifo_depth / 2, AIFIFO_Flag_6143);       /*  Set the FIFO half full level */
+       /* Set the FIFO half full level */
+       ni_writel(board->ai_fifo_depth / 2, AIFIFO_Flag_6143);
 
        /*  Strobe Relay disable bit */
        devpriv->ai_calib_source_enabled = 0;
@@ -1606,48 +1470,38 @@ static void pcimio_detach(struct comedi_device *dev)
                        mite_free(devpriv->mite);
                }
        }
-}
-
-static const struct ni_board_struct *
-pcimio_find_boardinfo(struct pci_dev *pcidev)
-{
-       unsigned int device_id = pcidev->device;
-       unsigned int n;
-
-       for (n = 0; n < ARRAY_SIZE(ni_boards); n++) {
-               const struct ni_board_struct *board = &ni_boards[n];
-               if (board->device_id == device_id)
-                       return board;
-       }
-       return NULL;
+       comedi_pci_disable(dev);
 }
 
 static int pcimio_auto_attach(struct comedi_device *dev,
-                                       unsigned long context_unused)
+                             unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+       const struct ni_board_struct *board = NULL;
        struct ni_private *devpriv;
        int ret;
 
-       dev_info(dev->class_dev, "ni_pcimio: attach %s\n", pci_name(pcidev));
+       if (context < ARRAY_SIZE(ni_boards))
+               board = &ni_boards[context];
+       if (!board)
+               return -ENODEV;
+       dev->board_ptr = board;
+       dev->board_name = board->name;
+
+       ret = comedi_pci_enable(dev);
+       if (ret)
+               return ret;
 
        ret = ni_alloc_private(dev);
        if (ret)
                return ret;
        devpriv = dev->private;
 
-       dev->board_ptr = pcimio_find_boardinfo(pcidev);
-       if (!dev->board_ptr)
-               return -ENODEV;
-
        devpriv->mite = mite_alloc(pcidev);
        if (!devpriv->mite)
                return -ENOMEM;
 
-       dev_dbg(dev->class_dev, "%s\n", boardtype.name);
-       dev->board_name = boardtype.name;
-
-       if (boardtype.reg_type & ni_reg_m_series_mask) {
+       if (board->reg_type & ni_reg_m_series_mask) {
                devpriv->stc_writew = &m_series_stc_writew;
                devpriv->stc_readw = &m_series_stc_readw;
                devpriv->stc_writel = &m_series_stc_writel;
@@ -1681,9 +1535,9 @@ static int pcimio_auto_attach(struct comedi_device *dev,
        if (devpriv->gpct_mite_ring[1] == NULL)
                return -ENOMEM;
 
-       if (boardtype.reg_type & ni_reg_m_series_mask)
+       if (board->reg_type & ni_reg_m_series_mask)
                m_series_init_eeprom_buffer(dev);
-       if (boardtype.reg_type == ni_reg_6143)
+       if (board->reg_type == ni_reg_6143)
                init_6143(dev);
 
        dev->irq = mite_irq(devpriv->mite);
@@ -1788,65 +1642,66 @@ static struct comedi_driver ni_pcimio_driver = {
 };
 
 static int ni_pcimio_pci_probe(struct pci_dev *dev,
-                                        const struct pci_device_id *ent)
+                              const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &ni_pcimio_driver);
+       return comedi_pci_auto_config(dev, &ni_pcimio_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(ni_pcimio_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0162) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1170) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1180) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1190) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11b0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11c0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x11d0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1270) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1330) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1340) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1350) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x14e0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x14f0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1580) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x15b0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1880) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1870) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x18b0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x18c0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2410) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2420) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2430) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2890) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x28c0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a60) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a70) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2a80) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2ab0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b80) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b90) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c80) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2ca0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70aa) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70ab) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70ac) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70af) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b6) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b7) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70b8) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bc) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bd) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70bf) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70c0) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x70f2) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x710d) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x716c) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x716d) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x717f) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x71bc) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x717d) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x72e8) },
+       { PCI_VDEVICE(NI, 0x0162), BOARD_PCIMIO_16XE_50 },      /* 0x1620? */
+       { PCI_VDEVICE(NI, 0x1170), BOARD_PCIMIO_16XE_10 },
+       { PCI_VDEVICE(NI, 0x1180), BOARD_PCIMIO_16E_1 },
+       { PCI_VDEVICE(NI, 0x1190), BOARD_PCIMIO_16E_4 },
+       { PCI_VDEVICE(NI, 0x11b0), BOARD_PXI6070E },
+       { PCI_VDEVICE(NI, 0x11c0), BOARD_PXI6040E },
+       { PCI_VDEVICE(NI, 0x11d0), BOARD_PXI6030E },
+       { PCI_VDEVICE(NI, 0x1270), BOARD_PCI6032E },
+       { PCI_VDEVICE(NI, 0x1330), BOARD_PCI6031E },
+       { PCI_VDEVICE(NI, 0x1340), BOARD_PCI6033E },
+       { PCI_VDEVICE(NI, 0x1350), BOARD_PCI6071E },
+       { PCI_VDEVICE(NI, 0x14e0), BOARD_PCI6110 },
+       { PCI_VDEVICE(NI, 0x14f0), BOARD_PCI6111 },
+       { PCI_VDEVICE(NI, 0x1580), BOARD_PXI6031E },
+       { PCI_VDEVICE(NI, 0x15b0), BOARD_PXI6071E },
+       { PCI_VDEVICE(NI, 0x1880), BOARD_PCI6711 },
+       { PCI_VDEVICE(NI, 0x1870), BOARD_PCI6713 },
+       { PCI_VDEVICE(NI, 0x18b0), BOARD_PCI6052E },
+       { PCI_VDEVICE(NI, 0x18c0), BOARD_PXI6052E },
+       { PCI_VDEVICE(NI, 0x2410), BOARD_PCI6733 },
+       { PCI_VDEVICE(NI, 0x2420), BOARD_PXI6733 },
+       { PCI_VDEVICE(NI, 0x2430), BOARD_PCI6731 },
+       { PCI_VDEVICE(NI, 0x2890), BOARD_PCI6036E },
+       { PCI_VDEVICE(NI, 0x28c0), BOARD_PCI6014 },
+       { PCI_VDEVICE(NI, 0x2a60), BOARD_PCI6023E },
+       { PCI_VDEVICE(NI, 0x2a70), BOARD_PCI6024E },
+       { PCI_VDEVICE(NI, 0x2a80), BOARD_PCI6025E },
+       { PCI_VDEVICE(NI, 0x2ab0), BOARD_PXI6025E },
+       { PCI_VDEVICE(NI, 0x2b80), BOARD_PXI6713 },
+       { PCI_VDEVICE(NI, 0x2b90), BOARD_PXI6711 },
+       { PCI_VDEVICE(NI, 0x2c80), BOARD_PCI6035E },
+       { PCI_VDEVICE(NI, 0x2ca0), BOARD_PCI6034E },
+       { PCI_VDEVICE(NI, 0x70aa), BOARD_PCI6229 },
+       { PCI_VDEVICE(NI, 0x70ab), BOARD_PCI6259 },
+       { PCI_VDEVICE(NI, 0x70ac), BOARD_PCI6289 },
+       { PCI_VDEVICE(NI, 0x70af), BOARD_PCI6221 },
+       { PCI_VDEVICE(NI, 0x70b0), BOARD_PCI6220 },
+       { PCI_VDEVICE(NI, 0x70b4), BOARD_PCI6250 },
+       { PCI_VDEVICE(NI, 0x70b6), BOARD_PCI6280 },
+       { PCI_VDEVICE(NI, 0x70b7), BOARD_PCI6254 },
+       { PCI_VDEVICE(NI, 0x70b8), BOARD_PCI6251 },
+       { PCI_VDEVICE(NI, 0x70bc), BOARD_PCI6284 },
+       { PCI_VDEVICE(NI, 0x70bd), BOARD_PCI6281 },
+       { PCI_VDEVICE(NI, 0x70bf), BOARD_PXI6281 },
+       { PCI_VDEVICE(NI, 0x70c0), BOARD_PCI6143 },
+       { PCI_VDEVICE(NI, 0x70f2), BOARD_PCI6224 },
+       { PCI_VDEVICE(NI, 0x70f3), BOARD_PXI6224 },
+       { PCI_VDEVICE(NI, 0x710d), BOARD_PXI6143 },
+       { PCI_VDEVICE(NI, 0x716c), BOARD_PCI6225 },
+       { PCI_VDEVICE(NI, 0x716d), BOARD_PXI6225 },
+       { PCI_VDEVICE(NI, 0x717f), BOARD_PCIE6259 },
+       { PCI_VDEVICE(NI, 0x71bc), BOARD_PCI6221_37PIN },
+       { PCI_VDEVICE(NI, 0x717d), BOARD_PCIE6251 },
+       { PCI_VDEVICE(NI, 0x72e8), BOARD_PXIE6251 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, ni_pcimio_pci_table);
index 504ea71553340f9b3bdc01581d5ffcdceb61160c..0a613c07760843b36a7eb612372a223a78158f56 100644 (file)
@@ -1421,10 +1421,6 @@ struct ni_board_struct {
        enum caldac_enum caldac[3];
 };
 
-#define n_ni_boards  (sizeof(ni_boards)/sizeof(struct ni_board_struct))
-
-#define boardtype (*(struct ni_board_struct *)dev->board_ptr)
-
 #define MAX_N_AO_CHAN 8
 #define NUM_GPCT 2
 
index f625fdab335c262dda2172e02baca6ce9903b5b6..ebd9e47060509637f02ef248b84123d750416cae 100644 (file)
@@ -837,7 +837,7 @@ start_pacer(struct comedi_device *dev, int mode, unsigned int divisor1,
 
 /*
 ==============================================================================
- Check if channel list from user is builded correctly
+ Check if channel list from user is built correctly
  If it's ok, then return non-zero length of repeated segment of channel list
 */
 static int
index 6a5c914fa50183be2a66ee00cd52dbbf3cdc36cb..46ad048a1ab65c0c09087262929d1696b24c4df1 100644 (file)
 /*
-    comedi/drivers/rtd520.c
-    Comedi driver for Real Time Devices (RTD) PCI4520/DM7520
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 2001 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/drivers/rtd520.c
+ * Comedi driver for Real Time Devices (RTD) PCI4520/DM7520
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 2001 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.
+ *
+ * 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.
+ */
 
-    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.
-*/
-/*
-Driver: rtd520
-Description: Real Time Devices PCI4520/DM7520
-Author: Dan Christian
-Devices: [Real Time Devices] DM7520HR-1 (rtd520), DM7520HR-8,
-  PCI4520, PCI4520-8
-Status: Works.  Only tested on DM7520-8.  Not SMP safe.
-
-Configuration options:
-  [0] - PCI bus of device (optional)
-       If bus / slot is not specified, the first available PCI
-       device will be used.
-  [1] - PCI slot of device (optional)
-*/
 /*
-    Created by Dan Christian, NASA Ames Research Center.
-
-    The PCI4520 is a PCI card.  The DM7520 is a PC/104-plus card.
-    Both have:
-    8/16 12 bit ADC with FIFO and channel gain table
-    8 bits high speed digital out (for external MUX) (or 8 in or 8 out)
-    8 bits high speed digital in with FIFO and interrupt on change (or 8 IO)
-    2 12 bit DACs with FIFOs
-    2 bits output
-    2 bits input
-    bus mastering DMA
-    timers: ADC sample, pacer, burst, about, delay, DA1, DA2
-    sample counter
-    3 user timer/counters (8254)
-    external interrupt
-
-    The DM7520 has slightly fewer features (fewer gain steps).
-
-    These boards can support external multiplexors and multi-board
-    synchronization, but this driver doesn't support that.
-
-    Board docs: http://www.rtdusa.com/PC104/DM/analog%20IO/dm7520.htm
-    Data sheet: http://www.rtdusa.com/pdf/dm7520.pdf
-    Example source: http://www.rtdusa.com/examples/dm/dm7520.zip
-    Call them and ask for the register level manual.
-    PCI chip: http://www.plxtech.com/products/io/pci9080
-
-    Notes:
-    This board is memory mapped.  There is some IO stuff, but it isn't needed.
-
-    I use a pretty loose naming style within the driver (rtd_blah).
-    All externally visible names should be rtd520_blah.
-    I use camelCase for structures (and inside them).
-    I may also use upper CamelCase for function names (old habit).
-
-    This board is somewhat related to the RTD PCI4400 board.
-
-    I borrowed heavily from the ni_mio_common, ni_atmio16d, mite, and
-    das1800, since they have the best documented code.  Driver
-    cb_pcidas64.c uses the same DMA controller.
-
-    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.
-
-*/
+ * Driver: rtd520
+ * Description: Real Time Devices PCI4520/DM7520
+ * Devices: (Real Time Devices) DM7520HR-1 [DM7520]
+ *         (Real Time Devices) DM7520HR-8 [DM7520]
+ *         (Real Time Devices) PCI4520 [PCI4520]
+ *         (Real Time Devices) PCI4520-8 [PCI4520]
+ * Author: Dan Christian
+ * Status: Works. Only tested on DM7520-8. Not SMP safe.
+ *
+ * Configuration options: not applicable, uses PCI auto config
+ */
 
 /*
-  driver status:
-
-  Analog-In supports instruction and command mode.
-
-  With DMA, you can sample at 1.15Mhz with 70% idle on a 400Mhz K6-2
-  (single channel, 64K read buffer).  I get random system lockups when
-  using DMA with ALI-15xx based systems.  I haven't been able to test
-  any other chipsets.  The lockups happen soon after the start of an
-  acquistion, not in the middle of a long run.
-
-  Without DMA, you can do 620Khz sampling with 20% idle on a 400Mhz K6-2
-  (with a 256K read buffer).
-
-  Digital-IO and Analog-Out only support instruction mode.
+ * Created by Dan Christian, NASA Ames Research Center.
+ *
+ * The PCI4520 is a PCI card. The DM7520 is a PC/104-plus card.
+ * Both have:
+ *   8/16 12 bit ADC with FIFO and channel gain table
+ *   8 bits high speed digital out (for external MUX) (or 8 in or 8 out)
+ *   8 bits high speed digital in with FIFO and interrupt on change (or 8 IO)
+ *   2 12 bit DACs with FIFOs
+ *   2 bits output
+ *   2 bits input
+ *   bus mastering DMA
+ *   timers: ADC sample, pacer, burst, about, delay, DA1, DA2
+ *   sample counter
+ *   3 user timer/counters (8254)
+ *   external interrupt
+ *
+ * The DM7520 has slightly fewer features (fewer gain steps).
+ *
+ * These boards can support external multiplexors and multi-board
+ * synchronization, but this driver doesn't support that.
+ *
+ * Board docs: http://www.rtdusa.com/PC104/DM/analog%20IO/dm7520.htm
+ * Data sheet: http://www.rtdusa.com/pdf/dm7520.pdf
+ * Example source: http://www.rtdusa.com/examples/dm/dm7520.zip
+ * Call them and ask for the register level manual.
+ * PCI chip: http://www.plxtech.com/products/io/pci9080
+ *
+ * Notes:
+ * This board is memory mapped. There is some IO stuff, but it isn't needed.
+ *
+ * I use a pretty loose naming style within the driver (rtd_blah).
+ * All externally visible names should be rtd520_blah.
+ * I use camelCase for structures (and inside them).
+ * I may also use upper CamelCase for function names (old habit).
+ *
+ * This board is somewhat related to the RTD PCI4400 board.
+ *
+ * I borrowed heavily from the ni_mio_common, ni_atmio16d, mite, and
+ * das1800, since they have the best documented code. Driver cb_pcidas64.c
+ * uses the same DMA controller.
+ *
+ * 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.
+ */
 
-*/
+/*
+ * driver status:
+ *
+ * Analog-In supports instruction and command mode.
+ *
+ * With DMA, you can sample at 1.15Mhz with 70% idle on a 400Mhz K6-2
+ * (single channel, 64K read buffer). I get random system lockups when
+ * using DMA with ALI-15xx based systems. I haven't been able to test
+ * any other chipsets. The lockups happen soon after the start of an
+ * acquistion, not in the middle of a long run.
+ *
+ * Without DMA, you can do 620Khz sampling with 20% idle on a 400Mhz K6-2
+ * (with a 256K read buffer).
+ *
+ * Digital-IO and Analog-Out only support instruction mode.
+ */
 
 #include <linux/pci.h>
 #include <linux/delay.h>
@@ -108,9 +106,123 @@ Configuration options:
 #include "../comedidev.h"
 
 #include "comedi_fc.h"
-#include "rtd520.h"
 #include "plx9080.h"
 
+/*
+ * Local Address Space 0 Offsets
+ */
+#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 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 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_BCLK              0x0044  /* Burst Clock (10bit) */
+#define LAS0_ADC_SCNT          0x0048  /* A/D Sample counter (10bit) */
+#define LAS0_DAC1_UCNT         0x004c  /* D/A1 Update counter (10 bit) */
+#define LAS0_DAC2_UCNT         0x0050  /* D/A2 Update counter (10 bit) */
+#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_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_DIO_STATUS                0x007c  /* Digital I/O Status */
+#define LAS0_BOARD_RESET       0x0100  /* Board reset */
+#define LAS0_DMA0_SRC          0x0104  /* DMA 0 Sources select */
+#define LAS0_DMA1_SRC          0x0108  /* DMA 1 Sources select */
+#define LAS0_ADC_CONVERSION    0x010c  /* A/D Conversion Signal select */
+#define LAS0_BURST_START       0x0110  /* Burst Clock Start Trigger select */
+#define LAS0_PACER_START       0x0114  /* Pacer Clock Start Trigger select */
+#define LAS0_PACER_STOP                0x0118  /* Pacer Clock Stop Trigger select */
+#define LAS0_ACNT_STOP_ENABLE  0x011c  /* About Counter Stop Enable */
+#define LAS0_PACER_REPEAT      0x0120  /* Pacer Start Trigger Mode select */
+#define LAS0_DIN_START         0x0124  /* HiSpd DI Sampling Signal select */
+#define LAS0_DIN_FIFO_CLEAR    0x0128  /* Digital Input FIFO Clear */
+#define LAS0_ADC_FIFO_CLEAR    0x012c  /* A/D FIFO Clear */
+#define LAS0_CGT_WRITE         0x0130  /* Channel Gain Table Write */
+#define LAS0_CGL_WRITE         0x0134  /* Channel Gain Latch Write */
+#define LAS0_CG_DATA           0x0138  /* Digital Table Write */
+#define LAS0_CGT_ENABLE                0x013c  /* Channel Gain Table Enable */
+#define LAS0_CG_ENABLE         0x0140  /* Digital Table Enable */
+#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_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_SBUS0_ENABLE      0x0188  /* SyncBus 0 enable */
+#define LAS0_SBUS1_SRC         0x018c  /* SyncBus 1 Source select */
+#define LAS0_SBUS1_ENABLE      0x0190  /* SyncBus 1 enable */
+#define LAS0_SBUS2_SRC         0x0198  /* SyncBus 2 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_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 LAS0_DMA1_RESET                0x01d0  /* DMA1 Request state machine reset */
+
+/*
+ * Local Address Space 1 Offsets
+ */
+#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) */
+
 /*======================================================================
   Driver specific stuff (tunable)
 ======================================================================*/
@@ -249,24 +361,27 @@ static const struct comedi_lrange rtd_ao_range = {
        }
 };
 
+enum rtd_boardid {
+       BOARD_DM7520,
+       BOARD_PCI4520,
+};
+
 struct rtdBoard {
        const char *name;
-       int device_id;
        int range10Start;       /* start of +-10V range */
        int rangeUniStart;      /* start of +10V range */
        const struct comedi_lrange *ai_range;
 };
 
 static const struct rtdBoard rtd520Boards[] = {
-       {
+       [BOARD_DM7520] = {
                .name           = "DM7520",
-               .device_id      = 0x7520,
                .range10Start   = 6,
                .rangeUniStart  = 12,
                .ai_range       = &rtd_ai_7520_range,
-       }, {
+       },
+       [BOARD_PCI4520] = {
                .name           = "PCI4520",
-               .device_id      = 0x4520,
                .range10Start   = 8,
                .rangeUniStart  = 16,
                .ai_range       = &rtd_ai_4520_range,
@@ -294,15 +409,6 @@ struct rtdPrivate {
        /* read back data */
        unsigned int aoValue[2];        /* Used for AO read back */
 
-       /* timer gate (when enabled) */
-       u8 utcGate[4];          /* 1 extra allows simple range check */
-
-       /* shadow registers affect other registers, but can't be read back */
-       /* The macros below update these on writes */
-       u16 intMask;            /* interrupt mask */
-       u16 intClearMask;       /* interrupt clear mask */
-       u8 utcCtrl[4];          /* crtl mode for 3 utc + read back */
-       u8 dioStatus;           /* could be read back (dio0Ctrl) */
        unsigned fifoLen;
 };
 
@@ -669,8 +775,7 @@ static irqreturn_t rtd_interrupt(int irq,   /* interrupt number (ignored) */
                goto abortTransfer;
 
        /* clear the interrupt */
-       devpriv->intClearMask = status;
-       writew(devpriv->intClearMask, devpriv->las0 + LAS0_CLEAR);
+       writew(status, devpriv->las0 + LAS0_CLEAR);
        readw(devpriv->las0 + LAS0_CLEAR);
        return IRQ_HANDLED;
 
@@ -685,8 +790,7 @@ transferDone:
        writel(0, devpriv->las0 + LAS0_PACER_STOP);
        writel(0, devpriv->las0 + LAS0_PACER);  /* stop pacer */
        writel(0, devpriv->las0 + LAS0_ADC_CONVERSION);
-       devpriv->intMask = 0;
-       writew(devpriv->intMask, devpriv->las0 + LAS0_IT);
+       writew(0, devpriv->las0 + LAS0_IT);
 
        if (devpriv->aiCount > 0) {     /* there shouldn't be anything left */
                fifoStatus = readl(devpriv->las0 + LAS0_ADC);
@@ -698,8 +802,7 @@ transferDone:
 
        /* clear the interrupt */
        status = readw(devpriv->las0 + LAS0_IT);
-       devpriv->intClearMask = status;
-       writew(devpriv->intClearMask, devpriv->las0 + LAS0_CLEAR);
+       writew(status, devpriv->las0 + LAS0_CLEAR);
        readw(devpriv->las0 + LAS0_CLEAR);
 
        fifoStatus = readl(devpriv->las0 + LAS0_ADC);
@@ -884,8 +987,7 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        writel(0, devpriv->las0 + LAS0_PACER_STOP);
        writel(0, devpriv->las0 + LAS0_PACER);  /* stop pacer */
        writel(0, devpriv->las0 + LAS0_ADC_CONVERSION);
-       devpriv->intMask = 0;
-       writew(devpriv->intMask, devpriv->las0 + LAS0_IT);
+       writew(0, devpriv->las0 + LAS0_IT);
        writel(0, devpriv->las0 + LAS0_ADC_FIFO_CLEAR);
        writel(0, devpriv->las0 + LAS0_OVERRUN);
 
@@ -1011,17 +1113,14 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 
        /* This doesn't seem to work.  There is no way to clear an interrupt
           that the priority controller has queued! */
-       devpriv->intClearMask = ~0;
-       writew(devpriv->intClearMask, devpriv->las0 + LAS0_CLEAR);
+       writew(~0, devpriv->las0 + LAS0_CLEAR);
        readw(devpriv->las0 + LAS0_CLEAR);
 
        /* TODO: allow multiple interrupt sources */
        if (devpriv->transCount > 0) {  /* transfer every N samples */
-               devpriv->intMask = IRQM_ADC_ABOUT_CNT;
-               writew(devpriv->intMask, devpriv->las0 + LAS0_IT);
+               writew(IRQM_ADC_ABOUT_CNT, devpriv->las0 + LAS0_IT);
        } else {                /* 1/2 FIFO transfers */
-               devpriv->intMask = IRQM_ADC_ABOUT_CNT;
-               writew(devpriv->intMask, devpriv->las0 + LAS0_IT);
+               writew(IRQM_ADC_ABOUT_CNT, devpriv->las0 + LAS0_IT);
        }
 
        /* BUG: start_src is ASSUMED to be TRIG_NOW */
@@ -1043,8 +1142,7 @@ static int rtd_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
        writel(0, devpriv->las0 + LAS0_PACER_STOP);
        writel(0, devpriv->las0 + LAS0_PACER);  /* stop pacer */
        writel(0, devpriv->las0 + LAS0_ADC_CONVERSION);
-       devpriv->intMask = 0;
-       writew(devpriv->intMask, devpriv->las0 + LAS0_IT);
+       writew(0, devpriv->las0 + LAS0_IT);
        devpriv->aiCount = 0;   /* stop and don't transfer any more */
        status = readw(devpriv->las0 + LAS0_IT);
        overrun = readl(devpriv->las0 + LAS0_OVERRUN) & 0xffff;
@@ -1125,33 +1223,22 @@ static int rtd_ao_rinsn(struct comedi_device *dev,
        return i;
 }
 
-/*
-   Write a masked set of bits and the read back the port.
-   We track what the bits should be (i.e. we don't read the port first).
-
-   DIO devices are slightly special.  Although it is possible to
- * implement the insn_read/insn_write interface, it is much more
- * useful to applications if you implement the insn_bits interface.
- * This allows packed reading/writing of the DIO channels.  The
- * comedi core can convert between insn_bits and insn_read/write
- */
 static int rtd_dio_insn_bits(struct comedi_device *dev,
                             struct comedi_subdevice *s,
-                            struct comedi_insn *insn, unsigned int *data)
+                            struct comedi_insn *insn,
+                            unsigned int *data)
 {
        struct rtdPrivate *devpriv = dev->private;
+       unsigned int mask = data[0];
+       unsigned int bits = data[1];
 
-       /* The insn data is a mask in data[0] and the new data
-        * in data[1], each channel cooresponding to a bit. */
-       if (data[0]) {
-               s->state &= ~data[0];
-               s->state |= data[0] & data[1];
+       if (mask) {
+               s->state &= ~mask;
+               s->state |= (bits & mask);
 
-               /* Write out the new digital output lines */
                writew(s->state & 0xff, devpriv->las0 + LAS0_DIO0);
        }
-       /* on return, data[1] contains the value of the digital
-        * input lines. */
+
        data[1] = readw(devpriv->las0 + LAS0_DIO0) & 0xff;
 
        return insn->n;
@@ -1188,11 +1275,13 @@ static int rtd_dio_insn_config(struct comedi_device *dev,
        }
 
        /* TODO support digital match interrupts and strobes */
-       devpriv->dioStatus = 0x01;      /* set direction */
-       writew(devpriv->dioStatus, devpriv->las0 + LAS0_DIO_STATUS);
+
+       /* set direction */
+       writew(0x01, devpriv->las0 + LAS0_DIO_STATUS);
        writew(s->io_bits & 0xff, devpriv->las0 + LAS0_DIO0_CTRL);
-       devpriv->dioStatus = 0x00;      /* clear interrupts */
-       writew(devpriv->dioStatus, devpriv->las0 + LAS0_DIO_STATUS);
+
+       /* clear interrupts */
+       writew(0x00, devpriv->las0 + LAS0_DIO_STATUS);
 
        /* port1 can only be all input or all output */
 
@@ -1207,11 +1296,9 @@ static void rtd_reset(struct comedi_device *dev)
 
        writel(0, devpriv->las0 + LAS0_BOARD_RESET);
        udelay(100);            /* needed? */
-       writel(0, devpriv->lcfg + LCFG_ITCSR);
-       devpriv->intMask = 0;
-       writew(devpriv->intMask, devpriv->las0 + LAS0_IT);
-       devpriv->intClearMask = ~0;
-       writew(devpriv->intClearMask, devpriv->las0 + LAS0_CLEAR);
+       writel(0, devpriv->lcfg + PLX_INTRCS_REG);
+       writew(0, devpriv->las0 + LAS0_IT);
+       writew(~0, devpriv->las0 + LAS0_CLEAR);
        readw(devpriv->las0 + LAS0_CLEAR);
 }
 
@@ -1231,16 +1318,11 @@ static void rtd_init_board(struct comedi_device *dev)
        writel(0, devpriv->las0 + LAS0_DAC1_RESET);
        writel(0, devpriv->las0 + LAS0_DAC2_RESET);
        /* clear digital IO fifo */
-       devpriv->dioStatus = 0;
-       writew(devpriv->dioStatus, devpriv->las0 + LAS0_DIO_STATUS);
-       devpriv->utcCtrl[0] = (0 << 6) | 0x30;
-       devpriv->utcCtrl[1] = (1 << 6) | 0x30;
-       devpriv->utcCtrl[2] = (2 << 6) | 0x30;
-       devpriv->utcCtrl[3] = (3 << 6) | 0x00;
-       writeb(devpriv->utcCtrl[0], devpriv->las0 + LAS0_UTC_CTRL);
-       writeb(devpriv->utcCtrl[1], devpriv->las0 + LAS0_UTC_CTRL);
-       writeb(devpriv->utcCtrl[2], devpriv->las0 + LAS0_UTC_CTRL);
-       writeb(devpriv->utcCtrl[3], devpriv->las0 + LAS0_UTC_CTRL);
+       writew(0, devpriv->las0 + LAS0_DIO_STATUS);
+       writeb((0 << 6) | 0x30, devpriv->las0 + LAS0_UTC_CTRL);
+       writeb((1 << 6) | 0x30, devpriv->las0 + LAS0_UTC_CTRL);
+       writeb((2 << 6) | 0x30, devpriv->las0 + LAS0_UTC_CTRL);
+       writeb((3 << 6) | 0x00, devpriv->las0 + LAS0_UTC_CTRL);
        /* TODO: set user out source ??? */
 }
 
@@ -1259,30 +1341,17 @@ static void rtd_pci_latency_quirk(struct comedi_device *dev,
        }
 }
 
-static const void *rtd_find_boardinfo(struct comedi_device *dev,
-                                     struct pci_dev *pcidev)
-{
-       const struct rtdBoard *thisboard;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(rtd520Boards); i++) {
-               thisboard = &rtd520Boards[i];
-               if (pcidev->device == thisboard->device_id)
-                       return thisboard;
-       }
-       return NULL;
-}
-
 static int rtd_auto_attach(struct comedi_device *dev,
-                                    unsigned long context_unused)
+                          unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct rtdBoard *thisboard;
+       const struct rtdBoard *thisboard = NULL;
        struct rtdPrivate *devpriv;
        struct comedi_subdevice *s;
        int ret;
 
-       thisboard = rtd_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(rtd520Boards))
+               thisboard = &rtd520Boards[context];
        if (!thisboard)
                return -ENODEV;
        dev->board_ptr = thisboard;
@@ -1293,17 +1362,13 @@ static int rtd_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
-       dev->iobase = 1;        /* the "detach" needs this */
-
-       devpriv->las0 = ioremap_nocache(pci_resource_start(pcidev, 2),
-                                       pci_resource_len(pcidev, 2));
-       devpriv->las1 = ioremap_nocache(pci_resource_start(pcidev, 3),
-                                       pci_resource_len(pcidev, 3));
-       devpriv->lcfg = ioremap_nocache(pci_resource_start(pcidev, 0),
-                                       pci_resource_len(pcidev, 0));
+
+       devpriv->las0 = pci_ioremap_bar(pcidev, 2);
+       devpriv->las1 = pci_ioremap_bar(pcidev, 3);
+       devpriv->lcfg = pci_ioremap_bar(pcidev, 0);
        if (!devpriv->las0 || !devpriv->las1 || !devpriv->lcfg)
                return -ENOMEM;
 
@@ -1373,7 +1438,7 @@ static int rtd_auto_attach(struct comedi_device *dev,
        devpriv->fifoLen = ret;
 
        if (dev->irq)
-               writel(ICS_PIE | ICS_PLIE, devpriv->lcfg + LCFG_ITCSR);
+               writel(ICS_PIE | ICS_PLIE, devpriv->lcfg + PLX_INTRCS_REG);
 
        dev_info(dev->class_dev, "%s attached\n", dev->board_name);
 
@@ -1383,16 +1448,15 @@ static int rtd_auto_attach(struct comedi_device *dev,
 static void rtd_detach(struct comedi_device *dev)
 {
        struct rtdPrivate *devpriv = dev->private;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
        if (devpriv) {
                /* Shut down any board ops by resetting it */
                if (devpriv->las0 && devpriv->lcfg)
                        rtd_reset(dev);
                if (dev->irq) {
-                       writel(readl(devpriv->lcfg + LCFG_ITCSR) &
+                       writel(readl(devpriv->lcfg + PLX_INTRCS_REG) &
                                ~(ICS_PLIE | ICS_DMA0_E | ICS_DMA1_E),
-                               devpriv->lcfg + LCFG_ITCSR);
+                               devpriv->lcfg + PLX_INTRCS_REG);
                        free_irq(dev->irq, dev);
                }
                if (devpriv->las0)
@@ -1402,10 +1466,7 @@ static void rtd_detach(struct comedi_device *dev)
                if (devpriv->lcfg)
                        iounmap(devpriv->lcfg);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver rtd520_driver = {
@@ -1416,14 +1477,14 @@ static struct comedi_driver rtd520_driver = {
 };
 
 static int rtd520_pci_probe(struct pci_dev *dev,
-                                     const struct pci_device_id *ent)
+                           const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &rtd520_driver);
+       return comedi_pci_auto_config(dev, &rtd520_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(rtd520_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x7520) },
-       { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x4520) },
+       { PCI_VDEVICE(RTD, 0x7520), BOARD_DM7520 },
+       { PCI_VDEVICE(RTD, 0x4520), BOARD_PCI4520 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, rtd520_pci_table);
diff --git a/drivers/staging/comedi/drivers/rtd520.h b/drivers/staging/comedi/drivers/rtd520.h
deleted file mode 100644 (file)
index 25188a5..0000000
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
-    comedi/drivers/rtd520.h
-    Comedi driver defines for Real Time Devices (RTD) PCI4520/DM7520
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 2001 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.
-
-    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.
-*/
-
-/*
-    Created by Dan Christian, NASA Ames Research Center.
-    See board notes in rtd520.c
-*/
-
-/*
- * Local Address Space 0 Offsets
- */
-#define LAS0_USER_IO           0x0008  /* User I/O */
-#define LAS0_ADC               0x0010  /* FIFO Status/Software A/D Start */
-#define LAS0_DAC1              0x0014  /* Software D/A1 Update (w) */
-#define LAS0_DAC2              0x0018  /* Software D/A2 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 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_BCLK              0x0044  /* Burst Clock (10bit) */
-#define LAS0_ADC_SCNT          0x0048  /* A/D Sample counter (10bit) */
-#define LAS0_DAC1_UCNT         0x004c  /* D/A1 Update counter (10 bit) */
-#define LAS0_DAC2_UCNT         0x0050  /* D/A2 Update counter (10 bit) */
-#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_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_DIO_STATUS                0x007c  /* Digital I/O Status */
-#define LAS0_BOARD_RESET       0x0100  /* Board reset */
-#define LAS0_DMA0_SRC          0x0104  /* DMA 0 Sources select */
-#define LAS0_DMA1_SRC          0x0108  /* DMA 1 Sources select */
-#define LAS0_ADC_CONVERSION    0x010c  /* A/D Conversion Signal select */
-#define LAS0_BURST_START       0x0110  /* Burst Clock Start Trigger select */
-#define LAS0_PACER_START       0x0114  /* Pacer Clock Start Trigger select */
-#define LAS0_PACER_STOP                0x0118  /* Pacer Clock Stop Trigger select */
-#define LAS0_ACNT_STOP_ENABLE  0x011c  /* About Counter Stop Enable */
-#define LAS0_PACER_REPEAT      0x0120  /* Pacer Start Trigger Mode select */
-#define LAS0_DIN_START         0x0124  /* HiSpd DI Sampling Signal select */
-#define LAS0_DIN_FIFO_CLEAR    0x0128  /* Digital Input FIFO Clear */
-#define LAS0_ADC_FIFO_CLEAR    0x012c  /* A/D FIFO Clear */
-#define LAS0_CGT_WRITE         0x0130  /* Channel Gain Table Write */
-#define LAS0_CGL_WRITE         0x0134  /* Channel Gain Latch Write */
-#define LAS0_CG_DATA           0x0138  /* Digital Table Write */
-#define LAS0_CGT_ENABLE                0x013c  /* Channel Gain Table Enable */
-#define LAS0_CG_ENABLE         0x0140  /* Digital Table Enable */
-#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_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_SBUS0_ENABLE      0x0188  /* SyncBus 0 enable */
-#define LAS0_SBUS1_SRC         0x018c  /* SyncBus 1 Source select */
-#define LAS0_SBUS1_ENABLE      0x0190  /* SyncBus 1 enable */
-#define LAS0_SBUS2_SRC         0x0198  /* SyncBus 2 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_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 LAS0_DMA1_RESET                0x01d0  /* DMA1 Request state machine reset */
-
-/*
- * Local Address Space 1 Offsets
- */
-#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) */
-
-/*
- * PLX 9080 local config & runtime registers
- */
-#define LCFG_ITCSR             0x0068  /* Interrupt Control/Status */
-#define LCFG_DMAMODE0          0x0080  /* DMA0 Mode */
-#define LCFG_DMAPADR0          0x0084  /* DMA0 PCI Address */
-#define LCFG_DMALADR0          0x0088  /* DMA0 Local Address */
-#define LCFG_DMASIZ0           0x008c  /* DMA0 Transfer Size (Bytes) */
-#define LCFG_DMADPR0           0x0090  /* DMA0 Descriptor Pointer */
-#define LCFG_DMAMODE1          0x0094  /* DMA1 Mode */
-#define LCFG_DMAPADR1          0x0098  /* DMA1 PCI Address */
-#define LCFG_DMALADR1          0x009c  /* DMA1 Local Address */
-#define LCFG_DMASIZ1           0x00a0  /* DMA1 Transfer Size (Bytes) */
-#define LCFG_DMADPR1           0x00a4  /* DMA1 Descriptor Pointer */
-#define LCFG_DMACSR0           0x00a8  /* DMA0 Command/Status */
-#define LCFG_DMACSR1           0x00a9  /* DMA0 Command/Status */
-#define LCFG_DMAARB            0x00ac  /* DMA Arbitration */
-#define LCFG_DMATHR            0x00b0  /* DMA Threshold */
-
-/*  FIFO Status Word Bits (RtdFifoStatus) */
-#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 */
-
-/*  Timer Status Word Bits (GetTimerStatus) */
-#define TS_PCLK_GATE           (1 << 0)  /* Pacer Clock Gate enabled */
-#define TS_BCLK_GATE           (1 << 1)  /* Burst Clock Gate running */
-#define TS_DCNT_GATE           (1 << 2)  /* Pacer Clock Delayed Start Trig. */
-#define TS_ACNT_GATE           (1 << 3)  /* Pacer Clock About Trig. */
-#define TS_PCLK_RUN            (1 << 4)  /* Pacer Clock Shutdown Flag */
-
-/*  External Trigger polarity select */
-/*  External Interrupt polarity select */
-#define POL_POSITIVE         0x0       /*  positive edge */
-#define POL_NEGATIVE         0x1       /*  negative edge */
-
-/*  User Output Signal select (SetUout0Source, SetUout1Source) */
-#define UOUT_ADC                0x0    /*  A/D Conversion Signal */
-#define UOUT_DAC1               0x1    /*  D/A1 Update */
-#define UOUT_DAC2               0x2    /*  D/A2 Update */
-#define UOUT_SOFTWARE           0x3    /*  Software Programmable */
-
-/*  Pacer clock select (SetPacerSource) */
-#define PCLK_INTERNAL           1      /*  Internal Pacer Clock */
-#define PCLK_EXTERNAL           0      /*  External Pacer Clock */
-
-/*  A/D Sample Counter Sources (SetAdcntSource, SetupSampleCounter) */
-#define ADC_SCNT_CGT_RESET         0x0 /*  needs restart with StartPacer */
-#define ADC_SCNT_FIFO_WRITE        0x1
-
-/*  A/D Conversion Signal Select (for SetConversionSelect) */
-#define ADC_START_SOFTWARE         0x0 /*  Software A/D Start */
-#define ADC_START_PCLK             0x1 /*  Pacer Clock (Ext. Int. see Func.509) */
-#define ADC_START_BCLK             0x2 /*  Burst Clock */
-#define ADC_START_DIGITAL_IT       0x3 /*  Digital Interrupt */
-#define ADC_START_DAC1_MARKER1     0x4 /*  D/A 1 Data Marker 1 */
-#define ADC_START_DAC2_MARKER1     0x5 /*  D/A 2 Data Marker 1 */
-#define ADC_START_SBUS0            0x6 /*  SyncBus 0 */
-#define ADC_START_SBUS1            0x7 /*  SyncBus 1 */
-#define ADC_START_SBUS2            0x8 /*  SyncBus 2 */
-
-/*  Burst Clock start trigger select (SetBurstStart) */
-#define BCLK_START_SOFTWARE        0x0 /*  Software A/D Start (StartBurst) */
-#define BCLK_START_PCLK            0x1 /*  Pacer Clock */
-#define BCLK_START_ETRIG           0x2 /*  External Trigger */
-#define BCLK_START_DIGITAL_IT      0x3 /*  Digital Interrupt */
-#define BCLK_START_SBUS0           0x4 /*  SyncBus 0 */
-#define BCLK_START_SBUS1           0x5 /*  SyncBus 1 */
-#define BCLK_START_SBUS2           0x6 /*  SyncBus 2 */
-
-/*  Pacer Clock start trigger select (SetPacerStart) */
-#define PCLK_START_SOFTWARE        0x0 /*  Software Pacer Start (StartPacer) */
-#define PCLK_START_ETRIG           0x1 /*  External trigger */
-#define PCLK_START_DIGITAL_IT      0x2 /*  Digital interrupt */
-#define PCLK_START_UTC2            0x3 /*  User TC 2 out */
-#define PCLK_START_SBUS0           0x4 /*  SyncBus 0 */
-#define PCLK_START_SBUS1           0x5 /*  SyncBus 1 */
-#define PCLK_START_SBUS2           0x6 /*  SyncBus 2 */
-#define PCLK_START_D_SOFTWARE      0x8 /*  Delayed Software Pacer Start */
-#define PCLK_START_D_ETRIG         0x9 /*  Delayed external trigger */
-#define PCLK_START_D_DIGITAL_IT    0xA /*  Delayed digital interrupt */
-#define PCLK_START_D_UTC2          0xB /*  Delayed User TC 2 out */
-#define PCLK_START_D_SBUS0         0xC /*  Delayed SyncBus 0 */
-#define PCLK_START_D_SBUS1         0xD /*  Delayed SyncBus 1 */
-#define PCLK_START_D_SBUS2         0xE /*  Delayed SyncBus 2 */
-#define PCLK_START_ETRIG_GATED     0xF /*  External Trigger Gated controlled mode */
-
-/*  Pacer Clock Stop Trigger select (SetPacerStop) */
-#define PCLK_STOP_SOFTWARE         0x0 /*  Software Pacer Stop (StopPacer) */
-#define PCLK_STOP_ETRIG            0x1 /*  External Trigger */
-#define PCLK_STOP_DIGITAL_IT       0x2 /*  Digital Interrupt */
-#define PCLK_STOP_ACNT             0x3 /*  About Counter */
-#define PCLK_STOP_UTC2             0x4 /*  User TC2 out */
-#define PCLK_STOP_SBUS0            0x5 /*  SyncBus 0 */
-#define PCLK_STOP_SBUS1            0x6 /*  SyncBus 1 */
-#define PCLK_STOP_SBUS2            0x7 /*  SyncBus 2 */
-#define PCLK_STOP_A_SOFTWARE       0x8 /*  About Software Pacer Stop */
-#define PCLK_STOP_A_ETRIG          0x9 /*  About External Trigger */
-#define PCLK_STOP_A_DIGITAL_IT     0xA /*  About Digital Interrupt */
-#define PCLK_STOP_A_UTC2           0xC /*  About User TC2 out */
-#define PCLK_STOP_A_SBUS0          0xD /*  About SyncBus 0 */
-#define PCLK_STOP_A_SBUS1          0xE /*  About SyncBus 1 */
-#define PCLK_STOP_A_SBUS2          0xF /*  About SyncBus 2 */
-
-/*  About Counter Stop Enable */
-#define ACNT_STOP                  0x0 /*  stop enable */
-#define ACNT_NO_STOP               0x1 /*  stop disabled */
-
-/*  DAC update source (SetDAC1Start & SetDAC2Start) */
-#define DAC_START_SOFTWARE         0x0 /*  Software Update */
-#define DAC_START_CGT              0x1 /*  CGT controlled Update */
-#define DAC_START_DAC_CLK          0x2 /*  D/A Clock */
-#define DAC_START_EPCLK            0x3 /*  External Pacer Clock */
-#define DAC_START_SBUS0            0x4 /*  SyncBus 0 */
-#define DAC_START_SBUS1            0x5 /*  SyncBus 1 */
-#define DAC_START_SBUS2            0x6 /*  SyncBus 2 */
-
-/*  DAC Cycle Mode (SetDAC1Cycle, SetDAC2Cycle, SetupDAC) */
-#define DAC_CYCLE_SINGLE           0x0 /*  not cycle */
-#define DAC_CYCLE_MULTI            0x1 /*  cycle */
-
-/*  8254 Operation Modes (Set8254Mode, SetupTimerCounter) */
-#define M8254_EVENT_COUNTER        0   /*  Event Counter */
-#define M8254_HW_ONE_SHOT          1   /*  Hardware-Retriggerable One-Shot */
-#define M8254_RATE_GENERATOR       2   /*  Rate Generator */
-#define M8254_SQUARE_WAVE          3   /*  Square Wave Mode */
-#define M8254_SW_STROBE            4   /*  Software Triggered Strobe */
-#define M8254_HW_STROBE            5   /*  Hardware Triggered Strobe (Retriggerable) */
-
-/*  User Timer/Counter 0 Clock Select (SetUtc0Clock) */
-#define CUTC0_8MHZ                 0x0 /*  8MHz */
-#define CUTC0_EXT_TC_CLOCK1        0x1 /*  Ext. TC Clock 1 */
-#define CUTC0_EXT_TC_CLOCK2        0x2 /*  Ext. TC Clock 2 */
-#define CUTC0_EXT_PCLK             0x3 /*  Ext. Pacer Clock */
-
-/*  User Timer/Counter 1 Clock Select (SetUtc1Clock) */
-#define CUTC1_8MHZ                 0x0 /*  8MHz */
-#define CUTC1_EXT_TC_CLOCK1        0x1 /*  Ext. TC Clock 1 */
-#define CUTC1_EXT_TC_CLOCK2        0x2 /*  Ext. TC Clock 2 */
-#define CUTC1_EXT_PCLK             0x3 /*  Ext. Pacer Clock */
-#define CUTC1_UTC0_OUT             0x4 /*  User Timer/Counter 0 out */
-#define CUTC1_DIN_SIGNAL           0x5 /*  High-Speed Digital Input   Sampling signal */
-
-/*  User Timer/Counter 2 Clock Select (SetUtc2Clock) */
-#define CUTC2_8MHZ                 0x0 /*  8MHz */
-#define CUTC2_EXT_TC_CLOCK1        0x1 /*  Ext. TC Clock 1 */
-#define CUTC2_EXT_TC_CLOCK2        0x2 /*  Ext. TC Clock 2 */
-#define CUTC2_EXT_PCLK             0x3 /*  Ext. Pacer Clock */
-#define CUTC2_UTC1_OUT             0x4 /*  User Timer/Counter 1 out */
-
-/*  User Timer/Counter 0 Gate Select (SetUtc0Gate) */
-#define GUTC0_NOT_GATED            0x0 /*  Not gated */
-#define GUTC0_GATED                0x1 /*  Gated */
-#define GUTC0_EXT_TC_GATE1         0x2 /*  Ext. TC Gate 1 */
-#define GUTC0_EXT_TC_GATE2         0x3 /*  Ext. TC Gate 2 */
-
-/*  User Timer/Counter 1 Gate Select (SetUtc1Gate) */
-#define GUTC1_NOT_GATED            0x0 /*  Not gated */
-#define GUTC1_GATED                0x1 /*  Gated */
-#define GUTC1_EXT_TC_GATE1         0x2 /*  Ext. TC Gate 1 */
-#define GUTC1_EXT_TC_GATE2         0x3 /*  Ext. TC Gate 2 */
-#define GUTC1_UTC0_OUT             0x4 /*  User Timer/Counter 0 out */
-
-/*  User Timer/Counter 2 Gate Select (SetUtc2Gate) */
-#define GUTC2_NOT_GATED            0x0 /*  Not gated */
-#define GUTC2_GATED                0x1 /*  Gated */
-#define GUTC2_EXT_TC_GATE1         0x2 /*  Ext. TC Gate 1 */
-#define GUTC2_EXT_TC_GATE2         0x3 /*  Ext. TC Gate 2 */
-#define GUTC2_UTC1_OUT             0x4 /*  User Timer/Counter 1 out */
-
-/*  Interrupt Source Masks (SetITMask, ClearITMask, GetITStatus) */
-#define IRQM_ADC_FIFO_WRITE        0x0001      /*  ADC FIFO Write */
-#define IRQM_CGT_RESET             0x0002      /*  Reset CGT */
-#define IRQM_CGT_PAUSE             0x0008      /*  Pause CGT */
-#define IRQM_ADC_ABOUT_CNT         0x0010      /*  About Counter out */
-#define IRQM_ADC_DELAY_CNT         0x0020      /*  Delay Counter out */
-#define IRQM_ADC_SAMPLE_CNT       0x0040       /*  ADC Sample Counter */
-#define IRQM_DAC1_UCNT             0x0080      /*  DAC1 Update Counter */
-#define IRQM_DAC2_UCNT             0x0100      /*  DAC2 Update Counter */
-#define IRQM_UTC1                  0x0200      /*  User TC1 out */
-#define IRQM_UTC1_INV              0x0400      /*  User TC1 out, inverted */
-#define IRQM_UTC2                  0x0800      /*  User TC2 out */
-#define IRQM_DIGITAL_IT            0x1000      /*  Digital Interrupt */
-#define IRQM_EXTERNAL_IT           0x2000      /*  External Interrupt */
-#define IRQM_ETRIG_RISING          0x4000      /*  External Trigger rising-edge */
-#define IRQM_ETRIG_FALLING         0x8000      /*  External Trigger falling-edge */
-
-/*  DMA Request Sources (LAS0) */
-#define DMAS_DISABLED              0x0 /*  DMA Disabled */
-#define DMAS_ADC_SCNT              0x1 /*  ADC Sample Counter */
-#define DMAS_DAC1_UCNT             0x2 /*  D/A1 Update Counter */
-#define DMAS_DAC2_UCNT             0x3 /*  D/A2 Update Counter */
-#define DMAS_UTC1                  0x4 /*  User TC1 out */
-#define DMAS_ADFIFO_HALF_FULL      0x8 /*  A/D FIFO half full */
-#define DMAS_DAC1_FIFO_HALF_EMPTY  0x9 /*  D/A1 FIFO half empty */
-#define DMAS_DAC2_FIFO_HALF_EMPTY  0xA /*  D/A2 FIFO half empty */
-
-/*  DMA Local Addresses   (0x40000000+LAS1 offset) */
-#define DMALADDR_ADC       0x40000000  /*  A/D FIFO */
-#define DMALADDR_HDIN      0x40000004  /*  High Speed Digital Input FIFO */
-#define DMALADDR_DAC1      0x40000008  /*  D/A1 FIFO */
-#define DMALADDR_DAC2      0x4000000C  /*  D/A2 FIFO */
-
-/*  Port 0 compare modes (SetDIO0CompareMode) */
-#define DIO_MODE_EVENT     0   /*  Event Mode */
-#define DIO_MODE_MATCH     1   /*  Match Mode */
-
-/*  Digital Table Enable (Port 1 disable) */
-#define DTBL_DISABLE       0   /*  Enable Digital Table */
-#define DTBL_ENABLE        1   /*  Disable Digital Table */
-
-/*  Sampling Signal for High Speed Digital Input (SetHdinStart) */
-#define HDIN_SOFTWARE      0x0 /*  Software Trigger */
-#define HDIN_ADC           0x1 /*  A/D Conversion Signal */
-#define HDIN_UTC0          0x2 /*  User TC out 0 */
-#define HDIN_UTC1          0x3 /*  User TC out 1 */
-#define HDIN_UTC2          0x4 /*  User TC out 2 */
-#define HDIN_EPCLK         0x5 /*  External Pacer Clock */
-#define HDIN_ETRG          0x6 /*  External Trigger */
-
-/*  Channel Gain Table / Channel Gain Latch */
-#define CSC_LATCH          0   /*  Channel Gain Latch mode */
-#define CSC_CGT            1   /*  Channel Gain Table mode */
-
-/*  Channel Gain Table Pause Enable */
-#define CGT_PAUSE_DISABLE  0   /*  Channel Gain Table Pause Disable */
-#define CGT_PAUSE_ENABLE   1   /*  Channel Gain Table Pause Enable */
-
-/*  DAC output type/range (p63) */
-#define AOUT_UNIP5         0   /*  0..+5 Volt */
-#define AOUT_UNIP10        1   /*  0..+10 Volt */
-#define AOUT_BIP5          2   /*  -5..+5 Volt */
-#define AOUT_BIP10         3   /*  -10..+10 Volt */
-
-/*  Ghannel Gain Table field definitions (p61) */
-/*  Gain */
-#define GAIN1              0
-#define GAIN2              1
-#define GAIN4              2
-#define GAIN8              3
-#define GAIN16             4
-#define GAIN32             5
-#define GAIN64             6
-#define GAIN128            7
-
-/*  Input range/polarity */
-#define AIN_BIP5           0   /*  -5..+5 Volt */
-#define AIN_BIP10          1   /*  -10..+10 Volt */
-#define AIN_UNIP10         2   /*  0..+10 Volt */
-
-/*  non referenced single ended select bit */
-#define NRSE_AGND          0   /*  AGND referenced SE input */
-#define NRSE_AINS          1   /*  AIN SENSE referenced SE input */
-
-/*  single ended vs differential */
-#define GND_SE         0       /*  Single-Ended */
-#define GND_DIFF       1       /*  Differential */
index 71a73ec5af8d90811faebf7d087c705231a0a316..02f9406f8f09e8a5b81a8799373abe7141d53433 100644 (file)
@@ -80,7 +80,7 @@ INSN_CONFIG instructions:
 #define PCI_SUBDEVICE_ID_S626 0x0272
 
 struct s626_private {
-       void __iomem *base_addr;
+       void __iomem *mmio;
        uint8_t ai_cmd_running; /*  ai_cmd is running */
        uint8_t ai_continous;   /*  continous acquisition */
        int ai_sample_count;    /*  number of samples to acquire */
@@ -106,64 +106,6 @@ struct s626_private {
        unsigned int ao_readback[S626_DAC_CHANNELS];
 };
 
-struct dio_private {
-       uint16_t RDDIn;
-       uint16_t WRDOut;
-       uint16_t RDEdgSel;
-       uint16_t WREdgSel;
-       uint16_t RDCapSel;
-       uint16_t WRCapSel;
-       uint16_t RDCapFlg;
-       uint16_t RDIntSel;
-       uint16_t WRIntSel;
-};
-
-static struct dio_private dio_private_A = {
-       .RDDIn = LP_RDDINA,
-       .WRDOut = LP_WRDOUTA,
-       .RDEdgSel = LP_RDEDGSELA,
-       .WREdgSel = LP_WREDGSELA,
-       .RDCapSel = LP_RDCAPSELA,
-       .WRCapSel = LP_WRCAPSELA,
-       .RDCapFlg = LP_RDCAPFLGA,
-       .RDIntSel = LP_RDINTSELA,
-       .WRIntSel = LP_WRINTSELA,
-};
-
-static struct dio_private dio_private_B = {
-       .RDDIn = LP_RDDINB,
-       .WRDOut = LP_WRDOUTB,
-       .RDEdgSel = LP_RDEDGSELB,
-       .WREdgSel = LP_WREDGSELB,
-       .RDCapSel = LP_RDCAPSELB,
-       .WRCapSel = LP_WRCAPSELB,
-       .RDCapFlg = LP_RDCAPFLGB,
-       .RDIntSel = LP_RDINTSELB,
-       .WRIntSel = LP_WRINTSELB,
-};
-
-static struct dio_private dio_private_C = {
-       .RDDIn = LP_RDDINC,
-       .WRDOut = LP_WRDOUTC,
-       .RDEdgSel = LP_RDEDGSELC,
-       .WREdgSel = LP_WREDGSELC,
-       .RDCapSel = LP_RDCAPSELC,
-       .WRCapSel = LP_WRCAPSELC,
-       .RDCapFlg = LP_RDCAPFLGC,
-       .RDIntSel = LP_RDINTSELC,
-       .WRIntSel = LP_WRINTSELC,
-};
-
-/* to group dio devices (48 bits mask and data are not allowed ???)
-static struct dio_private *dio_private_word[]={
-  &dio_private_A,
-  &dio_private_B,
-  &dio_private_C,
-};
-*/
-
-#define diopriv ((struct dio_private *)s->private)
-
 /*  COUNTER OBJECT ------------------------------------------------ */
 struct enc_private {
        /*  Pointers to functions that differ for A and B counters: */
@@ -195,37 +137,53 @@ struct enc_private {
 /*  Translation table to map IntSrc into equivalent RDMISC2 event flag  bits. */
 /* static const uint16_t EventBits[][4] = { EVBITS(0), EVBITS(1), EVBITS(2), EVBITS(3), EVBITS(4), EVBITS(5) }; */
 
-/*  enab/disable a function or test status bit(s) that are accessed */
-/*  through Main Control Registers 1 or 2. */
-#define MC_ENABLE(REGADRS, CTRLWORD)   writel(((uint32_t)(CTRLWORD) << 16) | (uint32_t)(CTRLWORD), devpriv->base_addr+(REGADRS))
+/*
+ * Enable/disable a function or test status bit(s) that are accessed
+ * through Main Control Registers 1 or 2.
+ */
+static void s626_mc_enable(struct comedi_device *dev,
+                          unsigned int cmd, unsigned int reg)
+{
+       struct s626_private *devpriv = dev->private;
+       unsigned int val = (cmd << 16) | cmd;
 
-#define MC_DISABLE(REGADRS, CTRLWORD)  writel((uint32_t)(CTRLWORD) << 16 , devpriv->base_addr+(REGADRS))
+       writel(val, devpriv->mmio + reg);
+}
 
-#define MC_TEST(REGADRS, CTRLWORD)     ((readl(devpriv->base_addr+(REGADRS)) & CTRLWORD) != 0)
+static void s626_mc_disable(struct comedi_device *dev,
+                           unsigned int cmd, unsigned int reg)
+{
+       struct s626_private *devpriv = dev->private;
 
-/* #define WR7146(REGARDS,CTRLWORD)
-    writel(CTRLWORD,(uint32_t)(devpriv->base_addr+(REGARDS))) */
-#define WR7146(REGARDS, CTRLWORD) writel(CTRLWORD, devpriv->base_addr+(REGARDS))
+       writel(cmd << 16 , devpriv->mmio + reg);
+}
 
-/* #define RR7146(REGARDS)
-    readl((uint32_t)(devpriv->base_addr+(REGARDS))) */
-#define RR7146(REGARDS)                readl(devpriv->base_addr+(REGARDS))
+static bool s626_mc_test(struct comedi_device *dev,
+                        unsigned int cmd, unsigned int reg)
+{
+       struct s626_private *devpriv = dev->private;
+       unsigned int val;
+
+       val = readl(devpriv->mmio + reg);
+
+       return (val & cmd) ? true : false;
+}
 
 #define BUGFIX_STREG(REGADRS)   (REGADRS - 4)
 
 /*  Write a time slot control record to TSL2. */
 #define VECTPORT(VECTNUM)              (P_TSL2 + ((VECTNUM) << 2))
-#define SETVECT(VECTNUM, VECTVAL)      WR7146(VECTPORT(VECTNUM), (VECTVAL))
 
 /*  Code macros used for constructing I2C command bytes. */
 #define I2C_B2(ATTR, VAL)      (((ATTR) << 6) | ((VAL) << 24))
 #define I2C_B1(ATTR, VAL)      (((ATTR) << 4) | ((VAL) << 16))
 #define I2C_B0(ATTR, VAL)      (((ATTR) << 2) | ((VAL) <<  8))
 
-static const struct comedi_lrange s626_range_table = { 2, {
-                                                          RANGE(-5, 5),
-                                                          RANGE(-10, 10),
-                                                          }
+static const struct comedi_lrange s626_range_table = {
+       2, {
+               BIP_RANGE(5),
+               BIP_RANGE(10),
+       }
 };
 
 /*  Execute a DEBI transfer.  This must be called from within a */
@@ -234,16 +192,18 @@ static void DEBItransfer(struct comedi_device *dev)
 {
        struct s626_private *devpriv = dev->private;
 
-       /*  Initiate upload of shadow RAM to DEBI control register. */
-       MC_ENABLE(P_MC2, MC2_UPLD_DEBI);
+       /* Initiate upload of shadow RAM to DEBI control register */
+       s626_mc_enable(dev, MC2_UPLD_DEBI, P_MC2);
 
-       /*  Wait for completion of upload from shadow RAM to DEBI control */
-       /*  register. */
-       while (!MC_TEST(P_MC2, MC2_UPLD_DEBI))
+       /*
+        * Wait for completion of upload from shadow RAM to
+        * DEBI control register.
+        */
+       while (!s626_mc_test(dev, MC2_UPLD_DEBI, P_MC2))
                ;
 
-       /*  Wait until DEBI transfer is done. */
-       while (RR7146(P_PSR) & PSR_DEBI_S)
+       /* Wait until DEBI transfer is done */
+       while (readl(devpriv->mmio + P_PSR) & PSR_DEBI_S)
                ;
 }
 
@@ -252,19 +212,14 @@ static void DEBItransfer(struct comedi_device *dev)
 static uint16_t DEBIread(struct comedi_device *dev, uint16_t addr)
 {
        struct s626_private *devpriv = dev->private;
-       uint16_t retval;
 
-       /*  Set up DEBI control register value in shadow RAM. */
-       WR7146(P_DEBICMD, DEBI_CMD_RDWORD | addr);
+       /* Set up DEBI control register value in shadow RAM */
+       writel(DEBI_CMD_RDWORD | addr, devpriv->mmio + P_DEBICMD);
 
        /*  Execute the DEBI transfer. */
        DEBItransfer(dev);
 
-       /*  Fetch target register value. */
-       retval = (uint16_t) RR7146(P_DEBIAD);
-
-       /*  Return register value. */
-       return retval;
+       return readl(devpriv->mmio + P_DEBIAD);
 }
 
 /*  Write a value to a gate array register. */
@@ -272,9 +227,9 @@ static void DEBIwrite(struct comedi_device *dev, uint16_t addr, uint16_t wdata)
 {
        struct s626_private *devpriv = dev->private;
 
-       /*  Set up DEBI control register value in shadow RAM. */
-       WR7146(P_DEBICMD, DEBI_CMD_WRWORD | addr);
-       WR7146(P_DEBIAD, wdata);
+       /* Set up DEBI control register value in shadow RAM */
+       writel(DEBI_CMD_WRWORD | addr, devpriv->mmio + P_DEBICMD);
+       writel(wdata, devpriv->mmio + P_DEBIAD);
 
        /*  Execute the DEBI transfer. */
        DEBItransfer(dev);
@@ -284,23 +239,22 @@ static void DEBIwrite(struct comedi_device *dev, uint16_t addr, uint16_t wdata)
  * specifies bits that are to be preserved, wdata is new value to be
  * or'd with the masked original.
  */
-static void DEBIreplace(struct comedi_device *dev, uint16_t addr, uint16_t mask,
-                       uint16_t wdata)
+static void DEBIreplace(struct comedi_device *dev, unsigned int addr,
+                       unsigned int mask, unsigned int wdata)
 {
        struct s626_private *devpriv = dev->private;
+       unsigned int val;
 
-       /*  Copy target gate array register into P_DEBIAD register. */
-       WR7146(P_DEBICMD, DEBI_CMD_RDWORD | addr);
-       /* Set up DEBI control reg value in shadow RAM. */
-       DEBItransfer(dev);      /*  Execute the DEBI Read transfer. */
-
-       /*  Write back the modified image. */
-       WR7146(P_DEBICMD, DEBI_CMD_WRWORD | addr);
-       /* Set up DEBI control reg value in shadow  RAM. */
+       addr &= 0xffff;
+       writel(DEBI_CMD_RDWORD | addr, devpriv->mmio + P_DEBICMD);
+       DEBItransfer(dev);
 
-       WR7146(P_DEBIAD, wdata | ((uint16_t) RR7146(P_DEBIAD) & mask));
-       /* Modify the register image. */
-       DEBItransfer(dev);      /*  Execute the DEBI Write transfer. */
+       writel(DEBI_CMD_WRWORD | addr, devpriv->mmio + P_DEBICMD);
+       val = readl(devpriv->mmio + P_DEBIAD);
+       val &= mask;
+       val |= wdata;
+       writel(val & 0xffff, devpriv->mmio + P_DEBIAD);
+       DEBItransfer(dev);
 }
 
 /* **************  EEPROM ACCESS FUNCTIONS  ************** */
@@ -308,31 +262,32 @@ static void DEBIreplace(struct comedi_device *dev, uint16_t addr, uint16_t mask,
 static uint32_t I2Chandshake(struct comedi_device *dev, uint32_t val)
 {
        struct s626_private *devpriv = dev->private;
+       unsigned int ctrl;
 
-       /*  Write I2C command to I2C Transfer Control shadow register. */
-       WR7146(P_I2CCTRL, val);
-
-       /*  Upload I2C shadow registers into working registers and wait for */
-       /*  upload confirmation. */
-
-       MC_ENABLE(P_MC2, MC2_UPLD_IIC);
-       while (!MC_TEST(P_MC2, MC2_UPLD_IIC))
-               ;
+       /* Write I2C command to I2C Transfer Control shadow register */
+       writel(val, devpriv->mmio + P_I2CCTRL);
 
-       /*  Wait until I2C bus transfer is finished or an error occurs. */
-       while ((RR7146(P_I2CCTRL) & (I2C_BUSY | I2C_ERR)) == I2C_BUSY)
+       /*
+        * Upload I2C shadow registers into working registers and
+        * wait for upload confirmation.
+        */
+       s626_mc_enable(dev, MC2_UPLD_IIC, P_MC2);
+       while (!s626_mc_test(dev, MC2_UPLD_IIC, P_MC2))
                ;
 
-       /*  Return non-zero if I2C error occurred. */
-       return RR7146(P_I2CCTRL) & I2C_ERR;
+       /* Wait until I2C bus transfer is finished or an error occurs */
+       do {
+               ctrl = readl(devpriv->mmio + P_I2CCTRL);
+       } while ((ctrl & (I2C_BUSY | I2C_ERR)) == I2C_BUSY);
 
+       /* Return non-zero if I2C error occurred */
+       return ctrl & I2C_ERR;
 }
 
 /*  Read uint8_t from EEPROM. */
 static uint8_t I2Cread(struct comedi_device *dev, uint8_t addr)
 {
        struct s626_private *devpriv = dev->private;
-       uint8_t rtnval;
 
        /*  Send EEPROM target address. */
        if (I2Chandshake(dev, I2C_B2(I2C_ATTRSTART, I2CW)
@@ -360,9 +315,8 @@ static uint8_t I2Cread(struct comedi_device *dev, uint8_t addr)
                /*  Abort function and declare error if handshake failed. */
                return 0;
        }
-       /*  Return copy of EEPROM value. */
-       rtnval = (uint8_t) (RR7146(P_I2CCTRL) >> 16);
-       return rtnval;
+
+       return (readl(devpriv->mmio + P_I2CCTRL) >> 16) & 0xff;
 }
 
 /* ***********  DAC FUNCTIONS *********** */
@@ -402,23 +356,25 @@ static void SendDAC(struct comedi_device *dev, uint32_t val)
 
        /* Copy DAC setpoint value to DAC's output DMA buffer. */
 
-       /* WR7146( (uint32_t)devpriv->pDacWBuf, val ); */
+       /* writel(val, devpriv->mmio + (uint32_t)devpriv->pDacWBuf); */
        *devpriv->pDacWBuf = val;
 
-       /* enab the output DMA transfer.  This will cause the DMAC to copy
-        * the DAC's data value to A2's output FIFO.  The DMA transfer will
+       /*
+        * Enable the output DMA transfer. This will cause the DMAC to copy
+        * the DAC's data value to A2's output FIFO. The DMA transfer will
         * then immediately terminate because the protection address is
         * reached upon transfer of the first DWORD value.
         */
-       MC_ENABLE(P_MC1, MC1_A2OUT);
+       s626_mc_enable(dev, MC1_A2OUT, P_MC1);
 
        /*  While the DMA transfer is executing ... */
 
-       /* Reset Audio2 output FIFO's underflow flag (along with any other
-        * FIFO underflow/overflow flags).  When set, this flag will
-        * indicate that we have emerged from slot 0.
+       /*
+        * Reset Audio2 output FIFO's underflow flag (along with any
+        * other FIFO underflow/overflow flags). When set, this flag
+        * will indicate that we have emerged from slot 0.
         */
-       WR7146(P_ISR, ISR_AFOU);
+       writel(ISR_AFOU, devpriv->mmio + P_ISR);
 
        /* Wait for the DMA transfer to finish so that there will be data
         * available in the FIFO when time slot 1 tries to transfer a DWORD
@@ -426,7 +382,7 @@ static void SendDAC(struct comedi_device *dev, uint32_t val)
         * Done by polling the DMAC enable flag; this flag is automatically
         * cleared when the transfer has finished.
         */
-       while ((RR7146(P_MC1) & MC1_A2OUT) != 0)
+       while (readl(devpriv->mmio + P_MC1) & MC1_A2OUT)
                ;
 
        /* START THE OUTPUT STREAM TO THE TARGET DAC -------------------- */
@@ -436,7 +392,7 @@ static void SendDAC(struct comedi_device *dev, uint32_t val)
         * will be shifted in and stored in FB_BUFFER2 for end-of-slot-list
         * detection.
         */
-       SETVECT(0, XSD2 | RSD3 | SIB_A2);
+       writel(XSD2 | RSD3 | SIB_A2, devpriv->mmio + VECTPORT(0));
 
        /* Wait for slot 1 to execute to ensure that the Packet will be
         * transmitted.  This is detected by polling the Audio2 output FIFO
@@ -444,7 +400,7 @@ static void SendDAC(struct comedi_device *dev, uint32_t val)
         * finished transferring the DAC's data DWORD from the output FIFO
         * to the output buffer register.
         */
-       while ((RR7146(P_SSR) & SSR_AF2_OUT) == 0)
+       while (!(readl(devpriv->mmio + P_SSR) & SSR_AF2_OUT))
                ;
 
        /* Set up to trap execution at slot 0 when the TSL sequencer cycles
@@ -453,7 +409,8 @@ static void SendDAC(struct comedi_device *dev, uint32_t val)
         * stored in the last byte to be shifted out of the FIFO's DWORD
         * buffer register.
         */
-       SETVECT(0, XSD2 | XFIFO_2 | RSD2 | SIB_A2 | EOS);
+       writel(XSD2 | XFIFO_2 | RSD2 | SIB_A2 | EOS,
+              devpriv->mmio + VECTPORT(0));
 
        /* WAIT FOR THE TRANSACTION TO FINISH ----------------------- */
 
@@ -474,14 +431,14 @@ static void SendDAC(struct comedi_device *dev, uint32_t val)
         *    we test for the FB_BUFFER2 MSB contents to be equal to 0xFF.  If
         *    the TSL has not yet finished executing slot 5 ...
         */
-       if ((RR7146(P_FB_BUFFER2) & 0xFF000000) != 0) {
+       if (readl(devpriv->mmio + P_FB_BUFFER2) & 0xff000000) {
                /* The trap was set on time and we are still executing somewhere
                 * in slots 2-5, so we now wait for slot 0 to execute and trap
                 * TSL execution.  This is detected when FB_BUFFER2 MSB changes
                 * from 0xFF to 0x00, which slot 0 causes to happen by shifting
                 * out/in on SD2 the 0x00 that is always referenced by slot 5.
                 */
-               while ((RR7146(P_FB_BUFFER2) & 0xFF000000) != 0)
+               while (readl(devpriv->mmio + P_FB_BUFFER2) & 0xff000000)
                        ;
        }
        /* Either (1) we were too late setting the slot 0 trap; the TSL
@@ -492,13 +449,13 @@ static void SendDAC(struct comedi_device *dev, uint32_t val)
         * In order to do this, we reprogram slot 0 so that it will shift in
         * SD3, which is driven only by a pull-up resistor.
         */
-       SETVECT(0, RSD3 | SIB_A2 | EOS);
+       writel(RSD3 | SIB_A2 | EOS, devpriv->mmio + VECTPORT(0));
 
        /* Wait for slot 0 to execute, at which time the TSL is setup for
         * the next DAC write.  This is detected when FB_BUFFER2 MSB changes
         * from 0x00 to 0xFF.
         */
-       while ((RR7146(P_FB_BUFFER2) & 0xFF000000) == 0)
+       while (!(readl(devpriv->mmio + P_FB_BUFFER2) & 0xff000000))
                ;
 }
 
@@ -532,16 +489,16 @@ static void SetDAC(struct comedi_device *dev, uint16_t chan, short dacdata)
         * disables gating for the DAC clock and all DAC chip selects.
         */
 
+       /* Choose DAC chip select to be asserted */
        WSImage = (chan & 2) ? WS1 : WS2;
-       /* Choose DAC chip select to be asserted. */
-       SETVECT(2, XSD2 | XFIFO_1 | WSImage);
-       /* Slot 2: Transmit high data byte to target DAC. */
-       SETVECT(3, XSD2 | XFIFO_0 | WSImage);
-       /* Slot 3: Transmit low data byte to target DAC. */
-       SETVECT(4, XSD2 | XFIFO_3 | WS3);
+       /* Slot 2: Transmit high data byte to target DAC */
+       writel(XSD2 | XFIFO_1 | WSImage, devpriv->mmio + VECTPORT(2));
+       /* Slot 3: Transmit low data byte to target DAC */
+       writel(XSD2 | XFIFO_0 | WSImage, devpriv->mmio + VECTPORT(3));
        /* Slot 4: Transmit to non-existent TrimDac channel to keep clock */
-       SETVECT(5, XSD2 | XFIFO_2 | WS3 | EOS);
-       /* Slot 5: running after writing target DAC's low data byte. */
+       writel(XSD2 | XFIFO_3 | WS3, devpriv->mmio + VECTPORT(4));
+       /* Slot 5: running after writing target DAC's low data byte */
+       writel(XSD2 | XFIFO_2 | WS3 | EOS, devpriv->mmio + VECTPORT(5));
 
        /*  Construct and transmit target DAC's serial packet:
         * ( A10D DDDD ),( DDDD DDDD ),( 0x0F ),( 0x00 ) where A is chan<0>,
@@ -577,14 +534,14 @@ static void WriteTrimDAC(struct comedi_device *dev, uint8_t LogicalChan,
         * can be detected.
         */
 
-       SETVECT(2, XSD2 | XFIFO_1 | WS3);
-       /* Slot 2: Send high uint8_t to target TrimDac. */
-       SETVECT(3, XSD2 | XFIFO_0 | WS3);
-       /* Slot 3: Send low uint8_t to target TrimDac. */
-       SETVECT(4, XSD2 | XFIFO_3 | WS1);
-       /* Slot 4: Send NOP high uint8_t to DAC0 to keep clock running. */
-       SETVECT(5, XSD2 | XFIFO_2 | WS1 | EOS);
-       /* Slot 5: Send NOP low  uint8_t to DAC0. */
+       /* Slot 2: Send high uint8_t to target TrimDac */
+       writel(XSD2 | XFIFO_1 | WS3, devpriv->mmio + VECTPORT(2));
+       /* Slot 3: Send low uint8_t to target TrimDac */
+       writel(XSD2 | XFIFO_0 | WS3, devpriv->mmio + VECTPORT(3));
+       /* Slot 4: Send NOP high uint8_t to DAC0 to keep clock running */
+       writel(XSD2 | XFIFO_3 | WS1, devpriv->mmio + VECTPORT(4));
+       /* Slot 5: Send NOP low  uint8_t to DAC0 */
+       writel(XSD2 | XFIFO_2 | WS1 | EOS, devpriv->mmio + VECTPORT(5));
 
        /* Construct and transmit target DAC's serial packet:
         * ( 0000 AAAA ), ( DDDD DDDD ),( 0x00 ),( 0x00 ) where A<3:0> is the
@@ -638,8 +595,8 @@ static void SetLatchSource(struct comedi_device *dev, struct enc_private *k,
                           uint16_t value)
 {
        DEBIreplace(dev, k->MyCRB,
-                   (uint16_t) (~(CRBMSK_INTCTRL | CRBMSK_LATCHSRC)),
-                   (uint16_t) (value << CRBBIT_LATCHSRC));
+                   ~(CRBMSK_INTCTRL | CRBMSK_LATCHSRC),
+                   value << CRBBIT_LATCHSRC);
 }
 
 /*  Write value into counter preload register. */
@@ -670,43 +627,24 @@ static unsigned int s626_ai_reg_to_uint(int data)
 
 static int s626_dio_set_irq(struct comedi_device *dev, unsigned int chan)
 {
-       unsigned int group;
-       unsigned int bitmask;
+       unsigned int group = chan / 16;
+       unsigned int mask = 1 << (chan - (16 * group));
        unsigned int status;
 
-       /* select dio bank */
-       group = chan / 16;
-       bitmask = 1 << (chan - (16 * group));
-
        /* set channel to capture positive edge */
-       status = DEBIread(dev,
-                         ((struct dio_private *)(dev->subdevices + 2 +
-                                                 group)->private)->RDEdgSel);
-       DEBIwrite(dev,
-                 ((struct dio_private *)(dev->subdevices + 2 +
-                                         group)->private)->WREdgSel,
-                 bitmask | status);
+       status = DEBIread(dev, LP_RDEDGSEL(group));
+       DEBIwrite(dev, LP_WREDGSEL(group), mask | status);
 
        /* enable interrupt on selected channel */
-       status = DEBIread(dev,
-                         ((struct dio_private *)(dev->subdevices + 2 +
-                                                 group)->private)->RDIntSel);
-       DEBIwrite(dev,
-                 ((struct dio_private *)(dev->subdevices + 2 +
-                                         group)->private)->WRIntSel,
-                 bitmask | status);
+       status = DEBIread(dev, LP_RDINTSEL(group));
+       DEBIwrite(dev, LP_WRINTSEL(group), mask | status);
 
        /* enable edge capture write command */
        DEBIwrite(dev, LP_MISC1, MISC1_EDCAP);
 
        /* enable edge capture on selected channel */
-       status = DEBIread(dev,
-                         ((struct dio_private *)(dev->subdevices + 2 +
-                                                 group)->private)->RDCapSel);
-       DEBIwrite(dev,
-                 ((struct dio_private *)(dev->subdevices + 2 +
-                                         group)->private)->WRCapSel,
-                 bitmask | status);
+       status = DEBIread(dev, LP_RDCAPSEL(group));
+       DEBIwrite(dev, LP_WRCAPSEL(group), mask | status);
 
        return 0;
 }
@@ -718,9 +656,7 @@ static int s626_dio_reset_irq(struct comedi_device *dev, unsigned int group,
        DEBIwrite(dev, LP_MISC1, MISC1_NOEDCAP);
 
        /* enable edge capture on selected channel */
-       DEBIwrite(dev,
-                 ((struct dio_private *)(dev->subdevices + 2 +
-                                         group)->private)->WRCapSel, mask);
+       DEBIwrite(dev, LP_WRCAPSEL(group), mask);
 
        return 0;
 }
@@ -732,244 +668,249 @@ static int s626_dio_clear_irq(struct comedi_device *dev)
        /* disable edge capture write command */
        DEBIwrite(dev, LP_MISC1, MISC1_NOEDCAP);
 
-       for (group = 0; group < S626_DIO_BANKS; group++) {
-               /* clear pending events and interrupt */
-               DEBIwrite(dev,
-                         ((struct dio_private *)(dev->subdevices + 2 +
-                                                 group)->private)->WRCapSel,
-                         0xffff);
-       }
+       /* clear all dio pending events and interrupt */
+       for (group = 0; group < S626_DIO_BANKS; group++)
+               DEBIwrite(dev, LP_WRCAPSEL(group), 0xffff);
 
        return 0;
 }
 
-static irqreturn_t s626_irq_handler(int irq, void *d)
+static void handle_dio_interrupt(struct comedi_device *dev,
+                                uint16_t irqbit, uint8_t group)
 {
-       struct comedi_device *dev = d;
        struct s626_private *devpriv = dev->private;
-       struct comedi_subdevice *s;
-       struct comedi_cmd *cmd;
-       struct enc_private *k;
-       unsigned long flags;
-       int32_t *readaddr;
-       uint32_t irqtype, irqstatus;
-       int i = 0;
-       short tempdata;
-       uint8_t group;
-       uint16_t irqbit;
+       struct comedi_subdevice *s = dev->read_subdev;
+       struct comedi_cmd *cmd = &s->async->cmd;
 
-       if (dev->attached == 0)
-               return IRQ_NONE;
-       /*  lock to avoid race with comedi_poll */
-       spin_lock_irqsave(&dev->spinlock, flags);
+       s626_dio_reset_irq(dev, group, irqbit);
 
-       /* save interrupt enable register state */
-       irqstatus = readl(devpriv->base_addr + P_IER);
+       if (devpriv->ai_cmd_running) {
+               /* check if interrupt is an ai acquisition start trigger */
+               if ((irqbit >> (cmd->start_arg - (16 * group))) == 1 &&
+                   cmd->start_src == TRIG_EXT) {
+                       /* Start executing the RPS program */
+                       s626_mc_enable(dev, MC1_ERPS1, P_MC1);
+
+                       if (cmd->scan_begin_src == TRIG_EXT)
+                               s626_dio_set_irq(dev, cmd->scan_begin_arg);
+               }
+               if ((irqbit >> (cmd->scan_begin_arg - (16 * group))) == 1 &&
+                   cmd->scan_begin_src == TRIG_EXT) {
+                       /* Trigger ADC scan loop start */
+                       s626_mc_enable(dev, MC2_ADC_RPS, P_MC2);
 
-       /* read interrupt type */
-       irqtype = readl(devpriv->base_addr + P_ISR);
+                       if (cmd->convert_src == TRIG_EXT) {
+                               devpriv->ai_convert_count = cmd->chanlist_len;
 
-       /* disable master interrupt */
-       writel(0, devpriv->base_addr + P_IER);
+                               s626_dio_set_irq(dev, cmd->convert_arg);
+                       }
 
-       /* clear interrupt */
-       writel(irqtype, devpriv->base_addr + P_ISR);
+                       if (cmd->convert_src == TRIG_TIMER) {
+                               struct enc_private *k = &encpriv[5];
 
-       switch (irqtype) {
-       case IRQ_RPS1:          /*  end_of_scan occurs */
-               /*  manage ai subdevice */
-               s = dev->subdevices;
-               cmd = &(s->async->cmd);
+                               devpriv->ai_convert_count = cmd->chanlist_len;
+                               k->SetEnable(dev, k, CLKENAB_ALWAYS);
+                       }
+               }
+               if ((irqbit >> (cmd->convert_arg - (16 * group))) == 1 &&
+                   cmd->convert_src == TRIG_EXT) {
+                       /* Trigger ADC scan loop start */
+                       s626_mc_enable(dev, MC2_ADC_RPS, P_MC2);
+
+                       devpriv->ai_convert_count--;
+                       if (devpriv->ai_convert_count > 0)
+                               s626_dio_set_irq(dev, cmd->convert_arg);
+               }
+       }
+}
 
-               /* Init ptr to DMA buffer that holds new ADC data.  We skip the
-                * first uint16_t in the buffer because it contains junk data from
-                * the final ADC of the previous poll list scan.
-                */
-               readaddr = (int32_t *) devpriv->ANABuf.LogicalBase + 1;
-
-               /*  get the data and hand it over to comedi */
-               for (i = 0; i < (s->async->cmd.chanlist_len); i++) {
-                       /*  Convert ADC data to 16-bit integer values and copy to application */
-                       /*  buffer. */
-                       tempdata = s626_ai_reg_to_uint((int)*readaddr);
-                       readaddr++;
-
-                       /* put data into read buffer */
-                       /*  comedi_buf_put(s->async, tempdata); */
-                       if (cfc_write_to_buffer(s, tempdata) == 0)
-                               printk
-                                   ("s626_irq_handler: cfc_write_to_buffer error!\n");
+static void check_dio_interrupts(struct comedi_device *dev)
+{
+       uint16_t irqbit;
+       uint8_t group;
+
+       for (group = 0; group < S626_DIO_BANKS; group++) {
+               irqbit = 0;
+               /* read interrupt type */
+               irqbit = DEBIread(dev, LP_RDCAPFLG(group));
+
+               /* check if interrupt is generated from dio channels */
+               if (irqbit) {
+                       handle_dio_interrupt(dev, irqbit, group);
+                       return;
                }
+       }
+}
 
-               /* end of scan occurs */
-               s->async->events |= COMEDI_CB_EOS;
+static void check_counter_interrupts(struct comedi_device *dev)
+{
+       struct s626_private *devpriv = dev->private;
+       struct comedi_subdevice *s = dev->read_subdev;
+       struct comedi_async *async = s->async;
+       struct comedi_cmd *cmd = &async->cmd;
+       struct enc_private *k;
+       uint16_t irqbit;
 
-               if (!(devpriv->ai_continous))
-                       devpriv->ai_sample_count--;
-               if (devpriv->ai_sample_count <= 0) {
-                       devpriv->ai_cmd_running = 0;
+       /* read interrupt type */
+       irqbit = DEBIread(dev, LP_RDMISC2);
 
-                       /*  Stop RPS program. */
-                       MC_DISABLE(P_MC1, MC1_ERPS1);
+       /* check interrupt on counters */
+       if (irqbit & IRQ_COINT1A) {
+               k = &encpriv[0];
 
-                       /* send end of acquisition */
-                       s->async->events |= COMEDI_CB_EOA;
+               /* clear interrupt capture flag */
+               k->ResetCapFlags(dev, k);
+       }
+       if (irqbit & IRQ_COINT2A) {
+               k = &encpriv[1];
 
-                       /* disable master interrupt */
-                       irqstatus = 0;
-               }
+               /* clear interrupt capture flag */
+               k->ResetCapFlags(dev, k);
+       }
+       if (irqbit & IRQ_COINT3A) {
+               k = &encpriv[2];
 
-               if (devpriv->ai_cmd_running && cmd->scan_begin_src == TRIG_EXT)
-                       s626_dio_set_irq(dev, cmd->scan_begin_arg);
-               /*  tell comedi that data is there */
-               comedi_event(dev, s);
-               break;
-       case IRQ_GPIO3: /* check dio and conter interrupt */
-               /*  manage ai subdevice */
-               s = dev->subdevices;
-               cmd = &(s->async->cmd);
+               /* clear interrupt capture flag */
+               k->ResetCapFlags(dev, k);
+       }
+       if (irqbit & IRQ_COINT1B) {
+               k = &encpriv[3];
 
-               /* s626_dio_clear_irq(dev); */
+               /* clear interrupt capture flag */
+               k->ResetCapFlags(dev, k);
+       }
+       if (irqbit & IRQ_COINT2B) {
+               k = &encpriv[4];
+
+               /* clear interrupt capture flag */
+               k->ResetCapFlags(dev, k);
+
+               if (devpriv->ai_convert_count > 0) {
+                       devpriv->ai_convert_count--;
+                       if (devpriv->ai_convert_count == 0)
+                               k->SetEnable(dev, k, CLKENAB_INDEX);
 
-               for (group = 0; group < S626_DIO_BANKS; group++) {
-                       irqbit = 0;
-                       /* read interrupt type */
-                       irqbit = DEBIread(dev,
-                                         ((struct dio_private *)(dev->
-                                                                 subdevices +
-                                                                 2 +
-                                                                 group)->
-                                          private)->RDCapFlg);
-
-                       /* check if interrupt is generated from dio channels */
-                       if (irqbit) {
-                               s626_dio_reset_irq(dev, group, irqbit);
-                               if (devpriv->ai_cmd_running) {
-                                       /* check if interrupt is an ai acquisition start trigger */
-                                       if ((irqbit >> (cmd->start_arg -
-                                                       (16 * group)))
-                                           == 1 && cmd->start_src == TRIG_EXT) {
-                                               /*  Start executing the RPS program. */
-                                               MC_ENABLE(P_MC1, MC1_ERPS1);
-
-                                               if (cmd->scan_begin_src ==
-                                                   TRIG_EXT) {
-                                                       s626_dio_set_irq(dev,
-                                                                        cmd->scan_begin_arg);
-                                               }
-                                       }
-                                       if ((irqbit >> (cmd->scan_begin_arg -
-                                                       (16 * group)))
-                                           == 1
-                                           && cmd->scan_begin_src ==
-                                           TRIG_EXT) {
-                                               /*  Trigger ADC scan loop start by setting RPS Signal 0. */
-                                               MC_ENABLE(P_MC2, MC2_ADC_RPS);
-
-                                               if (cmd->convert_src ==
-                                                   TRIG_EXT) {
-                                                       devpriv->ai_convert_count
-                                                           = cmd->chanlist_len;
-
-                                                       s626_dio_set_irq(dev,
-                                                                        cmd->convert_arg);
-                                               }
-
-                                               if (cmd->convert_src ==
-                                                   TRIG_TIMER) {
-                                                       k = &encpriv[5];
-                                                       devpriv->ai_convert_count
-                                                           = cmd->chanlist_len;
-                                                       k->SetEnable(dev, k,
-                                                                    CLKENAB_ALWAYS);
-                                               }
-                                       }
-                                       if ((irqbit >> (cmd->convert_arg -
-                                                       (16 * group)))
-                                           == 1
-                                           && cmd->convert_src == TRIG_EXT) {
-                                               /*  Trigger ADC scan loop start by setting RPS Signal 0. */
-                                               MC_ENABLE(P_MC2, MC2_ADC_RPS);
-
-                                               devpriv->ai_convert_count--;
-
-                                               if (devpriv->ai_convert_count >
-                                                   0) {
-                                                       s626_dio_set_irq(dev,
-                                                                        cmd->convert_arg);
-                                               }
-                                       }
-                               }
-                               break;
+                       if (cmd->convert_src == TRIG_TIMER) {
+                               /* Trigger ADC scan loop start */
+                               s626_mc_enable(dev, MC2_ADC_RPS, P_MC2);
                        }
                }
+       }
+       if (irqbit & IRQ_COINT3B) {
+               k = &encpriv[5];
 
-               /* read interrupt type */
-               irqbit = DEBIread(dev, LP_RDMISC2);
-
-               /* check interrupt on counters */
-               if (irqbit & IRQ_COINT1A) {
-                       k = &encpriv[0];
+               /* clear interrupt capture flag */
+               k->ResetCapFlags(dev, k);
 
-                       /* clear interrupt capture flag */
-                       k->ResetCapFlags(dev, k);
+               if (cmd->scan_begin_src == TRIG_TIMER) {
+                       /* Trigger ADC scan loop start */
+                       s626_mc_enable(dev, MC2_ADC_RPS, P_MC2);
                }
-               if (irqbit & IRQ_COINT2A) {
-                       k = &encpriv[1];
 
-                       /* clear interrupt capture flag */
-                       k->ResetCapFlags(dev, k);
+               if (cmd->convert_src == TRIG_TIMER) {
+                       k = &encpriv[4];
+                       devpriv->ai_convert_count = cmd->chanlist_len;
+                       k->SetEnable(dev, k, CLKENAB_ALWAYS);
                }
-               if (irqbit & IRQ_COINT3A) {
-                       k = &encpriv[2];
+       }
+}
 
-                       /* clear interrupt capture flag */
-                       k->ResetCapFlags(dev, k);
-               }
-               if (irqbit & IRQ_COINT1B) {
-                       k = &encpriv[3];
+static bool handle_eos_interrupt(struct comedi_device *dev)
+{
+       struct s626_private *devpriv = dev->private;
+       struct comedi_subdevice *s = dev->read_subdev;
+       struct comedi_async *async = s->async;
+       struct comedi_cmd *cmd = &async->cmd;
+       /*
+        * Init ptr to DMA buffer that holds new ADC data.  We skip the
+        * first uint16_t in the buffer because it contains junk data
+        * from the final ADC of the previous poll list scan.
+        */
+       int32_t *readaddr = (int32_t *)devpriv->ANABuf.LogicalBase + 1;
+       bool finished = false;
+       int i;
 
-                       /* clear interrupt capture flag */
-                       k->ResetCapFlags(dev, k);
-               }
-               if (irqbit & IRQ_COINT2B) {
-                       k = &encpriv[4];
+       /* get the data and hand it over to comedi */
+       for (i = 0; i < cmd->chanlist_len; i++) {
+               short tempdata;
 
-                       /* clear interrupt capture flag */
-                       k->ResetCapFlags(dev, k);
+               /*
+                * Convert ADC data to 16-bit integer values and copy
+                * to application buffer.
+                */
+               tempdata = s626_ai_reg_to_uint((int)*readaddr);
+               readaddr++;
 
-                       if (devpriv->ai_convert_count > 0) {
-                               devpriv->ai_convert_count--;
-                               if (devpriv->ai_convert_count == 0)
-                                       k->SetEnable(dev, k, CLKENAB_INDEX);
+               /* put data into read buffer */
+               /* comedi_buf_put(async, tempdata); */
+               cfc_write_to_buffer(s, tempdata);
+       }
 
-                               if (cmd->convert_src == TRIG_TIMER) {
-                                       /*  Trigger ADC scan loop start by setting RPS Signal 0. */
-                                       MC_ENABLE(P_MC2, MC2_ADC_RPS);
-                               }
-                       }
-               }
-               if (irqbit & IRQ_COINT3B) {
-                       k = &encpriv[5];
+       /* end of scan occurs */
+       async->events |= COMEDI_CB_EOS;
 
-                       /* clear interrupt capture flag */
-                       k->ResetCapFlags(dev, k);
+       if (!devpriv->ai_continous)
+               devpriv->ai_sample_count--;
+       if (devpriv->ai_sample_count <= 0) {
+               devpriv->ai_cmd_running = 0;
 
-                       if (cmd->scan_begin_src == TRIG_TIMER) {
-                               /*  Trigger ADC scan loop start by setting RPS Signal 0. */
-                               MC_ENABLE(P_MC2, MC2_ADC_RPS);
-                       }
+               /* Stop RPS program */
+               s626_mc_disable(dev, MC1_ERPS1, P_MC1);
 
-                       if (cmd->convert_src == TRIG_TIMER) {
-                               k = &encpriv[4];
-                               devpriv->ai_convert_count = cmd->chanlist_len;
-                               k->SetEnable(dev, k, CLKENAB_ALWAYS);
-                       }
-               }
+               /* send end of acquisition */
+               async->events |= COMEDI_CB_EOA;
+
+               /* disable master interrupt */
+               finished = true;
+       }
+
+       if (devpriv->ai_cmd_running && cmd->scan_begin_src == TRIG_EXT)
+               s626_dio_set_irq(dev, cmd->scan_begin_arg);
+
+       /* tell comedi that data is there */
+       comedi_event(dev, s);
+
+       return finished;
+}
+
+static irqreturn_t s626_irq_handler(int irq, void *d)
+{
+       struct comedi_device *dev = d;
+       struct s626_private *devpriv = dev->private;
+       unsigned long flags;
+       uint32_t irqtype, irqstatus;
+
+       if (!dev->attached)
+               return IRQ_NONE;
+       /*  lock to avoid race with comedi_poll */
+       spin_lock_irqsave(&dev->spinlock, flags);
+
+       /* save interrupt enable register state */
+       irqstatus = readl(devpriv->mmio + P_IER);
+
+       /* read interrupt type */
+       irqtype = readl(devpriv->mmio + P_ISR);
+
+       /* disable master interrupt */
+       writel(0, devpriv->mmio + P_IER);
+
+       /* clear interrupt */
+       writel(irqtype, devpriv->mmio + P_ISR);
+
+       switch (irqtype) {
+       case IRQ_RPS1:          /*  end_of_scan occurs */
+               if (handle_eos_interrupt(dev))
+                       irqstatus = 0;
+               break;
+       case IRQ_GPIO3: /* check dio and conter interrupt */
+               /* s626_dio_clear_irq(dev); */
+               check_dio_interrupts(dev);
+               check_counter_interrupts(dev);
+               break;
        }
 
        /* enable interrupt */
-       writel(irqstatus, devpriv->base_addr + P_IER);
+       writel(irqstatus, devpriv->mmio + P_IER);
 
        spin_unlock_irqrestore(&dev->spinlock, flags);
        return IRQ_HANDLED;
@@ -988,14 +929,15 @@ static void ResetADC(struct comedi_device *dev, uint8_t *ppl)
        uint32_t LocalPPL;
        struct comedi_cmd *cmd = &(dev->subdevices->async->cmd);
 
-       /*  Stop RPS program in case it is currently running. */
-       MC_DISABLE(P_MC1, MC1_ERPS1);
+       /* Stop RPS program in case it is currently running */
+       s626_mc_disable(dev, MC1_ERPS1, P_MC1);
 
        /*  Set starting logical address to write RPS commands. */
        pRPS = (uint32_t *) devpriv->RPSBuf.LogicalBase;
 
-       /*  Initialize RPS instruction pointer. */
-       WR7146(P_RPSADDR1, (uint32_t) devpriv->RPSBuf.PhysicalBase);
+       /* Initialize RPS instruction pointer */
+       writel((uint32_t)devpriv->RPSBuf.PhysicalBase,
+              devpriv->mmio + P_RPSADDR1);
 
        /*  Construct RPS program in RPSBuf DMA buffer */
 
@@ -1165,41 +1107,42 @@ static void ResetADC(struct comedi_device *dev, uint8_t *ppl)
        /*  End of RPS program build */
 }
 
-/* TO COMPLETE, IF NECESSARY */
-static int s626_ai_insn_config(struct comedi_device *dev,
-                              struct comedi_subdevice *s,
-                              struct comedi_insn *insn, unsigned int *data)
+#ifdef unused_code
+static int s626_ai_rinsn(struct comedi_device *dev,
+                        struct comedi_subdevice *s,
+                        struct comedi_insn *insn,
+                        unsigned int *data)
 {
+       struct s626_private *devpriv = dev->private;
+       register uint8_t i;
+       register int32_t *readaddr;
 
-       return -EINVAL;
-}
-
-/* static int s626_ai_rinsn(struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data) */
-/* { */
-/*   struct s626_private *devpriv = dev->private; */
-/*   register uint8_t  i; */
-/*   register int32_t  *readaddr; */
-
-/*   Trigger ADC scan loop start by setting RPS Signal 0. */
-/*   MC_ENABLE( P_MC2, MC2_ADC_RPS ); */
+       /* Trigger ADC scan loop start */
+       s626_mc_enable(dev, MC2_ADC_RPS, P_MC2);
 
-/*   Wait until ADC scan loop is finished (RPS Signal 0 reset). */
-/*   while ( MC_TEST( P_MC2, MC2_ADC_RPS ) ); */
+       /* Wait until ADC scan loop is finished (RPS Signal 0 reset) */
+       while (s626_mc_test(dev, MC2_ADC_RPS, P_MC2))
+               ;
 
-/* Init ptr to DMA buffer that holds new ADC data.  We skip the
- * first uint16_t in the buffer because it contains junk data from
- * the final ADC of the previous poll list scan.
- */
-/*   readaddr = (uint32_t *)devpriv->ANABuf.LogicalBase + 1; */
+       /*
+        * Init ptr to DMA buffer that holds new ADC data.  We skip the
+        * first uint16_t in the buffer because it contains junk data from
+        * the final ADC of the previous poll list scan.
+        */
+       readaddr = (uint32_t *)devpriv->ANABuf.LogicalBase + 1;
 
-/*  Convert ADC data to 16-bit integer values and copy to application buffer. */
-/*   for ( i = 0; i < devpriv->AdcItems; i++ ) { */
-/*     *data = s626_ai_reg_to_uint( *readaddr++ ); */
-/*     data++; */
-/*   } */
+       /*
+        * Convert ADC data to 16-bit integer values and
+        * copy to application buffer.
+        */
+       for (i = 0; i < devpriv->AdcItems; i++) {
+               *data = s626_ai_reg_to_uint(*readaddr++);
+               data++;
+       }
 
-/*   return i; */
-/* } */
+       return i;
+}
+#endif
 
 static int s626_ai_insn_read(struct comedi_device *dev,
                             struct comedi_subdevice *s,
@@ -1210,14 +1153,9 @@ static int s626_ai_insn_read(struct comedi_device *dev,
        uint16_t range = CR_RANGE(insn->chanspec);
        uint16_t AdcSpec = 0;
        uint32_t GpioImage;
+       int tmp;
        int n;
 
-       /* interrupt call test  */
-/*   writel(IRQ_GPIO3,devpriv->base_addr+P_PSR); */
-       /* Writing a logical 1 into any of the RPS_PSR bits causes the
-        * corresponding interrupt to be generated if enabled
-        */
-
        /* Convert application's ADC specification into form
         *  appropriate for register programming.
         */
@@ -1237,27 +1175,29 @@ static int s626_ai_insn_read(struct comedi_device *dev,
                /*  Delay 10 microseconds for analog input settling. */
                udelay(10);
 
-               /*  Start ADC by pulsing GPIO1 low. */
-               GpioImage = RR7146(P_GPIO);
-               /*  Assert ADC Start command */
-               WR7146(P_GPIO, GpioImage & ~GPIO1_HI);
-               /*    and stretch it out. */
-               WR7146(P_GPIO, GpioImage & ~GPIO1_HI);
-               WR7146(P_GPIO, GpioImage & ~GPIO1_HI);
-               /*  Negate ADC Start command. */
-               WR7146(P_GPIO, GpioImage | GPIO1_HI);
+               /* Start ADC by pulsing GPIO1 low */
+               GpioImage = readl(devpriv->mmio + P_GPIO);
+               /* Assert ADC Start command */
+               writel(GpioImage & ~GPIO1_HI, devpriv->mmio + P_GPIO);
+               /* and stretch it out */
+               writel(GpioImage & ~GPIO1_HI, devpriv->mmio + P_GPIO);
+               writel(GpioImage & ~GPIO1_HI, devpriv->mmio + P_GPIO);
+               /* Negate ADC Start command */
+               writel(GpioImage | GPIO1_HI, devpriv->mmio + P_GPIO);
 
                /*  Wait for ADC to complete (GPIO2 is asserted high when */
                /*  ADC not busy) and for data from previous conversion to */
                /*  shift into FB BUFFER 1 register. */
 
-               /*  Wait for ADC done. */
-               while (!(RR7146(P_PSR) & PSR_GPIO2))
+               /* Wait for ADC done */
+               while (!(readl(devpriv->mmio + P_PSR) & PSR_GPIO2))
                        ;
 
-               /*  Fetch ADC data. */
-               if (n != 0)
-                       data[n - 1] = s626_ai_reg_to_uint(RR7146(P_FB_BUFFER1));
+               /* Fetch ADC data */
+               if (n != 0) {
+                       tmp = readl(devpriv->mmio + P_FB_BUFFER1);
+                       data[n - 1] = s626_ai_reg_to_uint(tmp);
+               }
 
                /* Allow the ADC to stabilize for 4 microseconds before
                 * starting the next (final) conversion.  This delay is
@@ -1272,27 +1212,28 @@ static int s626_ai_insn_read(struct comedi_device *dev,
 
        /* Start a dummy conversion to cause the data from the
         * previous conversion to be shifted in. */
-       GpioImage = RR7146(P_GPIO);
-
+       GpioImage = readl(devpriv->mmio + P_GPIO);
        /* Assert ADC Start command */
-       WR7146(P_GPIO, GpioImage & ~GPIO1_HI);
-       /*    and stretch it out. */
-       WR7146(P_GPIO, GpioImage & ~GPIO1_HI);
-       WR7146(P_GPIO, GpioImage & ~GPIO1_HI);
-       /*  Negate ADC Start command. */
-       WR7146(P_GPIO, GpioImage | GPIO1_HI);
+       writel(GpioImage & ~GPIO1_HI, devpriv->mmio + P_GPIO);
+       /* and stretch it out */
+       writel(GpioImage & ~GPIO1_HI, devpriv->mmio + P_GPIO);
+       writel(GpioImage & ~GPIO1_HI, devpriv->mmio + P_GPIO);
+       /* Negate ADC Start command */
+       writel(GpioImage | GPIO1_HI, devpriv->mmio + P_GPIO);
 
        /*  Wait for the data to arrive in FB BUFFER 1 register. */
 
-       /*  Wait for ADC done. */
-       while (!(RR7146(P_PSR) & PSR_GPIO2))
+       /* Wait for ADC done */
+       while (!(readl(devpriv->mmio + P_PSR) & PSR_GPIO2))
                ;
 
        /*  Fetch ADC data from audio interface's input shift register. */
 
-       /*  Fetch ADC data. */
-       if (n != 0)
-               data[n - 1] = s626_ai_reg_to_uint(RR7146(P_FB_BUFFER1));
+       /* Fetch ADC data */
+       if (n != 0) {
+               tmp = readl(devpriv->mmio + P_FB_BUFFER1);
+               data[n - 1] = s626_ai_reg_to_uint(tmp);
+       }
 
        return n;
 }
@@ -1317,13 +1258,11 @@ static int s626_ai_load_polllist(uint8_t *ppl, struct comedi_cmd *cmd)
 static int s626_ai_inttrig(struct comedi_device *dev,
                           struct comedi_subdevice *s, unsigned int trignum)
 {
-       struct s626_private *devpriv = dev->private;
-
        if (trignum != 0)
                return -EINVAL;
 
-       /*  Start executing the RPS program. */
-       MC_ENABLE(P_MC1, MC1_ERPS1);
+       /* Start executing the RPS program */
+       s626_mc_enable(dev, MC1_ERPS1, P_MC1);
 
        s->async->inttrig = NULL;
 
@@ -1407,10 +1346,10 @@ static int s626_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                return -EBUSY;
        }
        /* disable interrupt */
-       writel(0, devpriv->base_addr + P_IER);
+       writel(0, devpriv->mmio + P_IER);
 
        /* clear interrupt request */
-       writel(IRQ_RPS1 | IRQ_GPIO3, devpriv->base_addr + P_ISR);
+       writel(IRQ_RPS1 | IRQ_GPIO3, devpriv->mmio + P_ISR);
 
        /* clear any pending interrupt */
        s626_dio_clear_irq(dev);
@@ -1491,11 +1430,11 @@ static int s626_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 
        switch (cmd->start_src) {
        case TRIG_NOW:
-               /*  Trigger ADC scan loop start by setting RPS Signal 0. */
-               /*  MC_ENABLE( P_MC2, MC2_ADC_RPS ); */
+               /* Trigger ADC scan loop start */
+               /* s626_mc_enable(dev, MC2_ADC_RPS, P_MC2); */
 
-               /*  Start executing the RPS program. */
-               MC_ENABLE(P_MC1, MC1_ERPS1);
+               /* Start executing the RPS program */
+               s626_mc_enable(dev, MC1_ERPS1, P_MC1);
 
                s->async->inttrig = NULL;
                break;
@@ -1511,7 +1450,7 @@ static int s626_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        }
 
        /* enable interrupt */
-       writel(IRQ_GPIO3 | IRQ_RPS1, devpriv->base_addr + P_IER);
+       writel(IRQ_GPIO3 | IRQ_RPS1, devpriv->mmio + P_IER);
 
        return 0;
 }
@@ -1628,11 +1567,11 @@ static int s626_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
 {
        struct s626_private *devpriv = dev->private;
 
-       /*  Stop RPS program in case it is currently running. */
-       MC_DISABLE(P_MC1, MC1_ERPS1);
+       /* Stop RPS program in case it is currently running */
+       s626_mc_disable(dev, MC1_ERPS1, P_MC1);
 
        /* disable master interrupt */
-       writel(0, devpriv->base_addr + P_IER);
+       writel(0, devpriv->mmio + P_IER);
 
        devpriv->ai_cmd_running = 0;
 
@@ -1679,84 +1618,74 @@ static int s626_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
 static void s626_dio_init(struct comedi_device *dev)
 {
        uint16_t group;
-       struct comedi_subdevice *s;
 
        /*  Prepare to treat writes to WRCapSel as capture disables. */
        DEBIwrite(dev, LP_MISC1, MISC1_NOEDCAP);
 
        /*  For each group of sixteen channels ... */
        for (group = 0; group < S626_DIO_BANKS; group++) {
-               s = dev->subdevices + 2 + group;
-               DEBIwrite(dev, diopriv->WRIntSel, 0);   /*  Disable all interrupts. */
-               DEBIwrite(dev, diopriv->WRCapSel, 0xFFFF);      /*  Disable all event */
-               /*  captures. */
-               DEBIwrite(dev, diopriv->WREdgSel, 0);   /*  Init all DIOs to */
-               /*  default edge */
-               /*  polarity. */
-               DEBIwrite(dev, diopriv->WRDOut, 0);     /*  Program all outputs */
-               /*  to inactive state. */
+               /* Disable all interrupts */
+               DEBIwrite(dev, LP_WRINTSEL(group), 0);
+               /* Disable all event captures */
+               DEBIwrite(dev, LP_WRCAPSEL(group), 0xffff);
+               /* Init all DIOs to default edge polarity */
+               DEBIwrite(dev, LP_WREDGSEL(group), 0);
+               /* Program all outputs to inactive state */
+               DEBIwrite(dev, LP_WRDOUT(group), 0);
        }
 }
 
-/* DIO devices are slightly special.  Although it is possible to
- * implement the insn_read/insn_write interface, it is much more
- * useful to applications if you implement the insn_bits interface.
- * This allows packed reading/writing of the DIO channels.  The comedi
- * core can convert between insn_bits and insn_read/write */
-
 static int s626_dio_insn_bits(struct comedi_device *dev,
                              struct comedi_subdevice *s,
-                             struct comedi_insn *insn, unsigned int *data)
+                             struct comedi_insn *insn,
+                             unsigned int *data)
 {
-       /*
-        * The insn data consists of a mask in data[0] and the new data in
-        * data[1]. The mask defines which bits we are concerning about.
-        * The new data must be anded with the mask.  Each channel
-        * corresponds to a bit.
-        */
-       if (data[0]) {
-               /* Check if requested ports are configured for output */
-               if ((s->io_bits & data[0]) != data[0])
-                       return -EIO;
+       unsigned long group = (unsigned long)s->private;
+       unsigned long mask = data[0];
+       unsigned long bits = data[1];
 
-               s->state &= ~data[0];
-               s->state |= data[0] & data[1];
+       if (mask) {
+               /* Check if requested channels are configured for output */
+               if ((s->io_bits & mask) != mask)
+                       return -EIO;
 
-               /* Write out the new digital output lines */
+               s->state &= ~mask;
+               s->state |= (bits & mask);
 
-               DEBIwrite(dev, diopriv->WRDOut, s->state);
+               DEBIwrite(dev, LP_WRDOUT(group), s->state);
        }
-       data[1] = DEBIread(dev, diopriv->RDDIn);
+       data[1] = DEBIread(dev, LP_RDDIN(group));
 
        return insn->n;
 }
 
 static int s626_dio_insn_config(struct comedi_device *dev,
                                struct comedi_subdevice *s,
-                               struct comedi_insn *insn, unsigned int *data)
+                               struct comedi_insn *insn,
+                               unsigned int *data)
 {
+       unsigned long group = (unsigned long)s->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int mask = 1 << chan;
 
        switch (data[0]) {
        case INSN_CONFIG_DIO_QUERY:
-               data[1] =
-                   (s->
-                    io_bits & (1 << CR_CHAN(insn->chanspec))) ? COMEDI_OUTPUT :
-                   COMEDI_INPUT;
+               data[1] = (s->io_bits & mask) ? COMEDI_OUTPUT : COMEDI_INPUT;
                return insn->n;
                break;
        case COMEDI_INPUT:
-               s->io_bits &= ~(1 << CR_CHAN(insn->chanspec));
+               s->io_bits &= ~mask;
                break;
        case COMEDI_OUTPUT:
-               s->io_bits |= 1 << CR_CHAN(insn->chanspec);
+               s->io_bits |= mask;
                break;
        default:
                return -EINVAL;
                break;
        }
-       DEBIwrite(dev, diopriv->WRDOut, s->io_bits);
+       DEBIwrite(dev, LP_WRDOUT(group), s->io_bits);
 
-       return 1;
+       return insn->n;
 }
 
 /* Now this function initializes the value of the counter (data[0])
@@ -1861,13 +1790,13 @@ static void CloseDMAB(struct comedi_device *dev, struct bufferDMA *pdma,
 
 static void ResetCapFlags_A(struct comedi_device *dev, struct enc_private *k)
 {
-       DEBIreplace(dev, k->MyCRB, (uint16_t) (~CRBMSK_INTCTRL),
+       DEBIreplace(dev, k->MyCRB, ~CRBMSK_INTCTRL,
                    CRBMSK_INTRESETCMD | CRBMSK_INTRESET_A);
 }
 
 static void ResetCapFlags_B(struct comedi_device *dev, struct enc_private *k)
 {
-       DEBIreplace(dev, k->MyCRB, (uint16_t) (~CRBMSK_INTCTRL),
+       DEBIreplace(dev, k->MyCRB, ~CRBMSK_INTCTRL,
                    CRBMSK_INTRESETCMD | CRBMSK_INTRESET_B);
 }
 
@@ -2012,8 +1941,7 @@ static void SetMode_A(struct comedi_device *dev, struct enc_private *k,
        /*  While retaining CounterB and LatchSrc configurations, program the */
        /*  new counter operating mode. */
        DEBIreplace(dev, k->MyCRA, CRAMSK_INDXSRC_B | CRAMSK_CLKSRC_B, cra);
-       DEBIreplace(dev, k->MyCRB,
-                   (uint16_t) (~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_A)), crb);
+       DEBIreplace(dev, k->MyCRB, ~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_A), crb);
 }
 
 static void SetMode_B(struct comedi_device *dev, struct enc_private *k,
@@ -2074,8 +2002,7 @@ static void SetMode_B(struct comedi_device *dev, struct enc_private *k,
 
        /*  While retaining CounterA and LatchSrc configurations, program the */
        /*  new counter operating mode. */
-       DEBIreplace(dev, k->MyCRA,
-                   (uint16_t) (~(CRAMSK_INDXSRC_B | CRAMSK_CLKSRC_B)), cra);
+       DEBIreplace(dev, k->MyCRA, ~(CRAMSK_INDXSRC_B | CRAMSK_CLKSRC_B), cra);
        DEBIreplace(dev, k->MyCRB, CRBMSK_CLKENAB_A | CRBMSK_LATCHSRC, crb);
 }
 
@@ -2084,17 +2011,15 @@ static void SetMode_B(struct comedi_device *dev, struct enc_private *k,
 static void SetEnable_A(struct comedi_device *dev, struct enc_private *k,
                        uint16_t enab)
 {
-       DEBIreplace(dev, k->MyCRB,
-                   (uint16_t) (~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_A)),
-                   (uint16_t) (enab << CRBBIT_CLKENAB_A));
+       DEBIreplace(dev, k->MyCRB, ~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_A),
+                   enab << CRBBIT_CLKENAB_A);
 }
 
 static void SetEnable_B(struct comedi_device *dev, struct enc_private *k,
                        uint16_t enab)
 {
-       DEBIreplace(dev, k->MyCRB,
-                   (uint16_t) (~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_B)),
-                   (uint16_t) (enab << CRBBIT_CLKENAB_B));
+       DEBIreplace(dev, k->MyCRB, ~(CRBMSK_INTCTRL | CRBMSK_CLKENAB_B),
+                   enab << CRBBIT_CLKENAB_B);
 }
 
 static uint16_t GetEnable_A(struct comedi_device *dev, struct enc_private *k)
@@ -2123,16 +2048,15 @@ static uint16_t GetEnable_B(struct comedi_device *dev, struct enc_private *k)
 static void SetLoadTrig_A(struct comedi_device *dev, struct enc_private *k,
                          uint16_t Trig)
 {
-       DEBIreplace(dev, k->MyCRA, (uint16_t) (~CRAMSK_LOADSRC_A),
-                   (uint16_t) (Trig << CRABIT_LOADSRC_A));
+       DEBIreplace(dev, k->MyCRA, ~CRAMSK_LOADSRC_A,
+                   Trig << CRABIT_LOADSRC_A);
 }
 
 static void SetLoadTrig_B(struct comedi_device *dev, struct enc_private *k,
                          uint16_t Trig)
 {
-       DEBIreplace(dev, k->MyCRB,
-                   (uint16_t) (~(CRBMSK_LOADSRC_B | CRBMSK_INTCTRL)),
-                   (uint16_t) (Trig << CRBBIT_LOADSRC_B));
+       DEBIreplace(dev, k->MyCRB, ~(CRBMSK_LOADSRC_B | CRBMSK_INTCTRL),
+                   Trig << CRBBIT_LOADSRC_B);
 }
 
 static uint16_t GetLoadTrig_A(struct comedi_device *dev, struct enc_private *k)
@@ -2156,12 +2080,12 @@ static void SetIntSrc_A(struct comedi_device *dev, struct enc_private *k,
        struct s626_private *devpriv = dev->private;
 
        /*  Reset any pending counter overflow or index captures. */
-       DEBIreplace(dev, k->MyCRB, (uint16_t) (~CRBMSK_INTCTRL),
+       DEBIreplace(dev, k->MyCRB, ~CRBMSK_INTCTRL,
                    CRBMSK_INTRESETCMD | CRBMSK_INTRESET_A);
 
        /*  Program counter interrupt source. */
        DEBIreplace(dev, k->MyCRA, ~CRAMSK_INTSRC_A,
-                   (uint16_t) (IntSource << CRABIT_INTSRC_A));
+                   IntSource << CRABIT_INTSRC_A);
 
        /*  Update MISC2 interrupt enable mask. */
        devpriv->CounterIntEnabs =
@@ -2430,7 +2354,7 @@ static void s626_initialize(struct comedi_device *dev)
        int i;
 
        /* Enable DEBI and audio pins, enable I2C interface */
-       MC_ENABLE(P_MC1, MC1_DEBI | MC1_AUDIO | MC1_I2C);
+       s626_mc_enable(dev, MC1_DEBI | MC1_AUDIO | MC1_I2C, P_MC1);
 
        /*
         *  Configure DEBI operating mode
@@ -2440,15 +2364,16 @@ static void s626_initialize(struct comedi_device *dev)
         *   Set up byte lane steering
         *   Intel-compatible local bus (DEBI never times out)
         */
-       WR7146(P_DEBICFG, DEBI_CFG_SLAVE16 |
-                         (DEBI_TOUT << DEBI_CFG_TOUT_BIT) |
-                         DEBI_SWAP | DEBI_CFG_INTEL);
+       writel(DEBI_CFG_SLAVE16 |
+              (DEBI_TOUT << DEBI_CFG_TOUT_BIT) |
+              DEBI_SWAP | DEBI_CFG_INTEL,
+              devpriv->mmio + P_DEBICFG);
 
        /* Disable MMU paging */
-       WR7146(P_DEBIPAGE, DEBI_PAGE_DISABLE);
+       writel(DEBI_PAGE_DISABLE, devpriv->mmio + P_DEBIPAGE);
 
        /* Init GPIO so that ADC Start* is negated */
-       WR7146(P_GPIO, GPIO_BASE | GPIO1_HI);
+       writel(GPIO_BASE | GPIO1_HI, devpriv->mmio + P_GPIO);
 
        /* I2C device address for onboard eeprom (revb) */
        devpriv->I2CAdrs = 0xA0;
@@ -2457,9 +2382,9 @@ static void s626_initialize(struct comedi_device *dev)
         * Issue an I2C ABORT command to halt any I2C
         * operation in progress and reset BUSY flag.
         */
-       WR7146(P_I2CSTAT, I2C_CLKSEL | I2C_ABORT);
-       MC_ENABLE(P_MC2, MC2_UPLD_IIC);
-       while ((RR7146(P_MC2) & MC2_UPLD_IIC) == 0)
+       writel(I2C_CLKSEL | I2C_ABORT, devpriv->mmio + P_I2CSTAT);
+       s626_mc_enable(dev, MC2_UPLD_IIC, P_MC2);
+       while (!(readl(devpriv->mmio + P_MC2) & MC2_UPLD_IIC))
                ;
 
        /*
@@ -2467,9 +2392,9 @@ static void s626_initialize(struct comedi_device *dev)
         * reg twice to reset all  I2C error flags.
         */
        for (i = 0; i < 2; i++) {
-               WR7146(P_I2CSTAT, I2C_CLKSEL);
-               MC_ENABLE(P_MC2, MC2_UPLD_IIC);
-               while (!MC_TEST(P_MC2, MC2_UPLD_IIC))
+               writel(I2C_CLKSEL, devpriv->mmio + P_I2CSTAT);
+               s626_mc_enable(dev, MC2_UPLD_IIC, P_MC2);
+               while (!s626_mc_test(dev, MC2_UPLD_IIC, P_MC2))
                        ;
        }
 
@@ -2479,7 +2404,7 @@ static void s626_initialize(struct comedi_device *dev)
         * DAC data setup times are satisfied, enable DAC serial
         * clock out.
         */
-       WR7146(P_ACON2, ACON2_INIT);
+       writel(ACON2_INIT, devpriv->mmio + P_ACON2);
 
        /*
         * Set up TSL1 slot list, which is used to control the
@@ -2487,22 +2412,23 @@ static void s626_initialize(struct comedi_device *dev)
         * SIB_A1  = store data uint8_t at next available location
         * in FB BUFFER1 register.
         */
-       WR7146(P_TSL1, RSD1 | SIB_A1);
-       WR7146(P_TSL1 + 4, RSD1 | SIB_A1 | EOS);
+       writel(RSD1 | SIB_A1, devpriv->mmio + P_TSL1);
+       writel(RSD1 | SIB_A1 | EOS, devpriv->mmio + P_TSL1 + 4);
 
        /* Enable TSL1 slot list so that it executes all the time */
-       WR7146(P_ACON1, ACON1_ADCSTART);
+       writel(ACON1_ADCSTART, devpriv->mmio + P_ACON1);
 
        /*
         * Initialize RPS registers used for ADC
         */
 
        /* Physical start of RPS program */
-       WR7146(P_RPSADDR1, (uint32_t)devpriv->RPSBuf.PhysicalBase);
+       writel((uint32_t)devpriv->RPSBuf.PhysicalBase,
+              devpriv->mmio + P_RPSADDR1);
        /* RPS program performs no explicit mem writes */
-       WR7146(P_RPSPAGE1, 0);
+       writel(0, devpriv->mmio + P_RPSPAGE1);
        /* Disable RPS timeouts */
-       WR7146(P_RPS1_TOUT, 0);
+       writel(0, devpriv->mmio + P_RPS1_TOUT);
 
 #if 0
        /*
@@ -2558,7 +2484,7 @@ static void s626_initialize(struct comedi_device *dev)
         *   burst length = 1 DWORD
         *   threshold = 1 DWORD.
         */
-       WR7146(P_PCI_BT_A, 0);
+       writel(0, devpriv->mmio + P_PCI_BT_A);
 
        /*
         * Init Audio2's output DMA physical addresses.  The protection
@@ -2568,8 +2494,9 @@ static void s626_initialize(struct comedi_device *dev)
         */
        pPhysBuf = devpriv->ANABuf.PhysicalBase +
                   (DAC_WDMABUF_OS * sizeof(uint32_t));
-       WR7146(P_BASEA2_OUT, (uint32_t) pPhysBuf);
-       WR7146(P_PROTA2_OUT, (uint32_t) (pPhysBuf + sizeof(uint32_t)));
+       writel((uint32_t)pPhysBuf, devpriv->mmio + P_BASEA2_OUT);
+       writel((uint32_t)(pPhysBuf + sizeof(uint32_t)),
+              devpriv->mmio + P_PROTA2_OUT);
 
        /*
         * Cache Audio2's output DMA buffer logical address.  This is
@@ -2584,7 +2511,7 @@ static void s626_initialize(struct comedi_device *dev)
         * DMAC will automatically halt and its PCI address pointer
         * will be reset when the protection address is reached.
         */
-       WR7146(P_PAGEA2_OUT, 8);
+       writel(8, devpriv->mmio + P_PAGEA2_OUT);
 
        /*
         * Initialize time slot list 2 (TSL2), which is used to control
@@ -2599,7 +2526,7 @@ static void s626_initialize(struct comedi_device *dev)
         */
 
        /* Slot 0: Trap TSL execution, shift 0xFF into FB_BUFFER2 */
-       SETVECT(0, XSD2 | RSD3 | SIB_A2 | EOS);
+       writel(XSD2 | RSD3 | SIB_A2 | EOS, devpriv->mmio + VECTPORT(0));
 
        /*
         * Initialize slot 1, which is constant.  Slot 1 causes a
@@ -2611,10 +2538,10 @@ static void s626_initialize(struct comedi_device *dev)
         */
 
        /* Slot 1: Fetch DWORD from Audio2's output FIFO */
-       SETVECT(1, LF_A2);
+       writel(LF_A2, devpriv->mmio + VECTPORT(1));
 
        /* Start DAC's audio interface (TSL2) running */
-       WR7146(P_ACON1, ACON1_DACSTART);
+       writel(ACON1_DACSTART, devpriv->mmio + P_ACON1);
 
        /*
         * Init Trim DACs to calibrated values.  Do it twice because the
@@ -2653,9 +2580,6 @@ static void s626_initialize(struct comedi_device *dev)
 
        /* Initialize the digital I/O subsystem */
        s626_dio_init(dev);
-
-       /* enable interrupt test */
-       /* writel(IRQ_GPIO3 | IRQ_RPS1, devpriv->base_addr + P_IER); */
 }
 
 static int s626_auto_attach(struct comedi_device *dev,
@@ -2673,21 +2597,20 @@ static int s626_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
-       dev->iobase = 1;        /* detach needs this */
 
-       devpriv->base_addr = ioremap(pci_resource_start(pcidev, 0),
-                                    pci_resource_len(pcidev, 0));
-       if (!devpriv->base_addr)
+       devpriv->mmio = ioremap(pci_resource_start(pcidev, 0),
+                               pci_resource_len(pcidev, 0));
+       if (!devpriv->mmio)
                return -ENOMEM;
 
        /* disable master interrupt */
-       writel(0, devpriv->base_addr + P_IER);
+       writel(0, devpriv->mmio + P_IER);
 
        /* soft reset */
-       writel(MC1_SOFT_RESET, devpriv->base_addr + P_MC1);
+       writel(MC1_SOFT_RESET, devpriv->mmio + P_MC1);
 
        /* DMA FIXME DMA// */
 
@@ -2707,79 +2630,79 @@ static int s626_auto_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
-       s = dev->subdevices + 0;
+       s = &dev->subdevices[0];
        /* analog input subdevice */
-       dev->read_subdev = s;
-       /* we support single-ended (ground) and differential */
-       s->type = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE | SDF_DIFF | SDF_CMD_READ;
-       s->n_chan = S626_ADC_CHANNELS;
-       s->maxdata = (0xffff >> 2);
-       s->range_table = &s626_range_table;
-       s->len_chanlist = S626_ADC_CHANNELS;
-       s->insn_config = s626_ai_insn_config;
-       s->insn_read = s626_ai_insn_read;
-       s->do_cmd = s626_ai_cmd;
-       s->do_cmdtest = s626_ai_cmdtest;
-       s->cancel = s626_ai_cancel;
-
-       s = dev->subdevices + 1;
+       s->type         = COMEDI_SUBD_AI;
+       s->subdev_flags = SDF_READABLE | SDF_DIFF | SDF_CMD_READ;
+       s->n_chan       = S626_ADC_CHANNELS;
+       s->maxdata      = 0x3fff;
+       s->range_table  = &s626_range_table;
+       s->len_chanlist = S626_ADC_CHANNELS;
+       s->insn_read    = s626_ai_insn_read;
+       if (dev->irq) {
+               dev->read_subdev = s;
+               s->do_cmd       = s626_ai_cmd;
+               s->do_cmdtest   = s626_ai_cmdtest;
+               s->cancel       = s626_ai_cancel;
+       }
+
+       s = &dev->subdevices[1];
        /* analog output subdevice */
-       s->type = COMEDI_SUBD_AO;
-       s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
-       s->n_chan = S626_DAC_CHANNELS;
-       s->maxdata = (0x3fff);
-       s->range_table = &range_bipolar10;
-       s->insn_write = s626_ao_winsn;
-       s->insn_read = s626_ao_rinsn;
-
-       s = dev->subdevices + 2;
+       s->type         = COMEDI_SUBD_AO;
+       s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
+       s->n_chan       = S626_DAC_CHANNELS;
+       s->maxdata      = 0x3fff;
+       s->range_table  = &range_bipolar10;
+       s->insn_write   = s626_ao_winsn;
+       s->insn_read    = s626_ao_rinsn;
+
+       s = &dev->subdevices[2];
        /* digital I/O subdevice */
-       s->type = COMEDI_SUBD_DIO;
-       s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
-       s->n_chan = 16;
-       s->maxdata = 1;
-       s->io_bits = 0xffff;
-       s->private = &dio_private_A;
-       s->range_table = &range_digital;
-       s->insn_config = s626_dio_insn_config;
-       s->insn_bits = s626_dio_insn_bits;
-
-       s = dev->subdevices + 3;
+       s->type         = COMEDI_SUBD_DIO;
+       s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
+       s->n_chan       = 16;
+       s->maxdata      = 1;
+       s->io_bits      = 0xffff;
+       s->private      = (void *)0;    /* DIO group 0 */
+       s->range_table  = &range_digital;
+       s->insn_config  = s626_dio_insn_config;
+       s->insn_bits    = s626_dio_insn_bits;
+
+       s = &dev->subdevices[3];
        /* digital I/O subdevice */
-       s->type = COMEDI_SUBD_DIO;
-       s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
-       s->n_chan = 16;
-       s->maxdata = 1;
-       s->io_bits = 0xffff;
-       s->private = &dio_private_B;
-       s->range_table = &range_digital;
-       s->insn_config = s626_dio_insn_config;
-       s->insn_bits = s626_dio_insn_bits;
-
-       s = dev->subdevices + 4;
+       s->type         = COMEDI_SUBD_DIO;
+       s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
+       s->n_chan       = 16;
+       s->maxdata      = 1;
+       s->io_bits      = 0xffff;
+       s->private      = (void *)1;    /* DIO group 1 */
+       s->range_table  = &range_digital;
+       s->insn_config  = s626_dio_insn_config;
+       s->insn_bits    = s626_dio_insn_bits;
+
+       s = &dev->subdevices[4];
        /* digital I/O subdevice */
-       s->type = COMEDI_SUBD_DIO;
-       s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
-       s->n_chan = 16;
-       s->maxdata = 1;
-       s->io_bits = 0xffff;
-       s->private = &dio_private_C;
-       s->range_table = &range_digital;
-       s->insn_config = s626_dio_insn_config;
-       s->insn_bits = s626_dio_insn_bits;
-
-       s = dev->subdevices + 5;
+       s->type         = COMEDI_SUBD_DIO;
+       s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
+       s->n_chan       = 16;
+       s->maxdata      = 1;
+       s->io_bits      = 0xffff;
+       s->private      = (void *)2;    /* DIO group 2 */
+       s->range_table  = &range_digital;
+       s->insn_config  = s626_dio_insn_config;
+       s->insn_bits    = s626_dio_insn_bits;
+
+       s = &dev->subdevices[5];
        /* encoder (counter) subdevice */
-       s->type = COMEDI_SUBD_COUNTER;
-       s->subdev_flags = SDF_WRITABLE | SDF_READABLE | SDF_LSAMPL;
-       s->n_chan = S626_ENCODER_CHANNELS;
-       s->private = enc_private_data;
-       s->insn_config = s626_enc_insn_config;
-       s->insn_read = s626_enc_insn_read;
-       s->insn_write = s626_enc_insn_write;
-       s->maxdata = 0xffffff;
-       s->range_table = &range_unknown;
+       s->type         = COMEDI_SUBD_COUNTER;
+       s->subdev_flags = SDF_WRITABLE | SDF_READABLE | SDF_LSAMPL;
+       s->n_chan       = S626_ENCODER_CHANNELS;
+       s->maxdata      = 0xffffff;
+       s->private      = enc_private_data;
+       s->range_table  = &range_unknown;
+       s->insn_config  = s626_enc_insn_config;
+       s->insn_read    = s626_enc_insn_read;
+       s->insn_write   = s626_enc_insn_write;
 
        s626_initialize(dev);
 
@@ -2790,24 +2713,26 @@ static int s626_auto_attach(struct comedi_device *dev,
 
 static void s626_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct s626_private *devpriv = dev->private;
 
        if (devpriv) {
                /* stop ai_command */
                devpriv->ai_cmd_running = 0;
 
-               if (devpriv->base_addr) {
+               if (devpriv->mmio) {
                        /* interrupt mask */
-                       WR7146(P_IER, 0);       /*  Disable master interrupt. */
-                       WR7146(P_ISR, IRQ_GPIO3 | IRQ_RPS1);    /*  Clear board's IRQ status flag. */
+                       /* Disable master interrupt */
+                       writel(0, devpriv->mmio + P_IER);
+                       /* Clear board's IRQ status flag */
+                       writel(IRQ_GPIO3 | IRQ_RPS1,
+                              devpriv->mmio + P_ISR);
 
                        /*  Disable the watchdog timer and battery charger. */
                        WriteMISC2(dev, 0);
 
-                       /*  Close all interfaces on 7146 device. */
-                       WR7146(P_MC1, MC1_SHUTDOWN);
-                       WR7146(P_ACON1, ACON1_BASE);
+                       /* Close all interfaces on 7146 device */
+                       writel(MC1_SHUTDOWN, devpriv->mmio + P_MC1);
+                       writel(ACON1_BASE, devpriv->mmio + P_ACON1);
 
                        CloseDMAB(dev, &devpriv->RPSBuf, DMABUF_SIZE);
                        CloseDMAB(dev, &devpriv->ANABuf, DMABUF_SIZE);
@@ -2815,13 +2740,10 @@ static void s626_detach(struct comedi_device *dev)
 
                if (dev->irq)
                        free_irq(dev->irq, dev);
-               if (devpriv->base_addr)
-                       iounmap(devpriv->base_addr);
-       }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
+               if (devpriv->mmio)
+                       iounmap(devpriv->mmio);
        }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver s626_driver = {
@@ -2832,9 +2754,9 @@ static struct comedi_driver s626_driver = {
 };
 
 static int s626_pci_probe(struct pci_dev *dev,
-                                   const struct pci_device_id *ent)
+                         const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &s626_driver);
+       return comedi_pci_auto_config(dev, &s626_driver, id->driver_data);
 }
 
 /*
index ff4b3a5e4e5f2096d1a4c889f591e77f9a73b440..99cd57b092ea7e40bd13bce47d9041f6416dc99f 100644 (file)
 #define LP_DACPOL              0x0082  /*   Write DAC polarity. */
 #define LP_GSEL                        0x0084  /*   Write ADC gain. */
 #define LP_ISEL                        0x0086  /*   Write ADC channel select. */
-/*  Digital I/O (write only): */
-#define LP_WRINTSELA           0x0042  /*   Write A interrupt enable. */
-#define LP_WREDGSELA           0x0044  /*   Write A edge selection. */
-#define LP_WRCAPSELA           0x0046  /*   Write A capture enable. */
-#define LP_WRDOUTA             0x0048  /*   Write A digital output. */
-#define LP_WRINTSELB           0x0052  /*   Write B interrupt enable. */
-#define LP_WREDGSELB           0x0054  /*   Write B edge selection. */
-#define LP_WRCAPSELB           0x0056  /*   Write B capture enable. */
-#define LP_WRDOUTB             0x0058  /*   Write B digital output. */
-#define LP_WRINTSELC           0x0062  /*   Write C interrupt enable. */
-#define LP_WREDGSELC           0x0064  /*   Write C edge selection. */
-#define LP_WRCAPSELC           0x0066  /*   Write C capture enable. */
-#define LP_WRDOUTC             0x0068  /*   Write C digital output. */
-
-/*  Digital I/O (read only): */
-#define LP_RDDINA              0x0040  /*   Read digital input. */
-#define LP_RDCAPFLGA           0x0048  /*   Read edges captured. */
-#define LP_RDINTSELA           0x004A  /*   Read interrupt enable register. */
-#define LP_RDEDGSELA           0x004C  /*   Read edge selection register. */
-#define LP_RDCAPSELA           0x004E  /*   Read capture enable register. */
-#define LP_RDDINB              0x0050  /*   Read digital input. */
-#define LP_RDCAPFLGB           0x0058  /*   Read edges captured. */
-#define LP_RDINTSELB           0x005A  /*   Read interrupt enable register. */
-#define LP_RDEDGSELB           0x005C  /*   Read edge selection register. */
-#define LP_RDCAPSELB           0x005E  /*   Read capture enable register. */
-#define LP_RDDINC              0x0060  /*   Read digital input. */
-#define LP_RDCAPFLGC           0x0068  /*   Read edges captured. */
-#define LP_RDINTSELC           0x006A  /*   Read interrupt enable register. */
-#define LP_RDEDGSELC           0x006C  /*   Read edge selection register. */
-#define LP_RDCAPSELC           0x006E  /*   Read capture enable register. */
+
+/* Digital I/O registers */
+#define LP_RDDIN(x)            (0x0040 + (x) * 0x10)   /* R: digital input */
+#define LP_WRINTSEL(x)         (0x0042 + (x) * 0x10)   /* W: int enable */
+#define LP_WREDGSEL(x)         (0x0044 + (x) * 0x10)   /* W: edge selection */
+#define LP_WRCAPSEL(x)         (0x0046 + (x) * 0x10)   /* W: capture enable */
+#define LP_RDCAPFLG(x)         (0x0048 + (x) * 0x10)   /* R: edges captured */
+#define LP_WRDOUT(x)           (0x0048 + (x) * 0x10)   /* W: digital output */
+#define LP_RDINTSEL(x)         (0x004a + (x) * 0x10)   /* R: int enable */
+#define LP_RDEDGSEL(x)         (0x004c + (x) * 0x10)   /* R: edge selection */
+#define LP_RDCAPSEL(x)         (0x004e + (x) * 0x10)   /* R: capture enable */
 
 /*  Counter Registers (read/write): */
 #define LP_CR0A                        0x0000  /*   0A setup register. */
 
 /*  Bit field masks for CRA and CRB. */
 
-#define CRAMSK_INDXSRC_B       ((uint16_t)(3 << CRABIT_INDXSRC_B))
-#define CRAMSK_CLKSRC_B                ((uint16_t)(3 << CRABIT_CLKSRC_B))
-#define CRAMSK_INDXPOL_A       ((uint16_t)(1 << CRABIT_INDXPOL_A))
-#define CRAMSK_LOADSRC_A       ((uint16_t)(3 << CRABIT_LOADSRC_A))
-#define CRAMSK_CLKMULT_A       ((uint16_t)(3 << CRABIT_CLKMULT_A))
-#define CRAMSK_INTSRC_A                ((uint16_t)(3 << CRABIT_INTSRC_A))
-#define CRAMSK_CLKPOL_A                ((uint16_t)(3 << CRABIT_CLKPOL_A))
-#define CRAMSK_INDXSRC_A       ((uint16_t)(3 << CRABIT_INDXSRC_A))
-#define CRAMSK_CLKSRC_A                ((uint16_t)(3 << CRABIT_CLKSRC_A))
-
-#define CRBMSK_INTRESETCMD     ((uint16_t)(1 << CRBBIT_INTRESETCMD))
-#define CRBMSK_INTRESET_B      ((uint16_t)(1 << CRBBIT_INTRESET_B))
-#define CRBMSK_INTRESET_A      ((uint16_t)(1 << CRBBIT_INTRESET_A))
-#define CRBMSK_CLKENAB_A       ((uint16_t)(1 << CRBBIT_CLKENAB_A))
-#define CRBMSK_INTSRC_B                ((uint16_t)(3 << CRBBIT_INTSRC_B))
-#define CRBMSK_LATCHSRC                ((uint16_t)(3 << CRBBIT_LATCHSRC))
-#define CRBMSK_LOADSRC_B       ((uint16_t)(3 << CRBBIT_LOADSRC_B))
-#define CRBMSK_CLKMULT_B       ((uint16_t)(3 << CRBBIT_CLKMULT_B))
-#define CRBMSK_CLKENAB_B       ((uint16_t)(1 << CRBBIT_CLKENAB_B))
-#define CRBMSK_INDXPOL_B       ((uint16_t)(1 << CRBBIT_INDXPOL_B))
-#define CRBMSK_CLKPOL_B                ((uint16_t)(1 << CRBBIT_CLKPOL_B))
+#define CRAMSK_INDXSRC_B       (3 << CRABIT_INDXSRC_B)
+#define CRAMSK_CLKSRC_B                (3 << CRABIT_CLKSRC_B)
+#define CRAMSK_INDXPOL_A       (1 << CRABIT_INDXPOL_A)
+#define CRAMSK_LOADSRC_A       (3 << CRABIT_LOADSRC_A)
+#define CRAMSK_CLKMULT_A       (3 << CRABIT_CLKMULT_A)
+#define CRAMSK_INTSRC_A                (3 << CRABIT_INTSRC_A)
+#define CRAMSK_CLKPOL_A                (3 << CRABIT_CLKPOL_A)
+#define CRAMSK_INDXSRC_A       (3 << CRABIT_INDXSRC_A)
+#define CRAMSK_CLKSRC_A                (3 << CRABIT_CLKSRC_A)
+
+#define CRBMSK_INTRESETCMD     (1 << CRBBIT_INTRESETCMD)
+#define CRBMSK_INTRESET_B      (1 << CRBBIT_INTRESET_B)
+#define CRBMSK_INTRESET_A      (1 << CRBBIT_INTRESET_A)
+#define CRBMSK_CLKENAB_A       (1 << CRBBIT_CLKENAB_A)
+#define CRBMSK_INTSRC_B                (3 << CRBBIT_INTSRC_B)
+#define CRBMSK_LATCHSRC                (3 << CRBBIT_LATCHSRC)
+#define CRBMSK_LOADSRC_B       (3 << CRBBIT_LOADSRC_B)
+#define CRBMSK_CLKMULT_B       (3 << CRBBIT_CLKMULT_B)
+#define CRBMSK_CLKENAB_B       (1 << CRBBIT_CLKENAB_B)
+#define CRBMSK_INDXPOL_B       (1 << CRBBIT_INDXPOL_B)
+#define CRBMSK_CLKPOL_B                (1 << CRBBIT_CLKPOL_B)
 
 #define CRBMSK_INTCTRL         (CRBMSK_INTRESETCMD | CRBMSK_INTRESET_A | CRBMSK_INTRESET_B)    /*  Interrupt reset control bits. */
 
 
 /*  Bit field masks for standardized SETUP structure. */
 
-#define STDMSK_INTSRC          ((uint16_t)(3 << STDBIT_INTSRC))
-#define STDMSK_LATCHSRC                ((uint16_t)(3 << STDBIT_LATCHSRC))
-#define STDMSK_LOADSRC         ((uint16_t)(3 << STDBIT_LOADSRC))
-#define STDMSK_INDXSRC         ((uint16_t)(1 << STDBIT_INDXSRC))
-#define STDMSK_INDXPOL         ((uint16_t)(1 << STDBIT_INDXPOL))
-#define STDMSK_CLKSRC          ((uint16_t)(3 << STDBIT_CLKSRC))
-#define STDMSK_CLKPOL          ((uint16_t)(1 << STDBIT_CLKPOL))
-#define STDMSK_CLKMULT         ((uint16_t)(3 << STDBIT_CLKMULT))
-#define STDMSK_CLKENAB         ((uint16_t)(1 << STDBIT_CLKENAB))
+#define STDMSK_INTSRC          (3 << STDBIT_INTSRC)
+#define STDMSK_LATCHSRC                (3 << STDBIT_LATCHSRC)
+#define STDMSK_LOADSRC         (3 << STDBIT_LOADSRC)
+#define STDMSK_INDXSRC         (1 << STDBIT_INDXSRC)
+#define STDMSK_INDXPOL         (1 << STDBIT_INDXPOL)
+#define STDMSK_CLKSRC          (3 << STDBIT_CLKSRC)
+#define STDMSK_CLKPOL          (1 << STDBIT_CLKPOL)
+#define STDMSK_CLKMULT         (3 << STDBIT_CLKMULT)
+#define STDMSK_CLKENAB         (1 << STDBIT_CLKENAB)
 
 struct bufferDMA {
        dma_addr_t PhysicalBase;
index cb83f6ae48b9630ecd0ec6793f259ed54506d0ae..6fb7d5d220946c4c313e3a74f9e77678cca0b6d6 100644 (file)
@@ -90,29 +90,30 @@ Configuration Options:
  * boards in this way is optional, and completely driver-dependent.
  * Some drivers use arrays such as this, other do not.
  */
+enum skel_boardid {
+       BOARD_SKEL100,
+       BOARD_SKEL200,
+};
+
 struct skel_board {
        const char *name;
-       unsigned int devid;
        int ai_chans;
        int ai_bits;
        int have_dio;
 };
 
 static const struct skel_board skel_boards[] = {
-       {
-        .name = "skel-100",
-        .devid = 0x100,
-        .ai_chans = 16,
-        .ai_bits = 12,
-        .have_dio = 1,
-        },
-       {
-        .name = "skel-200",
-        .devid = 0x200,
-        .ai_chans = 8,
-        .ai_bits = 16,
-        .have_dio = 0,
-        },
+       [BOARD_SKEL100] = {
+               .name           = "skel-100",
+               .ai_chans       = 16,
+               .ai_bits        = 12,
+               .have_dio       = 1,
+       },
+       [BOARD_SKEL200] = {
+               .name           = "skel-200",
+               .ai_chans       = 8,
+               .ai_bits        = 16,
+       },
 };
 
 /* this structure is for data unique to this hardware driver.  If
@@ -394,22 +395,6 @@ static int skel_dio_insn_config(struct comedi_device *dev,
        return insn->n;
 }
 
-static const struct skel_board *skel_find_pci_board(struct pci_dev *pcidev)
-{
-       unsigned int i;
-
-/*
- * This example code assumes all the entries in skel_boards[] are PCI boards
- * and all use the same PCI vendor ID.  If skel_boards[] contains a mixture
- * of PCI and non-PCI boards, this loop should skip over the non-PCI boards.
- */
-       for (i = 0; i < ARRAY_SIZE(skel_boards); i++)
-               if (/* skel_boards[i].bustype == pci_bustype && */
-                   pcidev->device == skel_boards[i].devid)
-                       return &skel_boards[i];
-       return NULL;
-}
-
 /*
  * Handle common part of skel_attach() and skel_auto_attach().
  */
@@ -541,16 +526,13 @@ static int skel_attach(struct comedi_device *dev, struct comedi_devconfig *it)
  * comedi_usb_auto_config(), etc.) to handle devices that can be attached
  * to the Comedi core automatically without the COMEDI_DEVCONFIG ioctl.
  *
- * The context parameter is usually unused, but if the driver called
- * comedi_auto_config() directly instead of the comedi_pci_auto_config()
- * wrapper function, this will be a copy of the context passed to
- * comedi_auto_config().
+ * The context parameter is driver dependent.
  */
 static int skel_auto_attach(struct comedi_device *dev,
-                                     unsigned long context)
+                           unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct skel_board *thisboard;
+       const struct skel_board *thisboard = NULL;
        struct skel_private *devpriv;
        int ret;
 
@@ -558,12 +540,18 @@ static int skel_auto_attach(struct comedi_device *dev,
        if (!IS_ENABLED(CONFIG_COMEDI_PCI_DRIVERS))
                return -EINVAL;
 
-       /* Find a matching board in skel_boards[]. */
-       thisboard = skel_find_pci_board(pcidev);
-       if (!thisboard) {
-               dev_err(dev->class_dev, "BUG! cannot determine board type!\n");
-               return -EINVAL;
-       }
+       /*
+        * In this example, the _auto_attach is for a PCI device.
+        *
+        * The 'context' passed to this function is the id->driver_data
+        * associated with the PCI device found in the id_table during
+        * the modprobe. This 'context' is the index of the entry in
+        * skel_boards[i] that contains the boardinfo for the PCI device.
+        */
+       if (context < ARRAY_SIZE(skel_boards))
+               thisboard = &skel_boards[context];
+       if (!thisboard)
+               return -ENODEV;
 
        /*
         * Point the struct comedi_device to the matching board info
@@ -579,7 +567,7 @@ static int skel_auto_attach(struct comedi_device *dev,
        dev->private = devpriv;
 
        /* Enable the PCI device. */
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
 
@@ -618,7 +606,6 @@ static void skel_detach(struct comedi_device *dev)
 {
        const struct skel_board *thisboard = comedi_board(dev);
        struct skel_private *devpriv = dev->private;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
        if (!thisboard || !devpriv)
                return;
@@ -638,8 +625,7 @@ static void skel_detach(struct comedi_device *dev)
                 * If PCI device enabled by _auto_attach() (or _attach()),
                 * disable it here.
                 */
-               if (pcidev && dev->iobase)
-                       comedi_pci_disable(pcidev);
+               comedi_pci_disable(dev);
        } else {
                /*
                 * ISA board
@@ -689,28 +675,33 @@ static struct comedi_driver skel_driver = {
 
 #ifdef CONFIG_COMEDI_PCI_DRIVERS
 
-/* This is used by modprobe to translate PCI IDs to drivers.  Should
- * only be used for PCI and ISA-PnP devices */
-/* Please add your PCI vendor ID to comedidev.h, and it will be forwarded
- * upstream. */
-#define PCI_VENDOR_ID_SKEL 0xdafe
+static int skel_pci_probe(struct pci_dev *dev,
+                         const struct pci_device_id *id)
+{
+       return comedi_pci_auto_config(dev, &skel_driver, id->driver_data);
+}
+
+/*
+ * Please add your PCI vendor ID to comedidev.h, and it will
+ * be forwarded upstream.
+ */
+#define PCI_VENDOR_ID_SKEL     0xdafe
+
+/*
+ * This is used by modprobe to translate PCI IDs to drivers.
+ * Should only be used for PCI and ISA-PnP devices
+ */
 static DEFINE_PCI_DEVICE_TABLE(skel_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_SKEL, 0x0100) },
-       { PCI_DEVICE(PCI_VENDOR_ID_SKEL, 0x0200) },
+       { PCI_VDEVICE(SKEL, 0x0100), BOARD_SKEL100 },
+       { PCI_VDEVICE(SKEL, 0x0200), BOARD_SKEL200 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, skel_pci_table);
 
-static int skel_pci_probe(struct pci_dev *dev,
-                                          const struct pci_device_id *ent)
-{
-       return comedi_pci_auto_config(dev, &skel_driver);
-}
-
 static struct pci_driver skel_pci_driver = {
-       .name = "dummy",
-       .id_table = skel_pci_table,
-       .probe = &skel_pci_probe,
+       .name           = "dummy",
+       .id_table       = skel_pci_table,
+       .probe          = skel_pci_probe,
        .remove         = comedi_pci_auto_unconfig,
 };
 module_comedi_pci_driver(skel_driver, skel_pci_driver);
index 6aac1f60bc42c1cc927cd2a9930aa1bc356f28cb..148ecfcc5dd5705e1eaa4ea41b7fa45183ab652d 100644 (file)
@@ -56,7 +56,7 @@ sampling rate. If you sample two channels you get 4kHz and so on.
  *       functions firmware upload is by fxload and no longer by comedi (due to
  *       enumeration)
  * 0.97: USB IDs received, adjusted table
- * 0.98: SMP, locking, memroy alloc: moved all usb memory alloc
+ * 0.98: SMP, locking, memory alloc: moved all usb memory alloc
  *       to the usb subsystem and moved all comedi related memory
  *       alloc to comedi.
  *       | kernel | registration | usbdux-usb | usbdux-comedi | comedi |
@@ -250,26 +250,26 @@ struct usbduxsub {
        /* pointer to the usb-device */
        struct usb_device *usbdev;
        /* actual number of in-buffers */
-       int numOfInBuffers;
+       int num_in_buffers;
        /* actual number of out-buffers */
-       int numOfOutBuffers;
+       int num_out_buffers;
        /* ISO-transfer handling: buffers */
-       struct urb **urbIn;
-       struct urb **urbOut;
+       struct urb **urb_in;
+       struct urb **urb_out;
        /* pwm-transfer handling */
-       struct urb *urbPwm;
+       struct urb *urb_pwm;
        /* PWM period */
-       unsigned int pwmPeriod;
+       unsigned int pwm_period;
        /* PWM internal delay for the GPIF in the FX2 */
-       int8_t pwmDelay;
+       int8_t pwn_delay;
        /* size of the PWM buffer which holds the bit pattern */
-       int sizePwmBuf;
+       int size_pwm_buf;
        /* input buffer for the ISO-transfer */
-       int16_t *inBuffer;
+       int16_t *in_buffer;
        /* input buffer for single insn */
-       int16_t *insnBuffer;
+       int16_t *insn_buffer;
        /* output buffer for single DA outputs */
-       int16_t *outBuffer;
+       int16_t *out_buffer;
        /* interface number */
        int ifnum;
        /* interface structure in 2.6 */
@@ -319,17 +319,17 @@ static DEFINE_SEMAPHORE(start_stop_sem);
  * Stops the data acquision
  * It should be safe to call this function from any context
  */
-static int usbduxsub_unlink_InURBs(struct usbduxsub *usbduxsub_tmp)
+static int usbduxsub_unlink_inurbs(struct usbduxsub *usbduxsub_tmp)
 {
        int i = 0;
        int err = 0;
 
-       if (usbduxsub_tmp && usbduxsub_tmp->urbIn) {
-               for (i = 0; i < usbduxsub_tmp->numOfInBuffers; i++) {
-                       if (usbduxsub_tmp->urbIn[i]) {
+       if (usbduxsub_tmp && usbduxsub_tmp->urb_in) {
+               for (i = 0; i < usbduxsub_tmp->num_in_buffers; i++) {
+                       if (usbduxsub_tmp->urb_in[i]) {
                                /* We wait here until all transfers have been
                                 * cancelled. */
-                               usb_kill_urb(usbduxsub_tmp->urbIn[i]);
+                               usb_kill_urb(usbduxsub_tmp->urb_in[i]);
                        }
                        dev_dbg(&usbduxsub_tmp->interface->dev,
                                "comedi: usbdux: unlinked InURB %d, err=%d\n",
@@ -356,7 +356,7 @@ static int usbdux_ai_stop(struct usbduxsub *this_usbduxsub, int do_unlink)
 
        if (do_unlink) {
                /* stop aquistion */
-               ret = usbduxsub_unlink_InURBs(this_usbduxsub);
+               ret = usbduxsub_unlink_inurbs(this_usbduxsub);
        }
 
        this_usbduxsub->ai_cmd_running = 0;
@@ -394,7 +394,7 @@ static int usbdux_ai_cancel(struct comedi_device *dev,
 }
 
 /* analogue IN - interrupt service routine */
-static void usbduxsub_ai_IsocIrq(struct urb *urb)
+static void usbduxsub_ai_isoc_irq(struct urb *urb)
 {
        int i, err, n;
        struct usbduxsub *this_usbduxsub;
@@ -412,7 +412,7 @@ static void usbduxsub_ai_IsocIrq(struct urb *urb)
        switch (urb->status) {
        case 0:
                /* copy the result in the transfer buffer */
-               memcpy(this_usbduxsub->inBuffer,
+               memcpy(this_usbduxsub->in_buffer,
                       urb->transfer_buffer, SIZEINBUF);
                break;
        case -EILSEQ:
@@ -517,11 +517,11 @@ static void usbduxsub_ai_IsocIrq(struct urb *urb)
                if (CR_RANGE(s->async->cmd.chanlist[i]) <= 1) {
                        err = comedi_buf_put
                            (s->async,
-                            le16_to_cpu(this_usbduxsub->inBuffer[i]) ^ 0x800);
+                            le16_to_cpu(this_usbduxsub->in_buffer[i]) ^ 0x800);
                } else {
                        err = comedi_buf_put
                            (s->async,
-                            le16_to_cpu(this_usbduxsub->inBuffer[i]));
+                            le16_to_cpu(this_usbduxsub->in_buffer[i]));
                }
                if (unlikely(err == 0)) {
                        /* buffer overflow */
@@ -534,15 +534,15 @@ static void usbduxsub_ai_IsocIrq(struct urb *urb)
        comedi_event(this_usbduxsub->comedidev, s);
 }
 
-static int usbduxsub_unlink_OutURBs(struct usbduxsub *usbduxsub_tmp)
+static int usbduxsub_unlink_outurbs(struct usbduxsub *usbduxsub_tmp)
 {
        int i = 0;
        int err = 0;
 
-       if (usbduxsub_tmp && usbduxsub_tmp->urbOut) {
-               for (i = 0; i < usbduxsub_tmp->numOfOutBuffers; i++) {
-                       if (usbduxsub_tmp->urbOut[i])
-                               usb_kill_urb(usbduxsub_tmp->urbOut[i]);
+       if (usbduxsub_tmp && usbduxsub_tmp->urb_out) {
+               for (i = 0; i < usbduxsub_tmp->num_out_buffers; i++) {
+                       if (usbduxsub_tmp->urb_out[i])
+                               usb_kill_urb(usbduxsub_tmp->urb_out[i]);
 
                        dev_dbg(&usbduxsub_tmp->interface->dev,
                                "comedi: usbdux: unlinked OutURB %d: res=%d\n",
@@ -564,7 +564,7 @@ static int usbdux_ao_stop(struct usbduxsub *this_usbduxsub, int do_unlink)
        dev_dbg(&this_usbduxsub->interface->dev, "comedi: usbdux_ao_cancel\n");
 
        if (do_unlink)
-               ret = usbduxsub_unlink_OutURBs(this_usbduxsub);
+               ret = usbduxsub_unlink_outurbs(this_usbduxsub);
 
        this_usbduxsub->ao_cmd_running = 0;
 
@@ -593,7 +593,7 @@ static int usbdux_ao_cancel(struct comedi_device *dev,
        return res;
 }
 
-static void usbduxsub_ao_IsocIrq(struct urb *urb)
+static void usbduxsub_ao_isoc_irq(struct urb *urb)
 {
        int i, ret;
        int8_t *datap;
@@ -798,7 +798,7 @@ static int usbduxsub_stop(struct usbduxsub *usbduxsub)
 
 static int usbduxsub_upload(struct usbduxsub *usbduxsub,
                            uint8_t *local_transfer_buffer,
-                           unsigned int startAddr, unsigned int len)
+                           unsigned int start_addr, unsigned int len)
 {
        int errcode;
 
@@ -809,7 +809,7 @@ static int usbduxsub_upload(struct usbduxsub *usbduxsub,
                                  /* bmRequestType */
                                  VENDOR_DIR_OUT,
                                  /* value */
-                                 startAddr,
+                                 start_addr,
                                  /* index */
                                  0x0000,
                                  /* our local safe buffer */
@@ -828,24 +828,24 @@ static int usbduxsub_upload(struct usbduxsub *usbduxsub,
 
 #define FIRMWARE_MAX_LEN 0x2000
 
-static int firmwareUpload(struct usbduxsub *usbduxsub,
-                         const u8 *firmwareBinary, int sizeFirmware)
+static int firmware_upload(struct usbduxsub *usbduxsub,
+                         const u8 *firmware_binary, int size_firmware)
 {
        int ret;
-       uint8_t *fwBuf;
+       uint8_t *fw_buf;
 
-       if (!firmwareBinary)
+       if (!firmware_binary)
                return 0;
 
-       if (sizeFirmware > FIRMWARE_MAX_LEN) {
+       if (size_firmware > FIRMWARE_MAX_LEN) {
                dev_err(&usbduxsub->interface->dev,
                        "usbdux firmware binary it too large for FX2.\n");
                return -ENOMEM;
        }
 
        /* we generate a local buffer for the firmware */
-       fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL);
-       if (!fwBuf) {
+       fw_buf = kmemdup(firmware_binary, size_firmware, GFP_KERNEL);
+       if (!fw_buf) {
                dev_err(&usbduxsub->interface->dev,
                        "comedi_: mem alloc for firmware failed\n");
                return -ENOMEM;
@@ -855,81 +855,81 @@ static int firmwareUpload(struct usbduxsub *usbduxsub,
        if (ret < 0) {
                dev_err(&usbduxsub->interface->dev,
                        "comedi_: can not stop firmware\n");
-               kfree(fwBuf);
+               kfree(fw_buf);
                return ret;
        }
 
-       ret = usbduxsub_upload(usbduxsub, fwBuf, 0, sizeFirmware);
+       ret = usbduxsub_upload(usbduxsub, fw_buf, 0, size_firmware);
        if (ret < 0) {
                dev_err(&usbduxsub->interface->dev,
                        "comedi_: firmware upload failed\n");
-               kfree(fwBuf);
+               kfree(fw_buf);
                return ret;
        }
        ret = usbduxsub_start(usbduxsub);
        if (ret < 0) {
                dev_err(&usbduxsub->interface->dev,
                        "comedi_: can not start firmware\n");
-               kfree(fwBuf);
+               kfree(fw_buf);
                return ret;
        }
-       kfree(fwBuf);
+       kfree(fw_buf);
        return 0;
 }
 
-static int usbduxsub_submit_InURBs(struct usbduxsub *usbduxsub)
+static int usbduxsub_submit_inurbs(struct usbduxsub *usbduxsub)
 {
-       int i, errFlag;
+       int i, err_flag;
 
        if (!usbduxsub)
                return -EFAULT;
 
        /* Submit all URBs and start the transfer on the bus */
-       for (i = 0; i < usbduxsub->numOfInBuffers; i++) {
+       for (i = 0; i < usbduxsub->num_in_buffers; i++) {
                /* in case of a resubmission after an unlink... */
-               usbduxsub->urbIn[i]->interval = usbduxsub->ai_interval;
-               usbduxsub->urbIn[i]->context = usbduxsub->comedidev;
-               usbduxsub->urbIn[i]->dev = usbduxsub->usbdev;
-               usbduxsub->urbIn[i]->status = 0;
-               usbduxsub->urbIn[i]->transfer_flags = URB_ISO_ASAP;
+               usbduxsub->urb_in[i]->interval = usbduxsub->ai_interval;
+               usbduxsub->urb_in[i]->context = usbduxsub->comedidev;
+               usbduxsub->urb_in[i]->dev = usbduxsub->usbdev;
+               usbduxsub->urb_in[i]->status = 0;
+               usbduxsub->urb_in[i]->transfer_flags = URB_ISO_ASAP;
                dev_dbg(&usbduxsub->interface->dev,
                        "comedi%d: submitting in-urb[%d]: %p,%p intv=%d\n",
                        usbduxsub->comedidev->minor, i,
-                       (usbduxsub->urbIn[i]->context),
-                       (usbduxsub->urbIn[i]->dev),
-                       (usbduxsub->urbIn[i]->interval));
-               errFlag = usb_submit_urb(usbduxsub->urbIn[i], GFP_ATOMIC);
-               if (errFlag) {
+                       (usbduxsub->urb_in[i]->context),
+                       (usbduxsub->urb_in[i]->dev),
+                       (usbduxsub->urb_in[i]->interval));
+               err_flag = usb_submit_urb(usbduxsub->urb_in[i], GFP_ATOMIC);
+               if (err_flag) {
                        dev_err(&usbduxsub->interface->dev,
                                "comedi_: ai: usb_submit_urb(%d) error %d\n",
-                               i, errFlag);
-                       return errFlag;
+                               i, err_flag);
+                       return err_flag;
                }
        }
        return 0;
 }
 
-static int usbduxsub_submit_OutURBs(struct usbduxsub *usbduxsub)
+static int usbduxsub_submit_outurbs(struct usbduxsub *usbduxsub)
 {
-       int i, errFlag;
+       int i, err_flag;
 
        if (!usbduxsub)
                return -EFAULT;
 
-       for (i = 0; i < usbduxsub->numOfOutBuffers; i++) {
+       for (i = 0; i < usbduxsub->num_out_buffers; i++) {
                dev_dbg(&usbduxsub->interface->dev,
                        "comedi_: submitting out-urb[%d]\n", i);
                /* in case of a resubmission after an unlink... */
-               usbduxsub->urbOut[i]->context = usbduxsub->comedidev;
-               usbduxsub->urbOut[i]->dev = usbduxsub->usbdev;
-               usbduxsub->urbOut[i]->status = 0;
-               usbduxsub->urbOut[i]->transfer_flags = URB_ISO_ASAP;
-               errFlag = usb_submit_urb(usbduxsub->urbOut[i], GFP_ATOMIC);
-               if (errFlag) {
+               usbduxsub->urb_out[i]->context = usbduxsub->comedidev;
+               usbduxsub->urb_out[i]->dev = usbduxsub->usbdev;
+               usbduxsub->urb_out[i]->status = 0;
+               usbduxsub->urb_out[i]->transfer_flags = URB_ISO_ASAP;
+               err_flag = usb_submit_urb(usbduxsub->urb_out[i], GFP_ATOMIC);
+               if (err_flag) {
                        dev_err(&usbduxsub->interface->dev,
                                "comedi_: ao: usb_submit_urb(%d) error %d\n",
-                               i, errFlag);
-                       return errFlag;
+                               i, err_flag);
+                       return err_flag;
                }
        }
        return 0;
@@ -940,7 +940,7 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev,
 {
        struct usbduxsub *this_usbduxsub = dev->private;
        int err = 0, i;
-       unsigned int tmpTimer;
+       unsigned int tmp_timer;
 
        if (!(this_usbduxsub->probed))
                return -ENODEV;
@@ -990,7 +990,7 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev,
                                                         1000000 / 8 * i);
                        /* now calc the real sampling rate with all the
                         * rounding errors */
-                       tmpTimer =
+                       tmp_timer =
                            ((unsigned int)(cmd->scan_begin_arg / 125000)) *
                            125000;
                } else {
@@ -1001,11 +1001,11 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev,
                        /*
                         * calc the real sampling rate with the rounding errors
                         */
-                       tmpTimer = ((unsigned int)(cmd->scan_begin_arg /
+                       tmp_timer = ((unsigned int)(cmd->scan_begin_arg /
                                                   1000000)) * 1000000;
                }
                err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg,
-                                               tmpTimer);
+                                               tmp_timer);
        }
 
        err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
@@ -1081,7 +1081,7 @@ static int receive_dux_commands(struct usbduxsub *this_usbduxsub, int command)
                result = usb_bulk_msg(this_usbduxsub->usbdev,
                                      usb_rcvbulkpipe(this_usbduxsub->usbdev,
                                                      COMMAND_IN_EP),
-                                     this_usbduxsub->insnBuffer, SIZEINSNBUF,
+                                     this_usbduxsub->insn_buffer, SIZEINSNBUF,
                                      &nrec, BULK_TIMEOUT);
                if (result < 0) {
                        dev_err(&this_usbduxsub->interface->dev, "comedi%d: "
@@ -1089,7 +1089,7 @@ static int receive_dux_commands(struct usbduxsub *this_usbduxsub, int command)
                                "\n", this_usbduxsub->comedidev->minor, result);
                        return result;
                }
-               if (le16_to_cpu(this_usbduxsub->insnBuffer[0]) == command)
+               if (le16_to_cpu(this_usbduxsub->insn_buffer[0]) == command)
                        return result;
        }
        /* this is only reached if the data has been requested a couple of
@@ -1097,7 +1097,7 @@ static int receive_dux_commands(struct usbduxsub *this_usbduxsub, int command)
        dev_err(&this_usbduxsub->interface->dev, "comedi%d: insn: "
                "wrong data returned from firmware: want cmd %d, got cmd %d.\n",
                this_usbduxsub->comedidev->minor, command,
-               le16_to_cpu(this_usbduxsub->insnBuffer[0]));
+               le16_to_cpu(this_usbduxsub->insn_buffer[0]));
        return -EFAULT;
 }
 
@@ -1126,7 +1126,7 @@ static int usbdux_ai_inttrig(struct comedi_device *dev,
        }
        if (!(this_usbduxsub->ai_cmd_running)) {
                this_usbduxsub->ai_cmd_running = 1;
-               ret = usbduxsub_submit_InURBs(this_usbduxsub);
+               ret = usbduxsub_submit_inurbs(this_usbduxsub);
                if (ret < 0) {
                        dev_err(&this_usbduxsub->interface->dev,
                                "comedi%d: usbdux_ai_inttrig: "
@@ -1243,7 +1243,7 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        if (cmd->start_src == TRIG_NOW) {
                /* enable this acquisition operation */
                this_usbduxsub->ai_cmd_running = 1;
-               ret = usbduxsub_submit_InURBs(this_usbduxsub);
+               ret = usbduxsub_submit_inurbs(this_usbduxsub);
                if (ret < 0) {
                        this_usbduxsub->ai_cmd_running = 0;
                        /* fixme: unlink here?? */
@@ -1311,7 +1311,7 @@ static int usbdux_ai_insn_read(struct comedi_device *dev,
                        up(&this_usbduxsub->sem);
                        return 0;
                }
-               one = le16_to_cpu(this_usbduxsub->insnBuffer[1]);
+               one = le16_to_cpu(this_usbduxsub->insn_buffer[1]);
                if (CR_RANGE(insn->chanspec) <= 1)
                        one = one ^ 0x800;
 
@@ -1341,7 +1341,7 @@ static int usbdux_ao_insn_read(struct comedi_device *dev,
                return -ENODEV;
        }
        for (i = 0; i < insn->n; i++)
-               data[i] = this_usbduxsub->outBuffer[chan];
+               data[i] = this_usbduxsub->out_buffer[chan];
 
        up(&this_usbduxsub->sem);
        return i;
@@ -1384,7 +1384,7 @@ static int usbdux_ao_insn_write(struct comedi_device *dev,
                /* one 16 bit value */
                *((int16_t *) (this_usbduxsub->dux_commands + 2)) =
                    cpu_to_le16(data[i]);
-               this_usbduxsub->outBuffer[chan] = data[i];
+               this_usbduxsub->out_buffer[chan] = data[i];
                /* channel number */
                this_usbduxsub->dux_commands[4] = (chan << 6);
                err = send_dux_commands(this_usbduxsub, SENDDACOMMANDS);
@@ -1421,7 +1421,7 @@ static int usbdux_ao_inttrig(struct comedi_device *dev,
        }
        if (!(this_usbduxsub->ao_cmd_running)) {
                this_usbduxsub->ao_cmd_running = 1;
-               ret = usbduxsub_submit_OutURBs(this_usbduxsub);
+               ret = usbduxsub_submit_outurbs(this_usbduxsub);
                if (ret < 0) {
                        dev_err(&this_usbduxsub->interface->dev,
                                "comedi%d: usbdux_ao_inttrig: submitURB: "
@@ -1616,7 +1616,7 @@ static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        if (cmd->start_src == TRIG_NOW) {
                /* enable this acquisition operation */
                this_usbduxsub->ao_cmd_running = 1;
-               ret = usbduxsub_submit_OutURBs(this_usbduxsub);
+               ret = usbduxsub_submit_outurbs(this_usbduxsub);
                if (ret < 0) {
                        this_usbduxsub->ao_cmd_running = 0;
                        /* fixme: unlink here?? */
@@ -1704,7 +1704,7 @@ static int usbdux_dio_insn_bits(struct comedi_device *dev,
                return err;
        }
 
-       data[1] = le16_to_cpu(this_usbduxsub->insnBuffer[1]);
+       data[1] = le16_to_cpu(this_usbduxsub->insn_buffer[1]);
        up(&this_usbduxsub->sem);
        return insn->n;
 }
@@ -1740,7 +1740,7 @@ static int usbdux_counter_read(struct comedi_device *dev,
                return err;
        }
 
-       data[0] = le16_to_cpu(this_usbduxsub->insnBuffer[chan + 1]);
+       data[0] = le16_to_cpu(this_usbduxsub->insn_buffer[chan + 1]);
        up(&this_usbduxsub->sem);
        return 1;
 }
@@ -1787,13 +1787,13 @@ static int usbdux_counter_config(struct comedi_device *dev,
 /***********************************/
 /* PWM */
 
-static int usbduxsub_unlink_PwmURBs(struct usbduxsub *usbduxsub_tmp)
+static int usbduxsub_unlink_pwm_urbs(struct usbduxsub *usbduxsub_tmp)
 {
        int err = 0;
 
-       if (usbduxsub_tmp && usbduxsub_tmp->urbPwm) {
-               if (usbduxsub_tmp->urbPwm)
-                       usb_kill_urb(usbduxsub_tmp->urbPwm);
+       if (usbduxsub_tmp && usbduxsub_tmp->urb_pwm) {
+               if (usbduxsub_tmp->urb_pwm)
+                       usb_kill_urb(usbduxsub_tmp->urb_pwm);
                dev_dbg(&usbduxsub_tmp->interface->dev,
                        "comedi: unlinked PwmURB: res=%d\n", err);
        }
@@ -1812,7 +1812,7 @@ static int usbdux_pwm_stop(struct usbduxsub *this_usbduxsub, int do_unlink)
 
        dev_dbg(&this_usbduxsub->interface->dev, "comedi: %s\n", __func__);
        if (do_unlink)
-               ret = usbduxsub_unlink_PwmURBs(this_usbduxsub);
+               ret = usbduxsub_unlink_pwm_urbs(this_usbduxsub);
 
        this_usbduxsub->pwm_cmd_running = 0;
 
@@ -1885,7 +1885,7 @@ static void usbduxsub_pwm_irq(struct urb *urb)
        if (!(this_usbduxsub->pwm_cmd_running))
                return;
 
-       urb->transfer_buffer_length = this_usbduxsub->sizePwmBuf;
+       urb->transfer_buffer_length = this_usbduxsub->size_pwm_buf;
        urb->dev = this_usbduxsub->usbdev;
        urb->status = 0;
        if (this_usbduxsub->pwm_cmd_running) {
@@ -1905,9 +1905,9 @@ static void usbduxsub_pwm_irq(struct urb *urb)
        }
 }
 
-static int usbduxsub_submit_PwmURBs(struct usbduxsub *usbduxsub)
+static int usbduxsub_submit_pwm_urbs(struct usbduxsub *usbduxsub)
 {
-       int errFlag;
+       int err_flag;
 
        if (!usbduxsub)
                return -EFAULT;
@@ -1915,19 +1915,19 @@ static int usbduxsub_submit_PwmURBs(struct usbduxsub *usbduxsub)
        dev_dbg(&usbduxsub->interface->dev, "comedi_: submitting pwm-urb\n");
 
        /* in case of a resubmission after an unlink... */
-       usb_fill_bulk_urb(usbduxsub->urbPwm,
+       usb_fill_bulk_urb(usbduxsub->urb_pwm,
                          usbduxsub->usbdev,
                          usb_sndbulkpipe(usbduxsub->usbdev, PWM_EP),
-                         usbduxsub->urbPwm->transfer_buffer,
-                         usbduxsub->sizePwmBuf, usbduxsub_pwm_irq,
+                         usbduxsub->urb_pwm->transfer_buffer,
+                         usbduxsub->size_pwm_buf, usbduxsub_pwm_irq,
                          usbduxsub->comedidev);
 
-       errFlag = usb_submit_urb(usbduxsub->urbPwm, GFP_ATOMIC);
-       if (errFlag) {
+       err_flag = usb_submit_urb(usbduxsub->urb_pwm, GFP_ATOMIC);
+       if (err_flag) {
                dev_err(&usbduxsub->interface->dev,
                        "comedi_: usbdux: pwm: usb_submit_urb error %d\n",
-                       errFlag);
-               return errFlag;
+                       err_flag);
+               return err_flag;
        }
        return 0;
 }
@@ -1952,8 +1952,8 @@ static int usbdux_pwm_period(struct comedi_device *dev,
                        return -EAGAIN;
                }
        }
-       this_usbduxsub->pwmDelay = fx2delay;
-       this_usbduxsub->pwmPeriod = period;
+       this_usbduxsub->pwn_delay = fx2delay;
+       this_usbduxsub->pwm_period = period;
        dev_dbg(&this_usbduxsub->interface->dev, "%s: frequ=%d, period=%d\n",
                __func__, period, fx2delay);
        return 0;
@@ -1974,17 +1974,17 @@ static int usbdux_pwm_start(struct comedi_device *dev,
                return 0;
        }
 
-       this_usbduxsub->dux_commands[1] = ((int8_t) this_usbduxsub->pwmDelay);
+       this_usbduxsub->dux_commands[1] = ((int8_t) this_usbduxsub->pwn_delay);
        ret = send_dux_commands(this_usbduxsub, SENDPWMON);
        if (ret < 0)
                return ret;
 
        /* initialise the buffer */
-       for (i = 0; i < this_usbduxsub->sizePwmBuf; i++)
-               ((char *)(this_usbduxsub->urbPwm->transfer_buffer))[i] = 0;
+       for (i = 0; i < this_usbduxsub->size_pwm_buf; i++)
+               ((char *)(this_usbduxsub->urb_pwm->transfer_buffer))[i] = 0;
 
        this_usbduxsub->pwm_cmd_running = 1;
-       ret = usbduxsub_submit_PwmURBs(this_usbduxsub);
+       ret = usbduxsub_submit_pwm_urbs(this_usbduxsub);
        if (ret < 0) {
                this_usbduxsub->pwm_cmd_running = 0;
                return ret;
@@ -1999,7 +1999,7 @@ static int usbdux_pwm_pattern(struct comedi_device *dev,
 {
        struct usbduxsub *this_usbduxsub = dev->private;
        int i, szbuf;
-       char *pBuf;
+       char *p_buf;
        char pwm_mask;
        char sgn_mask;
        char c;
@@ -2013,10 +2013,10 @@ static int usbdux_pwm_pattern(struct comedi_device *dev,
        sgn_mask = (16 << channel);
        /* this is the buffer which will be filled with the with bit */
        /* pattern for one period */
-       szbuf = this_usbduxsub->sizePwmBuf;
-       pBuf = (char *)(this_usbduxsub->urbPwm->transfer_buffer);
+       szbuf = this_usbduxsub->size_pwm_buf;
+       p_buf = (char *)(this_usbduxsub->urb_pwm->transfer_buffer);
        for (i = 0; i < szbuf; i++) {
-               c = *pBuf;
+               c = *p_buf;
                /* reset bits */
                c = c & (~pwm_mask);
                /* set the bit as long as the index is lower than the value */
@@ -2030,7 +2030,7 @@ static int usbdux_pwm_pattern(struct comedi_device *dev,
                        /* negative value */
                        c = c | sgn_mask;
                }
-               *(pBuf++) = c;
+               *(p_buf++) = c;
        }
        return 1;
 }
@@ -2102,7 +2102,7 @@ static int usbdux_pwm_config(struct comedi_device *dev,
                        "comedi%d: %s: setting period\n", dev->minor, __func__);
                return usbdux_pwm_period(dev, s, data[1]);
        case INSN_CONFIG_PWM_GET_PERIOD:
-               data[1] = this_usbduxsub->pwmPeriod;
+               data[1] = this_usbduxsub->pwm_period;
                return 0;
        case INSN_CONFIG_PWM_SET_H_BRIDGE:
                /* value in the first byte and the sign in the second for a
@@ -2138,55 +2138,55 @@ static void tidy_up(struct usbduxsub *usbduxsub_tmp)
 
        usbduxsub_tmp->probed = 0;
 
-       if (usbduxsub_tmp->urbIn) {
+       if (usbduxsub_tmp->urb_in) {
                if (usbduxsub_tmp->ai_cmd_running) {
                        usbduxsub_tmp->ai_cmd_running = 0;
-                       usbduxsub_unlink_InURBs(usbduxsub_tmp);
+                       usbduxsub_unlink_inurbs(usbduxsub_tmp);
                }
-               for (i = 0; i < usbduxsub_tmp->numOfInBuffers; i++) {
-                       kfree(usbduxsub_tmp->urbIn[i]->transfer_buffer);
-                       usbduxsub_tmp->urbIn[i]->transfer_buffer = NULL;
-                       usb_kill_urb(usbduxsub_tmp->urbIn[i]);
-                       usb_free_urb(usbduxsub_tmp->urbIn[i]);
-                       usbduxsub_tmp->urbIn[i] = NULL;
+               for (i = 0; i < usbduxsub_tmp->num_in_buffers; i++) {
+                       kfree(usbduxsub_tmp->urb_in[i]->transfer_buffer);
+                       usbduxsub_tmp->urb_in[i]->transfer_buffer = NULL;
+                       usb_kill_urb(usbduxsub_tmp->urb_in[i]);
+                       usb_free_urb(usbduxsub_tmp->urb_in[i]);
+                       usbduxsub_tmp->urb_in[i] = NULL;
                }
-               kfree(usbduxsub_tmp->urbIn);
-               usbduxsub_tmp->urbIn = NULL;
+               kfree(usbduxsub_tmp->urb_in);
+               usbduxsub_tmp->urb_in = NULL;
        }
-       if (usbduxsub_tmp->urbOut) {
+       if (usbduxsub_tmp->urb_out) {
                if (usbduxsub_tmp->ao_cmd_running) {
                        usbduxsub_tmp->ao_cmd_running = 0;
-                       usbduxsub_unlink_OutURBs(usbduxsub_tmp);
+                       usbduxsub_unlink_outurbs(usbduxsub_tmp);
                }
-               for (i = 0; i < usbduxsub_tmp->numOfOutBuffers; i++) {
-                       kfree(usbduxsub_tmp->urbOut[i]->transfer_buffer);
-                       usbduxsub_tmp->urbOut[i]->transfer_buffer = NULL;
-                       if (usbduxsub_tmp->urbOut[i]) {
-                               usb_kill_urb(usbduxsub_tmp->urbOut[i]);
-                               usb_free_urb(usbduxsub_tmp->urbOut[i]);
-                               usbduxsub_tmp->urbOut[i] = NULL;
+               for (i = 0; i < usbduxsub_tmp->num_out_buffers; i++) {
+                       kfree(usbduxsub_tmp->urb_out[i]->transfer_buffer);
+                       usbduxsub_tmp->urb_out[i]->transfer_buffer = NULL;
+                       if (usbduxsub_tmp->urb_out[i]) {
+                               usb_kill_urb(usbduxsub_tmp->urb_out[i]);
+                               usb_free_urb(usbduxsub_tmp->urb_out[i]);
+                               usbduxsub_tmp->urb_out[i] = NULL;
                        }
                }
-               kfree(usbduxsub_tmp->urbOut);
-               usbduxsub_tmp->urbOut = NULL;
+               kfree(usbduxsub_tmp->urb_out);
+               usbduxsub_tmp->urb_out = NULL;
        }
-       if (usbduxsub_tmp->urbPwm) {
+       if (usbduxsub_tmp->urb_pwm) {
                if (usbduxsub_tmp->pwm_cmd_running) {
                        usbduxsub_tmp->pwm_cmd_running = 0;
-                       usbduxsub_unlink_PwmURBs(usbduxsub_tmp);
+                       usbduxsub_unlink_pwm_urbs(usbduxsub_tmp);
                }
-               kfree(usbduxsub_tmp->urbPwm->transfer_buffer);
-               usbduxsub_tmp->urbPwm->transfer_buffer = NULL;
-               usb_kill_urb(usbduxsub_tmp->urbPwm);
-               usb_free_urb(usbduxsub_tmp->urbPwm);
-               usbduxsub_tmp->urbPwm = NULL;
-       }
-       kfree(usbduxsub_tmp->inBuffer);
-       usbduxsub_tmp->inBuffer = NULL;
-       kfree(usbduxsub_tmp->insnBuffer);
-       usbduxsub_tmp->insnBuffer = NULL;
-       kfree(usbduxsub_tmp->outBuffer);
-       usbduxsub_tmp->outBuffer = NULL;
+               kfree(usbduxsub_tmp->urb_pwm->transfer_buffer);
+               usbduxsub_tmp->urb_pwm->transfer_buffer = NULL;
+               usb_kill_urb(usbduxsub_tmp->urb_pwm);
+               usb_free_urb(usbduxsub_tmp->urb_pwm);
+               usbduxsub_tmp->urb_pwm = NULL;
+       }
+       kfree(usbduxsub_tmp->in_buffer);
+       usbduxsub_tmp->in_buffer = NULL;
+       kfree(usbduxsub_tmp->insn_buffer);
+       usbduxsub_tmp->insn_buffer = NULL;
+       kfree(usbduxsub_tmp->out_buffer);
+       usbduxsub_tmp->out_buffer = NULL;
        kfree(usbduxsub_tmp->dac_commands);
        usbduxsub_tmp->dac_commands = NULL;
        kfree(usbduxsub_tmp->dux_commands);
@@ -2309,7 +2309,7 @@ static int usbdux_attach_common(struct comedi_device *dev,
                s->subdev_flags = SDF_WRITABLE | SDF_PWM_HBRIDGE;
                s->n_chan = 8;
                /* this defines the max duty cycle resolution */
-               s->maxdata = udev->sizePwmBuf;
+               s->maxdata = udev->size_pwm_buf;
                s->insn_write = usbdux_pwm_write;
                s->insn_read = usbdux_pwm_read;
                s->insn_config = usbdux_pwm_config;
@@ -2388,7 +2388,7 @@ static void usbdux_firmware_request_complete_handler(const struct firmware *fw,
         * we need to upload the firmware here because fw will be
         * freed once we've left this function
         */
-       ret = firmwareUpload(usbduxsub_tmp, fw->data, fw->size);
+       ret = firmware_upload(usbduxsub_tmp, fw->data, fw->size);
 
        if (ret) {
                dev_err(&uinterf->dev,
@@ -2464,22 +2464,22 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
                return -ENOMEM;
        }
        /* create space for the in buffer and set it to zero */
-       usbduxsub[index].inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL);
-       if (!(usbduxsub[index].inBuffer)) {
+       usbduxsub[index].in_buffer = kzalloc(SIZEINBUF, GFP_KERNEL);
+       if (!(usbduxsub[index].in_buffer)) {
                tidy_up(&(usbduxsub[index]));
                up(&start_stop_sem);
                return -ENOMEM;
        }
        /* create space of the instruction buffer */
-       usbduxsub[index].insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL);
-       if (!(usbduxsub[index].insnBuffer)) {
+       usbduxsub[index].insn_buffer = kzalloc(SIZEINSNBUF, GFP_KERNEL);
+       if (!(usbduxsub[index].insn_buffer)) {
                tidy_up(&(usbduxsub[index]));
                up(&start_stop_sem);
                return -ENOMEM;
        }
        /* create space for the outbuffer */
-       usbduxsub[index].outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL);
-       if (!(usbduxsub[index].outBuffer)) {
+       usbduxsub[index].out_buffer = kzalloc(SIZEOUTBUF, GFP_KERNEL);
+       if (!(usbduxsub[index].out_buffer)) {
                tidy_up(&(usbduxsub[index]));
                up(&start_stop_sem);
                return -ENOMEM;
@@ -2496,124 +2496,124 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
                return -ENODEV;
        }
        if (usbduxsub[index].high_speed)
-               usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSHIGH;
+               usbduxsub[index].num_in_buffers = NUMOFINBUFFERSHIGH;
        else
-               usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSFULL;
+               usbduxsub[index].num_in_buffers = NUMOFINBUFFERSFULL;
 
-       usbduxsub[index].urbIn =
-               kcalloc(usbduxsub[index].numOfInBuffers, sizeof(struct urb *),
+       usbduxsub[index].urb_in =
+               kcalloc(usbduxsub[index].num_in_buffers, sizeof(struct urb *),
                        GFP_KERNEL);
-       if (!(usbduxsub[index].urbIn)) {
+       if (!(usbduxsub[index].urb_in)) {
                tidy_up(&(usbduxsub[index]));
                up(&start_stop_sem);
                return -ENOMEM;
        }
-       for (i = 0; i < usbduxsub[index].numOfInBuffers; i++) {
+       for (i = 0; i < usbduxsub[index].num_in_buffers; i++) {
                /* one frame: 1ms */
-               usbduxsub[index].urbIn[i] = usb_alloc_urb(1, GFP_KERNEL);
-               if (usbduxsub[index].urbIn[i] == NULL) {
+               usbduxsub[index].urb_in[i] = usb_alloc_urb(1, GFP_KERNEL);
+               if (usbduxsub[index].urb_in[i] == NULL) {
                        dev_err(dev, "comedi_: usbdux%d: "
                                "Could not alloc. urb(%d)\n", index, i);
                        tidy_up(&(usbduxsub[index]));
                        up(&start_stop_sem);
                        return -ENOMEM;
                }
-               usbduxsub[index].urbIn[i]->dev = usbduxsub[index].usbdev;
+               usbduxsub[index].urb_in[i]->dev = usbduxsub[index].usbdev;
                /* will be filled later with a pointer to the comedi-device */
                /* and ONLY then the urb should be submitted */
-               usbduxsub[index].urbIn[i]->context = NULL;
-               usbduxsub[index].urbIn[i]->pipe =
+               usbduxsub[index].urb_in[i]->context = NULL;
+               usbduxsub[index].urb_in[i]->pipe =
                    usb_rcvisocpipe(usbduxsub[index].usbdev, ISOINEP);
-               usbduxsub[index].urbIn[i]->transfer_flags = URB_ISO_ASAP;
-               usbduxsub[index].urbIn[i]->transfer_buffer =
+               usbduxsub[index].urb_in[i]->transfer_flags = URB_ISO_ASAP;
+               usbduxsub[index].urb_in[i]->transfer_buffer =
                    kzalloc(SIZEINBUF, GFP_KERNEL);
-               if (!(usbduxsub[index].urbIn[i]->transfer_buffer)) {
+               if (!(usbduxsub[index].urb_in[i]->transfer_buffer)) {
                        tidy_up(&(usbduxsub[index]));
                        up(&start_stop_sem);
                        return -ENOMEM;
                }
-               usbduxsub[index].urbIn[i]->complete = usbduxsub_ai_IsocIrq;
-               usbduxsub[index].urbIn[i]->number_of_packets = 1;
-               usbduxsub[index].urbIn[i]->transfer_buffer_length = SIZEINBUF;
-               usbduxsub[index].urbIn[i]->iso_frame_desc[0].offset = 0;
-               usbduxsub[index].urbIn[i]->iso_frame_desc[0].length = SIZEINBUF;
+               usbduxsub[index].urb_in[i]->complete = usbduxsub_ai_isoc_irq;
+               usbduxsub[index].urb_in[i]->number_of_packets = 1;
+               usbduxsub[index].urb_in[i]->transfer_buffer_length = SIZEINBUF;
+               usbduxsub[index].urb_in[i]->iso_frame_desc[0].offset = 0;
+               usbduxsub[index].urb_in[i]->iso_frame_desc[0].length = SIZEINBUF;
        }
 
        /* out */
        if (usbduxsub[index].high_speed)
-               usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSHIGH;
+               usbduxsub[index].num_out_buffers = NUMOFOUTBUFFERSHIGH;
        else
-               usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSFULL;
+               usbduxsub[index].num_out_buffers = NUMOFOUTBUFFERSFULL;
 
-       usbduxsub[index].urbOut =
-               kcalloc(usbduxsub[index].numOfOutBuffers, sizeof(struct urb *),
+       usbduxsub[index].urb_out =
+               kcalloc(usbduxsub[index].num_out_buffers, sizeof(struct urb *),
                        GFP_KERNEL);
-       if (!(usbduxsub[index].urbOut)) {
+       if (!(usbduxsub[index].urb_out)) {
                tidy_up(&(usbduxsub[index]));
                up(&start_stop_sem);
                return -ENOMEM;
        }
-       for (i = 0; i < usbduxsub[index].numOfOutBuffers; i++) {
+       for (i = 0; i < usbduxsub[index].num_out_buffers; i++) {
                /* one frame: 1ms */
-               usbduxsub[index].urbOut[i] = usb_alloc_urb(1, GFP_KERNEL);
-               if (usbduxsub[index].urbOut[i] == NULL) {
+               usbduxsub[index].urb_out[i] = usb_alloc_urb(1, GFP_KERNEL);
+               if (usbduxsub[index].urb_out[i] == NULL) {
                        dev_err(dev, "comedi_: usbdux%d: "
                                "Could not alloc. urb(%d)\n", index, i);
                        tidy_up(&(usbduxsub[index]));
                        up(&start_stop_sem);
                        return -ENOMEM;
                }
-               usbduxsub[index].urbOut[i]->dev = usbduxsub[index].usbdev;
+               usbduxsub[index].urb_out[i]->dev = usbduxsub[index].usbdev;
                /* will be filled later with a pointer to the comedi-device */
                /* and ONLY then the urb should be submitted */
-               usbduxsub[index].urbOut[i]->context = NULL;
-               usbduxsub[index].urbOut[i]->pipe =
+               usbduxsub[index].urb_out[i]->context = NULL;
+               usbduxsub[index].urb_out[i]->pipe =
                    usb_sndisocpipe(usbduxsub[index].usbdev, ISOOUTEP);
-               usbduxsub[index].urbOut[i]->transfer_flags = URB_ISO_ASAP;
-               usbduxsub[index].urbOut[i]->transfer_buffer =
+               usbduxsub[index].urb_out[i]->transfer_flags = URB_ISO_ASAP;
+               usbduxsub[index].urb_out[i]->transfer_buffer =
                    kzalloc(SIZEOUTBUF, GFP_KERNEL);
-               if (!(usbduxsub[index].urbOut[i]->transfer_buffer)) {
+               if (!(usbduxsub[index].urb_out[i]->transfer_buffer)) {
                        tidy_up(&(usbduxsub[index]));
                        up(&start_stop_sem);
                        return -ENOMEM;
                }
-               usbduxsub[index].urbOut[i]->complete = usbduxsub_ao_IsocIrq;
-               usbduxsub[index].urbOut[i]->number_of_packets = 1;
-               usbduxsub[index].urbOut[i]->transfer_buffer_length = SIZEOUTBUF;
-               usbduxsub[index].urbOut[i]->iso_frame_desc[0].offset = 0;
-               usbduxsub[index].urbOut[i]->iso_frame_desc[0].length =
+               usbduxsub[index].urb_out[i]->complete = usbduxsub_ao_isoc_irq;
+               usbduxsub[index].urb_out[i]->number_of_packets = 1;
+               usbduxsub[index].urb_out[i]->transfer_buffer_length = SIZEOUTBUF;
+               usbduxsub[index].urb_out[i]->iso_frame_desc[0].offset = 0;
+               usbduxsub[index].urb_out[i]->iso_frame_desc[0].length =
                    SIZEOUTBUF;
                if (usbduxsub[index].high_speed) {
                        /* uframes */
-                       usbduxsub[index].urbOut[i]->interval = 8;
+                       usbduxsub[index].urb_out[i]->interval = 8;
                } else {
                        /* frames */
-                       usbduxsub[index].urbOut[i]->interval = 1;
+                       usbduxsub[index].urb_out[i]->interval = 1;
                }
        }
 
        /* pwm */
        if (usbduxsub[index].high_speed) {
                /* max bulk ep size in high speed */
-               usbduxsub[index].sizePwmBuf = 512;
-               usbduxsub[index].urbPwm = usb_alloc_urb(0, GFP_KERNEL);
-               if (usbduxsub[index].urbPwm == NULL) {
+               usbduxsub[index].size_pwm_buf = 512;
+               usbduxsub[index].urb_pwm = usb_alloc_urb(0, GFP_KERNEL);
+               if (usbduxsub[index].urb_pwm == NULL) {
                        dev_err(dev, "comedi_: usbdux%d: "
                                "Could not alloc. pwm urb\n", index);
                        tidy_up(&(usbduxsub[index]));
                        up(&start_stop_sem);
                        return -ENOMEM;
                }
-               usbduxsub[index].urbPwm->transfer_buffer =
-                   kzalloc(usbduxsub[index].sizePwmBuf, GFP_KERNEL);
-               if (!(usbduxsub[index].urbPwm->transfer_buffer)) {
+               usbduxsub[index].urb_pwm->transfer_buffer =
+                   kzalloc(usbduxsub[index].size_pwm_buf, GFP_KERNEL);
+               if (!(usbduxsub[index].urb_pwm->transfer_buffer)) {
                        tidy_up(&(usbduxsub[index]));
                        up(&start_stop_sem);
                        return -ENOMEM;
                }
        } else {
-               usbduxsub[index].urbPwm = NULL;
-               usbduxsub[index].sizePwmBuf = 0;
+               usbduxsub[index].urb_pwm = NULL;
+               usbduxsub[index].size_pwm_buf = 0;
        }
 
        usbduxsub[index].ai_cmd_running = 0;
index a728c8fc32a270e4a8963dc0eca3e14799fd6602..656135ef3972b577edf73d031b23609292d66a55 100644 (file)
@@ -1376,7 +1376,7 @@ static int usbdux_getstatusinfo(struct comedi_device *dev, int chan)
 
        /* 32 bits big endian from the A/D converter */
        one = be32_to_cpu(*((int32_t *)((this_usbduxsub->insnBuffer)+1)));
-       /* mask out the staus byte */
+       /* mask out the status byte */
        one = one & 0x00ffffff;
        one = one ^ 0x00800000;
 
index f3f4a9c9c67a9b2e5c494582a1702311f328d367..01179e46f47d8db9136793e5d96de30f7a80154d 100644 (file)
@@ -1,10 +1,10 @@
 /*****************************************************************************
 
-            (c) Cambridge Silicon Radio Limited 2010
-            All rights reserved and confidential information of CSR
+       (c) Cambridge Silicon Radio Limited 2010
+       All rights reserved and confidential information of CSR
 
-            Refer to LICENSE.txt included with this source for details
-            on the license terms.
+       Refer to LICENSE.txt included with this source for details
+       on the license terms.
 
 *****************************************************************************/
 
index fde1508c1eae33e7bbdd6b1df1a342e82c922163..fc5c5aa6a3c49b17d5b6b7d60623fef32b572b53 100644 (file)
@@ -70,7 +70,7 @@ extern CsrWifiFsmContext* CsrWifiFsmInit(void *applicationContext, void *externa
  *   This function is used to free any dynamic resources allocated for the
  *   given context by CsrWifiFsmInit().
  *   The FSM's reset function is called to cleanup any fsm specific memory
- *   The reset funtion does NOT need to free the fsm data pointer as
+ *   The reset function does NOT need to free the fsm data pointer as
  *   CsrWifiFsmShutdown() will do it.
  *   the FSM's init function is call again to reinitialise the FSM context.
  *   CsrWifiFsmReset() should NEVER be called when CsrWifiFsmExecute() is running.
@@ -91,7 +91,7 @@ extern void CsrWifiFsmReset(CsrWifiFsmContext *context);
  *   given context by CsrWifiFsmInit(), prior to complete termination of
  *   the program.
  *   The FSM's reset function is called to cleanup any fsm specific memory.
- *   The reset funtion does NOT need to free the fsm data pointer as
+ *   The reset function does NOT need to free the fsm data pointer as
  *   CsrWifiFsmShutdown() will do it.
  *   CsrWifiFsmShutdown() should NEVER be called when CsrWifiFsmExecute() is running.
  *
@@ -203,7 +203,7 @@ extern void CsrWifiFsmFastForward(CsrWifiFsmContext *context, u16 ms);
  *   shift the current time of day by ms amount
  *
  * @par Description
- *   usefull to speed up tests where time needs to pass
+ *   useful to speed up tests where time needs to pass
  *
  * @param[in]    context  : FSM context
  * @param[in]    ms       : ms to adjust time by
index 25cabf3234c29bf8b486250500881d448a61f4e9..d5425325894cfcd576731eac9a22e466f8ca8150 100644 (file)
@@ -559,7 +559,7 @@ static void _build_sdio_config_data(sdio_config_data_t *cfg_data,
  *      padding bytes. Every read from this memory has to be transformed in
  *      host (cpu specific) format, before it is stored in driver's parameters
  *      or/and structures. Athough unifi_card_read16() and unifi_read32() do perform
- *      the convertion internally, unifi_readn() does not.
+ *      the conversion internally, unifi_readn() does not.
  * ---------------------------------------------------------------------------
  */
 static CsrResult card_hw_init(card_t *card)
@@ -1332,7 +1332,7 @@ static CsrResult card_access_panic(card_t *card)
     s32 i;
     CsrResult r, sr;
 
-    /* A chip version of zero means that the version never got succesfully read
+    /* A chip version of zero means that the version never got successfully read
      * during reset. In this case give up because it will not be possible to
      * verify the chip version.
      */
@@ -2446,7 +2446,7 @@ static CsrResult unifi_prepare_hw(card_t *card)
 
     if (old_state == UNIFI_HOST_STATE_TORPID)
     {
-        /* Ensure the initial clock rate is set; if a reset occured when the chip was
+        /* Ensure the initial clock rate is set; if a reset occurred when the chip was
          * TORPID, unifi_set_host_state() may have raised it to MAX.
          */
         csrResult = CsrSdioMaxBusClockFrequencySet(card->sdio_if, UNIFI_SDIO_CLOCK_INIT_HZ);
@@ -2567,7 +2567,7 @@ static CsrResult unifi_reset_hardware(card_t *card)
     csrResult = CsrSdioHardReset(card->sdio_if);
     if (csrResult == CSR_RESULT_SUCCESS)
     {
-        unifi_info(card->ospriv, "CsrSdioHardReset succeeded on reseting UniFi\n");
+        unifi_info(card->ospriv, "CsrSdioHardReset succeeded on resetting UniFi\n");
         r = unifi_prepare_hw(card);
         if (r == CSR_WIFI_HIP_RESULT_NO_DEVICE)
         {
index 3bd52fdeac3b162f2b628444a9a4e97782cd4a95..5520d6539f77256c67f7cfbf1c0afd8b92bc1c43 100644 (file)
@@ -1815,7 +1815,7 @@ udi_log_event(ul_client_t *pcli,
     }
 
     /* Allocate log structure plus actual signal. */
-    logptr = (udi_log_t *)kmalloc(sizeof(udi_log_t) + total_len, GFP_KERNEL);
+    logptr = kmalloc(sizeof(udi_log_t) + total_len, GFP_KERNEL);
 
     if (logptr == NULL) {
         printk(KERN_ERR
@@ -1890,7 +1890,7 @@ uf_sme_queue_message(unifi_priv_t *priv, u8 *buffer, int length)
     }
 
     /* Allocate log structure plus actual signal. */
-    logptr = (udi_log_t *)kmalloc(sizeof(udi_log_t) + length, GFP_ATOMIC);
+    logptr = kmalloc(sizeof(udi_log_t) + length, GFP_ATOMIC);
     if (logptr == NULL) {
         unifi_error(priv, "Failed to allocate %d bytes for an SME message\n",
                     sizeof(udi_log_t) + length);
index 7dad26f701758c228f4bc6cdf67a89fe0bb8192c..a0177d998978fe25524a333fc557bdada13d2c42 100644 (file)
@@ -2365,7 +2365,7 @@ unifi_rx(unifi_priv_t *priv, CSR_SIGNAL *signal, bulk_data_param_t *bulkdata)
         rx_buffered_packets_t *rx_q_item;
         struct list_head *rx_list;
 
-        rx_q_item = (rx_buffered_packets_t *)kmalloc(sizeof(rx_buffered_packets_t),
+        rx_q_item = kmalloc(sizeof(rx_buffered_packets_t),
                 GFP_KERNEL);
         if (rx_q_item == NULL) {
             unifi_error(priv, "%s: Failed to allocate %d bytes for rx packet record\n",
index b6a16de08f4ec7373da26c5f556b2afdcce2753d..30271d35af55e41862d0dffb4c541b43d742d599 100644 (file)
@@ -1031,8 +1031,7 @@ uf_glue_sdio_probe(struct sdio_func *func,
            sdio_func_id(func), instance);
 
     /* Allocate context */
-    sdio_ctx = (CsrSdioFunction *)kmalloc(sizeof(CsrSdioFunction),
-                                          GFP_KERNEL);
+    sdio_ctx = kmalloc(sizeof(CsrSdioFunction), GFP_KERNEL);
     if (sdio_ctx == NULL) {
         sdio_release_host(func);
         return -ENOMEM;
index 525fe1bce0e653a7e4e996715fde91d137c06c66..ca55249bde3e7e29cd49cc7690192f3c4ab93719 100644 (file)
@@ -273,7 +273,7 @@ sme_native_log_event(ul_client_t *pcli,
     }
 
     /* Allocate log structure plus actual signal. */
-    logptr = (udi_log_t *)kmalloc(sizeof(udi_log_t) + total_len, GFP_KERNEL);
+    logptr = kmalloc(sizeof(udi_log_t) + total_len, GFP_KERNEL);
 
     if (logptr == NULL) {
         unifi_error(priv,
index 5e06a380b40acc19c7643f8be843dd80a5d76d94..4129a6436b7635470cb70d77c613a7193f278b2d 100644 (file)
@@ -1273,7 +1273,6 @@ unifi_siwscan(struct net_device *dev, struct iw_request_info *info,
 {
     netInterface_priv_t *interfacePriv = (netInterface_priv_t *)netdev_priv(dev);
     unifi_priv_t *priv = interfacePriv->privPtr;
-    int scantype;
     int r;
     CsrWifiSsid scan_ssid;
     unsigned char *channel_list = NULL;
@@ -1293,8 +1292,6 @@ unifi_siwscan(struct net_device *dev, struct iw_request_info *info,
     }
 
 
-    scantype = UNIFI_SCAN_ACTIVE;
-
 #if WIRELESS_EXT > 17
     /* Providing a valid channel list will force an active scan */
     if (req) {
index 95efc360cc2daff5c9e1fd8b328bf69c610812d3..f9b421b5aa3592111e25cebdabb4d3f7564ed3ff 100644 (file)
@@ -403,7 +403,7 @@ CsrResult enque_tx_data_pdu(unifi_priv_t *priv, bulk_data_param_t *bulkdata,
 
 
 
-    tx_q_item = (tx_buffered_packets_t *)kmalloc(sizeof(tx_buffered_packets_t), GFP_ATOMIC);
+    tx_q_item = kmalloc(sizeof(tx_buffered_packets_t), GFP_ATOMIC);
     if (tx_q_item == NULL) {
         unifi_error(priv,
                 "Failed to allocate %d bytes for tx packet record\n",
@@ -1468,7 +1468,7 @@ static int update_macheader(unifi_priv_t *priv, struct sk_buff *skb,
             }
     }
 
-    /* prepare the complete skb, by pushing the MAC header to the begining of the skb->data */
+    /* prepare the complete skb, by pushing the MAC header to the beginning of the skb->data */
     unifi_trace(priv, UDBG5, "updated Mac Header: %d \n",macHeaderLengthInBytes);
     memcpy(bufPtr, macHeaderBuf, macHeaderLengthInBytes);
 
@@ -1546,7 +1546,7 @@ uf_ap_process_data_pdu(unifi_priv_t *priv, struct sk_buff *skb,
         return -1;
     }
 
-    /* fetch the destination record from staion record database */
+    /* fetch the destination record from station record database */
     dstStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, ehdr->h_dest, interfaceTag);
 
     /* AP mode processing, & if packet is unicast */
@@ -1878,13 +1878,13 @@ CsrResult uf_process_ma_packet_req(unifi_priv_t *priv,
         }
         else if ((pktType == CSR_WIFI_MULTICAST_PDU) && (!status))
         {
-            /* If broadcast Tim is set && queuing is successfull, then only update TIM */
+            /* If broadcast Tim is set && queuing is successful, then only update TIM */
             spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
             interfacePriv->noOfbroadcastPktQueued++;
             spin_unlock_irqrestore(&priv->staRecord_lock,lock_flags);
         }
     }
-    /* If broadcast Tim is set && queuing is successfull, then only update TIM */
+    /* If broadcast Tim is set && queuing is successful, then only update TIM */
     if(setBcTim && !status) {
         unifi_trace(priv, UDBG3, "tim set due to broadcast pkt\n");
         if (!interfacePriv->bcTimSetReqPendingFlag)
@@ -1995,7 +1995,7 @@ s8 uf_get_protection_bit_from_interfacemode(unifi_priv_t *priv, u16 interfaceTag
                      */
                     protection = interfacePriv->protect;
                 } else {
-                    /* fetch the destination record from staion record database */
+                    /* fetch the destination record from station record database */
                     dstStaInfo = CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(priv, daddr, interfaceTag);
                     if (!dstStaInfo) {
                         unifi_trace(priv, UDBG3, "peer not found in station record in send_ma_pkt_request\n");
@@ -3170,7 +3170,7 @@ void uf_process_ps_poll(unifi_priv_t *priv,u8* sa,u8* da,u8 pmBit,u16 interfaceT
         /*Send Data From Management Frames*/
         /* Priority orders for delivering the buffered packets are
          * 1. Deliver the Management frames if there
-         * 2. Other access catagory frames which are non deliver enable including UNIFI_TRAFFIC_Q_VO
+         * 2. Other access category frames which are non deliver enable including UNIFI_TRAFFIC_Q_VO
          * priority is from VO->BK
          */
 
@@ -3282,7 +3282,7 @@ void add_to_send_cfm_list(unifi_priv_t * priv,
 {
     tx_buffered_packets_t *send_cfm_list_item = NULL;
 
-    send_cfm_list_item = (tx_buffered_packets_t *) kmalloc(sizeof(tx_buffered_packets_t), GFP_ATOMIC);
+    send_cfm_list_item = kmalloc(sizeof(tx_buffered_packets_t), GFP_ATOMIC);
 
     if(send_cfm_list_item == NULL){
         unifi_warning(priv, "%s: Failed to allocate memory for new list item \n");
@@ -3439,7 +3439,7 @@ CsrWifiRouterCtrlStaInfo_t *CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(
 
     interfacePriv = priv->interfacePriv[interfaceTag];
 
-    /* disable the preemption untill station record is fetched */
+    /* disable the preemption until station record is fetched */
     spin_lock_irqsave(&priv->staRecord_lock,lock_flags);
 
     for (i = 0; i < UNIFI_MAX_CONNECTIONS; i++) {
@@ -3665,7 +3665,7 @@ void update_eosp_to_head_of_broadcast_list_head(unifi_priv_t *priv,u16 interface
     if (interfacePriv->noOfbroadcastPktQueued) {
 
         /* Update the EOSP to the HEAD of b/c list
-         * beacuse we have received any mgmt packet so it should not hold for long time
+         * because we have received any mgmt packet so it should not hold for long time
          * peer may time out.
          */
         spin_lock_irqsave(&priv->tx_q_lock,lock_flags);
index 021cca498f2c510ccb6bcd63a23582e39b094f16..67fb3d6c45ea01709329ed33b84f1e5cf1eb8f47 100644 (file)
@@ -116,7 +116,7 @@ void dgrp_register_dpa_hook(struct proc_dir_entry *de)
        struct nd_struct *node = de->data;
 
        de->proc_iops = &dpa_inode_ops;
-       de->proc_fops = &dpa_ops;
+       rcu_assign_pointer(de->proc_fops, &dpa_ops);
 
        node->nd_dpa_de = de;
        spin_lock_init(&node->nd_dpa_lock);
index 4792d056a36532b179968dda51f73b37ce56cb95..b484fccb494e96852fecd01e0a2e497ee5371710 100644 (file)
@@ -66,7 +66,7 @@ void dgrp_register_mon_hook(struct proc_dir_entry *de)
        struct nd_struct *node = de->data;
 
        de->proc_iops = &mon_inode_ops;
-       de->proc_fops = &mon_ops;
+       rcu_assign_pointer(de->proc_fops, &mon_ops);
        node->nd_mon_de = de;
        sema_init(&node->nd_mon_semaphore, 1);
 }
index e6018823b9deca9079ff3ee72251a5669ad99b2f..64f48ffb9d4e70a7f89f2d13d8ff8214f247708e 100644 (file)
@@ -91,7 +91,7 @@ void dgrp_register_net_hook(struct proc_dir_entry *de)
        struct nd_struct *node = de->data;
 
        de->proc_iops = &net_inode_ops;
-       de->proc_fops = &net_ops;
+       rcu_assign_pointer(de->proc_fops, &net_ops);
        node->nd_net_de = de;
        sema_init(&node->nd_net_semaphore, 1);
        node->nd_state = NS_CLOSED;
@@ -3405,7 +3405,7 @@ static long dgrp_net_ioctl(struct file *file, unsigned int cmd,
                if (size != sizeof(struct link_struct))
                        return -EINVAL;
 
-               if (copy_from_user((void *)(&link), (void __user *) arg, size))
+               if (copy_from_user(&link, (void __user *)arg, size))
                        return -EFAULT;
 
                if (link.lk_fast_rate < 9600)
index cd1fc20886242f27a38b0b17f4c5880a47ba8835..f93dc1f262f5b9dfc0fbb83da71c8d9faee7af14 100644 (file)
@@ -65,7 +65,7 @@ void dgrp_register_ports_hook(struct proc_dir_entry *de)
        struct nd_struct *node = de->data;
 
        de->proc_iops = &ports_inode_ops;
-       de->proc_fops = &ports_ops;
+       rcu_assign_pointer(de->proc_fops, &ports_ops);
        node->nd_ports_de = de;
 }
 
index 73f287f966046b7f89ff5e4a6c3038f9c98d6d52..d66712c8aa9453f4e6b2f8b22b3fcc4ebaf6628e 100644 (file)
@@ -271,9 +271,11 @@ static void register_proc_table(struct dgrp_proc_entry *table,
                        if (!table->child) {
                                de->proc_iops = &proc_inode_ops;
                                if (table->proc_file_ops)
-                                       de->proc_fops = table->proc_file_ops;
+                                       rcu_assign_pointer(de->proc_fops,
+                                                       table->proc_file_ops);
                                else
-                                       de->proc_fops = &dgrp_proc_file_ops;
+                                       rcu_assign_pointer(de->proc_fops,
+                                                        &dgrp_proc_file_ops);
                        }
                }
                table->de = de;
diff --git a/drivers/staging/dwc2/Kconfig b/drivers/staging/dwc2/Kconfig
new file mode 100644 (file)
index 0000000..bc4cdfe
--- /dev/null
@@ -0,0 +1,42 @@
+config USB_DWC2
+       tristate "DesignWare USB2 DRD Core Support"
+       depends on USB
+       depends on VIRT_TO_BUS
+       select USB_OTG_UTILS
+       help
+         Say Y or M here if your system has a Dual Role HighSpeed
+         USB controller based on the DesignWare HSOTG IP Core.
+
+         If you choose to build this driver as dynamically linked
+         modules, the core module will be called dwc2.ko, and the
+         PCI bus interface module (if you have a PCI bus system)
+         will be called dwc2_pci.ko.
+
+         NOTE: This driver at present only implements the Host mode
+         of the controller. The existing s3c-hsotg driver supports
+         Peripheral mode, but only for the Samsung S3C platforms.
+         There are plans to merge the s3c-hsotg driver with this
+         driver in the near future to create a dual-role driver.
+
+if USB_DWC2
+
+config USB_DWC2_DEBUG
+       bool "Enable Debugging Messages"
+       help
+         Say Y here to enable debugging messages in the DWC2 Driver.
+
+config USB_DWC2_VERBOSE
+       bool "Enable Verbose Debugging Messages"
+       depends on USB_DWC2_DEBUG
+       help
+         Say Y here to enable verbose debugging messages in the DWC2 Driver.
+         WARNING: Enabling this will quickly fill your message log.
+         If in doubt, say N.
+
+config USB_DWC2_TRACK_MISSED_SOFS
+       bool "Enable Missed SOF Tracking"
+       help
+         Say Y here to enable logging of missed SOF events to the dmesg log.
+         If in doubt, say N.
+
+endif
diff --git a/drivers/staging/dwc2/Makefile b/drivers/staging/dwc2/Makefile
new file mode 100644 (file)
index 0000000..6dccf46
--- /dev/null
@@ -0,0 +1,23 @@
+ccflags-$(CONFIG_USB_DWC2_DEBUG)       += -DDEBUG
+ccflags-$(CONFIG_USB_DWC2_VERBOSE)     += -DVERBOSE_DEBUG
+
+obj-$(CONFIG_USB_DWC2)                 += dwc2.o
+
+dwc2-y                                 += core.o core_intr.o
+
+# NOTE: This driver at present only implements the Host mode
+# of the controller. The existing s3c-hsotg driver supports
+# Peripheral mode, but only for the Samsung S3C platforms.
+# There are plans to merge the s3c-hsotg driver with this
+# driver in the near future to create a dual-role driver. Once
+# that is done, Host mode will become an optional feature that
+# is selected with a config option.
+
+dwc2-y                                 += hcd.o hcd_intr.o
+dwc2-y                                 += hcd_queue.o hcd_ddma.o
+
+ifneq ($(CONFIG_PCI),)
+       obj-$(CONFIG_USB_DWC2)          += dwc2_pci.o
+endif
+
+dwc2_pci-y                             += pci.o
diff --git a/drivers/staging/dwc2/core.c b/drivers/staging/dwc2/core.c
new file mode 100644 (file)
index 0000000..f695a9b
--- /dev/null
@@ -0,0 +1,2678 @@
+/*
+ * core.c - DesignWare HS OTG Controller common routines
+ *
+ * Copyright (C) 2004-2013 Synopsys, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. 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.
+ * 3. The names of the above-listed copyright holders may not 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 the 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 OWNER 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.
+ */
+
+/*
+ * The Core code provides basic services for accessing and managing the
+ * DWC_otg hardware. These services are used by both the Host Controller
+ * Driver and the Peripheral Controller Driver.
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/dma-mapping.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+
+#include <linux/usb/hcd.h>
+#include <linux/usb/ch11.h>
+
+#include "core.h"
+#include "hcd.h"
+
+/**
+ * dwc2_enable_common_interrupts() - Initializes the commmon interrupts,
+ * used in both device and host modes
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ */
+static void dwc2_enable_common_interrupts(struct dwc2_hsotg *hsotg)
+{
+       u32 intmsk;
+
+       /* Clear any pending OTG Interrupts */
+       writel(0xffffffff, hsotg->regs + GOTGINT);
+
+       /* Clear any pending interrupts */
+       writel(0xffffffff, hsotg->regs + GINTSTS);
+
+       /* Enable the interrupts in the GINTMSK */
+       intmsk = GINTSTS_MODEMIS | GINTSTS_OTGINT;
+
+       if (hsotg->core_params->dma_enable <= 0)
+               intmsk |= GINTSTS_RXFLVL;
+
+       intmsk |= GINTSTS_CONIDSTSCHNG | GINTSTS_WKUPINT | GINTSTS_USBSUSP |
+                 GINTSTS_SESSREQINT;
+
+       writel(intmsk, hsotg->regs + GINTMSK);
+}
+
+/*
+ * Initializes the FSLSPClkSel field of the HCFG register depending on the
+ * PHY type
+ */
+static void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg)
+{
+       u32 hs_phy_type = hsotg->hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK;
+       u32 fs_phy_type = hsotg->hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK;
+       u32 hcfg, val;
+
+       if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI &&
+            fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED &&
+            hsotg->core_params->ulpi_fs_ls > 0) ||
+           hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) {
+               /* Full speed PHY */
+               val = HCFG_FSLSPCLKSEL_48_MHZ;
+       } else {
+               /* High speed PHY running at full speed or high speed */
+               val = HCFG_FSLSPCLKSEL_30_60_MHZ;
+       }
+
+       dev_dbg(hsotg->dev, "Initializing HCFG.FSLSPClkSel to %08x\n", val);
+       hcfg = readl(hsotg->regs + HCFG);
+       hcfg &= ~HCFG_FSLSPCLKSEL_MASK;
+       hcfg |= val;
+       writel(hcfg, hsotg->regs + HCFG);
+}
+
+/*
+ * Do core a soft reset of the core.  Be careful with this because it
+ * resets all the internal state machines of the core.
+ */
+static void dwc2_core_reset(struct dwc2_hsotg *hsotg)
+{
+       u32 greset;
+       int count = 0;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       /* Wait for AHB master IDLE state */
+       do {
+               usleep_range(20000, 40000);
+               greset = readl(hsotg->regs + GRSTCTL);
+               if (++count > 50) {
+                       dev_warn(hsotg->dev,
+                                "%s() HANG! AHB Idle GRSTCTL=%0x\n",
+                                __func__, greset);
+                       return;
+               }
+       } while (!(greset & GRSTCTL_AHBIDLE));
+
+       /* Core Soft Reset */
+       count = 0;
+       greset |= GRSTCTL_CSFTRST;
+       writel(greset, hsotg->regs + GRSTCTL);
+       do {
+               usleep_range(20000, 40000);
+               greset = readl(hsotg->regs + GRSTCTL);
+               if (++count > 50) {
+                       dev_warn(hsotg->dev,
+                                "%s() HANG! Soft Reset GRSTCTL=%0x\n",
+                                __func__, greset);
+                       break;
+               }
+       } while (greset & GRSTCTL_CSFTRST);
+
+       /*
+        * NOTE: This long sleep is _very_ important, otherwise the core will
+        * not stay in host mode after a connector ID change!
+        */
+       usleep_range(150000, 200000);
+}
+
+static void dwc2_fs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
+{
+       u32 usbcfg, i2cctl;
+
+       /*
+        * core_init() is now called on every switch so only call the
+        * following for the first time through
+        */
+       if (select_phy) {
+               dev_dbg(hsotg->dev, "FS PHY selected\n");
+               usbcfg = readl(hsotg->regs + GUSBCFG);
+               usbcfg |= GUSBCFG_PHYSEL;
+               writel(usbcfg, hsotg->regs + GUSBCFG);
+
+               /* Reset after a PHY select */
+               dwc2_core_reset(hsotg);
+       }
+
+       /*
+        * Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
+        * do this on HNP Dev/Host mode switches (done in dev_init and
+        * host_init).
+        */
+       if (dwc2_is_host_mode(hsotg))
+               dwc2_init_fs_ls_pclk_sel(hsotg);
+
+       if (hsotg->core_params->i2c_enable > 0) {
+               dev_dbg(hsotg->dev, "FS PHY enabling I2C\n");
+
+               /* Program GUSBCFG.OtgUtmiFsSel to I2C */
+               usbcfg = readl(hsotg->regs + GUSBCFG);
+               usbcfg |= GUSBCFG_OTG_UTMI_FS_SEL;
+               writel(usbcfg, hsotg->regs + GUSBCFG);
+
+               /* Program GI2CCTL.I2CEn */
+               i2cctl = readl(hsotg->regs + GI2CCTL);
+               i2cctl &= ~GI2CCTL_I2CDEVADDR_MASK;
+               i2cctl |= 1 << GI2CCTL_I2CDEVADDR_SHIFT;
+               i2cctl &= ~GI2CCTL_I2CEN;
+               writel(i2cctl, hsotg->regs + GI2CCTL);
+               i2cctl |= GI2CCTL_I2CEN;
+               writel(i2cctl, hsotg->regs + GI2CCTL);
+       }
+}
+
+static void dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
+{
+       u32 usbcfg;
+
+       if (!select_phy)
+               return;
+
+       usbcfg = readl(hsotg->regs + GUSBCFG);
+
+       /*
+        * HS PHY parameters. These parameters are preserved during soft reset
+        * so only program the first time. Do a soft reset immediately after
+        * setting phyif.
+        */
+       switch (hsotg->core_params->phy_type) {
+       case DWC2_PHY_TYPE_PARAM_ULPI:
+               /* ULPI interface */
+               dev_dbg(hsotg->dev, "HS ULPI PHY selected\n");
+               usbcfg |= GUSBCFG_ULPI_UTMI_SEL;
+               usbcfg &= ~(GUSBCFG_PHYIF16 | GUSBCFG_DDRSEL);
+               if (hsotg->core_params->phy_ulpi_ddr > 0)
+                       usbcfg |= GUSBCFG_DDRSEL;
+               break;
+       case DWC2_PHY_TYPE_PARAM_UTMI:
+               /* UTMI+ interface */
+               dev_dbg(hsotg->dev, "HS UTMI+ PHY selected\n");
+               usbcfg &= ~(GUSBCFG_ULPI_UTMI_SEL | GUSBCFG_PHYIF16);
+               if (hsotg->core_params->phy_utmi_width == 16)
+                       usbcfg |= GUSBCFG_PHYIF16;
+               break;
+       default:
+               dev_err(hsotg->dev, "FS PHY selected at HS!\n");
+               break;
+       }
+
+       writel(usbcfg, hsotg->regs + GUSBCFG);
+
+       /* Reset after setting the PHY parameters */
+       dwc2_core_reset(hsotg);
+}
+
+static void dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
+{
+       u32 usbcfg, hs_phy_type, fs_phy_type;
+
+       if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL &&
+           hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) {
+               /* If FS mode with FS PHY */
+               dwc2_fs_phy_init(hsotg, select_phy);
+       } else {
+               /* High speed PHY */
+               dwc2_hs_phy_init(hsotg, select_phy);
+       }
+
+       hs_phy_type = hsotg->hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK;
+       fs_phy_type = hsotg->hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK;
+
+       if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI &&
+           fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED &&
+           hsotg->core_params->ulpi_fs_ls > 0) {
+               dev_dbg(hsotg->dev, "Setting ULPI FSLS\n");
+               usbcfg = readl(hsotg->regs + GUSBCFG);
+               usbcfg |= GUSBCFG_ULPI_FS_LS;
+               usbcfg |= GUSBCFG_ULPI_CLK_SUSP_M;
+               writel(usbcfg, hsotg->regs + GUSBCFG);
+       } else {
+               usbcfg = readl(hsotg->regs + GUSBCFG);
+               usbcfg &= ~GUSBCFG_ULPI_FS_LS;
+               usbcfg &= ~GUSBCFG_ULPI_CLK_SUSP_M;
+               writel(usbcfg, hsotg->regs + GUSBCFG);
+       }
+}
+
+static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg)
+{
+       u32 ahbcfg = 0;
+
+       switch (hsotg->hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) {
+       case GHWCFG2_EXT_DMA_ARCH:
+               dev_err(hsotg->dev, "External DMA Mode not supported\n");
+               return -EINVAL;
+
+       case GHWCFG2_INT_DMA_ARCH:
+               dev_dbg(hsotg->dev, "Internal DMA Mode\n");
+               /*
+                * Old value was GAHBCFG_HBSTLEN_INCR - done for
+                * Host mode ISOC in issue fix - vahrama
+                */
+               ahbcfg |= GAHBCFG_HBSTLEN_INCR4;
+               break;
+
+       case GHWCFG2_SLAVE_ONLY_ARCH:
+       default:
+               dev_dbg(hsotg->dev, "Slave Only Mode\n");
+               break;
+       }
+
+       dev_dbg(hsotg->dev, "dma_enable:%d dma_desc_enable:%d\n",
+               hsotg->core_params->dma_enable,
+               hsotg->core_params->dma_desc_enable);
+
+       if (hsotg->core_params->dma_enable > 0) {
+               if (hsotg->core_params->dma_desc_enable > 0)
+                       dev_dbg(hsotg->dev, "Using Descriptor DMA mode\n");
+               else
+                       dev_dbg(hsotg->dev, "Using Buffer DMA mode\n");
+       } else {
+               dev_dbg(hsotg->dev, "Using Slave mode\n");
+               hsotg->core_params->dma_desc_enable = 0;
+       }
+
+       if (hsotg->core_params->ahb_single > 0)
+               ahbcfg |= GAHBCFG_AHB_SINGLE;
+
+       if (hsotg->core_params->dma_enable > 0)
+               ahbcfg |= GAHBCFG_DMA_EN;
+
+       writel(ahbcfg, hsotg->regs + GAHBCFG);
+
+       return 0;
+}
+
+static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg)
+{
+       u32 usbcfg;
+
+       usbcfg = readl(hsotg->regs + GUSBCFG);
+       usbcfg &= ~(GUSBCFG_HNPCAP | GUSBCFG_SRPCAP);
+
+       switch (hsotg->hwcfg2 & GHWCFG2_OP_MODE_MASK) {
+       case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
+               if (hsotg->core_params->otg_cap ==
+                               DWC2_CAP_PARAM_HNP_SRP_CAPABLE)
+                       usbcfg |= GUSBCFG_HNPCAP;
+               if (hsotg->core_params->otg_cap !=
+                               DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE)
+                       usbcfg |= GUSBCFG_SRPCAP;
+               break;
+
+       case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
+       case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
+       case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
+               if (hsotg->core_params->otg_cap !=
+                               DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE)
+                       usbcfg |= GUSBCFG_SRPCAP;
+               break;
+
+       case GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE:
+       case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE:
+       case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST:
+       default:
+               break;
+       }
+
+       writel(usbcfg, hsotg->regs + GUSBCFG);
+}
+
+/**
+ * dwc2_core_init() - Initializes the DWC_otg controller registers and
+ * prepares the core for device mode or host mode operation
+ *
+ * @hsotg:      Programming view of the DWC_otg controller
+ * @select_phy: If true then also set the Phy type
+ */
+int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy)
+{
+       u32 usbcfg, otgctl;
+       int retval;
+
+       dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg);
+
+       usbcfg = readl(hsotg->regs + GUSBCFG);
+
+       /* Set ULPI External VBUS bit if needed */
+       usbcfg &= ~GUSBCFG_ULPI_EXT_VBUS_DRV;
+       if (hsotg->core_params->phy_ulpi_ext_vbus ==
+                               DWC2_PHY_ULPI_EXTERNAL_VBUS)
+               usbcfg |= GUSBCFG_ULPI_EXT_VBUS_DRV;
+
+       /* Set external TS Dline pulsing bit if needed */
+       usbcfg &= ~GUSBCFG_TERMSELDLPULSE;
+       if (hsotg->core_params->ts_dline > 0)
+               usbcfg |= GUSBCFG_TERMSELDLPULSE;
+
+       writel(usbcfg, hsotg->regs + GUSBCFG);
+
+       /* Reset the Controller */
+       dwc2_core_reset(hsotg);
+
+       dev_dbg(hsotg->dev, "num_dev_perio_in_ep=%d\n",
+               hsotg->hwcfg4 >> GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT &
+               GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK >>
+                               GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT);
+
+       hsotg->total_fifo_size = hsotg->hwcfg3 >> GHWCFG3_DFIFO_DEPTH_SHIFT &
+                       GHWCFG3_DFIFO_DEPTH_MASK >> GHWCFG3_DFIFO_DEPTH_SHIFT;
+       hsotg->rx_fifo_size = readl(hsotg->regs + GRXFSIZ);
+       hsotg->nperio_tx_fifo_size =
+                       readl(hsotg->regs + GNPTXFSIZ) >> 16 & 0xffff;
+
+       dev_dbg(hsotg->dev, "Total FIFO SZ=%d\n", hsotg->total_fifo_size);
+       dev_dbg(hsotg->dev, "RxFIFO SZ=%d\n", hsotg->rx_fifo_size);
+       dev_dbg(hsotg->dev, "NP TxFIFO SZ=%d\n", hsotg->nperio_tx_fifo_size);
+
+       /*
+        * This needs to happen in FS mode before any other programming occurs
+        */
+       dwc2_phy_init(hsotg, select_phy);
+
+       /* Program the GAHBCFG Register */
+       retval = dwc2_gahbcfg_init(hsotg);
+       if (retval)
+               return retval;
+
+       /* Program the GUSBCFG register */
+       dwc2_gusbcfg_init(hsotg);
+
+       /* Program the GOTGCTL register */
+       otgctl = readl(hsotg->regs + GOTGCTL);
+       otgctl &= ~GOTGCTL_OTGVER;
+       if (hsotg->core_params->otg_ver > 0)
+               otgctl |= GOTGCTL_OTGVER;
+       writel(otgctl, hsotg->regs + GOTGCTL);
+       dev_dbg(hsotg->dev, "OTG VER PARAM: %d\n", hsotg->core_params->otg_ver);
+
+       /* Clear the SRP success bit for FS-I2c */
+       hsotg->srp_success = 0;
+
+       /* Enable common interrupts */
+       dwc2_enable_common_interrupts(hsotg);
+
+       /*
+        * Do device or host intialization based on mode during PCD and
+        * HCD initialization
+        */
+       if (dwc2_is_host_mode(hsotg)) {
+               dev_dbg(hsotg->dev, "Host Mode\n");
+               hsotg->op_state = OTG_STATE_A_HOST;
+       } else {
+               dev_dbg(hsotg->dev, "Device Mode\n");
+               hsotg->op_state = OTG_STATE_B_PERIPHERAL;
+       }
+
+       return 0;
+}
+
+/**
+ * dwc2_enable_host_interrupts() - Enables the Host mode interrupts
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ */
+void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg)
+{
+       u32 intmsk;
+
+       dev_dbg(hsotg->dev, "%s()\n", __func__);
+
+       /* Disable all interrupts */
+       writel(0, hsotg->regs + GINTMSK);
+       writel(0, hsotg->regs + HAINTMSK);
+
+       /* Clear any pending interrupts */
+       writel(0xffffffff, hsotg->regs + GINTSTS);
+
+       /* Enable the common interrupts */
+       dwc2_enable_common_interrupts(hsotg);
+
+       /* Enable host mode interrupts without disturbing common interrupts */
+       intmsk = readl(hsotg->regs + GINTMSK);
+       intmsk |= GINTSTS_DISCONNINT | GINTSTS_PRTINT | GINTSTS_HCHINT;
+       writel(intmsk, hsotg->regs + GINTMSK);
+}
+
+/**
+ * dwc2_disable_host_interrupts() - Disables the Host Mode interrupts
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ */
+void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg)
+{
+       u32 intmsk = readl(hsotg->regs + GINTMSK);
+
+       /* Disable host mode interrupts without disturbing common interrupts */
+       intmsk &= ~(GINTSTS_SOF | GINTSTS_PRTINT | GINTSTS_HCHINT |
+                   GINTSTS_PTXFEMP | GINTSTS_NPTXFEMP);
+       writel(intmsk, hsotg->regs + GINTMSK);
+}
+
+static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
+{
+       struct dwc2_core_params *params = hsotg->core_params;
+       u32 rxfsiz, nptxfsiz, ptxfsiz, hptxfsiz, dfifocfg;
+
+       if (!(hsotg->hwcfg2 & GHWCFG2_DYNAMIC_FIFO) ||
+           !params->enable_dynamic_fifo)
+               return;
+
+       dev_dbg(hsotg->dev, "Total FIFO Size=%d\n", hsotg->total_fifo_size);
+       dev_dbg(hsotg->dev, "Rx FIFO Size=%d\n", params->host_rx_fifo_size);
+       dev_dbg(hsotg->dev, "NP Tx FIFO Size=%d\n",
+               params->host_nperio_tx_fifo_size);
+       dev_dbg(hsotg->dev, "P Tx FIFO Size=%d\n",
+               params->host_perio_tx_fifo_size);
+
+       /* Rx FIFO */
+       dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n",
+               readl(hsotg->regs + GRXFSIZ));
+       writel(params->host_rx_fifo_size, hsotg->regs + GRXFSIZ);
+       dev_dbg(hsotg->dev, "new grxfsiz=%08x\n", readl(hsotg->regs + GRXFSIZ));
+
+       /* Non-periodic Tx FIFO */
+       dev_dbg(hsotg->dev, "initial gnptxfsiz=%08x\n",
+               readl(hsotg->regs + GNPTXFSIZ));
+       nptxfsiz = params->host_nperio_tx_fifo_size <<
+                  FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK;
+       nptxfsiz |= params->host_rx_fifo_size <<
+                   FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK;
+       writel(nptxfsiz, hsotg->regs + GNPTXFSIZ);
+       dev_dbg(hsotg->dev, "new gnptxfsiz=%08x\n",
+               readl(hsotg->regs + GNPTXFSIZ));
+
+       /* Periodic Tx FIFO */
+       dev_dbg(hsotg->dev, "initial hptxfsiz=%08x\n",
+               readl(hsotg->regs + HPTXFSIZ));
+       ptxfsiz = params->host_perio_tx_fifo_size <<
+                 FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK;
+       ptxfsiz |= (params->host_rx_fifo_size +
+                   params->host_nperio_tx_fifo_size) <<
+                  FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK;
+       writel(ptxfsiz, hsotg->regs + HPTXFSIZ);
+       dev_dbg(hsotg->dev, "new hptxfsiz=%08x\n",
+               readl(hsotg->regs + HPTXFSIZ));
+
+       if (hsotg->core_params->en_multiple_tx_fifo > 0 &&
+           hsotg->snpsid <= DWC2_CORE_REV_2_94a) {
+               /*
+                * Global DFIFOCFG calculation for Host mode -
+                * include RxFIFO, NPTXFIFO and HPTXFIFO
+                */
+               dfifocfg = readl(hsotg->regs + GDFIFOCFG);
+               rxfsiz = readl(hsotg->regs + GRXFSIZ) & 0x0000ffff;
+               nptxfsiz = readl(hsotg->regs + GNPTXFSIZ) >> 16 & 0xffff;
+               hptxfsiz = readl(hsotg->regs + HPTXFSIZ) >> 16 & 0xffff;
+               dfifocfg &= ~GDFIFOCFG_EPINFOBASE_MASK;
+               dfifocfg |= (rxfsiz + nptxfsiz + hptxfsiz) <<
+                           GDFIFOCFG_EPINFOBASE_SHIFT &
+                           GDFIFOCFG_EPINFOBASE_MASK;
+               writel(dfifocfg, hsotg->regs + GDFIFOCFG);
+       }
+}
+
+/**
+ * dwc2_core_host_init() - Initializes the DWC_otg controller registers for
+ * Host mode
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ *
+ * This function flushes the Tx and Rx FIFOs and flushes any entries in the
+ * request queues. Host channels are reset to ensure that they are ready for
+ * performing transfers.
+ */
+void dwc2_core_host_init(struct dwc2_hsotg *hsotg)
+{
+       u32 hcfg, hfir, otgctl;
+
+       dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg);
+
+       /* Restart the Phy Clock */
+       writel(0, hsotg->regs + PCGCTL);
+
+       /* Initialize Host Configuration Register */
+       dwc2_init_fs_ls_pclk_sel(hsotg);
+       if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL) {
+               hcfg = readl(hsotg->regs + HCFG);
+               hcfg |= HCFG_FSLSSUPP;
+               writel(hcfg, hsotg->regs + HCFG);
+       }
+
+       /*
+        * This bit allows dynamic reloading of the HFIR register during
+        * runtime. This bit needs to be programmed during inital configuration
+        * and its value must not be changed during runtime.
+        */
+       if (hsotg->core_params->reload_ctl > 0) {
+               hfir = readl(hsotg->regs + HFIR);
+               hfir |= HFIR_RLDCTRL;
+               writel(hfir, hsotg->regs + HFIR);
+       }
+
+       if (hsotg->core_params->dma_desc_enable > 0) {
+               u32 op_mode = hsotg->hwcfg2 & GHWCFG2_OP_MODE_MASK;
+
+               if (hsotg->snpsid < DWC2_CORE_REV_2_90a ||
+                   !(hsotg->hwcfg4 & GHWCFG4_DESC_DMA) ||
+                   op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE ||
+                   op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE ||
+                   op_mode == GHWCFG2_OP_MODE_UNDEFINED) {
+                       dev_err(hsotg->dev,
+                               "Hardware does not support descriptor DMA mode -\n");
+                       dev_err(hsotg->dev,
+                               "falling back to buffer DMA mode.\n");
+                       hsotg->core_params->dma_desc_enable = 0;
+               } else {
+                       hcfg = readl(hsotg->regs + HCFG);
+                       hcfg |= HCFG_DESCDMA;
+                       writel(hcfg, hsotg->regs + HCFG);
+               }
+       }
+
+       /* Configure data FIFO sizes */
+       dwc2_config_fifos(hsotg);
+
+       /* TODO - check this */
+       /* Clear Host Set HNP Enable in the OTG Control Register */
+       otgctl = readl(hsotg->regs + GOTGCTL);
+       otgctl &= ~GOTGCTL_HSTSETHNPEN;
+       writel(otgctl, hsotg->regs + GOTGCTL);
+
+       /* Make sure the FIFOs are flushed */
+       dwc2_flush_tx_fifo(hsotg, 0x10 /* all TX FIFOs */);
+       dwc2_flush_rx_fifo(hsotg);
+
+       /* Clear Host Set HNP Enable in the OTG Control Register */
+       otgctl = readl(hsotg->regs + GOTGCTL);
+       otgctl &= ~GOTGCTL_HSTSETHNPEN;
+       writel(otgctl, hsotg->regs + GOTGCTL);
+
+       if (hsotg->core_params->dma_desc_enable <= 0) {
+               int num_channels, i;
+               u32 hcchar;
+
+               /* Flush out any leftover queued requests */
+               num_channels = hsotg->core_params->host_channels;
+               for (i = 0; i < num_channels; i++) {
+                       hcchar = readl(hsotg->regs + HCCHAR(i));
+                       hcchar &= ~HCCHAR_CHENA;
+                       hcchar |= HCCHAR_CHDIS;
+                       hcchar &= ~HCCHAR_EPDIR;
+                       writel(hcchar, hsotg->regs + HCCHAR(i));
+               }
+
+               /* Halt all channels to put them into a known state */
+               for (i = 0; i < num_channels; i++) {
+                       int count = 0;
+
+                       hcchar = readl(hsotg->regs + HCCHAR(i));
+                       hcchar |= HCCHAR_CHENA | HCCHAR_CHDIS;
+                       hcchar &= ~HCCHAR_EPDIR;
+                       writel(hcchar, hsotg->regs + HCCHAR(i));
+                       dev_dbg(hsotg->dev, "%s: Halt channel %d\n",
+                               __func__, i);
+                       do {
+                               hcchar = readl(hsotg->regs + HCCHAR(i));
+                               if (++count > 1000) {
+                                       dev_err(hsotg->dev,
+                                               "Unable to clear enable on channel %d\n",
+                                               i);
+                                       break;
+                               }
+                               udelay(1);
+                       } while (hcchar & HCCHAR_CHENA);
+               }
+       }
+
+       /* Turn on the vbus power */
+       dev_dbg(hsotg->dev, "Init: Port Power? op_state=%d\n", hsotg->op_state);
+       if (hsotg->op_state == OTG_STATE_A_HOST) {
+               u32 hprt0 = dwc2_read_hprt0(hsotg);
+
+               dev_dbg(hsotg->dev, "Init: Power Port (%d)\n",
+                       !!(hprt0 & HPRT0_PWR));
+               if (!(hprt0 & HPRT0_PWR)) {
+                       hprt0 |= HPRT0_PWR;
+                       writel(hprt0, hsotg->regs + HPRT0);
+               }
+       }
+
+       dwc2_enable_host_interrupts(hsotg);
+}
+
+static void dwc2_hc_enable_slave_ints(struct dwc2_hsotg *hsotg,
+                                     struct dwc2_host_chan *chan)
+{
+       u32 hcintmsk = HCINTMSK_CHHLTD;
+
+       switch (chan->ep_type) {
+       case USB_ENDPOINT_XFER_CONTROL:
+       case USB_ENDPOINT_XFER_BULK:
+               dev_vdbg(hsotg->dev, "control/bulk\n");
+               hcintmsk |= HCINTMSK_XFERCOMPL;
+               hcintmsk |= HCINTMSK_STALL;
+               hcintmsk |= HCINTMSK_XACTERR;
+               hcintmsk |= HCINTMSK_DATATGLERR;
+               if (chan->ep_is_in) {
+                       hcintmsk |= HCINTMSK_BBLERR;
+               } else {
+                       hcintmsk |= HCINTMSK_NAK;
+                       hcintmsk |= HCINTMSK_NYET;
+                       if (chan->do_ping)
+                               hcintmsk |= HCINTMSK_ACK;
+               }
+
+               if (chan->do_split) {
+                       hcintmsk |= HCINTMSK_NAK;
+                       if (chan->complete_split)
+                               hcintmsk |= HCINTMSK_NYET;
+                       else
+                               hcintmsk |= HCINTMSK_ACK;
+               }
+
+               if (chan->error_state)
+                       hcintmsk |= HCINTMSK_ACK;
+               break;
+
+       case USB_ENDPOINT_XFER_INT:
+               dev_vdbg(hsotg->dev, "intr\n");
+               hcintmsk |= HCINTMSK_XFERCOMPL;
+               hcintmsk |= HCINTMSK_NAK;
+               hcintmsk |= HCINTMSK_STALL;
+               hcintmsk |= HCINTMSK_XACTERR;
+               hcintmsk |= HCINTMSK_DATATGLERR;
+               hcintmsk |= HCINTMSK_FRMOVRUN;
+
+               if (chan->ep_is_in)
+                       hcintmsk |= HCINTMSK_BBLERR;
+               if (chan->error_state)
+                       hcintmsk |= HCINTMSK_ACK;
+               if (chan->do_split) {
+                       if (chan->complete_split)
+                               hcintmsk |= HCINTMSK_NYET;
+                       else
+                               hcintmsk |= HCINTMSK_ACK;
+               }
+               break;
+
+       case USB_ENDPOINT_XFER_ISOC:
+               dev_vdbg(hsotg->dev, "isoc\n");
+               hcintmsk |= HCINTMSK_XFERCOMPL;
+               hcintmsk |= HCINTMSK_FRMOVRUN;
+               hcintmsk |= HCINTMSK_ACK;
+
+               if (chan->ep_is_in) {
+                       hcintmsk |= HCINTMSK_XACTERR;
+                       hcintmsk |= HCINTMSK_BBLERR;
+               }
+               break;
+       default:
+               dev_err(hsotg->dev, "## Unknown EP type ##\n");
+               break;
+       }
+
+       writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num));
+       dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk);
+}
+
+static void dwc2_hc_enable_dma_ints(struct dwc2_hsotg *hsotg,
+                                   struct dwc2_host_chan *chan)
+{
+       u32 hcintmsk = HCINTMSK_CHHLTD;
+
+       /*
+        * For Descriptor DMA mode core halts the channel on AHB error.
+        * Interrupt is not required.
+        */
+       if (hsotg->core_params->dma_desc_enable <= 0) {
+               dev_vdbg(hsotg->dev, "desc DMA disabled\n");
+               hcintmsk |= HCINTMSK_AHBERR;
+       } else {
+               dev_vdbg(hsotg->dev, "desc DMA enabled\n");
+               if (chan->ep_type == USB_ENDPOINT_XFER_ISOC)
+                       hcintmsk |= HCINTMSK_XFERCOMPL;
+       }
+
+       if (chan->error_state && !chan->do_split &&
+           chan->ep_type != USB_ENDPOINT_XFER_ISOC) {
+               dev_vdbg(hsotg->dev, "setting ACK\n");
+               hcintmsk |= HCINTMSK_ACK;
+               if (chan->ep_is_in) {
+                       hcintmsk |= HCINTMSK_DATATGLERR;
+                       if (chan->ep_type != USB_ENDPOINT_XFER_INT)
+                               hcintmsk |= HCINTMSK_NAK;
+               }
+       }
+
+       writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num));
+       dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk);
+}
+
+static void dwc2_hc_enable_ints(struct dwc2_hsotg *hsotg,
+                               struct dwc2_host_chan *chan)
+{
+       u32 intmsk;
+
+       if (hsotg->core_params->dma_enable > 0) {
+               dev_vdbg(hsotg->dev, "DMA enabled\n");
+               dwc2_hc_enable_dma_ints(hsotg, chan);
+       } else {
+               dev_vdbg(hsotg->dev, "DMA disabled\n");
+               dwc2_hc_enable_slave_ints(hsotg, chan);
+       }
+
+       /* Enable the top level host channel interrupt */
+       intmsk = readl(hsotg->regs + HAINTMSK);
+       intmsk |= 1 << chan->hc_num;
+       writel(intmsk, hsotg->regs + HAINTMSK);
+       dev_vdbg(hsotg->dev, "set HAINTMSK to %08x\n", intmsk);
+
+       /* Make sure host channel interrupts are enabled */
+       intmsk = readl(hsotg->regs + GINTMSK);
+       intmsk |= GINTSTS_HCHINT;
+       writel(intmsk, hsotg->regs + GINTMSK);
+       dev_vdbg(hsotg->dev, "set GINTMSK to %08x\n", intmsk);
+}
+
+/**
+ * dwc2_hc_init() - Prepares a host channel for transferring packets to/from
+ * a specific endpoint
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ * @chan:  Information needed to initialize the host channel
+ *
+ * The HCCHARn register is set up with the characteristics specified in chan.
+ * Host channel interrupts that may need to be serviced while this transfer is
+ * in progress are enabled.
+ */
+void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan)
+{
+       u8 hc_num = chan->hc_num;
+       u32 hcintmsk;
+       u32 hcchar;
+       u32 hcsplt = 0;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       /* Clear old interrupt conditions for this host channel */
+       hcintmsk = 0xffffffff;
+       hcintmsk &= ~HCINTMSK_RESERVED14_31;
+       writel(hcintmsk, hsotg->regs + HCINT(hc_num));
+
+       /* Enable channel interrupts required for this transfer */
+       dwc2_hc_enable_ints(hsotg, chan);
+
+       /*
+        * Program the HCCHARn register with the endpoint characteristics for
+        * the current transfer
+        */
+       hcchar = chan->dev_addr << HCCHAR_DEVADDR_SHIFT & HCCHAR_DEVADDR_MASK;
+       hcchar |= chan->ep_num << HCCHAR_EPNUM_SHIFT & HCCHAR_EPNUM_MASK;
+       if (chan->ep_is_in)
+               hcchar |= HCCHAR_EPDIR;
+       if (chan->speed == USB_SPEED_LOW)
+               hcchar |= HCCHAR_LSPDDEV;
+       hcchar |= chan->ep_type << HCCHAR_EPTYPE_SHIFT & HCCHAR_EPTYPE_MASK;
+       hcchar |= chan->max_packet << HCCHAR_MPS_SHIFT & HCCHAR_MPS_MASK;
+       writel(hcchar, hsotg->regs + HCCHAR(hc_num));
+       dev_vdbg(hsotg->dev, "set HCCHAR(%d) to %08x\n", hc_num, hcchar);
+
+       dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, hc_num);
+       dev_vdbg(hsotg->dev, "   Dev Addr: %d\n",
+                hcchar >> HCCHAR_DEVADDR_SHIFT &
+                HCCHAR_DEVADDR_MASK >> HCCHAR_DEVADDR_SHIFT);
+       dev_vdbg(hsotg->dev, "   Ep Num: %d\n",
+                hcchar >> HCCHAR_EPNUM_SHIFT &
+                HCCHAR_EPNUM_MASK >> HCCHAR_EPNUM_SHIFT);
+       dev_vdbg(hsotg->dev, "   Is In: %d\n", !!(hcchar & HCCHAR_EPDIR));
+       dev_vdbg(hsotg->dev, "   Is Low Speed: %d\n",
+                !!(hcchar & HCCHAR_LSPDDEV));
+       dev_vdbg(hsotg->dev, "   Ep Type: %d\n",
+                hcchar >> HCCHAR_EPTYPE_SHIFT &
+                HCCHAR_EPTYPE_MASK >> HCCHAR_EPTYPE_SHIFT);
+       dev_vdbg(hsotg->dev, "   Max Pkt: %d\n",
+                hcchar >> HCCHAR_MPS_SHIFT &
+                HCCHAR_MPS_MASK >> HCCHAR_MPS_SHIFT);
+       dev_vdbg(hsotg->dev, "   Multi Cnt: %d\n",
+                hcchar >> HCCHAR_MULTICNT_SHIFT &
+                HCCHAR_MULTICNT_MASK >> HCCHAR_MULTICNT_SHIFT);
+
+       /* Program the HCSPLT register for SPLITs */
+       if (chan->do_split) {
+               dev_vdbg(hsotg->dev, "Programming HC %d with split --> %s\n",
+                        hc_num, chan->complete_split ? "CSPLIT" : "SSPLIT");
+               if (chan->complete_split)
+                       hcsplt |= HCSPLT_COMPSPLT;
+               hcsplt |= chan->xact_pos << HCSPLT_XACTPOS_SHIFT &
+                         HCSPLT_XACTPOS_MASK;
+               hcsplt |= chan->hub_addr << HCSPLT_HUBADDR_SHIFT &
+                         HCSPLT_HUBADDR_MASK;
+               hcsplt |= chan->hub_port << HCSPLT_PRTADDR_SHIFT &
+                         HCSPLT_PRTADDR_MASK;
+               dev_vdbg(hsotg->dev, "    comp split %d\n",
+                        chan->complete_split);
+               dev_vdbg(hsotg->dev, "    xact pos %d\n", chan->xact_pos);
+               dev_vdbg(hsotg->dev, "    hub addr %d\n", chan->hub_addr);
+               dev_vdbg(hsotg->dev, "    hub port %d\n", chan->hub_port);
+               dev_vdbg(hsotg->dev, "    is_in %d\n", chan->ep_is_in);
+               dev_vdbg(hsotg->dev, "    Max Pkt %d\n",
+                        hcchar >> HCCHAR_MPS_SHIFT &
+                        HCCHAR_MPS_MASK >> HCCHAR_MPS_SHIFT);
+               dev_vdbg(hsotg->dev, "    xferlen %d\n", chan->xfer_len);
+       }
+
+       writel(hcsplt, hsotg->regs + HCSPLT(hc_num));
+}
+
+/**
+ * dwc2_hc_halt() - Attempts to halt a host channel
+ *
+ * @hsotg:       Controller register interface
+ * @chan:        Host channel to halt
+ * @halt_status: Reason for halting the channel
+ *
+ * This function should only be called in Slave mode or to abort a transfer in
+ * either Slave mode or DMA mode. Under normal circumstances in DMA mode, the
+ * controller halts the channel when the transfer is complete or a condition
+ * occurs that requires application intervention.
+ *
+ * In slave mode, checks for a free request queue entry, then sets the Channel
+ * Enable and Channel Disable bits of the Host Channel Characteristics
+ * register of the specified channel to intiate the halt. If there is no free
+ * request queue entry, sets only the Channel Disable bit of the HCCHARn
+ * register to flush requests for this channel. In the latter case, sets a
+ * flag to indicate that the host channel needs to be halted when a request
+ * queue slot is open.
+ *
+ * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
+ * HCCHARn register. The controller ensures there is space in the request
+ * queue before submitting the halt request.
+ *
+ * Some time may elapse before the core flushes any posted requests for this
+ * host channel and halts. The Channel Halted interrupt handler completes the
+ * deactivation of the host channel.
+ */
+void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
+                 enum dwc2_halt_status halt_status)
+{
+       u32 nptxsts, hptxsts, hcchar;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+       if (halt_status == DWC2_HC_XFER_NO_HALT_STATUS)
+               dev_err(hsotg->dev, "!!! halt_status = %d !!!\n", halt_status);
+
+       if (halt_status == DWC2_HC_XFER_URB_DEQUEUE ||
+           halt_status == DWC2_HC_XFER_AHB_ERR) {
+               /*
+                * Disable all channel interrupts except Ch Halted. The QTD
+                * and QH state associated with this transfer has been cleared
+                * (in the case of URB_DEQUEUE), so the channel needs to be
+                * shut down carefully to prevent crashes.
+                */
+               u32 hcintmsk = HCINTMSK_CHHLTD;
+
+               dev_vdbg(hsotg->dev, "dequeue/error\n");
+               writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num));
+
+               /*
+                * Make sure no other interrupts besides halt are currently
+                * pending. Handling another interrupt could cause a crash due
+                * to the QTD and QH state.
+                */
+               writel(~hcintmsk, hsotg->regs + HCINT(chan->hc_num));
+
+               /*
+                * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
+                * even if the channel was already halted for some other
+                * reason
+                */
+               chan->halt_status = halt_status;
+
+               hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
+               if (!(hcchar & HCCHAR_CHENA)) {
+                       /*
+                        * The channel is either already halted or it hasn't
+                        * started yet. In DMA mode, the transfer may halt if
+                        * it finishes normally or a condition occurs that
+                        * requires driver intervention. Don't want to halt
+                        * the channel again. In either Slave or DMA mode,
+                        * it's possible that the transfer has been assigned
+                        * to a channel, but not started yet when an URB is
+                        * dequeued. Don't want to halt a channel that hasn't
+                        * started yet.
+                        */
+                       return;
+               }
+       }
+       if (chan->halt_pending) {
+               /*
+                * A halt has already been issued for this channel. This might
+                * happen when a transfer is aborted by a higher level in
+                * the stack.
+                */
+               dev_vdbg(hsotg->dev,
+                        "*** %s: Channel %d, chan->halt_pending already set ***\n",
+                        __func__, chan->hc_num);
+               return;
+       }
+
+       hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
+
+       /* No need to set the bit in DDMA for disabling the channel */
+       /* TODO check it everywhere channel is disabled */
+       if (hsotg->core_params->dma_desc_enable <= 0) {
+               dev_vdbg(hsotg->dev, "desc DMA disabled\n");
+               hcchar |= HCCHAR_CHENA;
+       } else {
+               dev_dbg(hsotg->dev, "desc DMA enabled\n");
+       }
+       hcchar |= HCCHAR_CHDIS;
+
+       if (hsotg->core_params->dma_enable <= 0) {
+               dev_vdbg(hsotg->dev, "DMA not enabled\n");
+               hcchar |= HCCHAR_CHENA;
+
+               /* Check for space in the request queue to issue the halt */
+               if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
+                   chan->ep_type == USB_ENDPOINT_XFER_BULK) {
+                       dev_vdbg(hsotg->dev, "control/bulk\n");
+                       nptxsts = readl(hsotg->regs + GNPTXSTS);
+                       if ((nptxsts & TXSTS_QSPCAVAIL_MASK) == 0) {
+                               dev_vdbg(hsotg->dev, "Disabling channel\n");
+                               hcchar &= ~HCCHAR_CHENA;
+                       }
+               } else {
+                       dev_vdbg(hsotg->dev, "isoc/intr\n");
+                       hptxsts = readl(hsotg->regs + HPTXSTS);
+                       if ((hptxsts & TXSTS_QSPCAVAIL_MASK) == 0 ||
+                           hsotg->queuing_high_bandwidth) {
+                               dev_vdbg(hsotg->dev, "Disabling channel\n");
+                               hcchar &= ~HCCHAR_CHENA;
+                       }
+               }
+       } else {
+               dev_vdbg(hsotg->dev, "DMA enabled\n");
+       }
+
+       writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
+       chan->halt_status = halt_status;
+
+       if (hcchar & HCCHAR_CHENA) {
+               dev_vdbg(hsotg->dev, "Channel enabled\n");
+               chan->halt_pending = 1;
+               chan->halt_on_queue = 0;
+       } else {
+               dev_vdbg(hsotg->dev, "Channel disabled\n");
+               chan->halt_on_queue = 1;
+       }
+
+       dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, chan->hc_num);
+       dev_vdbg(hsotg->dev, "   hcchar: 0x%08x\n", hcchar);
+       dev_vdbg(hsotg->dev, "   halt_pending: %d\n", chan->halt_pending);
+       dev_vdbg(hsotg->dev, "   halt_on_queue: %d\n", chan->halt_on_queue);
+       dev_vdbg(hsotg->dev, "   halt_status: %d\n", chan->halt_status);
+}
+
+/**
+ * dwc2_hc_cleanup() - Clears the transfer state for a host channel
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ * @chan:  Identifies the host channel to clean up
+ *
+ * This function is normally called after a transfer is done and the host
+ * channel is being released
+ */
+void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan)
+{
+       u32 hcintmsk;
+
+       chan->xfer_started = 0;
+
+       /*
+        * Clear channel interrupt enables and any unhandled channel interrupt
+        * conditions
+        */
+       writel(0, hsotg->regs + HCINTMSK(chan->hc_num));
+       hcintmsk = 0xffffffff;
+       hcintmsk &= ~HCINTMSK_RESERVED14_31;
+       writel(hcintmsk, hsotg->regs + HCINT(chan->hc_num));
+}
+
+/**
+ * dwc2_hc_set_even_odd_frame() - Sets the channel property that indicates in
+ * which frame a periodic transfer should occur
+ *
+ * @hsotg:  Programming view of DWC_otg controller
+ * @chan:   Identifies the host channel to set up and its properties
+ * @hcchar: Current value of the HCCHAR register for the specified host channel
+ *
+ * This function has no effect on non-periodic transfers
+ */
+static void dwc2_hc_set_even_odd_frame(struct dwc2_hsotg *hsotg,
+                                      struct dwc2_host_chan *chan, u32 *hcchar)
+{
+       u32 hfnum, frnum;
+
+       if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
+           chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
+               hfnum = readl(hsotg->regs + HFNUM);
+               frnum = hfnum >> HFNUM_FRNUM_SHIFT &
+                       HFNUM_FRNUM_MASK >> HFNUM_FRNUM_SHIFT;
+
+               /* 1 if _next_ frame is odd, 0 if it's even */
+               if (frnum & 0x1)
+                       *hcchar |= HCCHAR_ODDFRM;
+       }
+}
+
+static void dwc2_set_pid_isoc(struct dwc2_host_chan *chan)
+{
+       /* Set up the initial PID for the transfer */
+       if (chan->speed == USB_SPEED_HIGH) {
+               if (chan->ep_is_in) {
+                       if (chan->multi_count == 1)
+                               chan->data_pid_start = DWC2_HC_PID_DATA0;
+                       else if (chan->multi_count == 2)
+                               chan->data_pid_start = DWC2_HC_PID_DATA1;
+                       else
+                               chan->data_pid_start = DWC2_HC_PID_DATA2;
+               } else {
+                       if (chan->multi_count == 1)
+                               chan->data_pid_start = DWC2_HC_PID_DATA0;
+                       else
+                               chan->data_pid_start = DWC2_HC_PID_MDATA;
+               }
+       } else {
+               chan->data_pid_start = DWC2_HC_PID_DATA0;
+       }
+}
+
+/**
+ * dwc2_hc_write_packet() - Writes a packet into the Tx FIFO associated with
+ * the Host Channel
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ * @chan:  Information needed to initialize the host channel
+ *
+ * This function should only be called in Slave mode. For a channel associated
+ * with a non-periodic EP, the non-periodic Tx FIFO is written. For a channel
+ * associated with a periodic EP, the periodic Tx FIFO is written.
+ *
+ * Upon return the xfer_buf and xfer_count fields in chan are incremented by
+ * the number of bytes written to the Tx FIFO.
+ */
+static void dwc2_hc_write_packet(struct dwc2_hsotg *hsotg,
+                                struct dwc2_host_chan *chan)
+{
+       u32 i;
+       u32 remaining_count;
+       u32 byte_count;
+       u32 dword_count;
+       u32 __iomem *data_fifo;
+       u32 *data_buf = (u32 *)chan->xfer_buf;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       data_fifo = (u32 __iomem *)(hsotg->regs + HCFIFO(chan->hc_num));
+
+       remaining_count = chan->xfer_len - chan->xfer_count;
+       if (remaining_count > chan->max_packet)
+               byte_count = chan->max_packet;
+       else
+               byte_count = remaining_count;
+
+       dword_count = (byte_count + 3) / 4;
+
+       if (((unsigned long)data_buf & 0x3) == 0) {
+               /* xfer_buf is DWORD aligned */
+               for (i = 0; i < dword_count; i++, data_buf++)
+                       writel(*data_buf, data_fifo);
+       } else {
+               /* xfer_buf is not DWORD aligned */
+               for (i = 0; i < dword_count; i++, data_buf++) {
+                       u32 data = data_buf[0] | data_buf[1] << 8 |
+                                  data_buf[2] << 16 | data_buf[3] << 24;
+                       writel(data, data_fifo);
+               }
+       }
+
+       chan->xfer_count += byte_count;
+       chan->xfer_buf += byte_count;
+}
+
+/**
+ * dwc2_hc_start_transfer() - Does the setup for a data transfer for a host
+ * channel and starts the transfer
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ * @chan:  Information needed to initialize the host channel. The xfer_len value
+ *         may be reduced to accommodate the max widths of the XferSize and
+ *         PktCnt fields in the HCTSIZn register. The multi_count value may be
+ *         changed to reflect the final xfer_len value.
+ *
+ * This function may be called in either Slave mode or DMA mode. In Slave mode,
+ * the caller must ensure that there is sufficient space in the request queue
+ * and Tx Data FIFO.
+ *
+ * For an OUT transfer in Slave mode, it loads a data packet into the
+ * appropriate FIFO. If necessary, additional data packets are loaded in the
+ * Host ISR.
+ *
+ * For an IN transfer in Slave mode, a data packet is requested. The data
+ * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
+ * additional data packets are requested in the Host ISR.
+ *
+ * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
+ * register along with a packet count of 1 and the channel is enabled. This
+ * causes a single PING transaction to occur. Other fields in HCTSIZ are
+ * simply set to 0 since no data transfer occurs in this case.
+ *
+ * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
+ * all the information required to perform the subsequent data transfer. In
+ * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
+ * controller performs the entire PING protocol, then starts the data
+ * transfer.
+ */
+void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
+                           struct dwc2_host_chan *chan)
+{
+       u32 max_hc_xfer_size = hsotg->core_params->max_transfer_size;
+       u16 max_hc_pkt_count = hsotg->core_params->max_packet_count;
+       u32 hcchar;
+       u32 hctsiz = 0;
+       u16 num_packets;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       if (chan->do_ping) {
+               if (hsotg->core_params->dma_enable <= 0) {
+                       dev_vdbg(hsotg->dev, "ping, no DMA\n");
+                       dwc2_hc_do_ping(hsotg, chan);
+                       chan->xfer_started = 1;
+                       return;
+               } else {
+                       dev_vdbg(hsotg->dev, "ping, DMA\n");
+                       hctsiz |= TSIZ_DOPNG;
+               }
+       }
+
+       if (chan->do_split) {
+               dev_vdbg(hsotg->dev, "split\n");
+               num_packets = 1;
+
+               if (chan->complete_split && !chan->ep_is_in)
+                       /*
+                        * For CSPLIT OUT Transfer, set the size to 0 so the
+                        * core doesn't expect any data written to the FIFO
+                        */
+                       chan->xfer_len = 0;
+               else if (chan->ep_is_in || chan->xfer_len > chan->max_packet)
+                       chan->xfer_len = chan->max_packet;
+               else if (!chan->ep_is_in && chan->xfer_len > 188)
+                       chan->xfer_len = 188;
+
+               hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT &
+                         TSIZ_XFERSIZE_MASK;
+       } else {
+               dev_vdbg(hsotg->dev, "no split\n");
+               /*
+                * Ensure that the transfer length and packet count will fit
+                * in the widths allocated for them in the HCTSIZn register
+                */
+               if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
+                   chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
+                       /*
+                        * Make sure the transfer size is no larger than one
+                        * (micro)frame's worth of data. (A check was done
+                        * when the periodic transfer was accepted to ensure
+                        * that a (micro)frame's worth of data can be
+                        * programmed into a channel.)
+                        */
+                       u32 max_periodic_len =
+                               chan->multi_count * chan->max_packet;
+
+                       if (chan->xfer_len > max_periodic_len)
+                               chan->xfer_len = max_periodic_len;
+               } else if (chan->xfer_len > max_hc_xfer_size) {
+                       /*
+                        * Make sure that xfer_len is a multiple of max packet
+                        * size
+                        */
+                       chan->xfer_len =
+                               max_hc_xfer_size - chan->max_packet + 1;
+               }
+
+               if (chan->xfer_len > 0) {
+                       num_packets = (chan->xfer_len + chan->max_packet - 1) /
+                                       chan->max_packet;
+                       if (num_packets > max_hc_pkt_count) {
+                               num_packets = max_hc_pkt_count;
+                               chan->xfer_len = num_packets * chan->max_packet;
+                       }
+               } else {
+                       /* Need 1 packet for transfer length of 0 */
+                       num_packets = 1;
+               }
+
+               if (chan->ep_is_in)
+                       /*
+                        * Always program an integral # of max packets for IN
+                        * transfers
+                        */
+                       chan->xfer_len = num_packets * chan->max_packet;
+
+               if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
+                   chan->ep_type == USB_ENDPOINT_XFER_ISOC)
+                       /*
+                        * Make sure that the multi_count field matches the
+                        * actual transfer length
+                        */
+                       chan->multi_count = num_packets;
+
+               if (chan->ep_type == USB_ENDPOINT_XFER_ISOC)
+                       dwc2_set_pid_isoc(chan);
+
+               hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT &
+                         TSIZ_XFERSIZE_MASK;
+       }
+
+       chan->start_pkt_count = num_packets;
+       hctsiz |= num_packets << TSIZ_PKTCNT_SHIFT & TSIZ_PKTCNT_MASK;
+       hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT &
+                 TSIZ_SC_MC_PID_MASK;
+       writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num));
+       dev_vdbg(hsotg->dev, "Wrote %08x to HCTSIZ(%d)\n",
+                hctsiz, chan->hc_num);
+
+       dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, chan->hc_num);
+       dev_vdbg(hsotg->dev, "   Xfer Size: %d\n",
+                hctsiz >> TSIZ_XFERSIZE_SHIFT &
+                TSIZ_XFERSIZE_MASK >> TSIZ_XFERSIZE_SHIFT);
+       dev_vdbg(hsotg->dev, "   Num Pkts: %d\n",
+                hctsiz >> TSIZ_PKTCNT_SHIFT &
+                TSIZ_PKTCNT_MASK >> TSIZ_PKTCNT_SHIFT);
+       dev_vdbg(hsotg->dev, "   Start PID: %d\n",
+                hctsiz >> TSIZ_SC_MC_PID_SHIFT &
+                TSIZ_SC_MC_PID_MASK >> TSIZ_SC_MC_PID_SHIFT);
+
+       if (hsotg->core_params->dma_enable > 0) {
+               dma_addr_t dma_addr;
+
+               if (chan->align_buf) {
+                       dev_vdbg(hsotg->dev, "align_buf\n");
+                       dma_addr = chan->align_buf;
+               } else {
+                       dma_addr = chan->xfer_dma;
+               }
+               writel((u32)dma_addr, hsotg->regs + HCDMA(chan->hc_num));
+               dev_vdbg(hsotg->dev, "Wrote %08lx to HCDMA(%d)\n",
+                        (unsigned long)dma_addr, chan->hc_num);
+       }
+
+       /* Start the split */
+       if (chan->do_split) {
+               u32 hcsplt = readl(hsotg->regs + HCSPLT(chan->hc_num));
+
+               hcsplt |= HCSPLT_SPLTENA;
+               writel(hcsplt, hsotg->regs + HCSPLT(chan->hc_num));
+       }
+
+       hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
+       hcchar &= ~HCCHAR_MULTICNT_MASK;
+       hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT &
+                 HCCHAR_MULTICNT_MASK;
+       dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar);
+
+       if (hcchar & HCCHAR_CHDIS)
+               dev_warn(hsotg->dev,
+                        "%s: chdis set, channel %d, hcchar 0x%08x\n",
+                        __func__, chan->hc_num, hcchar);
+
+       /* Set host channel enable after all other setup is complete */
+       hcchar |= HCCHAR_CHENA;
+       hcchar &= ~HCCHAR_CHDIS;
+
+       dev_vdbg(hsotg->dev, "   Multi Cnt: %d\n",
+                hcchar >> HCCHAR_MULTICNT_SHIFT &
+                HCCHAR_MULTICNT_MASK >> HCCHAR_MULTICNT_SHIFT);
+
+       writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
+       dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar,
+                chan->hc_num);
+
+       chan->xfer_started = 1;
+       chan->requests++;
+
+       if (hsotg->core_params->dma_enable <= 0 &&
+           !chan->ep_is_in && chan->xfer_len > 0)
+               /* Load OUT packet into the appropriate Tx FIFO */
+               dwc2_hc_write_packet(hsotg, chan);
+}
+
+/**
+ * dwc2_hc_start_transfer_ddma() - Does the setup for a data transfer for a
+ * host channel and starts the transfer in Descriptor DMA mode
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ * @chan:  Information needed to initialize the host channel
+ *
+ * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
+ * Sets PID and NTD values. For periodic transfers initializes SCHED_INFO field
+ * with micro-frame bitmap.
+ *
+ * Initializes HCDMA register with descriptor list address and CTD value then
+ * starts the transfer via enabling the channel.
+ */
+void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
+                                struct dwc2_host_chan *chan)
+{
+       u32 hcchar;
+       u32 hc_dma;
+       u32 hctsiz = 0;
+
+       if (chan->do_ping)
+               hctsiz |= TSIZ_DOPNG;
+
+       if (chan->ep_type == USB_ENDPOINT_XFER_ISOC)
+               dwc2_set_pid_isoc(chan);
+
+       /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
+       hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT &
+                 TSIZ_SC_MC_PID_MASK;
+
+       /* 0 - 1 descriptor, 1 - 2 descriptors, etc */
+       hctsiz |= (chan->ntd - 1) << TSIZ_NTD_SHIFT & TSIZ_NTD_MASK;
+
+       /* Non-zero only for high-speed interrupt endpoints */
+       hctsiz |= chan->schinfo << TSIZ_SCHINFO_SHIFT & TSIZ_SCHINFO_MASK;
+
+       dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, chan->hc_num);
+       dev_vdbg(hsotg->dev, "   Start PID: %d\n", chan->data_pid_start);
+       dev_vdbg(hsotg->dev, "   NTD: %d\n", chan->ntd - 1);
+
+       writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num));
+
+       hc_dma = (u32)chan->desc_list_addr & HCDMA_DMA_ADDR_MASK;
+
+       /* Always start from first descriptor */
+       hc_dma &= ~HCDMA_CTD_MASK;
+       writel(hc_dma, hsotg->regs + HCDMA(chan->hc_num));
+       dev_vdbg(hsotg->dev, "Wrote %08x to HCDMA(%d)\n", hc_dma, chan->hc_num);
+
+       hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
+       hcchar &= ~HCCHAR_MULTICNT_MASK;
+       hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT &
+                 HCCHAR_MULTICNT_MASK;
+
+       if (hcchar & HCCHAR_CHDIS)
+               dev_warn(hsotg->dev,
+                        "%s: chdis set, channel %d, hcchar 0x%08x\n",
+                        __func__, chan->hc_num, hcchar);
+
+       /* Set host channel enable after all other setup is complete */
+       hcchar |= HCCHAR_CHENA;
+       hcchar &= ~HCCHAR_CHDIS;
+
+       dev_vdbg(hsotg->dev, "   Multi Cnt: %d\n",
+                hcchar >> HCCHAR_MULTICNT_SHIFT &
+                HCCHAR_MULTICNT_MASK >> HCCHAR_MULTICNT_SHIFT);
+
+       writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
+       dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar,
+                chan->hc_num);
+
+       chan->xfer_started = 1;
+       chan->requests++;
+}
+
+/**
+ * dwc2_hc_continue_transfer() - Continues a data transfer that was started by
+ * a previous call to dwc2_hc_start_transfer()
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ * @chan:  Information needed to initialize the host channel
+ *
+ * The caller must ensure there is sufficient space in the request queue and Tx
+ * Data FIFO. This function should only be called in Slave mode. In DMA mode,
+ * the controller acts autonomously to complete transfers programmed to a host
+ * channel.
+ *
+ * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
+ * if there is any data remaining to be queued. For an IN transfer, another
+ * data packet is always requested. For the SETUP phase of a control transfer,
+ * this function does nothing.
+ *
+ * Return: 1 if a new request is queued, 0 if no more requests are required
+ * for this transfer
+ */
+int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
+                             struct dwc2_host_chan *chan)
+{
+       dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, chan->hc_num);
+
+       if (chan->do_split)
+               /* SPLITs always queue just once per channel */
+               return 0;
+
+       if (chan->data_pid_start == DWC2_HC_PID_SETUP)
+               /* SETUPs are queued only once since they can't be NAK'd */
+               return 0;
+
+       if (chan->ep_is_in) {
+               /*
+                * Always queue another request for other IN transfers. If
+                * back-to-back INs are issued and NAKs are received for both,
+                * the driver may still be processing the first NAK when the
+                * second NAK is received. When the interrupt handler clears
+                * the NAK interrupt for the first NAK, the second NAK will
+                * not be seen. So we can't depend on the NAK interrupt
+                * handler to requeue a NAK'd request. Instead, IN requests
+                * are issued each time this function is called. When the
+                * transfer completes, the extra requests for the channel will
+                * be flushed.
+                */
+               u32 hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
+
+               dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar);
+               hcchar |= HCCHAR_CHENA;
+               hcchar &= ~HCCHAR_CHDIS;
+               dev_vdbg(hsotg->dev, "   IN xfer: hcchar = 0x%08x\n", hcchar);
+               writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
+               chan->requests++;
+               return 1;
+       }
+
+       /* OUT transfers */
+
+       if (chan->xfer_count < chan->xfer_len) {
+               if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
+                   chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
+                       u32 hcchar = readl(hsotg->regs +
+                                          HCCHAR(chan->hc_num));
+
+                       dwc2_hc_set_even_odd_frame(hsotg, chan,
+                                                  &hcchar);
+               }
+
+               /* Load OUT packet into the appropriate Tx FIFO */
+               dwc2_hc_write_packet(hsotg, chan);
+               chan->requests++;
+               return 1;
+       }
+
+       return 0;
+}
+
+/**
+ * dwc2_hc_do_ping() - Starts a PING transfer
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ * @chan:  Information needed to initialize the host channel
+ *
+ * This function should only be called in Slave mode. The Do Ping bit is set in
+ * the HCTSIZ register, then the channel is enabled.
+ */
+void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan)
+{
+       u32 hcchar;
+       u32 hctsiz;
+
+       dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, chan->hc_num);
+
+       hctsiz = TSIZ_DOPNG;
+       hctsiz |= 1 << TSIZ_PKTCNT_SHIFT;
+       writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num));
+
+       hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
+       hcchar |= HCCHAR_CHENA;
+       hcchar &= ~HCCHAR_CHDIS;
+       writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
+}
+
+/**
+ * dwc2_calc_frame_interval() - Calculates the correct frame Interval value for
+ * the HFIR register according to PHY type and speed
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ *
+ * NOTE: The caller can modify the value of the HFIR register only after the
+ * Port Enable bit of the Host Port Control and Status register (HPRT.EnaPort)
+ * has been set
+ */
+u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg)
+{
+       u32 usbcfg;
+       u32 hwcfg2;
+       u32 hprt0;
+       int clock = 60; /* default value */
+
+       usbcfg = readl(hsotg->regs + GUSBCFG);
+       hwcfg2 = readl(hsotg->regs + GHWCFG2);
+       hprt0 = readl(hsotg->regs + HPRT0);
+
+       if (!(usbcfg & GUSBCFG_PHYSEL) && (usbcfg & GUSBCFG_ULPI_UTMI_SEL) &&
+           !(usbcfg & GUSBCFG_PHYIF16))
+               clock = 60;
+       if ((usbcfg & GUSBCFG_PHYSEL) && (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) ==
+           GHWCFG2_FS_PHY_TYPE_SHARED_ULPI)
+               clock = 48;
+       if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) &&
+           !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16))
+               clock = 30;
+       if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) &&
+           !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && !(usbcfg & GUSBCFG_PHYIF16))
+               clock = 60;
+       if ((usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) &&
+           !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16))
+               clock = 48;
+       if ((usbcfg & GUSBCFG_PHYSEL) && !(usbcfg & GUSBCFG_PHYIF16) &&
+           (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) ==
+           GHWCFG2_FS_PHY_TYPE_SHARED_UTMI)
+               clock = 48;
+       if ((usbcfg & GUSBCFG_PHYSEL) && (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) ==
+           GHWCFG2_FS_PHY_TYPE_DEDICATED)
+               clock = 48;
+
+       if ((hprt0 & HPRT0_SPD_MASK) == 0)
+               /* High speed case */
+               return 125 * clock;
+       else
+               /* FS/LS case */
+               return 1000 * clock;
+}
+
+/**
+ * dwc2_read_packet() - Reads a packet from the Rx FIFO into the destination
+ * buffer
+ *
+ * @core_if: Programming view of DWC_otg controller
+ * @dest:    Destination buffer for the packet
+ * @bytes:   Number of bytes to copy to the destination
+ */
+void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes)
+{
+       u32 __iomem *fifo = hsotg->regs + HCFIFO(0);
+       u32 *data_buf = (u32 *)dest;
+       int word_count = (bytes + 3) / 4;
+       int i;
+
+       /*
+        * Todo: Account for the case where dest is not dword aligned. This
+        * requires reading data from the FIFO into a u32 temp buffer, then
+        * moving it into the data buffer.
+        */
+
+       dev_vdbg(hsotg->dev, "%s(%p,%p,%d)\n", __func__, hsotg, dest, bytes);
+
+       for (i = 0; i < word_count; i++, data_buf++)
+               *data_buf = readl(fifo);
+}
+
+/**
+ * dwc2_dump_host_registers() - Prints the host registers
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ *
+ * NOTE: This function will be removed once the peripheral controller code
+ * is integrated and the driver is stable
+ */
+void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg)
+{
+#ifdef DEBUG
+       u32 __iomem *addr;
+       int i;
+
+       dev_dbg(hsotg->dev, "Host Global Registers\n");
+       addr = hsotg->regs + HCFG;
+       dev_dbg(hsotg->dev, "HCFG        @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + HFIR;
+       dev_dbg(hsotg->dev, "HFIR        @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + HFNUM;
+       dev_dbg(hsotg->dev, "HFNUM       @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + HPTXSTS;
+       dev_dbg(hsotg->dev, "HPTXSTS     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + HAINT;
+       dev_dbg(hsotg->dev, "HAINT       @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + HAINTMSK;
+       dev_dbg(hsotg->dev, "HAINTMSK    @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       if (hsotg->core_params->dma_desc_enable > 0) {
+               addr = hsotg->regs + HFLBADDR;
+               dev_dbg(hsotg->dev, "HFLBADDR @0x%08lX : 0x%08X\n",
+                       (unsigned long)addr, readl(addr));
+       }
+
+       addr = hsotg->regs + HPRT0;
+       dev_dbg(hsotg->dev, "HPRT0       @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+
+       for (i = 0; i < hsotg->core_params->host_channels; i++) {
+               dev_dbg(hsotg->dev, "Host Channel %d Specific Registers\n", i);
+               addr = hsotg->regs + HCCHAR(i);
+               dev_dbg(hsotg->dev, "HCCHAR      @0x%08lX : 0x%08X\n",
+                       (unsigned long)addr, readl(addr));
+               addr = hsotg->regs + HCSPLT(i);
+               dev_dbg(hsotg->dev, "HCSPLT      @0x%08lX : 0x%08X\n",
+                       (unsigned long)addr, readl(addr));
+               addr = hsotg->regs + HCINT(i);
+               dev_dbg(hsotg->dev, "HCINT       @0x%08lX : 0x%08X\n",
+                       (unsigned long)addr, readl(addr));
+               addr = hsotg->regs + HCINTMSK(i);
+               dev_dbg(hsotg->dev, "HCINTMSK    @0x%08lX : 0x%08X\n",
+                       (unsigned long)addr, readl(addr));
+               addr = hsotg->regs + HCTSIZ(i);
+               dev_dbg(hsotg->dev, "HCTSIZ      @0x%08lX : 0x%08X\n",
+                       (unsigned long)addr, readl(addr));
+               addr = hsotg->regs + HCDMA(i);
+               dev_dbg(hsotg->dev, "HCDMA       @0x%08lX : 0x%08X\n",
+                       (unsigned long)addr, readl(addr));
+               if (hsotg->core_params->dma_desc_enable > 0) {
+                       addr = hsotg->regs + HCDMAB(i);
+                       dev_dbg(hsotg->dev, "HCDMAB      @0x%08lX : 0x%08X\n",
+                               (unsigned long)addr, readl(addr));
+               }
+       }
+#endif
+}
+
+/**
+ * dwc2_dump_global_registers() - Prints the core global registers
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ *
+ * NOTE: This function will be removed once the peripheral controller code
+ * is integrated and the driver is stable
+ */
+void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg)
+{
+#ifdef DEBUG
+       u32 __iomem *addr;
+       int i, ep_num;
+       char *txfsiz;
+
+       dev_dbg(hsotg->dev, "Core Global Registers\n");
+       addr = hsotg->regs + GOTGCTL;
+       dev_dbg(hsotg->dev, "GOTGCTL     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GOTGINT;
+       dev_dbg(hsotg->dev, "GOTGINT     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GAHBCFG;
+       dev_dbg(hsotg->dev, "GAHBCFG     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GUSBCFG;
+       dev_dbg(hsotg->dev, "GUSBCFG     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GRSTCTL;
+       dev_dbg(hsotg->dev, "GRSTCTL     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GINTSTS;
+       dev_dbg(hsotg->dev, "GINTSTS     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GINTMSK;
+       dev_dbg(hsotg->dev, "GINTMSK     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GRXSTSR;
+       dev_dbg(hsotg->dev, "GRXSTSR     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GRXFSIZ;
+       dev_dbg(hsotg->dev, "GRXFSIZ     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GNPTXFSIZ;
+       dev_dbg(hsotg->dev, "GNPTXFSIZ   @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GNPTXSTS;
+       dev_dbg(hsotg->dev, "GNPTXSTS    @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GI2CCTL;
+       dev_dbg(hsotg->dev, "GI2CCTL     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GPVNDCTL;
+       dev_dbg(hsotg->dev, "GPVNDCTL    @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GGPIO;
+       dev_dbg(hsotg->dev, "GGPIO       @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GUID;
+       dev_dbg(hsotg->dev, "GUID        @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GSNPSID;
+       dev_dbg(hsotg->dev, "GSNPSID     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GHWCFG1;
+       dev_dbg(hsotg->dev, "GHWCFG1     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GHWCFG2;
+       dev_dbg(hsotg->dev, "GHWCFG2     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GHWCFG3;
+       dev_dbg(hsotg->dev, "GHWCFG3     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GHWCFG4;
+       dev_dbg(hsotg->dev, "GHWCFG4     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GLPMCFG;
+       dev_dbg(hsotg->dev, "GLPMCFG     @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GPWRDN;
+       dev_dbg(hsotg->dev, "GPWRDN      @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + GDFIFOCFG;
+       dev_dbg(hsotg->dev, "GDFIFOCFG   @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+       addr = hsotg->regs + HPTXFSIZ;
+       dev_dbg(hsotg->dev, "HPTXFSIZ    @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+
+       if (hsotg->core_params->en_multiple_tx_fifo <= 0) {
+               ep_num = hsotg->hwcfg4 >> GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT &
+                        GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK >>
+                                        GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT;
+               txfsiz = "DPTXFSIZ";
+       } else {
+               ep_num = hsotg->hwcfg4 >> GHWCFG4_NUM_IN_EPS_SHIFT &
+                        GHWCFG4_NUM_IN_EPS_MASK >> GHWCFG4_NUM_IN_EPS_SHIFT;
+               txfsiz = "DIENPTXF";
+       }
+
+       for (i = 0; i < ep_num; i++) {
+               addr = hsotg->regs + DPTXFSIZN(i + 1);
+               dev_dbg(hsotg->dev, "%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
+                       (unsigned long)addr, readl(addr));
+       }
+
+       addr = hsotg->regs + PCGCTL;
+       dev_dbg(hsotg->dev, "PCGCTL      @0x%08lX : 0x%08X\n",
+               (unsigned long)addr, readl(addr));
+#endif
+}
+
+/**
+ * dwc2_flush_tx_fifo() - Flushes a Tx FIFO
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ * @num:   Tx FIFO to flush
+ */
+void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num)
+{
+       u32 greset;
+       int count = 0;
+
+       dev_vdbg(hsotg->dev, "Flush Tx FIFO %d\n", num);
+
+       greset = GRSTCTL_TXFFLSH;
+       greset |= num << GRSTCTL_TXFNUM_SHIFT & GRSTCTL_TXFNUM_MASK;
+       writel(greset, hsotg->regs + GRSTCTL);
+
+       do {
+               greset = readl(hsotg->regs + GRSTCTL);
+               if (++count > 10000) {
+                       dev_warn(hsotg->dev,
+                                "%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
+                                __func__, greset,
+                                readl(hsotg->regs + GNPTXSTS));
+                       break;
+               }
+               udelay(1);
+       } while (greset & GRSTCTL_TXFFLSH);
+
+       /* Wait for at least 3 PHY Clocks */
+       udelay(1);
+}
+
+/**
+ * dwc2_flush_rx_fifo() - Flushes the Rx FIFO
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ */
+void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg)
+{
+       u32 greset;
+       int count = 0;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       greset = GRSTCTL_RXFFLSH;
+       writel(greset, hsotg->regs + GRSTCTL);
+
+       do {
+               greset = readl(hsotg->regs + GRSTCTL);
+               if (++count > 10000) {
+                       dev_warn(hsotg->dev, "%s() HANG! GRSTCTL=%0x\n",
+                                __func__, greset);
+                       break;
+               }
+               udelay(1);
+       } while (greset & GRSTCTL_RXFFLSH);
+
+       /* Wait for at least 3 PHY Clocks */
+       udelay(1);
+}
+
+#define DWC2_PARAM_TEST(a, b, c)       ((a) < (b) || (a) > (c))
+
+/* Parameter access functions */
+int dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+       u32 op_mode;
+
+       op_mode = hsotg->hwcfg2 & GHWCFG2_OP_MODE_MASK;
+
+       switch (val) {
+       case DWC2_CAP_PARAM_HNP_SRP_CAPABLE:
+               if (op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE)
+                       valid = 0;
+               break;
+       case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE:
+               switch (op_mode) {
+               case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
+               case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
+               case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
+               case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
+                       break;
+               default:
+                       valid = 0;
+                       break;
+               }
+               break;
+       case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE:
+               /* always valid */
+               break;
+       default:
+               valid = 0;
+               break;
+       }
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for otg_cap parameter. Check HW configuration.\n",
+                               val);
+               switch (op_mode) {
+               case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
+                       val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE;
+                       break;
+               case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
+               case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
+               case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
+                       val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE;
+                       break;
+               default:
+                       val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
+                       break;
+               }
+               dev_dbg(hsotg->dev, "Setting otg_cap to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->otg_cap = val;
+       return retval;
+}
+
+int dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+
+       if (val > 0 && (hsotg->hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) ==
+           GHWCFG2_SLAVE_ONLY_ARCH)
+               valid = 0;
+       if (val < 0)
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for dma_enable parameter. Check HW configuration.\n",
+                               val);
+               val = (hsotg->hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) !=
+                       GHWCFG2_SLAVE_ONLY_ARCH;
+               dev_dbg(hsotg->dev, "Setting dma_enable to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->dma_enable = val;
+       return retval;
+}
+
+int dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+
+       if (val > 0 && (hsotg->core_params->dma_enable <= 0 ||
+                       !(hsotg->hwcfg4 & GHWCFG4_DESC_DMA)))
+               valid = 0;
+       if (val < 0)
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for dma_desc_enable parameter. Check HW configuration.\n",
+                               val);
+               val = (hsotg->core_params->dma_enable > 0 &&
+                       (hsotg->hwcfg4 & GHWCFG4_DESC_DMA));
+               dev_dbg(hsotg->dev, "Setting dma_desc_enable to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->dma_desc_enable = val;
+       return retval;
+}
+
+int dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg,
+                                               int val)
+{
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 0, 1)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev,
+                               "Wrong value for host_support_fs_low_power\n");
+                       dev_err(hsotg->dev,
+                               "host_support_fs_low_power must be 0 or 1\n");
+               }
+               val = 0;
+               dev_dbg(hsotg->dev,
+                       "Setting host_support_fs_low_power to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->host_support_fs_ls_low_power = val;
+       return retval;
+}
+
+int dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+
+       if (val > 0 && !(hsotg->hwcfg2 & GHWCFG2_DYNAMIC_FIFO))
+               valid = 0;
+       if (val < 0)
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for enable_dynamic_fifo parameter. Check HW configuration.\n",
+                               val);
+               val = !!(hsotg->hwcfg2 & GHWCFG2_DYNAMIC_FIFO);
+               dev_dbg(hsotg->dev, "Setting enable_dynamic_fifo to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->enable_dynamic_fifo = val;
+       return retval;
+}
+
+int dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+
+       if (val < 16 || val > readl(hsotg->regs + GRXFSIZ))
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for host_rx_fifo_size. Check HW configuration.\n",
+                               val);
+               val = readl(hsotg->regs + GRXFSIZ);
+               dev_dbg(hsotg->dev, "Setting host_rx_fifo_size to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->host_rx_fifo_size = val;
+       return retval;
+}
+
+int dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+
+       if (val < 16 || val > (readl(hsotg->regs + GNPTXFSIZ) >> 16 & 0xffff))
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
+                               val);
+               val = readl(hsotg->regs + GNPTXFSIZ) >> 16 & 0xffff;
+               dev_dbg(hsotg->dev, "Setting host_nperio_tx_fifo_size to %d\n",
+                       val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->host_nperio_tx_fifo_size = val;
+       return retval;
+}
+
+int dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+
+       if (val < 16 || val > (hsotg->hptxfsiz >> 16))
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
+                               val);
+               val = hsotg->hptxfsiz >> 16;
+               dev_dbg(hsotg->dev, "Setting host_perio_tx_fifo_size to %d\n",
+                       val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->host_perio_tx_fifo_size = val;
+       return retval;
+}
+
+int dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+       int width = hsotg->hwcfg3 >> GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT &
+                   GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK >>
+                               GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT;
+
+       if (val < 2047 || val >= (1 << (width + 11)))
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for max_transfer_size. Check HW configuration.\n",
+                               val);
+               val = (1 << (width + 11)) - 1;
+               dev_dbg(hsotg->dev, "Setting max_transfer_size to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->max_transfer_size = val;
+       return retval;
+}
+
+int dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+       int width = hsotg->hwcfg3 >> GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT &
+                   GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK >>
+                               GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT;
+
+       if (val < 15 || val > (1 << (width + 4)))
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for max_packet_count. Check HW configuration.\n",
+                               val);
+               val = (1 << (width + 4)) - 1;
+               dev_dbg(hsotg->dev, "Setting max_packet_count to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->max_packet_count = val;
+       return retval;
+}
+
+int dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+       int num_chan = hsotg->hwcfg2 >> GHWCFG2_NUM_HOST_CHAN_SHIFT &
+               GHWCFG2_NUM_HOST_CHAN_MASK >> GHWCFG2_NUM_HOST_CHAN_SHIFT;
+
+       if (val < 1 || val > num_chan + 1)
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for host_channels. Check HW configuration.\n",
+                               val);
+               val = num_chan + 1;
+               dev_dbg(hsotg->dev, "Setting host_channels to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->host_channels = val;
+       return retval;
+}
+
+int dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val)
+{
+#ifndef NO_FS_PHY_HW_CHECKS
+       int valid = 0;
+       u32 hs_phy_type;
+       u32 fs_phy_type;
+#endif
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, DWC2_PHY_TYPE_PARAM_FS,
+                           DWC2_PHY_TYPE_PARAM_ULPI)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev, "Wrong value for phy_type\n");
+                       dev_err(hsotg->dev, "phy_type must be 0, 1 or 2\n");
+               }
+
+#ifndef NO_FS_PHY_HW_CHECKS
+               valid = 0;
+#else
+               val = 0;
+               dev_dbg(hsotg->dev, "Setting phy_type to %d\n", val);
+               retval = -EINVAL;
+#endif
+       }
+
+#ifndef NO_FS_PHY_HW_CHECKS
+       hs_phy_type = hsotg->hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK;
+       fs_phy_type = hsotg->hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK;
+
+       if (val == DWC2_PHY_TYPE_PARAM_UTMI &&
+           (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
+            hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
+               valid = 1;
+       else if (val == DWC2_PHY_TYPE_PARAM_ULPI &&
+                (hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI ||
+                 hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
+               valid = 1;
+       else if (val == DWC2_PHY_TYPE_PARAM_FS &&
+                fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED)
+               valid = 1;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for phy_type. Check HW configuration.\n",
+                               val);
+               val = 0;
+               if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) {
+                       if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
+                           hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)
+                               val = DWC2_PHY_TYPE_PARAM_UTMI;
+                       else
+                               val = DWC2_PHY_TYPE_PARAM_ULPI;
+               }
+               dev_dbg(hsotg->dev, "Setting phy_type to %d\n", val);
+               retval = -EINVAL;
+       }
+#endif
+
+       hsotg->core_params->phy_type = val;
+       return retval;
+}
+
+static int dwc2_get_param_phy_type(struct dwc2_hsotg *hsotg)
+{
+       return hsotg->core_params->phy_type;
+}
+
+int dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 0, 1)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev, "Wrong value for speed parameter\n");
+                       dev_err(hsotg->dev, "max_speed parameter must be 0 or 1\n");
+               }
+               valid = 0;
+       }
+
+       if (val == 0 && dwc2_get_param_phy_type(hsotg) ==
+                                       DWC2_PHY_TYPE_PARAM_FS)
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for speed parameter. Check HW configuration.\n",
+                               val);
+               val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS ?
+                               1 : 0;
+               dev_dbg(hsotg->dev, "Setting speed to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->speed = val;
+       return retval;
+}
+
+int dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ,
+                           DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev,
+                               "Wrong value for host_ls_low_power_phy_clk parameter\n");
+                       dev_err(hsotg->dev,
+                               "host_ls_low_power_phy_clk must be 0 or 1\n");
+               }
+               valid = 0;
+       }
+
+       if (val == DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ &&
+           dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS)
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
+                               val);
+               val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS
+                       ? DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ
+                       : DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
+               dev_dbg(hsotg->dev, "Setting host_ls_low_power_phy_clk to %d\n",
+                       val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->host_ls_low_power_phy_clk = val;
+       return retval;
+}
+
+int dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val)
+{
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 0, 1)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev, "Wrong value for phy_ulpi_ddr\n");
+                       dev_err(hsotg->dev, "phy_upli_ddr must be 0 or 1\n");
+               }
+               val = 0;
+               dev_dbg(hsotg->dev, "Setting phy_upli_ddr to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->phy_ulpi_ddr = val;
+       return retval;
+}
+
+int dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val)
+{
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 0, 1)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev,
+                               "Wrong value for phy_ulpi_ext_vbus\n");
+                       dev_err(hsotg->dev,
+                               "phy_ulpi_ext_vbus must be 0 or 1\n");
+               }
+               val = 0;
+               dev_dbg(hsotg->dev, "Setting phy_ulpi_ext_vbus to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->phy_ulpi_ext_vbus = val;
+       return retval;
+}
+
+int dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val)
+{
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 8, 8) && DWC2_PARAM_TEST(val, 16, 16)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev, "Wrong value for phy_utmi_width\n");
+                       dev_err(hsotg->dev, "phy_utmi_width must be 8 or 16\n");
+               }
+               val = 8;
+               dev_dbg(hsotg->dev, "Setting phy_utmi_width to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->phy_utmi_width = val;
+       return retval;
+}
+
+int dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val)
+{
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 0, 1)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev, "Wrong value for ulpi_fs_ls\n");
+                       dev_err(hsotg->dev, "ulpi_fs_ls must be 0 or 1\n");
+               }
+               val = 0;
+               dev_dbg(hsotg->dev, "Setting ulpi_fs_ls to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->ulpi_fs_ls = val;
+       return retval;
+}
+
+int dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val)
+{
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 0, 1)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev, "Wrong value for ts_dline\n");
+                       dev_err(hsotg->dev, "ts_dline must be 0 or 1\n");
+               }
+               val = 0;
+               dev_dbg(hsotg->dev, "Setting ts_dline to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->ts_dline = val;
+       return retval;
+}
+
+int dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val)
+{
+#ifndef NO_FS_PHY_HW_CHECKS
+       int valid = 1;
+#endif
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 0, 1)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev, "Wrong value for i2c_enable\n");
+                       dev_err(hsotg->dev, "i2c_enable must be 0 or 1\n");
+               }
+
+#ifndef NO_FS_PHY_HW_CHECKS
+               valid = 0;
+#else
+               val = 0;
+               dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val);
+               retval = -EINVAL;
+#endif
+       }
+
+#ifndef NO_FS_PHY_HW_CHECKS
+       if (val == 1 && !(hsotg->hwcfg3 & GHWCFG3_I2C))
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for i2c_enable. Check HW configuration.\n",
+                               val);
+               val = !!(hsotg->hwcfg3 & GHWCFG3_I2C);
+               dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val);
+               retval = -EINVAL;
+       }
+#endif
+
+       hsotg->core_params->i2c_enable = val;
+       return retval;
+}
+
+int dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 0, 1)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev,
+                               "Wrong value for en_multiple_tx_fifo,\n");
+                       dev_err(hsotg->dev,
+                               "en_multiple_tx_fifo must be 0 or 1\n");
+               }
+               valid = 0;
+       }
+
+       if (val == 1 && !(hsotg->hwcfg4 & GHWCFG4_DED_FIFO_EN))
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
+                               val);
+               val = !!(hsotg->hwcfg4 & GHWCFG4_DED_FIFO_EN);
+               dev_dbg(hsotg->dev, "Setting en_multiple_tx_fifo to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->en_multiple_tx_fifo = val;
+       return retval;
+}
+
+int dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 0, 1)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev,
+                               "'%d' invalid for parameter reload_ctl\n", val);
+                       dev_err(hsotg->dev, "reload_ctl must be 0 or 1\n");
+               }
+               valid = 0;
+       }
+
+       if (val == 1 && hsotg->snpsid < DWC2_CORE_REV_2_92a)
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for parameter reload_ctl. Check HW configuration.\n",
+                               val);
+               val = hsotg->snpsid >= DWC2_CORE_REV_2_92a;
+               dev_dbg(hsotg->dev, "Setting reload_ctl to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->reload_ctl = val;
+       return retval;
+}
+
+int dwc2_set_param_ahb_single(struct dwc2_hsotg *hsotg, int val)
+{
+       int valid = 1;
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 0, 1)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev,
+                               "'%d' invalid for parameter ahb_single\n", val);
+                       dev_err(hsotg->dev, "ahb_single must be 0 or 1\n");
+               }
+               valid = 0;
+       }
+
+       if (val > 0 && hsotg->snpsid < DWC2_CORE_REV_2_94a)
+               valid = 0;
+
+       if (!valid) {
+               if (val >= 0)
+                       dev_err(hsotg->dev,
+                               "%d invalid for parameter ahb_single. Check HW configuration.\n",
+                               val);
+               val = 0;
+               dev_dbg(hsotg->dev, "Setting ahb_single to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->ahb_single = val;
+       return retval;
+}
+
+int dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val)
+{
+       int retval = 0;
+
+       if (DWC2_PARAM_TEST(val, 0, 1)) {
+               if (val >= 0) {
+                       dev_err(hsotg->dev,
+                               "'%d' invalid for parameter otg_ver\n", val);
+                       dev_err(hsotg->dev,
+                               "otg_ver must be 0 (for OTG 1.3 support) or 1 (for OTG 2.0 support)\n");
+               }
+               val = 0;
+               dev_dbg(hsotg->dev, "Setting otg_ver to %d\n", val);
+               retval = -EINVAL;
+       }
+
+       hsotg->core_params->otg_ver = val;
+       return retval;
+}
+
+/*
+ * This function is called during module intialization to pass module parameters
+ * for the DWC_otg core. It returns non-0 if any parameters are invalid.
+ */
+int dwc2_set_parameters(struct dwc2_hsotg *hsotg,
+                       struct dwc2_core_params *params)
+{
+       int retval = 0;
+
+       dev_dbg(hsotg->dev, "%s()\n", __func__);
+
+       retval |= dwc2_set_param_otg_cap(hsotg, params->otg_cap);
+       retval |= dwc2_set_param_dma_enable(hsotg, params->dma_enable);
+       retval |= dwc2_set_param_dma_desc_enable(hsotg,
+                                                params->dma_desc_enable);
+       retval |= dwc2_set_param_host_support_fs_ls_low_power(hsotg,
+                       params->host_support_fs_ls_low_power);
+       retval |= dwc2_set_param_enable_dynamic_fifo(hsotg,
+                       params->enable_dynamic_fifo);
+       retval |= dwc2_set_param_host_rx_fifo_size(hsotg,
+                       params->host_rx_fifo_size);
+       retval |= dwc2_set_param_host_nperio_tx_fifo_size(hsotg,
+                       params->host_nperio_tx_fifo_size);
+       retval |= dwc2_set_param_host_perio_tx_fifo_size(hsotg,
+                       params->host_perio_tx_fifo_size);
+       retval |= dwc2_set_param_max_transfer_size(hsotg,
+                       params->max_transfer_size);
+       retval |= dwc2_set_param_max_packet_count(hsotg,
+                       params->max_packet_count);
+       retval |= dwc2_set_param_host_channels(hsotg, params->host_channels);
+       retval |= dwc2_set_param_phy_type(hsotg, params->phy_type);
+       retval |= dwc2_set_param_speed(hsotg, params->speed);
+       retval |= dwc2_set_param_host_ls_low_power_phy_clk(hsotg,
+                       params->host_ls_low_power_phy_clk);
+       retval |= dwc2_set_param_phy_ulpi_ddr(hsotg, params->phy_ulpi_ddr);
+       retval |= dwc2_set_param_phy_ulpi_ext_vbus(hsotg,
+                       params->phy_ulpi_ext_vbus);
+       retval |= dwc2_set_param_phy_utmi_width(hsotg, params->phy_utmi_width);
+       retval |= dwc2_set_param_ulpi_fs_ls(hsotg, params->ulpi_fs_ls);
+       retval |= dwc2_set_param_ts_dline(hsotg, params->ts_dline);
+       retval |= dwc2_set_param_i2c_enable(hsotg, params->i2c_enable);
+       retval |= dwc2_set_param_en_multiple_tx_fifo(hsotg,
+                       params->en_multiple_tx_fifo);
+       retval |= dwc2_set_param_reload_ctl(hsotg, params->reload_ctl);
+       retval |= dwc2_set_param_ahb_single(hsotg, params->ahb_single);
+       retval |= dwc2_set_param_otg_ver(hsotg, params->otg_ver);
+
+       return retval;
+}
+
+u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg)
+{
+       return (u16)(hsotg->core_params->otg_ver == 1 ? 0x0200 : 0x0103);
+}
+
+int dwc2_check_core_status(struct dwc2_hsotg *hsotg)
+{
+       if (readl(hsotg->regs + GSNPSID) == 0xffffffff)
+               return -1;
+       else
+               return 0;
+}
+
+/**
+ * dwc2_enable_global_interrupts() - Enables the controller's Global
+ * Interrupt in the AHB Config register
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ */
+void dwc2_enable_global_interrupts(struct dwc2_hsotg *hsotg)
+{
+       u32 ahbcfg = readl(hsotg->regs + GAHBCFG);
+
+       ahbcfg |= GAHBCFG_GLBL_INTR_EN;
+       writel(ahbcfg, hsotg->regs + GAHBCFG);
+}
+
+/**
+ * dwc2_disable_global_interrupts() - Disables the controller's Global
+ * Interrupt in the AHB Config register
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ */
+void dwc2_disable_global_interrupts(struct dwc2_hsotg *hsotg)
+{
+       u32 ahbcfg = readl(hsotg->regs + GAHBCFG);
+
+       ahbcfg &= ~GAHBCFG_GLBL_INTR_EN;
+       writel(ahbcfg, hsotg->regs + GAHBCFG);
+}
+
+MODULE_DESCRIPTION("DESIGNWARE HS OTG Core");
+MODULE_AUTHOR("Synopsys, Inc.");
+MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/staging/dwc2/core.h b/drivers/staging/dwc2/core.h
new file mode 100644 (file)
index 0000000..f8ee04b
--- /dev/null
@@ -0,0 +1,658 @@
+/*
+ * core.h - DesignWare HS OTG Controller common declarations
+ *
+ * Copyright (C) 2004-2013 Synopsys, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. 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.
+ * 3. The names of the above-listed copyright holders may not 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 the 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 OWNER 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 __DWC2_CORE_H__
+#define __DWC2_CORE_H__
+
+#include <linux/usb/phy.h>
+#include "hw.h"
+
+#ifdef DWC2_LOG_WRITES
+static inline void do_write(u32 value, void *addr)
+{
+       writel(value, addr);
+       pr_info("INFO:: wrote %08x to %p\n", value, addr);
+}
+
+#undef writel
+#define writel(v, a)   do_write(v, a)
+#endif
+
+/* Maximum number of Endpoints/HostChannels */
+#define MAX_EPS_CHANNELS       16
+
+struct dwc2_hsotg;
+struct dwc2_host_chan;
+
+/* Device States */
+enum dwc2_lx_state {
+       DWC2_L0,        /* On state */
+       DWC2_L1,        /* LPM sleep state */
+       DWC2_L2,        /* USB suspend state */
+       DWC2_L3,        /* Off state */
+};
+
+/**
+ * struct dwc2_core_params - Parameters for configuring the core
+ *
+ * @otg_cap:            Specifies the OTG capabilities. The driver will
+ *                      automatically detect the value for this parameter if
+ *                      none is specified.
+ *                       0 - HNP and SRP capable (default)
+ *                       1 - SRP Only capable
+ *                       2 - No HNP/SRP capable
+ * @dma_enable:         Specifies whether to use slave or DMA mode for accessing
+ *                      the data FIFOs. The driver will automatically detect the
+ *                      value for this parameter if none is specified.
+ *                       0 - Slave
+ *                       1 - DMA (default, if available)
+ * @dma_desc_enable:    When DMA mode is enabled, specifies whether to use
+ *                      address DMA mode or descriptor DMA mode for accessing
+ *                      the data FIFOs. The driver will automatically detect the
+ *                      value for this if none is specified.
+ *                       0 - Address DMA
+ *                       1 - Descriptor DMA (default, if available)
+ * @speed:              Specifies the maximum speed of operation in host and
+ *                      device mode. The actual speed depends on the speed of
+ *                      the attached device and the value of phy_type.
+ *                       0 - High Speed (default)
+ *                       1 - Full Speed
+ * @host_support_fs_ls_low_power: Specifies whether low power mode is supported
+ *                      when attached to a Full Speed or Low Speed device in
+ *                      host mode.
+ *                       0 - Don't support low power mode (default)
+ *                       1 - Support low power mode
+ * @host_ls_low_power_phy_clk: Specifies the PHY clock rate in low power mode
+ *                      when connected to a Low Speed device in host mode. This
+ *                      parameter is applicable only if
+ *                      host_support_fs_ls_low_power is enabled. If phy_type is
+ *                      set to FS then defaults to 6 MHZ otherwise 48 MHZ.
+ *                       0 - 48 MHz
+ *                       1 - 6 MHz
+ * @enable_dynamic_fifo: 0 - Use coreConsultant-specified FIFO size parameters
+ *                       1 - Allow dynamic FIFO sizing (default)
+ * @host_rx_fifo_size:  Number of 4-byte words in the Rx FIFO in host mode when
+ *                      dynamic FIFO sizing is enabled
+ *                       16 to 32768 (default 1024)
+ * @host_nperio_tx_fifo_size: Number of 4-byte words in the non-periodic Tx FIFO
+ *                      in host mode when dynamic FIFO sizing is enabled
+ *                       16 to 32768 (default 1024)
+ * @host_perio_tx_fifo_size: Number of 4-byte words in the periodic Tx FIFO in
+ *                      host mode when dynamic FIFO sizing is enabled
+ *                       16 to 32768 (default 1024)
+ * @max_transfer_size:  The maximum transfer size supported, in bytes
+ *                       2047 to 65,535 (default 65,535)
+ * @max_packet_count:   The maximum number of packets in a transfer
+ *                       15 to 511 (default 511)
+ * @host_channels:      The number of host channel registers to use
+ *                       1 to 16 (default 12)
+ * @phy_type:           Specifies the type of PHY interface to use. By default,
+ *                      the driver will automatically detect the phy_type.
+ * @phy_utmi_width:     Specifies the UTMI+ Data Width (in bits). This parameter
+ *                      is applicable for a phy_type of UTMI+ or ULPI. (For a
+ *                      ULPI phy_type, this parameter indicates the data width
+ *                      between the MAC and the ULPI Wrapper.) Also, this
+ *                      parameter is applicable only if the OTG_HSPHY_WIDTH cC
+ *                      parameter was set to "8 and 16 bits", meaning that the
+ *                      core has been configured to work at either data path
+ *                      width.
+ *                       8 or 16 (default 16)
+ * @phy_ulpi_ddr:       Specifies whether the ULPI operates at double or single
+ *                      data rate. This parameter is only applicable if phy_type
+ *                      is ULPI.
+ *                       0 - single data rate ULPI interface with 8 bit wide
+ *                           data bus (default)
+ *                       1 - double data rate ULPI interface with 4 bit wide
+ *                           data bus
+ * @phy_ulpi_ext_vbus:  For a ULPI phy, specifies whether to use the internal or
+ *                      external supply to drive the VBus
+ * @i2c_enable:         Specifies whether to use the I2Cinterface for a full
+ *                      speed PHY. This parameter is only applicable if phy_type
+ *                      is FS.
+ *                       0 - No (default)
+ *                       1 - Yes
+ * @ulpi_fs_ls:         True to make ULPI phy operate in FS/LS mode only
+ * @ts_dline:           True to enable Term Select Dline pulsing
+ * @en_multiple_tx_fifo: Specifies whether dedicated per-endpoint transmit FIFOs
+ *                      are enabled
+ * @reload_ctl:         True to allow dynamic reloading of HFIR register during
+ *                      runtime
+ * @ahb_single:         This bit enables SINGLE transfers for remainder data in
+ *                      a transfer for DMA mode of operation.
+ *                       0 - remainder data will be sent using INCR burst size
+ *                       1 - remainder data will be sent using SINGLE burst size
+ * @otg_ver:            OTG version supported
+ *                       0 - 1.3
+ *                       1 - 2.0
+ *
+ * The following parameters may be specified when starting the module. These
+ * parameters define how the DWC_otg controller should be configured.
+ */
+struct dwc2_core_params {
+       int otg_cap;
+       int otg_ver;
+       int dma_enable;
+       int dma_desc_enable;
+       int speed;
+       int enable_dynamic_fifo;
+       int en_multiple_tx_fifo;
+       int host_rx_fifo_size;
+       int host_nperio_tx_fifo_size;
+       int host_perio_tx_fifo_size;
+       int max_transfer_size;
+       int max_packet_count;
+       int host_channels;
+       int phy_type;
+       int phy_utmi_width;
+       int phy_ulpi_ddr;
+       int phy_ulpi_ext_vbus;
+       int i2c_enable;
+       int ulpi_fs_ls;
+       int host_support_fs_ls_low_power;
+       int host_ls_low_power_phy_clk;
+       int ts_dline;
+       int reload_ctl;
+       int ahb_single;
+};
+
+/**
+ * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
+ * and periodic schedules
+ *
+ * @dev:                The struct device pointer
+ * @regs:              Pointer to controller regs
+ * @core_params:        Parameters that define how the core should be configured
+ * @hwcfg1:             Hardware Configuration - stored here for convenience
+ * @hwcfg2:             Hardware Configuration - stored here for convenience
+ * @hwcfg3:             Hardware Configuration - stored here for convenience
+ * @hwcfg4:             Hardware Configuration - stored here for convenience
+ * @hptxfsiz:           Hardware Configuration - stored here for convenience
+ * @snpsid:             Value from SNPSID register
+ * @total_fifo_size:    Total internal RAM for FIFOs (bytes)
+ * @rx_fifo_size:       Size of Rx FIFO (bytes)
+ * @nperio_tx_fifo_size: Size of Non-periodic Tx FIFO (Bytes)
+ * @op_state:           The operational State, during transitions (a_host=>
+ *                      a_peripheral and b_device=>b_host) this may not match
+ *                      the core, but allows the software to determine
+ *                      transitions
+ * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
+ *                      transfer are in process of being queued
+ * @srp_success:        Stores status of SRP request in the case of a FS PHY
+ *                      with an I2C interface
+ * @wq_otg:             Workqueue object used for handling of some interrupts
+ * @wf_otg:             Work object for handling Connector ID Status Change
+ *                      interrupt
+ * @wkp_timer:          Timer object for handling Wakeup Detected interrupt
+ * @lx_state:           Lx state of connected device
+ * @flags:              Flags for handling root port state changes
+ * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule.
+ *                      Transfers associated with these QHs are not currently
+ *                      assigned to a host channel.
+ * @non_periodic_sched_active: Active QHs in the non-periodic schedule.
+ *                      Transfers associated with these QHs are currently
+ *                      assigned to a host channel.
+ * @non_periodic_qh_ptr: Pointer to next QH to process in the active
+ *                      non-periodic schedule
+ * @periodic_sched_inactive: Inactive QHs in the periodic schedule. This is a
+ *                      list of QHs for periodic transfers that are _not_
+ *                      scheduled for the next frame. Each QH in the list has an
+ *                      interval counter that determines when it needs to be
+ *                      scheduled for execution. This scheduling mechanism
+ *                      allows only a simple calculation for periodic bandwidth
+ *                      used (i.e. must assume that all periodic transfers may
+ *                      need to execute in the same frame). However, it greatly
+ *                      simplifies scheduling and should be sufficient for the
+ *                      vast majority of OTG hosts, which need to connect to a
+ *                      small number of peripherals at one time. Items move from
+ *                      this list to periodic_sched_ready when the QH interval
+ *                      counter is 0 at SOF.
+ * @periodic_sched_ready:  List of periodic QHs that are ready for execution in
+ *                      the next frame, but have not yet been assigned to host
+ *                      channels. Items move from this list to
+ *                      periodic_sched_assigned as host channels become
+ *                      available during the current frame.
+ * @periodic_sched_assigned: List of periodic QHs to be executed in the next
+ *                      frame that are assigned to host channels. Items move
+ *                      from this list to periodic_sched_queued as the
+ *                      transactions for the QH are queued to the DWC_otg
+ *                      controller.
+ * @periodic_sched_queued: List of periodic QHs that have been queued for
+ *                      execution. Items move from this list to either
+ *                      periodic_sched_inactive or periodic_sched_ready when the
+ *                      channel associated with the transfer is released. If the
+ *                      interval for the QH is 1, the item moves to
+ *                      periodic_sched_ready because it must be rescheduled for
+ *                      the next frame. Otherwise, the item moves to
+ *                      periodic_sched_inactive.
+ * @periodic_usecs:     Total bandwidth claimed so far for periodic transfers.
+ *                      This value is in microseconds per (micro)frame. The
+ *                      assumption is that all periodic transfers may occur in
+ *                      the same (micro)frame.
+ * @frame_number:       Frame number read from the core at SOF. The value ranges
+ *                      from 0 to HFNUM_MAX_FRNUM.
+ * @periodic_qh_count:  Count of periodic QHs, if using several eps. Used for
+ *                      SOF enable/disable.
+ * @free_hc_list:       Free host channels in the controller. This is a list of
+ *                      struct dwc2_host_chan items.
+ * @periodic_channels:  Number of host channels assigned to periodic transfers.
+ *                      Currently assuming that there is a dedicated host
+ *                      channel for each periodic transaction and at least one
+ *                      host channel is available for non-periodic transactions.
+ * @non_periodic_channels: Number of host channels assigned to non-periodic
+ *                      transfers
+ * @hc_ptr_array:       Array of pointers to the host channel descriptors.
+ *                      Allows accessing a host channel descriptor given the
+ *                      host channel number. This is useful in interrupt
+ *                      handlers.
+ * @status_buf:         Buffer used for data received during the status phase of
+ *                      a control transfer.
+ * @status_buf_dma:     DMA address for status_buf
+ * @start_work:         Delayed work for handling host A-cable connection
+ * @reset_work:         Delayed work for handling a port reset
+ * @lock:               Spinlock that protects all the driver data structures
+ * @priv:               Stores a pointer to the struct usb_hcd
+ * @otg_port:           OTG port number
+ * @frame_list:         Frame list
+ * @frame_list_dma:     Frame list DMA address
+ */
+struct dwc2_hsotg {
+       struct device *dev;
+       void __iomem *regs;
+       struct dwc2_core_params *core_params;
+       u32 hwcfg1;
+       u32 hwcfg2;
+       u32 hwcfg3;
+       u32 hwcfg4;
+       u32 hptxfsiz;
+       u32 snpsid;
+       u16 total_fifo_size;
+       u16 rx_fifo_size;
+       u16 nperio_tx_fifo_size;
+       enum usb_otg_state op_state;
+
+       unsigned int queuing_high_bandwidth:1;
+       unsigned int srp_success:1;
+
+       struct workqueue_struct *wq_otg;
+       struct work_struct wf_otg;
+       struct timer_list wkp_timer;
+       enum dwc2_lx_state lx_state;
+
+       union dwc2_hcd_internal_flags {
+               u32 d32;
+               struct {
+                       unsigned port_connect_status_change:1;
+                       unsigned port_connect_status:1;
+                       unsigned port_reset_change:1;
+                       unsigned port_enable_change:1;
+                       unsigned port_suspend_change:1;
+                       unsigned port_over_current_change:1;
+                       unsigned port_l1_change:1;
+                       unsigned reserved:26;
+               } b;
+       } flags;
+
+       struct list_head non_periodic_sched_inactive;
+       struct list_head non_periodic_sched_active;
+       struct list_head *non_periodic_qh_ptr;
+       struct list_head periodic_sched_inactive;
+       struct list_head periodic_sched_ready;
+       struct list_head periodic_sched_assigned;
+       struct list_head periodic_sched_queued;
+       u16 periodic_usecs;
+       u16 frame_number;
+       u16 periodic_qh_count;
+
+#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
+#define FRAME_NUM_ARRAY_SIZE 1000
+       u16 last_frame_num;
+       u16 *frame_num_array;
+       u16 *last_frame_num_array;
+       int frame_num_idx;
+       int dumped_frame_num_array;
+#endif
+
+       struct list_head free_hc_list;
+       int periodic_channels;
+       int non_periodic_channels;
+       struct dwc2_host_chan *hc_ptr_array[MAX_EPS_CHANNELS];
+       u8 *status_buf;
+       dma_addr_t status_buf_dma;
+#define DWC2_HCD_STATUS_BUF_SIZE 64
+
+       struct delayed_work start_work;
+       struct delayed_work reset_work;
+       spinlock_t lock;
+       void *priv;
+       u8 otg_port;
+       u32 *frame_list;
+       dma_addr_t frame_list_dma;
+
+       /* DWC OTG HW Release versions */
+#define DWC2_CORE_REV_2_71a    0x4f54271a
+#define DWC2_CORE_REV_2_90a    0x4f54290a
+#define DWC2_CORE_REV_2_92a    0x4f54292a
+#define DWC2_CORE_REV_2_94a    0x4f54294a
+#define DWC2_CORE_REV_3_00a    0x4f54300a
+
+#ifdef DEBUG
+       u32 frrem_samples;
+       u64 frrem_accum;
+
+       u32 hfnum_7_samples_a;
+       u64 hfnum_7_frrem_accum_a;
+       u32 hfnum_0_samples_a;
+       u64 hfnum_0_frrem_accum_a;
+       u32 hfnum_other_samples_a;
+       u64 hfnum_other_frrem_accum_a;
+
+       u32 hfnum_7_samples_b;
+       u64 hfnum_7_frrem_accum_b;
+       u32 hfnum_0_samples_b;
+       u64 hfnum_0_frrem_accum_b;
+       u32 hfnum_other_samples_b;
+       u64 hfnum_other_frrem_accum_b;
+#endif
+};
+
+/* Reasons for halting a host channel */
+enum dwc2_halt_status {
+       DWC2_HC_XFER_NO_HALT_STATUS,
+       DWC2_HC_XFER_COMPLETE,
+       DWC2_HC_XFER_URB_COMPLETE,
+       DWC2_HC_XFER_ACK,
+       DWC2_HC_XFER_NAK,
+       DWC2_HC_XFER_NYET,
+       DWC2_HC_XFER_STALL,
+       DWC2_HC_XFER_XACT_ERR,
+       DWC2_HC_XFER_FRAME_OVERRUN,
+       DWC2_HC_XFER_BABBLE_ERR,
+       DWC2_HC_XFER_DATA_TOGGLE_ERR,
+       DWC2_HC_XFER_AHB_ERR,
+       DWC2_HC_XFER_PERIODIC_INCOMPLETE,
+       DWC2_HC_XFER_URB_DEQUEUE,
+};
+
+/*
+ * The following functions support initialization of the core driver component
+ * and the DWC_otg controller
+ */
+extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg);
+
+/*
+ * Host core Functions.
+ * The following functions support managing the DWC_otg controller in host
+ * mode.
+ */
+extern void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan);
+extern void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
+                        enum dwc2_halt_status halt_status);
+extern void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg,
+                           struct dwc2_host_chan *chan);
+extern void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
+                                  struct dwc2_host_chan *chan);
+extern void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
+                                       struct dwc2_host_chan *chan);
+extern int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
+                                    struct dwc2_host_chan *chan);
+extern void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg,
+                           struct dwc2_host_chan *chan);
+extern void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg);
+extern void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg);
+
+extern u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg);
+extern int dwc2_check_core_status(struct dwc2_hsotg *hsotg);
+
+/*
+ * Common core Functions.
+ * The following functions support managing the DWC_otg controller in either
+ * device or host mode.
+ */
+extern void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes);
+extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num);
+extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg);
+
+extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy);
+extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd);
+extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd);
+
+/* This function should be called on every hardware interrupt. */
+extern irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
+
+/* OTG Core Parameters */
+
+/*
+ * Specifies the OTG capabilities. The driver will automatically
+ * detect the value for this parameter if none is specified.
+ * 0 - HNP and SRP capable (default)
+ * 1 - SRP Only capable
+ * 2 - No HNP/SRP capable
+ */
+extern int dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val);
+#define DWC2_CAP_PARAM_HNP_SRP_CAPABLE         0
+#define DWC2_CAP_PARAM_SRP_ONLY_CAPABLE                1
+#define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE      2
+
+/*
+ * Specifies whether to use slave or DMA mode for accessing the data
+ * FIFOs. The driver will automatically detect the value for this
+ * parameter if none is specified.
+ * 0 - Slave
+ * 1 - DMA (default, if available)
+ */
+extern int dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val);
+
+/*
+ * When DMA mode is enabled specifies whether to use
+ * address DMA or DMA Descritor mode for accessing the data
+ * FIFOs in device mode. The driver will automatically detect
+ * the value for this parameter if none is specified.
+ * 0 - address DMA
+ * 1 - DMA Descriptor(default, if available)
+ */
+extern int dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val);
+
+/*
+ * Specifies the maximum speed of operation in host and device mode.
+ * The actual speed depends on the speed of the attached device and
+ * the value of phy_type. The actual speed depends on the speed of the
+ * attached device.
+ * 0 - High Speed (default)
+ * 1 - Full Speed
+ */
+extern int dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val);
+#define DWC2_SPEED_PARAM_HIGH  0
+#define DWC2_SPEED_PARAM_FULL  1
+
+/*
+ * Specifies whether low power mode is supported when attached
+ * to a Full Speed or Low Speed device in host mode.
+ *
+ * 0 - Don't support low power mode (default)
+ * 1 - Support low power mode
+ */
+extern int dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg,
+                                                      int val);
+
+/*
+ * Specifies the PHY clock rate in low power mode when connected to a
+ * Low Speed device in host mode. This parameter is applicable only if
+ * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
+ * then defaults to 6 MHZ otherwise 48 MHZ.
+ *
+ * 0 - 48 MHz
+ * 1 - 6 MHz
+ */
+extern int dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg,
+                                                   int val);
+#define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ     0
+#define DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ      1
+
+/*
+ * 0 - Use cC FIFO size parameters
+ * 1 - Allow dynamic FIFO sizing (default)
+ */
+extern int dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg,
+                                             int val);
+
+/*
+ * Number of 4-byte words in the Rx FIFO in host mode when dynamic
+ * FIFO sizing is enabled.
+ * 16 to 32768 (default 1024)
+ */
+extern int dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val);
+
+/*
+ * Number of 4-byte words in the non-periodic Tx FIFO in host mode
+ * when Dynamic FIFO sizing is enabled in the core.
+ * 16 to 32768 (default 256)
+ */
+extern int dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg,
+                                                  int val);
+
+/*
+ * Number of 4-byte words in the host periodic Tx FIFO when dynamic
+ * FIFO sizing is enabled.
+ * 16 to 32768 (default 256)
+ */
+extern int dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg,
+                                                 int val);
+
+/*
+ * The maximum transfer size supported in bytes.
+ * 2047 to 65,535  (default 65,535)
+ */
+extern int dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val);
+
+/*
+ * The maximum number of packets in a transfer.
+ * 15 to 511  (default 511)
+ */
+extern int dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val);
+
+/*
+ * The number of host channel registers to use.
+ * 1 to 16 (default 11)
+ * Note: The FPGA configuration supports a maximum of 11 host channels.
+ */
+extern int dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val);
+
+/*
+ * Specifies the type of PHY interface to use. By default, the driver
+ * will automatically detect the phy_type.
+ *
+ * 0 - Full Speed PHY
+ * 1 - UTMI+ (default)
+ * 2 - ULPI
+ */
+extern int dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val);
+#define DWC2_PHY_TYPE_PARAM_FS         0
+#define DWC2_PHY_TYPE_PARAM_UTMI       1
+#define DWC2_PHY_TYPE_PARAM_ULPI       2
+
+/*
+ * Specifies the UTMI+ Data Width. This parameter is
+ * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
+ * PHY_TYPE, this parameter indicates the data width between
+ * the MAC and the ULPI Wrapper.) Also, this parameter is
+ * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
+ * to "8 and 16 bits", meaning that the core has been
+ * configured to work at either data path width.
+ *
+ * 8 or 16 bits (default 16)
+ */
+extern int dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val);
+
+/*
+ * Specifies whether the ULPI operates at double or single
+ * data rate. This parameter is only applicable if PHY_TYPE is
+ * ULPI.
+ *
+ * 0 - single data rate ULPI interface with 8 bit wide data
+ * bus (default)
+ * 1 - double data rate ULPI interface with 4 bit wide data
+ * bus
+ */
+extern int dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val);
+
+/*
+ * Specifies whether to use the internal or external supply to
+ * drive the vbus with a ULPI phy.
+ */
+extern int dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val);
+#define DWC2_PHY_ULPI_INTERNAL_VBUS    0
+#define DWC2_PHY_ULPI_EXTERNAL_VBUS    1
+
+/*
+ * Specifies whether to use the I2Cinterface for full speed PHY. This
+ * parameter is only applicable if PHY_TYPE is FS.
+ * 0 - No (default)
+ * 1 - Yes
+ */
+extern int dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val);
+
+extern int dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val);
+
+extern int dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val);
+
+/*
+ * Specifies whether dedicated transmit FIFOs are
+ * enabled for non periodic IN endpoints in device mode
+ * 0 - No
+ * 1 - Yes
+ */
+extern int dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg,
+                                             int val);
+
+extern int dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val);
+
+extern int dwc2_set_param_ahb_single(struct dwc2_hsotg *hsotg, int val);
+
+extern int dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
+
+/*
+ * Dump core registers and SPRAM
+ */
+extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
+extern void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg);
+extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);
+
+/*
+ * Return OTG version - either 1.3 or 2.0
+ */
+extern u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg);
+
+#endif /* __DWC2_CORE_H__ */
diff --git a/drivers/staging/dwc2/core_intr.c b/drivers/staging/dwc2/core_intr.c
new file mode 100644 (file)
index 0000000..44c0166
--- /dev/null
@@ -0,0 +1,505 @@
+/*
+ * core_intr.c - DesignWare HS OTG Controller common interrupt handling
+ *
+ * Copyright (C) 2004-2013 Synopsys, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. 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.
+ * 3. The names of the above-listed copyright holders may not 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 the 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 OWNER 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.
+ */
+
+/*
+ * This file contains the common interrupt handlers
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+
+#include <linux/usb/hcd.h>
+#include <linux/usb/ch11.h>
+
+#include "core.h"
+#include "hcd.h"
+
+static const char *dwc2_op_state_str(struct dwc2_hsotg *hsotg)
+{
+#ifdef DEBUG
+       switch (hsotg->op_state) {
+       case OTG_STATE_A_HOST:
+               return "a_host";
+       case OTG_STATE_A_SUSPEND:
+               return "a_suspend";
+       case OTG_STATE_A_PERIPHERAL:
+               return "a_peripheral";
+       case OTG_STATE_B_PERIPHERAL:
+               return "b_peripheral";
+       case OTG_STATE_B_HOST:
+               return "b_host";
+       default:
+               return "unknown";
+       }
+#else
+       return "";
+#endif
+}
+
+/**
+ * dwc2_handle_mode_mismatch_intr() - Logs a mode mismatch warning message
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ */
+static void dwc2_handle_mode_mismatch_intr(struct dwc2_hsotg *hsotg)
+{
+       dev_warn(hsotg->dev, "Mode Mismatch Interrupt: currently in %s mode\n",
+                dwc2_is_host_mode(hsotg) ? "Host" : "Device");
+
+       /* Clear interrupt */
+       writel(GINTSTS_MODEMIS, hsotg->regs + GINTSTS);
+}
+
+/**
+ * dwc2_handle_otg_intr() - Handles the OTG Interrupts. It reads the OTG
+ * Interrupt Register (GOTGINT) to determine what interrupt has occurred.
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ */
+static void dwc2_handle_otg_intr(struct dwc2_hsotg *hsotg)
+{
+       u32 gotgint;
+       u32 gotgctl;
+       u32 gintmsk;
+
+       gotgint = readl(hsotg->regs + GOTGINT);
+       gotgctl = readl(hsotg->regs + GOTGCTL);
+       dev_dbg(hsotg->dev, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint,
+               dwc2_op_state_str(hsotg));
+
+       if (gotgint & GOTGINT_SES_END_DET) {
+               dev_dbg(hsotg->dev,
+                       " ++OTG Interrupt: Session End Detected++ (%s)\n",
+                       dwc2_op_state_str(hsotg));
+               gotgctl = readl(hsotg->regs + GOTGCTL);
+
+               if (hsotg->op_state == OTG_STATE_B_HOST) {
+                       hsotg->op_state = OTG_STATE_B_PERIPHERAL;
+               } else {
+                       /*
+                        * If not B_HOST and Device HNP still set, HNP did
+                        * not succeed!
+                        */
+                       if (gotgctl & GOTGCTL_DEVHNPEN) {
+                               dev_dbg(hsotg->dev, "Session End Detected\n");
+                               dev_err(hsotg->dev,
+                                       "Device Not Connected/Responding!\n");
+                       }
+
+                       /*
+                        * If Session End Detected the B-Cable has been
+                        * disconnected
+                        */
+                       /* Reset to a clean state */
+                       hsotg->lx_state = DWC2_L0;
+               }
+
+               gotgctl = readl(hsotg->regs + GOTGCTL);
+               gotgctl &= ~GOTGCTL_DEVHNPEN;
+               writel(gotgctl, hsotg->regs + GOTGCTL);
+       }
+
+       if (gotgint & GOTGINT_SES_REQ_SUC_STS_CHNG) {
+               dev_dbg(hsotg->dev,
+                       " ++OTG Interrupt: Session Request Success Status Change++\n");
+               gotgctl = readl(hsotg->regs + GOTGCTL);
+               if (gotgctl & GOTGCTL_SESREQSCS) {
+                       if (hsotg->core_params->phy_type ==
+                                       DWC2_PHY_TYPE_PARAM_FS
+                           && hsotg->core_params->i2c_enable > 0) {
+                               hsotg->srp_success = 1;
+                       } else {
+                               /* Clear Session Request */
+                               gotgctl = readl(hsotg->regs + GOTGCTL);
+                               gotgctl &= ~GOTGCTL_SESREQ;
+                               writel(gotgctl, hsotg->regs + GOTGCTL);
+                       }
+               }
+       }
+
+       if (gotgint & GOTGINT_HST_NEG_SUC_STS_CHNG) {
+               /*
+                * Print statements during the HNP interrupt handling
+                * can cause it to fail
+                */
+               gotgctl = readl(hsotg->regs + GOTGCTL);
+               /*
+                * WA for 3.00a- HW is not setting cur_mode, even sometimes
+                * this does not help
+                */
+               if (hsotg->snpsid >= DWC2_CORE_REV_3_00a)
+                       udelay(100);
+               if (gotgctl & GOTGCTL_HSTNEGSCS) {
+                       if (dwc2_is_host_mode(hsotg)) {
+                               hsotg->op_state = OTG_STATE_B_HOST;
+                               /*
+                                * Need to disable SOF interrupt immediately.
+                                * When switching from device to host, the PCD
+                                * interrupt handler won't handle the interrupt
+                                * if host mode is already set. The HCD
+                                * interrupt handler won't get called if the
+                                * HCD state is HALT. This means that the
+                                * interrupt does not get handled and Linux
+                                * complains loudly.
+                                */
+                               gintmsk = readl(hsotg->regs + GINTMSK);
+                               gintmsk &= ~GINTSTS_SOF;
+                               writel(gintmsk, hsotg->regs + GINTMSK);
+
+                               /*
+                                * Call callback function with spin lock
+                                * released
+                                */
+                               spin_unlock(&hsotg->lock);
+
+                               /* Initialize the Core for Host mode */
+                               dwc2_hcd_start(hsotg);
+                               spin_lock(&hsotg->lock);
+                               hsotg->op_state = OTG_STATE_B_HOST;
+                       }
+               } else {
+                       gotgctl = readl(hsotg->regs + GOTGCTL);
+                       gotgctl &= ~(GOTGCTL_HNPREQ | GOTGCTL_DEVHNPEN);
+                       writel(gotgctl, hsotg->regs + GOTGCTL);
+                       dev_dbg(hsotg->dev, "HNP Failed\n");
+                       dev_err(hsotg->dev,
+                               "Device Not Connected/Responding\n");
+               }
+       }
+
+       if (gotgint & GOTGINT_HST_NEG_DET) {
+               /*
+                * The disconnect interrupt is set at the same time as
+                * Host Negotiation Detected. During the mode switch all
+                * interrupts are cleared so the disconnect interrupt
+                * handler will not get executed.
+                */
+               dev_dbg(hsotg->dev,
+                       " ++OTG Interrupt: Host Negotiation Detected++ (%s)\n",
+                       (dwc2_is_host_mode(hsotg) ? "Host" : "Device"));
+               if (dwc2_is_device_mode(hsotg)) {
+                       dev_dbg(hsotg->dev, "a_suspend->a_peripheral (%d)\n",
+                               hsotg->op_state);
+                       spin_unlock(&hsotg->lock);
+                       dwc2_hcd_disconnect(hsotg);
+                       spin_lock(&hsotg->lock);
+                       hsotg->op_state = OTG_STATE_A_PERIPHERAL;
+               } else {
+                       /* Need to disable SOF interrupt immediately */
+                       gintmsk = readl(hsotg->regs + GINTMSK);
+                       gintmsk &= ~GINTSTS_SOF;
+                       writel(gintmsk, hsotg->regs + GINTMSK);
+                       spin_unlock(&hsotg->lock);
+                       dwc2_hcd_start(hsotg);
+                       spin_lock(&hsotg->lock);
+                       hsotg->op_state = OTG_STATE_A_HOST;
+               }
+       }
+
+       if (gotgint & GOTGINT_A_DEV_TOUT_CHG)
+               dev_dbg(hsotg->dev,
+                       " ++OTG Interrupt: A-Device Timeout Change++\n");
+       if (gotgint & GOTGINT_DBNCE_DONE)
+               dev_dbg(hsotg->dev, " ++OTG Interrupt: Debounce Done++\n");
+
+       /* Clear GOTGINT */
+       writel(gotgint, hsotg->regs + GOTGINT);
+}
+
+/**
+ * dwc2_handle_conn_id_status_change_intr() - Handles the Connector ID Status
+ * Change Interrupt
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ *
+ * Reads the OTG Interrupt Register (GOTCTL) to determine whether this is a
+ * Device to Host Mode transition or a Host to Device Mode transition. This only
+ * occurs when the cable is connected/removed from the PHY connector.
+ */
+static void dwc2_handle_conn_id_status_change_intr(struct dwc2_hsotg *hsotg)
+{
+       u32 gintmsk = readl(hsotg->regs + GINTMSK);
+
+       /* Need to disable SOF interrupt immediately */
+       gintmsk &= ~GINTSTS_SOF;
+       writel(gintmsk, hsotg->regs + GINTMSK);
+
+       dev_dbg(hsotg->dev, " ++Connector ID Status Change Interrupt++  (%s)\n",
+               dwc2_is_host_mode(hsotg) ? "Host" : "Device");
+
+       /*
+        * Need to schedule a work, as there are possible DELAY function calls.
+        * Release lock before scheduling workq as it holds spinlock during
+        * scheduling.
+        */
+       spin_unlock(&hsotg->lock);
+       queue_work(hsotg->wq_otg, &hsotg->wf_otg);
+       spin_lock(&hsotg->lock);
+
+       /* Clear interrupt */
+       writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS);
+}
+
+/**
+ * dwc2_handle_session_req_intr() - This interrupt indicates that a device is
+ * initiating the Session Request Protocol to request the host to turn on bus
+ * power so a new session can begin
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ *
+ * This handler responds by turning on bus power. If the DWC_otg controller is
+ * in low power mode, this handler brings the controller out of low power mode
+ * before turning on bus power.
+ */
+static void dwc2_handle_session_req_intr(struct dwc2_hsotg *hsotg)
+{
+       dev_dbg(hsotg->dev, "++Session Request Interrupt++\n");
+
+       /* Clear interrupt */
+       writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS);
+}
+
+/*
+ * This interrupt indicates that the DWC_otg controller has detected a
+ * resume or remote wakeup sequence. If the DWC_otg controller is in
+ * low power mode, the handler must brings the controller out of low
+ * power mode. The controller automatically begins resume signaling.
+ * The handler schedules a time to stop resume signaling.
+ */
+static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg)
+{
+       dev_dbg(hsotg->dev, "++Resume or Remote Wakeup Detected Interrupt++\n");
+       dev_dbg(hsotg->dev, "%s lxstate = %d\n", __func__, hsotg->lx_state);
+
+       if (dwc2_is_device_mode(hsotg)) {
+               dev_dbg(hsotg->dev, "DSTS=0x%0x\n", readl(hsotg->regs + DSTS));
+               if (hsotg->lx_state == DWC2_L2) {
+                       u32 dctl = readl(hsotg->regs + DCTL);
+
+                       /* Clear Remote Wakeup Signaling */
+                       dctl &= ~DCTL_RMTWKUPSIG;
+                       writel(dctl, hsotg->regs + DCTL);
+               }
+               /* Change to L0 state */
+               hsotg->lx_state = DWC2_L0;
+       } else {
+               if (hsotg->lx_state != DWC2_L1) {
+                       u32 pcgcctl = readl(hsotg->regs + PCGCTL);
+
+                       /* Restart the Phy Clock */
+                       pcgcctl &= ~PCGCTL_STOPPCLK;
+                       writel(pcgcctl, hsotg->regs + PCGCTL);
+                       mod_timer(&hsotg->wkp_timer,
+                                 jiffies + msecs_to_jiffies(71));
+               } else {
+                       /* Change to L0 state */
+                       hsotg->lx_state = DWC2_L0;
+               }
+       }
+
+       /* Clear interrupt */
+       writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS);
+}
+
+/*
+ * This interrupt indicates that a device has been disconnected from the
+ * root port
+ */
+static void dwc2_handle_disconnect_intr(struct dwc2_hsotg *hsotg)
+{
+       dev_dbg(hsotg->dev, "++Disconnect Detected Interrupt++ (%s) %s\n",
+               dwc2_is_host_mode(hsotg) ? "Host" : "Device",
+               dwc2_op_state_str(hsotg));
+
+       /* Change to L3 (OFF) state */
+       hsotg->lx_state = DWC2_L3;
+
+       writel(GINTSTS_DISCONNINT, hsotg->regs + GINTSTS);
+}
+
+/*
+ * This interrupt indicates that SUSPEND state has been detected on the USB.
+ *
+ * For HNP the USB Suspend interrupt signals the change from "a_peripheral"
+ * to "a_host".
+ *
+ * When power management is enabled the core will be put in low power mode.
+ */
+static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg)
+{
+       u32 dsts;
+
+       dev_dbg(hsotg->dev, "USB SUSPEND\n");
+
+       if (dwc2_is_device_mode(hsotg)) {
+               /*
+                * Check the Device status register to determine if the Suspend
+                * state is active
+                */
+               dsts = readl(hsotg->regs + DSTS);
+               dev_dbg(hsotg->dev, "DSTS=0x%0x\n", dsts);
+               dev_dbg(hsotg->dev,
+                       "DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d\n",
+                       !!(dsts & DSTS_SUSPSTS),
+                       !!(hsotg->hwcfg4 & GHWCFG4_POWER_OPTIMIZ));
+       } else {
+               if (hsotg->op_state == OTG_STATE_A_PERIPHERAL) {
+                       dev_dbg(hsotg->dev, "a_peripheral->a_host\n");
+
+                       /* Clear the a_peripheral flag, back to a_host */
+                       spin_unlock(&hsotg->lock);
+                       dwc2_hcd_start(hsotg);
+                       spin_lock(&hsotg->lock);
+                       hsotg->op_state = OTG_STATE_A_HOST;
+               }
+       }
+
+       /* Change to L2 (suspend) state */
+       hsotg->lx_state = DWC2_L2;
+
+       /* Clear interrupt */
+       writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS);
+}
+
+#define GINTMSK_COMMON (GINTSTS_WKUPINT | GINTSTS_SESSREQINT |         \
+                        GINTSTS_CONIDSTSCHNG | GINTSTS_OTGINT |        \
+                        GINTSTS_MODEMIS | GINTSTS_DISCONNINT |         \
+                        GINTSTS_USBSUSP | GINTSTS_RESTOREDONE |        \
+                        GINTSTS_PRTINT)
+
+/*
+ * This function returns the Core Interrupt register
+ */
+static u32 dwc2_read_common_intr(struct dwc2_hsotg *hsotg)
+{
+       u32 gintsts;
+       u32 gintmsk;
+       u32 gahbcfg;
+       u32 gintmsk_common = GINTMSK_COMMON;
+
+       gintsts = readl(hsotg->regs + GINTSTS);
+       gintmsk = readl(hsotg->regs + GINTMSK);
+       gahbcfg = readl(hsotg->regs + GAHBCFG);
+
+#ifdef DEBUG
+       /* If any common interrupts set */
+       if (gintsts & gintmsk_common)
+               dev_dbg(hsotg->dev, "gintsts=%08x  gintmsk=%08x\n",
+                       gintsts, gintmsk);
+#endif
+
+       if (gahbcfg & GAHBCFG_GLBL_INTR_EN)
+               return gintsts & gintmsk & gintmsk_common;
+       else
+               return 0;
+}
+
+/*
+ * Common interrupt handler
+ *
+ * The common interrupts are those that occur in both Host and Device mode.
+ * This handler handles the following interrupts:
+ * - Mode Mismatch Interrupt
+ * - OTG Interrupt
+ * - Connector ID Status Change Interrupt
+ * - Disconnect Interrupt
+ * - Session Request Interrupt
+ * - Resume / Remote Wakeup Detected Interrupt
+ * - Suspend Interrupt
+ */
+irqreturn_t dwc2_handle_common_intr(int irq, void *dev)
+{
+       struct dwc2_hsotg *hsotg = dev;
+       u32 gintsts;
+       int retval = 0;
+
+       if (dwc2_check_core_status(hsotg) < 0) {
+               dev_warn(hsotg->dev, "Controller is disconnected");
+               goto out;
+       }
+
+       spin_lock(&hsotg->lock);
+
+       gintsts = dwc2_read_common_intr(hsotg);
+       if (gintsts & ~GINTSTS_PRTINT)
+               retval = 1;
+
+       if (gintsts & GINTSTS_MODEMIS)
+               dwc2_handle_mode_mismatch_intr(hsotg);
+       if (gintsts & GINTSTS_OTGINT)
+               dwc2_handle_otg_intr(hsotg);
+       if (gintsts & GINTSTS_CONIDSTSCHNG)
+               dwc2_handle_conn_id_status_change_intr(hsotg);
+       if (gintsts & GINTSTS_DISCONNINT)
+               dwc2_handle_disconnect_intr(hsotg);
+       if (gintsts & GINTSTS_SESSREQINT)
+               dwc2_handle_session_req_intr(hsotg);
+       if (gintsts & GINTSTS_WKUPINT)
+               dwc2_handle_wakeup_detected_intr(hsotg);
+       if (gintsts & GINTSTS_USBSUSP)
+               dwc2_handle_usb_suspend_intr(hsotg);
+
+       if (gintsts & GINTSTS_RESTOREDONE) {
+               gintsts = GINTSTS_RESTOREDONE;
+               writel(gintsts, hsotg->regs + GINTSTS);
+               dev_dbg(hsotg->dev, " --Restore done interrupt received--\n");
+       }
+
+       if (gintsts & GINTSTS_PRTINT) {
+               /*
+                * The port interrupt occurs while in device mode with HPRT0
+                * Port Enable/Disable
+                */
+               if (dwc2_is_device_mode(hsotg)) {
+                       dev_dbg(hsotg->dev,
+                               " --Port interrupt received in Device mode--\n");
+                       gintsts = GINTSTS_PRTINT;
+                       writel(gintsts, hsotg->regs + GINTSTS);
+                       retval = 1;
+               }
+       }
+
+       spin_unlock(&hsotg->lock);
+out:
+       return IRQ_RETVAL(retval);
+}
+EXPORT_SYMBOL_GPL(dwc2_handle_common_intr);
diff --git a/drivers/staging/dwc2/hcd.c b/drivers/staging/dwc2/hcd.c
new file mode 100644 (file)
index 0000000..91ff504
--- /dev/null
@@ -0,0 +1,2962 @@
+/*
+ * hcd.c - DesignWare HS OTG Controller host-mode routines
+ *
+ * Copyright (C) 2004-2013 Synopsys, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. 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.
+ * 3. The names of the above-listed copyright holders may not 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 the 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 OWNER 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.
+ */
+
+/*
+ * This file contains the core HCD code, and implements the Linux hc_driver
+ * API
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/dma-mapping.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+
+#include <linux/usb/hcd.h>
+#include <linux/usb/ch11.h>
+
+#include "core.h"
+#include "hcd.h"
+
+/**
+ * dwc2_dump_channel_info() - Prints the state of a host channel
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ * @chan:  Pointer to the channel to dump
+ *
+ * Must be called with interrupt disabled and spinlock held
+ *
+ * NOTE: This function will be removed once the peripheral controller code
+ * is integrated and the driver is stable
+ */
+static void dwc2_dump_channel_info(struct dwc2_hsotg *hsotg,
+                                  struct dwc2_host_chan *chan)
+{
+#ifdef VERBOSE_DEBUG
+       int num_channels = hsotg->core_params->host_channels;
+       struct dwc2_qh *qh;
+       u32 hcchar;
+       u32 hcsplt;
+       u32 hctsiz;
+       u32 hc_dma;
+       int i;
+
+       if (chan == NULL)
+               return;
+
+       hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
+       hcsplt = readl(hsotg->regs + HCSPLT(chan->hc_num));
+       hctsiz = readl(hsotg->regs + HCTSIZ(chan->hc_num));
+       hc_dma = readl(hsotg->regs + HCDMA(chan->hc_num));
+
+       dev_dbg(hsotg->dev, "  Assigned to channel %p:\n", chan);
+       dev_dbg(hsotg->dev, "    hcchar 0x%08x, hcsplt 0x%08x\n",
+               hcchar, hcsplt);
+       dev_dbg(hsotg->dev, "    hctsiz 0x%08x, hc_dma 0x%08x\n",
+               hctsiz, hc_dma);
+       dev_dbg(hsotg->dev, "    dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
+               chan->dev_addr, chan->ep_num, chan->ep_is_in);
+       dev_dbg(hsotg->dev, "    ep_type: %d\n", chan->ep_type);
+       dev_dbg(hsotg->dev, "    max_packet: %d\n", chan->max_packet);
+       dev_dbg(hsotg->dev, "    data_pid_start: %d\n", chan->data_pid_start);
+       dev_dbg(hsotg->dev, "    xfer_started: %d\n", chan->xfer_started);
+       dev_dbg(hsotg->dev, "    halt_status: %d\n", chan->halt_status);
+       dev_dbg(hsotg->dev, "    xfer_buf: %p\n", chan->xfer_buf);
+       dev_dbg(hsotg->dev, "    xfer_dma: %08lx\n",
+               (unsigned long)chan->xfer_dma);
+       dev_dbg(hsotg->dev, "    xfer_len: %d\n", chan->xfer_len);
+       dev_dbg(hsotg->dev, "    qh: %p\n", chan->qh);
+       dev_dbg(hsotg->dev, "  NP inactive sched:\n");
+       list_for_each_entry(qh, &hsotg->non_periodic_sched_inactive,
+                           qh_list_entry)
+               dev_dbg(hsotg->dev, "    %p\n", qh);
+       dev_dbg(hsotg->dev, "  NP active sched:\n");
+       list_for_each_entry(qh, &hsotg->non_periodic_sched_active,
+                           qh_list_entry)
+               dev_dbg(hsotg->dev, "    %p\n", qh);
+       dev_dbg(hsotg->dev, "  Channels:\n");
+       for (i = 0; i < num_channels; i++) {
+               struct dwc2_host_chan *chan = hsotg->hc_ptr_array[i];
+
+               dev_dbg(hsotg->dev, "    %2d: %p\n", i, chan);
+       }
+#endif /* VERBOSE_DEBUG */
+}
+
+/*
+ * Processes all the URBs in a single list of QHs. Completes them with
+ * -ETIMEDOUT and frees the QTD.
+ *
+ * Must be called with interrupt disabled and spinlock held
+ */
+static void dwc2_kill_urbs_in_qh_list(struct dwc2_hsotg *hsotg,
+                                     struct list_head *qh_list)
+{
+       struct dwc2_qh *qh, *qh_tmp;
+       struct dwc2_qtd *qtd, *qtd_tmp;
+
+       list_for_each_entry_safe(qh, qh_tmp, qh_list, qh_list_entry) {
+               list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list,
+                                        qtd_list_entry) {
+                       if (qtd->urb != NULL) {
+                               dwc2_host_complete(hsotg, qtd->urb->priv,
+                                                  qtd->urb, -ETIMEDOUT);
+                               dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
+                       }
+               }
+       }
+}
+
+static void dwc2_qh_list_free(struct dwc2_hsotg *hsotg,
+                             struct list_head *qh_list)
+{
+       struct dwc2_qtd *qtd, *qtd_tmp;
+       struct dwc2_qh *qh, *qh_tmp;
+       unsigned long flags;
+
+       if (!qh_list->next)
+               /* The list hasn't been initialized yet */
+               return;
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+
+       /* Ensure there are no QTDs or URBs left */
+       dwc2_kill_urbs_in_qh_list(hsotg, qh_list);
+
+       list_for_each_entry_safe(qh, qh_tmp, qh_list, qh_list_entry) {
+               dwc2_hcd_qh_unlink(hsotg, qh);
+
+               /* Free each QTD in the QH's QTD list */
+               list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list,
+                                        qtd_list_entry)
+                       dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
+
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+               dwc2_hcd_qh_free(hsotg, qh);
+               spin_lock_irqsave(&hsotg->lock, flags);
+       }
+
+       spin_unlock_irqrestore(&hsotg->lock, flags);
+}
+
+/*
+ * Responds with an error status of -ETIMEDOUT to all URBs in the non-periodic
+ * and periodic schedules. The QTD associated with each URB is removed from
+ * the schedule and freed. This function may be called when a disconnect is
+ * detected or when the HCD is being stopped.
+ *
+ * Must be called with interrupt disabled and spinlock held
+ */
+static void dwc2_kill_all_urbs(struct dwc2_hsotg *hsotg)
+{
+       dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_inactive);
+       dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->non_periodic_sched_active);
+       dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_inactive);
+       dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_ready);
+       dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_assigned);
+       dwc2_kill_urbs_in_qh_list(hsotg, &hsotg->periodic_sched_queued);
+}
+
+/**
+ * dwc2_hcd_start() - Starts the HCD when switching to Host mode
+ *
+ * @hsotg: Pointer to struct dwc2_hsotg
+ */
+void dwc2_hcd_start(struct dwc2_hsotg *hsotg)
+{
+       u32 hprt0;
+
+       if (hsotg->op_state == OTG_STATE_B_HOST) {
+               /*
+                * Reset the port. During a HNP mode switch the reset
+                * needs to occur within 1ms and have a duration of at
+                * least 50ms.
+                */
+               hprt0 = dwc2_read_hprt0(hsotg);
+               hprt0 |= HPRT0_RST;
+               writel(hprt0, hsotg->regs + HPRT0);
+       }
+
+       queue_delayed_work(hsotg->wq_otg, &hsotg->start_work,
+                          msecs_to_jiffies(50));
+}
+
+/* Must be called with interrupt disabled and spinlock held */
+static void dwc2_hcd_cleanup_channels(struct dwc2_hsotg *hsotg)
+{
+       int num_channels = hsotg->core_params->host_channels;
+       struct dwc2_host_chan *channel;
+       u32 hcchar;
+       int i;
+
+       if (hsotg->core_params->dma_enable <= 0) {
+               /* Flush out any channel requests in slave mode */
+               for (i = 0; i < num_channels; i++) {
+                       channel = hsotg->hc_ptr_array[i];
+                       if (!list_empty(&channel->hc_list_entry))
+                               continue;
+                       hcchar = readl(hsotg->regs + HCCHAR(i));
+                       if (hcchar & HCCHAR_CHENA) {
+                               hcchar &= ~(HCCHAR_CHENA | HCCHAR_EPDIR);
+                               hcchar |= HCCHAR_CHDIS;
+                               writel(hcchar, hsotg->regs + HCCHAR(i));
+                       }
+               }
+       }
+
+       for (i = 0; i < num_channels; i++) {
+               channel = hsotg->hc_ptr_array[i];
+               if (!list_empty(&channel->hc_list_entry))
+                       continue;
+               hcchar = readl(hsotg->regs + HCCHAR(i));
+               if (hcchar & HCCHAR_CHENA) {
+                       /* Halt the channel */
+                       hcchar |= HCCHAR_CHDIS;
+                       writel(hcchar, hsotg->regs + HCCHAR(i));
+               }
+
+               dwc2_hc_cleanup(hsotg, channel);
+               list_add_tail(&channel->hc_list_entry, &hsotg->free_hc_list);
+               /*
+                * Added for Descriptor DMA to prevent channel double cleanup in
+                * release_channel_ddma(), which is called from ep_disable when
+                * device disconnects
+                */
+               channel->qh = NULL;
+       }
+}
+
+/**
+ * dwc2_hcd_disconnect() - Handles disconnect of the HCD
+ *
+ * @hsotg: Pointer to struct dwc2_hsotg
+ *
+ * Must be called with interrupt disabled and spinlock held
+ */
+void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg)
+{
+       u32 intr;
+
+       /* Set status flags for the hub driver */
+       hsotg->flags.b.port_connect_status_change = 1;
+       hsotg->flags.b.port_connect_status = 0;
+
+       /*
+        * Shutdown any transfers in process by clearing the Tx FIFO Empty
+        * interrupt mask and status bits and disabling subsequent host
+        * channel interrupts.
+        */
+       intr = readl(hsotg->regs + GINTMSK);
+       intr &= ~(GINTSTS_NPTXFEMP | GINTSTS_PTXFEMP | GINTSTS_HCHINT);
+       writel(intr, hsotg->regs + GINTMSK);
+       intr = GINTSTS_NPTXFEMP | GINTSTS_PTXFEMP | GINTSTS_HCHINT;
+       writel(intr, hsotg->regs + GINTSTS);
+
+       /*
+        * Turn off the vbus power only if the core has transitioned to device
+        * mode. If still in host mode, need to keep power on to detect a
+        * reconnection.
+        */
+       if (dwc2_is_device_mode(hsotg)) {
+               if (hsotg->op_state != OTG_STATE_A_SUSPEND) {
+                       dev_dbg(hsotg->dev, "Disconnect: PortPower off\n");
+                       writel(0, hsotg->regs + HPRT0);
+               }
+
+               dwc2_disable_host_interrupts(hsotg);
+       }
+
+       /* Respond with an error status to all URBs in the schedule */
+       dwc2_kill_all_urbs(hsotg);
+
+       if (dwc2_is_host_mode(hsotg))
+               /* Clean up any host channels that were in use */
+               dwc2_hcd_cleanup_channels(hsotg);
+
+       dwc2_host_disconnect(hsotg);
+}
+
+/**
+ * dwc2_hcd_rem_wakeup() - Handles Remote Wakeup
+ *
+ * @hsotg: Pointer to struct dwc2_hsotg
+ */
+static void dwc2_hcd_rem_wakeup(struct dwc2_hsotg *hsotg)
+{
+       if (hsotg->lx_state == DWC2_L2)
+               hsotg->flags.b.port_suspend_change = 1;
+       else
+               hsotg->flags.b.port_l1_change = 1;
+}
+
+/**
+ * dwc2_hcd_stop() - Halts the DWC_otg host mode operations in a clean manner
+ *
+ * @hsotg: Pointer to struct dwc2_hsotg
+ *
+ * Must be called with interrupt disabled and spinlock held
+ */
+void dwc2_hcd_stop(struct dwc2_hsotg *hsotg)
+{
+       dev_dbg(hsotg->dev, "DWC OTG HCD STOP\n");
+
+       /*
+        * The root hub should be disconnected before this function is called.
+        * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
+        * and the QH lists (via ..._hcd_endpoint_disable).
+        */
+
+       /* Turn off all host-specific interrupts */
+       dwc2_disable_host_interrupts(hsotg);
+
+       /* Turn off the vbus power */
+       dev_dbg(hsotg->dev, "PortPower off\n");
+       writel(0, hsotg->regs + HPRT0);
+}
+
+static int dwc2_hcd_urb_enqueue(struct dwc2_hsotg *hsotg,
+                               struct dwc2_hcd_urb *urb, void **ep_handle,
+                               gfp_t mem_flags)
+{
+       struct dwc2_qtd *qtd;
+       unsigned long flags;
+       u32 intr_mask;
+       int retval;
+
+       if (!hsotg->flags.b.port_connect_status) {
+               /* No longer connected */
+               dev_err(hsotg->dev, "Not connected\n");
+               return -ENODEV;
+       }
+
+       qtd = kzalloc(sizeof(*qtd), mem_flags);
+       if (!qtd)
+               return -ENOMEM;
+
+       dwc2_hcd_qtd_init(qtd, urb);
+       retval = dwc2_hcd_qtd_add(hsotg, qtd, (struct dwc2_qh **)ep_handle,
+                                 mem_flags);
+       if (retval < 0) {
+               dev_err(hsotg->dev,
+                       "DWC OTG HCD URB Enqueue failed adding QTD. Error status %d\n",
+                       retval);
+               kfree(qtd);
+               return retval;
+       }
+
+       intr_mask = readl(hsotg->regs + GINTMSK);
+       if (!(intr_mask & GINTSTS_SOF) && retval == 0) {
+               enum dwc2_transaction_type tr_type;
+
+               if (qtd->qh->ep_type == USB_ENDPOINT_XFER_BULK &&
+                   !(qtd->urb->flags & URB_GIVEBACK_ASAP))
+                       /*
+                        * Do not schedule SG transactions until qtd has
+                        * URB_GIVEBACK_ASAP set
+                        */
+                       return 0;
+
+               spin_lock_irqsave(&hsotg->lock, flags);
+               tr_type = dwc2_hcd_select_transactions(hsotg);
+               if (tr_type != DWC2_TRANSACTION_NONE)
+                       dwc2_hcd_queue_transactions(hsotg, tr_type);
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+       }
+
+       return retval;
+}
+
+/* Must be called with interrupt disabled and spinlock held */
+static int dwc2_hcd_urb_dequeue(struct dwc2_hsotg *hsotg,
+                               struct dwc2_hcd_urb *urb)
+{
+       struct dwc2_qh *qh;
+       struct dwc2_qtd *urb_qtd;
+
+       urb_qtd = urb->qtd;
+       if (!urb_qtd) {
+               dev_dbg(hsotg->dev, "## Urb QTD is NULL ##\n");
+               return -EINVAL;
+       }
+
+       qh = urb_qtd->qh;
+       if (!qh) {
+               dev_dbg(hsotg->dev, "## Urb QTD QH is NULL ##\n");
+               return -EINVAL;
+       }
+
+       if (urb_qtd->in_process && qh->channel) {
+               dwc2_dump_channel_info(hsotg, qh->channel);
+
+               /* The QTD is in process (it has been assigned to a channel) */
+               if (hsotg->flags.b.port_connect_status)
+                       /*
+                        * If still connected (i.e. in host mode), halt the
+                        * channel so it can be used for other transfers. If
+                        * no longer connected, the host registers can't be
+                        * written to halt the channel since the core is in
+                        * device mode.
+                        */
+                       dwc2_hc_halt(hsotg, qh->channel,
+                                    DWC2_HC_XFER_URB_DEQUEUE);
+       }
+
+       /*
+        * Free the QTD and clean up the associated QH. Leave the QH in the
+        * schedule if it has any remaining QTDs.
+        */
+       if (hsotg->core_params->dma_desc_enable <= 0) {
+               u8 in_process = urb_qtd->in_process;
+
+               dwc2_hcd_qtd_unlink_and_free(hsotg, urb_qtd, qh);
+               if (in_process) {
+                       dwc2_hcd_qh_deactivate(hsotg, qh, 0);
+                       qh->channel = NULL;
+               } else if (list_empty(&qh->qtd_list)) {
+                       dwc2_hcd_qh_unlink(hsotg, qh);
+               }
+       } else {
+               dwc2_hcd_qtd_unlink_and_free(hsotg, urb_qtd, qh);
+       }
+
+       return 0;
+}
+
+/* Must NOT be called with interrupt disabled or spinlock held */
+static int dwc2_hcd_endpoint_disable(struct dwc2_hsotg *hsotg,
+                                    struct usb_host_endpoint *ep, int retry)
+{
+       struct dwc2_qtd *qtd, *qtd_tmp;
+       struct dwc2_qh *qh;
+       unsigned long flags;
+       int rc;
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+
+       qh = ep->hcpriv;
+       if (!qh) {
+               rc = -EINVAL;
+               goto err;
+       }
+
+       while (!list_empty(&qh->qtd_list) && retry--) {
+               if (retry == 0) {
+                       dev_err(hsotg->dev,
+                               "## timeout in dwc2_hcd_endpoint_disable() ##\n");
+                       rc = -EBUSY;
+                       goto err;
+               }
+
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+               usleep_range(20000, 40000);
+               spin_lock_irqsave(&hsotg->lock, flags);
+               qh = ep->hcpriv;
+               if (!qh) {
+                       rc = -EINVAL;
+                       goto err;
+               }
+       }
+
+       dwc2_hcd_qh_unlink(hsotg, qh);
+
+       /* Free each QTD in the QH's QTD list */
+       list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry)
+               dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
+
+       ep->hcpriv = NULL;
+       spin_unlock_irqrestore(&hsotg->lock, flags);
+       dwc2_hcd_qh_free(hsotg, qh);
+
+       return 0;
+
+err:
+       ep->hcpriv = NULL;
+       spin_unlock_irqrestore(&hsotg->lock, flags);
+
+       return rc;
+}
+
+/* Must be called with interrupt disabled and spinlock held */
+static int dwc2_hcd_endpoint_reset(struct dwc2_hsotg *hsotg,
+                                  struct usb_host_endpoint *ep)
+{
+       struct dwc2_qh *qh = ep->hcpriv;
+
+       if (!qh)
+               return -EINVAL;
+
+       qh->data_toggle = DWC2_HC_PID_DATA0;
+
+       return 0;
+}
+
+/*
+ * Initializes dynamic portions of the DWC_otg HCD state
+ *
+ * Must be called with interrupt disabled and spinlock held
+ */
+static void dwc2_hcd_reinit(struct dwc2_hsotg *hsotg)
+{
+       struct dwc2_host_chan *chan, *chan_tmp;
+       int num_channels;
+       int i;
+
+       hsotg->flags.d32 = 0;
+
+       hsotg->non_periodic_qh_ptr = &hsotg->non_periodic_sched_active;
+       hsotg->non_periodic_channels = 0;
+       hsotg->periodic_channels = 0;
+
+       /*
+        * Put all channels in the free channel list and clean up channel
+        * states
+        */
+       list_for_each_entry_safe(chan, chan_tmp, &hsotg->free_hc_list,
+                                hc_list_entry)
+               list_del_init(&chan->hc_list_entry);
+
+       num_channels = hsotg->core_params->host_channels;
+       for (i = 0; i < num_channels; i++) {
+               chan = hsotg->hc_ptr_array[i];
+               list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list);
+               dwc2_hc_cleanup(hsotg, chan);
+       }
+
+       /* Initialize the DWC core for host mode operation */
+       dwc2_core_host_init(hsotg);
+}
+
+static void dwc2_hc_init_split(struct dwc2_hsotg *hsotg,
+                              struct dwc2_host_chan *chan,
+                              struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb)
+{
+       int hub_addr, hub_port;
+
+       chan->do_split = 1;
+       chan->xact_pos = qtd->isoc_split_pos;
+       chan->complete_split = qtd->complete_split;
+       dwc2_host_hub_info(hsotg, urb->priv, &hub_addr, &hub_port);
+       chan->hub_addr = (u8)hub_addr;
+       chan->hub_port = (u8)hub_port;
+}
+
+static void *dwc2_hc_init_xfer(struct dwc2_hsotg *hsotg,
+                              struct dwc2_host_chan *chan,
+                              struct dwc2_qtd *qtd, void *bufptr)
+{
+       struct dwc2_hcd_urb *urb = qtd->urb;
+       struct dwc2_hcd_iso_packet_desc *frame_desc;
+
+       switch (dwc2_hcd_get_pipe_type(&urb->pipe_info)) {
+       case USB_ENDPOINT_XFER_CONTROL:
+               chan->ep_type = USB_ENDPOINT_XFER_CONTROL;
+
+               switch (qtd->control_phase) {
+               case DWC2_CONTROL_SETUP:
+                       dev_vdbg(hsotg->dev, "  Control setup transaction\n");
+                       chan->do_ping = 0;
+                       chan->ep_is_in = 0;
+                       chan->data_pid_start = DWC2_HC_PID_SETUP;
+                       if (hsotg->core_params->dma_enable > 0)
+                               chan->xfer_dma = urb->setup_dma;
+                       else
+                               chan->xfer_buf = urb->setup_packet;
+                       chan->xfer_len = 8;
+                       bufptr = NULL;
+                       break;
+
+               case DWC2_CONTROL_DATA:
+                       dev_vdbg(hsotg->dev, "  Control data transaction\n");
+                       chan->data_pid_start = qtd->data_toggle;
+                       break;
+
+               case DWC2_CONTROL_STATUS:
+                       /*
+                        * Direction is opposite of data direction or IN if no
+                        * data
+                        */
+                       dev_vdbg(hsotg->dev, "  Control status transaction\n");
+                       if (urb->length == 0)
+                               chan->ep_is_in = 1;
+                       else
+                               chan->ep_is_in =
+                                       dwc2_hcd_is_pipe_out(&urb->pipe_info);
+                       if (chan->ep_is_in)
+                               chan->do_ping = 0;
+                       chan->data_pid_start = DWC2_HC_PID_DATA1;
+                       chan->xfer_len = 0;
+                       if (hsotg->core_params->dma_enable > 0)
+                               chan->xfer_dma = hsotg->status_buf_dma;
+                       else
+                               chan->xfer_buf = hsotg->status_buf;
+                       bufptr = NULL;
+                       break;
+               }
+               break;
+
+       case USB_ENDPOINT_XFER_BULK:
+               chan->ep_type = USB_ENDPOINT_XFER_BULK;
+               break;
+
+       case USB_ENDPOINT_XFER_INT:
+               chan->ep_type = USB_ENDPOINT_XFER_INT;
+               break;
+
+       case USB_ENDPOINT_XFER_ISOC:
+               chan->ep_type = USB_ENDPOINT_XFER_ISOC;
+               if (hsotg->core_params->dma_desc_enable > 0)
+                       break;
+
+               frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
+               frame_desc->status = 0;
+
+               if (hsotg->core_params->dma_enable > 0) {
+                       chan->xfer_dma = urb->dma;
+                       chan->xfer_dma += frame_desc->offset +
+                                       qtd->isoc_split_offset;
+               } else {
+                       chan->xfer_buf = urb->buf;
+                       chan->xfer_buf += frame_desc->offset +
+                                       qtd->isoc_split_offset;
+               }
+
+               chan->xfer_len = frame_desc->length - qtd->isoc_split_offset;
+
+               /* For non-dword aligned buffers */
+               if (hsotg->core_params->dma_enable > 0 &&
+                   (chan->xfer_dma & 0x3))
+                       bufptr = (u8 *)urb->buf + frame_desc->offset +
+                                       qtd->isoc_split_offset;
+               else
+                       bufptr = NULL;
+
+               if (chan->xact_pos == DWC2_HCSPLT_XACTPOS_ALL) {
+                       if (chan->xfer_len <= 188)
+                               chan->xact_pos = DWC2_HCSPLT_XACTPOS_ALL;
+                       else
+                               chan->xact_pos = DWC2_HCSPLT_XACTPOS_BEGIN;
+               }
+               break;
+       }
+
+       return bufptr;
+}
+
+static int dwc2_hc_setup_align_buf(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
+                                  struct dwc2_host_chan *chan, void *bufptr)
+{
+       u32 buf_size;
+
+       if (chan->ep_type != USB_ENDPOINT_XFER_ISOC)
+               buf_size = hsotg->core_params->max_transfer_size;
+       else
+               buf_size = 4096;
+
+       if (!qh->dw_align_buf) {
+               qh->dw_align_buf = dma_alloc_coherent(hsotg->dev, buf_size,
+                                                     &qh->dw_align_buf_dma,
+                                                     GFP_ATOMIC);
+               if (!qh->dw_align_buf)
+                       return -ENOMEM;
+       }
+
+       if (!chan->ep_is_in && chan->xfer_len) {
+               dma_sync_single_for_cpu(hsotg->dev, chan->xfer_dma, buf_size,
+                                       DMA_TO_DEVICE);
+               memcpy(qh->dw_align_buf, bufptr, chan->xfer_len);
+               dma_sync_single_for_device(hsotg->dev, chan->xfer_dma, buf_size,
+                                          DMA_TO_DEVICE);
+       }
+
+       chan->align_buf = qh->dw_align_buf_dma;
+       return 0;
+}
+
+/**
+ * dwc2_assign_and_init_hc() - Assigns transactions from a QTD to a free host
+ * channel and initializes the host channel to perform the transactions. The
+ * host channel is removed from the free list.
+ *
+ * @hsotg: The HCD state structure
+ * @qh:    Transactions from the first QTD for this QH are selected and assigned
+ *         to a free host channel
+ */
+static void dwc2_assign_and_init_hc(struct dwc2_hsotg *hsotg,
+                                   struct dwc2_qh *qh)
+{
+       struct dwc2_host_chan *chan;
+       struct dwc2_hcd_urb *urb;
+       struct dwc2_qtd *qtd;
+       void *bufptr = NULL;
+
+       dev_vdbg(hsotg->dev, "%s(%p,%p)\n", __func__, hsotg, qh);
+
+       if (list_empty(&qh->qtd_list)) {
+               dev_dbg(hsotg->dev, "No QTDs in QH list\n");
+               return;
+       }
+
+       if (list_empty(&hsotg->free_hc_list)) {
+               dev_dbg(hsotg->dev, "No free channel to assign\n");
+               return;
+       }
+
+       chan = list_first_entry(&hsotg->free_hc_list, struct dwc2_host_chan,
+                               hc_list_entry);
+
+       /* Remove the host channel from the free list */
+       list_del_init(&chan->hc_list_entry);
+
+       qtd = list_first_entry(&qh->qtd_list, struct dwc2_qtd, qtd_list_entry);
+       urb = qtd->urb;
+       qh->channel = chan;
+       qtd->in_process = 1;
+
+       /*
+        * Use usb_pipedevice to determine device address. This address is
+        * 0 before the SET_ADDRESS command and the correct address afterward.
+        */
+       chan->dev_addr = dwc2_hcd_get_dev_addr(&urb->pipe_info);
+       chan->ep_num = dwc2_hcd_get_ep_num(&urb->pipe_info);
+       chan->speed = qh->dev_speed;
+       chan->max_packet = dwc2_max_packet(qh->maxp);
+
+       chan->xfer_started = 0;
+       chan->halt_status = DWC2_HC_XFER_NO_HALT_STATUS;
+       chan->error_state = (qtd->error_count > 0);
+       chan->halt_on_queue = 0;
+       chan->halt_pending = 0;
+       chan->requests = 0;
+
+       /*
+        * The following values may be modified in the transfer type section
+        * below. The xfer_len value may be reduced when the transfer is
+        * started to accommodate the max widths of the XferSize and PktCnt
+        * fields in the HCTSIZn register.
+        */
+
+       chan->ep_is_in = (dwc2_hcd_is_pipe_in(&urb->pipe_info) != 0);
+       if (chan->ep_is_in)
+               chan->do_ping = 0;
+       else
+               chan->do_ping = qh->ping_state;
+
+       chan->data_pid_start = qh->data_toggle;
+       chan->multi_count = 1;
+
+       if (hsotg->core_params->dma_enable > 0) {
+               chan->xfer_dma = urb->dma + urb->actual_length;
+
+               /* For non-dword aligned case */
+               if (hsotg->core_params->dma_desc_enable <= 0 &&
+                   (chan->xfer_dma & 0x3))
+                       bufptr = (u8 *)urb->buf + urb->actual_length;
+       } else {
+               chan->xfer_buf = (u8 *)urb->buf + urb->actual_length;
+       }
+
+       chan->xfer_len = urb->length - urb->actual_length;
+       chan->xfer_count = 0;
+
+       /* Set the split attributes if required */
+       if (qh->do_split)
+               dwc2_hc_init_split(hsotg, chan, qtd, urb);
+       else
+               chan->do_split = 0;
+
+       /* Set the transfer attributes */
+       bufptr = dwc2_hc_init_xfer(hsotg, chan, qtd, bufptr);
+
+       /* Non DWORD-aligned buffer case */
+       if (bufptr) {
+               dev_vdbg(hsotg->dev, "Non-aligned buffer\n");
+               if (dwc2_hc_setup_align_buf(hsotg, qh, chan, bufptr)) {
+                       dev_err(hsotg->dev,
+                               "%s: Failed to allocate memory to handle non-dword aligned buffer\n",
+                               __func__);
+                       /* Add channel back to free list */
+                       chan->align_buf = 0;
+                       chan->multi_count = 0;
+                       list_add_tail(&chan->hc_list_entry,
+                                     &hsotg->free_hc_list);
+                       qtd->in_process = 0;
+                       qh->channel = NULL;
+                       return;
+               }
+       } else {
+               chan->align_buf = 0;
+       }
+
+       if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
+           chan->ep_type == USB_ENDPOINT_XFER_ISOC)
+               /*
+                * This value may be modified when the transfer is started
+                * to reflect the actual transfer length
+                */
+               chan->multi_count = dwc2_hb_mult(qh->maxp);
+
+       if (hsotg->core_params->dma_desc_enable > 0)
+               chan->desc_list_addr = qh->desc_list_dma;
+
+       dwc2_hc_init(hsotg, chan);
+       chan->qh = qh;
+}
+
+/**
+ * dwc2_hcd_select_transactions() - Selects transactions from the HCD transfer
+ * schedule and assigns them to available host channels. Called from the HCD
+ * interrupt handler functions.
+ *
+ * @hsotg: The HCD state structure
+ *
+ * Return: The types of new transactions that were assigned to host channels
+ */
+enum dwc2_transaction_type dwc2_hcd_select_transactions(
+               struct dwc2_hsotg *hsotg)
+{
+       enum dwc2_transaction_type ret_val = DWC2_TRANSACTION_NONE;
+       struct list_head *qh_ptr;
+       struct dwc2_qh *qh;
+       int num_channels;
+
+#ifdef DWC2_DEBUG_SOF
+       dev_vdbg(hsotg->dev, "  Select Transactions\n");
+#endif
+
+       /* Process entries in the periodic ready list */
+       qh_ptr = hsotg->periodic_sched_ready.next;
+       while (qh_ptr != &hsotg->periodic_sched_ready) {
+               if (list_empty(&hsotg->free_hc_list))
+                       break;
+               qh = list_entry(qh_ptr, struct dwc2_qh, qh_list_entry);
+               dwc2_assign_and_init_hc(hsotg, qh);
+
+               /*
+                * Move the QH from the periodic ready schedule to the
+                * periodic assigned schedule
+                */
+               qh_ptr = qh_ptr->next;
+               list_move(&qh->qh_list_entry, &hsotg->periodic_sched_assigned);
+               ret_val = DWC2_TRANSACTION_PERIODIC;
+       }
+
+       /*
+        * Process entries in the inactive portion of the non-periodic
+        * schedule. Some free host channels may not be used if they are
+        * reserved for periodic transfers.
+        */
+       num_channels = hsotg->core_params->host_channels;
+       qh_ptr = hsotg->non_periodic_sched_inactive.next;
+       while (qh_ptr != &hsotg->non_periodic_sched_inactive) {
+               if (hsotg->non_periodic_channels >= num_channels -
+                                               hsotg->periodic_channels)
+                       break;
+               if (list_empty(&hsotg->free_hc_list))
+                       break;
+               qh = list_entry(qh_ptr, struct dwc2_qh, qh_list_entry);
+               dwc2_assign_and_init_hc(hsotg, qh);
+
+               /*
+                * Move the QH from the non-periodic inactive schedule to the
+                * non-periodic active schedule
+                */
+               qh_ptr = qh_ptr->next;
+               list_move(&qh->qh_list_entry,
+                         &hsotg->non_periodic_sched_active);
+
+               if (ret_val == DWC2_TRANSACTION_NONE)
+                       ret_val = DWC2_TRANSACTION_NON_PERIODIC;
+               else
+                       ret_val = DWC2_TRANSACTION_ALL;
+
+               hsotg->non_periodic_channels++;
+       }
+
+       return ret_val;
+}
+
+/**
+ * dwc2_queue_transaction() - Attempts to queue a single transaction request for
+ * a host channel associated with either a periodic or non-periodic transfer
+ *
+ * @hsotg: The HCD state structure
+ * @chan:  Host channel descriptor associated with either a periodic or
+ *         non-periodic transfer
+ * @fifo_dwords_avail: Number of DWORDs available in the periodic Tx FIFO
+ *                     for periodic transfers or the non-periodic Tx FIFO
+ *                     for non-periodic transfers
+ *
+ * Return: 1 if a request is queued and more requests may be needed to
+ * complete the transfer, 0 if no more requests are required for this
+ * transfer, -1 if there is insufficient space in the Tx FIFO
+ *
+ * This function assumes that there is space available in the appropriate
+ * request queue. For an OUT transfer or SETUP transaction in Slave mode,
+ * it checks whether space is available in the appropriate Tx FIFO.
+ *
+ * Must be called with interrupt disabled and spinlock held
+ */
+static int dwc2_queue_transaction(struct dwc2_hsotg *hsotg,
+                                 struct dwc2_host_chan *chan,
+                                 u16 fifo_dwords_avail)
+{
+       int retval = 0;
+
+       if (hsotg->core_params->dma_enable > 0) {
+               if (hsotg->core_params->dma_desc_enable > 0) {
+                       if (!chan->xfer_started ||
+                           chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
+                               dwc2_hcd_start_xfer_ddma(hsotg, chan->qh);
+                               chan->qh->ping_state = 0;
+                       }
+               } else if (!chan->xfer_started) {
+                       dwc2_hc_start_transfer(hsotg, chan);
+                       chan->qh->ping_state = 0;
+               }
+       } else if (chan->halt_pending) {
+               /* Don't queue a request if the channel has been halted */
+       } else if (chan->halt_on_queue) {
+               dwc2_hc_halt(hsotg, chan, chan->halt_status);
+       } else if (chan->do_ping) {
+               if (!chan->xfer_started)
+                       dwc2_hc_start_transfer(hsotg, chan);
+       } else if (!chan->ep_is_in ||
+                  chan->data_pid_start == DWC2_HC_PID_SETUP) {
+               if ((fifo_dwords_avail * 4) >= chan->max_packet) {
+                       if (!chan->xfer_started) {
+                               dwc2_hc_start_transfer(hsotg, chan);
+                               retval = 1;
+                       } else {
+                               retval = dwc2_hc_continue_transfer(hsotg, chan);
+                       }
+               } else {
+                       retval = -1;
+               }
+       } else {
+               if (!chan->xfer_started) {
+                       dwc2_hc_start_transfer(hsotg, chan);
+                       retval = 1;
+               } else {
+                       retval = dwc2_hc_continue_transfer(hsotg, chan);
+               }
+       }
+
+       return retval;
+}
+
+/*
+ * Processes periodic channels for the next frame and queues transactions for
+ * these channels to the DWC_otg controller. After queueing transactions, the
+ * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
+ * to queue as Periodic Tx FIFO or request queue space becomes available.
+ * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
+ *
+ * Must be called with interrupt disabled and spinlock held
+ */
+static void dwc2_process_periodic_channels(struct dwc2_hsotg *hsotg)
+{
+       struct list_head *qh_ptr;
+       struct dwc2_qh *qh;
+       u32 tx_status;
+       u32 fspcavail;
+       u32 gintmsk;
+       int status;
+       int no_queue_space = 0;
+       int no_fifo_space = 0;
+       u32 qspcavail;
+
+       dev_vdbg(hsotg->dev, "Queue periodic transactions\n");
+
+       tx_status = readl(hsotg->regs + HPTXSTS);
+       qspcavail = tx_status >> TXSTS_QSPCAVAIL_SHIFT &
+                   TXSTS_QSPCAVAIL_MASK >> TXSTS_QSPCAVAIL_SHIFT;
+       fspcavail = tx_status >> TXSTS_FSPCAVAIL_SHIFT &
+                   TXSTS_FSPCAVAIL_MASK >> TXSTS_FSPCAVAIL_SHIFT;
+       dev_vdbg(hsotg->dev, "  P Tx Req Queue Space Avail (before queue): %d\n",
+                qspcavail);
+       dev_vdbg(hsotg->dev, "  P Tx FIFO Space Avail (before queue): %d\n",
+                fspcavail);
+
+       qh_ptr = hsotg->periodic_sched_assigned.next;
+       while (qh_ptr != &hsotg->periodic_sched_assigned) {
+               tx_status = readl(hsotg->regs + HPTXSTS);
+               if ((tx_status & TXSTS_QSPCAVAIL_MASK) == 0) {
+                       no_queue_space = 1;
+                       break;
+               }
+
+               qh = list_entry(qh_ptr, struct dwc2_qh, qh_list_entry);
+               if (!qh->channel) {
+                       qh_ptr = qh_ptr->next;
+                       continue;
+               }
+
+               /* Make sure EP's TT buffer is clean before queueing qtds */
+               if (qh->tt_buffer_dirty) {
+                       qh_ptr = qh_ptr->next;
+                       continue;
+               }
+
+               /*
+                * Set a flag if we're queuing high-bandwidth in slave mode.
+                * The flag prevents any halts to get into the request queue in
+                * the middle of multiple high-bandwidth packets getting queued.
+                */
+               if (hsotg->core_params->dma_enable <= 0 &&
+                               qh->channel->multi_count > 1)
+                       hsotg->queuing_high_bandwidth = 1;
+
+               fspcavail = tx_status >> TXSTS_FSPCAVAIL_SHIFT &
+                           TXSTS_FSPCAVAIL_MASK >> TXSTS_FSPCAVAIL_SHIFT;
+               status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail);
+               if (status < 0) {
+                       no_fifo_space = 1;
+                       break;
+               }
+
+               /*
+                * In Slave mode, stay on the current transfer until there is
+                * nothing more to do or the high-bandwidth request count is
+                * reached. In DMA mode, only need to queue one request. The
+                * controller automatically handles multiple packets for
+                * high-bandwidth transfers.
+                */
+               if (hsotg->core_params->dma_enable > 0 || status == 0 ||
+                   qh->channel->requests == qh->channel->multi_count) {
+                       qh_ptr = qh_ptr->next;
+                       /*
+                        * Move the QH from the periodic assigned schedule to
+                        * the periodic queued schedule
+                        */
+                       list_move(&qh->qh_list_entry,
+                                 &hsotg->periodic_sched_queued);
+
+                       /* done queuing high bandwidth */
+                       hsotg->queuing_high_bandwidth = 0;
+               }
+       }
+
+       if (hsotg->core_params->dma_enable <= 0) {
+               tx_status = readl(hsotg->regs + HPTXSTS);
+               qspcavail = tx_status >> TXSTS_QSPCAVAIL_SHIFT &
+                           TXSTS_QSPCAVAIL_MASK >> TXSTS_QSPCAVAIL_SHIFT;
+               fspcavail = tx_status >> TXSTS_FSPCAVAIL_SHIFT &
+                           TXSTS_FSPCAVAIL_MASK >> TXSTS_FSPCAVAIL_SHIFT;
+               dev_vdbg(hsotg->dev,
+                        "  P Tx Req Queue Space Avail (after queue): %d\n",
+                        qspcavail);
+               dev_vdbg(hsotg->dev,
+                        "  P Tx FIFO Space Avail (after queue): %d\n",
+                        fspcavail);
+
+               if (!list_empty(&hsotg->periodic_sched_assigned) ||
+                   no_queue_space || no_fifo_space) {
+                       /*
+                        * May need to queue more transactions as the request
+                        * queue or Tx FIFO empties. Enable the periodic Tx
+                        * FIFO empty interrupt. (Always use the half-empty
+                        * level to ensure that new requests are loaded as
+                        * soon as possible.)
+                        */
+                       gintmsk = readl(hsotg->regs + GINTMSK);
+                       gintmsk |= GINTSTS_PTXFEMP;
+                       writel(gintmsk, hsotg->regs + GINTMSK);
+               } else {
+                       /*
+                        * Disable the Tx FIFO empty interrupt since there are
+                        * no more transactions that need to be queued right
+                        * now. This function is called from interrupt
+                        * handlers to queue more transactions as transfer
+                        * states change.
+                        */
+                       gintmsk = readl(hsotg->regs + GINTMSK);
+                       gintmsk &= ~GINTSTS_PTXFEMP;
+                       writel(gintmsk, hsotg->regs + GINTMSK);
+               }
+       }
+}
+
+/*
+ * Processes active non-periodic channels and queues transactions for these
+ * channels to the DWC_otg controller. After queueing transactions, the NP Tx
+ * FIFO Empty interrupt is enabled if there are more transactions to queue as
+ * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
+ * FIFO Empty interrupt is disabled.
+ *
+ * Must be called with interrupt disabled and spinlock held
+ */
+static void dwc2_process_non_periodic_channels(struct dwc2_hsotg *hsotg)
+{
+       struct list_head *orig_qh_ptr;
+       struct dwc2_qh *qh;
+       u32 tx_status;
+       u32 qspcavail;
+       u32 fspcavail;
+       u32 gintmsk;
+       int status;
+       int no_queue_space = 0;
+       int no_fifo_space = 0;
+       int more_to_do = 0;
+
+       dev_vdbg(hsotg->dev, "Queue non-periodic transactions\n");
+
+       tx_status = readl(hsotg->regs + GNPTXSTS);
+       qspcavail = tx_status >> TXSTS_QSPCAVAIL_SHIFT &
+                   TXSTS_QSPCAVAIL_MASK >> TXSTS_QSPCAVAIL_SHIFT;
+       fspcavail = tx_status >> TXSTS_FSPCAVAIL_SHIFT &
+                   TXSTS_FSPCAVAIL_MASK >> TXSTS_FSPCAVAIL_SHIFT;
+       dev_vdbg(hsotg->dev, "  NP Tx Req Queue Space Avail (before queue): %d\n",
+                qspcavail);
+       dev_vdbg(hsotg->dev, "  NP Tx FIFO Space Avail (before queue): %d\n",
+                fspcavail);
+
+       /*
+        * Keep track of the starting point. Skip over the start-of-list
+        * entry.
+        */
+       if (hsotg->non_periodic_qh_ptr == &hsotg->non_periodic_sched_active)
+               hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next;
+       orig_qh_ptr = hsotg->non_periodic_qh_ptr;
+
+       /*
+        * Process once through the active list or until no more space is
+        * available in the request queue or the Tx FIFO
+        */
+       do {
+               tx_status = readl(hsotg->regs + GNPTXSTS);
+               qspcavail = tx_status >> TXSTS_QSPCAVAIL_SHIFT &
+                           TXSTS_QSPCAVAIL_MASK >> TXSTS_QSPCAVAIL_SHIFT;
+               if (hsotg->core_params->dma_enable <= 0 && qspcavail == 0) {
+                       no_queue_space = 1;
+                       break;
+               }
+
+               qh = list_entry(hsotg->non_periodic_qh_ptr, struct dwc2_qh,
+                               qh_list_entry);
+               if (!qh->channel)
+                       goto next;
+
+               /* Make sure EP's TT buffer is clean before queueing qtds */
+               if (qh->tt_buffer_dirty)
+                       goto next;
+
+               fspcavail = tx_status >> TXSTS_FSPCAVAIL_SHIFT &
+                           TXSTS_FSPCAVAIL_MASK >> TXSTS_FSPCAVAIL_SHIFT;
+               status = dwc2_queue_transaction(hsotg, qh->channel, fspcavail);
+
+               if (status > 0) {
+                       more_to_do = 1;
+               } else if (status < 0) {
+                       no_fifo_space = 1;
+                       break;
+               }
+next:
+               /* Advance to next QH, skipping start-of-list entry */
+               hsotg->non_periodic_qh_ptr = hsotg->non_periodic_qh_ptr->next;
+               if (hsotg->non_periodic_qh_ptr ==
+                               &hsotg->non_periodic_sched_active)
+                       hsotg->non_periodic_qh_ptr =
+                                       hsotg->non_periodic_qh_ptr->next;
+       } while (hsotg->non_periodic_qh_ptr != orig_qh_ptr);
+
+       if (hsotg->core_params->dma_enable <= 0) {
+               tx_status = readl(hsotg->regs + GNPTXSTS);
+               qspcavail = tx_status >> TXSTS_QSPCAVAIL_SHIFT &
+                           TXSTS_QSPCAVAIL_MASK >> TXSTS_QSPCAVAIL_SHIFT;
+               fspcavail = tx_status >> TXSTS_FSPCAVAIL_SHIFT &
+                           TXSTS_FSPCAVAIL_MASK >> TXSTS_FSPCAVAIL_SHIFT;
+               dev_vdbg(hsotg->dev,
+                        "  NP Tx Req Queue Space Avail (after queue): %d\n",
+                        qspcavail);
+               dev_vdbg(hsotg->dev,
+                        "  NP Tx FIFO Space Avail (after queue): %d\n",
+                        fspcavail);
+
+               if (more_to_do || no_queue_space || no_fifo_space) {
+                       /*
+                        * May need to queue more transactions as the request
+                        * queue or Tx FIFO empties. Enable the non-periodic
+                        * Tx FIFO empty interrupt. (Always use the half-empty
+                        * level to ensure that new requests are loaded as
+                        * soon as possible.)
+                        */
+                       gintmsk = readl(hsotg->regs + GINTMSK);
+                       gintmsk |= GINTSTS_NPTXFEMP;
+                       writel(gintmsk, hsotg->regs + GINTMSK);
+               } else {
+                       /*
+                        * Disable the Tx FIFO empty interrupt since there are
+                        * no more transactions that need to be queued right
+                        * now. This function is called from interrupt
+                        * handlers to queue more transactions as transfer
+                        * states change.
+                        */
+                       gintmsk = readl(hsotg->regs + GINTMSK);
+                       gintmsk &= ~GINTSTS_NPTXFEMP;
+                       writel(gintmsk, hsotg->regs + GINTMSK);
+               }
+       }
+}
+
+/**
+ * dwc2_hcd_queue_transactions() - Processes the currently active host channels
+ * and queues transactions for these channels to the DWC_otg controller. Called
+ * from the HCD interrupt handler functions.
+ *
+ * @hsotg:   The HCD state structure
+ * @tr_type: The type(s) of transactions to queue (non-periodic, periodic,
+ *           or both)
+ *
+ * Must be called with interrupt disabled and spinlock held
+ */
+void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg,
+                                enum dwc2_transaction_type tr_type)
+{
+#ifdef DWC2_DEBUG_SOF
+       dev_vdbg(hsotg->dev, "Queue Transactions\n");
+#endif
+       /* Process host channels associated with periodic transfers */
+       if ((tr_type == DWC2_TRANSACTION_PERIODIC ||
+            tr_type == DWC2_TRANSACTION_ALL) &&
+           !list_empty(&hsotg->periodic_sched_assigned))
+               dwc2_process_periodic_channels(hsotg);
+
+       /* Process host channels associated with non-periodic transfers */
+       if (tr_type == DWC2_TRANSACTION_NON_PERIODIC ||
+           tr_type == DWC2_TRANSACTION_ALL) {
+               if (!list_empty(&hsotg->non_periodic_sched_active)) {
+                       dwc2_process_non_periodic_channels(hsotg);
+               } else {
+                       /*
+                        * Ensure NP Tx FIFO empty interrupt is disabled when
+                        * there are no non-periodic transfers to process
+                        */
+                       u32 gintmsk = readl(hsotg->regs + GINTMSK);
+
+                       gintmsk &= ~GINTSTS_NPTXFEMP;
+                       writel(gintmsk, hsotg->regs + GINTMSK);
+               }
+       }
+}
+
+static void dwc2_conn_id_status_change(struct work_struct *work)
+{
+       struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg,
+                                               wf_otg);
+       u32 count = 0;
+       u32 gotgctl;
+
+       dev_dbg(hsotg->dev, "%s()\n", __func__);
+
+       gotgctl = readl(hsotg->regs + GOTGCTL);
+       dev_dbg(hsotg->dev, "gotgctl=%0x\n", gotgctl);
+       dev_dbg(hsotg->dev, "gotgctl.b.conidsts=%d\n",
+               !!(gotgctl & GOTGCTL_CONID_B));
+
+       /* B-Device connector (Device Mode) */
+       if (gotgctl & GOTGCTL_CONID_B) {
+               /* Wait for switch to device mode */
+               dev_dbg(hsotg->dev, "connId B\n");
+               while (!dwc2_is_device_mode(hsotg)) {
+                       dev_info(hsotg->dev,
+                                "Waiting for Peripheral Mode, Mode=%s\n",
+                                dwc2_is_host_mode(hsotg) ? "Host" :
+                                "Peripheral");
+                       usleep_range(20000, 40000);
+                       if (++count > 250)
+                               break;
+               }
+               if (count > 250)
+                       dev_err(hsotg->dev,
+                               "Connection id status change timed out");
+               hsotg->op_state = OTG_STATE_B_PERIPHERAL;
+               dwc2_core_init(hsotg, false);
+               dwc2_enable_global_interrupts(hsotg);
+       } else {
+               /* A-Device connector (Host Mode) */
+               dev_dbg(hsotg->dev, "connId A\n");
+               while (!dwc2_is_host_mode(hsotg)) {
+                       dev_info(hsotg->dev, "Waiting for Host Mode, Mode=%s\n",
+                                dwc2_is_host_mode(hsotg) ?
+                                "Host" : "Peripheral");
+                       usleep_range(20000, 40000);
+                       if (++count > 250)
+                               break;
+               }
+               if (count > 250)
+                       dev_err(hsotg->dev,
+                               "Connection id status change timed out");
+               hsotg->op_state = OTG_STATE_A_HOST;
+
+               /* Initialize the Core for Host mode */
+               dwc2_core_init(hsotg, false);
+               dwc2_enable_global_interrupts(hsotg);
+               dwc2_hcd_start(hsotg);
+       }
+}
+
+static void dwc2_wakeup_detected(unsigned long data)
+{
+       struct dwc2_hsotg *hsotg = (struct dwc2_hsotg *)data;
+       u32 hprt0;
+
+       dev_dbg(hsotg->dev, "%s()\n", __func__);
+
+       /*
+        * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
+        * so that OPT tests pass with all PHYs.)
+        */
+       hprt0 = dwc2_read_hprt0(hsotg);
+       dev_dbg(hsotg->dev, "Resume: HPRT0=%0x\n", hprt0);
+       hprt0 &= ~HPRT0_RES;
+       writel(hprt0, hsotg->regs + HPRT0);
+       dev_dbg(hsotg->dev, "Clear Resume: HPRT0=%0x\n",
+               readl(hsotg->regs + HPRT0));
+
+       dwc2_hcd_rem_wakeup(hsotg);
+
+       /* Change to L0 state */
+       hsotg->lx_state = DWC2_L0;
+}
+
+static int dwc2_host_is_b_hnp_enabled(struct dwc2_hsotg *hsotg)
+{
+       struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg);
+
+       return hcd->self.b_hnp_enable;
+}
+
+/* Must NOT be called with interrupt disabled or spinlock held */
+static void dwc2_port_suspend(struct dwc2_hsotg *hsotg, u16 windex)
+{
+       unsigned long flags;
+       u32 hprt0;
+       u32 pcgctl;
+       u32 gotgctl;
+
+       dev_dbg(hsotg->dev, "%s()\n", __func__);
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+
+       if (windex == hsotg->otg_port && dwc2_host_is_b_hnp_enabled(hsotg)) {
+               gotgctl = readl(hsotg->regs + GOTGCTL);
+               gotgctl |= GOTGCTL_HSTSETHNPEN;
+               writel(gotgctl, hsotg->regs + GOTGCTL);
+               hsotg->op_state = OTG_STATE_A_SUSPEND;
+       }
+
+       hprt0 = dwc2_read_hprt0(hsotg);
+       hprt0 |= HPRT0_SUSP;
+       writel(hprt0, hsotg->regs + HPRT0);
+
+       /* Update lx_state */
+       hsotg->lx_state = DWC2_L2;
+
+       /* Suspend the Phy Clock */
+       pcgctl = readl(hsotg->regs + PCGCTL);
+       pcgctl |= PCGCTL_STOPPCLK;
+       writel(pcgctl, hsotg->regs + PCGCTL);
+       udelay(10);
+
+       /* For HNP the bus must be suspended for at least 200ms */
+       if (dwc2_host_is_b_hnp_enabled(hsotg)) {
+               pcgctl = readl(hsotg->regs + PCGCTL);
+               pcgctl &= ~PCGCTL_STOPPCLK;
+               writel(pcgctl, hsotg->regs + PCGCTL);
+
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+
+               usleep_range(200000, 250000);
+       } else {
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+       }
+}
+
+/* Handles hub class-specific requests */
+static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq,
+                               u16 wvalue, u16 windex, char *buf, u16 wlength)
+{
+       struct usb_hub_descriptor *hub_desc;
+       int retval = 0;
+       u32 hprt0;
+       u32 port_status;
+       u32 speed;
+       u32 pcgctl;
+
+       switch (typereq) {
+       case ClearHubFeature:
+               dev_dbg(hsotg->dev, "ClearHubFeature %1xh\n", wvalue);
+
+               switch (wvalue) {
+               case C_HUB_LOCAL_POWER:
+               case C_HUB_OVER_CURRENT:
+                       /* Nothing required here */
+                       break;
+
+               default:
+                       retval = -EINVAL;
+                       dev_err(hsotg->dev,
+                               "ClearHubFeature request %1xh unknown\n",
+                               wvalue);
+               }
+               break;
+
+       case ClearPortFeature:
+               if (wvalue != USB_PORT_FEAT_L1)
+                       if (!windex || windex > 1)
+                               goto error;
+               switch (wvalue) {
+               case USB_PORT_FEAT_ENABLE:
+                       dev_dbg(hsotg->dev,
+                               "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
+                       hprt0 = dwc2_read_hprt0(hsotg);
+                       hprt0 |= HPRT0_ENA;
+                       writel(hprt0, hsotg->regs + HPRT0);
+                       break;
+
+               case USB_PORT_FEAT_SUSPEND:
+                       dev_dbg(hsotg->dev,
+                               "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
+                       writel(0, hsotg->regs + PCGCTL);
+                       usleep_range(20000, 40000);
+
+                       hprt0 = dwc2_read_hprt0(hsotg);
+                       hprt0 |= HPRT0_RES;
+                       writel(hprt0, hsotg->regs + HPRT0);
+                       hprt0 &= ~HPRT0_SUSP;
+                       usleep_range(100000, 150000);
+
+                       hprt0 &= ~HPRT0_RES;
+                       writel(hprt0, hsotg->regs + HPRT0);
+                       break;
+
+               case USB_PORT_FEAT_POWER:
+                       dev_dbg(hsotg->dev,
+                               "ClearPortFeature USB_PORT_FEAT_POWER\n");
+                       hprt0 = dwc2_read_hprt0(hsotg);
+                       hprt0 &= ~HPRT0_PWR;
+                       writel(hprt0, hsotg->regs + HPRT0);
+                       break;
+
+               case USB_PORT_FEAT_INDICATOR:
+                       dev_dbg(hsotg->dev,
+                               "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
+                       /* Port indicator not supported */
+                       break;
+
+               case USB_PORT_FEAT_C_CONNECTION:
+                       /*
+                        * Clears driver's internal Connect Status Change flag
+                        */
+                       dev_dbg(hsotg->dev,
+                               "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
+                       hsotg->flags.b.port_connect_status_change = 0;
+                       break;
+
+               case USB_PORT_FEAT_C_RESET:
+                       /* Clears driver's internal Port Reset Change flag */
+                       dev_dbg(hsotg->dev,
+                               "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
+                       hsotg->flags.b.port_reset_change = 0;
+                       break;
+
+               case USB_PORT_FEAT_C_ENABLE:
+                       /*
+                        * Clears the driver's internal Port Enable/Disable
+                        * Change flag
+                        */
+                       dev_dbg(hsotg->dev,
+                               "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
+                       hsotg->flags.b.port_enable_change = 0;
+                       break;
+
+               case USB_PORT_FEAT_C_SUSPEND:
+                       /*
+                        * Clears the driver's internal Port Suspend Change
+                        * flag, which is set when resume signaling on the host
+                        * port is complete
+                        */
+                       dev_dbg(hsotg->dev,
+                               "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
+                       hsotg->flags.b.port_suspend_change = 0;
+                       break;
+
+               case USB_PORT_FEAT_C_PORT_L1:
+                       dev_dbg(hsotg->dev,
+                               "ClearPortFeature USB_PORT_FEAT_C_PORT_L1\n");
+                       hsotg->flags.b.port_l1_change = 0;
+                       break;
+
+               case USB_PORT_FEAT_C_OVER_CURRENT:
+                       dev_dbg(hsotg->dev,
+                               "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
+                       hsotg->flags.b.port_over_current_change = 0;
+                       break;
+
+               default:
+                       retval = -EINVAL;
+                       dev_err(hsotg->dev,
+                               "ClearPortFeature request %1xh unknown or unsupported\n",
+                               wvalue);
+               }
+               break;
+
+       case GetHubDescriptor:
+               dev_dbg(hsotg->dev, "GetHubDescriptor\n");
+               hub_desc = (struct usb_hub_descriptor *)buf;
+               hub_desc->bDescLength = 9;
+               hub_desc->bDescriptorType = 0x29;
+               hub_desc->bNbrPorts = 1;
+               hub_desc->wHubCharacteristics = cpu_to_le16(0x08);
+               hub_desc->bPwrOn2PwrGood = 1;
+               hub_desc->bHubContrCurrent = 0;
+               hub_desc->u.hs.DeviceRemovable[0] = 0;
+               hub_desc->u.hs.DeviceRemovable[1] = 0xff;
+               break;
+
+       case GetHubStatus:
+               dev_dbg(hsotg->dev, "GetHubStatus\n");
+               memset(buf, 0, 4);
+               break;
+
+       case GetPortStatus:
+               dev_dbg(hsotg->dev,
+                       "GetPortStatus wIndex=0x%04x flags=0x%08x\n", windex,
+                       hsotg->flags.d32);
+               if (!windex || windex > 1)
+                       goto error;
+
+               port_status = 0;
+               if (hsotg->flags.b.port_connect_status_change)
+                       port_status |= USB_PORT_STAT_C_CONNECTION << 16;
+               if (hsotg->flags.b.port_enable_change)
+                       port_status |= USB_PORT_STAT_C_ENABLE << 16;
+               if (hsotg->flags.b.port_suspend_change)
+                       port_status |= USB_PORT_STAT_C_SUSPEND << 16;
+               if (hsotg->flags.b.port_l1_change)
+                       port_status |= USB_PORT_STAT_C_L1 << 16;
+               if (hsotg->flags.b.port_reset_change)
+                       port_status |= USB_PORT_STAT_C_RESET << 16;
+               if (hsotg->flags.b.port_over_current_change) {
+                       dev_warn(hsotg->dev, "Overcurrent change detected\n");
+                       port_status |= USB_PORT_STAT_C_OVERCURRENT << 16;
+               }
+
+               if (!hsotg->flags.b.port_connect_status) {
+                       /*
+                        * The port is disconnected, which means the core is
+                        * either in device mode or it soon will be. Just
+                        * return 0's for the remainder of the port status
+                        * since the port register can't be read if the core
+                        * is in device mode.
+                        */
+                       *(__le32 *)buf = cpu_to_le32(port_status);
+                       break;
+               }
+
+               hprt0 = readl(hsotg->regs + HPRT0);
+               dev_dbg(hsotg->dev, "  HPRT0: 0x%08x\n", hprt0);
+
+               if (hprt0 & HPRT0_CONNSTS)
+                       port_status |= USB_PORT_STAT_CONNECTION;
+               if (hprt0 & HPRT0_ENA)
+                       port_status |= USB_PORT_STAT_ENABLE;
+               if (hprt0 & HPRT0_SUSP)
+                       port_status |= USB_PORT_STAT_SUSPEND;
+               if (hprt0 & HPRT0_OVRCURRACT)
+                       port_status |= USB_PORT_STAT_OVERCURRENT;
+               if (hprt0 & HPRT0_RST)
+                       port_status |= USB_PORT_STAT_RESET;
+               if (hprt0 & HPRT0_PWR)
+                       port_status |= USB_PORT_STAT_POWER;
+
+               speed = hprt0 & HPRT0_SPD_MASK;
+               if (speed == HPRT0_SPD_HIGH_SPEED)
+                       port_status |= USB_PORT_STAT_HIGH_SPEED;
+               else if (speed == HPRT0_SPD_LOW_SPEED)
+                       port_status |= USB_PORT_STAT_LOW_SPEED;
+
+               if (hprt0 & HPRT0_TSTCTL_MASK)
+                       port_status |= USB_PORT_STAT_TEST;
+               /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
+
+               dev_dbg(hsotg->dev, "port_status=%08x\n", port_status);
+               *(__le32 *)buf = cpu_to_le32(port_status);
+               break;
+
+       case SetHubFeature:
+               dev_dbg(hsotg->dev, "SetHubFeature\n");
+               /* No HUB features supported */
+               break;
+
+       case SetPortFeature:
+               dev_dbg(hsotg->dev, "SetPortFeature\n");
+               if (wvalue != USB_PORT_FEAT_TEST && (!windex || windex > 1))
+                       goto error;
+
+               if (!hsotg->flags.b.port_connect_status) {
+                       /*
+                        * The port is disconnected, which means the core is
+                        * either in device mode or it soon will be. Just
+                        * return without doing anything since the port
+                        * register can't be written if the core is in device
+                        * mode.
+                        */
+                       break;
+               }
+
+               switch (wvalue) {
+               case USB_PORT_FEAT_SUSPEND:
+                       dev_dbg(hsotg->dev,
+                               "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
+                       if (windex != hsotg->otg_port)
+                               goto error;
+                       dwc2_port_suspend(hsotg, windex);
+                       break;
+
+               case USB_PORT_FEAT_POWER:
+                       dev_dbg(hsotg->dev,
+                               "SetPortFeature - USB_PORT_FEAT_POWER\n");
+                       hprt0 = dwc2_read_hprt0(hsotg);
+                       hprt0 |= HPRT0_PWR;
+                       writel(hprt0, hsotg->regs + HPRT0);
+                       break;
+
+               case USB_PORT_FEAT_RESET:
+                       hprt0 = dwc2_read_hprt0(hsotg);
+                       dev_dbg(hsotg->dev,
+                               "SetPortFeature - USB_PORT_FEAT_RESET\n");
+                       pcgctl = readl(hsotg->regs + PCGCTL);
+                       pcgctl &= ~(PCGCTL_ENBL_SLEEP_GATING | PCGCTL_STOPPCLK);
+                       writel(pcgctl, hsotg->regs + PCGCTL);
+                       /* ??? Original driver does this */
+                       writel(0, hsotg->regs + PCGCTL);
+
+                       hprt0 = dwc2_read_hprt0(hsotg);
+                       /* Clear suspend bit if resetting from suspend state */
+                       hprt0 &= ~HPRT0_SUSP;
+
+                       /*
+                        * When B-Host the Port reset bit is set in the Start
+                        * HCD Callback function, so that the reset is started
+                        * within 1ms of the HNP success interrupt
+                        */
+                       if (!dwc2_hcd_is_b_host(hsotg)) {
+                               hprt0 |= HPRT0_PWR | HPRT0_RST;
+                               dev_dbg(hsotg->dev,
+                                       "In host mode, hprt0=%08x\n", hprt0);
+                               writel(hprt0, hsotg->regs + HPRT0);
+                       }
+
+                       /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
+                       usleep_range(50000, 70000);
+                       hprt0 &= ~HPRT0_RST;
+                       writel(hprt0, hsotg->regs + HPRT0);
+                       hsotg->lx_state = DWC2_L0; /* Now back to On state */
+                       break;
+
+               case USB_PORT_FEAT_INDICATOR:
+                       dev_dbg(hsotg->dev,
+                               "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
+                       /* Not supported */
+                       break;
+
+               default:
+                       retval = -EINVAL;
+                       dev_err(hsotg->dev,
+                               "SetPortFeature %1xh unknown or unsupported\n",
+                               wvalue);
+                       break;
+               }
+               break;
+
+       default:
+error:
+               retval = -EINVAL;
+               dev_dbg(hsotg->dev,
+                       "Unknown hub control request: %1xh wIndex: %1xh wValue: %1xh\n",
+                       typereq, windex, wvalue);
+               break;
+       }
+
+       return retval;
+}
+
+static int dwc2_hcd_is_status_changed(struct dwc2_hsotg *hsotg, int port)
+{
+       int retval;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       if (port != 1)
+               return -EINVAL;
+
+       retval = (hsotg->flags.b.port_connect_status_change ||
+                 hsotg->flags.b.port_reset_change ||
+                 hsotg->flags.b.port_enable_change ||
+                 hsotg->flags.b.port_suspend_change ||
+                 hsotg->flags.b.port_over_current_change);
+
+       if (retval) {
+               dev_dbg(hsotg->dev,
+                       "DWC OTG HCD HUB STATUS DATA: Root port status changed\n");
+               dev_dbg(hsotg->dev, "  port_connect_status_change: %d\n",
+                       hsotg->flags.b.port_connect_status_change);
+               dev_dbg(hsotg->dev, "  port_reset_change: %d\n",
+                       hsotg->flags.b.port_reset_change);
+               dev_dbg(hsotg->dev, "  port_enable_change: %d\n",
+                       hsotg->flags.b.port_enable_change);
+               dev_dbg(hsotg->dev, "  port_suspend_change: %d\n",
+                       hsotg->flags.b.port_suspend_change);
+               dev_dbg(hsotg->dev, "  port_over_current_change: %d\n",
+                       hsotg->flags.b.port_over_current_change);
+       }
+
+       return retval;
+}
+
+int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
+{
+       u32 hfnum = readl(hsotg->regs + HFNUM);
+
+#ifdef DWC2_DEBUG_SOF
+       dev_vdbg(hsotg->dev, "DWC OTG HCD GET FRAME NUMBER %d\n",
+                hfnum >> HFNUM_FRNUM_SHIFT &
+                HFNUM_FRNUM_MASK >> HFNUM_FRNUM_SHIFT);
+#endif
+       return hfnum >> HFNUM_FRNUM_SHIFT &
+              HFNUM_FRNUM_MASK >> HFNUM_FRNUM_SHIFT;
+}
+
+int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg)
+{
+       return (hsotg->op_state == OTG_STATE_B_HOST);
+}
+
+static struct dwc2_hcd_urb *dwc2_hcd_urb_alloc(struct dwc2_hsotg *hsotg,
+                                              int iso_desc_count,
+                                              gfp_t mem_flags)
+{
+       struct dwc2_hcd_urb *urb;
+       u32 size = sizeof(*urb) + iso_desc_count *
+                  sizeof(struct dwc2_hcd_iso_packet_desc);
+
+       urb = kzalloc(size, mem_flags);
+       if (urb)
+               urb->packet_count = iso_desc_count;
+       return urb;
+}
+
+static void dwc2_hcd_urb_set_pipeinfo(struct dwc2_hsotg *hsotg,
+                                     struct dwc2_hcd_urb *urb, u8 dev_addr,
+                                     u8 ep_num, u8 ep_type, u8 ep_dir, u16 mps)
+{
+       dev_vdbg(hsotg->dev,
+                "addr=%d, ep_num=%d, ep_dir=%1x, ep_type=%1x, mps=%d\n",
+                dev_addr, ep_num, ep_dir, ep_type, mps);
+       urb->pipe_info.dev_addr = dev_addr;
+       urb->pipe_info.ep_num = ep_num;
+       urb->pipe_info.pipe_type = ep_type;
+       urb->pipe_info.pipe_dir = ep_dir;
+       urb->pipe_info.mps = mps;
+}
+
+/*
+ * NOTE: This function will be removed once the peripheral controller code
+ * is integrated and the driver is stable
+ */
+void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg)
+{
+#ifdef DEBUG
+       struct dwc2_host_chan *chan;
+       struct dwc2_hcd_urb *urb;
+       struct dwc2_qtd *qtd;
+       int num_channels;
+       u32 np_tx_status;
+       u32 p_tx_status;
+       int i;
+
+       num_channels = hsotg->core_params->host_channels;
+       dev_dbg(hsotg->dev, "\n");
+       dev_dbg(hsotg->dev,
+               "************************************************************\n");
+       dev_dbg(hsotg->dev, "HCD State:\n");
+       dev_dbg(hsotg->dev, "  Num channels: %d\n", num_channels);
+
+       for (i = 0; i < num_channels; i++) {
+               chan = hsotg->hc_ptr_array[i];
+               dev_dbg(hsotg->dev, "  Channel %d:\n", i);
+               dev_dbg(hsotg->dev,
+                       "    dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
+                       chan->dev_addr, chan->ep_num, chan->ep_is_in);
+               dev_dbg(hsotg->dev, "    speed: %d\n", chan->speed);
+               dev_dbg(hsotg->dev, "    ep_type: %d\n", chan->ep_type);
+               dev_dbg(hsotg->dev, "    max_packet: %d\n", chan->max_packet);
+               dev_dbg(hsotg->dev, "    data_pid_start: %d\n",
+                       chan->data_pid_start);
+               dev_dbg(hsotg->dev, "    multi_count: %d\n", chan->multi_count);
+               dev_dbg(hsotg->dev, "    xfer_started: %d\n",
+                       chan->xfer_started);
+               dev_dbg(hsotg->dev, "    xfer_buf: %p\n", chan->xfer_buf);
+               dev_dbg(hsotg->dev, "    xfer_dma: %08lx\n",
+                       (unsigned long)chan->xfer_dma);
+               dev_dbg(hsotg->dev, "    xfer_len: %d\n", chan->xfer_len);
+               dev_dbg(hsotg->dev, "    xfer_count: %d\n", chan->xfer_count);
+               dev_dbg(hsotg->dev, "    halt_on_queue: %d\n",
+                       chan->halt_on_queue);
+               dev_dbg(hsotg->dev, "    halt_pending: %d\n",
+                       chan->halt_pending);
+               dev_dbg(hsotg->dev, "    halt_status: %d\n", chan->halt_status);
+               dev_dbg(hsotg->dev, "    do_split: %d\n", chan->do_split);
+               dev_dbg(hsotg->dev, "    complete_split: %d\n",
+                       chan->complete_split);
+               dev_dbg(hsotg->dev, "    hub_addr: %d\n", chan->hub_addr);
+               dev_dbg(hsotg->dev, "    hub_port: %d\n", chan->hub_port);
+               dev_dbg(hsotg->dev, "    xact_pos: %d\n", chan->xact_pos);
+               dev_dbg(hsotg->dev, "    requests: %d\n", chan->requests);
+               dev_dbg(hsotg->dev, "    qh: %p\n", chan->qh);
+
+               if (chan->xfer_started) {
+                       u32 hfnum, hcchar, hctsiz, hcint, hcintmsk;
+
+                       hfnum = readl(hsotg->regs + HFNUM);
+                       hcchar = readl(hsotg->regs + HCCHAR(i));
+                       hctsiz = readl(hsotg->regs + HCTSIZ(i));
+                       hcint = readl(hsotg->regs + HCINT(i));
+                       hcintmsk = readl(hsotg->regs + HCINTMSK(i));
+                       dev_dbg(hsotg->dev, "    hfnum: 0x%08x\n", hfnum);
+                       dev_dbg(hsotg->dev, "    hcchar: 0x%08x\n", hcchar);
+                       dev_dbg(hsotg->dev, "    hctsiz: 0x%08x\n", hctsiz);
+                       dev_dbg(hsotg->dev, "    hcint: 0x%08x\n", hcint);
+                       dev_dbg(hsotg->dev, "    hcintmsk: 0x%08x\n", hcintmsk);
+               }
+
+               if (!(chan->xfer_started && chan->qh))
+                       continue;
+
+               list_for_each_entry(qtd, &chan->qh->qtd_list, qtd_list_entry) {
+                       if (!qtd->in_process)
+                               break;
+                       urb = qtd->urb;
+                       dev_dbg(hsotg->dev, "    URB Info:\n");
+                       dev_dbg(hsotg->dev, "      qtd: %p, urb: %p\n",
+                               qtd, urb);
+                       if (urb) {
+                               dev_dbg(hsotg->dev,
+                                       "      Dev: %d, EP: %d %s\n",
+                                       dwc2_hcd_get_dev_addr(&urb->pipe_info),
+                                       dwc2_hcd_get_ep_num(&urb->pipe_info),
+                                       dwc2_hcd_is_pipe_in(&urb->pipe_info) ?
+                                       "IN" : "OUT");
+                               dev_dbg(hsotg->dev,
+                                       "      Max packet size: %d\n",
+                                       dwc2_hcd_get_mps(&urb->pipe_info));
+                               dev_dbg(hsotg->dev,
+                                       "      transfer_buffer: %p\n",
+                                       urb->buf);
+                               dev_dbg(hsotg->dev,
+                                       "      transfer_dma: %08lx\n",
+                                       (unsigned long)urb->dma);
+                               dev_dbg(hsotg->dev,
+                                       "      transfer_buffer_length: %d\n",
+                                       urb->length);
+                               dev_dbg(hsotg->dev, "      actual_length: %d\n",
+                                       urb->actual_length);
+                       }
+               }
+       }
+
+       dev_dbg(hsotg->dev, "  non_periodic_channels: %d\n",
+               hsotg->non_periodic_channels);
+       dev_dbg(hsotg->dev, "  periodic_channels: %d\n",
+               hsotg->periodic_channels);
+       dev_dbg(hsotg->dev, "  periodic_usecs: %d\n", hsotg->periodic_usecs);
+       np_tx_status = readl(hsotg->regs + GNPTXSTS);
+       dev_dbg(hsotg->dev, "  NP Tx Req Queue Space Avail: %d\n",
+               np_tx_status >> TXSTS_QSPCAVAIL_SHIFT &
+               TXSTS_QSPCAVAIL_MASK >> TXSTS_QSPCAVAIL_SHIFT);
+       dev_dbg(hsotg->dev, "  NP Tx FIFO Space Avail: %d\n",
+               np_tx_status >> TXSTS_FSPCAVAIL_SHIFT &
+               TXSTS_FSPCAVAIL_MASK >> TXSTS_FSPCAVAIL_SHIFT);
+       p_tx_status = readl(hsotg->regs + HPTXSTS);
+       dev_dbg(hsotg->dev, "  P Tx Req Queue Space Avail: %d\n",
+               p_tx_status >> TXSTS_QSPCAVAIL_SHIFT &
+               TXSTS_QSPCAVAIL_MASK >> TXSTS_QSPCAVAIL_SHIFT);
+       dev_dbg(hsotg->dev, "  P Tx FIFO Space Avail: %d\n",
+               p_tx_status >> TXSTS_FSPCAVAIL_SHIFT &
+               TXSTS_FSPCAVAIL_MASK >> TXSTS_FSPCAVAIL_SHIFT);
+       dwc2_hcd_dump_frrem(hsotg);
+       dwc2_dump_global_registers(hsotg);
+       dwc2_dump_host_registers(hsotg);
+       dev_dbg(hsotg->dev,
+               "************************************************************\n");
+       dev_dbg(hsotg->dev, "\n");
+#endif
+}
+
+/*
+ * NOTE: This function will be removed once the peripheral controller code
+ * is integrated and the driver is stable
+ */
+void dwc2_hcd_dump_frrem(struct dwc2_hsotg *hsotg)
+{
+#ifdef DWC2_DUMP_FRREM
+       dev_dbg(hsotg->dev, "Frame remaining at SOF:\n");
+       dev_dbg(hsotg->dev, "  samples %u, accum %llu, avg %llu\n",
+               hsotg->frrem_samples, hsotg->frrem_accum,
+               hsotg->frrem_samples > 0 ?
+               hsotg->frrem_accum / hsotg->frrem_samples : 0);
+       dev_dbg(hsotg->dev, "\n");
+       dev_dbg(hsotg->dev, "Frame remaining at start_transfer (uframe 7):\n");
+       dev_dbg(hsotg->dev, "  samples %u, accum %llu, avg %llu\n",
+               hsotg->hfnum_7_samples,
+               hsotg->hfnum_7_frrem_accum,
+               hsotg->hfnum_7_samples > 0 ?
+               hsotg->hfnum_7_frrem_accum / hsotg->hfnum_7_samples : 0);
+       dev_dbg(hsotg->dev, "Frame remaining at start_transfer (uframe 0):\n");
+       dev_dbg(hsotg->dev, "  samples %u, accum %llu, avg %llu\n",
+               hsotg->hfnum_0_samples,
+               hsotg->hfnum_0_frrem_accum,
+               hsotg->hfnum_0_samples > 0 ?
+               hsotg->hfnum_0_frrem_accum / hsotg->hfnum_0_samples : 0);
+       dev_dbg(hsotg->dev, "Frame remaining at start_transfer (uframe 1-6):\n");
+       dev_dbg(hsotg->dev, "  samples %u, accum %llu, avg %llu\n",
+               hsotg->hfnum_other_samples,
+               hsotg->hfnum_other_frrem_accum,
+               hsotg->hfnum_other_samples > 0 ?
+               hsotg->hfnum_other_frrem_accum / hsotg->hfnum_other_samples :
+               0);
+       dev_dbg(hsotg->dev, "\n");
+       dev_dbg(hsotg->dev, "Frame remaining at sample point A (uframe 7):\n");
+       dev_dbg(hsotg->dev, "  samples %u, accum %llu, avg %llu\n",
+               hsotg->hfnum_7_samples_a, hsotg->hfnum_7_frrem_accum_a,
+               hsotg->hfnum_7_samples_a > 0 ?
+               hsotg->hfnum_7_frrem_accum_a / hsotg->hfnum_7_samples_a : 0);
+       dev_dbg(hsotg->dev, "Frame remaining at sample point A (uframe 0):\n");
+       dev_dbg(hsotg->dev, "  samples %u, accum %llu, avg %llu\n",
+               hsotg->hfnum_0_samples_a, hsotg->hfnum_0_frrem_accum_a,
+               hsotg->hfnum_0_samples_a > 0 ?
+               hsotg->hfnum_0_frrem_accum_a / hsotg->hfnum_0_samples_a : 0);
+       dev_dbg(hsotg->dev, "Frame remaining at sample point A (uframe 1-6):\n");
+       dev_dbg(hsotg->dev, "  samples %u, accum %llu, avg %llu\n",
+               hsotg->hfnum_other_samples_a, hsotg->hfnum_other_frrem_accum_a,
+               hsotg->hfnum_other_samples_a > 0 ?
+               hsotg->hfnum_other_frrem_accum_a / hsotg->hfnum_other_samples_a
+               : 0);
+       dev_dbg(hsotg->dev, "\n");
+       dev_dbg(hsotg->dev, "Frame remaining at sample point B (uframe 7):\n");
+       dev_dbg(hsotg->dev, "  samples %u, accum %llu, avg %llu\n",
+               hsotg->hfnum_7_samples_b, hsotg->hfnum_7_frrem_accum_b,
+               hsotg->hfnum_7_samples_b > 0 ?
+               hsotg->hfnum_7_frrem_accum_b / hsotg->hfnum_7_samples_b : 0);
+       dev_dbg(hsotg->dev, "Frame remaining at sample point B (uframe 0):\n");
+       dev_dbg(hsotg->dev, "  samples %u, accum %llu, avg %llu\n",
+               hsotg->hfnum_0_samples_b, hsotg->hfnum_0_frrem_accum_b,
+               (hsotg->hfnum_0_samples_b > 0) ?
+               hsotg->hfnum_0_frrem_accum_b / hsotg->hfnum_0_samples_b : 0);
+       dev_dbg(hsotg->dev, "Frame remaining at sample point B (uframe 1-6):\n");
+       dev_dbg(hsotg->dev, "  samples %u, accum %llu, avg %llu\n",
+               hsotg->hfnum_other_samples_b, hsotg->hfnum_other_frrem_accum_b,
+               (hsotg->hfnum_other_samples_b > 0) ?
+               hsotg->hfnum_other_frrem_accum_b / hsotg->hfnum_other_samples_b
+               : 0);
+#endif
+}
+
+struct wrapper_priv_data {
+       struct dwc2_hsotg *hsotg;
+};
+
+/* Gets the dwc2_hsotg from a usb_hcd */
+static struct dwc2_hsotg *dwc2_hcd_to_hsotg(struct usb_hcd *hcd)
+{
+       struct wrapper_priv_data *p;
+
+       p = (struct wrapper_priv_data *) &hcd->hcd_priv;
+       return p->hsotg;
+}
+
+static int _dwc2_hcd_start(struct usb_hcd *hcd);
+
+void dwc2_host_start(struct dwc2_hsotg *hsotg)
+{
+       struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg);
+
+       hcd->self.is_b_host = dwc2_hcd_is_b_host(hsotg);
+       _dwc2_hcd_start(hcd);
+}
+
+void dwc2_host_disconnect(struct dwc2_hsotg *hsotg)
+{
+       struct usb_hcd *hcd = dwc2_hsotg_to_hcd(hsotg);
+
+       hcd->self.is_b_host = 0;
+}
+
+void dwc2_host_hub_info(struct dwc2_hsotg *hsotg, void *context, int *hub_addr,
+                       int *hub_port)
+{
+       struct urb *urb = context;
+
+       if (urb->dev->tt)
+               *hub_addr = urb->dev->tt->hub->devnum;
+       else
+               *hub_addr = 0;
+       *hub_port = urb->dev->ttport;
+}
+
+int dwc2_host_get_speed(struct dwc2_hsotg *hsotg, void *context)
+{
+       struct urb *urb = context;
+
+       return urb->dev->speed;
+}
+
+static void dwc2_allocate_bus_bandwidth(struct usb_hcd *hcd, u16 bw,
+                                       struct urb *urb)
+{
+       struct usb_bus *bus = hcd_to_bus(hcd);
+
+       if (urb->interval)
+               bus->bandwidth_allocated += bw / urb->interval;
+       if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
+               bus->bandwidth_isoc_reqs++;
+       else
+               bus->bandwidth_int_reqs++;
+}
+
+static void dwc2_free_bus_bandwidth(struct usb_hcd *hcd, u16 bw,
+                                   struct urb *urb)
+{
+       struct usb_bus *bus = hcd_to_bus(hcd);
+
+       if (urb->interval)
+               bus->bandwidth_allocated -= bw / urb->interval;
+       if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
+               bus->bandwidth_isoc_reqs--;
+       else
+               bus->bandwidth_int_reqs--;
+}
+
+/*
+ * Sets the final status of an URB and returns it to the upper layer. Any
+ * required cleanup of the URB is performed.
+ *
+ * Must be called with interrupt disabled and spinlock held
+ */
+void dwc2_host_complete(struct dwc2_hsotg *hsotg, void *context,
+                       struct dwc2_hcd_urb *dwc2_urb, int status)
+{
+       struct urb *urb = context;
+       int i;
+
+       if (!urb) {
+               dev_dbg(hsotg->dev, "## %s: context is NULL ##\n", __func__);
+               return;
+       }
+
+       if (!dwc2_urb) {
+               dev_dbg(hsotg->dev, "## %s: dwc2_urb is NULL ##\n", __func__);
+               return;
+       }
+
+       urb->actual_length = dwc2_hcd_urb_get_actual_length(dwc2_urb);
+
+       dev_vdbg(hsotg->dev,
+                "%s: urb %p device %d ep %d-%s status %d actual %d\n",
+                __func__, urb, usb_pipedevice(urb->pipe),
+                usb_pipeendpoint(urb->pipe),
+                usb_pipein(urb->pipe) ? "IN" : "OUT", status,
+                urb->actual_length);
+
+       if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
+               for (i = 0; i < urb->number_of_packets; i++)
+                       dev_vdbg(hsotg->dev, " ISO Desc %d status %d\n",
+                                i, urb->iso_frame_desc[i].status);
+       }
+
+       if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
+               urb->error_count = dwc2_hcd_urb_get_error_count(dwc2_urb);
+               for (i = 0; i < urb->number_of_packets; ++i) {
+                       urb->iso_frame_desc[i].actual_length =
+                               dwc2_hcd_urb_get_iso_desc_actual_length(
+                                               dwc2_urb, i);
+                       urb->iso_frame_desc[i].status =
+                               dwc2_hcd_urb_get_iso_desc_status(dwc2_urb, i);
+               }
+       }
+
+       urb->status = status;
+       urb->hcpriv = NULL;
+       if (!status) {
+               if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
+                   urb->actual_length < urb->transfer_buffer_length)
+                       urb->status = -EREMOTEIO;
+       }
+
+       if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS ||
+           usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
+               struct usb_host_endpoint *ep = urb->ep;
+
+               if (ep)
+                       dwc2_free_bus_bandwidth(dwc2_hsotg_to_hcd(hsotg),
+                                       dwc2_hcd_get_ep_bandwidth(hsotg, ep),
+                                       urb);
+       }
+
+       kfree(dwc2_urb);
+
+       spin_unlock(&hsotg->lock);
+       usb_hcd_giveback_urb(dwc2_hsotg_to_hcd(hsotg), urb, status);
+       spin_lock(&hsotg->lock);
+}
+
+/*
+ * Work queue function for starting the HCD when A-Cable is connected
+ */
+static void dwc2_hcd_start_func(struct work_struct *work)
+{
+       struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg,
+                                               start_work.work);
+
+       dev_dbg(hsotg->dev, "%s() %p\n", __func__, hsotg);
+       dwc2_host_start(hsotg);
+}
+
+/*
+ * Reset work queue function
+ */
+static void dwc2_hcd_reset_func(struct work_struct *work)
+{
+       struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg,
+                                               reset_work.work);
+       u32 hprt0;
+
+       dev_dbg(hsotg->dev, "USB RESET function called\n");
+       hprt0 = dwc2_read_hprt0(hsotg);
+       hprt0 &= ~HPRT0_RST;
+       writel(hprt0, hsotg->regs + HPRT0);
+       hsotg->flags.b.port_reset_change = 1;
+}
+
+/*
+ * =========================================================================
+ *  Linux HC Driver Functions
+ * =========================================================================
+ */
+
+/*
+ * Initializes the DWC_otg controller and its root hub and prepares it for host
+ * mode operation. Activates the root port. Returns 0 on success and a negative
+ * error code on failure.
+ */
+static int _dwc2_hcd_start(struct usb_hcd *hcd)
+{
+       struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+       struct usb_bus *bus = hcd_to_bus(hcd);
+       unsigned long flags;
+
+       dev_dbg(hsotg->dev, "DWC OTG HCD START\n");
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+
+       hcd->state = HC_STATE_RUNNING;
+
+       if (dwc2_is_device_mode(hsotg)) {
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+               return 0;       /* why 0 ?? */
+       }
+
+       dwc2_hcd_reinit(hsotg);
+
+       /* Initialize and connect root hub if one is not already attached */
+       if (bus->root_hub) {
+               dev_dbg(hsotg->dev, "DWC OTG HCD Has Root Hub\n");
+               /* Inform the HUB driver to resume */
+               usb_hcd_resume_root_hub(hcd);
+       }
+
+       spin_unlock_irqrestore(&hsotg->lock, flags);
+       return 0;
+}
+
+/*
+ * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
+ * stopped.
+ */
+static void _dwc2_hcd_stop(struct usb_hcd *hcd)
+{
+       struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+       unsigned long flags;
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+       dwc2_hcd_stop(hsotg);
+       spin_unlock_irqrestore(&hsotg->lock, flags);
+
+       usleep_range(1000, 3000);
+}
+
+/* Returns the current frame number */
+static int _dwc2_hcd_get_frame_number(struct usb_hcd *hcd)
+{
+       struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+
+       return dwc2_hcd_get_frame_number(hsotg);
+}
+
+static void dwc2_dump_urb_info(struct usb_hcd *hcd, struct urb *urb,
+                              char *fn_name)
+{
+#ifdef VERBOSE_DEBUG
+       struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+       char *pipetype;
+       char *speed;
+
+       dev_vdbg(hsotg->dev, "%s, urb %p\n", fn_name, urb);
+       dev_vdbg(hsotg->dev, "  Device address: %d\n",
+                usb_pipedevice(urb->pipe));
+       dev_vdbg(hsotg->dev, "  Endpoint: %d, %s\n",
+                usb_pipeendpoint(urb->pipe),
+                usb_pipein(urb->pipe) ? "IN" : "OUT");
+
+       switch (usb_pipetype(urb->pipe)) {
+       case PIPE_CONTROL:
+               pipetype = "CONTROL";
+               break;
+       case PIPE_BULK:
+               pipetype = "BULK";
+               break;
+       case PIPE_INTERRUPT:
+               pipetype = "INTERRUPT";
+               break;
+       case PIPE_ISOCHRONOUS:
+               pipetype = "ISOCHRONOUS";
+               break;
+       default:
+               pipetype = "UNKNOWN";
+               break;
+       }
+
+       dev_vdbg(hsotg->dev, "  Endpoint type: %s %s (%s)\n", pipetype,
+                usb_urb_dir_in(urb) ? "IN" : "OUT", usb_pipein(urb->pipe) ?
+                "IN" : "OUT");
+
+       switch (urb->dev->speed) {
+       case USB_SPEED_HIGH:
+               speed = "HIGH";
+               break;
+       case USB_SPEED_FULL:
+               speed = "FULL";
+               break;
+       case USB_SPEED_LOW:
+               speed = "LOW";
+               break;
+       default:
+               speed = "UNKNOWN";
+               break;
+       }
+
+       dev_vdbg(hsotg->dev, "  Speed: %s\n", speed);
+       dev_vdbg(hsotg->dev, "  Max packet size: %d\n",
+                usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
+       dev_vdbg(hsotg->dev, "  Data buffer length: %d\n",
+                urb->transfer_buffer_length);
+       dev_vdbg(hsotg->dev, "  Transfer buffer: %p, Transfer DMA: %08lx\n",
+                urb->transfer_buffer, (unsigned long)urb->transfer_dma);
+       dev_vdbg(hsotg->dev, "  Setup buffer: %p, Setup DMA: %08lx\n",
+                urb->setup_packet, (unsigned long)urb->setup_dma);
+       dev_vdbg(hsotg->dev, "  Interval: %d\n", urb->interval);
+
+       if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
+               int i;
+
+               for (i = 0; i < urb->number_of_packets; i++) {
+                       dev_vdbg(hsotg->dev, "  ISO Desc %d:\n", i);
+                       dev_vdbg(hsotg->dev, "    offset: %d, length %d\n",
+                                urb->iso_frame_desc[i].offset,
+                                urb->iso_frame_desc[i].length);
+               }
+       }
+#endif
+}
+
+/*
+ * Starts processing a USB transfer request specified by a USB Request Block
+ * (URB). mem_flags indicates the type of memory allocation to use while
+ * processing this URB.
+ */
+static int _dwc2_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
+                                gfp_t mem_flags)
+{
+       struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+       struct usb_host_endpoint *ep = urb->ep;
+       struct dwc2_hcd_urb *dwc2_urb;
+       int i;
+       int alloc_bandwidth = 0;
+       int retval = 0;
+       u8 ep_type = 0;
+       u32 tflags = 0;
+       void *buf;
+       unsigned long flags;
+
+       dev_vdbg(hsotg->dev, "DWC OTG HCD URB Enqueue\n");
+       dwc2_dump_urb_info(hcd, urb, "urb_enqueue");
+
+       if (ep == NULL)
+               return -EINVAL;
+
+       if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS ||
+           usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
+               spin_lock_irqsave(&hsotg->lock, flags);
+               if (!dwc2_hcd_is_bandwidth_allocated(hsotg, ep))
+                       alloc_bandwidth = 1;
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+       }
+
+       switch (usb_pipetype(urb->pipe)) {
+       case PIPE_CONTROL:
+               ep_type = USB_ENDPOINT_XFER_CONTROL;
+               break;
+       case PIPE_ISOCHRONOUS:
+               ep_type = USB_ENDPOINT_XFER_ISOC;
+               break;
+       case PIPE_BULK:
+               ep_type = USB_ENDPOINT_XFER_BULK;
+               break;
+       case PIPE_INTERRUPT:
+               ep_type = USB_ENDPOINT_XFER_INT;
+               break;
+       default:
+               dev_warn(hsotg->dev, "Wrong ep type\n");
+       }
+
+       dwc2_urb = dwc2_hcd_urb_alloc(hsotg, urb->number_of_packets,
+                                     mem_flags);
+       if (!dwc2_urb)
+               return -ENOMEM;
+
+       dwc2_hcd_urb_set_pipeinfo(hsotg, dwc2_urb, usb_pipedevice(urb->pipe),
+                                 usb_pipeendpoint(urb->pipe), ep_type,
+                                 usb_pipein(urb->pipe),
+                                 usb_maxpacket(urb->dev, urb->pipe,
+                                               !(usb_pipein(urb->pipe))));
+
+       buf = urb->transfer_buffer;
+       if (hcd->self.uses_dma) {
+               /*
+                * Calculate virtual address from physical address, because
+                * some class driver may not fill transfer_buffer.
+                * In Buffer DMA mode virtual address is used, when handling
+                * non-DWORD aligned buffers.
+                */
+               buf = bus_to_virt(urb->transfer_dma);
+       }
+
+       if (!(urb->transfer_flags & URB_NO_INTERRUPT))
+               tflags |= URB_GIVEBACK_ASAP;
+       if (urb->transfer_flags & URB_ZERO_PACKET)
+               tflags |= URB_SEND_ZERO_PACKET;
+
+       dwc2_urb->priv = urb;
+       dwc2_urb->buf = buf;
+       dwc2_urb->dma = urb->transfer_dma;
+       dwc2_urb->length = urb->transfer_buffer_length;
+       dwc2_urb->setup_packet = urb->setup_packet;
+       dwc2_urb->setup_dma = urb->setup_dma;
+       dwc2_urb->flags = tflags;
+       dwc2_urb->interval = urb->interval;
+       dwc2_urb->status = -EINPROGRESS;
+
+       for (i = 0; i < urb->number_of_packets; ++i)
+               dwc2_hcd_urb_set_iso_desc_params(dwc2_urb, i,
+                                                urb->iso_frame_desc[i].offset,
+                                                urb->iso_frame_desc[i].length);
+
+       urb->hcpriv = dwc2_urb;
+       retval = dwc2_hcd_urb_enqueue(hsotg, dwc2_urb, &ep->hcpriv,
+                                     mem_flags);
+       if (retval) {
+               urb->hcpriv = NULL;
+               kfree(dwc2_urb);
+       } else {
+               if (alloc_bandwidth) {
+                       spin_lock_irqsave(&hsotg->lock, flags);
+                       dwc2_allocate_bus_bandwidth(hcd,
+                                       dwc2_hcd_get_ep_bandwidth(hsotg, ep),
+                                       urb);
+                       spin_unlock_irqrestore(&hsotg->lock, flags);
+               }
+       }
+
+       return retval;
+}
+
+/*
+ * Aborts/cancels a USB transfer request. Always returns 0 to indicate success.
+ */
+static int _dwc2_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
+                                int status)
+{
+       struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+       int rc = 0;
+       unsigned long flags;
+
+       dev_dbg(hsotg->dev, "DWC OTG HCD URB Dequeue\n");
+       dwc2_dump_urb_info(hcd, urb, "urb_dequeue");
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+
+       if (!urb->hcpriv) {
+               dev_dbg(hsotg->dev, "## urb->hcpriv is NULL ##\n");
+               goto out;
+       }
+
+       rc = dwc2_hcd_urb_dequeue(hsotg, urb->hcpriv);
+
+       kfree(urb->hcpriv);
+       urb->hcpriv = NULL;
+
+       /* Higher layer software sets URB status */
+       spin_unlock(&hsotg->lock);
+       usb_hcd_giveback_urb(hcd, urb, status);
+       spin_lock(&hsotg->lock);
+
+       dev_dbg(hsotg->dev, "Called usb_hcd_giveback_urb()\n");
+       dev_dbg(hsotg->dev, "  urb->status = %d\n", urb->status);
+out:
+       spin_unlock_irqrestore(&hsotg->lock, flags);
+
+       return rc;
+}
+
+/*
+ * Frees resources in the DWC_otg controller related to a given endpoint. Also
+ * clears state in the HCD related to the endpoint. Any URBs for the endpoint
+ * must already be dequeued.
+ */
+static void _dwc2_hcd_endpoint_disable(struct usb_hcd *hcd,
+                                      struct usb_host_endpoint *ep)
+{
+       struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+
+       dev_dbg(hsotg->dev,
+               "DWC OTG HCD EP DISABLE: bEndpointAddress=0x%02x, ep->hcpriv=%p\n",
+               ep->desc.bEndpointAddress, ep->hcpriv);
+       dwc2_hcd_endpoint_disable(hsotg, ep, 250);
+}
+
+/*
+ * Resets endpoint specific parameter values, in current version used to reset
+ * the data toggle (as a WA). This function can be called from usb_clear_halt
+ * routine.
+ */
+static void _dwc2_hcd_endpoint_reset(struct usb_hcd *hcd,
+                                    struct usb_host_endpoint *ep)
+{
+       struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+       int is_control = usb_endpoint_xfer_control(&ep->desc);
+       int is_out = usb_endpoint_dir_out(&ep->desc);
+       int epnum = usb_endpoint_num(&ep->desc);
+       struct usb_device *udev;
+       unsigned long flags;
+
+       dev_dbg(hsotg->dev,
+               "DWC OTG HCD EP RESET: bEndpointAddress=0x%02x\n",
+               ep->desc.bEndpointAddress);
+
+       udev = to_usb_device(hsotg->dev);
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+
+       usb_settoggle(udev, epnum, is_out, 0);
+       if (is_control)
+               usb_settoggle(udev, epnum, !is_out, 0);
+       dwc2_hcd_endpoint_reset(hsotg, ep);
+
+       spin_unlock_irqrestore(&hsotg->lock, flags);
+}
+
+/*
+ * Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
+ * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
+ * interrupt.
+ *
+ * This function is called by the USB core when an interrupt occurs
+ */
+static irqreturn_t _dwc2_hcd_irq(struct usb_hcd *hcd)
+{
+       struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+       int retval = dwc2_hcd_intr(hsotg);
+
+       return IRQ_RETVAL(retval);
+}
+
+/*
+ * Creates Status Change bitmap for the root hub and root port. The bitmap is
+ * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
+ * is the status change indicator for the single root port. Returns 1 if either
+ * change indicator is 1, otherwise returns 0.
+ */
+static int _dwc2_hcd_hub_status_data(struct usb_hcd *hcd, char *buf)
+{
+       struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+
+       buf[0] = dwc2_hcd_is_status_changed(hsotg, 1) << 1;
+       return buf[0] != 0;
+}
+
+/* Handles hub class-specific requests */
+static int _dwc2_hcd_hub_control(struct usb_hcd *hcd, u16 typereq, u16 wvalue,
+                                u16 windex, char *buf, u16 wlength)
+{
+       int retval = dwc2_hcd_hub_control(dwc2_hcd_to_hsotg(hcd), typereq,
+                                         wvalue, windex, buf, wlength);
+       return retval;
+}
+
+/* Handles hub TT buffer clear completions */
+static void _dwc2_hcd_clear_tt_buffer_complete(struct usb_hcd *hcd,
+                                              struct usb_host_endpoint *ep)
+{
+       struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+       struct dwc2_qh *qh;
+       unsigned long flags;
+
+       qh = ep->hcpriv;
+       if (!qh)
+               return;
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+       qh->tt_buffer_dirty = 0;
+
+       if (hsotg->flags.b.port_connect_status)
+               dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_ALL);
+
+       spin_unlock_irqrestore(&hsotg->lock, flags);
+}
+
+static struct hc_driver dwc2_hc_driver = {
+       .description = "dwc2_hsotg",
+       .product_desc = "DWC OTG Controller",
+       .hcd_priv_size = sizeof(struct wrapper_priv_data),
+
+       .irq = _dwc2_hcd_irq,
+       .flags = HCD_MEMORY | HCD_USB2,
+
+       .start = _dwc2_hcd_start,
+       .stop = _dwc2_hcd_stop,
+       .urb_enqueue = _dwc2_hcd_urb_enqueue,
+       .urb_dequeue = _dwc2_hcd_urb_dequeue,
+       .endpoint_disable = _dwc2_hcd_endpoint_disable,
+       .endpoint_reset = _dwc2_hcd_endpoint_reset,
+       .get_frame_number = _dwc2_hcd_get_frame_number,
+
+       .hub_status_data = _dwc2_hcd_hub_status_data,
+       .hub_control = _dwc2_hcd_hub_control,
+       .clear_tt_buffer_complete = _dwc2_hcd_clear_tt_buffer_complete,
+};
+
+/*
+ * Frees secondary storage associated with the dwc2_hsotg structure contained
+ * in the struct usb_hcd field
+ */
+static void dwc2_hcd_free(struct dwc2_hsotg *hsotg)
+{
+       u32 ahbcfg;
+       u32 dctl;
+       int i;
+
+       dev_dbg(hsotg->dev, "DWC OTG HCD FREE\n");
+
+       /* Free memory for QH/QTD lists */
+       dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_inactive);
+       dwc2_qh_list_free(hsotg, &hsotg->non_periodic_sched_active);
+       dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_inactive);
+       dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_ready);
+       dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_assigned);
+       dwc2_qh_list_free(hsotg, &hsotg->periodic_sched_queued);
+
+       /* Free memory for the host channels */
+       for (i = 0; i < MAX_EPS_CHANNELS; i++) {
+               struct dwc2_host_chan *chan = hsotg->hc_ptr_array[i];
+
+               if (chan != NULL) {
+                       dev_dbg(hsotg->dev, "HCD Free channel #%i, chan=%p\n",
+                               i, chan);
+                       hsotg->hc_ptr_array[i] = NULL;
+                       kfree(chan);
+               }
+       }
+
+       if (hsotg->core_params->dma_enable > 0) {
+               if (hsotg->status_buf) {
+                       dma_free_coherent(hsotg->dev, DWC2_HCD_STATUS_BUF_SIZE,
+                                         hsotg->status_buf,
+                                         hsotg->status_buf_dma);
+                       hsotg->status_buf = NULL;
+               }
+       } else {
+               kfree(hsotg->status_buf);
+               hsotg->status_buf = NULL;
+       }
+
+       ahbcfg = readl(hsotg->regs + GAHBCFG);
+
+       /* Disable all interrupts */
+       ahbcfg &= ~GAHBCFG_GLBL_INTR_EN;
+       writel(ahbcfg, hsotg->regs + GAHBCFG);
+       writel(0, hsotg->regs + GINTMSK);
+
+       if (hsotg->snpsid >= DWC2_CORE_REV_3_00a) {
+               dctl = readl(hsotg->regs + DCTL);
+               dctl |= DCTL_SFTDISCON;
+               writel(dctl, hsotg->regs + DCTL);
+       }
+
+       if (hsotg->wq_otg) {
+               if (!cancel_work_sync(&hsotg->wf_otg))
+                       flush_workqueue(hsotg->wq_otg);
+               destroy_workqueue(hsotg->wq_otg);
+       }
+
+       kfree(hsotg->core_params);
+       hsotg->core_params = NULL;
+       del_timer(&hsotg->wkp_timer);
+}
+
+static void dwc2_hcd_release(struct dwc2_hsotg *hsotg)
+{
+       /* Turn off all host-specific interrupts */
+       dwc2_disable_host_interrupts(hsotg);
+
+       dwc2_hcd_free(hsotg);
+}
+
+static void dwc2_set_uninitialized(int *p, int size)
+{
+       int i;
+
+       for (i = 0; i < size; i++)
+               p[i] = -1;
+}
+
+/*
+ * Initializes the HCD. This function allocates memory for and initializes the
+ * static parts of the usb_hcd and dwc2_hsotg structures. It also registers the
+ * USB bus with the core and calls the hc_driver->start() function. It returns
+ * a negative error on failure.
+ */
+int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
+                 struct dwc2_core_params *params)
+{
+       struct usb_hcd *hcd;
+       struct dwc2_host_chan *channel;
+       u32 snpsid, gusbcfg, hcfg;
+       int i, num_channels;
+       int retval = -ENOMEM;
+
+       dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n");
+
+       /*
+        * Attempt to ensure this device is really a DWC_otg Controller.
+        * Read and verify the GSNPSID register contents. The value should be
+        * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3",
+        * as in "OTG version 2.xx" or "OTG version 3.xx".
+        */
+       snpsid = readl(hsotg->regs + GSNPSID);
+       if ((snpsid & 0xfffff000) != 0x4f542000 &&
+           (snpsid & 0xfffff000) != 0x4f543000) {
+               dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", snpsid);
+               retval = -ENODEV;
+               goto error1;
+       }
+
+       /*
+        * Store the contents of the hardware configuration registers here for
+        * easy access later
+        */
+       hsotg->hwcfg1 = readl(hsotg->regs + GHWCFG1);
+       hsotg->hwcfg2 = readl(hsotg->regs + GHWCFG2);
+       hsotg->hwcfg3 = readl(hsotg->regs + GHWCFG3);
+       hsotg->hwcfg4 = readl(hsotg->regs + GHWCFG4);
+
+       dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hsotg->hwcfg1);
+       dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hsotg->hwcfg2);
+       dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hsotg->hwcfg3);
+       dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hsotg->hwcfg4);
+
+       /* Force host mode to get HPTXFSIZ exact power on value */
+       gusbcfg = readl(hsotg->regs + GUSBCFG);
+       gusbcfg |= GUSBCFG_FORCEHOSTMODE;
+       writel(gusbcfg, hsotg->regs + GUSBCFG);
+       usleep_range(100000, 150000);
+
+       hsotg->hptxfsiz = readl(hsotg->regs + HPTXFSIZ);
+       dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hsotg->hptxfsiz);
+       gusbcfg = readl(hsotg->regs + GUSBCFG);
+       gusbcfg &= ~GUSBCFG_FORCEHOSTMODE;
+       writel(gusbcfg, hsotg->regs + GUSBCFG);
+       usleep_range(100000, 150000);
+
+       hcfg = readl(hsotg->regs + HCFG);
+       dev_dbg(hsotg->dev, "hcfg=%08x\n", hcfg);
+       dev_dbg(hsotg->dev, "op_mode=%0x\n",
+               hsotg->hwcfg2 >> GHWCFG2_OP_MODE_SHIFT &
+               GHWCFG2_OP_MODE_MASK >> GHWCFG2_OP_MODE_SHIFT);
+       dev_dbg(hsotg->dev, "arch=%0x\n",
+               hsotg->hwcfg2 >> GHWCFG2_ARCHITECTURE_SHIFT &
+               GHWCFG2_ARCHITECTURE_MASK >> GHWCFG2_ARCHITECTURE_SHIFT);
+       dev_dbg(hsotg->dev, "num_dev_ep=%d\n",
+               hsotg->hwcfg2 >> GHWCFG2_NUM_DEV_EP_SHIFT &
+               GHWCFG2_NUM_DEV_EP_MASK >> GHWCFG2_NUM_DEV_EP_SHIFT);
+       dev_dbg(hsotg->dev, "max_host_chan=%d\n",
+               hsotg->hwcfg2 >> GHWCFG2_NUM_HOST_CHAN_SHIFT &
+               GHWCFG2_NUM_HOST_CHAN_MASK >> GHWCFG2_NUM_HOST_CHAN_SHIFT);
+       dev_dbg(hsotg->dev, "nonperio_tx_q_depth=0x%0x\n",
+               hsotg->hwcfg2 >> GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT &
+               GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK >>
+                               GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT);
+       dev_dbg(hsotg->dev, "host_perio_tx_q_depth=0x%0x\n",
+               hsotg->hwcfg2 >> GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT &
+               GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK >>
+                               GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT);
+       dev_dbg(hsotg->dev, "dev_token_q_depth=0x%0x\n",
+               hsotg->hwcfg2 >> GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT &
+               GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK >>
+                               GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT);
+
+#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
+       hsotg->frame_num_array = kzalloc(sizeof(*hsotg->frame_num_array) *
+                                        FRAME_NUM_ARRAY_SIZE, GFP_KERNEL);
+       if (!hsotg->frame_num_array)
+               goto error1;
+       hsotg->last_frame_num_array = kzalloc(
+                       sizeof(*hsotg->last_frame_num_array) *
+                       FRAME_NUM_ARRAY_SIZE, GFP_KERNEL);
+       if (!hsotg->last_frame_num_array)
+               goto error1;
+       hsotg->last_frame_num = HFNUM_MAX_FRNUM;
+#endif
+
+       hsotg->core_params = kzalloc(sizeof(*hsotg->core_params), GFP_KERNEL);
+       if (!hsotg->core_params)
+               goto error1;
+
+       dwc2_set_uninitialized((int *)hsotg->core_params,
+                              sizeof(*hsotg->core_params) / sizeof(int));
+
+       /* Validate parameter values */
+       dwc2_set_parameters(hsotg, params);
+
+       /* Set device flags indicating whether the HCD supports DMA */
+       if (hsotg->core_params->dma_enable > 0) {
+               if (dma_set_mask(hsotg->dev, DMA_BIT_MASK(31)) < 0)
+                       dev_warn(hsotg->dev,
+                                "can't enable workaround for >2GB RAM\n");
+               if (dma_set_coherent_mask(hsotg->dev, DMA_BIT_MASK(31)) < 0)
+                       dev_warn(hsotg->dev,
+                                "can't enable workaround for >2GB RAM\n");
+       } else {
+               dma_set_mask(hsotg->dev, 0);
+               dma_set_coherent_mask(hsotg->dev, 0);
+       }
+
+       hcd = usb_create_hcd(&dwc2_hc_driver, hsotg->dev, dev_name(hsotg->dev));
+       if (!hcd)
+               goto error1;
+
+       hcd->has_tt = 1;
+
+       spin_lock_init(&hsotg->lock);
+       ((struct wrapper_priv_data *) &hcd->hcd_priv)->hsotg = hsotg;
+       hsotg->priv = hcd;
+
+       /* Initialize the DWC_otg core, and select the Phy type */
+       retval = dwc2_core_init(hsotg, true);
+       if (retval)
+               goto error2;
+
+       /*
+        * Disable the global interrupt until all the interrupt handlers are
+        * installed
+        */
+       dwc2_disable_global_interrupts(hsotg);
+
+       /* Create new workqueue and init work */
+       hsotg->wq_otg = create_singlethread_workqueue("dwc_otg");
+       if (!hsotg->wq_otg) {
+               dev_err(hsotg->dev, "Failed to create workqueue\n");
+               goto error2;
+       }
+       INIT_WORK(&hsotg->wf_otg, dwc2_conn_id_status_change);
+
+       hsotg->snpsid = readl(hsotg->regs + GSNPSID);
+       dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x\n",
+               hsotg->snpsid >> 12 & 0xf, hsotg->snpsid >> 8 & 0xf,
+               hsotg->snpsid >> 4 & 0xf, hsotg->snpsid & 0xf);
+
+       setup_timer(&hsotg->wkp_timer, dwc2_wakeup_detected,
+                   (unsigned long)hsotg);
+
+       /* Initialize the non-periodic schedule */
+       INIT_LIST_HEAD(&hsotg->non_periodic_sched_inactive);
+       INIT_LIST_HEAD(&hsotg->non_periodic_sched_active);
+
+       /* Initialize the periodic schedule */
+       INIT_LIST_HEAD(&hsotg->periodic_sched_inactive);
+       INIT_LIST_HEAD(&hsotg->periodic_sched_ready);
+       INIT_LIST_HEAD(&hsotg->periodic_sched_assigned);
+       INIT_LIST_HEAD(&hsotg->periodic_sched_queued);
+
+       /*
+        * Create a host channel descriptor for each host channel implemented
+        * in the controller. Initialize the channel descriptor array.
+        */
+       INIT_LIST_HEAD(&hsotg->free_hc_list);
+       num_channels = hsotg->core_params->host_channels;
+       memset(&hsotg->hc_ptr_array[0], 0, sizeof(hsotg->hc_ptr_array));
+
+       for (i = 0; i < num_channels; i++) {
+               channel = kzalloc(sizeof(*channel), GFP_KERNEL);
+               if (channel == NULL)
+                       goto error3;
+               channel->hc_num = i;
+               hsotg->hc_ptr_array[i] = channel;
+       }
+
+       /* Initialize hsotg start work */
+       INIT_DELAYED_WORK(&hsotg->start_work, dwc2_hcd_start_func);
+
+       /* Initialize port reset work */
+       INIT_DELAYED_WORK(&hsotg->reset_work, dwc2_hcd_reset_func);
+
+       /*
+        * Allocate space for storing data on status transactions. Normally no
+        * data is sent, but this space acts as a bit bucket. This must be
+        * done after usb_add_hcd since that function allocates the DMA buffer
+        * pool.
+        */
+       if (hsotg->core_params->dma_enable > 0)
+               hsotg->status_buf = dma_alloc_coherent(hsotg->dev,
+                                       DWC2_HCD_STATUS_BUF_SIZE,
+                                       &hsotg->status_buf_dma, GFP_KERNEL);
+       else
+               hsotg->status_buf = kzalloc(DWC2_HCD_STATUS_BUF_SIZE,
+                                         GFP_KERNEL);
+
+       if (!hsotg->status_buf)
+               goto error3;
+
+       hsotg->otg_port = 1;
+       hsotg->frame_list = NULL;
+       hsotg->frame_list_dma = 0;
+       hsotg->periodic_qh_count = 0;
+
+       /* Initiate lx_state to L3 disconnected state */
+       hsotg->lx_state = DWC2_L3;
+
+       hcd->self.otg_port = hsotg->otg_port;
+
+       /* Don't support SG list at this point */
+       hcd->self.sg_tablesize = 0;
+
+       /*
+        * Finish generic HCD initialization and start the HCD. This function
+        * allocates the DMA buffer pool, registers the USB bus, requests the
+        * IRQ line, and calls hcd_start method.
+        */
+       retval = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED);
+       if (retval < 0)
+               goto error3;
+
+       dwc2_dump_global_registers(hsotg);
+       dwc2_dump_host_registers(hsotg);
+       dwc2_hcd_dump_state(hsotg);
+
+       dwc2_enable_global_interrupts(hsotg);
+
+       return 0;
+
+error3:
+       dwc2_hcd_release(hsotg);
+error2:
+       usb_put_hcd(hcd);
+error1:
+       kfree(hsotg->core_params);
+
+#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
+       kfree(hsotg->last_frame_num_array);
+       kfree(hsotg->frame_num_array);
+#endif
+
+       dev_err(hsotg->dev, "%s() FAILED, returning %d\n", __func__, retval);
+       return retval;
+}
+EXPORT_SYMBOL_GPL(dwc2_hcd_init);
+
+/*
+ * Removes the HCD.
+ * Frees memory and resources associated with the HCD and deregisters the bus.
+ */
+void dwc2_hcd_remove(struct dwc2_hsotg *hsotg)
+{
+       struct usb_hcd *hcd;
+
+       dev_dbg(hsotg->dev, "DWC OTG HCD REMOVE\n");
+
+       hcd = dwc2_hsotg_to_hcd(hsotg);
+       dev_dbg(hsotg->dev, "hsotg->hcd = %p\n", hcd);
+
+       if (!hcd) {
+               dev_dbg(hsotg->dev, "%s: dwc2_hsotg_to_hcd(hsotg) NULL!\n",
+                       __func__);
+               return;
+       }
+
+       usb_remove_hcd(hcd);
+       hsotg->priv = NULL;
+       dwc2_hcd_release(hsotg);
+       usb_put_hcd(hcd);
+
+#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
+       kfree(hsotg->last_frame_num_array);
+       kfree(hsotg->frame_num_array);
+#endif
+}
+EXPORT_SYMBOL_GPL(dwc2_hcd_remove);
diff --git a/drivers/staging/dwc2/hcd.h b/drivers/staging/dwc2/hcd.h
new file mode 100644 (file)
index 0000000..8a60dcf
--- /dev/null
@@ -0,0 +1,737 @@
+/*
+ * hcd.h - DesignWare HS OTG Controller host-mode declarations
+ *
+ * Copyright (C) 2004-2013 Synopsys, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. 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.
+ * 3. The names of the above-listed copyright holders may not 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 the 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 OWNER 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 __DWC2_HCD_H__
+#define __DWC2_HCD_H__
+
+/*
+ * This file contains the structures, constants, and interfaces for the
+ * Host Contoller Driver (HCD)
+ *
+ * The Host Controller Driver (HCD) is responsible for translating requests
+ * from the USB Driver into the appropriate actions on the DWC_otg controller.
+ * It isolates the USBD from the specifics of the controller by providing an
+ * API to the USBD.
+ */
+
+struct dwc2_qh;
+
+/**
+ * struct dwc2_host_chan - Software host channel descriptor
+ *
+ * @hc_num:             Host channel number, used for register address lookup
+ * @dev_addr:           Address of the device
+ * @ep_num:             Endpoint of the device
+ * @ep_is_in:           Endpoint direction
+ * @speed:              Device speed. One of the following values:
+ *                       - USB_SPEED_LOW
+ *                       - USB_SPEED_FULL
+ *                       - USB_SPEED_HIGH
+ * @ep_type:            Endpoint type. One of the following values:
+ *                       - USB_ENDPOINT_XFER_CONTROL: 0
+ *                       - USB_ENDPOINT_XFER_ISOC:    1
+ *                       - USB_ENDPOINT_XFER_BULK:    2
+ *                       - USB_ENDPOINT_XFER_INTR:    3
+ * @max_packet:         Max packet size in bytes
+ * @data_pid_start:     PID for initial transaction.
+ *                       0: DATA0
+ *                       1: DATA2
+ *                       2: DATA1
+ *                       3: MDATA (non-Control EP),
+ *                          SETUP (Control EP)
+ * @multi_count:        Number of additional periodic transactions per
+ *                      (micro)frame
+ * @xfer_buf:           Pointer to current transfer buffer position
+ * @xfer_dma:           DMA address of xfer_buf
+ * @align_buf:          In Buffer DMA mode this will be used if xfer_buf is not
+ *                      DWORD aligned
+ * @xfer_len:           Total number of bytes to transfer
+ * @xfer_count:         Number of bytes transferred so far
+ * @start_pkt_count:    Packet count at start of transfer
+ * @xfer_started:       True if the transfer has been started
+ * @ping:               True if a PING request should be issued on this channel
+ * @error_state:        True if the error count for this transaction is non-zero
+ * @halt_on_queue:      True if this channel should be halted the next time a
+ *                      request is queued for the channel. This is necessary in
+ *                      slave mode if no request queue space is available when
+ *                      an attempt is made to halt the channel.
+ * @halt_pending:       True if the host channel has been halted, but the core
+ *                      is not finished flushing queued requests
+ * @do_split:           Enable split for the channel
+ * @complete_split:     Enable complete split
+ * @hub_addr:           Address of high speed hub for the split
+ * @hub_port:           Port of the low/full speed device for the split
+ * @xact_pos:           Split transaction position. One of the following values:
+ *                       - DWC2_HCSPLT_XACTPOS_MID
+ *                       - DWC2_HCSPLT_XACTPOS_BEGIN
+ *                       - DWC2_HCSPLT_XACTPOS_END
+ *                       - DWC2_HCSPLT_XACTPOS_ALL
+ * @requests:           Number of requests issued for this channel since it was
+ *                      assigned to the current transfer (not counting PINGs)
+ * @schinfo:            Scheduling micro-frame bitmap
+ * @ntd:                Number of transfer descriptors for the transfer
+ * @halt_status:        Reason for halting the host channel
+ * @hcint               Contents of the HCINT register when the interrupt came
+ * @qh:                 QH for the transfer being processed by this channel
+ * @hc_list_entry:      For linking to list of host channels
+ * @desc_list_addr:     Current QH's descriptor list DMA address
+ *
+ * This structure represents the state of a single host channel when acting in
+ * host mode. It contains the data items needed to transfer packets to an
+ * endpoint via a host channel.
+ */
+struct dwc2_host_chan {
+       u8 hc_num;
+
+       unsigned dev_addr:7;
+       unsigned ep_num:4;
+       unsigned ep_is_in:1;
+       unsigned speed:4;
+       unsigned ep_type:2;
+       unsigned max_packet:11;
+       unsigned data_pid_start:2;
+#define DWC2_HC_PID_DATA0      (TSIZ_SC_MC_PID_DATA0 >> TSIZ_SC_MC_PID_SHIFT)
+#define DWC2_HC_PID_DATA2      (TSIZ_SC_MC_PID_DATA2 >> TSIZ_SC_MC_PID_SHIFT)
+#define DWC2_HC_PID_DATA1      (TSIZ_SC_MC_PID_DATA1 >> TSIZ_SC_MC_PID_SHIFT)
+#define DWC2_HC_PID_MDATA      (TSIZ_SC_MC_PID_MDATA >> TSIZ_SC_MC_PID_SHIFT)
+#define DWC2_HC_PID_SETUP      (TSIZ_SC_MC_PID_SETUP >> TSIZ_SC_MC_PID_SHIFT)
+
+       unsigned multi_count:2;
+
+       u8 *xfer_buf;
+       dma_addr_t xfer_dma;
+       dma_addr_t align_buf;
+       u32 xfer_len;
+       u32 xfer_count;
+       u16 start_pkt_count;
+       u8 xfer_started;
+       u8 do_ping;
+       u8 error_state;
+       u8 halt_on_queue;
+       u8 halt_pending;
+       u8 do_split;
+       u8 complete_split;
+       u8 hub_addr;
+       u8 hub_port;
+       u8 xact_pos;
+#define DWC2_HCSPLT_XACTPOS_MID        (HCSPLT_XACTPOS_MID >> HCSPLT_XACTPOS_SHIFT)
+#define DWC2_HCSPLT_XACTPOS_END        (HCSPLT_XACTPOS_END >> HCSPLT_XACTPOS_SHIFT)
+#define DWC2_HCSPLT_XACTPOS_BEGIN (HCSPLT_XACTPOS_BEGIN >> HCSPLT_XACTPOS_SHIFT)
+#define DWC2_HCSPLT_XACTPOS_ALL        (HCSPLT_XACTPOS_ALL >> HCSPLT_XACTPOS_SHIFT)
+
+       u8 requests;
+       u8 schinfo;
+       u16 ntd;
+       enum dwc2_halt_status halt_status;
+       u32 hcint;
+       struct dwc2_qh *qh;
+       struct list_head hc_list_entry;
+       dma_addr_t desc_list_addr;
+};
+
+struct dwc2_hcd_pipe_info {
+       u8 dev_addr;
+       u8 ep_num;
+       u8 pipe_type;
+       u8 pipe_dir;
+       u16 mps;
+};
+
+struct dwc2_hcd_iso_packet_desc {
+       u32 offset;
+       u32 length;
+       u32 actual_length;
+       u32 status;
+};
+
+struct dwc2_qtd;
+
+struct dwc2_hcd_urb {
+       void *priv;
+       struct dwc2_qtd *qtd;
+       void *buf;
+       dma_addr_t dma;
+       void *setup_packet;
+       dma_addr_t setup_dma;
+       u32 length;
+       u32 actual_length;
+       u32 status;
+       u32 error_count;
+       u32 packet_count;
+       u32 flags;
+       u16 interval;
+       struct dwc2_hcd_pipe_info pipe_info;
+       struct dwc2_hcd_iso_packet_desc iso_descs[0];
+};
+
+/* Phases for control transfers */
+enum dwc2_control_phase {
+       DWC2_CONTROL_SETUP,
+       DWC2_CONTROL_DATA,
+       DWC2_CONTROL_STATUS,
+};
+
+/* Transaction types */
+enum dwc2_transaction_type {
+       DWC2_TRANSACTION_NONE,
+       DWC2_TRANSACTION_PERIODIC,
+       DWC2_TRANSACTION_NON_PERIODIC,
+       DWC2_TRANSACTION_ALL,
+};
+
+/**
+ * struct dwc2_qh - Software queue head structure
+ *
+ * @ep_type:            Endpoint type. One of the following values:
+ *                       - USB_ENDPOINT_XFER_CONTROL
+ *                       - USB_ENDPOINT_XFER_BULK
+ *                       - USB_ENDPOINT_XFER_INT
+ *                       - USB_ENDPOINT_XFER_ISOC
+ * @ep_is_in:           Endpoint direction
+ * @maxp:               Value from wMaxPacketSize field of Endpoint Descriptor
+ * @dev_speed:          Device speed. One of the following values:
+ *                       - USB_SPEED_LOW
+ *                       - USB_SPEED_FULL
+ *                       - USB_SPEED_HIGH
+ * @data_toggle:        Determines the PID of the next data packet for
+ *                      non-controltransfers. Ignored for control transfers.
+ *                      One of the following values:
+ *                       - DWC2_HC_PID_DATA0
+ *                       - DWC2_HC_PID_DATA1
+ * @ping_state:         Ping state
+ * @do_split:           Full/low speed endpoint on high-speed hub requires split
+ * @qtd_list:           List of QTDs for this QH
+ * @channel:            Host channel currently processing transfers for this QH
+ * @usecs:              Bandwidth in microseconds per (micro)frame
+ * @interval:           Interval between transfers in (micro)frames
+ * @sched_frame:        (micro)frame to initialize a periodic transfer.
+ *                      The transfer executes in the following (micro)frame.
+ * @start_split_frame:  (Micro)frame at which last start split was initialized
+ * @dw_align_buf:       Used instead of original buffer if its physical address
+ *                      is not dword-aligned
+ * @dw_align_buf_dma:   DMA address for align_buf
+ * @qh_list_entry:      Entry for QH in either the periodic or non-periodic
+ *                      schedule
+ * @desc_list:          List of transfer descriptors
+ * @desc_list_dma:      Physical address of desc_list
+ * @n_bytes:            Xfer Bytes array. Each element corresponds to a transfer
+ *                      descriptor and indicates original XferSize value for the
+ *                      descriptor
+ * @ntd:                Actual number of transfer descriptors in a list
+ * @td_first:           Index of first activated isochronous transfer descriptor
+ * @td_last:            Index of last activated isochronous transfer descriptor
+ * @tt_buffer_dirty     True if clear_tt_buffer_complete is pending
+ *
+ * A Queue Head (QH) holds the static characteristics of an endpoint and
+ * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
+ * be entered in either the non-periodic or periodic schedule.
+ */
+struct dwc2_qh {
+       u8 ep_type;
+       u8 ep_is_in;
+       u16 maxp;
+       u8 dev_speed;
+       u8 data_toggle;
+       u8 ping_state;
+       u8 do_split;
+       struct list_head qtd_list;
+       struct dwc2_host_chan *channel;
+       u16 usecs;
+       u16 interval;
+       u16 sched_frame;
+       u16 start_split_frame;
+       u8 *dw_align_buf;
+       dma_addr_t dw_align_buf_dma;
+       struct list_head qh_list_entry;
+       struct dwc2_hcd_dma_desc *desc_list;
+       dma_addr_t desc_list_dma;
+       u32 *n_bytes;
+       u16 ntd;
+       u8 td_first;
+       u8 td_last;
+       unsigned tt_buffer_dirty:1;
+};
+
+/**
+ * struct dwc2_qtd - Software queue transfer descriptor (QTD)
+ *
+ * @control_phase:      Current phase for control transfers (Setup, Data, or
+ *                      Status)
+ * @in_process:         Indicates if this QTD is currently processed by HW
+ * @data_toggle:        Determines the PID of the next data packet for the
+ *                      data phase of control transfers. Ignored for other
+ *                      transfer types. One of the following values:
+ *                       - DWC2_HC_PID_DATA0
+ *                       - DWC2_HC_PID_DATA1
+ * @complete_split:     Keeps track of the current split type for FS/LS
+ *                      endpoints on a HS Hub
+ * @isoc_split_pos:     Position of the ISOC split in full/low speed
+ * @isoc_frame_index:   Index of the next frame descriptor for an isochronous
+ *                      transfer. A frame descriptor describes the buffer
+ *                      position and length of the data to be transferred in the
+ *                      next scheduled (micro)frame of an isochronous transfer.
+ *                      It also holds status for that transaction. The frame
+ *                      index starts at 0.
+ * @isoc_split_offset:  Position of the ISOC split in the buffer for the
+ *                      current frame
+ * @ssplit_out_xfer_count: How many bytes transferred during SSPLIT OUT
+ * @error_count:        Holds the number of bus errors that have occurred for
+ *                      a transaction within this transfer
+ * @n_desc:             Number of DMA descriptors for this QTD
+ * @isoc_frame_index_last: Last activated frame (packet) index, used in
+ *                      descriptor DMA mode only
+ * @urb:                URB for this transfer
+ * @qh:                 Queue head for this QTD
+ * @qtd_list_entry:     For linking to the QH's list of QTDs
+ *
+ * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
+ * interrupt, or isochronous transfer. A single QTD is created for each URB
+ * (of one of these types) submitted to the HCD. The transfer associated with
+ * a QTD may require one or multiple transactions.
+ *
+ * A QTD is linked to a Queue Head, which is entered in either the
+ * non-periodic or periodic schedule for execution. When a QTD is chosen for
+ * execution, some or all of its transactions may be executed. After
+ * execution, the state of the QTD is updated. The QTD may be retired if all
+ * its transactions are complete or if an error occurred. Otherwise, it
+ * remains in the schedule so more transactions can be executed later.
+ */
+struct dwc2_qtd {
+       enum dwc2_control_phase control_phase;
+       u8 in_process;
+       u8 data_toggle;
+       u8 complete_split;
+       u8 isoc_split_pos;
+       u16 isoc_frame_index;
+       u16 isoc_split_offset;
+       u32 ssplit_out_xfer_count;
+       u8 error_count;
+       u8 n_desc;
+       u16 isoc_frame_index_last;
+       struct dwc2_hcd_urb *urb;
+       struct dwc2_qh *qh;
+       struct list_head qtd_list_entry;
+};
+
+#ifdef DEBUG
+struct hc_xfer_info {
+       struct dwc2_hsotg *hsotg;
+       struct dwc2_host_chan *chan;
+};
+#endif
+
+/* Gets the struct usb_hcd that contains a struct dwc2_hsotg */
+static inline struct usb_hcd *dwc2_hsotg_to_hcd(struct dwc2_hsotg *hsotg)
+{
+       return (struct usb_hcd *)hsotg->priv;
+}
+
+/*
+ * Inline used to disable one channel interrupt. Channel interrupts are
+ * disabled when the channel is halted or released by the interrupt handler.
+ * There is no need to handle further interrupts of that type until the
+ * channel is re-assigned. In fact, subsequent handling may cause crashes
+ * because the channel structures are cleaned up when the channel is released.
+ */
+static inline void disable_hc_int(struct dwc2_hsotg *hsotg, int chnum, u32 intr)
+{
+       u32 mask = readl(hsotg->regs + HCINTMSK(chnum));
+
+       mask &= ~intr;
+       writel(mask, hsotg->regs + HCINTMSK(chnum));
+}
+
+/*
+ * Returns the mode of operation, host or device
+ */
+static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg)
+{
+       return (readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) != 0;
+}
+static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg)
+{
+       return (readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) == 0;
+}
+
+/*
+ * Reads HPRT0 in preparation to modify. It keeps the WC bits 0 so that if they
+ * are read as 1, they won't clear when written back.
+ */
+static inline u32 dwc2_read_hprt0(struct dwc2_hsotg *hsotg)
+{
+       u32 hprt0 = readl(hsotg->regs + HPRT0);
+
+       hprt0 &= ~(HPRT0_ENA | HPRT0_CONNDET | HPRT0_ENACHG | HPRT0_OVRCURRCHG);
+       return hprt0;
+}
+
+static inline u8 dwc2_hcd_get_ep_num(struct dwc2_hcd_pipe_info *pipe)
+{
+       return pipe->ep_num;
+}
+
+static inline u8 dwc2_hcd_get_pipe_type(struct dwc2_hcd_pipe_info *pipe)
+{
+       return pipe->pipe_type;
+}
+
+static inline u16 dwc2_hcd_get_mps(struct dwc2_hcd_pipe_info *pipe)
+{
+       return pipe->mps;
+}
+
+static inline u8 dwc2_hcd_get_dev_addr(struct dwc2_hcd_pipe_info *pipe)
+{
+       return pipe->dev_addr;
+}
+
+static inline u8 dwc2_hcd_is_pipe_isoc(struct dwc2_hcd_pipe_info *pipe)
+{
+       return pipe->pipe_type == USB_ENDPOINT_XFER_ISOC;
+}
+
+static inline u8 dwc2_hcd_is_pipe_int(struct dwc2_hcd_pipe_info *pipe)
+{
+       return pipe->pipe_type == USB_ENDPOINT_XFER_INT;
+}
+
+static inline u8 dwc2_hcd_is_pipe_bulk(struct dwc2_hcd_pipe_info *pipe)
+{
+       return pipe->pipe_type == USB_ENDPOINT_XFER_BULK;
+}
+
+static inline u8 dwc2_hcd_is_pipe_control(struct dwc2_hcd_pipe_info *pipe)
+{
+       return pipe->pipe_type == USB_ENDPOINT_XFER_CONTROL;
+}
+
+static inline u8 dwc2_hcd_is_pipe_in(struct dwc2_hcd_pipe_info *pipe)
+{
+       return pipe->pipe_dir == USB_DIR_IN;
+}
+
+static inline u8 dwc2_hcd_is_pipe_out(struct dwc2_hcd_pipe_info *pipe)
+{
+       return !dwc2_hcd_is_pipe_in(pipe);
+}
+
+extern int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
+                        struct dwc2_core_params *params);
+extern void dwc2_hcd_remove(struct dwc2_hsotg *hsotg);
+extern int dwc2_set_parameters(struct dwc2_hsotg *hsotg,
+                              struct dwc2_core_params *params);
+
+/* Transaction Execution Functions */
+extern enum dwc2_transaction_type dwc2_hcd_select_transactions(
+                                               struct dwc2_hsotg *hsotg);
+extern void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg,
+                                       enum dwc2_transaction_type tr_type);
+
+/* Schedule Queue Functions */
+/* Implemented in hcd_queue.c */
+extern void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
+extern int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
+extern void dwc2_hcd_qh_unlink(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
+extern void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
+                                  int sched_csplit);
+
+extern void dwc2_hcd_qtd_init(struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb);
+extern int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
+                           struct dwc2_qh **qh, gfp_t mem_flags);
+
+/* Unlinks and frees a QTD */
+static inline void dwc2_hcd_qtd_unlink_and_free(struct dwc2_hsotg *hsotg,
+                                               struct dwc2_qtd *qtd,
+                                               struct dwc2_qh *qh)
+{
+       list_del(&qtd->qtd_list_entry);
+       kfree(qtd);
+}
+
+/* Descriptor DMA support functions */
+extern void dwc2_hcd_start_xfer_ddma(struct dwc2_hsotg *hsotg,
+                                    struct dwc2_qh *qh);
+extern void dwc2_hcd_complete_xfer_ddma(struct dwc2_hsotg *hsotg,
+                                       struct dwc2_host_chan *chan, int chnum,
+                                       enum dwc2_halt_status halt_status);
+
+extern int dwc2_hcd_qh_init_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
+                                gfp_t mem_flags);
+extern void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh);
+
+/* Check if QH is non-periodic */
+#define dwc2_qh_is_non_per(_qh_ptr_) \
+       ((_qh_ptr_)->ep_type == USB_ENDPOINT_XFER_BULK || \
+        (_qh_ptr_)->ep_type == USB_ENDPOINT_XFER_CONTROL)
+
+/* High bandwidth multiplier as encoded in highspeed endpoint descriptors */
+#define dwc2_hb_mult(wmaxpacketsize) (1 + (((wmaxpacketsize) >> 11) & 0x03))
+
+/* Packet size for any kind of endpoint descriptor */
+#define dwc2_max_packet(wmaxpacketsize) ((wmaxpacketsize) & 0x07ff)
+
+/*
+ * Returns true if frame1 is less than or equal to frame2. The comparison is
+ * done modulo HFNUM_MAX_FRNUM. This accounts for the rollover of the
+ * frame number when the max frame number is reached.
+ */
+static inline int dwc2_frame_num_le(u16 frame1, u16 frame2)
+{
+       return ((frame2 - frame1) & HFNUM_MAX_FRNUM) <= (HFNUM_MAX_FRNUM >> 1);
+}
+
+/*
+ * Returns true if frame1 is greater than frame2. The comparison is done
+ * modulo HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
+ * number when the max frame number is reached.
+ */
+static inline int dwc2_frame_num_gt(u16 frame1, u16 frame2)
+{
+       return (frame1 != frame2) &&
+              ((frame1 - frame2) & HFNUM_MAX_FRNUM) < (HFNUM_MAX_FRNUM >> 1);
+}
+
+/*
+ * Increments frame by the amount specified by inc. The addition is done
+ * modulo HFNUM_MAX_FRNUM. Returns the incremented value.
+ */
+static inline u16 dwc2_frame_num_inc(u16 frame, u16 inc)
+{
+       return (frame + inc) & HFNUM_MAX_FRNUM;
+}
+
+static inline u16 dwc2_full_frame_num(u16 frame)
+{
+       return (frame & HFNUM_MAX_FRNUM) >> 3;
+}
+
+static inline u16 dwc2_micro_frame_num(u16 frame)
+{
+       return frame & 0x7;
+}
+
+/*
+ * Returns the Core Interrupt Status register contents, ANDed with the Core
+ * Interrupt Mask register contents
+ */
+static inline u32 dwc2_read_core_intr(struct dwc2_hsotg *hsotg)
+{
+       return readl(hsotg->regs + GINTSTS) & readl(hsotg->regs + GINTMSK);
+}
+
+static inline u32 dwc2_hcd_urb_get_status(struct dwc2_hcd_urb *dwc2_urb)
+{
+       return dwc2_urb->status;
+}
+
+static inline u32 dwc2_hcd_urb_get_actual_length(
+               struct dwc2_hcd_urb *dwc2_urb)
+{
+       return dwc2_urb->actual_length;
+}
+
+static inline u32 dwc2_hcd_urb_get_error_count(struct dwc2_hcd_urb *dwc2_urb)
+{
+       return dwc2_urb->error_count;
+}
+
+static inline void dwc2_hcd_urb_set_iso_desc_params(
+               struct dwc2_hcd_urb *dwc2_urb, int desc_num, u32 offset,
+               u32 length)
+{
+       dwc2_urb->iso_descs[desc_num].offset = offset;
+       dwc2_urb->iso_descs[desc_num].length = length;
+}
+
+static inline u32 dwc2_hcd_urb_get_iso_desc_status(
+               struct dwc2_hcd_urb *dwc2_urb, int desc_num)
+{
+       return dwc2_urb->iso_descs[desc_num].status;
+}
+
+static inline u32 dwc2_hcd_urb_get_iso_desc_actual_length(
+               struct dwc2_hcd_urb *dwc2_urb, int desc_num)
+{
+       return dwc2_urb->iso_descs[desc_num].actual_length;
+}
+
+static inline int dwc2_hcd_is_bandwidth_allocated(struct dwc2_hsotg *hsotg,
+                                                 struct usb_host_endpoint *ep)
+{
+       struct dwc2_qh *qh = ep->hcpriv;
+
+       if (qh && !list_empty(&qh->qh_list_entry))
+               return 1;
+
+       return 0;
+}
+
+static inline u16 dwc2_hcd_get_ep_bandwidth(struct dwc2_hsotg *hsotg,
+                                           struct usb_host_endpoint *ep)
+{
+       struct dwc2_qh *qh = ep->hcpriv;
+
+       if (!qh) {
+               WARN_ON(1);
+               return 0;
+       }
+
+       return qh->usecs;
+}
+
+extern void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,
+                                     struct dwc2_host_chan *chan, int chnum,
+                                     struct dwc2_qtd *qtd);
+
+/* HCD Core API */
+
+/**
+ * dwc2_hcd_intr() - Called on every hardware interrupt
+ *
+ * @hsotg: The DWC2 HCD
+ *
+ * Returns non zero if interrupt is handled
+ * Return 0 if interrupt is not handled
+ */
+extern int dwc2_hcd_intr(struct dwc2_hsotg *hsotg);
+
+/**
+ * dwc2_hcd_stop() - Halts the DWC_otg host mode operation
+ *
+ * @hsotg: The DWC2 HCD
+ */
+extern void dwc2_hcd_stop(struct dwc2_hsotg *hsotg);
+
+extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
+extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
+
+/**
+ * dwc2_hcd_is_b_host() - Returns 1 if core currently is acting as B host,
+ * and 0 otherwise
+ *
+ * @hsotg: The DWC2 HCD
+ */
+extern int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg);
+
+/**
+ * dwc2_hcd_get_frame_number() - Returns current frame number
+ *
+ * @hsotg: The DWC2 HCD
+ */
+extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
+
+/**
+ * dwc2_hcd_dump_state() - Dumps hsotg state
+ *
+ * @hsotg: The DWC2 HCD
+ *
+ * NOTE: This function will be removed once the peripheral controller code
+ * is integrated and the driver is stable
+ */
+extern void dwc2_hcd_dump_state(struct dwc2_hsotg *hsotg);
+
+/**
+ * dwc2_hcd_dump_frrem() - Dumps the average frame remaining at SOF
+ *
+ * @hsotg: The DWC2 HCD
+ *
+ * This can be used to determine average interrupt latency. Frame remaining is
+ * also shown for start transfer and two additional sample points.
+ *
+ * NOTE: This function will be removed once the peripheral controller code
+ * is integrated and the driver is stable
+ */
+extern void dwc2_hcd_dump_frrem(struct dwc2_hsotg *hsotg);
+
+/* URB interface */
+
+/* Transfer flags */
+#define URB_GIVEBACK_ASAP      0x1
+#define URB_SEND_ZERO_PACKET   0x2
+
+/* Host driver callbacks */
+
+extern void dwc2_host_start(struct dwc2_hsotg *hsotg);
+extern void dwc2_host_disconnect(struct dwc2_hsotg *hsotg);
+extern void dwc2_host_hub_info(struct dwc2_hsotg *hsotg, void *context,
+                              int *hub_addr, int *hub_port);
+extern int dwc2_host_get_speed(struct dwc2_hsotg *hsotg, void *context);
+extern void dwc2_host_complete(struct dwc2_hsotg *hsotg, void *context,
+                              struct dwc2_hcd_urb *dwc2_urb, int status);
+
+#ifdef DEBUG
+/*
+ * Macro to sample the remaining PHY clocks left in the current frame. This
+ * may be used during debugging to determine the average time it takes to
+ * execute sections of code. There are two possible sample points, "a" and
+ * "b", so the _letter_ argument must be one of these values.
+ *
+ * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
+ * example, "cat /sys/devices/lm0/hcd_frrem".
+ */
+#define dwc2_sample_frrem(_hcd_, _qh_, _letter_)                       \
+do {                                                                   \
+       struct hfnum_data _hfnum_;                                      \
+       struct dwc2_qtd *_qtd_;                                         \
+                                                                       \
+       _qtd_ = list_entry((_qh_)->qtd_list.next, struct dwc2_qtd,      \
+                          qtd_list_entry);                             \
+       if (usb_pipeint(_qtd_->urb->pipe) &&                            \
+           (_qh_)->start_split_frame != 0 && !_qtd_->complete_split) { \
+               _hfnum_.d32 = readl((_hcd_)->regs + HFNUM);             \
+               switch (_hfnum_.b.frnum & 0x7) {                        \
+               case 7:                                                 \
+                       (_hcd_)->hfnum_7_samples_##_letter_++;          \
+                       (_hcd_)->hfnum_7_frrem_accum_##_letter_ +=      \
+                               _hfnum_.b.frrem;                        \
+                       break;                                          \
+               case 0:                                                 \
+                       (_hcd_)->hfnum_0_samples_##_letter_++;          \
+                       (_hcd_)->hfnum_0_frrem_accum_##_letter_ +=      \
+                               _hfnum_.b.frrem;                        \
+                       break;                                          \
+               default:                                                \
+                       (_hcd_)->hfnum_other_samples_##_letter_++;      \
+                       (_hcd_)->hfnum_other_frrem_accum_##_letter_ +=  \
+                               _hfnum_.b.frrem;                        \
+                       break;                                          \
+               }                                                       \
+       }                                                               \
+} while (0)
+#else
+#define dwc2_sample_frrem(_hcd_, _qh_, _letter_)       do {} while (0)
+#endif
+
+#endif /* __DWC2_HCD_H__ */
diff --git a/drivers/staging/dwc2/hcd_ddma.c b/drivers/staging/dwc2/hcd_ddma.c
new file mode 100644 (file)
index 0000000..ab88f50
--- /dev/null
@@ -0,0 +1,1196 @@
+/*
+ * hcd_ddma.c - DesignWare HS OTG Controller descriptor DMA routines
+ *
+ * Copyright (C) 2004-2013 Synopsys, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. 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.
+ * 3. The names of the above-listed copyright holders may not 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 the 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 OWNER 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.
+ */
+
+/*
+ * This file contains the Descriptor DMA implementation for Host mode
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+
+#include <linux/usb/hcd.h>
+#include <linux/usb/ch11.h>
+
+#include "core.h"
+#include "hcd.h"
+
+static u16 dwc2_frame_list_idx(u16 frame)
+{
+       return frame & (FRLISTEN_64_SIZE - 1);
+}
+
+static u16 dwc2_desclist_idx_inc(u16 idx, u16 inc, u8 speed)
+{
+       return (idx + inc) &
+               ((speed == USB_SPEED_HIGH ? MAX_DMA_DESC_NUM_HS_ISOC :
+                 MAX_DMA_DESC_NUM_GENERIC) - 1);
+}
+
+static u16 dwc2_desclist_idx_dec(u16 idx, u16 inc, u8 speed)
+{
+       return (idx - inc) &
+               ((speed == USB_SPEED_HIGH ? MAX_DMA_DESC_NUM_HS_ISOC :
+                 MAX_DMA_DESC_NUM_GENERIC) - 1);
+}
+
+static u16 dwc2_max_desc_num(struct dwc2_qh *qh)
+{
+       return (qh->ep_type == USB_ENDPOINT_XFER_ISOC &&
+               qh->dev_speed == USB_SPEED_HIGH) ?
+               MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC;
+}
+
+static u16 dwc2_frame_incr_val(struct dwc2_qh *qh)
+{
+       return qh->dev_speed == USB_SPEED_HIGH ?
+              (qh->interval + 8 - 1) / 8 : qh->interval;
+}
+
+static int dwc2_desc_list_alloc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
+                               gfp_t flags)
+{
+       qh->desc_list = dma_alloc_coherent(hsotg->dev,
+                               sizeof(struct dwc2_hcd_dma_desc) *
+                               dwc2_max_desc_num(qh), &qh->desc_list_dma,
+                               flags);
+
+       if (!qh->desc_list)
+               return -ENOMEM;
+
+       memset(qh->desc_list, 0,
+              sizeof(struct dwc2_hcd_dma_desc) * dwc2_max_desc_num(qh));
+
+       qh->n_bytes = kzalloc(sizeof(u32) * dwc2_max_desc_num(qh), flags);
+       if (!qh->n_bytes) {
+               dma_free_coherent(hsotg->dev, sizeof(struct dwc2_hcd_dma_desc)
+                                 * dwc2_max_desc_num(qh), qh->desc_list,
+                                 qh->desc_list_dma);
+               qh->desc_list = NULL;
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+static void dwc2_desc_list_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
+{
+       if (qh->desc_list) {
+               dma_free_coherent(hsotg->dev, sizeof(struct dwc2_hcd_dma_desc)
+                                 * dwc2_max_desc_num(qh), qh->desc_list,
+                                 qh->desc_list_dma);
+               qh->desc_list = NULL;
+       }
+
+       kfree(qh->n_bytes);
+       qh->n_bytes = NULL;
+}
+
+static int dwc2_frame_list_alloc(struct dwc2_hsotg *hsotg, gfp_t mem_flags)
+{
+       if (hsotg->frame_list)
+               return 0;
+
+       hsotg->frame_list = dma_alloc_coherent(hsotg->dev,
+                                              4 * FRLISTEN_64_SIZE,
+                                              &hsotg->frame_list_dma,
+                                              mem_flags);
+       if (!hsotg->frame_list)
+               return -ENOMEM;
+
+       memset(hsotg->frame_list, 0, 4 * FRLISTEN_64_SIZE);
+       return 0;
+}
+
+static void dwc2_frame_list_free(struct dwc2_hsotg *hsotg)
+{
+       u32 *frame_list;
+       dma_addr_t frame_list_dma;
+       unsigned long flags;
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+
+       if (!hsotg->frame_list) {
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+               return;
+       }
+
+       frame_list = hsotg->frame_list;
+       frame_list_dma = hsotg->frame_list_dma;
+       hsotg->frame_list = NULL;
+
+       spin_unlock_irqrestore(&hsotg->lock, flags);
+
+       dma_free_coherent(hsotg->dev, 4 * FRLISTEN_64_SIZE, frame_list,
+                         frame_list_dma);
+}
+
+static void dwc2_per_sched_enable(struct dwc2_hsotg *hsotg, u32 fr_list_en)
+{
+       u32 hcfg;
+       unsigned long flags;
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+
+       hcfg = readl(hsotg->regs + HCFG);
+       if (hcfg & HCFG_PERSCHEDENA) {
+               /* already enabled */
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+               return;
+       }
+
+       writel(hsotg->frame_list_dma, hsotg->regs + HFLBADDR);
+
+       hcfg &= ~HCFG_FRLISTEN_MASK;
+       hcfg |= fr_list_en | HCFG_PERSCHEDENA;
+       dev_vdbg(hsotg->dev, "Enabling Periodic schedule\n");
+       writel(hcfg, hsotg->regs + HCFG);
+
+       spin_unlock_irqrestore(&hsotg->lock, flags);
+}
+
+static void dwc2_per_sched_disable(struct dwc2_hsotg *hsotg)
+{
+       u32 hcfg;
+       unsigned long flags;
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+
+       hcfg = readl(hsotg->regs + HCFG);
+       if (!(hcfg & HCFG_PERSCHEDENA)) {
+               /* already disabled */
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+               return;
+       }
+
+       hcfg &= ~HCFG_PERSCHEDENA;
+       dev_vdbg(hsotg->dev, "Disabling Periodic schedule\n");
+       writel(hcfg, hsotg->regs + HCFG);
+
+       spin_unlock_irqrestore(&hsotg->lock, flags);
+}
+
+/*
+ * Activates/Deactivates FrameList entries for the channel based on endpoint
+ * servicing period
+ */
+static void dwc2_update_frame_list(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
+                                  int enable)
+{
+       struct dwc2_host_chan *chan;
+       u16 i, j, inc;
+
+       if (!qh->channel) {
+               dev_err(hsotg->dev, "qh->channel = %p", qh->channel);
+               return;
+       }
+
+       if (!hsotg) {
+               dev_err(hsotg->dev, "------hsotg = %p", hsotg);
+               return;
+       }
+
+       if (!hsotg->frame_list) {
+               dev_err(hsotg->dev, "-------hsotg->frame_list = %p",
+                       hsotg->frame_list);
+               return;
+       }
+
+       chan = qh->channel;
+       inc = dwc2_frame_incr_val(qh);
+       if (qh->ep_type == USB_ENDPOINT_XFER_ISOC)
+               i = dwc2_frame_list_idx(qh->sched_frame);
+       else
+               i = 0;
+
+       j = i;
+       do {
+               if (enable)
+                       hsotg->frame_list[j] |= 1 << chan->hc_num;
+               else
+                       hsotg->frame_list[j] &= ~(1 << chan->hc_num);
+               j = (j + inc) & (FRLISTEN_64_SIZE - 1);
+       } while (j != i);
+
+       if (!enable)
+               return;
+
+       chan->schinfo = 0;
+       if (chan->speed == USB_SPEED_HIGH && qh->interval) {
+               j = 1;
+               /* TODO - check this */
+               inc = (8 + qh->interval - 1) / qh->interval;
+               for (i = 0; i < inc; i++) {
+                       chan->schinfo |= j;
+                       j = j << qh->interval;
+               }
+       } else {
+               chan->schinfo = 0xff;
+       }
+}
+
+static void dwc2_release_channel_ddma(struct dwc2_hsotg *hsotg,
+                                     struct dwc2_qh *qh)
+{
+       struct dwc2_host_chan *chan = qh->channel;
+
+       if (dwc2_qh_is_non_per(qh))
+               hsotg->non_periodic_channels--;
+       else
+               dwc2_update_frame_list(hsotg, qh, 0);
+
+       /*
+        * The condition is added to prevent double cleanup try in case of
+        * device disconnect. See channel cleanup in dwc2_hcd_disconnect().
+        */
+       if (chan->qh) {
+               if (!list_empty(&chan->hc_list_entry))
+                       list_del(&chan->hc_list_entry);
+               dwc2_hc_cleanup(hsotg, chan);
+               list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list);
+               chan->qh = NULL;
+       }
+
+       qh->channel = NULL;
+       qh->ntd = 0;
+
+       if (qh->desc_list)
+               memset(qh->desc_list, 0, sizeof(struct dwc2_hcd_dma_desc) *
+                      dwc2_max_desc_num(qh));
+}
+
+/**
+ * dwc2_hcd_qh_init_ddma() - Initializes a QH structure's Descriptor DMA
+ * related members
+ *
+ * @hsotg: The HCD state structure for the DWC OTG controller
+ * @qh:    The QH to init
+ *
+ * Return: 0 if successful, negative error code otherwise
+ *
+ * Allocates memory for the descriptor list. For the first periodic QH,
+ * allocates memory for the FrameList and enables periodic scheduling.
+ */
+int dwc2_hcd_qh_init_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
+                         gfp_t mem_flags)
+{
+       int retval;
+
+       if (qh->do_split) {
+               dev_err(hsotg->dev,
+                       "SPLIT Transfers are not supported in Descriptor DMA mode.\n");
+               retval = -EINVAL;
+               goto err0;
+       }
+
+       retval = dwc2_desc_list_alloc(hsotg, qh, mem_flags);
+       if (retval)
+               goto err0;
+
+       if (qh->ep_type == USB_ENDPOINT_XFER_ISOC ||
+           qh->ep_type == USB_ENDPOINT_XFER_INT) {
+               if (!hsotg->frame_list) {
+                       retval = dwc2_frame_list_alloc(hsotg, mem_flags);
+                       if (retval)
+                               goto err1;
+                       /* Enable periodic schedule on first periodic QH */
+                       dwc2_per_sched_enable(hsotg, HCFG_FRLISTEN_64);
+               }
+       }
+
+       qh->ntd = 0;
+       return 0;
+
+err1:
+       dwc2_desc_list_free(hsotg, qh);
+err0:
+       return retval;
+}
+
+/**
+ * dwc2_hcd_qh_free_ddma() - Frees a QH structure's Descriptor DMA related
+ * members
+ *
+ * @hsotg: The HCD state structure for the DWC OTG controller
+ * @qh:    The QH to free
+ *
+ * Frees descriptor list memory associated with the QH. If QH is periodic and
+ * the last, frees FrameList memory and disables periodic scheduling.
+ */
+void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
+{
+       dwc2_desc_list_free(hsotg, qh);
+
+       /*
+        * Channel still assigned due to some reasons.
+        * Seen on Isoc URB dequeue. Channel halted but no subsequent
+        * ChHalted interrupt to release the channel. Afterwards
+        * when it comes here from endpoint disable routine
+        * channel remains assigned.
+        */
+       if (qh->channel)
+               dwc2_release_channel_ddma(hsotg, qh);
+
+       if ((qh->ep_type == USB_ENDPOINT_XFER_ISOC ||
+            qh->ep_type == USB_ENDPOINT_XFER_INT) &&
+           !hsotg->periodic_channels && hsotg->frame_list) {
+               dwc2_per_sched_disable(hsotg);
+               dwc2_frame_list_free(hsotg);
+       }
+}
+
+static u8 dwc2_frame_to_desc_idx(struct dwc2_qh *qh, u16 frame_idx)
+{
+       if (qh->dev_speed == USB_SPEED_HIGH)
+               /* Descriptor set (8 descriptors) index which is 8-aligned */
+               return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
+       else
+               return frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1);
+}
+
+/*
+ * Determine starting frame for Isochronous transfer.
+ * Few frames skipped to prevent race condition with HC.
+ */
+static u16 dwc2_calc_starting_frame(struct dwc2_hsotg *hsotg,
+                                   struct dwc2_qh *qh, u16 *skip_frames)
+{
+       u16 frame;
+
+       hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg);
+
+       /* sched_frame is always frame number (not uFrame) both in FS and HS! */
+
+       /*
+        * skip_frames is used to limit activated descriptors number
+        * to avoid the situation when HC services the last activated
+        * descriptor firstly.
+        * Example for FS:
+        * Current frame is 1, scheduled frame is 3. Since HC always fetches
+        * the descriptor corresponding to curr_frame+1, the descriptor
+        * corresponding to frame 2 will be fetched. If the number of
+        * descriptors is max=64 (or greather) the list will be fully programmed
+        * with Active descriptors and it is possible case (rare) that the
+        * latest descriptor(considering rollback) corresponding to frame 2 will
+        * be serviced first. HS case is more probable because, in fact, up to
+        * 11 uframes (16 in the code) may be skipped.
+        */
+       if (qh->dev_speed == USB_SPEED_HIGH) {
+               /*
+                * Consider uframe counter also, to start xfer asap. If half of
+                * the frame elapsed skip 2 frames otherwise just 1 frame.
+                * Starting descriptor index must be 8-aligned, so if the
+                * current frame is near to complete the next one is skipped as
+                * well.
+                */
+               if (dwc2_micro_frame_num(hsotg->frame_number) >= 5) {
+                       *skip_frames = 2 * 8;
+                       frame = dwc2_frame_num_inc(hsotg->frame_number,
+                                                  *skip_frames);
+               } else {
+                       *skip_frames = 1 * 8;
+                       frame = dwc2_frame_num_inc(hsotg->frame_number,
+                                                  *skip_frames);
+               }
+
+               frame = dwc2_full_frame_num(frame);
+       } else {
+               /*
+                * Two frames are skipped for FS - the current and the next.
+                * But for descriptor programming, 1 frame (descriptor) is
+                * enough, see example above.
+                */
+               *skip_frames = 1;
+               frame = dwc2_frame_num_inc(hsotg->frame_number, 2);
+       }
+
+       return frame;
+}
+
+/*
+ * Calculate initial descriptor index for isochronous transfer based on
+ * scheduled frame
+ */
+static u16 dwc2_recalc_initial_desc_idx(struct dwc2_hsotg *hsotg,
+                                       struct dwc2_qh *qh)
+{
+       u16 frame, fr_idx, fr_idx_tmp, skip_frames;
+
+       /*
+        * With current ISOC processing algorithm the channel is being released
+        * when no more QTDs in the list (qh->ntd == 0). Thus this function is
+        * called only when qh->ntd == 0 and qh->channel == 0.
+        *
+        * So qh->channel != NULL branch is not used and just not removed from
+        * the source file. It is required for another possible approach which
+        * is, do not disable and release the channel when ISOC session
+        * completed, just move QH to inactive schedule until new QTD arrives.
+        * On new QTD, the QH moved back to 'ready' schedule, starting frame and
+        * therefore starting desc_index are recalculated. In this case channel
+        * is released only on ep_disable.
+        */
+
+       /*
+        * Calculate starting descriptor index. For INTERRUPT endpoint it is
+        * always 0.
+        */
+       if (qh->channel) {
+               frame = dwc2_calc_starting_frame(hsotg, qh, &skip_frames);
+               /*
+                * Calculate initial descriptor index based on FrameList current
+                * bitmap and servicing period
+                */
+               fr_idx_tmp = dwc2_frame_list_idx(frame);
+               fr_idx = (FRLISTEN_64_SIZE +
+                         dwc2_frame_list_idx(qh->sched_frame) - fr_idx_tmp)
+                        % dwc2_frame_incr_val(qh);
+               fr_idx = (fr_idx + fr_idx_tmp) % FRLISTEN_64_SIZE;
+       } else {
+               qh->sched_frame = dwc2_calc_starting_frame(hsotg, qh,
+                                                          &skip_frames);
+               fr_idx = dwc2_frame_list_idx(qh->sched_frame);
+       }
+
+       qh->td_first = qh->td_last = dwc2_frame_to_desc_idx(qh, fr_idx);
+
+       return skip_frames;
+}
+
+#define ISOC_URB_GIVEBACK_ASAP
+
+#define MAX_ISOC_XFER_SIZE_FS  1023
+#define MAX_ISOC_XFER_SIZE_HS  3072
+#define DESCNUM_THRESHOLD      4
+
+static void dwc2_fill_host_isoc_dma_desc(struct dwc2_hsotg *hsotg,
+                                        struct dwc2_qtd *qtd,
+                                        struct dwc2_qh *qh, u32 max_xfer_size,
+                                        u16 idx)
+{
+       struct dwc2_hcd_dma_desc *dma_desc = &qh->desc_list[idx];
+       struct dwc2_hcd_iso_packet_desc *frame_desc;
+
+       memset(dma_desc, 0, sizeof(*dma_desc));
+       frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
+
+       if (frame_desc->length > max_xfer_size)
+               qh->n_bytes[idx] = max_xfer_size;
+       else
+               qh->n_bytes[idx] = frame_desc->length;
+
+       dma_desc->buf = (u32)(qtd->urb->dma + frame_desc->offset);
+       dma_desc->status = qh->n_bytes[idx] << HOST_DMA_ISOC_NBYTES_SHIFT &
+                          HOST_DMA_ISOC_NBYTES_MASK;
+
+#ifdef ISOC_URB_GIVEBACK_ASAP
+       /* Set IOC for each descriptor corresponding to last frame of URB */
+       if (qtd->isoc_frame_index_last == qtd->urb->packet_count)
+               dma_desc->status |= HOST_DMA_IOC;
+#endif
+
+       qh->ntd++;
+       qtd->isoc_frame_index_last++;
+}
+
+static void dwc2_init_isoc_dma_desc(struct dwc2_hsotg *hsotg,
+                                   struct dwc2_qh *qh, u16 skip_frames)
+{
+       struct dwc2_qtd *qtd;
+       u32 max_xfer_size;
+       u16 idx, inc, n_desc, ntd_max = 0;
+
+       idx = qh->td_last;
+       inc = qh->interval;
+       n_desc = 0;
+
+       if (qh->interval) {
+               ntd_max = (dwc2_max_desc_num(qh) + qh->interval - 1) /
+                               qh->interval;
+               if (skip_frames && !qh->channel)
+                       ntd_max -= skip_frames / qh->interval;
+       }
+
+       max_xfer_size = qh->dev_speed == USB_SPEED_HIGH ?
+                       MAX_ISOC_XFER_SIZE_HS : MAX_ISOC_XFER_SIZE_FS;
+
+       list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) {
+               while (qh->ntd < ntd_max && qtd->isoc_frame_index_last <
+                                               qtd->urb->packet_count) {
+                       if (n_desc > 1)
+                               qh->desc_list[n_desc - 1].status |= HOST_DMA_A;
+                       dwc2_fill_host_isoc_dma_desc(hsotg, qtd, qh,
+                                                    max_xfer_size, idx);
+                       idx = dwc2_desclist_idx_inc(idx, inc, qh->dev_speed);
+                       n_desc++;
+               }
+               qtd->in_process = 1;
+       }
+
+       qh->td_last = idx;
+
+#ifdef ISOC_URB_GIVEBACK_ASAP
+       /* Set IOC for last descriptor if descriptor list is full */
+       if (qh->ntd == ntd_max) {
+               idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
+               qh->desc_list[idx].status |= HOST_DMA_IOC;
+       }
+#else
+       /*
+        * Set IOC bit only for one descriptor. Always try to be ahead of HW
+        * processing, i.e. on IOC generation driver activates next descriptor
+        * but core continues to process descriptors following the one with IOC
+        * set.
+        */
+
+       if (n_desc > DESCNUM_THRESHOLD)
+               /*
+                * Move IOC "up". Required even if there is only one QTD
+                * in the list, because QTDs might continue to be queued,
+                * but during the activation it was only one queued.
+                * Actually more than one QTD might be in the list if this
+                * function called from XferCompletion - QTDs was queued during
+                * HW processing of the previous descriptor chunk.
+                */
+               idx = dwc2_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2),
+                                           qh->dev_speed);
+       else
+               /*
+                * Set the IOC for the latest descriptor if either number of
+                * descriptors is not greater than threshold or no more new
+                * descriptors activated
+                */
+               idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
+
+       qh->desc_list[idx].status |= HOST_DMA_IOC;
+#endif
+
+       if (n_desc) {
+               qh->desc_list[n_desc - 1].status |= HOST_DMA_A;
+               if (n_desc > 1)
+                       qh->desc_list[0].status |= HOST_DMA_A;
+       }
+}
+
+static void dwc2_fill_host_dma_desc(struct dwc2_hsotg *hsotg,
+                                   struct dwc2_host_chan *chan,
+                                   struct dwc2_qtd *qtd, struct dwc2_qh *qh,
+                                   int n_desc)
+{
+       struct dwc2_hcd_dma_desc *dma_desc = &qh->desc_list[n_desc];
+       int len = chan->xfer_len;
+
+       if (len > MAX_DMA_DESC_SIZE)
+               len = MAX_DMA_DESC_SIZE - chan->max_packet + 1;
+
+       if (chan->ep_is_in) {
+               int num_packets;
+
+               if (len > 0 && chan->max_packet)
+                       num_packets = (len + chan->max_packet - 1)
+                                       / chan->max_packet;
+               else
+                       /* Need 1 packet for transfer length of 0 */
+                       num_packets = 1;
+
+               /* Always program an integral # of packets for IN transfers */
+               len = num_packets * chan->max_packet;
+       }
+
+       dma_desc->status = len << HOST_DMA_NBYTES_SHIFT & HOST_DMA_NBYTES_MASK;
+       qh->n_bytes[n_desc] = len;
+
+       if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL &&
+           qtd->control_phase == DWC2_CONTROL_SETUP)
+               dma_desc->status |= HOST_DMA_SUP;
+
+       dma_desc->buf = (u32)chan->xfer_dma;
+
+       /*
+        * Last (or only) descriptor of IN transfer with actual size less
+        * than MaxPacket
+        */
+       if (len > chan->xfer_len) {
+               chan->xfer_len = 0;
+       } else {
+               chan->xfer_dma += len;
+               chan->xfer_len -= len;
+       }
+}
+
+static void dwc2_init_non_isoc_dma_desc(struct dwc2_hsotg *hsotg,
+                                       struct dwc2_qh *qh)
+{
+       struct dwc2_qtd *qtd;
+       struct dwc2_host_chan *chan = qh->channel;
+       int n_desc = 0;
+
+       dev_vdbg(hsotg->dev, "%s(): qh=%p dma=%08lx len=%d\n", __func__, qh,
+                (unsigned long)chan->xfer_dma, chan->xfer_len);
+
+       /*
+        * Start with chan->xfer_dma initialized in assign_and_init_hc(), then
+        * if SG transfer consists of multiple URBs, this pointer is re-assigned
+        * to the buffer of the currently processed QTD. For non-SG request
+        * there is always one QTD active.
+        */
+
+       list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) {
+               dev_vdbg(hsotg->dev, "qtd=%p\n", qtd);
+
+               if (n_desc) {
+                       /* SG request - more than 1 QTD */
+                       chan->xfer_dma = qtd->urb->dma +
+                                       qtd->urb->actual_length;
+                       chan->xfer_len = qtd->urb->length -
+                                       qtd->urb->actual_length;
+                       dev_vdbg(hsotg->dev, "buf=%08lx len=%d\n",
+                                (unsigned long)chan->xfer_dma, chan->xfer_len);
+               }
+
+               qtd->n_desc = 0;
+               do {
+                       if (n_desc > 1) {
+                               qh->desc_list[n_desc - 1].status |= HOST_DMA_A;
+                               dev_vdbg(hsotg->dev,
+                                        "set A bit in desc %d (%p)\n",
+                                        n_desc - 1,
+                                        &qh->desc_list[n_desc - 1]);
+                       }
+                       dwc2_fill_host_dma_desc(hsotg, chan, qtd, qh, n_desc);
+                       dev_vdbg(hsotg->dev,
+                                "desc %d (%p) buf=%08x status=%08x\n",
+                                n_desc, &qh->desc_list[n_desc],
+                                qh->desc_list[n_desc].buf,
+                                qh->desc_list[n_desc].status);
+                       qtd->n_desc++;
+                       n_desc++;
+               } while (chan->xfer_len > 0 &&
+                        n_desc != MAX_DMA_DESC_NUM_GENERIC);
+
+               dev_vdbg(hsotg->dev, "n_desc=%d\n", n_desc);
+               qtd->in_process = 1;
+               if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL)
+                       break;
+               if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
+                       break;
+       }
+
+       if (n_desc) {
+               qh->desc_list[n_desc - 1].status |=
+                               HOST_DMA_IOC | HOST_DMA_EOL | HOST_DMA_A;
+               dev_vdbg(hsotg->dev, "set IOC/EOL/A bits in desc %d (%p)\n",
+                        n_desc - 1, &qh->desc_list[n_desc - 1]);
+               if (n_desc > 1) {
+                       qh->desc_list[0].status |= HOST_DMA_A;
+                       dev_vdbg(hsotg->dev, "set A bit in desc 0 (%p)\n",
+                                &qh->desc_list[0]);
+               }
+               chan->ntd = n_desc;
+       }
+}
+
+/**
+ * dwc2_hcd_start_xfer_ddma() - Starts a transfer in Descriptor DMA mode
+ *
+ * @hsotg: The HCD state structure for the DWC OTG controller
+ * @qh:    The QH to init
+ *
+ * Return: 0 if successful, negative error code otherwise
+ *
+ * For Control and Bulk endpoints, initializes descriptor list and starts the
+ * transfer. For Interrupt and Isochronous endpoints, initializes descriptor
+ * list then updates FrameList, marking appropriate entries as active.
+ *
+ * For Isochronous endpoints the starting descriptor index is calculated based
+ * on the scheduled frame, but only on the first transfer descriptor within a
+ * session. Then the transfer is started via enabling the channel.
+ *
+ * For Isochronous endpoints the channel is not halted on XferComplete
+ * interrupt so remains assigned to the endpoint(QH) until session is done.
+ */
+void dwc2_hcd_start_xfer_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
+{
+       /* Channel is already assigned */
+       struct dwc2_host_chan *chan = qh->channel;
+       u16 skip_frames = 0;
+
+       switch (chan->ep_type) {
+       case USB_ENDPOINT_XFER_CONTROL:
+       case USB_ENDPOINT_XFER_BULK:
+               dwc2_init_non_isoc_dma_desc(hsotg, qh);
+               dwc2_hc_start_transfer_ddma(hsotg, chan);
+               break;
+       case USB_ENDPOINT_XFER_INT:
+               dwc2_init_non_isoc_dma_desc(hsotg, qh);
+               dwc2_update_frame_list(hsotg, qh, 1);
+               dwc2_hc_start_transfer_ddma(hsotg, chan);
+               break;
+       case USB_ENDPOINT_XFER_ISOC:
+               if (!qh->ntd)
+                       skip_frames = dwc2_recalc_initial_desc_idx(hsotg, qh);
+               dwc2_init_isoc_dma_desc(hsotg, qh, skip_frames);
+
+               if (!chan->xfer_started) {
+                       dwc2_update_frame_list(hsotg, qh, 1);
+
+                       /*
+                        * Always set to max, instead of actual size. Otherwise
+                        * ntd will be changed with channel being enabled. Not
+                        * recommended.
+                        */
+                       chan->ntd = dwc2_max_desc_num(qh);
+
+                       /* Enable channel only once for ISOC */
+                       dwc2_hc_start_transfer_ddma(hsotg, chan);
+               }
+
+               break;
+       default:
+               break;
+       }
+}
+
+#define DWC2_CMPL_DONE         1
+#define DWC2_CMPL_STOP         2
+
+static int dwc2_cmpl_host_isoc_dma_desc(struct dwc2_hsotg *hsotg,
+                                       struct dwc2_host_chan *chan,
+                                       struct dwc2_qtd *qtd,
+                                       struct dwc2_qh *qh, u16 idx)
+{
+       struct dwc2_hcd_dma_desc *dma_desc = &qh->desc_list[idx];
+       struct dwc2_hcd_iso_packet_desc *frame_desc;
+       u16 remain = 0;
+       int rc = 0;
+
+       frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
+       dma_desc->buf = (u32)(qtd->urb->dma + frame_desc->offset);
+       if (chan->ep_is_in)
+               remain = dma_desc->status >> HOST_DMA_ISOC_NBYTES_SHIFT &
+                       HOST_DMA_ISOC_NBYTES_MASK >> HOST_DMA_ISOC_NBYTES_SHIFT;
+
+       if ((dma_desc->status & HOST_DMA_STS_MASK) == HOST_DMA_STS_PKTERR) {
+               /*
+                * XactError, or unable to complete all the transactions
+                * in the scheduled micro-frame/frame, both indicated by
+                * HOST_DMA_STS_PKTERR
+                */
+               qtd->urb->error_count++;
+               frame_desc->actual_length = qh->n_bytes[idx] - remain;
+               frame_desc->status = -EPROTO;
+       } else {
+               /* Success */
+               frame_desc->actual_length = qh->n_bytes[idx] - remain;
+               frame_desc->status = 0;
+       }
+
+       if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
+               /*
+                * urb->status is not used for isoc transfers here. The
+                * individual frame_desc status are used instead.
+                */
+               dwc2_host_complete(hsotg, qtd->urb->priv, qtd->urb, 0);
+               dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
+
+               /*
+                * This check is necessary because urb_dequeue can be called
+                * from urb complete callback (sound driver for example). All
+                * pending URBs are dequeued there, so no need for further
+                * processing.
+                */
+               if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE)
+                       return -1;
+               rc = DWC2_CMPL_DONE;
+       }
+
+       qh->ntd--;
+
+       /* Stop if IOC requested descriptor reached */
+       if (dma_desc->status & HOST_DMA_IOC)
+               rc = DWC2_CMPL_STOP;
+
+       return rc;
+}
+
+static void dwc2_complete_isoc_xfer_ddma(struct dwc2_hsotg *hsotg,
+                                        struct dwc2_host_chan *chan,
+                                        enum dwc2_halt_status halt_status)
+{
+       struct dwc2_hcd_iso_packet_desc *frame_desc;
+       struct dwc2_qtd *qtd, *qtd_tmp;
+       struct dwc2_qh *qh;
+       u16 idx;
+       int rc;
+
+       qh = chan->qh;
+       idx = qh->td_first;
+
+       if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) {
+               list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry)
+                       qtd->in_process = 0;
+               return;
+       }
+
+       if (halt_status == DWC2_HC_XFER_AHB_ERR ||
+           halt_status == DWC2_HC_XFER_BABBLE_ERR) {
+               /*
+                * Channel is halted in these error cases, considered as serious
+                * issues.
+                * Complete all URBs marking all frames as failed, irrespective
+                * whether some of the descriptors (frames) succeeded or not.
+                * Pass error code to completion routine as well, to update
+                * urb->status, some of class drivers might use it to stop
+                * queing transfer requests.
+                */
+               int err = halt_status == DWC2_HC_XFER_AHB_ERR ?
+                         -EIO : -EOVERFLOW;
+
+               list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list,
+                                        qtd_list_entry) {
+                       for (idx = 0; idx < qtd->urb->packet_count; idx++) {
+                               frame_desc = &qtd->urb->iso_descs[idx];
+                               frame_desc->status = err;
+                       }
+
+                       dwc2_host_complete(hsotg, qtd->urb->priv, qtd->urb,
+                                          err);
+                       dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
+               }
+
+               return;
+       }
+
+       list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
+               if (!qtd->in_process)
+                       break;
+               do {
+                       rc = dwc2_cmpl_host_isoc_dma_desc(hsotg, chan, qtd, qh,
+                                                         idx);
+                       if (rc < 0)
+                               return;
+                       idx = dwc2_desclist_idx_inc(idx, qh->interval,
+                                                   chan->speed);
+                       if (rc == DWC2_CMPL_STOP)
+                               goto stop_scan;
+                       if (rc == DWC2_CMPL_DONE)
+                               break;
+               } while (idx != qh->td_first);
+       }
+
+stop_scan:
+       qh->td_first = idx;
+}
+
+static int dwc2_update_non_isoc_urb_state_ddma(struct dwc2_hsotg *hsotg,
+                                       struct dwc2_host_chan *chan,
+                                       struct dwc2_qtd *qtd,
+                                       struct dwc2_hcd_dma_desc *dma_desc,
+                                       enum dwc2_halt_status halt_status,
+                                       u32 n_bytes, int *xfer_done)
+{
+       struct dwc2_hcd_urb *urb = qtd->urb;
+       u16 remain = 0;
+
+       if (chan->ep_is_in)
+               remain = dma_desc->status >> HOST_DMA_NBYTES_SHIFT &
+                        HOST_DMA_NBYTES_MASK >> HOST_DMA_NBYTES_SHIFT;
+
+       dev_vdbg(hsotg->dev, "remain=%d dwc2_urb=%p\n", remain, urb);
+
+       if (halt_status == DWC2_HC_XFER_AHB_ERR) {
+               dev_err(hsotg->dev, "EIO\n");
+               urb->status = -EIO;
+               return 1;
+       }
+
+       if ((dma_desc->status & HOST_DMA_STS_MASK) == HOST_DMA_STS_PKTERR) {
+               switch (halt_status) {
+               case DWC2_HC_XFER_STALL:
+                       dev_vdbg(hsotg->dev, "Stall\n");
+                       urb->status = -EPIPE;
+                       break;
+               case DWC2_HC_XFER_BABBLE_ERR:
+                       dev_err(hsotg->dev, "Babble\n");
+                       urb->status = -EOVERFLOW;
+                       break;
+               case DWC2_HC_XFER_XACT_ERR:
+                       dev_err(hsotg->dev, "XactErr\n");
+                       urb->status = -EPROTO;
+                       break;
+               default:
+                       dev_err(hsotg->dev,
+                               "%s: Unhandled descriptor error status (%d)\n",
+                               __func__, halt_status);
+                       break;
+               }
+               return 1;
+       }
+
+       if (dma_desc->status & HOST_DMA_A) {
+               dev_vdbg(hsotg->dev,
+                        "Active descriptor encountered on channel %d\n",
+                        chan->hc_num);
+               return 0;
+       }
+
+       if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL) {
+               if (qtd->control_phase == DWC2_CONTROL_DATA) {
+                       urb->actual_length += n_bytes - remain;
+                       if (remain || urb->actual_length >= urb->length) {
+                               /*
+                                * For Control Data stage do not set urb->status
+                                * to 0, to prevent URB callback. Set it when
+                                * Status phase is done. See below.
+                                */
+                               *xfer_done = 1;
+                       }
+               } else if (qtd->control_phase == DWC2_CONTROL_STATUS) {
+                       urb->status = 0;
+                       *xfer_done = 1;
+               }
+               /* No handling for SETUP stage */
+       } else {
+               /* BULK and INTR */
+               urb->actual_length += n_bytes - remain;
+               dev_vdbg(hsotg->dev, "length=%d actual=%d\n", urb->length,
+                        urb->actual_length);
+               if (remain || urb->actual_length >= urb->length) {
+                       urb->status = 0;
+                       *xfer_done = 1;
+               }
+       }
+
+       return 0;
+}
+
+static int dwc2_process_non_isoc_desc(struct dwc2_hsotg *hsotg,
+                                     struct dwc2_host_chan *chan,
+                                     int chnum, struct dwc2_qtd *qtd,
+                                     int desc_num,
+                                     enum dwc2_halt_status halt_status,
+                                     int *xfer_done)
+{
+       struct dwc2_qh *qh = chan->qh;
+       struct dwc2_hcd_urb *urb = qtd->urb;
+       struct dwc2_hcd_dma_desc *dma_desc;
+       u32 n_bytes;
+       int failed;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       dma_desc = &qh->desc_list[desc_num];
+       n_bytes = qh->n_bytes[desc_num];
+       dev_vdbg(hsotg->dev,
+                "qtd=%p dwc2_urb=%p desc_num=%d desc=%p n_bytes=%d\n",
+                qtd, urb, desc_num, dma_desc, n_bytes);
+       failed = dwc2_update_non_isoc_urb_state_ddma(hsotg, chan, qtd, dma_desc,
+                                                    halt_status, n_bytes,
+                                                    xfer_done);
+       if (failed || (*xfer_done && urb->status != -EINPROGRESS)) {
+               dwc2_host_complete(hsotg, urb->priv, urb, urb->status);
+               dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
+               dev_vdbg(hsotg->dev, "failed=%1x xfer_done=%1x status=%08x\n",
+                        failed, *xfer_done, urb->status);
+               return failed;
+       }
+
+       if (qh->ep_type == USB_ENDPOINT_XFER_CONTROL) {
+               switch (qtd->control_phase) {
+               case DWC2_CONTROL_SETUP:
+                       if (urb->length > 0)
+                               qtd->control_phase = DWC2_CONTROL_DATA;
+                       else
+                               qtd->control_phase = DWC2_CONTROL_STATUS;
+                       dev_vdbg(hsotg->dev,
+                                "  Control setup transaction done\n");
+                       break;
+               case DWC2_CONTROL_DATA:
+                       if (*xfer_done) {
+                               qtd->control_phase = DWC2_CONTROL_STATUS;
+                               dev_vdbg(hsotg->dev,
+                                        "  Control data transfer done\n");
+                       } else if (desc_num + 1 == qtd->n_desc) {
+                               /*
+                                * Last descriptor for Control data stage which
+                                * is not completed yet
+                                */
+                               dwc2_hcd_save_data_toggle(hsotg, chan, chnum,
+                                                         qtd);
+                       }
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       return 0;
+}
+
+static void dwc2_complete_non_isoc_xfer_ddma(struct dwc2_hsotg *hsotg,
+                                            struct dwc2_host_chan *chan,
+                                            int chnum,
+                                            enum dwc2_halt_status halt_status)
+{
+       struct list_head *qtd_item, *qtd_tmp;
+       struct dwc2_qh *qh = chan->qh;
+       struct dwc2_qtd *qtd = NULL;
+       int xfer_done;
+       int desc_num = 0;
+
+       if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) {
+               list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry)
+                       qtd->in_process = 0;
+               return;
+       }
+
+       list_for_each_safe(qtd_item, qtd_tmp, &qh->qtd_list) {
+               int i;
+
+               qtd = list_entry(qtd_item, struct dwc2_qtd, qtd_list_entry);
+               xfer_done = 0;
+
+               for (i = 0; i < qtd->n_desc; i++) {
+                       if (dwc2_process_non_isoc_desc(hsotg, chan, chnum, qtd,
+                                                      desc_num, halt_status,
+                                                      &xfer_done))
+                               break;
+                       desc_num++;
+               }
+       }
+
+       if (qh->ep_type != USB_ENDPOINT_XFER_CONTROL) {
+               /*
+                * Resetting the data toggle for bulk and interrupt endpoints
+                * in case of stall. See handle_hc_stall_intr().
+                */
+               if (halt_status == DWC2_HC_XFER_STALL)
+                       qh->data_toggle = DWC2_HC_PID_DATA0;
+               else if (qtd)
+                       dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
+       }
+
+       if (halt_status == DWC2_HC_XFER_COMPLETE) {
+               if (chan->hcint & HCINTMSK_NYET) {
+                       /*
+                        * Got a NYET on the last transaction of the transfer.
+                        * It means that the endpoint should be in the PING
+                        * state at the beginning of the next transfer.
+                        */
+                       qh->ping_state = 1;
+               }
+       }
+}
+
+/**
+ * dwc2_hcd_complete_xfer_ddma() - Scans the descriptor list, updates URB's
+ * status and calls completion routine for the URB if it's done. Called from
+ * interrupt handlers.
+ *
+ * @hsotg:       The HCD state structure for the DWC OTG controller
+ * @chan:        Host channel the transfer is completed on
+ * @chnum:       Index of Host channel registers
+ * @halt_status: Reason the channel is being halted or just XferComplete
+ *               for isochronous transfers
+ *
+ * Releases the channel to be used by other transfers.
+ * In case of Isochronous endpoint the channel is not halted until the end of
+ * the session, i.e. QTD list is empty.
+ * If periodic channel released the FrameList is updated accordingly.
+ * Calls transaction selection routines to activate pending transfers.
+ */
+void dwc2_hcd_complete_xfer_ddma(struct dwc2_hsotg *hsotg,
+                                struct dwc2_host_chan *chan, int chnum,
+                                enum dwc2_halt_status halt_status)
+{
+       struct dwc2_qh *qh = chan->qh;
+       int continue_isoc_xfer = 0;
+       enum dwc2_transaction_type tr_type;
+
+       if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
+               dwc2_complete_isoc_xfer_ddma(hsotg, chan, halt_status);
+
+               /* Release the channel if halted or session completed */
+               if (halt_status != DWC2_HC_XFER_COMPLETE ||
+                   list_empty(&qh->qtd_list)) {
+                       /* Halt the channel if session completed */
+                       if (halt_status == DWC2_HC_XFER_COMPLETE)
+                               dwc2_hc_halt(hsotg, chan, halt_status);
+                       dwc2_release_channel_ddma(hsotg, qh);
+                       dwc2_hcd_qh_unlink(hsotg, qh);
+               } else {
+                       /* Keep in assigned schedule to continue transfer */
+                       list_move(&qh->qh_list_entry,
+                                 &hsotg->periodic_sched_assigned);
+                       continue_isoc_xfer = 1;
+               }
+               /*
+                * Todo: Consider the case when period exceeds FrameList size.
+                * Frame Rollover interrupt should be used.
+                */
+       } else {
+               /*
+                * Scan descriptor list to complete the URB(s), then release
+                * the channel
+                */
+               dwc2_complete_non_isoc_xfer_ddma(hsotg, chan, chnum,
+                                                halt_status);
+               dwc2_release_channel_ddma(hsotg, qh);
+               dwc2_hcd_qh_unlink(hsotg, qh);
+
+               if (!list_empty(&qh->qtd_list)) {
+                       /*
+                        * Add back to inactive non-periodic schedule on normal
+                        * completion
+                        */
+                       dwc2_hcd_qh_add(hsotg, qh);
+               }
+       }
+
+       tr_type = dwc2_hcd_select_transactions(hsotg);
+       if (tr_type != DWC2_TRANSACTION_NONE || continue_isoc_xfer) {
+               if (continue_isoc_xfer) {
+                       if (tr_type == DWC2_TRANSACTION_NONE)
+                               tr_type = DWC2_TRANSACTION_PERIODIC;
+                       else if (tr_type == DWC2_TRANSACTION_NON_PERIODIC)
+                               tr_type = DWC2_TRANSACTION_ALL;
+               }
+               dwc2_hcd_queue_transactions(hsotg, tr_type);
+       }
+}
diff --git a/drivers/staging/dwc2/hcd_intr.c b/drivers/staging/dwc2/hcd_intr.c
new file mode 100644 (file)
index 0000000..8b68df8
--- /dev/null
@@ -0,0 +1,2104 @@
+/*
+ * hcd_intr.c - DesignWare HS OTG Controller host-mode interrupt handling
+ *
+ * Copyright (C) 2004-2013 Synopsys, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. 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.
+ * 3. The names of the above-listed copyright holders may not 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 the 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 OWNER 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.
+ */
+
+/*
+ * This file contains the interrupt handlers for Host mode
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+
+#include <linux/usb/hcd.h>
+#include <linux/usb/ch11.h>
+
+#include "core.h"
+#include "hcd.h"
+
+/* This function is for debug only */
+static void dwc2_track_missed_sofs(struct dwc2_hsotg *hsotg)
+{
+#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
+#warning Compiling code to track missed SOFs
+
+       u16 curr_frame_number = hsotg->frame_number;
+
+       if (hsotg->frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
+               if (((hsotg->last_frame_num + 1) & HFNUM_MAX_FRNUM) !=
+                   curr_frame_number) {
+                       hsotg->frame_num_array[hsotg->frame_num_idx] =
+                                       curr_frame_number;
+                       hsotg->last_frame_num_array[hsotg->frame_num_idx] =
+                                       hsotg->last_frame_num;
+                       hsotg->frame_num_idx++;
+               }
+       } else if (!hsotg->dumped_frame_num_array) {
+               int i;
+
+               dev_info(hsotg->dev, "Frame     Last Frame\n");
+               dev_info(hsotg->dev, "-----     ----------\n");
+               for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
+                       dev_info(hsotg->dev, "0x%04x    0x%04x\n",
+                                hsotg->frame_num_array[i],
+                                hsotg->last_frame_num_array[i]);
+               }
+               hsotg->dumped_frame_num_array = 1;
+       }
+       hsotg->last_frame_num = curr_frame_number;
+#endif
+}
+
+static void dwc2_hc_handle_tt_clear(struct dwc2_hsotg *hsotg,
+                                   struct dwc2_host_chan *chan,
+                                   struct dwc2_qtd *qtd)
+{
+       struct urb *usb_urb;
+
+       if (!chan->qh || !qtd->urb)
+               return;
+
+       usb_urb = qtd->urb->priv;
+       if (!usb_urb || !usb_urb->dev)
+               return;
+
+       if (chan->qh->dev_speed != USB_SPEED_HIGH &&
+           qtd->urb->status != -EPIPE && qtd->urb->status != -EREMOTEIO) {
+               chan->qh->tt_buffer_dirty = 1;
+               if (usb_hub_clear_tt_buffer(usb_urb))
+                       /* Clear failed; let's hope things work anyway */
+                       chan->qh->tt_buffer_dirty = 0;
+       }
+}
+
+/*
+ * Handles the start-of-frame interrupt in host mode. Non-periodic
+ * transactions may be queued to the DWC_otg controller for the current
+ * (micro)frame. Periodic transactions may be queued to the controller
+ * for the next (micro)frame.
+ */
+static void dwc2_sof_intr(struct dwc2_hsotg *hsotg)
+{
+       struct list_head *qh_entry;
+       struct dwc2_qh *qh;
+       u32 hfnum;
+       enum dwc2_transaction_type tr_type;
+
+#ifdef DEBUG_SOF
+       dev_vdbg(hsotg->dev, "--Start of Frame Interrupt--\n");
+#endif
+
+       hfnum = readl(hsotg->regs + HFNUM);
+       hsotg->frame_number = hfnum >> HFNUM_FRNUM_SHIFT &
+                           HFNUM_FRNUM_MASK >> HFNUM_FRNUM_SHIFT;
+
+       dwc2_track_missed_sofs(hsotg);
+
+       /* Determine whether any periodic QHs should be executed */
+       qh_entry = hsotg->periodic_sched_inactive.next;
+       while (qh_entry != &hsotg->periodic_sched_inactive) {
+               qh = list_entry(qh_entry, struct dwc2_qh, qh_list_entry);
+               qh_entry = qh_entry->next;
+               if (dwc2_frame_num_le(qh->sched_frame, hsotg->frame_number))
+                       /*
+                        * Move QH to the ready list to be executed next
+                        * (micro)frame
+                        */
+                       list_move(&qh->qh_list_entry,
+                                 &hsotg->periodic_sched_ready);
+       }
+       tr_type = dwc2_hcd_select_transactions(hsotg);
+       if (tr_type != DWC2_TRANSACTION_NONE)
+               dwc2_hcd_queue_transactions(hsotg, tr_type);
+
+       /* Clear interrupt */
+       writel(GINTSTS_SOF, hsotg->regs + GINTSTS);
+}
+
+/*
+ * Handles the Rx FIFO Level Interrupt, which indicates that there is
+ * at least one packet in the Rx FIFO. The packets are moved from the FIFO to
+ * memory if the DWC_otg controller is operating in Slave mode.
+ */
+static void dwc2_rx_fifo_level_intr(struct dwc2_hsotg *hsotg)
+{
+       u32 grxsts, chnum, bcnt, dpid, pktsts;
+       struct dwc2_host_chan *chan;
+
+       dev_vdbg(hsotg->dev, "--RxFIFO Level Interrupt--\n");
+
+       grxsts = readl(hsotg->regs + GRXSTSP);
+       chnum = grxsts >> GRXSTS_HCHNUM_SHIFT &
+               GRXSTS_HCHNUM_MASK >> GRXSTS_HCHNUM_SHIFT;
+       chan = hsotg->hc_ptr_array[chnum];
+       if (!chan) {
+               dev_err(hsotg->dev, "Unable to get corresponding channel\n");
+               return;
+       }
+
+       bcnt = grxsts >> GRXSTS_BYTECNT_SHIFT &
+              GRXSTS_BYTECNT_MASK >> GRXSTS_BYTECNT_SHIFT;
+       dpid = grxsts >> GRXSTS_DPID_SHIFT &
+              GRXSTS_DPID_MASK >> GRXSTS_DPID_SHIFT;
+       pktsts = grxsts & GRXSTS_PKTSTS_MASK;
+
+       /* Packet Status */
+       dev_vdbg(hsotg->dev, "    Ch num = %d\n", chnum);
+       dev_vdbg(hsotg->dev, "    Count = %d\n", bcnt);
+       dev_vdbg(hsotg->dev, "    DPID = %d, chan.dpid = %d\n", dpid,
+                chan->data_pid_start);
+       dev_vdbg(hsotg->dev, "    PStatus = %d\n",
+                pktsts >> GRXSTS_PKTSTS_SHIFT &
+                GRXSTS_PKTSTS_MASK >> GRXSTS_PKTSTS_SHIFT);
+
+       switch (pktsts) {
+       case GRXSTS_PKTSTS_HCHIN:
+               /* Read the data into the host buffer */
+               if (bcnt > 0) {
+                       dwc2_read_packet(hsotg, chan->xfer_buf, bcnt);
+
+                       /* Update the HC fields for the next packet received */
+                       chan->xfer_count += bcnt;
+                       chan->xfer_buf += bcnt;
+               }
+               break;
+       case GRXSTS_PKTSTS_HCHIN_XFER_COMP:
+       case GRXSTS_PKTSTS_DATATOGGLEERR:
+       case GRXSTS_PKTSTS_HCHHALTED:
+               /* Handled in interrupt, just ignore data */
+               break;
+       default:
+               dev_err(hsotg->dev,
+                       "RxFIFO Level Interrupt: Unknown status %d\n", pktsts);
+               break;
+       }
+}
+
+/*
+ * This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
+ * data packets may be written to the FIFO for OUT transfers. More requests
+ * may be written to the non-periodic request queue for IN transfers. This
+ * interrupt is enabled only in Slave mode.
+ */
+static void dwc2_np_tx_fifo_empty_intr(struct dwc2_hsotg *hsotg)
+{
+       dev_vdbg(hsotg->dev, "--Non-Periodic TxFIFO Empty Interrupt--\n");
+       dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_NON_PERIODIC);
+}
+
+/*
+ * This interrupt occurs when the periodic Tx FIFO is half-empty. More data
+ * packets may be written to the FIFO for OUT transfers. More requests may be
+ * written to the periodic request queue for IN transfers. This interrupt is
+ * enabled only in Slave mode.
+ */
+static void dwc2_perio_tx_fifo_empty_intr(struct dwc2_hsotg *hsotg)
+{
+       dev_vdbg(hsotg->dev, "--Periodic TxFIFO Empty Interrupt--\n");
+       dwc2_hcd_queue_transactions(hsotg, DWC2_TRANSACTION_PERIODIC);
+}
+
+static void dwc2_hprt0_enable(struct dwc2_hsotg *hsotg, u32 hprt0,
+                             u32 *hprt0_modify)
+{
+       struct dwc2_core_params *params = hsotg->core_params;
+       int do_reset = 0;
+       u32 usbcfg;
+       u32 prtspd;
+       u32 hcfg;
+       u32 hfir;
+
+       dev_vdbg(hsotg->dev, "%s(%p)\n", __func__, hsotg);
+
+       /* Every time when port enables calculate HFIR.FrInterval */
+       hfir = readl(hsotg->regs + HFIR);
+       hfir &= ~HFIR_FRINT_MASK;
+       hfir |= dwc2_calc_frame_interval(hsotg) << HFIR_FRINT_SHIFT &
+               HFIR_FRINT_MASK;
+       writel(hfir, hsotg->regs + HFIR);
+
+       /* Check if we need to adjust the PHY clock speed for low power */
+       if (!params->host_support_fs_ls_low_power) {
+               /* Port has been enabled, set the reset change flag */
+               hsotg->flags.b.port_reset_change = 1;
+               return;
+       }
+
+       usbcfg = readl(hsotg->regs + GUSBCFG);
+       prtspd = hprt0 & HPRT0_SPD_MASK;
+
+       if (prtspd == HPRT0_SPD_LOW_SPEED || prtspd == HPRT0_SPD_FULL_SPEED) {
+               /* Low power */
+               if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL)) {
+                       /* Set PHY low power clock select for FS/LS devices */
+                       usbcfg |= GUSBCFG_PHY_LP_CLK_SEL;
+                       writel(usbcfg, hsotg->regs + GUSBCFG);
+                       do_reset = 1;
+               }
+
+               hcfg = readl(hsotg->regs + HCFG);
+
+               if (prtspd == HPRT0_SPD_LOW_SPEED &&
+                   params->host_ls_low_power_phy_clk ==
+                   DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ) {
+                       /* 6 MHZ */
+                       dev_vdbg(hsotg->dev,
+                                "FS_PHY programming HCFG to 6 MHz\n");
+                       if ((hcfg & HCFG_FSLSPCLKSEL_MASK) !=
+                           HCFG_FSLSPCLKSEL_6_MHZ) {
+                               hcfg &= ~HCFG_FSLSPCLKSEL_MASK;
+                               hcfg |= HCFG_FSLSPCLKSEL_6_MHZ;
+                               writel(hcfg, hsotg->regs + HCFG);
+                               do_reset = 1;
+                       }
+               } else {
+                       /* 48 MHZ */
+                       dev_vdbg(hsotg->dev,
+                                "FS_PHY programming HCFG to 48 MHz\n");
+                       if ((hcfg & HCFG_FSLSPCLKSEL_MASK) !=
+                           HCFG_FSLSPCLKSEL_48_MHZ) {
+                               hcfg &= ~HCFG_FSLSPCLKSEL_MASK;
+                               hcfg |= HCFG_FSLSPCLKSEL_48_MHZ;
+                               writel(hcfg, hsotg->regs + HCFG);
+                               do_reset = 1;
+                       }
+               }
+       } else {
+               /* Not low power */
+               if (usbcfg & GUSBCFG_PHY_LP_CLK_SEL) {
+                       usbcfg &= ~GUSBCFG_PHY_LP_CLK_SEL;
+                       writel(usbcfg, hsotg->regs + GUSBCFG);
+                       do_reset = 1;
+               }
+       }
+
+       if (do_reset) {
+               *hprt0_modify |= HPRT0_RST;
+               queue_delayed_work(hsotg->wq_otg, &hsotg->reset_work,
+                                  msecs_to_jiffies(60));
+       } else {
+               /* Port has been enabled, set the reset change flag */
+               hsotg->flags.b.port_reset_change = 1;
+       }
+}
+
+/*
+ * There are multiple conditions that can cause a port interrupt. This function
+ * determines which interrupt conditions have occurred and handles them
+ * appropriately.
+ */
+static void dwc2_port_intr(struct dwc2_hsotg *hsotg)
+{
+       u32 hprt0;
+       u32 hprt0_modify;
+
+       dev_vdbg(hsotg->dev, "--Port Interrupt--\n");
+
+       hprt0 = readl(hsotg->regs + HPRT0);
+       hprt0_modify = hprt0;
+
+       /*
+        * Clear appropriate bits in HPRT0 to clear the interrupt bit in
+        * GINTSTS
+        */
+       hprt0_modify &= ~(HPRT0_ENA | HPRT0_CONNDET | HPRT0_ENACHG |
+                         HPRT0_OVRCURRCHG);
+
+       /*
+        * Port Connect Detected
+        * Set flag and clear if detected
+        */
+       if (hprt0 & HPRT0_CONNDET) {
+               dev_vdbg(hsotg->dev,
+                        "--Port Interrupt HPRT0=0x%08x Port Connect Detected--\n",
+                        hprt0);
+               hsotg->flags.b.port_connect_status_change = 1;
+               hsotg->flags.b.port_connect_status = 1;
+               hprt0_modify |= HPRT0_CONNDET;
+
+               /*
+                * The Hub driver asserts a reset when it sees port connect
+                * status change flag
+                */
+       }
+
+       /*
+        * Port Enable Changed
+        * Clear if detected - Set internal flag if disabled
+        */
+       if (hprt0 & HPRT0_ENACHG) {
+               dev_vdbg(hsotg->dev,
+                        "  --Port Interrupt HPRT0=0x%08x Port Enable Changed (now %d)--\n",
+                        hprt0, !!(hprt0 & HPRT0_ENA));
+               hprt0_modify |= HPRT0_ENACHG;
+               if (hprt0 & HPRT0_ENA)
+                       dwc2_hprt0_enable(hsotg, hprt0, &hprt0_modify);
+               else
+                       hsotg->flags.b.port_enable_change = 1;
+       }
+
+       /* Overcurrent Change Interrupt */
+       if (hprt0 & HPRT0_OVRCURRCHG) {
+               dev_vdbg(hsotg->dev,
+                        "  --Port Interrupt HPRT0=0x%08x Port Overcurrent Changed--\n",
+                        hprt0);
+               hsotg->flags.b.port_over_current_change = 1;
+               hprt0_modify |= HPRT0_OVRCURRCHG;
+       }
+
+       /* Clear Port Interrupts */
+       writel(hprt0_modify, hsotg->regs + HPRT0);
+}
+
+/*
+ * Gets the actual length of a transfer after the transfer halts. halt_status
+ * holds the reason for the halt.
+ *
+ * For IN transfers where halt_status is DWC2_HC_XFER_COMPLETE, *short_read
+ * is set to 1 upon return if less than the requested number of bytes were
+ * transferred. short_read may also be NULL on entry, in which case it remains
+ * unchanged.
+ */
+static u32 dwc2_get_actual_xfer_length(struct dwc2_hsotg *hsotg,
+                                      struct dwc2_host_chan *chan, int chnum,
+                                      struct dwc2_qtd *qtd,
+                                      enum dwc2_halt_status halt_status,
+                                      int *short_read)
+{
+       u32 hctsiz, count, length;
+
+       hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
+
+       if (halt_status == DWC2_HC_XFER_COMPLETE) {
+               if (chan->ep_is_in) {
+                       count = hctsiz >> TSIZ_XFERSIZE_SHIFT &
+                               TSIZ_XFERSIZE_MASK >> TSIZ_XFERSIZE_SHIFT;
+                       length = chan->xfer_len - count;
+                       if (short_read != NULL)
+                               *short_read = (count != 0);
+               } else if (chan->qh->do_split) {
+                       length = qtd->ssplit_out_xfer_count;
+               } else {
+                       length = chan->xfer_len;
+               }
+       } else {
+               /*
+                * Must use the hctsiz.pktcnt field to determine how much data
+                * has been transferred. This field reflects the number of
+                * packets that have been transferred via the USB. This is
+                * always an integral number of packets if the transfer was
+                * halted before its normal completion. (Can't use the
+                * hctsiz.xfersize field because that reflects the number of
+                * bytes transferred via the AHB, not the USB).
+                */
+               count = hctsiz >> TSIZ_PKTCNT_SHIFT &
+                       TSIZ_PKTCNT_MASK >> TSIZ_PKTCNT_SHIFT;
+               length = (chan->start_pkt_count - count) * chan->max_packet;
+       }
+
+       return length;
+}
+
+/**
+ * dwc2_update_urb_state() - Updates the state of the URB after a Transfer
+ * Complete interrupt on the host channel. Updates the actual_length field
+ * of the URB based on the number of bytes transferred via the host channel.
+ * Sets the URB status if the data transfer is finished.
+ *
+ * Return: 1 if the data transfer specified by the URB is completely finished,
+ * 0 otherwise
+ */
+static int dwc2_update_urb_state(struct dwc2_hsotg *hsotg,
+                                struct dwc2_host_chan *chan, int chnum,
+                                struct dwc2_hcd_urb *urb,
+                                struct dwc2_qtd *qtd)
+{
+       u32 hctsiz;
+       int xfer_done = 0;
+       int short_read = 0;
+       int xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
+                                                     DWC2_HC_XFER_COMPLETE,
+                                                     &short_read);
+
+       if (urb->actual_length + xfer_length > urb->length) {
+               dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__);
+               xfer_length = urb->length - urb->actual_length;
+       }
+
+       /* Non DWORD-aligned buffer case handling */
+       if (chan->align_buf && xfer_length && chan->ep_is_in) {
+               dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
+               dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length,
+                                       DMA_FROM_DEVICE);
+               memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
+                      xfer_length);
+               dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length,
+                                          DMA_FROM_DEVICE);
+       }
+
+       dev_vdbg(hsotg->dev, "urb->actual_length=%d xfer_length=%d\n",
+                urb->actual_length, xfer_length);
+       urb->actual_length += xfer_length;
+
+       if (xfer_length && chan->ep_type == USB_ENDPOINT_XFER_BULK &&
+           (urb->flags & URB_SEND_ZERO_PACKET) &&
+           urb->actual_length >= urb->length &&
+           !(urb->length % chan->max_packet)) {
+               xfer_done = 0;
+       } else if (short_read || urb->actual_length >= urb->length) {
+               xfer_done = 1;
+               urb->status = 0;
+       }
+
+       hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
+       dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
+                __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
+       dev_vdbg(hsotg->dev, "  chan->xfer_len %d\n", chan->xfer_len);
+       dev_vdbg(hsotg->dev, "  hctsiz.xfersize %d\n",
+                hctsiz >> TSIZ_XFERSIZE_SHIFT &
+                TSIZ_XFERSIZE_MASK >> TSIZ_XFERSIZE_SHIFT);
+       dev_vdbg(hsotg->dev, "  urb->transfer_buffer_length %d\n", urb->length);
+       dev_vdbg(hsotg->dev, "  urb->actual_length %d\n", urb->actual_length);
+       dev_vdbg(hsotg->dev, "  short_read %d, xfer_done %d\n", short_read,
+                xfer_done);
+
+       return xfer_done;
+}
+
+/*
+ * Save the starting data toggle for the next transfer. The data toggle is
+ * saved in the QH for non-control transfers and it's saved in the QTD for
+ * control transfers.
+ */
+void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,
+                              struct dwc2_host_chan *chan, int chnum,
+                              struct dwc2_qtd *qtd)
+{
+       u32 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
+       u32 pid = hctsiz & TSIZ_SC_MC_PID_MASK;
+
+       if (chan->ep_type != USB_ENDPOINT_XFER_CONTROL) {
+               if (pid == TSIZ_SC_MC_PID_DATA0)
+                       chan->qh->data_toggle = DWC2_HC_PID_DATA0;
+               else
+                       chan->qh->data_toggle = DWC2_HC_PID_DATA1;
+       } else {
+               if (pid == TSIZ_SC_MC_PID_DATA0)
+                       qtd->data_toggle = DWC2_HC_PID_DATA0;
+               else
+                       qtd->data_toggle = DWC2_HC_PID_DATA1;
+       }
+}
+
+/**
+ * dwc2_update_isoc_urb_state() - Updates the state of an Isochronous URB when
+ * the transfer is stopped for any reason. The fields of the current entry in
+ * the frame descriptor array are set based on the transfer state and the input
+ * halt_status. Completes the Isochronous URB if all the URB frames have been
+ * completed.
+ *
+ * Return: DWC2_HC_XFER_COMPLETE if there are more frames remaining to be
+ * transferred in the URB. Otherwise return DWC2_HC_XFER_URB_COMPLETE.
+ */
+static enum dwc2_halt_status dwc2_update_isoc_urb_state(
+               struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
+               int chnum, struct dwc2_qtd *qtd,
+               enum dwc2_halt_status halt_status)
+{
+       struct dwc2_hcd_iso_packet_desc *frame_desc;
+       struct dwc2_hcd_urb *urb = qtd->urb;
+
+       if (!urb)
+               return DWC2_HC_XFER_NO_HALT_STATUS;
+
+       frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
+
+       switch (halt_status) {
+       case DWC2_HC_XFER_COMPLETE:
+               frame_desc->status = 0;
+               frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
+                                       chan, chnum, qtd, halt_status, NULL);
+
+               /* Non DWORD-aligned buffer case handling */
+               if (chan->align_buf && frame_desc->actual_length &&
+                   chan->ep_is_in) {
+                       dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n",
+                               __func__);
+                       dma_sync_single_for_cpu(hsotg->dev, urb->dma,
+                                               urb->length, DMA_FROM_DEVICE);
+                       memcpy(urb->buf + frame_desc->offset +
+                              qtd->isoc_split_offset, chan->qh->dw_align_buf,
+                              frame_desc->actual_length);
+                       dma_sync_single_for_device(hsotg->dev, urb->dma,
+                                                  urb->length,
+                                                  DMA_FROM_DEVICE);
+               }
+               break;
+       case DWC2_HC_XFER_FRAME_OVERRUN:
+               urb->error_count++;
+               if (chan->ep_is_in)
+                       frame_desc->status = -ENOSR;
+               else
+                       frame_desc->status = -ECOMM;
+               frame_desc->actual_length = 0;
+               break;
+       case DWC2_HC_XFER_BABBLE_ERR:
+               urb->error_count++;
+               frame_desc->status = -EOVERFLOW;
+               /* Don't need to update actual_length in this case */
+               break;
+       case DWC2_HC_XFER_XACT_ERR:
+               urb->error_count++;
+               frame_desc->status = -EPROTO;
+               frame_desc->actual_length = dwc2_get_actual_xfer_length(hsotg,
+                                       chan, chnum, qtd, halt_status, NULL);
+
+               /* Non DWORD-aligned buffer case handling */
+               if (chan->align_buf && frame_desc->actual_length &&
+                   chan->ep_is_in) {
+                       dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n",
+                               __func__);
+                       dma_sync_single_for_cpu(hsotg->dev, urb->dma,
+                                               urb->length, DMA_FROM_DEVICE);
+                       memcpy(urb->buf + frame_desc->offset +
+                              qtd->isoc_split_offset, chan->qh->dw_align_buf,
+                              frame_desc->actual_length);
+                       dma_sync_single_for_device(hsotg->dev, urb->dma,
+                                                  urb->length,
+                                                  DMA_FROM_DEVICE);
+               }
+
+               /* Skip whole frame */
+               if (chan->qh->do_split &&
+                   chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in &&
+                   hsotg->core_params->dma_enable > 0) {
+                       qtd->complete_split = 0;
+                       qtd->isoc_split_offset = 0;
+               }
+
+               break;
+       default:
+               dev_err(hsotg->dev, "Unhandled halt_status (%d)\n",
+                       halt_status);
+               break;
+       }
+
+       if (++qtd->isoc_frame_index == urb->packet_count) {
+               /*
+                * urb->status is not used for isoc transfers. The individual
+                * frame_desc statuses are used instead.
+                */
+               dwc2_host_complete(hsotg, urb->priv, urb, 0);
+               halt_status = DWC2_HC_XFER_URB_COMPLETE;
+       } else {
+               halt_status = DWC2_HC_XFER_COMPLETE;
+       }
+
+       return halt_status;
+}
+
+/*
+ * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
+ * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
+ * still linked to the QH, the QH is added to the end of the inactive
+ * non-periodic schedule. For periodic QHs, removes the QH from the periodic
+ * schedule if no more QTDs are linked to the QH.
+ */
+static void dwc2_deactivate_qh(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
+                              int free_qtd)
+{
+       int continue_split = 0;
+       struct dwc2_qtd *qtd;
+
+       dev_vdbg(hsotg->dev, "  %s(%p,%p,%d)\n", __func__, hsotg, qh, free_qtd);
+
+       if (list_empty(&qh->qtd_list)) {
+               dev_dbg(hsotg->dev, "## QTD list empty ##\n");
+               goto no_qtd;
+       }
+
+       qtd = list_first_entry(&qh->qtd_list, struct dwc2_qtd, qtd_list_entry);
+
+       if (qtd->complete_split)
+               continue_split = 1;
+       else if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_MID ||
+                qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_END)
+               continue_split = 1;
+
+       if (free_qtd) {
+               dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh);
+               continue_split = 0;
+       }
+
+no_qtd:
+       if (qh->channel)
+               qh->channel->align_buf = 0;
+       qh->channel = NULL;
+       dwc2_hcd_qh_deactivate(hsotg, qh, continue_split);
+}
+
+/**
+ * dwc2_release_channel() - Releases a host channel for use by other transfers
+ *
+ * @hsotg:       The HCD state structure
+ * @chan:        The host channel to release
+ * @qtd:         The QTD associated with the host channel. This QTD may be
+ *               freed if the transfer is complete or an error has occurred.
+ * @halt_status: Reason the channel is being released. This status
+ *               determines the actions taken by this function.
+ *
+ * Also attempts to select and queue more transactions since at least one host
+ * channel is available.
+ */
+static void dwc2_release_channel(struct dwc2_hsotg *hsotg,
+                                struct dwc2_host_chan *chan,
+                                struct dwc2_qtd *qtd,
+                                enum dwc2_halt_status halt_status)
+{
+       enum dwc2_transaction_type tr_type;
+       u32 haintmsk;
+       int free_qtd = 0;
+
+       dev_vdbg(hsotg->dev, "  %s: channel %d, halt_status %d\n",
+                __func__, chan->hc_num, halt_status);
+
+       switch (halt_status) {
+       case DWC2_HC_XFER_URB_COMPLETE:
+               free_qtd = 1;
+               break;
+       case DWC2_HC_XFER_AHB_ERR:
+       case DWC2_HC_XFER_STALL:
+       case DWC2_HC_XFER_BABBLE_ERR:
+               free_qtd = 1;
+               break;
+       case DWC2_HC_XFER_XACT_ERR:
+               if (qtd && qtd->error_count >= 3) {
+                       dev_vdbg(hsotg->dev,
+                                "  Complete URB with transaction error\n");
+                       free_qtd = 1;
+                       if (qtd->urb) {
+                               qtd->urb->status = -EPROTO;
+                               dwc2_host_complete(hsotg, qtd->urb->priv,
+                                                  qtd->urb, -EPROTO);
+                       }
+               }
+               break;
+       case DWC2_HC_XFER_URB_DEQUEUE:
+               /*
+                * The QTD has already been removed and the QH has been
+                * deactivated. Don't want to do anything except release the
+                * host channel and try to queue more transfers.
+                */
+               goto cleanup;
+       case DWC2_HC_XFER_PERIODIC_INCOMPLETE:
+               dev_vdbg(hsotg->dev, "  Complete URB with I/O error\n");
+               free_qtd = 1;
+               if (qtd && qtd->urb) {
+                       qtd->urb->status = -EIO;
+                       dwc2_host_complete(hsotg, qtd->urb->priv, qtd->urb,
+                                          -EIO);
+               }
+               break;
+       case DWC2_HC_XFER_NO_HALT_STATUS:
+       default:
+               break;
+       }
+
+       dwc2_deactivate_qh(hsotg, chan->qh, free_qtd);
+
+cleanup:
+       /*
+        * Release the host channel for use by other transfers. The cleanup
+        * function clears the channel interrupt enables and conditions, so
+        * there's no need to clear the Channel Halted interrupt separately.
+        */
+       if (!list_empty(&chan->hc_list_entry))
+               list_del(&chan->hc_list_entry);
+       dwc2_hc_cleanup(hsotg, chan);
+       list_add_tail(&chan->hc_list_entry, &hsotg->free_hc_list);
+
+       switch (chan->ep_type) {
+       case USB_ENDPOINT_XFER_CONTROL:
+       case USB_ENDPOINT_XFER_BULK:
+               hsotg->non_periodic_channels--;
+               break;
+       default:
+               /*
+                * Don't release reservations for periodic channels here.
+                * That's done when a periodic transfer is descheduled (i.e.
+                * when the QH is removed from the periodic schedule).
+                */
+               break;
+       }
+
+       haintmsk = readl(hsotg->regs + HAINTMSK);
+       haintmsk &= ~(1 << chan->hc_num);
+       writel(haintmsk, hsotg->regs + HAINTMSK);
+
+       /* Try to queue more transfers now that there's a free channel */
+       tr_type = dwc2_hcd_select_transactions(hsotg);
+       if (tr_type != DWC2_TRANSACTION_NONE)
+               dwc2_hcd_queue_transactions(hsotg, tr_type);
+}
+
+/*
+ * Halts a host channel. If the channel cannot be halted immediately because
+ * the request queue is full, this function ensures that the FIFO empty
+ * interrupt for the appropriate queue is enabled so that the halt request can
+ * be queued when there is space in the request queue.
+ *
+ * This function may also be called in DMA mode. In that case, the channel is
+ * simply released since the core always halts the channel automatically in
+ * DMA mode.
+ */
+static void dwc2_halt_channel(struct dwc2_hsotg *hsotg,
+                             struct dwc2_host_chan *chan, struct dwc2_qtd *qtd,
+                             enum dwc2_halt_status halt_status)
+{
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       if (hsotg->core_params->dma_enable > 0) {
+               dev_vdbg(hsotg->dev, "DMA enabled\n");
+               dwc2_release_channel(hsotg, chan, qtd, halt_status);
+               return;
+       }
+
+       /* Slave mode processing */
+       dwc2_hc_halt(hsotg, chan, halt_status);
+
+       if (chan->halt_on_queue) {
+               u32 gintmsk;
+
+               dev_vdbg(hsotg->dev, "Halt on queue\n");
+               if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
+                   chan->ep_type == USB_ENDPOINT_XFER_BULK) {
+                       dev_vdbg(hsotg->dev, "control/bulk\n");
+                       /*
+                        * Make sure the Non-periodic Tx FIFO empty interrupt
+                        * is enabled so that the non-periodic schedule will
+                        * be processed
+                        */
+                       gintmsk = readl(hsotg->regs + GINTMSK);
+                       gintmsk |= GINTSTS_NPTXFEMP;
+                       writel(gintmsk, hsotg->regs + GINTMSK);
+               } else {
+                       dev_vdbg(hsotg->dev, "isoc/intr\n");
+                       /*
+                        * Move the QH from the periodic queued schedule to
+                        * the periodic assigned schedule. This allows the
+                        * halt to be queued when the periodic schedule is
+                        * processed.
+                        */
+                       list_move(&chan->qh->qh_list_entry,
+                                 &hsotg->periodic_sched_assigned);
+
+                       /*
+                        * Make sure the Periodic Tx FIFO Empty interrupt is
+                        * enabled so that the periodic schedule will be
+                        * processed
+                        */
+                       gintmsk = readl(hsotg->regs + GINTMSK);
+                       gintmsk |= GINTSTS_PTXFEMP;
+                       writel(gintmsk, hsotg->regs + GINTMSK);
+               }
+       }
+}
+
+/*
+ * Performs common cleanup for non-periodic transfers after a Transfer
+ * Complete interrupt. This function should be called after any endpoint type
+ * specific handling is finished to release the host channel.
+ */
+static void dwc2_complete_non_periodic_xfer(struct dwc2_hsotg *hsotg,
+                                           struct dwc2_host_chan *chan,
+                                           int chnum, struct dwc2_qtd *qtd,
+                                           enum dwc2_halt_status halt_status)
+{
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       qtd->error_count = 0;
+
+       if (chan->hcint & HCINTMSK_NYET) {
+               /*
+                * Got a NYET on the last transaction of the transfer. This
+                * means that the endpoint should be in the PING state at the
+                * beginning of the next transfer.
+                */
+               dev_vdbg(hsotg->dev, "got NYET\n");
+               chan->qh->ping_state = 1;
+       }
+
+       /*
+        * Always halt and release the host channel to make it available for
+        * more transfers. There may still be more phases for a control
+        * transfer or more data packets for a bulk transfer at this point,
+        * but the host channel is still halted. A channel will be reassigned
+        * to the transfer when the non-periodic schedule is processed after
+        * the channel is released. This allows transactions to be queued
+        * properly via dwc2_hcd_queue_transactions, which also enables the
+        * Tx FIFO Empty interrupt if necessary.
+        */
+       if (chan->ep_is_in) {
+               /*
+                * IN transfers in Slave mode require an explicit disable to
+                * halt the channel. (In DMA mode, this call simply releases
+                * the channel.)
+                */
+               dwc2_halt_channel(hsotg, chan, qtd, halt_status);
+       } else {
+               /*
+                * The channel is automatically disabled by the core for OUT
+                * transfers in Slave mode
+                */
+               dwc2_release_channel(hsotg, chan, qtd, halt_status);
+       }
+}
+
+/*
+ * Performs common cleanup for periodic transfers after a Transfer Complete
+ * interrupt. This function should be called after any endpoint type specific
+ * handling is finished to release the host channel.
+ */
+static void dwc2_complete_periodic_xfer(struct dwc2_hsotg *hsotg,
+                                       struct dwc2_host_chan *chan, int chnum,
+                                       struct dwc2_qtd *qtd,
+                                       enum dwc2_halt_status halt_status)
+{
+       u32 hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
+
+       qtd->error_count = 0;
+
+       if (!chan->ep_is_in || (hctsiz & TSIZ_PKTCNT_MASK) == 0)
+               /* Core halts channel in these cases */
+               dwc2_release_channel(hsotg, chan, qtd, halt_status);
+       else
+               /* Flush any outstanding requests from the Tx queue */
+               dwc2_halt_channel(hsotg, chan, qtd, halt_status);
+}
+
+static int dwc2_xfercomp_isoc_split_in(struct dwc2_hsotg *hsotg,
+                                      struct dwc2_host_chan *chan, int chnum,
+                                      struct dwc2_qtd *qtd)
+{
+       struct dwc2_hcd_iso_packet_desc *frame_desc;
+       u32 len;
+
+       if (!qtd->urb)
+               return 0;
+
+       frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
+       len = dwc2_get_actual_xfer_length(hsotg, chan, chnum, qtd,
+                                         DWC2_HC_XFER_COMPLETE, NULL);
+       if (!len) {
+               qtd->complete_split = 0;
+               qtd->isoc_split_offset = 0;
+               return 0;
+       }
+
+       frame_desc->actual_length += len;
+
+       if (chan->align_buf && len) {
+               dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
+               dma_sync_single_for_cpu(hsotg->dev, qtd->urb->dma,
+                                       qtd->urb->length, DMA_FROM_DEVICE);
+               memcpy(qtd->urb->buf + frame_desc->offset +
+                      qtd->isoc_split_offset, chan->qh->dw_align_buf, len);
+               dma_sync_single_for_device(hsotg->dev, qtd->urb->dma,
+                                          qtd->urb->length, DMA_FROM_DEVICE);
+       }
+
+       qtd->isoc_split_offset += len;
+
+       if (frame_desc->actual_length >= frame_desc->length) {
+               frame_desc->status = 0;
+               qtd->isoc_frame_index++;
+               qtd->complete_split = 0;
+               qtd->isoc_split_offset = 0;
+       }
+
+       if (qtd->isoc_frame_index == qtd->urb->packet_count) {
+               dwc2_host_complete(hsotg, qtd->urb->priv, qtd->urb, 0);
+               dwc2_release_channel(hsotg, chan, qtd,
+                                    DWC2_HC_XFER_URB_COMPLETE);
+       } else {
+               dwc2_release_channel(hsotg, chan, qtd,
+                                    DWC2_HC_XFER_NO_HALT_STATUS);
+       }
+
+       return 1;       /* Indicates that channel released */
+}
+
+/*
+ * Handles a host channel Transfer Complete interrupt. This handler may be
+ * called in either DMA mode or Slave mode.
+ */
+static void dwc2_hc_xfercomp_intr(struct dwc2_hsotg *hsotg,
+                                 struct dwc2_host_chan *chan, int chnum,
+                                 struct dwc2_qtd *qtd)
+{
+       struct dwc2_hcd_urb *urb = qtd->urb;
+       int pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
+       enum dwc2_halt_status halt_status = DWC2_HC_XFER_COMPLETE;
+       int urb_xfer_done;
+
+       dev_vdbg(hsotg->dev,
+                "--Host Channel %d Interrupt: Transfer Complete--\n", chnum);
+
+       if (hsotg->core_params->dma_desc_enable > 0) {
+               dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum, halt_status);
+               if (pipe_type == USB_ENDPOINT_XFER_ISOC)
+                       /* Do not disable the interrupt, just clear it */
+                       return;
+               goto handle_xfercomp_done;
+       }
+
+       /* Handle xfer complete on CSPLIT */
+       if (chan->qh->do_split) {
+               if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && chan->ep_is_in &&
+                   hsotg->core_params->dma_enable > 0) {
+                       if (qtd->complete_split &&
+                           dwc2_xfercomp_isoc_split_in(hsotg, chan, chnum,
+                                                       qtd))
+                               goto handle_xfercomp_done;
+               } else {
+                       qtd->complete_split = 0;
+               }
+       }
+
+       if (!urb)
+               goto handle_xfercomp_done;
+
+       /* Update the QTD and URB states */
+       switch (pipe_type) {
+       case USB_ENDPOINT_XFER_CONTROL:
+               switch (qtd->control_phase) {
+               case DWC2_CONTROL_SETUP:
+                       if (urb->length > 0)
+                               qtd->control_phase = DWC2_CONTROL_DATA;
+                       else
+                               qtd->control_phase = DWC2_CONTROL_STATUS;
+                       dev_vdbg(hsotg->dev,
+                                "  Control setup transaction done\n");
+                       halt_status = DWC2_HC_XFER_COMPLETE;
+                       break;
+               case DWC2_CONTROL_DATA:
+                       urb_xfer_done = dwc2_update_urb_state(hsotg, chan,
+                                                             chnum, urb, qtd);
+                       if (urb_xfer_done) {
+                               qtd->control_phase = DWC2_CONTROL_STATUS;
+                               dev_vdbg(hsotg->dev,
+                                        "  Control data transfer done\n");
+                       } else {
+                               dwc2_hcd_save_data_toggle(hsotg, chan, chnum,
+                                                         qtd);
+                       }
+                       halt_status = DWC2_HC_XFER_COMPLETE;
+                       break;
+               case DWC2_CONTROL_STATUS:
+                       dev_vdbg(hsotg->dev, "  Control transfer complete\n");
+                       if (urb->status == -EINPROGRESS)
+                               urb->status = 0;
+                       dwc2_host_complete(hsotg, urb->priv, urb, urb->status);
+                       halt_status = DWC2_HC_XFER_URB_COMPLETE;
+                       break;
+               }
+
+               dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd,
+                                               halt_status);
+               break;
+       case USB_ENDPOINT_XFER_BULK:
+               dev_vdbg(hsotg->dev, "  Bulk transfer complete\n");
+               urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb,
+                                                     qtd);
+               if (urb_xfer_done) {
+                       dwc2_host_complete(hsotg, urb->priv, urb, urb->status);
+                       halt_status = DWC2_HC_XFER_URB_COMPLETE;
+               } else {
+                       halt_status = DWC2_HC_XFER_COMPLETE;
+               }
+
+               dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
+               dwc2_complete_non_periodic_xfer(hsotg, chan, chnum, qtd,
+                                               halt_status);
+               break;
+       case USB_ENDPOINT_XFER_INT:
+               dev_vdbg(hsotg->dev, "  Interrupt transfer complete\n");
+               urb_xfer_done = dwc2_update_urb_state(hsotg, chan, chnum, urb,
+                                                     qtd);
+
+               /*
+                * Interrupt URB is done on the first transfer complete
+                * interrupt
+                */
+               if (urb_xfer_done) {
+                               dwc2_host_complete(hsotg, urb->priv, urb,
+                                                  urb->status);
+                               halt_status = DWC2_HC_XFER_URB_COMPLETE;
+               } else {
+                               halt_status = DWC2_HC_XFER_COMPLETE;
+               }
+
+               dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
+               dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd,
+                                           halt_status);
+               break;
+       case USB_ENDPOINT_XFER_ISOC:
+               dev_vdbg(hsotg->dev, "  Isochronous transfer complete\n");
+               if (qtd->isoc_split_pos == DWC2_HCSPLT_XACTPOS_ALL)
+                       halt_status = dwc2_update_isoc_urb_state(hsotg, chan,
+                                       chnum, qtd, DWC2_HC_XFER_COMPLETE);
+               dwc2_complete_periodic_xfer(hsotg, chan, chnum, qtd,
+                                           halt_status);
+               break;
+       }
+
+handle_xfercomp_done:
+       disable_hc_int(hsotg, chnum, HCINTMSK_XFERCOMPL);
+}
+
+/*
+ * Handles a host channel STALL interrupt. This handler may be called in
+ * either DMA mode or Slave mode.
+ */
+static void dwc2_hc_stall_intr(struct dwc2_hsotg *hsotg,
+                              struct dwc2_host_chan *chan, int chnum,
+                              struct dwc2_qtd *qtd)
+{
+       struct dwc2_hcd_urb *urb = qtd->urb;
+       int pipe_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
+
+       dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: STALL Received--\n",
+               chnum);
+
+       if (hsotg->core_params->dma_desc_enable > 0) {
+               dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
+                                           DWC2_HC_XFER_STALL);
+               goto handle_stall_done;
+       }
+
+       if (!urb)
+               goto handle_stall_halt;
+
+       if (pipe_type == USB_ENDPOINT_XFER_CONTROL)
+               dwc2_host_complete(hsotg, urb->priv, urb, -EPIPE);
+
+       if (pipe_type == USB_ENDPOINT_XFER_BULK ||
+           pipe_type == USB_ENDPOINT_XFER_INT) {
+               dwc2_host_complete(hsotg, urb->priv, urb, -EPIPE);
+               /*
+                * USB protocol requires resetting the data toggle for bulk
+                * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
+                * setup command is issued to the endpoint. Anticipate the
+                * CLEAR_FEATURE command since a STALL has occurred and reset
+                * the data toggle now.
+                */
+               chan->qh->data_toggle = 0;
+       }
+
+handle_stall_halt:
+       dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_STALL);
+
+handle_stall_done:
+       disable_hc_int(hsotg, chnum, HCINTMSK_STALL);
+}
+
+/*
+ * Updates the state of the URB when a transfer has been stopped due to an
+ * abnormal condition before the transfer completes. Modifies the
+ * actual_length field of the URB to reflect the number of bytes that have
+ * actually been transferred via the host channel.
+ */
+static void dwc2_update_urb_state_abn(struct dwc2_hsotg *hsotg,
+                                     struct dwc2_host_chan *chan, int chnum,
+                                     struct dwc2_hcd_urb *urb,
+                                     struct dwc2_qtd *qtd,
+                                     enum dwc2_halt_status halt_status)
+{
+       u32 xfer_length = dwc2_get_actual_xfer_length(hsotg, chan, chnum,
+                                                     qtd, halt_status, NULL);
+       u32 hctsiz;
+
+       if (urb->actual_length + xfer_length > urb->length) {
+               dev_warn(hsotg->dev, "%s(): trimming xfer length\n", __func__);
+               xfer_length = urb->length - urb->actual_length;
+       }
+
+       /* Non DWORD-aligned buffer case handling */
+       if (chan->align_buf && xfer_length && chan->ep_is_in) {
+               dev_dbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
+               dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length,
+                                       DMA_FROM_DEVICE);
+               memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
+                      xfer_length);
+               dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length,
+                                          DMA_FROM_DEVICE);
+       }
+
+       urb->actual_length += xfer_length;
+
+       hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
+       dev_vdbg(hsotg->dev, "DWC_otg: %s: %s, channel %d\n",
+                __func__, (chan->ep_is_in ? "IN" : "OUT"), chnum);
+       dev_vdbg(hsotg->dev, "  chan->start_pkt_count %d\n",
+                chan->start_pkt_count);
+       dev_vdbg(hsotg->dev, "  hctsiz.pktcnt %d\n",
+                hctsiz >> TSIZ_PKTCNT_SHIFT &
+                TSIZ_PKTCNT_MASK >> TSIZ_PKTCNT_SHIFT);
+       dev_vdbg(hsotg->dev, "  chan->max_packet %d\n", chan->max_packet);
+       dev_vdbg(hsotg->dev, "  bytes_transferred %d\n",
+                xfer_length);
+       dev_vdbg(hsotg->dev, "  urb->actual_length %d\n",
+                urb->actual_length);
+       dev_vdbg(hsotg->dev, "  urb->transfer_buffer_length %d\n",
+                urb->length);
+}
+
+/*
+ * Handles a host channel NAK interrupt. This handler may be called in either
+ * DMA mode or Slave mode.
+ */
+static void dwc2_hc_nak_intr(struct dwc2_hsotg *hsotg,
+                            struct dwc2_host_chan *chan, int chnum,
+                            struct dwc2_qtd *qtd)
+{
+       dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NAK Received--\n",
+                chnum);
+
+       /*
+        * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
+        * interrupt. Re-start the SSPLIT transfer.
+        */
+       if (chan->do_split) {
+               if (chan->complete_split)
+                       qtd->error_count = 0;
+               qtd->complete_split = 0;
+               dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
+               goto handle_nak_done;
+       }
+
+       switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
+       case USB_ENDPOINT_XFER_CONTROL:
+       case USB_ENDPOINT_XFER_BULK:
+               if (hsotg->core_params->dma_enable > 0 && chan->ep_is_in) {
+                       /*
+                        * NAK interrupts are enabled on bulk/control IN
+                        * transfers in DMA mode for the sole purpose of
+                        * resetting the error count after a transaction error
+                        * occurs. The core will continue transferring data.
+                        */
+                       qtd->error_count = 0;
+                       break;
+               }
+
+               /*
+                * NAK interrupts normally occur during OUT transfers in DMA
+                * or Slave mode. For IN transfers, more requests will be
+                * queued as request queue space is available.
+                */
+               qtd->error_count = 0;
+
+               if (!chan->qh->ping_state) {
+                       dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
+                                                 qtd, DWC2_HC_XFER_NAK);
+                       dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
+
+                       if (chan->speed == USB_SPEED_HIGH)
+                               chan->qh->ping_state = 1;
+               }
+
+               /*
+                * Halt the channel so the transfer can be re-started from
+                * the appropriate point or the PING protocol will
+                * start/continue
+                */
+               dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
+               break;
+       case USB_ENDPOINT_XFER_INT:
+               qtd->error_count = 0;
+               dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NAK);
+               break;
+       case USB_ENDPOINT_XFER_ISOC:
+               /* Should never get called for isochronous transfers */
+               dev_err(hsotg->dev, "NACK interrupt for ISOC transfer\n");
+               break;
+       }
+
+handle_nak_done:
+       disable_hc_int(hsotg, chnum, HCINTMSK_NAK);
+}
+
+/*
+ * Handles a host channel ACK interrupt. This interrupt is enabled when
+ * performing the PING protocol in Slave mode, when errors occur during
+ * either Slave mode or DMA mode, and during Start Split transactions.
+ */
+static void dwc2_hc_ack_intr(struct dwc2_hsotg *hsotg,
+                            struct dwc2_host_chan *chan, int chnum,
+                            struct dwc2_qtd *qtd)
+{
+       struct dwc2_hcd_iso_packet_desc *frame_desc;
+
+       dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: ACK Received--\n",
+                chnum);
+
+       if (chan->do_split) {
+               /* Handle ACK on SSPLIT. ACK should not occur in CSPLIT. */
+               if (!chan->ep_is_in &&
+                   chan->data_pid_start != DWC2_HC_PID_SETUP)
+                       qtd->ssplit_out_xfer_count = chan->xfer_len;
+
+               if (chan->ep_type != USB_ENDPOINT_XFER_ISOC || chan->ep_is_in) {
+                       qtd->complete_split = 1;
+                       dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
+               } else {
+                       /* ISOC OUT */
+                       switch (chan->xact_pos) {
+                       case DWC2_HCSPLT_XACTPOS_ALL:
+                               break;
+                       case DWC2_HCSPLT_XACTPOS_END:
+                               qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL;
+                               qtd->isoc_split_offset = 0;
+                               break;
+                       case DWC2_HCSPLT_XACTPOS_BEGIN:
+                       case DWC2_HCSPLT_XACTPOS_MID:
+                               /*
+                                * For BEGIN or MID, calculate the length for
+                                * the next microframe to determine the correct
+                                * SSPLIT token, either MID or END
+                                */
+                               frame_desc = &qtd->urb->iso_descs[
+                                               qtd->isoc_frame_index];
+                               qtd->isoc_split_offset += 188;
+
+                               if (frame_desc->length - qtd->isoc_split_offset
+                                                       <= 188)
+                                       qtd->isoc_split_pos =
+                                                       DWC2_HCSPLT_XACTPOS_END;
+                               else
+                                       qtd->isoc_split_pos =
+                                                       DWC2_HCSPLT_XACTPOS_MID;
+                               break;
+                       }
+               }
+       } else {
+               qtd->error_count = 0;
+
+               if (chan->qh->ping_state) {
+                       chan->qh->ping_state = 0;
+                       /*
+                        * Halt the channel so the transfer can be re-started
+                        * from the appropriate point. This only happens in
+                        * Slave mode. In DMA mode, the ping_state is cleared
+                        * when the transfer is started because the core
+                        * automatically executes the PING, then the transfer.
+                        */
+                       dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_ACK);
+               }
+       }
+
+       /*
+        * If the ACK occurred when _not_ in the PING state, let the channel
+        * continue transferring data after clearing the error count
+        */
+       disable_hc_int(hsotg, chnum, HCINTMSK_ACK);
+}
+
+/*
+ * Handles a host channel NYET interrupt. This interrupt should only occur on
+ * Bulk and Control OUT endpoints and for complete split transactions. If a
+ * NYET occurs at the same time as a Transfer Complete interrupt, it is
+ * handled in the xfercomp interrupt handler, not here. This handler may be
+ * called in either DMA mode or Slave mode.
+ */
+static void dwc2_hc_nyet_intr(struct dwc2_hsotg *hsotg,
+                             struct dwc2_host_chan *chan, int chnum,
+                             struct dwc2_qtd *qtd)
+{
+       dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: NYET Received--\n",
+                chnum);
+
+       /*
+        * NYET on CSPLIT
+        * re-do the CSPLIT immediately on non-periodic
+        */
+       if (chan->do_split && chan->complete_split) {
+               if (chan->ep_is_in && chan->ep_type == USB_ENDPOINT_XFER_ISOC &&
+                   hsotg->core_params->dma_enable > 0) {
+                       qtd->complete_split = 0;
+                       qtd->isoc_split_offset = 0;
+                       if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
+                               if (qtd->urb)
+                                       dwc2_host_complete(hsotg,
+                                                          qtd->urb->priv,
+                                                          qtd->urb, 0);
+                               dwc2_release_channel(hsotg, chan, qtd,
+                                               DWC2_HC_XFER_URB_COMPLETE);
+                       } else {
+                               dwc2_release_channel(hsotg, chan, qtd,
+                                               DWC2_HC_XFER_NO_HALT_STATUS);
+                       }
+                       goto handle_nyet_done;
+               }
+
+               if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
+                   chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
+                       int frnum = dwc2_hcd_get_frame_number(hsotg);
+
+                       if (dwc2_full_frame_num(frnum) !=
+                           dwc2_full_frame_num(chan->qh->sched_frame)) {
+                               /*
+                                * No longer in the same full speed frame.
+                                * Treat this as a transaction error.
+                                */
+#if 0
+                               /*
+                                * Todo: Fix system performance so this can
+                                * be treated as an error. Right now complete
+                                * splits cannot be scheduled precisely enough
+                                * due to other system activity, so this error
+                                * occurs regularly in Slave mode.
+                                */
+                               qtd->error_count++;
+#endif
+                               qtd->complete_split = 0;
+                               dwc2_halt_channel(hsotg, chan, qtd,
+                                                 DWC2_HC_XFER_XACT_ERR);
+                               /* Todo: add support for isoc release */
+                               goto handle_nyet_done;
+                       }
+               }
+
+               dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
+               goto handle_nyet_done;
+       }
+
+       chan->qh->ping_state = 1;
+       qtd->error_count = 0;
+
+       dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb, qtd,
+                                 DWC2_HC_XFER_NYET);
+       dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
+
+       /*
+        * Halt the channel and re-start the transfer so the PING protocol
+        * will start
+        */
+       dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_NYET);
+
+handle_nyet_done:
+       disable_hc_int(hsotg, chnum, HCINTMSK_NYET);
+}
+
+/*
+ * Handles a host channel babble interrupt. This handler may be called in
+ * either DMA mode or Slave mode.
+ */
+static void dwc2_hc_babble_intr(struct dwc2_hsotg *hsotg,
+                               struct dwc2_host_chan *chan, int chnum,
+                               struct dwc2_qtd *qtd)
+{
+       dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Babble Error--\n",
+               chnum);
+
+       if (hsotg->core_params->dma_desc_enable > 0) {
+               dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
+                                           DWC2_HC_XFER_BABBLE_ERR);
+               goto handle_babble_done;
+       }
+
+       if (chan->ep_type != USB_ENDPOINT_XFER_ISOC) {
+               if (qtd->urb)
+                       dwc2_host_complete(hsotg, qtd->urb->priv, qtd->urb,
+                                          -EOVERFLOW);
+               dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_BABBLE_ERR);
+       } else {
+               enum dwc2_halt_status halt_status;
+
+               halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
+                                               qtd, DWC2_HC_XFER_BABBLE_ERR);
+               dwc2_halt_channel(hsotg, chan, qtd, halt_status);
+       }
+
+handle_babble_done:
+       dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
+       disable_hc_int(hsotg, chnum, HCINTMSK_BBLERR);
+}
+
+/*
+ * Handles a host channel AHB error interrupt. This handler is only called in
+ * DMA mode.
+ */
+static void dwc2_hc_ahberr_intr(struct dwc2_hsotg *hsotg,
+                               struct dwc2_host_chan *chan, int chnum,
+                               struct dwc2_qtd *qtd)
+{
+       struct dwc2_hcd_urb *urb = qtd->urb;
+       char *pipetype, *speed;
+       u32 hcchar;
+       u32 hcsplt;
+       u32 hctsiz;
+       u32 hc_dma;
+
+       dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: AHB Error--\n",
+               chnum);
+
+       if (!urb)
+               goto handle_ahberr_halt;
+
+       hcchar = readl(hsotg->regs + HCCHAR(chnum));
+       hcsplt = readl(hsotg->regs + HCSPLT(chnum));
+       hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
+       hc_dma = readl(hsotg->regs + HCDMA(chnum));
+
+       dev_err(hsotg->dev, "AHB ERROR, Channel %d\n", chnum);
+       dev_err(hsotg->dev, "  hcchar 0x%08x, hcsplt 0x%08x\n", hcchar, hcsplt);
+       dev_err(hsotg->dev, "  hctsiz 0x%08x, hc_dma 0x%08x\n", hctsiz, hc_dma);
+       dev_err(hsotg->dev, "  Device address: %d\n",
+               dwc2_hcd_get_dev_addr(&urb->pipe_info));
+       dev_err(hsotg->dev, "  Endpoint: %d, %s\n",
+               dwc2_hcd_get_ep_num(&urb->pipe_info),
+               dwc2_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
+
+       switch (dwc2_hcd_get_pipe_type(&urb->pipe_info)) {
+       case USB_ENDPOINT_XFER_CONTROL:
+               pipetype = "CONTROL";
+               break;
+       case USB_ENDPOINT_XFER_BULK:
+               pipetype = "BULK";
+               break;
+       case USB_ENDPOINT_XFER_INT:
+               pipetype = "INTERRUPT";
+               break;
+       case USB_ENDPOINT_XFER_ISOC:
+               pipetype = "ISOCHRONOUS";
+               break;
+       default:
+               pipetype = "UNKNOWN";
+               break;
+       }
+
+       dev_err(hsotg->dev, "  Endpoint type: %s\n", pipetype);
+
+       switch (chan->speed) {
+       case USB_SPEED_HIGH:
+               speed = "HIGH";
+               break;
+       case USB_SPEED_FULL:
+               speed = "FULL";
+               break;
+       case USB_SPEED_LOW:
+               speed = "LOW";
+               break;
+       default:
+               speed = "UNKNOWN";
+               break;
+       }
+
+       dev_err(hsotg->dev, "  Speed: %s\n", speed);
+
+       dev_err(hsotg->dev, "  Max packet size: %d\n",
+               dwc2_hcd_get_mps(&urb->pipe_info));
+       dev_err(hsotg->dev, "  Data buffer length: %d\n", urb->length);
+       dev_err(hsotg->dev, "  Transfer buffer: %p, Transfer DMA: %08lx\n",
+               urb->buf, (unsigned long)urb->dma);
+       dev_err(hsotg->dev, "  Setup buffer: %p, Setup DMA: %08lx\n",
+               urb->setup_packet, (unsigned long)urb->setup_dma);
+       dev_err(hsotg->dev, "  Interval: %d\n", urb->interval);
+
+       /* Core halts the channel for Descriptor DMA mode */
+       if (hsotg->core_params->dma_desc_enable > 0) {
+               dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
+                                           DWC2_HC_XFER_AHB_ERR);
+               goto handle_ahberr_done;
+       }
+
+       dwc2_host_complete(hsotg, urb->priv, urb, -EIO);
+
+handle_ahberr_halt:
+       /*
+        * Force a channel halt. Don't call dwc2_halt_channel because that won't
+        * write to the HCCHARn register in DMA mode to force the halt.
+        */
+       dwc2_hc_halt(hsotg, chan, DWC2_HC_XFER_AHB_ERR);
+
+handle_ahberr_done:
+       dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
+       disable_hc_int(hsotg, chnum, HCINTMSK_AHBERR);
+}
+
+/*
+ * Handles a host channel transaction error interrupt. This handler may be
+ * called in either DMA mode or Slave mode.
+ */
+static void dwc2_hc_xacterr_intr(struct dwc2_hsotg *hsotg,
+                                struct dwc2_host_chan *chan, int chnum,
+                                struct dwc2_qtd *qtd)
+{
+       dev_dbg(hsotg->dev,
+               "--Host Channel %d Interrupt: Transaction Error--\n", chnum);
+
+       if (hsotg->core_params->dma_desc_enable > 0) {
+               dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
+                                           DWC2_HC_XFER_XACT_ERR);
+               goto handle_xacterr_done;
+       }
+
+       switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
+       case USB_ENDPOINT_XFER_CONTROL:
+       case USB_ENDPOINT_XFER_BULK:
+               qtd->error_count++;
+               if (!chan->qh->ping_state) {
+
+                       dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb,
+                                                 qtd, DWC2_HC_XFER_XACT_ERR);
+                       dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd);
+                       if (!chan->ep_is_in && chan->speed == USB_SPEED_HIGH)
+                               chan->qh->ping_state = 1;
+               }
+
+               /*
+                * Halt the channel so the transfer can be re-started from
+                * the appropriate point or the PING protocol will start
+                */
+               dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
+               break;
+       case USB_ENDPOINT_XFER_INT:
+               qtd->error_count++;
+               if (chan->do_split && chan->complete_split)
+                       qtd->complete_split = 0;
+               dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR);
+               break;
+       case USB_ENDPOINT_XFER_ISOC:
+               {
+                       enum dwc2_halt_status halt_status;
+
+                       halt_status = dwc2_update_isoc_urb_state(hsotg, chan,
+                                       chnum, qtd, DWC2_HC_XFER_XACT_ERR);
+                       dwc2_halt_channel(hsotg, chan, qtd, halt_status);
+               }
+               break;
+       }
+
+handle_xacterr_done:
+       dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
+       disable_hc_int(hsotg, chnum, HCINTMSK_XACTERR);
+}
+
+/*
+ * Handles a host channel frame overrun interrupt. This handler may be called
+ * in either DMA mode or Slave mode.
+ */
+static void dwc2_hc_frmovrun_intr(struct dwc2_hsotg *hsotg,
+                                 struct dwc2_host_chan *chan, int chnum,
+                                 struct dwc2_qtd *qtd)
+{
+       enum dwc2_halt_status halt_status;
+
+       dev_dbg(hsotg->dev, "--Host Channel %d Interrupt: Frame Overrun--\n",
+               chnum);
+
+       switch (dwc2_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
+       case USB_ENDPOINT_XFER_CONTROL:
+       case USB_ENDPOINT_XFER_BULK:
+               break;
+       case USB_ENDPOINT_XFER_INT:
+               dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_FRAME_OVERRUN);
+               break;
+       case USB_ENDPOINT_XFER_ISOC:
+               halt_status = dwc2_update_isoc_urb_state(hsotg, chan, chnum,
+                                       qtd, DWC2_HC_XFER_FRAME_OVERRUN);
+               dwc2_halt_channel(hsotg, chan, qtd, halt_status);
+               break;
+       }
+
+       dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
+       disable_hc_int(hsotg, chnum, HCINTMSK_FRMOVRUN);
+}
+
+/*
+ * Handles a host channel data toggle error interrupt. This handler may be
+ * called in either DMA mode or Slave mode.
+ */
+static void dwc2_hc_datatglerr_intr(struct dwc2_hsotg *hsotg,
+                                   struct dwc2_host_chan *chan, int chnum,
+                                   struct dwc2_qtd *qtd)
+{
+       dev_dbg(hsotg->dev,
+               "--Host Channel %d Interrupt: Data Toggle Error--\n", chnum);
+
+       if (chan->ep_is_in)
+               qtd->error_count = 0;
+       else
+               dev_err(hsotg->dev,
+                       "Data Toggle Error on OUT transfer, channel %d\n",
+                       chnum);
+
+       dwc2_hc_handle_tt_clear(hsotg, chan, qtd);
+       disable_hc_int(hsotg, chnum, HCINTMSK_DATATGLERR);
+}
+
+/*
+ * For debug only. It checks that a valid halt status is set and that
+ * HCCHARn.chdis is clear. If there's a problem, corrective action is
+ * taken and a warning is issued.
+ *
+ * Return: true if halt status is ok, false otherwise
+ */
+static bool dwc2_halt_status_ok(struct dwc2_hsotg *hsotg,
+                               struct dwc2_host_chan *chan, int chnum,
+                               struct dwc2_qtd *qtd)
+{
+#ifdef DEBUG
+       u32 hcchar;
+       u32 hctsiz;
+       u32 hcintmsk;
+       u32 hcsplt;
+
+       if (chan->halt_status == DWC2_HC_XFER_NO_HALT_STATUS) {
+               /*
+                * This code is here only as a check. This condition should
+                * never happen. Ignore the halt if it does occur.
+                */
+               hcchar = readl(hsotg->regs + HCCHAR(chnum));
+               hctsiz = readl(hsotg->regs + HCTSIZ(chnum));
+               hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
+               hcsplt = readl(hsotg->regs + HCSPLT(chnum));
+               dev_dbg(hsotg->dev,
+                       "%s: chan->halt_status DWC2_HC_XFER_NO_HALT_STATUS,\n",
+                        __func__);
+               dev_dbg(hsotg->dev,
+                       "channel %d, hcchar 0x%08x, hctsiz 0x%08x,\n",
+                       chnum, hcchar, hctsiz);
+               dev_dbg(hsotg->dev,
+                       "hcint 0x%08x, hcintmsk 0x%08x, hcsplt 0x%08x,\n",
+                       chan->hcint, hcintmsk, hcsplt);
+               if (qtd)
+                       dev_dbg(hsotg->dev, "qtd->complete_split %d\n",
+                               qtd->complete_split);
+               dev_warn(hsotg->dev,
+                        "%s: no halt status, channel %d, ignoring interrupt\n",
+                        __func__, chnum);
+               return false;
+       }
+
+       /*
+        * This code is here only as a check. hcchar.chdis should never be set
+        * when the halt interrupt occurs. Halt the channel again if it does
+        * occur.
+        */
+       hcchar = readl(hsotg->regs + HCCHAR(chnum));
+       if (hcchar & HCCHAR_CHDIS) {
+               dev_warn(hsotg->dev,
+                        "%s: hcchar.chdis set unexpectedly, hcchar 0x%08x, trying to halt again\n",
+                        __func__, hcchar);
+               chan->halt_pending = 0;
+               dwc2_halt_channel(hsotg, chan, qtd, chan->halt_status);
+               return false;
+       }
+#endif
+
+       return true;
+}
+
+/*
+ * Handles a host Channel Halted interrupt in DMA mode. This handler
+ * determines the reason the channel halted and proceeds accordingly.
+ */
+static void dwc2_hc_chhltd_intr_dma(struct dwc2_hsotg *hsotg,
+                                   struct dwc2_host_chan *chan, int chnum,
+                                   struct dwc2_qtd *qtd)
+{
+       u32 hcintmsk;
+       int out_nak_enh = 0;
+
+       dev_vdbg(hsotg->dev,
+                "--Host Channel %d Interrupt: DMA Channel Halted--\n", chnum);
+
+       /*
+        * For core with OUT NAK enhancement, the flow for high-speed
+        * CONTROL/BULK OUT is handled a little differently
+        */
+       if (hsotg->snpsid >= DWC2_CORE_REV_2_71a) {
+               if (chan->speed == USB_SPEED_HIGH && !chan->ep_is_in &&
+                   (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
+                    chan->ep_type == USB_ENDPOINT_XFER_BULK)) {
+                       out_nak_enh = 1;
+               }
+       }
+
+       if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE ||
+           (chan->halt_status == DWC2_HC_XFER_AHB_ERR &&
+            hsotg->core_params->dma_desc_enable <= 0)) {
+               if (hsotg->core_params->dma_desc_enable > 0)
+                       dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
+                                                   chan->halt_status);
+               else
+                       /*
+                        * Just release the channel. A dequeue can happen on a
+                        * transfer timeout. In the case of an AHB Error, the
+                        * channel was forced to halt because there's no way to
+                        * gracefully recover.
+                        */
+                       dwc2_release_channel(hsotg, chan, qtd,
+                                            chan->halt_status);
+               return;
+       }
+
+       hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
+
+       if (chan->hcint & HCINTMSK_XFERCOMPL) {
+               /*
+                * Todo: This is here because of a possible hardware bug. Spec
+                * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
+                * interrupt w/ACK bit set should occur, but I only see the
+                * XFERCOMP bit, even with it masked out. This is a workaround
+                * for that behavior. Should fix this when hardware is fixed.
+                */
+               if (chan->ep_type == USB_ENDPOINT_XFER_ISOC && !chan->ep_is_in)
+                       dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
+               dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
+       } else if (chan->hcint & HCINTMSK_STALL) {
+               dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
+       } else if ((chan->hcint & HCINTMSK_XACTERR) &&
+                  hsotg->core_params->dma_desc_enable <= 0) {
+               if (out_nak_enh) {
+                       if (chan->hcint &
+                           (HCINTMSK_NYET | HCINTMSK_NAK | HCINTMSK_ACK)) {
+                               dev_vdbg(hsotg->dev,
+                                        "XactErr with NYET/NAK/ACK\n");
+                               qtd->error_count = 0;
+                       } else {
+                               dev_vdbg(hsotg->dev,
+                                        "XactErr without NYET/NAK/ACK\n");
+                       }
+               }
+
+               /*
+                * Must handle xacterr before nak or ack. Could get a xacterr
+                * at the same time as either of these on a BULK/CONTROL OUT
+                * that started with a PING. The xacterr takes precedence.
+                */
+               dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
+       } else if ((chan->hcint & HCINTMSK_XCS_XACT) &&
+                  hsotg->core_params->dma_desc_enable > 0) {
+               dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
+       } else if ((chan->hcint & HCINTMSK_AHBERR) &&
+                  hsotg->core_params->dma_desc_enable > 0) {
+               dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
+       } else if (chan->hcint & HCINTMSK_BBLERR) {
+               dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
+       } else if (chan->hcint & HCINTMSK_FRMOVRUN) {
+               dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
+       } else if (!out_nak_enh) {
+               if (chan->hcint & HCINTMSK_NYET) {
+                       /*
+                        * Must handle nyet before nak or ack. Could get a nyet
+                        * at the same time as either of those on a BULK/CONTROL
+                        * OUT that started with a PING. The nyet takes
+                        * precedence.
+                        */
+                       dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
+               } else if ((chan->hcint & HCINTMSK_NAK) &&
+                          !(hcintmsk & HCINTMSK_NAK)) {
+                       /*
+                        * If nak is not masked, it's because a non-split IN
+                        * transfer is in an error state. In that case, the nak
+                        * is handled by the nak interrupt handler, not here.
+                        * Handle nak here for BULK/CONTROL OUT transfers, which
+                        * halt on a NAK to allow rewinding the buffer pointer.
+                        */
+                       dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
+               } else if ((chan->hcint & HCINTMSK_ACK) &&
+                          !(hcintmsk & HCINTMSK_ACK)) {
+                       /*
+                        * If ack is not masked, it's because a non-split IN
+                        * transfer is in an error state. In that case, the ack
+                        * is handled by the ack interrupt handler, not here.
+                        * Handle ack here for split transfers. Start splits
+                        * halt on ACK.
+                        */
+                       dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
+               } else {
+                       if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
+                           chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
+                               /*
+                                * A periodic transfer halted with no other
+                                * channel interrupts set. Assume it was halted
+                                * by the core because it could not be completed
+                                * in its scheduled (micro)frame.
+                                */
+                               dev_dbg(hsotg->dev,
+                                       "%s: Halt channel %d (assume incomplete periodic transfer)\n",
+                                       __func__, chnum);
+                               dwc2_halt_channel(hsotg, chan, qtd,
+                                       DWC2_HC_XFER_PERIODIC_INCOMPLETE);
+                       } else {
+                               dev_err(hsotg->dev,
+                                       "%s: Channel %d - ChHltd set, but reason is unknown\n",
+                                       __func__, chnum);
+                               dev_err(hsotg->dev,
+                                       "hcint 0x%08x, intsts 0x%08x\n",
+                                       chan->hcint,
+                                       readl(hsotg->regs + GINTSTS));
+                       }
+               }
+       } else {
+               dev_info(hsotg->dev,
+                        "NYET/NAK/ACK/other in non-error case, 0x%08x\n",
+                        chan->hcint);
+       }
+}
+
+/*
+ * Handles a host channel Channel Halted interrupt
+ *
+ * In slave mode, this handler is called only when the driver specifically
+ * requests a halt. This occurs during handling other host channel interrupts
+ * (e.g. nak, xacterr, stall, nyet, etc.).
+ *
+ * In DMA mode, this is the interrupt that occurs when the core has finished
+ * processing a transfer on a channel. Other host channel interrupts (except
+ * ahberr) are disabled in DMA mode.
+ */
+static void dwc2_hc_chhltd_intr(struct dwc2_hsotg *hsotg,
+                               struct dwc2_host_chan *chan, int chnum,
+                               struct dwc2_qtd *qtd)
+{
+       dev_vdbg(hsotg->dev, "--Host Channel %d Interrupt: Channel Halted--\n",
+                chnum);
+
+       if (hsotg->core_params->dma_enable > 0) {
+               dwc2_hc_chhltd_intr_dma(hsotg, chan, chnum, qtd);
+       } else {
+               if (!dwc2_halt_status_ok(hsotg, chan, chnum, qtd))
+                       return;
+               dwc2_release_channel(hsotg, chan, qtd, chan->halt_status);
+       }
+}
+
+/* Handles interrupt for a specific Host Channel */
+static void dwc2_hc_n_intr(struct dwc2_hsotg *hsotg, int chnum)
+{
+       struct dwc2_qtd *qtd;
+       struct dwc2_host_chan *chan;
+       u32 hcint, hcintmsk;
+
+       dev_vdbg(hsotg->dev, "--Host Channel Interrupt--, Channel %d\n", chnum);
+
+       hcint = readl(hsotg->regs + HCINT(chnum));
+       hcintmsk = readl(hsotg->regs + HCINTMSK(chnum));
+       dev_vdbg(hsotg->dev,
+                "  hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
+                hcint, hcintmsk, hcint & hcintmsk);
+
+       chan = hsotg->hc_ptr_array[chnum];
+       if (!chan) {
+               dev_err(hsotg->dev, "## hc_ptr_array for channel is NULL ##\n");
+               writel(hcint, hsotg->regs + HCINT(chnum));
+               return;
+       }
+
+       writel(hcint, hsotg->regs + HCINT(chnum));
+       chan->hcint = hcint;
+       hcint &= hcintmsk;
+
+       /*
+        * If the channel was halted due to a dequeue, the qtd list might
+        * be empty or at least the first entry will not be the active qtd.
+        * In this case, take a shortcut and just release the channel.
+        */
+       if (chan->halt_status == DWC2_HC_XFER_URB_DEQUEUE) {
+               /*
+                * If the channel was halted, this should be the only
+                * interrupt unmasked
+                */
+               WARN_ON(hcint != HCINTMSK_CHHLTD);
+               if (hsotg->core_params->dma_desc_enable > 0)
+                       dwc2_hcd_complete_xfer_ddma(hsotg, chan, chnum,
+                                                   chan->halt_status);
+               else
+                       dwc2_release_channel(hsotg, chan, NULL,
+                                            chan->halt_status);
+               return;
+       }
+
+       if (list_empty(&chan->qh->qtd_list)) {
+               /*
+                * TODO: Will this ever happen with the
+                * DWC2_HC_XFER_URB_DEQUEUE handling above?
+                */
+               dev_dbg(hsotg->dev, "## no QTD queued for channel %d ##\n",
+                       chnum);
+               dev_dbg(hsotg->dev,
+                       "  hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
+                       chan->hcint, hcintmsk, hcint);
+               chan->halt_status = DWC2_HC_XFER_NO_HALT_STATUS;
+               disable_hc_int(hsotg, chnum, HCINTMSK_CHHLTD);
+               chan->hcint = 0;
+               return;
+       }
+
+       qtd = list_first_entry(&chan->qh->qtd_list, struct dwc2_qtd,
+                              qtd_list_entry);
+
+       if (hsotg->core_params->dma_enable <= 0) {
+               if ((hcint & HCINTMSK_CHHLTD) && hcint != HCINTMSK_CHHLTD)
+                       hcint &= ~HCINTMSK_CHHLTD;
+       }
+
+       if (hcint & HCINTMSK_XFERCOMPL) {
+               dwc2_hc_xfercomp_intr(hsotg, chan, chnum, qtd);
+               /*
+                * If NYET occurred at same time as Xfer Complete, the NYET is
+                * handled by the Xfer Complete interrupt handler. Don't want
+                * to call the NYET interrupt handler in this case.
+                */
+               hcint &= ~HCINTMSK_NYET;
+       }
+       if (hcint & HCINTMSK_CHHLTD)
+               dwc2_hc_chhltd_intr(hsotg, chan, chnum, qtd);
+       if (hcint & HCINTMSK_AHBERR)
+               dwc2_hc_ahberr_intr(hsotg, chan, chnum, qtd);
+       if (hcint & HCINTMSK_STALL)
+               dwc2_hc_stall_intr(hsotg, chan, chnum, qtd);
+       if (hcint & HCINTMSK_NAK)
+               dwc2_hc_nak_intr(hsotg, chan, chnum, qtd);
+       if (hcint & HCINTMSK_ACK)
+               dwc2_hc_ack_intr(hsotg, chan, chnum, qtd);
+       if (hcint & HCINTMSK_NYET)
+               dwc2_hc_nyet_intr(hsotg, chan, chnum, qtd);
+       if (hcint & HCINTMSK_XACTERR)
+               dwc2_hc_xacterr_intr(hsotg, chan, chnum, qtd);
+       if (hcint & HCINTMSK_BBLERR)
+               dwc2_hc_babble_intr(hsotg, chan, chnum, qtd);
+       if (hcint & HCINTMSK_FRMOVRUN)
+               dwc2_hc_frmovrun_intr(hsotg, chan, chnum, qtd);
+       if (hcint & HCINTMSK_DATATGLERR)
+               dwc2_hc_datatglerr_intr(hsotg, chan, chnum, qtd);
+
+       chan->hcint = 0;
+}
+
+/*
+ * This interrupt indicates that one or more host channels has a pending
+ * interrupt. There are multiple conditions that can cause each host channel
+ * interrupt. This function determines which conditions have occurred for each
+ * host channel interrupt and handles them appropriately.
+ */
+static void dwc2_hc_intr(struct dwc2_hsotg *hsotg)
+{
+       u32 haint;
+       int i;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       haint = readl(hsotg->regs + HAINT);
+       dev_vdbg(hsotg->dev, "HAINT=%08x\n", haint);
+
+       for (i = 0; i < hsotg->core_params->host_channels; i++) {
+               if (haint & (1 << i))
+                       dwc2_hc_n_intr(hsotg, i);
+       }
+}
+
+/* This function handles interrupts for the HCD */
+int dwc2_hcd_intr(struct dwc2_hsotg *hsotg)
+{
+       u32 gintsts;
+       int retval = 0;
+
+       if (dwc2_check_core_status(hsotg) < 0) {
+               dev_warn(hsotg->dev, "Controller is disconnected");
+               return 0;
+       }
+
+       spin_lock(&hsotg->lock);
+
+       /* Check if HOST Mode */
+       if (dwc2_is_host_mode(hsotg)) {
+               gintsts = dwc2_read_core_intr(hsotg);
+               if (!gintsts) {
+                       spin_unlock(&hsotg->lock);
+                       return 0;
+               }
+
+               retval = 1;
+
+#ifndef DEBUG_SOF
+               /* Don't print debug message in the interrupt handler on SOF */
+               if (gintsts != GINTSTS_SOF)
+#endif
+                       dev_vdbg(hsotg->dev,
+                                "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x\n",
+                                gintsts);
+
+               if (gintsts & GINTSTS_SOF)
+                       dwc2_sof_intr(hsotg);
+               if (gintsts & GINTSTS_RXFLVL)
+                       dwc2_rx_fifo_level_intr(hsotg);
+               if (gintsts & GINTSTS_NPTXFEMP)
+                       dwc2_np_tx_fifo_empty_intr(hsotg);
+               if (gintsts & GINTSTS_I2CINT)
+                       /* Todo: Implement i2cintr handler */
+                       writel(GINTSTS_I2CINT, hsotg->regs + GINTSTS);
+               if (gintsts & GINTSTS_PRTINT)
+                       dwc2_port_intr(hsotg);
+               if (gintsts & GINTSTS_HCHINT)
+                       dwc2_hc_intr(hsotg);
+               if (gintsts & GINTSTS_PTXFEMP)
+                       dwc2_perio_tx_fifo_empty_intr(hsotg);
+
+#ifndef DEBUG_SOF
+               if (gintsts != GINTSTS_SOF) {
+#endif
+                       dev_vdbg(hsotg->dev,
+                                "DWC OTG HCD Finished Servicing Interrupts\n");
+                       dev_vdbg(hsotg->dev,
+                                "DWC OTG HCD gintsts=0x%08x gintmsk=0x%08x\n",
+                                readl(hsotg->regs + GINTSTS),
+                                readl(hsotg->regs + GINTMSK));
+#ifndef DEBUG_SOF
+               }
+#endif
+       }
+
+       spin_unlock(&hsotg->lock);
+
+       return retval;
+}
diff --git a/drivers/staging/dwc2/hcd_queue.c b/drivers/staging/dwc2/hcd_queue.c
new file mode 100644 (file)
index 0000000..74b7b9b
--- /dev/null
@@ -0,0 +1,675 @@
+/*
+ * hcd_queue.c - DesignWare HS OTG Controller host queuing routines
+ *
+ * Copyright (C) 2004-2013 Synopsys, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. 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.
+ * 3. The names of the above-listed copyright holders may not 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 the 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 OWNER 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.
+ */
+
+/*
+ * This file contains the functions to manage Queue Heads and Queue
+ * Transfer Descriptors for Host mode
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+
+#include <linux/usb/hcd.h>
+#include <linux/usb/ch11.h>
+
+#include "core.h"
+#include "hcd.h"
+
+/**
+ * dwc2_qh_init() - Initializes a QH structure
+ *
+ * @hsotg: The HCD state structure for the DWC OTG controller
+ * @qh:    The QH to init
+ * @urb:   Holds the information about the device/endpoint needed to initialize
+ *         the QH
+ */
+#define SCHEDULE_SLOP 10
+static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
+                        struct dwc2_hcd_urb *urb)
+{
+       int dev_speed, hub_addr, hub_port;
+       char *speed, *type;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       /* Initialize QH */
+       qh->ep_type = dwc2_hcd_get_pipe_type(&urb->pipe_info);
+       qh->ep_is_in = dwc2_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
+
+       qh->data_toggle = DWC2_HC_PID_DATA0;
+       qh->maxp = dwc2_hcd_get_mps(&urb->pipe_info);
+       INIT_LIST_HEAD(&qh->qtd_list);
+       INIT_LIST_HEAD(&qh->qh_list_entry);
+
+       /* FS/LS Endpoint on HS Hub, NOT virtual root hub */
+       dev_speed = dwc2_host_get_speed(hsotg, urb->priv);
+
+       dwc2_host_hub_info(hsotg, urb->priv, &hub_addr, &hub_port);
+
+       if ((dev_speed == USB_SPEED_LOW || dev_speed == USB_SPEED_FULL) &&
+           hub_addr != 0 && hub_addr != 1) {
+               dev_vdbg(hsotg->dev,
+                        "QH init: EP %d: TT found at hub addr %d, for port %d\n",
+                        dwc2_hcd_get_ep_num(&urb->pipe_info), hub_addr,
+                        hub_port);
+               qh->do_split = 1;
+       }
+
+       if (qh->ep_type == USB_ENDPOINT_XFER_INT ||
+           qh->ep_type == USB_ENDPOINT_XFER_ISOC) {
+               /* Compute scheduling parameters once and save them */
+               u32 hprt, prtspd;
+
+               /* Todo: Account for split transfers in the bus time */
+               int bytecount =
+                       dwc2_hb_mult(qh->maxp) * dwc2_max_packet(qh->maxp);
+
+               qh->usecs = NS_TO_US(usb_calc_bus_time(qh->do_split ?
+                               USB_SPEED_HIGH : dev_speed, qh->ep_is_in,
+                               qh->ep_type == USB_ENDPOINT_XFER_ISOC,
+                               bytecount));
+               /* Start in a slightly future (micro)frame */
+               qh->sched_frame = dwc2_frame_num_inc(hsotg->frame_number,
+                                                    SCHEDULE_SLOP);
+               qh->interval = urb->interval;
+#if 0
+               /* Increase interrupt polling rate for debugging */
+               if (qh->ep_type == USB_ENDPOINT_XFER_INT)
+                       qh->interval = 8;
+#endif
+               hprt = readl(hsotg->regs + HPRT0);
+               prtspd = hprt & HPRT0_SPD_MASK;
+               if (prtspd == HPRT0_SPD_HIGH_SPEED &&
+                   (dev_speed == USB_SPEED_LOW ||
+                    dev_speed == USB_SPEED_FULL)) {
+                       qh->interval *= 8;
+                       qh->sched_frame |= 0x7;
+                       qh->start_split_frame = qh->sched_frame;
+               }
+               dev_dbg(hsotg->dev, "interval=%d\n", qh->interval);
+       }
+
+       dev_vdbg(hsotg->dev, "DWC OTG HCD QH Initialized\n");
+       dev_vdbg(hsotg->dev, "DWC OTG HCD QH - qh = %p\n", qh);
+       dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Device Address = %d\n",
+                dwc2_hcd_get_dev_addr(&urb->pipe_info));
+       dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Endpoint %d, %s\n",
+                dwc2_hcd_get_ep_num(&urb->pipe_info),
+                dwc2_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
+
+       qh->dev_speed = dev_speed;
+
+       switch (dev_speed) {
+       case USB_SPEED_LOW:
+               speed = "low";
+               break;
+       case USB_SPEED_FULL:
+               speed = "full";
+               break;
+       case USB_SPEED_HIGH:
+               speed = "high";
+               break;
+       default:
+               speed = "?";
+               break;
+       }
+       dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Speed = %s\n", speed);
+
+       switch (qh->ep_type) {
+       case USB_ENDPOINT_XFER_ISOC:
+               type = "isochronous";
+               break;
+       case USB_ENDPOINT_XFER_INT:
+               type = "interrupt";
+               break;
+       case USB_ENDPOINT_XFER_CONTROL:
+               type = "control";
+               break;
+       case USB_ENDPOINT_XFER_BULK:
+               type = "bulk";
+               break;
+       default:
+               type = "?";
+               break;
+       }
+
+       dev_vdbg(hsotg->dev, "DWC OTG HCD QH - Type = %s\n", type);
+
+       if (qh->ep_type == USB_ENDPOINT_XFER_INT) {
+               dev_vdbg(hsotg->dev, "DWC OTG HCD QH - usecs = %d\n",
+                        qh->usecs);
+               dev_vdbg(hsotg->dev, "DWC OTG HCD QH - interval = %d\n",
+                        qh->interval);
+       }
+}
+
+/**
+ * dwc2_hcd_qh_create() - Allocates and initializes a QH
+ *
+ * @hsotg:        The HCD state structure for the DWC OTG controller
+ * @urb:          Holds the information about the device/endpoint needed
+ *                to initialize the QH
+ * @atomic_alloc: Flag to do atomic allocation if needed
+ *
+ * Return: Pointer to the newly allocated QH, or NULL on error
+ */
+static struct dwc2_qh *dwc2_hcd_qh_create(struct dwc2_hsotg *hsotg,
+                                         struct dwc2_hcd_urb *urb,
+                                         gfp_t mem_flags)
+{
+       struct dwc2_qh *qh;
+
+       /* Allocate memory */
+       qh = kzalloc(sizeof(*qh), mem_flags);
+       if (!qh)
+               return NULL;
+
+       dwc2_qh_init(hsotg, qh, urb);
+
+       if (hsotg->core_params->dma_desc_enable > 0 &&
+           dwc2_hcd_qh_init_ddma(hsotg, qh, mem_flags) < 0) {
+               dwc2_hcd_qh_free(hsotg, qh);
+               return NULL;
+       }
+
+       return qh;
+}
+
+/**
+ * dwc2_hcd_qh_free() - Frees the QH
+ *
+ * @hsotg: HCD instance
+ * @qh:    The QH to free
+ *
+ * QH should already be removed from the list. QTD list should already be empty
+ * if called from URB Dequeue.
+ *
+ * Must NOT be called with interrupt disabled or spinlock held
+ */
+void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
+{
+       u32 buf_size;
+
+       if (hsotg->core_params->dma_desc_enable > 0) {
+               dwc2_hcd_qh_free_ddma(hsotg, qh);
+       } else if (qh->dw_align_buf) {
+               if (qh->ep_type == USB_ENDPOINT_XFER_ISOC)
+                       buf_size = 4096;
+               else
+                       buf_size = hsotg->core_params->max_transfer_size;
+               dma_free_coherent(hsotg->dev, buf_size, qh->dw_align_buf,
+                                 qh->dw_align_buf_dma);
+       }
+
+       kfree(qh);
+}
+
+/**
+ * dwc2_periodic_channel_available() - Checks that a channel is available for a
+ * periodic transfer
+ *
+ * @hsotg: The HCD state structure for the DWC OTG controller
+ *
+ * Return: 0 if successful, negative error code otherise
+ */
+static int dwc2_periodic_channel_available(struct dwc2_hsotg *hsotg)
+{
+       /*
+        * Currently assuming that there is a dedicated host channnel for
+        * each periodic transaction plus at least one host channel for
+        * non-periodic transactions
+        */
+       int status;
+       int num_channels;
+
+       num_channels = hsotg->core_params->host_channels;
+       if (hsotg->periodic_channels + hsotg->non_periodic_channels <
+                                                               num_channels
+           && hsotg->periodic_channels < num_channels - 1) {
+               status = 0;
+       } else {
+               dev_dbg(hsotg->dev,
+                       "%s: Total channels: %d, Periodic: %d, "
+                       "Non-periodic: %d\n", __func__, num_channels,
+                       hsotg->periodic_channels, hsotg->non_periodic_channels);
+               status = -ENOSPC;
+       }
+
+       return status;
+}
+
+/**
+ * dwc2_check_periodic_bandwidth() - Checks that there is sufficient bandwidth
+ * for the specified QH in the periodic schedule
+ *
+ * @hsotg: The HCD state structure for the DWC OTG controller
+ * @qh:    QH containing periodic bandwidth required
+ *
+ * Return: 0 if successful, negative error code otherwise
+ *
+ * For simplicity, this calculation assumes that all the transfers in the
+ * periodic schedule may occur in the same (micro)frame
+ */
+static int dwc2_check_periodic_bandwidth(struct dwc2_hsotg *hsotg,
+                                        struct dwc2_qh *qh)
+{
+       int status;
+       s16 max_claimed_usecs;
+
+       status = 0;
+
+       if (qh->dev_speed == USB_SPEED_HIGH || qh->do_split) {
+               /*
+                * High speed mode
+                * Max periodic usecs is 80% x 125 usec = 100 usec
+                */
+               max_claimed_usecs = 100 - qh->usecs;
+       } else {
+               /*
+                * Full speed mode
+                * Max periodic usecs is 90% x 1000 usec = 900 usec
+                */
+               max_claimed_usecs = 900 - qh->usecs;
+       }
+
+       if (hsotg->periodic_usecs > max_claimed_usecs) {
+               dev_err(hsotg->dev,
+                       "%s: already claimed usecs %d, required usecs %d\n",
+                       __func__, hsotg->periodic_usecs, qh->usecs);
+               status = -ENOSPC;
+       }
+
+       return status;
+}
+
+/**
+ * dwc2_check_max_xfer_size() - Checks that the max transfer size allowed in a
+ * host channel is large enough to handle the maximum data transfer in a single
+ * (micro)frame for a periodic transfer
+ *
+ * @hsotg: The HCD state structure for the DWC OTG controller
+ * @qh:    QH for a periodic endpoint
+ *
+ * Return: 0 if successful, negative error code otherwise
+ */
+static int dwc2_check_max_xfer_size(struct dwc2_hsotg *hsotg,
+                                   struct dwc2_qh *qh)
+{
+       u32 max_xfer_size;
+       u32 max_channel_xfer_size;
+       int status = 0;
+
+       max_xfer_size = dwc2_max_packet(qh->maxp) * dwc2_hb_mult(qh->maxp);
+       max_channel_xfer_size = hsotg->core_params->max_transfer_size;
+
+       if (max_xfer_size > max_channel_xfer_size) {
+               dev_err(hsotg->dev,
+                       "%s: Periodic xfer length %d > max xfer length for channel %d\n",
+                       __func__, max_xfer_size, max_channel_xfer_size);
+               status = -ENOSPC;
+       }
+
+       return status;
+}
+
+/**
+ * dwc2_schedule_periodic() - Schedules an interrupt or isochronous transfer in
+ * the periodic schedule
+ *
+ * @hsotg: The HCD state structure for the DWC OTG controller
+ * @qh:    QH for the periodic transfer. The QH should already contain the
+ *         scheduling information.
+ *
+ * Return: 0 if successful, negative error code otherwise
+ */
+static int dwc2_schedule_periodic(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
+{
+       int status;
+
+       status = dwc2_periodic_channel_available(hsotg);
+       if (status) {
+               dev_dbg(hsotg->dev,
+                       "%s: No host channel available for periodic transfer\n",
+                       __func__);
+               return status;
+       }
+
+       status = dwc2_check_periodic_bandwidth(hsotg, qh);
+       if (status) {
+               dev_dbg(hsotg->dev,
+                       "%s: Insufficient periodic bandwidth for periodic transfer\n",
+                       __func__);
+               return status;
+       }
+
+       status = dwc2_check_max_xfer_size(hsotg, qh);
+       if (status) {
+               dev_dbg(hsotg->dev,
+                       "%s: Channel max transfer size too small for periodic transfer\n",
+                       __func__);
+               return status;
+       }
+
+       if (hsotg->core_params->dma_desc_enable > 0)
+               /* Don't rely on SOF and start in ready schedule */
+               list_add_tail(&qh->qh_list_entry, &hsotg->periodic_sched_ready);
+       else
+               /* Always start in inactive schedule */
+               list_add_tail(&qh->qh_list_entry,
+                             &hsotg->periodic_sched_inactive);
+
+       /* Reserve periodic channel */
+       hsotg->periodic_channels++;
+
+       /* Update claimed usecs per (micro)frame */
+       hsotg->periodic_usecs += qh->usecs;
+
+       return status;
+}
+
+/**
+ * dwc2_deschedule_periodic() - Removes an interrupt or isochronous transfer
+ * from the periodic schedule
+ *
+ * @hsotg: The HCD state structure for the DWC OTG controller
+ * @qh:           QH for the periodic transfer
+ */
+static void dwc2_deschedule_periodic(struct dwc2_hsotg *hsotg,
+                                    struct dwc2_qh *qh)
+{
+       list_del_init(&qh->qh_list_entry);
+
+       /* Release periodic channel reservation */
+       hsotg->periodic_channels--;
+
+       /* Update claimed usecs per (micro)frame */
+       hsotg->periodic_usecs -= qh->usecs;
+}
+
+/**
+ * dwc2_hcd_qh_add() - Adds a QH to either the non periodic or periodic
+ * schedule if it is not already in the schedule. If the QH is already in
+ * the schedule, no action is taken.
+ *
+ * @hsotg: The HCD state structure for the DWC OTG controller
+ * @qh:    The QH to add
+ *
+ * Return: 0 if successful, negative error code otherwise
+ */
+int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
+{
+       int status = 0;
+       u32 intr_mask;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       if (!list_empty(&qh->qh_list_entry))
+               /* QH already in a schedule */
+               return status;
+
+       /* Add the new QH to the appropriate schedule */
+       if (dwc2_qh_is_non_per(qh)) {
+               /* Always start in inactive schedule */
+               list_add_tail(&qh->qh_list_entry,
+                             &hsotg->non_periodic_sched_inactive);
+       } else {
+               status = dwc2_schedule_periodic(hsotg, qh);
+               if (status == 0) {
+                       if (!hsotg->periodic_qh_count) {
+                               intr_mask = readl(hsotg->regs + GINTMSK);
+                               intr_mask |= GINTSTS_SOF;
+                               writel(intr_mask, hsotg->regs + GINTMSK);
+                       }
+                       hsotg->periodic_qh_count++;
+               }
+       }
+
+       return status;
+}
+
+/**
+ * dwc2_hcd_qh_unlink() - Removes a QH from either the non-periodic or periodic
+ * schedule. Memory is not freed.
+ *
+ * @hsotg: The HCD state structure
+ * @qh:    QH to remove from schedule
+ */
+void dwc2_hcd_qh_unlink(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)
+{
+       u32 intr_mask;
+
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       if (list_empty(&qh->qh_list_entry))
+               /* QH is not in a schedule */
+               return;
+
+       if (dwc2_qh_is_non_per(qh)) {
+               if (hsotg->non_periodic_qh_ptr == &qh->qh_list_entry)
+                       hsotg->non_periodic_qh_ptr =
+                                       hsotg->non_periodic_qh_ptr->next;
+               list_del_init(&qh->qh_list_entry);
+       } else {
+               dwc2_deschedule_periodic(hsotg, qh);
+               hsotg->periodic_qh_count--;
+               if (!hsotg->periodic_qh_count) {
+                       intr_mask = readl(hsotg->regs + GINTMSK);
+                       intr_mask &= ~GINTSTS_SOF;
+                       writel(intr_mask, hsotg->regs + GINTMSK);
+               }
+       }
+}
+
+/*
+ * Schedule the next continuing periodic split transfer
+ */
+static void dwc2_sched_periodic_split(struct dwc2_hsotg *hsotg,
+                                     struct dwc2_qh *qh, u16 frame_number,
+                                     int sched_next_periodic_split)
+{
+       u16 incr;
+
+       if (sched_next_periodic_split) {
+               qh->sched_frame = frame_number;
+               incr = dwc2_frame_num_inc(qh->start_split_frame, 1);
+               if (dwc2_frame_num_le(frame_number, incr)) {
+                       /*
+                        * Allow one frame to elapse after start split
+                        * microframe before scheduling complete split, but
+                        * DON'T if we are doing the next start split in the
+                        * same frame for an ISOC out
+                        */
+                       if (qh->ep_type != USB_ENDPOINT_XFER_ISOC ||
+                           qh->ep_is_in != 0) {
+                               qh->sched_frame =
+                                       dwc2_frame_num_inc(qh->sched_frame, 1);
+                       }
+               }
+       } else {
+               qh->sched_frame = dwc2_frame_num_inc(qh->start_split_frame,
+                                                    qh->interval);
+               if (dwc2_frame_num_le(qh->sched_frame, frame_number))
+                       qh->sched_frame = frame_number;
+               qh->sched_frame |= 0x7;
+               qh->start_split_frame = qh->sched_frame;
+       }
+}
+
+/*
+ * Deactivates a QH. For non-periodic QHs, removes the QH from the active
+ * non-periodic schedule. The QH is added to the inactive non-periodic
+ * schedule if any QTDs are still attached to the QH.
+ *
+ * For periodic QHs, the QH is removed from the periodic queued schedule. If
+ * there are any QTDs still attached to the QH, the QH is added to either the
+ * periodic inactive schedule or the periodic ready schedule and its next
+ * scheduled frame is calculated. The QH is placed in the ready schedule if
+ * the scheduled frame has been reached already. Otherwise it's placed in the
+ * inactive schedule. If there are no QTDs attached to the QH, the QH is
+ * completely removed from the periodic schedule.
+ */
+void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
+                           int sched_next_periodic_split)
+{
+       dev_vdbg(hsotg->dev, "%s()\n", __func__);
+
+       if (dwc2_qh_is_non_per(qh)) {
+               dwc2_hcd_qh_unlink(hsotg, qh);
+               if (!list_empty(&qh->qtd_list))
+                       /* Add back to inactive non-periodic schedule */
+                       dwc2_hcd_qh_add(hsotg, qh);
+       } else {
+               u16 frame_number = dwc2_hcd_get_frame_number(hsotg);
+
+               if (qh->do_split) {
+                       dwc2_sched_periodic_split(hsotg, qh, frame_number,
+                                                 sched_next_periodic_split);
+               } else {
+                       qh->sched_frame = dwc2_frame_num_inc(qh->sched_frame,
+                                                            qh->interval);
+                       if (dwc2_frame_num_le(qh->sched_frame, frame_number))
+                               qh->sched_frame = frame_number;
+               }
+
+               if (list_empty(&qh->qtd_list)) {
+                       dwc2_hcd_qh_unlink(hsotg, qh);
+               } else {
+                       /*
+                        * Remove from periodic_sched_queued and move to
+                        * appropriate queue
+                        */
+                       if (qh->sched_frame == frame_number)
+                               list_move(&qh->qh_list_entry,
+                                         &hsotg->periodic_sched_ready);
+                       else
+                               list_move(&qh->qh_list_entry,
+                                         &hsotg->periodic_sched_inactive);
+               }
+       }
+}
+
+/**
+ * dwc2_hcd_qtd_init() - Initializes a QTD structure
+ *
+ * @qtd: The QTD to initialize
+ * @urb: The associated URB
+ */
+void dwc2_hcd_qtd_init(struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb)
+{
+       qtd->urb = urb;
+       if (dwc2_hcd_get_pipe_type(&urb->pipe_info) ==
+                       USB_ENDPOINT_XFER_CONTROL) {
+               /*
+                * The only time the QTD data toggle is used is on the data
+                * phase of control transfers. This phase always starts with
+                * DATA1.
+                */
+               qtd->data_toggle = DWC2_HC_PID_DATA1;
+               qtd->control_phase = DWC2_CONTROL_SETUP;
+       }
+
+       /* Start split */
+       qtd->complete_split = 0;
+       qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL;
+       qtd->isoc_split_offset = 0;
+       qtd->in_process = 0;
+
+       /* Store the qtd ptr in the urb to reference the QTD */
+       urb->qtd = qtd;
+}
+
+/**
+ * dwc2_hcd_qtd_add() - Adds a QTD to the QTD-list of a QH
+ *
+ * @hsotg:        The DWC HCD structure
+ * @qtd:          The QTD to add
+ * @qh:           Out parameter to return queue head
+ * @atomic_alloc: Flag to do atomic alloc if needed
+ *
+ * Return: 0 if successful, negative error code otherwise
+ *
+ * Finds the correct QH to place the QTD into. If it does not find a QH, it
+ * will create a new QH. If the QH to which the QTD is added is not currently
+ * scheduled, it is placed into the proper schedule based on its EP type.
+ */
+int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
+                    struct dwc2_qh **qh, gfp_t mem_flags)
+{
+       struct dwc2_hcd_urb *urb = qtd->urb;
+       unsigned long flags;
+       int allocated = 0;
+       int retval = 0;
+
+       /*
+        * Get the QH which holds the QTD-list to insert to. Create QH if it
+        * doesn't exist.
+        */
+       if (*qh == NULL) {
+               *qh = dwc2_hcd_qh_create(hsotg, urb, mem_flags);
+               if (*qh == NULL)
+                       return -ENOMEM;
+               allocated = 1;
+       }
+
+       spin_lock_irqsave(&hsotg->lock, flags);
+       retval = dwc2_hcd_qh_add(hsotg, *qh);
+       if (retval && allocated) {
+               struct dwc2_qtd *qtd2, *qtd2_tmp;
+               struct dwc2_qh *qh_tmp = *qh;
+
+               *qh = NULL;
+               dwc2_hcd_qh_unlink(hsotg, qh_tmp);
+
+               /* Free each QTD in the QH's QTD list */
+               list_for_each_entry_safe(qtd2, qtd2_tmp, &qh_tmp->qtd_list,
+                                        qtd_list_entry)
+                       dwc2_hcd_qtd_unlink_and_free(hsotg, qtd2, qh_tmp);
+
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+               dwc2_hcd_qh_free(hsotg, qh_tmp);
+       } else {
+               qtd->qh = *qh;
+               list_add_tail(&qtd->qtd_list_entry, &(*qh)->qtd_list);
+               spin_unlock_irqrestore(&hsotg->lock, flags);
+       }
+
+       return retval;
+}
diff --git a/drivers/staging/dwc2/hw.h b/drivers/staging/dwc2/hw.h
new file mode 100644 (file)
index 0000000..382a1d7
--- /dev/null
@@ -0,0 +1,811 @@
+/*
+ * hw.h - DesignWare HS OTG Controller hardware definitions
+ *
+ * Copyright 2004-2013 Synopsys, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. 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.
+ * 3. The names of the above-listed copyright holders may not 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 the 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 OWNER 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 __DWC2_HW_H__
+#define __DWC2_HW_H__
+
+#define HSOTG_REG(x)   (x)
+
+#define GOTGCTL                                HSOTG_REG(0x000)
+#define GOTGCTL_CHIRPEN                        (1 << 27)
+#define GOTGCTL_MULT_VALID_BC_MASK     (0x1f << 22)
+#define GOTGCTL_MULT_VALID_BC_SHIFT    22
+#define GOTGCTL_OTGVER                 (1 << 20)
+#define GOTGCTL_BSESVLD                        (1 << 19)
+#define GOTGCTL_ASESVLD                        (1 << 18)
+#define GOTGCTL_DBNC_SHORT             (1 << 17)
+#define GOTGCTL_CONID_B                        (1 << 16)
+#define GOTGCTL_DEVHNPEN               (1 << 11)
+#define GOTGCTL_HSTSETHNPEN            (1 << 10)
+#define GOTGCTL_HNPREQ                 (1 << 9)
+#define GOTGCTL_HSTNEGSCS              (1 << 8)
+#define GOTGCTL_SESREQ                 (1 << 1)
+#define GOTGCTL_SESREQSCS              (1 << 0)
+
+#define GOTGINT                                HSOTG_REG(0x004)
+#define GOTGINT_DBNCE_DONE             (1 << 19)
+#define GOTGINT_A_DEV_TOUT_CHG         (1 << 18)
+#define GOTGINT_HST_NEG_DET            (1 << 17)
+#define GOTGINT_HST_NEG_SUC_STS_CHNG   (1 << 9)
+#define GOTGINT_SES_REQ_SUC_STS_CHNG   (1 << 8)
+#define GOTGINT_SES_END_DET            (1 << 2)
+
+#define GAHBCFG                                HSOTG_REG(0x008)
+#define GAHBCFG_AHB_SINGLE             (1 << 23)
+#define GAHBCFG_NOTI_ALL_DMA_WRIT      (1 << 22)
+#define GAHBCFG_REM_MEM_SUPP           (1 << 21)
+#define GAHBCFG_P_TXF_EMP_LVL          (1 << 8)
+#define GAHBCFG_NP_TXF_EMP_LVL         (1 << 7)
+#define GAHBCFG_DMA_EN                 (1 << 5)
+#define GAHBCFG_HBSTLEN_MASK           (0xf << 1)
+#define GAHBCFG_HBSTLEN_SHIFT          1
+#define GAHBCFG_HBSTLEN_SINGLE                 (0 << 1)
+#define GAHBCFG_HBSTLEN_INCR                   (1 << 1)
+#define GAHBCFG_HBSTLEN_INCR4                  (3 << 1)
+#define GAHBCFG_HBSTLEN_INCR8                  (5 << 1)
+#define GAHBCFG_HBSTLEN_INCR16                 (7 << 1)
+#define GAHBCFG_GLBL_INTR_EN           (1 << 0)
+
+#define GUSBCFG                                HSOTG_REG(0x00C)
+#define GUSBCFG_FORCEDEVMODE           (1 << 30)
+#define GUSBCFG_FORCEHOSTMODE          (1 << 29)
+#define GUSBCFG_TXENDDELAY             (1 << 28)
+#define GUSBCFG_ICTRAFFICPULLREMOVE    (1 << 27)
+#define GUSBCFG_ICUSBCAP               (1 << 26)
+#define GUSBCFG_ULPI_INT_PROT_DIS      (1 << 25)
+#define GUSBCFG_INDICATORPASSTHROUGH   (1 << 24)
+#define GUSBCFG_INDICATORCOMPLEMENT    (1 << 23)
+#define GUSBCFG_TERMSELDLPULSE         (1 << 22)
+#define GUSBCFG_ULPI_INT_VBUS_IND      (1 << 21)
+#define GUSBCFG_ULPI_EXT_VBUS_DRV      (1 << 20)
+#define GUSBCFG_ULPI_CLK_SUSP_M                (1 << 19)
+#define GUSBCFG_ULPI_AUTO_RES          (1 << 18)
+#define GUSBCFG_ULPI_FS_LS             (1 << 17)
+#define GUSBCFG_OTG_UTMI_FS_SEL                (1 << 16)
+#define GUSBCFG_PHY_LP_CLK_SEL         (1 << 15)
+#define GUSBCFG_USBTRDTIM_MASK         (0xf << 10)
+#define GUSBCFG_USBTRDTIM_SHIFT                10
+#define GUSBCFG_HNPCAP                 (1 << 9)
+#define GUSBCFG_SRPCAP                 (1 << 8)
+#define GUSBCFG_DDRSEL                 (1 << 7)
+#define GUSBCFG_PHYSEL                 (1 << 6)
+#define GUSBCFG_FSINTF                 (1 << 5)
+#define GUSBCFG_ULPI_UTMI_SEL          (1 << 4)
+#define GUSBCFG_PHYIF16                        (1 << 3)
+#define GUSBCFG_TOUTCAL_MASK           (0x7 << 0)
+#define GUSBCFG_TOUTCAL_SHIFT          0
+#define GUSBCFG_TOUTCAL_LIMIT          0x7
+#define GUSBCFG_TOUTCAL(_x)            ((_x) << 0)
+
+#define GRSTCTL                                HSOTG_REG(0x010)
+#define GRSTCTL_AHBIDLE                        (1 << 31)
+#define GRSTCTL_DMAREQ                 (1 << 30)
+#define GRSTCTL_TXFNUM_MASK            (0x1f << 6)
+#define GRSTCTL_TXFNUM_SHIFT           6
+#define GRSTCTL_TXFNUM_LIMIT           0x1f
+#define GRSTCTL_TXFNUM(_x)             ((_x) << 6)
+#define GRSTCTL_TXFFLSH                        (1 << 5)
+#define GRSTCTL_RXFFLSH                        (1 << 4)
+#define GRSTCTL_IN_TKNQ_FLSH           (1 << 3)
+#define GRSTCTL_FRMCNTRRST             (1 << 2)
+#define GRSTCTL_HSFTRST                        (1 << 1)
+#define GRSTCTL_CSFTRST                        (1 << 0)
+
+#define GINTSTS                                HSOTG_REG(0x014)
+#define GINTMSK                                HSOTG_REG(0x018)
+#define GINTSTS_WKUPINT                        (1 << 31)
+#define GINTSTS_SESSREQINT             (1 << 30)
+#define GINTSTS_DISCONNINT             (1 << 29)
+#define GINTSTS_CONIDSTSCHNG           (1 << 28)
+#define GINTSTS_LPMTRANRCVD            (1 << 27)
+#define GINTSTS_PTXFEMP                        (1 << 26)
+#define GINTSTS_HCHINT                 (1 << 25)
+#define GINTSTS_PRTINT                 (1 << 24)
+#define GINTSTS_RESETDET               (1 << 23)
+#define GINTSTS_FET_SUSP               (1 << 22)
+#define GINTSTS_INCOMPL_IP             (1 << 21)
+#define GINTSTS_INCOMPL_SOIN           (1 << 20)
+#define GINTSTS_OEPINT                 (1 << 19)
+#define GINTSTS_IEPINT                 (1 << 18)
+#define GINTSTS_EPMIS                  (1 << 17)
+#define GINTSTS_RESTOREDONE            (1 << 16)
+#define GINTSTS_EOPF                   (1 << 15)
+#define GINTSTS_ISOUTDROP              (1 << 14)
+#define GINTSTS_ENUMDONE               (1 << 13)
+#define GINTSTS_USBRST                 (1 << 12)
+#define GINTSTS_USBSUSP                        (1 << 11)
+#define GINTSTS_ERLYSUSP               (1 << 10)
+#define GINTSTS_I2CINT                 (1 << 9)
+#define GINTSTS_ULPI_CK_INT            (1 << 8)
+#define GINTSTS_GOUTNAKEFF             (1 << 7)
+#define GINTSTS_GINNAKEFF              (1 << 6)
+#define GINTSTS_NPTXFEMP               (1 << 5)
+#define GINTSTS_RXFLVL                 (1 << 4)
+#define GINTSTS_SOF                    (1 << 3)
+#define GINTSTS_OTGINT                 (1 << 2)
+#define GINTSTS_MODEMIS                        (1 << 1)
+#define GINTSTS_CURMODE_HOST           (1 << 0)
+
+#define GRXSTSR                                HSOTG_REG(0x01C)
+#define GRXSTSP                                HSOTG_REG(0x020)
+#define GRXSTS_FN_MASK                 (0x7f << 25)
+#define GRXSTS_FN_SHIFT                        25
+#define GRXSTS_PKTSTS_MASK             (0xf << 17)
+#define GRXSTS_PKTSTS_SHIFT            17
+#define GRXSTS_PKTSTS_GLOBALOUTNAK             (1 << 17)
+#define GRXSTS_PKTSTS_OUTRX                    (2 << 17)
+#define GRXSTS_PKTSTS_HCHIN                    (2 << 17)
+#define GRXSTS_PKTSTS_OUTDONE                  (3 << 17)
+#define GRXSTS_PKTSTS_HCHIN_XFER_COMP          (3 << 17)
+#define GRXSTS_PKTSTS_SETUPDONE                        (4 << 17)
+#define GRXSTS_PKTSTS_DATATOGGLEERR            (5 << 17)
+#define GRXSTS_PKTSTS_SETUPRX                  (6 << 17)
+#define GRXSTS_PKTSTS_HCHHALTED                        (7 << 17)
+#define GRXSTS_HCHNUM_MASK             (0xf << 0)
+#define GRXSTS_HCHNUM_SHIFT            0
+#define GRXSTS_DPID_MASK               (0x3 << 15)
+#define GRXSTS_DPID_SHIFT              15
+#define GRXSTS_BYTECNT_MASK            (0x7ff << 4)
+#define GRXSTS_BYTECNT_SHIFT           4
+#define GRXSTS_EPNUM_MASK              (0xf << 0)
+#define GRXSTS_EPNUM_SHIFT             0
+
+#define GRXFSIZ                                HSOTG_REG(0x024)
+
+#define GNPTXFSIZ                      HSOTG_REG(0x028)
+#define GNPTXFSIZ_NP_TXF_DEP_MASK      (0xffff << 16)
+#define GNPTXFSIZ_NP_TXF_DEP_SHIFT     16
+#define GNPTXFSIZ_NP_TXF_DEP_LIMIT     0xffff
+#define GNPTXFSIZ_NP_TXF_DEP(_x)       ((_x) << 16)
+#define GNPTXFSIZ_NP_TXF_ST_ADDR_MASK  (0xffff << 0)
+#define GNPTXFSIZ_NP_TXF_ST_ADDR_SHIFT 0
+#define GNPTXFSIZ_NP_TXF_ST_ADDR_LIMIT 0xffff
+#define GNPTXFSIZ_NP_TXF_ST_ADDR(_x)   ((_x) << 0)
+
+#define GNPTXSTS                       HSOTG_REG(0x02C)
+#define GNPTXSTS_NP_TXQ_TOP_MASK               (0x7f << 24)
+#define GNPTXSTS_NP_TXQ_TOP_SHIFT              24
+#define GNPTXSTS_NP_TXQ_SPC_AVAIL_MASK         (0xff << 16)
+#define GNPTXSTS_NP_TXQ_SPC_AVAIL_SHIFT                16
+#define GNPTXSTS_NP_TXQ_SPC_AVAIL_GET(_v)      (((_v) >> 16) & 0xff)
+#define GNPTXSTS_NP_TXF_SPC_AVAIL_MASK         (0xffff << 0)
+#define GNPTXSTS_NP_TXF_SPC_AVAIL_SHIFT                0
+#define GNPTXSTS_NP_TXF_SPC_AVAIL_GET(_v)      (((_v) >> 0) & 0xffff)
+
+#define GI2CCTL                                HSOTG_REG(0x0030)
+#define GI2CCTL_BSYDNE                 (1 << 31)
+#define GI2CCTL_RW                     (1 << 30)
+#define GI2CCTL_I2CDATSE0              (1 << 28)
+#define GI2CCTL_I2CDEVADDR_MASK                (0x3 << 26)
+#define GI2CCTL_I2CDEVADDR_SHIFT       26
+#define GI2CCTL_I2CSUSPCTL             (1 << 25)
+#define GI2CCTL_ACK                    (1 << 24)
+#define GI2CCTL_I2CEN                  (1 << 23)
+#define GI2CCTL_ADDR_MASK              (0x7f << 16)
+#define GI2CCTL_ADDR_SHIFT             16
+#define GI2CCTL_REGADDR_MASK           (0xff << 8)
+#define GI2CCTL_REGADDR_SHIFT          8
+#define GI2CCTL_RWDATA_MASK            (0xff << 0)
+#define GI2CCTL_RWDATA_SHIFT           0
+
+#define GPVNDCTL                       HSOTG_REG(0x0034)
+#define GGPIO                          HSOTG_REG(0x0038)
+#define GUID                           HSOTG_REG(0x003c)
+#define GSNPSID                                HSOTG_REG(0x0040)
+#define GHWCFG1                                HSOTG_REG(0x0044)
+
+#define GHWCFG2                                HSOTG_REG(0x0048)
+#define GHWCFG2_OTG_ENABLE_IC_USB              (1 << 31)
+#define GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK         (0x1f << 26)
+#define GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT                26
+#define GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK     (0x3 << 24)
+#define GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT    24
+#define GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK       (0x3 << 22)
+#define GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT      22
+#define GHWCFG2_MULTI_PROC_INT                 (1 << 20)
+#define GHWCFG2_DYNAMIC_FIFO                   (1 << 19)
+#define GHWCFG2_PERIO_EP_SUPPORTED             (1 << 18)
+#define GHWCFG2_NUM_HOST_CHAN_MASK             (0xf << 14)
+#define GHWCFG2_NUM_HOST_CHAN_SHIFT            14
+#define GHWCFG2_NUM_DEV_EP_MASK                        (0xf << 10)
+#define GHWCFG2_NUM_DEV_EP_SHIFT               10
+#define GHWCFG2_FS_PHY_TYPE_MASK               (0x3 << 8)
+#define GHWCFG2_FS_PHY_TYPE_SHIFT              8
+#define GHWCFG2_FS_PHY_TYPE_NOT_SUPPORTED              (0 << 8)
+#define GHWCFG2_FS_PHY_TYPE_DEDICATED                  (1 << 8)
+#define GHWCFG2_FS_PHY_TYPE_SHARED_UTMI                        (2 << 8)
+#define GHWCFG2_FS_PHY_TYPE_SHARED_ULPI                        (3 << 8)
+#define GHWCFG2_HS_PHY_TYPE_MASK               (0x3 << 6)
+#define GHWCFG2_HS_PHY_TYPE_SHIFT              6
+#define GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED              (0 << 6)
+#define GHWCFG2_HS_PHY_TYPE_UTMI                       (1 << 6)
+#define GHWCFG2_HS_PHY_TYPE_ULPI                       (2 << 6)
+#define GHWCFG2_HS_PHY_TYPE_UTMI_ULPI                  (3 << 6)
+#define GHWCFG2_POINT2POINT                    (1 << 5)
+#define GHWCFG2_ARCHITECTURE_MASK              (0x3 << 3)
+#define GHWCFG2_ARCHITECTURE_SHIFT             3
+#define GHWCFG2_SLAVE_ONLY_ARCH                                (0 << 3)
+#define GHWCFG2_EXT_DMA_ARCH                           (1 << 3)
+#define GHWCFG2_INT_DMA_ARCH                           (2 << 3)
+#define GHWCFG2_OP_MODE_MASK                   (0x7 << 0)
+#define GHWCFG2_OP_MODE_SHIFT                  0
+#define GHWCFG2_OP_MODE_HNP_SRP_CAPABLE                        (0 << 0)
+#define GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE               (1 << 0)
+#define GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE             (2 << 0)
+#define GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE             (3 << 0)
+#define GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE          (4 << 0)
+#define GHWCFG2_OP_MODE_SRP_CAPABLE_HOST               (5 << 0)
+#define GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST            (6 << 0)
+#define GHWCFG2_OP_MODE_UNDEFINED                      (7 << 0)
+
+#define GHWCFG3                                HSOTG_REG(0x004c)
+#define GHWCFG3_DFIFO_DEPTH_MASK               (0xffff << 16)
+#define GHWCFG3_DFIFO_DEPTH_SHIFT              16
+#define GHWCFG3_OTG_LPM_EN                     (1 << 15)
+#define GHWCFG3_BC_SUPPORT                     (1 << 14)
+#define GHWCFG3_OTG_ENABLE_HSIC                        (1 << 13)
+#define GHWCFG3_ADP_SUPP                       (1 << 12)
+#define GHWCFG3_SYNCH_RESET_TYPE               (1 << 11)
+#define GHWCFG3_OPTIONAL_FEATURES              (1 << 10)
+#define GHWCFG3_VENDOR_CTRL_IF                 (1 << 9)
+#define GHWCFG3_I2C                            (1 << 8)
+#define GHWCFG3_OTG_FUNC                       (1 << 7)
+#define GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK    (0x7 << 4)
+#define GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT   4
+#define GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK      (0xf << 0)
+#define GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT     0
+
+#define GHWCFG4                                HSOTG_REG(0x0050)
+#define GHWCFG4_DESC_DMA_DYN                   (1 << 31)
+#define GHWCFG4_DESC_DMA                       (1 << 30)
+#define GHWCFG4_NUM_IN_EPS_MASK                        (0xf << 26)
+#define GHWCFG4_NUM_IN_EPS_SHIFT               26
+#define GHWCFG4_DED_FIFO_EN                    (1 << 25)
+#define GHWCFG4_SESSION_END_FILT_EN            (1 << 24)
+#define GHWCFG4_B_VALID_FILT_EN                        (1 << 23)
+#define GHWCFG4_A_VALID_FILT_EN                        (1 << 22)
+#define GHWCFG4_VBUS_VALID_FILT_EN             (1 << 21)
+#define GHWCFG4_IDDIG_FILT_EN                  (1 << 20)
+#define GHWCFG4_NUM_DEV_MODE_CTRL_EP_MASK      (0xf << 16)
+#define GHWCFG4_NUM_DEV_MODE_CTRL_EP_SHIFT     16
+#define GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK       (0x3 << 14)
+#define GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT      14
+#define GHWCFG4_XHIBER                         (1 << 7)
+#define GHWCFG4_HIBER                          (1 << 6)
+#define GHWCFG4_MIN_AHB_FREQ                   (1 << 5)
+#define GHWCFG4_POWER_OPTIMIZ                  (1 << 4)
+#define GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK       (0xf << 0)
+#define GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT      0
+
+#define GLPMCFG                                HSOTG_REG(0x0054)
+#define GLPMCFG_INV_SEL_HSIC           (1 << 31)
+#define GLPMCFG_HSIC_CONNECT           (1 << 30)
+#define GLPMCFG_RETRY_COUNT_STS_MASK   (0x7 << 25)
+#define GLPMCFG_RETRY_COUNT_STS_SHIFT  25
+#define GLPMCFG_SEND_LPM               (1 << 24)
+#define GLPMCFG_RETRY_COUNT_MASK       (0x7 << 21)
+#define GLPMCFG_RETRY_COUNT_SHIFT      21
+#define GLPMCFG_LPM_CHAN_INDEX_MASK    (0xf << 17)
+#define GLPMCFG_LPM_CHAN_INDEX_SHIFT   17
+#define GLPMCFG_SLEEP_STATE_RESUMEOK   (1 << 16)
+#define GLPMCFG_PRT_SLEEP_STS          (1 << 15)
+#define GLPMCFG_LPM_RESP_MASK          (0x3 << 13)
+#define GLPMCFG_LPM_RESP_SHIFT         13
+#define GLPMCFG_HIRD_THRES_MASK                (0x1f << 8)
+#define GLPMCFG_HIRD_THRES_SHIFT       8
+#define GLPMCFG_HIRD_THRES_EN                  (0x10 << 8)
+#define GLPMCFG_EN_UTMI_SLEEP          (1 << 7)
+#define GLPMCFG_REM_WKUP_EN            (1 << 6)
+#define GLPMCFG_HIRD_MASK              (0xf << 2)
+#define GLPMCFG_HIRD_SHIFT             2
+#define GLPMCFG_APPL_RESP              (1 << 1)
+#define GLPMCFG_LPM_CAP_EN             (1 << 0)
+
+#define GPWRDN                         HSOTG_REG(0x0058)
+#define GPWRDN_MULT_VAL_ID_BC_MASK     (0x1f << 24)
+#define GPWRDN_MULT_VAL_ID_BC_SHIFT    24
+#define GPWRDN_ADP_INT                 (1 << 23)
+#define GPWRDN_BSESSVLD                        (1 << 22)
+#define GPWRDN_IDSTS                   (1 << 21)
+#define GPWRDN_LINESTATE_MASK          (0x3 << 19)
+#define GPWRDN_LINESTATE_SHIFT         19
+#define GPWRDN_STS_CHGINT_MSK          (1 << 18)
+#define GPWRDN_STS_CHGINT              (1 << 17)
+#define GPWRDN_SRP_DET_MSK             (1 << 16)
+#define GPWRDN_SRP_DET                 (1 << 15)
+#define GPWRDN_CONNECT_DET_MSK         (1 << 14)
+#define GPWRDN_CONNECT_DET             (1 << 13)
+#define GPWRDN_DISCONN_DET_MSK         (1 << 12)
+#define GPWRDN_DISCONN_DET             (1 << 11)
+#define GPWRDN_RST_DET_MSK             (1 << 10)
+#define GPWRDN_RST_DET                 (1 << 9)
+#define GPWRDN_LNSTSCHG_MSK            (1 << 8)
+#define GPWRDN_LNSTSCHG                        (1 << 7)
+#define GPWRDN_DIS_VBUS                        (1 << 6)
+#define GPWRDN_PWRDNSWTCH              (1 << 5)
+#define GPWRDN_PWRDNRSTN               (1 << 4)
+#define GPWRDN_PWRDNCLMP               (1 << 3)
+#define GPWRDN_RESTORE                 (1 << 2)
+#define GPWRDN_PMUACTV                 (1 << 1)
+#define GPWRDN_PMUINTSEL               (1 << 0)
+
+#define GDFIFOCFG                      HSOTG_REG(0x005c)
+#define GDFIFOCFG_EPINFOBASE_MASK      (0xffff << 16)
+#define GDFIFOCFG_EPINFOBASE_SHIFT     16
+#define GDFIFOCFG_GDFIFOCFG_MASK       (0xffff << 0)
+#define GDFIFOCFG_GDFIFOCFG_SHIFT      0
+
+#define ADPCTL                         HSOTG_REG(0x0060)
+#define ADPCTL_AR_MASK                 (0x3 << 27)
+#define ADPCTL_AR_SHIFT                        27
+#define ADPCTL_ADP_TMOUT_INT_MSK       (1 << 26)
+#define ADPCTL_ADP_SNS_INT_MSK         (1 << 25)
+#define ADPCTL_ADP_PRB_INT_MSK         (1 << 24)
+#define ADPCTL_ADP_TMOUT_INT           (1 << 23)
+#define ADPCTL_ADP_SNS_INT             (1 << 22)
+#define ADPCTL_ADP_PRB_INT             (1 << 21)
+#define ADPCTL_ADPENA                  (1 << 20)
+#define ADPCTL_ADPRES                  (1 << 19)
+#define ADPCTL_ENASNS                  (1 << 18)
+#define ADPCTL_ENAPRB                  (1 << 17)
+#define ADPCTL_RTIM_MASK               (0x7ff << 6)
+#define ADPCTL_RTIM_SHIFT              6
+#define ADPCTL_PRB_PER_MASK            (0x3 << 4)
+#define ADPCTL_PRB_PER_SHIFT           4
+#define ADPCTL_PRB_DELTA_MASK          (0x3 << 2)
+#define ADPCTL_PRB_DELTA_SHIFT         2
+#define ADPCTL_PRB_DSCHRG_MASK         (0x3 << 0)
+#define ADPCTL_PRB_DSCHRG_SHIFT                0
+
+#define HPTXFSIZ                       HSOTG_REG(0x100)
+
+#define DPTXFSIZN(_a)                  HSOTG_REG(0x104 + (((_a) - 1) * 4))
+#define DPTXFSIZN_DP_TXF_SIZE_MASK     (0xffff << 16)
+#define DPTXFSIZN_DP_TXF_SIZE_SHIFT    16
+#define DPTXFSIZN_DP_TXF_SIZE_GET(_v)  (((_v) >> 16) & 0xffff)
+#define DPTXFSIZN_DP_TXF_SIZE_LIMIT    0xffff
+#define DPTXFSIZN_DP_TXF_SIZE(_x)      ((_x) << 16)
+#define DPTXFSIZN_DP_TXF_ST_ADDR_MASK  (0xffff << 0)
+#define DPTXFSIZN_DP_TXF_ST_ADDR_SHIFT 0
+
+#define FIFOSIZE_DEPTH_MASK            (0xffff << 16)
+#define FIFOSIZE_DEPTH_SHIFT           16
+#define FIFOSIZE_STARTADDR_MASK                (0xffff << 0)
+#define FIFOSIZE_STARTADDR_SHIFT       0
+
+/* Device mode registers */
+
+#define DCFG                           HSOTG_REG(0x800)
+#define DCFG_EPMISCNT_MASK             (0x1f << 18)
+#define DCFG_EPMISCNT_SHIFT            18
+#define DCFG_EPMISCNT_LIMIT            0x1f
+#define DCFG_EPMISCNT(_x)              ((_x) << 18)
+#define DCFG_PERFRINT_MASK             (0x3 << 11)
+#define DCFG_PERFRINT_SHIFT            11
+#define DCFG_PERFRINT_LIMIT            0x3
+#define DCFG_PERFRINT(_x)              ((_x) << 11)
+#define DCFG_DEVADDR_MASK              (0x7f << 4)
+#define DCFG_DEVADDR_SHIFT             4
+#define DCFG_DEVADDR_LIMIT             0x7f
+#define DCFG_DEVADDR(_x)               ((_x) << 4)
+#define DCFG_NZ_STS_OUT_HSHK           (1 << 2)
+#define DCFG_DEVSPD_MASK               (0x3 << 0)
+#define DCFG_DEVSPD_SHIFT              0
+#define DCFG_DEVSPD_HS                         (0 << 0)
+#define DCFG_DEVSPD_FS                         (1 << 0)
+#define DCFG_DEVSPD_LS                         (2 << 0)
+#define DCFG_DEVSPD_FS48                       (3 << 0)
+
+#define DCTL                           HSOTG_REG(0x804)
+#define DCTL_PWRONPRGDONE              (1 << 11)
+#define DCTL_CGOUTNAK                  (1 << 10)
+#define DCTL_SGOUTNAK                  (1 << 9)
+#define DCTL_CGNPINNAK                 (1 << 8)
+#define DCTL_SGNPINNAK                 (1 << 7)
+#define DCTL_TSTCTL_MASK               (0x7 << 4)
+#define DCTL_TSTCTL_SHIFT              4
+#define DCTL_GOUTNAKSTS                        (1 << 3)
+#define DCTL_GNPINNAKSTS               (1 << 2)
+#define DCTL_SFTDISCON                 (1 << 1)
+#define DCTL_RMTWKUPSIG                        (1 << 0)
+
+#define DSTS                           HSOTG_REG(0x808)
+#define DSTS_SOFFN_MASK                        (0x3fff << 8)
+#define DSTS_SOFFN_SHIFT               8
+#define DSTS_SOFFN_LIMIT               0x3fff
+#define DSTS_SOFFN(_x)                 ((_x) << 8)
+#define DSTS_ERRATICERR                        (1 << 3)
+#define DSTS_ENUMSPD_MASK              (0x3 << 1)
+#define DSTS_ENUMSPD_SHIFT             1
+#define DSTS_ENUMSPD_HS                                (0 << 1)
+#define DSTS_ENUMSPD_FS                                (1 << 1)
+#define DSTS_ENUMSPD_LS                                (2 << 1)
+#define DSTS_ENUMSPD_FS48                      (3 << 1)
+#define DSTS_SUSPSTS                   (1 << 0)
+
+#define DIEPMSK                                HSOTG_REG(0x810)
+#define DIEPMSK_TXFIFOEMPTY            (1 << 7)
+#define DIEPMSK_INEPNAKEFFMSK          (1 << 6)
+#define DIEPMSK_INTKNEPMISMSK          (1 << 5)
+#define DIEPMSK_INTKNTXFEMPMSK         (1 << 4)
+#define DIEPMSK_TIMEOUTMSK             (1 << 3)
+#define DIEPMSK_AHBERRMSK              (1 << 2)
+#define DIEPMSK_EPDISBLDMSK            (1 << 1)
+#define DIEPMSK_XFERCOMPLMSK           (1 << 0)
+
+#define DOEPMSK                                HSOTG_REG(0x814)
+#define DOEPMSK_BACK2BACKSETUP         (1 << 6)
+#define DOEPMSK_OUTTKNEPDISMSK         (1 << 4)
+#define DOEPMSK_SETUPMSK               (1 << 3)
+#define DOEPMSK_AHBERRMSK              (1 << 2)
+#define DOEPMSK_EPDISBLDMSK            (1 << 1)
+#define DOEPMSK_XFERCOMPLMSK           (1 << 0)
+
+#define DAINT                          HSOTG_REG(0x818)
+#define DAINTMSK                       HSOTG_REG(0x81C)
+#define DAINT_OUTEP_SHIFT              16
+#define DAINT_OUTEP(_x)                        (1 << ((_x) + 16))
+#define DAINT_INEP(_x)                 (1 << (_x))
+
+#define DTKNQR1                                HSOTG_REG(0x820)
+#define DTKNQR2                                HSOTG_REG(0x824)
+#define DTKNQR3                                HSOTG_REG(0x830)
+#define DTKNQR4                                HSOTG_REG(0x834)
+
+#define DVBUSDIS                       HSOTG_REG(0x828)
+#define DVBUSPULSE                     HSOTG_REG(0x82C)
+
+#define DIEPCTL0                       HSOTG_REG(0x900)
+#define DIEPCTL(_a)                    HSOTG_REG(0x900 + ((_a) * 0x20))
+
+#define DOEPCTL0                       HSOTG_REG(0xB00)
+#define DOEPCTL(_a)                    HSOTG_REG(0xB00 + ((_a) * 0x20))
+
+/* EP0 specialness:
+ * bits[29..28] - reserved (no SetD0PID, SetD1PID)
+ * bits[25..22] - should always be zero, this isn't a periodic endpoint
+ * bits[10..0]  - MPS setting different for EP0
+ */
+#define D0EPCTL_MPS_MASK               (0x3 << 0)
+#define D0EPCTL_MPS_SHIFT              0
+#define D0EPCTL_MPS_64                         (0 << 0)
+#define D0EPCTL_MPS_32                         (1 << 0)
+#define D0EPCTL_MPS_16                         (2 << 0)
+#define D0EPCTL_MPS_8                          (3 << 0)
+
+#define DXEPCTL_EPENA                  (1 << 31)
+#define DXEPCTL_EPDIS                  (1 << 30)
+#define DXEPCTL_SETD1PID               (1 << 29)
+#define DXEPCTL_SETODDFR               (1 << 29)
+#define DXEPCTL_SETD0PID               (1 << 28)
+#define DXEPCTL_SETEVENFR              (1 << 28)
+#define DXEPCTL_SNAK                   (1 << 27)
+#define DXEPCTL_CNAK                   (1 << 26)
+#define DXEPCTL_TXFNUM_MASK            (0xf << 22)
+#define DXEPCTL_TXFNUM_SHIFT           22
+#define DXEPCTL_TXFNUM_LIMIT           0xf
+#define DXEPCTL_TXFNUM(_x)             ((_x) << 22)
+#define DXEPCTL_STALL                  (1 << 21)
+#define DXEPCTL_SNP                    (1 << 20)
+#define DXEPCTL_EPTYPE_MASK            (0x3 << 18)
+#define DXEPCTL_EPTYPE_SHIFT           18
+#define DXEPCTL_EPTYPE_CONTROL                 (0 << 18)
+#define DXEPCTL_EPTYPE_ISO                     (1 << 18)
+#define DXEPCTL_EPTYPE_BULK                    (2 << 18)
+#define DXEPCTL_EPTYPE_INTTERUPT               (3 << 18)
+#define DXEPCTL_NAKSTS                 (1 << 17)
+#define DXEPCTL_DPID                   (1 << 16)
+#define DXEPCTL_EOFRNUM                        (1 << 16)
+#define DXEPCTL_USBACTEP               (1 << 15)
+#define DXEPCTL_NEXTEP_MASK            (0xf << 11)
+#define DXEPCTL_NEXTEP_SHIFT           11
+#define DXEPCTL_NEXTEP_LIMIT           0xf
+#define DXEPCTL_NEXTEP(_x)             ((_x) << 11)
+#define DXEPCTL_MPS_MASK               (0x7ff << 0)
+#define DXEPCTL_MPS_SHIFT              0
+#define DXEPCTL_MPS_LIMIT              0x7ff
+#define DXEPCTL_MPS(_x)                        ((_x) << 0)
+
+#define DIEPINT(_a)                    HSOTG_REG(0x908 + ((_a) * 0x20))
+#define DOEPINT(_a)                    HSOTG_REG(0xB08 + ((_a) * 0x20))
+#define DXEPINT_INEPNAKEFF             (1 << 6)
+#define DXEPINT_BACK2BACKSETUP         (1 << 6)
+#define DXEPINT_INTKNEPMIS             (1 << 5)
+#define DXEPINT_INTKNTXFEMP            (1 << 4)
+#define DXEPINT_OUTTKNEPDIS            (1 << 4)
+#define DXEPINT_TIMEOUT                        (1 << 3)
+#define DXEPINT_SETUP                  (1 << 3)
+#define DXEPINT_AHBERR                 (1 << 2)
+#define DXEPINT_EPDISBLD               (1 << 1)
+#define DXEPINT_XFERCOMPL              (1 << 0)
+
+#define DIEPTSIZ0                      HSOTG_REG(0x910)
+#define DIEPTSIZ0_PKTCNT_MASK          (0x3 << 19)
+#define DIEPTSIZ0_PKTCNT_SHIFT         19
+#define DIEPTSIZ0_PKTCNT_LIMIT         0x3
+#define DIEPTSIZ0_PKTCNT(_x)           ((_x) << 19)
+#define DIEPTSIZ0_XFERSIZE_MASK                (0x7f << 0)
+#define DIEPTSIZ0_XFERSIZE_SHIFT       0
+#define DIEPTSIZ0_XFERSIZE_LIMIT       0x7f
+#define DIEPTSIZ0_XFERSIZE(_x)         ((_x) << 0)
+
+#define DOEPTSIZ0                      HSOTG_REG(0xB10)
+#define DOEPTSIZ0_SUPCNT_MASK          (0x3 << 29)
+#define DOEPTSIZ0_SUPCNT_SHIFT         29
+#define DOEPTSIZ0_SUPCNT_LIMIT         0x3
+#define DOEPTSIZ0_SUPCNT(_x)           ((_x) << 29)
+#define DOEPTSIZ0_PKTCNT               (1 << 19)
+#define DOEPTSIZ0_XFERSIZE_MASK                (0x7f << 0)
+#define DOEPTSIZ0_XFERSIZE_SHIFT       0
+
+#define DIEPTSIZ(_a)                   HSOTG_REG(0x910 + ((_a) * 0x20))
+#define DOEPTSIZ(_a)                   HSOTG_REG(0xB10 + ((_a) * 0x20))
+#define DXEPTSIZ_MC_MASK               (0x3 << 29)
+#define DXEPTSIZ_MC_SHIFT              29
+#define DXEPTSIZ_MC_LIMIT              0x3
+#define DXEPTSIZ_MC(_x)                        ((_x) << 29)
+#define DXEPTSIZ_PKTCNT_MASK           (0x3ff << 19)
+#define DXEPTSIZ_PKTCNT_SHIFT          19
+#define DXEPTSIZ_PKTCNT_LIMIT          0x3ff
+#define DXEPTSIZ_PKTCNT_GET(_v)                (((_v) >> 19) & 0x3ff)
+#define DXEPTSIZ_PKTCNT(_x)            ((_x) << 19)
+#define DXEPTSIZ_XFERSIZE_MASK         (0x7ffff << 0)
+#define DXEPTSIZ_XFERSIZE_SHIFT                0
+#define DXEPTSIZ_XFERSIZE_LIMIT                0x7ffff
+#define DXEPTSIZ_XFERSIZE_GET(_v)      (((_v) >> 0) & 0x7ffff)
+#define DXEPTSIZ_XFERSIZE(_x)          ((_x) << 0)
+
+#define DIEPDMA(_a)                    HSOTG_REG(0x914 + ((_a) * 0x20))
+#define DOEPDMA(_a)                    HSOTG_REG(0xB14 + ((_a) * 0x20))
+
+#define DTXFSTS(_a)                    HSOTG_REG(0x918 + ((_a) * 0x20))
+
+#define PCGCTL                         HSOTG_REG(0x0e00)
+#define PCGCTL_IF_DEV_MODE             (1 << 31)
+#define PCGCTL_P2HD_PRT_SPD_MASK       (0x3 << 29)
+#define PCGCTL_P2HD_PRT_SPD_SHIFT      29
+#define PCGCTL_P2HD_DEV_ENUM_SPD_MASK  (0x3 << 27)
+#define PCGCTL_P2HD_DEV_ENUM_SPD_SHIFT 27
+#define PCGCTL_MAC_DEV_ADDR_MASK       (0x7f << 20)
+#define PCGCTL_MAC_DEV_ADDR_SHIFT      20
+#define PCGCTL_MAX_TERMSEL             (1 << 19)
+#define PCGCTL_MAX_XCVRSELECT_MASK     (0x3 << 17)
+#define PCGCTL_MAX_XCVRSELECT_SHIFT    17
+#define PCGCTL_PORT_POWER              (1 << 16)
+#define PCGCTL_PRT_CLK_SEL_MASK                (0x3 << 14)
+#define PCGCTL_PRT_CLK_SEL_SHIFT       14
+#define PCGCTL_ESS_REG_RESTORED                (1 << 13)
+#define PCGCTL_EXTND_HIBER_SWITCH      (1 << 12)
+#define PCGCTL_EXTND_HIBER_PWRCLMP     (1 << 11)
+#define PCGCTL_ENBL_EXTND_HIBER                (1 << 10)
+#define PCGCTL_RESTOREMODE             (1 << 9)
+#define PCGCTL_RESETAFTSUSP            (1 << 8)
+#define PCGCTL_DEEP_SLEEP              (1 << 7)
+#define PCGCTL_PHY_IN_SLEEP            (1 << 6)
+#define PCGCTL_ENBL_SLEEP_GATING       (1 << 5)
+#define PCGCTL_RSTPDWNMODULE           (1 << 3)
+#define PCGCTL_PWRCLMP                 (1 << 2)
+#define PCGCTL_GATEHCLK                        (1 << 1)
+#define PCGCTL_STOPPCLK                        (1 << 0)
+
+#define EPFIFO(_a)                     HSOTG_REG(0x1000 + ((_a) * 0x1000))
+
+/* Host Mode Registers */
+
+#define HCFG                           HSOTG_REG(0x0400)
+#define HCFG_MODECHTIMEN               (1 << 31)
+#define HCFG_PERSCHEDENA               (1 << 26)
+#define HCFG_FRLISTEN_MASK             (0x3 << 24)
+#define HCFG_FRLISTEN_SHIFT            24
+#define HCFG_FRLISTEN_8                                (0 << 24)
+#define FRLISTEN_8_SIZE                                8
+#define HCFG_FRLISTEN_16                       (1 << 24)
+#define FRLISTEN_16_SIZE                       16
+#define HCFG_FRLISTEN_32                       (2 << 24)
+#define FRLISTEN_32_SIZE                       32
+#define HCFG_FRLISTEN_64                       (3 << 24)
+#define FRLISTEN_64_SIZE                       64
+#define HCFG_DESCDMA                   (1 << 23)
+#define HCFG_RESVALID_MASK             (0xff << 8)
+#define HCFG_RESVALID_SHIFT            8
+#define HCFG_ENA32KHZ                  (1 << 7)
+#define HCFG_FSLSSUPP                  (1 << 2)
+#define HCFG_FSLSPCLKSEL_MASK          (0x3 << 0)
+#define HCFG_FSLSPCLKSEL_SHIFT         0
+#define HCFG_FSLSPCLKSEL_30_60_MHZ             (0 << 0)
+#define HCFG_FSLSPCLKSEL_48_MHZ                        (1 << 0)
+#define HCFG_FSLSPCLKSEL_6_MHZ                 (2 << 0)
+
+#define HFIR                           HSOTG_REG(0x0404)
+#define HFIR_FRINT_MASK                        (0xffff << 0)
+#define HFIR_FRINT_SHIFT               0
+#define HFIR_RLDCTRL                   (1 << 16)
+
+#define HFNUM                          HSOTG_REG(0x0408)
+#define HFNUM_FRREM_MASK               (0xffff << 16)
+#define HFNUM_FRREM_SHIFT              16
+#define HFNUM_FRNUM_MASK               (0xffff << 0)
+#define HFNUM_FRNUM_SHIFT              0
+#define HFNUM_MAX_FRNUM                        0x3fff
+
+#define HPTXSTS                                HSOTG_REG(0x0410)
+#define TXSTS_QTOP_ODD                 (1 << 31)
+#define TXSTS_QTOP_CHNEP_MASK          (0xf << 27)
+#define TXSTS_QTOP_CHNEP_SHIFT         27
+#define TXSTS_QTOP_TOKEN_MASK          (0x3 << 25)
+#define TXSTS_QTOP_TOKEN_SHIFT         25
+#define TXSTS_QTOP_TERMINATE           (1 << 24)
+#define TXSTS_QSPCAVAIL_MASK           (0xff << 16)
+#define TXSTS_QSPCAVAIL_SHIFT          16
+#define TXSTS_FSPCAVAIL_MASK           (0xffff << 0)
+#define TXSTS_FSPCAVAIL_SHIFT          0
+
+#define HAINT                          HSOTG_REG(0x0414)
+#define HAINTMSK                       HSOTG_REG(0x0418)
+#define HFLBADDR                       HSOTG_REG(0x041c)
+
+#define HPRT0                          HSOTG_REG(0x0440)
+#define HPRT0_SPD_MASK                 (0x3 << 17)
+#define HPRT0_SPD_SHIFT                        17
+#define HPRT0_SPD_HIGH_SPEED           (0 << 17)
+#define HPRT0_SPD_FULL_SPEED           (1 << 17)
+#define HPRT0_SPD_LOW_SPEED            (2 << 17)
+#define HPRT0_TSTCTL_MASK              (0xf << 13)
+#define HPRT0_TSTCTL_SHIFT             13
+#define HPRT0_PWR                      (1 << 12)
+#define HPRT0_LNSTS_MASK               (0x3 << 10)
+#define HPRT0_LNSTS_SHIFT              10
+#define HPRT0_RST                      (1 << 8)
+#define HPRT0_SUSP                     (1 << 7)
+#define HPRT0_RES                      (1 << 6)
+#define HPRT0_OVRCURRCHG               (1 << 5)
+#define HPRT0_OVRCURRACT               (1 << 4)
+#define HPRT0_ENACHG                   (1 << 3)
+#define HPRT0_ENA                      (1 << 2)
+#define HPRT0_CONNDET                  (1 << 1)
+#define HPRT0_CONNSTS                  (1 << 0)
+
+#define HCCHAR(_ch)                    HSOTG_REG(0x0500 + 0x20 * (_ch))
+#define HCCHAR_CHENA                   (1 << 31)
+#define HCCHAR_CHDIS                   (1 << 30)
+#define HCCHAR_ODDFRM                  (1 << 29)
+#define HCCHAR_DEVADDR_MASK            (0x7f << 22)
+#define HCCHAR_DEVADDR_SHIFT           22
+#define HCCHAR_MULTICNT_MASK           (0x3 << 20)
+#define HCCHAR_MULTICNT_SHIFT          20
+#define HCCHAR_EPTYPE_MASK             (0x3 << 18)
+#define HCCHAR_EPTYPE_SHIFT            18
+#define HCCHAR_LSPDDEV                 (1 << 17)
+#define HCCHAR_EPDIR                   (1 << 15)
+#define HCCHAR_EPNUM_MASK              (0xf << 11)
+#define HCCHAR_EPNUM_SHIFT             11
+#define HCCHAR_MPS_MASK                        (0x7ff << 0)
+#define HCCHAR_MPS_SHIFT               0
+
+#define HCSPLT(_ch)                    HSOTG_REG(0x0504 + 0x20 * (_ch))
+#define HCSPLT_SPLTENA                 (1 << 31)
+#define HCSPLT_COMPSPLT                        (1 << 16)
+#define HCSPLT_XACTPOS_MASK            (0x3 << 14)
+#define HCSPLT_XACTPOS_SHIFT           14
+#define HCSPLT_XACTPOS_MID             (0 << 14)
+#define HCSPLT_XACTPOS_END             (1 << 14)
+#define HCSPLT_XACTPOS_BEGIN           (2 << 14)
+#define HCSPLT_XACTPOS_ALL             (3 << 14)
+#define HCSPLT_HUBADDR_MASK            (0x7f << 7)
+#define HCSPLT_HUBADDR_SHIFT           7
+#define HCSPLT_PRTADDR_MASK            (0x7f << 0)
+#define HCSPLT_PRTADDR_SHIFT           0
+
+#define HCINT(_ch)                     HSOTG_REG(0x0508 + 0x20 * (_ch))
+#define HCINTMSK(_ch)                  HSOTG_REG(0x050c + 0x20 * (_ch))
+#define HCINTMSK_RESERVED14_31         (0x3ffff << 14)
+#define HCINTMSK_FRM_LIST_ROLL         (1 << 13)
+#define HCINTMSK_XCS_XACT              (1 << 12)
+#define HCINTMSK_BNA                   (1 << 11)
+#define HCINTMSK_DATATGLERR            (1 << 10)
+#define HCINTMSK_FRMOVRUN              (1 << 9)
+#define HCINTMSK_BBLERR                        (1 << 8)
+#define HCINTMSK_XACTERR               (1 << 7)
+#define HCINTMSK_NYET                  (1 << 6)
+#define HCINTMSK_ACK                   (1 << 5)
+#define HCINTMSK_NAK                   (1 << 4)
+#define HCINTMSK_STALL                 (1 << 3)
+#define HCINTMSK_AHBERR                        (1 << 2)
+#define HCINTMSK_CHHLTD                        (1 << 1)
+#define HCINTMSK_XFERCOMPL             (1 << 0)
+
+#define HCTSIZ(_ch)                    HSOTG_REG(0x0510 + 0x20 * (_ch))
+#define TSIZ_DOPNG                     (1 << 31)
+#define TSIZ_SC_MC_PID_MASK            (0x3 << 29)
+#define TSIZ_SC_MC_PID_SHIFT           29
+#define TSIZ_SC_MC_PID_DATA0           (0 << 29)
+#define TSIZ_SC_MC_PID_DATA2           (1 << 29)
+#define TSIZ_SC_MC_PID_DATA1           (2 << 29)
+#define TSIZ_SC_MC_PID_MDATA           (3 << 29)
+#define TSIZ_SC_MC_PID_SETUP           (3 << 29)
+#define TSIZ_PKTCNT_MASK               (0x3ff << 19)
+#define TSIZ_PKTCNT_SHIFT              19
+#define TSIZ_NTD_MASK                  (0xff << 8)
+#define TSIZ_NTD_SHIFT                 8
+#define TSIZ_SCHINFO_MASK              (0xff << 0)
+#define TSIZ_SCHINFO_SHIFT             0
+#define TSIZ_XFERSIZE_MASK             (0x7ffff << 0)
+#define TSIZ_XFERSIZE_SHIFT            0
+
+#define HCDMA(_ch)                     HSOTG_REG(0x0514 + 0x20 * (_ch))
+#define HCDMA_DMA_ADDR_MASK            (0x1fffff << 11)
+#define HCDMA_DMA_ADDR_SHIFT           11
+#define HCDMA_CTD_MASK                 (0xff << 3)
+#define HCDMA_CTD_SHIFT                        3
+
+#define HCDMAB(_ch)                    HSOTG_REG(0x051c + 0x20 * (_ch))
+
+#define HCFIFO(_ch)                    HSOTG_REG(0x1000 + 0x1000 * (_ch))
+
+/**
+ * struct dwc2_hcd_dma_desc - Host-mode DMA descriptor structure
+ *
+ * @status: DMA descriptor status quadlet
+ * @buf:    DMA descriptor data buffer pointer
+ *
+ * DMA Descriptor structure contains two quadlets:
+ * Status quadlet and Data buffer pointer.
+ */
+struct dwc2_hcd_dma_desc {
+       u32 status;
+       u32 buf;
+};
+
+#define HOST_DMA_A                     (1 << 31)
+#define HOST_DMA_STS_MASK              (0x3 << 28)
+#define HOST_DMA_STS_SHIFT             28
+#define HOST_DMA_STS_PKTERR            (1 << 28)
+#define HOST_DMA_EOL                   (1 << 26)
+#define HOST_DMA_IOC                   (1 << 25)
+#define HOST_DMA_SUP                   (1 << 24)
+#define HOST_DMA_ALT_QTD               (1 << 23)
+#define HOST_DMA_QTD_OFFSET_MASK       (0x3f << 17)
+#define HOST_DMA_QTD_OFFSET_SHIFT      17
+#define HOST_DMA_ISOC_NBYTES_MASK      (0xfff << 0)
+#define HOST_DMA_ISOC_NBYTES_SHIFT     0
+#define HOST_DMA_NBYTES_MASK           (0x1ffff << 0)
+#define HOST_DMA_NBYTES_SHIFT          0
+
+#define MAX_DMA_DESC_SIZE              131071
+#define MAX_DMA_DESC_NUM_GENERIC       64
+#define MAX_DMA_DESC_NUM_HS_ISOC       256
+
+#endif /* __DWC2_HW_H__ */
diff --git a/drivers/staging/dwc2/pci.c b/drivers/staging/dwc2/pci.c
new file mode 100644 (file)
index 0000000..0825eef
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * pci.c - DesignWare HS OTG Controller PCI driver
+ *
+ * Copyright (C) 2004-2013 Synopsys, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. 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.
+ * 3. The names of the above-listed copyright holders may not 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 the 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 OWNER 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.
+ */
+
+/*
+ * Provides the initialization and cleanup entry points for the DWC_otg PCI
+ * driver
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/pci.h>
+#include <linux/usb.h>
+
+#include <linux/usb/hcd.h>
+#include <linux/usb/ch11.h>
+
+#include "core.h"
+#include "hcd.h"
+
+#define PCI_VENDOR_ID_SYNOPSYS         0x16c3
+#define PCI_PRODUCT_ID_HAPS_HSOTG      0xabc0
+
+static const char dwc2_driver_name[] = "dwc_otg";
+
+static struct dwc2_core_params dwc2_module_params = {
+       .otg_cap                        = -1,
+       .otg_ver                        = -1,
+       .dma_enable                     = -1,
+       .dma_desc_enable                = 0,
+       .speed                          = -1,
+       .enable_dynamic_fifo            = -1,
+       .en_multiple_tx_fifo            = -1,
+       .host_rx_fifo_size              = 1024,
+       .host_nperio_tx_fifo_size       = 256,
+       .host_perio_tx_fifo_size        = 1024,
+       .max_transfer_size              = 65535,
+       .max_packet_count               = 511,
+       .host_channels                  = -1,
+       .phy_type                       = -1,
+       .phy_utmi_width                 = 16,   /* 16 bits - NOT DETECTABLE */
+       .phy_ulpi_ddr                   = -1,
+       .phy_ulpi_ext_vbus              = -1,
+       .i2c_enable                     = -1,
+       .ulpi_fs_ls                     = -1,
+       .host_support_fs_ls_low_power   = -1,
+       .host_ls_low_power_phy_clk      = -1,
+       .ts_dline                       = -1,
+       .reload_ctl                     = -1,
+       .ahb_single                     = -1,
+};
+
+/**
+ * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the
+ * DWC_otg driver
+ *
+ * @dev: Bus device
+ *
+ * This routine is called, for example, when the rmmod command is executed. The
+ * device may or may not be electrically present. If it is present, the driver
+ * stops device processing. Any resources used on behalf of this device are
+ * freed.
+ */
+static void dwc2_driver_remove(struct pci_dev *dev)
+{
+       struct dwc2_hsotg *hsotg = pci_get_drvdata(dev);
+
+       dev_dbg(&dev->dev, "%s(%p)\n", __func__, dev);
+
+       dwc2_hcd_remove(hsotg);
+       pci_disable_device(dev);
+}
+
+/**
+ * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg
+ * driver
+ *
+ * @dev: Bus device
+ *
+ * This routine creates the driver components required to control the device
+ * (core, HCD, and PCD) and initializes the device. The driver components are
+ * stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved
+ * in the device private data. This allows the driver to access the dwc2_hsotg
+ * structure on subsequent calls to driver methods for this device.
+ */
+static int dwc2_driver_probe(struct pci_dev *dev,
+                            const struct pci_device_id *id)
+{
+       struct dwc2_hsotg *hsotg;
+       int retval;
+
+       dev_dbg(&dev->dev, "%s(%p)\n", __func__, dev);
+
+       hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL);
+       if (!hsotg)
+               return -ENOMEM;
+
+       pci_set_power_state(dev, PCI_D0);
+
+       hsotg->dev = &dev->dev;
+       hsotg->regs = devm_request_and_ioremap(&dev->dev, &dev->resource[0]);
+       if (!hsotg->regs)
+               return -ENOMEM;
+
+       dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
+               (unsigned long)pci_resource_start(dev, 0), hsotg->regs);
+
+       if (pci_enable_device(dev) < 0)
+               return -ENODEV;
+
+       pci_set_master(dev);
+
+       retval = dwc2_hcd_init(hsotg, dev->irq, &dwc2_module_params);
+       if (retval) {
+               pci_disable_device(dev);
+               return retval;
+       }
+
+       pci_set_drvdata(dev, hsotg);
+       dev_dbg(&dev->dev, "hsotg=%p\n", hsotg);
+
+       dev_dbg(&dev->dev, "registering common handler for irq%d\n", dev->irq);
+       retval = devm_request_irq(&dev->dev, dev->irq, dwc2_handle_common_intr,
+                                 IRQF_SHARED | IRQ_LEVEL, dev_name(&dev->dev),
+                                 hsotg);
+       if (retval)
+               dwc2_hcd_remove(hsotg);
+
+       return retval;
+}
+
+static DEFINE_PCI_DEVICE_TABLE(dwc2_pci_ids) = {
+       {
+               PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG),
+       },
+       { /* end: all zeroes */ }
+};
+MODULE_DEVICE_TABLE(pci, dwc2_pci_ids);
+
+static struct pci_driver dwc2_pci_driver = {
+       .name = dwc2_driver_name,
+       .id_table = dwc2_pci_ids,
+       .probe = dwc2_driver_probe,
+       .remove = dwc2_driver_remove,
+};
+
+module_pci_driver(dwc2_pci_driver);
+
+MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue");
+MODULE_AUTHOR("Synopsys, Inc.");
+MODULE_LICENSE("Dual BSD/GPL");
index 42ae5e83f907bc61bc919cb6dffeb1477ecceac6..c7e9e1d6bf70e2a217b200c6109ff4d4362a1d3b 100644 (file)
@@ -595,7 +595,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data)
         */
 
        err = eeprom_wait_ready(pdev, NULL);
-       if (err)
+       if (err < 0)
                return err;
 
         /* 2. Write to the LBCIF Control Register:  bit 7=1, bit 6=1, bit 3=0,
@@ -709,7 +709,7 @@ static int eeprom_read(struct et131x_adapter *adapter, u32 addr, u8 *pdata)
         */
 
        err = eeprom_wait_ready(pdev, NULL);
-       if (err)
+       if (err < 0)
                return err;
        /* Write to the LBCIF Control Register:  bit 7=1, bit 6=0, bit 3=0,
         * and bits 1:0 both =0.  Bit 5 should be set according to the type
index 1e6303123722b0742285c3be2c83ce79558df466..b795353e8348a3fcab6d1a01d0472a7168c370a1 100644 (file)
@@ -337,7 +337,6 @@ void gdm_recv_qos_hci_packet(void *nic_ptr, u8 *buf, int size)
        struct nic *nic = nic_ptr;
        u32 i, SFID, index, pos;
        u8 subCmdEvt;
-       u8 len;
        struct qos_cb_s *qcb = &nic->qos;
        struct qos_entry_s *entry, *n;
        struct list_head send_list;
@@ -347,8 +346,6 @@ void gdm_recv_qos_hci_packet(void *nic_ptr, u8 *buf, int size)
        subCmdEvt = (u8)buf[4];
 
        if (subCmdEvt == QOS_REPORT) {
-               len = (u8)buf[5];
-
                spin_lock_irqsave(&qcb->qos_lock, flags);
                for (i = 0; i < qcb->qos_list_cnt; i++) {
                        SFID = ((buf[(i*5)+6]<<24)&0xff000000);
@@ -368,21 +365,24 @@ void gdm_recv_qos_hci_packet(void *nic_ptr, u8 *buf, int size)
                spin_unlock_irqrestore(&qcb->qos_lock, flags);
                send_qos_list(nic, &send_list);
                return;
-       } else if (subCmdEvt == QOS_ADD) {
-               pos = 5;
-               len = (u8)buf[pos++];
-
-               SFID = ((buf[pos++]<<24)&0xff000000);
-               SFID += ((buf[pos++]<<16)&0xff0000);
-               SFID += ((buf[pos++]<<8)&0xff00);
-               SFID += (buf[pos++]);
-
-               index = get_csr(qcb, SFID, 1);
-               if (index == -1) {
-                       netdev_err(nic->netdev, "QoS ERROR: csr Update Error\n");
-                       return;
-               }
+       }
+
+       /* subCmdEvt == QOS_ADD || subCmdEvt == QOS_CHANG_DEL */
+       pos = 6;
+       SFID = ((buf[pos++]<<24)&0xff000000);
+       SFID += ((buf[pos++]<<16)&0xff0000);
+       SFID += ((buf[pos++]<<8)&0xff00);
+       SFID += (buf[pos++]);
+
+       index = get_csr(qcb, SFID, 1);
+       if (index == -1) {
+               netdev_err(nic->netdev,
+                          "QoS ERROR: csr Update Error / Wrong index (%d) \n",
+                          index);
+               return;
+       }
 
+       if (subCmdEvt == QOS_ADD) {
                netdev_dbg(nic->netdev, "QOS_ADD SFID = 0x%x, index=%d\n",
                           SFID, index);
 
@@ -424,19 +424,6 @@ void gdm_recv_qos_hci_packet(void *nic_ptr, u8 *buf, int size)
                qcb->qos_limit_size = 254/qcb->qos_list_cnt;
                spin_unlock_irqrestore(&qcb->qos_lock, flags);
        } else if (subCmdEvt == QOS_CHANGE_DEL) {
-               pos = 5;
-               len = (u8)buf[pos++];
-               SFID = ((buf[pos++]<<24)&0xff000000);
-               SFID += ((buf[pos++]<<16)&0xff0000);
-               SFID += ((buf[pos++]<<8)&0xff00);
-               SFID += (buf[pos++]);
-               index = get_csr(qcb, SFID, 1);
-               if (index == -1) {
-                       netdev_err(nic->netdev, "QoS ERROR: Wrong index(%d)\n",
-                                  index);
-                       return;
-               }
-
                netdev_dbg(nic->netdev, "QOS_CHANGE_DEL SFID = 0x%x, index=%d\n",
                           SFID, index);
 
index 52c25ba5831d1bf2f595b6b37c1eefe6ee7b6fcf..8a92605adbff64db0909b5b40ae6ac9f57d8d5c8 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/netlink.h>
 #include <asm/byteorder.h>
 #include <net/sock.h>
+#include "netlink_k.h"
 
 #if !defined(NLMSG_HDRLEN)
 #define NLMSG_HDRLEN    ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
index 93046dda78f0c2e72d99e30a5b48cea5065c81b3..4302fcbdfdc3cea30e9faf46e313667dcf758f4e 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/firmware.h>
 
 #include "gdm_sdio.h"
+#include "sdio_boot.h"
 
 #define TYPE_A_HEADER_SIZE     4
 #define TYPE_A_LOOKAHEAD_SIZE   16
index 75cc37ff1ed007dc722f37c1405e619208deb88a..64e2e08fb4d034e2da93c924b7c064a452dace91 100644 (file)
@@ -10,9 +10,6 @@ struct iio_trig *trig = iio_trigger_alloc("<trigger format string>", ...);
 allocates a trigger structure.  The key elements to then fill in within
 a driver are:
 
-trig->private_data
-       Device specific private data.
-
 trig->owner
        Typically set to THIS_MODULE. Used to ensure correct
        ownership of core allocated resources.
index dc267175a2b59fe9be12d1c4d584fa1faf741ef3..db4d6dc032432cf0d92ff71d6c38e52dff17ce13 100644 (file)
@@ -4,14 +4,6 @@
 menu "IIO staging drivers"
        depends on IIO
 
-config IIO_ST_HWMON
-       tristate "Hwmon driver that uses channels specified via iio maps"
-       depends on HWMON
-       help
-         This is a platform driver that in combination with a suitable
-         map allows IIO devices to provide  basic hwmon functionality
-         for those channels specified in the map.
-
 source "drivers/staging/iio/accel/Kconfig"
 source "drivers/staging/iio/adc/Kconfig"
 source "drivers/staging/iio/addac/Kconfig"
index 158e0a017e7b27c0d132d1518342a57467158547..d87106135b270133a50067a07f31f9459a8a6776 100644 (file)
@@ -9,8 +9,6 @@ iio_dummy-$(CONFIG_IIO_SIMPLE_DUMMY_BUFFER) += iio_simple_dummy_buffer.o
 
 obj-$(CONFIG_IIO_DUMMY_EVGEN) += iio_dummy_evgen.o
 
-obj-$(CONFIG_IIO_ST_HWMON) += iio_hwmon.o
-
 obj-y += accel/
 obj-y += adc/
 obj-y += addac/
index 9e5791ff2a04ca3e33b528a153f279a916fc23cb..ab8ec7af88b49a80689480bcd43deedad4d2cbab 100644 (file)
@@ -134,14 +134,14 @@ static const struct iio_chan_spec adis16201_channels[] = {
        ADIS_SUPPLY_CHAN(ADIS16201_SUPPLY_OUT, ADIS16201_SCAN_SUPPLY, 12),
        ADIS_TEMP_CHAN(ADIS16201_TEMP_OUT, ADIS16201_SCAN_TEMP, 12),
        ADIS_ACCEL_CHAN(X, ADIS16201_XACCL_OUT, ADIS16201_SCAN_ACC_X,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14),
+               BIT(IIO_CHAN_INFO_CALIBBIAS), 14),
        ADIS_ACCEL_CHAN(Y, ADIS16201_YACCL_OUT, ADIS16201_SCAN_ACC_Y,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14),
+               BIT(IIO_CHAN_INFO_CALIBBIAS), 14),
        ADIS_AUX_ADC_CHAN(ADIS16201_AUX_ADC, ADIS16201_SCAN_AUX_ADC, 12),
        ADIS_INCLI_CHAN(X, ADIS16201_XINCL_OUT, ADIS16201_SCAN_INCLI_X,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14),
+               BIT(IIO_CHAN_INFO_CALIBBIAS), 14),
        ADIS_INCLI_CHAN(X, ADIS16201_YINCL_OUT, ADIS16201_SCAN_INCLI_Y,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14),
+               BIT(IIO_CHAN_INFO_CALIBBIAS), 14),
        IIO_CHAN_SOFT_TIMESTAMP(7)
 };
 
index 8c235273ff131031a473c0b1176c76094a1bd8d0..b08ac8fdeee2726cd38d5edcda192410861b2935 100644 (file)
@@ -102,7 +102,7 @@ static const struct iio_chan_spec adis16203_channels[] = {
        ADIS_SUPPLY_CHAN(ADIS16203_SUPPLY_OUT, ADIS16203_SCAN_SUPPLY, 12),
        ADIS_AUX_ADC_CHAN(ADIS16203_AUX_ADC, ADIS16203_SCAN_AUX_ADC, 12),
        ADIS_INCLI_CHAN(X, ADIS16203_XINCL_OUT, ADIS16203_SCAN_INCLI_X,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14),
+               BIT(IIO_CHAN_INFO_CALIBBIAS), 14),
        /* Fixme: Not what it appears to be - see data sheet */
        ADIS_INCLI_CHAN(Y, ADIS16203_YINCL_OUT, ADIS16203_SCAN_INCLI_Y, 0, 14),
        ADIS_TEMP_CHAN(ADIS16203_TEMP_OUT, ADIS16203_SCAN_TEMP, 12),
index f3592668e066d07f8d5022a06927d61d61ca0f4f..792ec25a50dca5b9c8ef18827ead6a6e3b5f002e 100644 (file)
@@ -140,13 +140,11 @@ static const struct iio_chan_spec adis16204_channels[] = {
        ADIS_AUX_ADC_CHAN(ADIS16204_AUX_ADC, ADIS16204_SCAN_AUX_ADC, 12),
        ADIS_TEMP_CHAN(ADIS16204_TEMP_OUT, ADIS16204_SCAN_TEMP, 12),
        ADIS_ACCEL_CHAN(X, ADIS16204_XACCL_OUT, ADIS16204_SCAN_ACC_X,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
-               IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 14),
+               BIT(IIO_CHAN_INFO_CALIBBIAS) | BIT(IIO_CHAN_INFO_PEAK), 14),
        ADIS_ACCEL_CHAN(Y, ADIS16204_YACCL_OUT, ADIS16204_SCAN_ACC_Y,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
-               IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 14),
+               BIT(IIO_CHAN_INFO_CALIBBIAS) | BIT(IIO_CHAN_INFO_PEAK), 14),
        ADIS_ACCEL_CHAN(ROOT_SUM_SQUARED_X_Y, ADIS16204_XY_RSS_OUT,
-               ADIS16204_SCAN_ACC_XY, IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 14),
+               ADIS16204_SCAN_ACC_XY, BIT(IIO_CHAN_INFO_PEAK), 14),
        IIO_CHAN_SOFT_TIMESTAMP(5),
 };
 
index 69c50ee44ce34c82c0db95bb00d97ac8281ce1b5..323c169d699ca54bf8044921c5bb71c3c1fc27ee 100644 (file)
@@ -133,9 +133,9 @@ static const struct iio_chan_spec adis16209_channels[] = {
        ADIS_SUPPLY_CHAN(ADIS16209_SUPPLY_OUT, ADIS16209_SCAN_SUPPLY, 14),
        ADIS_TEMP_CHAN(ADIS16209_TEMP_OUT, ADIS16209_SCAN_TEMP, 12),
        ADIS_ACCEL_CHAN(X, ADIS16209_XACCL_OUT, ADIS16209_SCAN_ACC_X,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14),
+               BIT(IIO_CHAN_INFO_CALIBBIAS), 14),
        ADIS_ACCEL_CHAN(Y, ADIS16209_YACCL_OUT, ADIS16209_SCAN_ACC_Y,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT, 14),
+               BIT(IIO_CHAN_INFO_CALIBBIAS), 14),
        ADIS_AUX_ADC_CHAN(ADIS16209_AUX_ADC, ADIS16209_SCAN_AUX_ADC, 12),
        ADIS_INCLI_CHAN(X, ADIS16209_XINCL_OUT, ADIS16209_SCAN_INCLI_X, 0, 14),
        ADIS_INCLI_CHAN(Y, ADIS16209_YINCL_OUT, ADIS16209_SCAN_INCLI_Y, 0, 14),
index 370b01aa767a713f10d0a9e86465559ad632b131..0e72f795ed091cab1ee06f462d2a829f334583cf 100644 (file)
@@ -344,37 +344,37 @@ static const struct iio_chan_spec adis16220_channels[] = {
                .indexed = 1,
                .channel = 0,
                .extend_name = "supply",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE),
                .address = in_supply,
        }, {
                .type = IIO_ACCEL,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
-                            IIO_CHAN_INFO_PEAK_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_OFFSET) |
+                       BIT(IIO_CHAN_INFO_SCALE) |
+                       BIT(IIO_CHAN_INFO_PEAK),
                .address = accel,
        }, {
                .type = IIO_TEMP,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_OFFSET) |
+                       BIT(IIO_CHAN_INFO_SCALE),
                .address = temp,
        }, {
                .type = IIO_VOLTAGE,
                .indexed = 1,
                .channel = 1,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_OFFSET) |
+                       BIT(IIO_CHAN_INFO_SCALE),
                .address = in_1,
        }, {
                .type = IIO_VOLTAGE,
                .indexed = 1,
                .channel = 2,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .address = in_2,
        }
 };
index e97fa0b0233dae9b77f1b1aae6ff63fa7bfedd8d..fd1f0fd0fba8c4be0fcb5676047cb3ab4f02c2bb 100644 (file)
@@ -176,14 +176,11 @@ static const struct iio_chan_spec adis16240_channels[] = {
        ADIS_SUPPLY_CHAN(ADIS16240_SUPPLY_OUT, ADIS16240_SCAN_SUPPLY, 10),
        ADIS_AUX_ADC_CHAN(ADIS16240_AUX_ADC, ADIS16240_SCAN_AUX_ADC, 10),
        ADIS_ACCEL_CHAN(X, ADIS16240_XACCL_OUT, ADIS16240_SCAN_ACC_X,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
-               IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 10),
+               BIT(IIO_CHAN_INFO_CALIBBIAS) | BIT(IIO_CHAN_INFO_PEAK), 10),
        ADIS_ACCEL_CHAN(Y, ADIS16240_YACCL_OUT, ADIS16240_SCAN_ACC_Y,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
-               IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 10),
+               BIT(IIO_CHAN_INFO_CALIBBIAS) | BIT(IIO_CHAN_INFO_PEAK), 10),
        ADIS_ACCEL_CHAN(Z, ADIS16240_ZACCL_OUT, ADIS16240_SCAN_ACC_Z,
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
-               IIO_CHAN_INFO_PEAK_SEPARATE_BIT, 10),
+               BIT(IIO_CHAN_INFO_CALIBBIAS) | BIT(IIO_CHAN_INFO_PEAK), 10),
        ADIS_TEMP_CHAN(ADIS16240_TEMP_OUT, ADIS16240_SCAN_TEMP, 10),
        IIO_CHAN_SOFT_TIMESTAMP(6)
 };
index 0e019306439cd86fff57ab2e7b7bd28cb1f9d7ad..1bfe5d81792ba47c9aae04eeb9f0174e9653289e 100644 (file)
@@ -501,12 +501,6 @@ static irqreturn_t lis3l02dq_event_handler(int irq, void *private)
        return IRQ_HANDLED;
 }
 
-#define LIS3L02DQ_INFO_MASK                            \
-       (IIO_CHAN_INFO_RAW_SEPARATE_BIT |               \
-        IIO_CHAN_INFO_SCALE_SHARED_BIT |               \
-        IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |        \
-        IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT)
-
 #define LIS3L02DQ_EVENT_MASK                                   \
        (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |    \
         IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
@@ -516,7 +510,10 @@ static irqreturn_t lis3l02dq_event_handler(int irq, void *private)
                .type = IIO_ACCEL,                              \
                .modified = 1,                                  \
                .channel2 = mod,                                \
-               .info_mask =  LIS3L02DQ_INFO_MASK,              \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |  \
+                       BIT(IIO_CHAN_INFO_CALIBSCALE) |         \
+                       BIT(IIO_CHAN_INFO_CALIBBIAS),           \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
                .address = index,                               \
                .scan_index = index,                            \
                .scan_type = {                                  \
index e676403ea3ea6cbc3dff62d7a720d6786314e474..5b8f0f6c99385d409ba471acfe902a041518da38 100644 (file)
@@ -228,7 +228,7 @@ error_ret:
 static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig,
                                                bool state)
 {
-       struct iio_dev *indio_dev = trig->private_data;
+       struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
        int ret = 0;
        u8 t;
 
@@ -252,7 +252,7 @@ static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig,
  */
 static int lis3l02dq_trig_try_reen(struct iio_trigger *trig)
 {
-       struct iio_dev *indio_dev = trig->private_data;
+       struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
        struct lis3l02dq_state *st = iio_priv(indio_dev);
        int i;
 
@@ -290,7 +290,7 @@ int lis3l02dq_probe_trigger(struct iio_dev *indio_dev)
 
        st->trig->dev.parent = &st->us->dev;
        st->trig->ops = &lis3l02dq_trigger_ops;
-       st->trig->private_data = indio_dev;
+       iio_trigger_set_drvdata(st->trig, indio_dev);
        ret = iio_trigger_register(st->trig);
        if (ret)
                goto error_free_trig;
index 14683f583ccfb27ded6ed02f01338be325457bc5..32950ad9485777609a3ab0be9365444e529f557e 100644 (file)
@@ -419,8 +419,6 @@ static IIO_DEVICE_ATTR(measurement_mode, S_IRUGO | S_IWUSR,
 
 static IIO_DEVICE_ATTR(revision, S_IRUGO, sca3000_show_rev, NULL, 0);
 
-#define SCA3000_INFO_MASK                      \
-       IIO_CHAN_INFO_RAW_SEPARATE_BIT | IIO_CHAN_INFO_SCALE_SHARED_BIT
 #define SCA3000_EVENT_MASK                                     \
        (IIO_EV_BIT(IIO_EV_TYPE_MAG, IIO_EV_DIR_RISING))
 
@@ -429,7 +427,8 @@ static IIO_DEVICE_ATTR(revision, S_IRUGO, sca3000_show_rev, NULL, 0);
                .type = IIO_ACCEL,                              \
                .modified = 1,                                  \
                .channel2 = mod,                                \
-               .info_mask = SCA3000_INFO_MASK,                 \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
                .address = index,                               \
                .scan_index = index,                            \
                .scan_type = {                                  \
index 7b2a01d64f5ecfc517aafd56e13b78126f1d73dc..d990829008ffc2c45a163b08212e272f16bd21a5 100644 (file)
@@ -90,13 +90,6 @@ config AD7192
          To compile this driver as a module, choose M here: the
          module will be called ad7192.
 
-config ADT7410
-       tristate "Analog Devices ADT7310/ADT7410 temperature sensor driver"
-       depends on I2C || SPI_MASTER
-       help
-         Say yes here to build support for Analog Devices ADT7310/ADT7410
-         temperature sensors.
-
 config AD7280
        tristate "Analog Devices AD7280A Lithium Ion Battery Monitoring System"
        depends on SPI
index d285596272a09ab51704bdc02113bc5e400a4413..3e9fb143d25b4d3fe18ffc7c3abaf0133b51ef6f 100644 (file)
@@ -16,7 +16,6 @@ obj-$(CONFIG_AD7291) += ad7291.o
 obj-$(CONFIG_AD7780) += ad7780.o
 obj-$(CONFIG_AD7816) += ad7816.o
 obj-$(CONFIG_AD7192) += ad7192.o
-obj-$(CONFIG_ADT7410) += adt7410.o
 obj-$(CONFIG_AD7280) += ad7280a.o
 obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
 obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
index 1f190c1b12a600c058ece50d1cdf2a6628bf7868..2fd6ee3c1902ad27bd63dbae1c8d711783256229 100644 (file)
@@ -503,9 +503,10 @@ static int ad7280_channel_init(struct ad7280_state *st)
                                st->channels[cnt].channel = (dev * 6) + ch - 6;
                        }
                        st->channels[cnt].indexed = 1;
-                       st->channels[cnt].info_mask =
-                               IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                               IIO_CHAN_INFO_SCALE_SHARED_BIT;
+                       st->channels[cnt].info_mask_separate =
+                               BIT(IIO_CHAN_INFO_RAW);
+                       st->channels[cnt].info_mask_shared_by_type =
+                               BIT(IIO_CHAN_INFO_SCALE);
                        st->channels[cnt].address =
                                AD7280A_DEVADDR(dev) << 8 | ch;
                        st->channels[cnt].scan_index = cnt;
@@ -521,9 +522,8 @@ static int ad7280_channel_init(struct ad7280_state *st)
        st->channels[cnt].channel2 = dev * 6;
        st->channels[cnt].address = AD7280A_ALL_CELLS;
        st->channels[cnt].indexed = 1;
-       st->channels[cnt].info_mask =
-               IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT;
+       st->channels[cnt].info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
+       st->channels[cnt].info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE);
        st->channels[cnt].scan_index = cnt;
        st->channels[cnt].scan_type.sign = 'u';
        st->channels[cnt].scan_type.realbits = 32;
index 6e58e36d242ccff0e3ec9e936ce435ebe2c229c4..d088c662d5cd3a193c3b29bd4f4407aa55b76ba7 100644 (file)
@@ -536,8 +536,8 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
 #define AD7291_VOLTAGE_CHAN(_chan)                                     \
 {                                                                      \
        .type = IIO_VOLTAGE,                                            \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |                   \
-       IIO_CHAN_INFO_SCALE_SHARED_BIT,                                 \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),                   \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),           \
        .indexed = 1,                                                   \
        .channel = _chan,                                               \
        .event_mask = IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING)|\
@@ -555,9 +555,9 @@ static const struct iio_chan_spec ad7291_channels[] = {
        AD7291_VOLTAGE_CHAN(7),
        {
                .type = IIO_TEMP,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                               IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT |
-                               IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                               BIT(IIO_CHAN_INFO_AVERAGE_RAW) |
+                               BIT(IIO_CHAN_INFO_SCALE),
                .indexed = 1,
                .channel = 0,
                .event_mask =
index bae61cbe921259cbc9eb0a71136534f36b2da97f..d104b43784241f7931003978f35ccdcb01e88277 100644 (file)
@@ -235,8 +235,8 @@ static const struct attribute_group ad7606_attribute_group_range = {
                .indexed = 1,                                   \
                .channel = num,                                 \
                .address = num,                                 \
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |   \
-                               IIO_CHAN_INFO_SCALE_SHARED_BIT, \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
                .scan_index = num,                              \
                .scan_type = IIO_ST('s', 16, 16, 0),            \
        }
index 3e363c4ba2117fe3fe24e1e375859282c1bd99aa..b51680c1c331a65593a531a93ec6f1bd6f1b191c 100644 (file)
@@ -87,7 +87,6 @@ struct ad799x_state;
  * struct ad799x_chip_info - chip specifc information
  * @channel:           channel specification
  * @num_channels:      number of channels
- * @int_vref_mv:       the internal reference voltage
  * @monitor_mode:      whether the chip supports monitor interrupts
  * @default_config:    device default configuration
  * @event_attrs:       pointer to the monitor event attribute group
@@ -96,7 +95,6 @@ struct ad799x_state;
 struct ad799x_chip_info {
        struct iio_chan_spec            channel[9];
        int                             num_channels;
-       u16                             int_vref_mv;
        u16                             default_config;
        const struct iio_info           *info;
 };
@@ -104,12 +102,13 @@ struct ad799x_chip_info {
 struct ad799x_state {
        struct i2c_client               *client;
        const struct ad799x_chip_info   *chip_info;
-       struct iio_trigger              *trig;
        struct regulator                *reg;
        u16                             int_vref_mv;
        unsigned                        id;
-       char                            *name;
        u16                             config;
+
+       u8                              *rx_buf;
+       unsigned int                    transfer_size;
 };
 
 /*
index 077eedbd0a0c120982224ea2fc97c63a6f70bafa..8dc97b36e05a7ab5506da9b2be2ffaf0019b4e6f 100644 (file)
@@ -48,13 +48,13 @@ static int ad799x_i2c_read16(struct ad799x_state *st, u8 reg, u16 *data)
        struct i2c_client *client = st->client;
        int ret = 0;
 
-       ret = i2c_smbus_read_word_data(client, reg);
+       ret = i2c_smbus_read_word_swapped(client, reg);
        if (ret < 0) {
                dev_err(&client->dev, "I2C read error\n");
                return ret;
        }
 
-       *data = swab16((u16)ret);
+       *data = (u16)ret;
 
        return 0;
 }
@@ -80,7 +80,7 @@ static int ad799x_i2c_write16(struct ad799x_state *st, u8 reg, u16 data)
        struct i2c_client *client = st->client;
        int ret = 0;
 
-       ret = i2c_smbus_write_word_data(client, reg, swab16(data));
+       ret = i2c_smbus_write_word_swapped(client, reg, data);
        if (ret < 0)
                dev_err(&client->dev, "I2C write error\n");
 
@@ -104,6 +104,13 @@ static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
 {
        struct ad799x_state *st = iio_priv(indio_dev);
 
+       kfree(st->rx_buf);
+       st->rx_buf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
+       if (!st->rx_buf)
+               return -ENOMEM;
+
+       st->transfer_size = bitmap_weight(scan_mask, indio_dev->masklength) * 2;
+
        switch (st->id) {
        case ad7997:
        case ad7998:
@@ -460,395 +467,114 @@ static const struct iio_info ad7993_4_7_8_info = {
 #define AD799X_EV_MASK (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \
                        IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING))
 
+#define AD799X_CHANNEL(_index, _realbits, _evmask) { \
+       .type = IIO_VOLTAGE, \
+       .indexed = 1, \
+       .channel = (_index), \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
+       .scan_index = (_index), \
+       .scan_type = IIO_ST('u', _realbits, 16, 12 - (_realbits)), \
+       .event_mask = (_evmask), \
+}
+
 static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
        [ad7991] = {
                .channel = {
-                       [0] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 0,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 0,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                       },
-                       [1] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 1,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 1,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                       },
-                       [2] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 2,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 2,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                       },
-                       [3] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 3,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 3,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                       },
-                       [4] = IIO_CHAN_SOFT_TIMESTAMP(4),
+                       AD799X_CHANNEL(0, 12, 0),
+                       AD799X_CHANNEL(1, 12, 0),
+                       AD799X_CHANNEL(2, 12, 0),
+                       AD799X_CHANNEL(3, 12, 0),
+                       IIO_CHAN_SOFT_TIMESTAMP(4),
                },
                .num_channels = 5,
-               .int_vref_mv = 4096,
                .info = &ad7991_info,
        },
        [ad7995] = {
                .channel = {
-                       [0] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 0,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 0,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                       },
-                       [1] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 1,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 1,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                       },
-                       [2] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 2,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 2,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                       },
-                       [3] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 3,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 3,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                       },
-                       [4] = IIO_CHAN_SOFT_TIMESTAMP(4),
+                       AD799X_CHANNEL(0, 10, 0),
+                       AD799X_CHANNEL(1, 10, 0),
+                       AD799X_CHANNEL(2, 10, 0),
+                       AD799X_CHANNEL(3, 10, 0),
+                       IIO_CHAN_SOFT_TIMESTAMP(4),
                },
                .num_channels = 5,
-               .int_vref_mv = 1024,
                .info = &ad7991_info,
        },
        [ad7999] = {
                .channel = {
-                       [0] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 0,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 0,
-                               .scan_type = IIO_ST('u', 8, 16, 4),
-                       },
-                       [1] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 1,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 1,
-                               .scan_type = IIO_ST('u', 8, 16, 4),
-                       },
-                       [2] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 2,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 2,
-                               .scan_type = IIO_ST('u', 8, 16, 4),
-                       },
-                       [3] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 3,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 3,
-                               .scan_type = IIO_ST('u', 8, 16, 4),
-                       },
-                       [4] = IIO_CHAN_SOFT_TIMESTAMP(4),
+                       AD799X_CHANNEL(0, 8, 0),
+                       AD799X_CHANNEL(1, 8, 0),
+                       AD799X_CHANNEL(2, 8, 0),
+                       AD799X_CHANNEL(3, 8, 0),
+                       IIO_CHAN_SOFT_TIMESTAMP(4),
                },
                .num_channels = 5,
-               .int_vref_mv = 1024,
                .info = &ad7991_info,
        },
        [ad7992] = {
                .channel = {
-                       [0] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 0,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 0,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [1] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 1,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 1,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [2] = IIO_CHAN_SOFT_TIMESTAMP(2),
+                       AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
+                       AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
+                       IIO_CHAN_SOFT_TIMESTAMP(3),
                },
                .num_channels = 3,
-               .int_vref_mv = 4096,
                .default_config = AD7998_ALERT_EN,
                .info = &ad7992_info,
        },
        [ad7993] = {
                .channel = {
-                       [0] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 0,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 0,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [1] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 1,
-                               .scan_index = 1,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [2] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 2,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 2,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [3] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 3,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 3,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [4] = IIO_CHAN_SOFT_TIMESTAMP(4),
+                       AD799X_CHANNEL(0, 10, AD799X_EV_MASK),
+                       AD799X_CHANNEL(1, 10, AD799X_EV_MASK),
+                       AD799X_CHANNEL(2, 10, AD799X_EV_MASK),
+                       AD799X_CHANNEL(3, 10, AD799X_EV_MASK),
+                       IIO_CHAN_SOFT_TIMESTAMP(4),
                },
                .num_channels = 5,
-               .int_vref_mv = 1024,
                .default_config = AD7998_ALERT_EN,
                .info = &ad7993_4_7_8_info,
        },
        [ad7994] = {
                .channel = {
-                       [0] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 0,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 0,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [1] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 1,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 1,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [2] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 2,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 2,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [3] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 3,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 3,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [4] = IIO_CHAN_SOFT_TIMESTAMP(4),
+                       AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
+                       AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
+                       AD799X_CHANNEL(2, 12, AD799X_EV_MASK),
+                       AD799X_CHANNEL(3, 12, AD799X_EV_MASK),
+                       IIO_CHAN_SOFT_TIMESTAMP(4),
                },
                .num_channels = 5,
-               .int_vref_mv = 4096,
                .default_config = AD7998_ALERT_EN,
                .info = &ad7993_4_7_8_info,
        },
        [ad7997] = {
                .channel = {
-                       [0] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 0,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 0,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [1] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 1,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 1,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [2] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 2,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 2,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [3] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 3,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 3,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [4] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 4,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 4,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                       },
-                       [5] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 5,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 5,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                       },
-                       [6] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 6,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 6,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                       },
-                       [7] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 7,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 7,
-                               .scan_type = IIO_ST('u', 10, 16, 2),
-                       },
-                       [8] = IIO_CHAN_SOFT_TIMESTAMP(8),
+                       AD799X_CHANNEL(0, 10, AD799X_EV_MASK),
+                       AD799X_CHANNEL(1, 10, AD799X_EV_MASK),
+                       AD799X_CHANNEL(2, 10, AD799X_EV_MASK),
+                       AD799X_CHANNEL(3, 10, AD799X_EV_MASK),
+                       AD799X_CHANNEL(4, 10, 0),
+                       AD799X_CHANNEL(5, 10, 0),
+                       AD799X_CHANNEL(6, 10, 0),
+                       AD799X_CHANNEL(7, 10, 0),
+                       IIO_CHAN_SOFT_TIMESTAMP(8),
                },
                .num_channels = 9,
-               .int_vref_mv = 1024,
                .default_config = AD7998_ALERT_EN,
                .info = &ad7993_4_7_8_info,
        },
        [ad7998] = {
                .channel = {
-                       [0] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 0,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 0,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [1] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 1,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 1,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [2] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 2,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 2,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [3] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 3,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 3,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                               .event_mask = AD799X_EV_MASK,
-                       },
-                       [4] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 4,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 4,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                       },
-                       [5] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 5,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 5,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                       },
-                       [6] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 6,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 6,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                       },
-                       [7] = {
-                               .type = IIO_VOLTAGE,
-                               .indexed = 1,
-                               .channel = 7,
-                               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
-                               .scan_index = 7,
-                               .scan_type = IIO_ST('u', 12, 16, 0),
-                       },
-                       [8] = IIO_CHAN_SOFT_TIMESTAMP(8),
+                       AD799X_CHANNEL(0, 12, AD799X_EV_MASK),
+                       AD799X_CHANNEL(1, 12, AD799X_EV_MASK),
+                       AD799X_CHANNEL(2, 12, AD799X_EV_MASK),
+                       AD799X_CHANNEL(3, 12, AD799X_EV_MASK),
+                       AD799X_CHANNEL(4, 12, 0),
+                       AD799X_CHANNEL(5, 12, 0),
+                       AD799X_CHANNEL(6, 12, 0),
+                       AD799X_CHANNEL(7, 12, 0),
+                       IIO_CHAN_SOFT_TIMESTAMP(8),
                },
                .num_channels = 9,
-               .int_vref_mv = 4096,
                .default_config = AD7998_ALERT_EN,
                .info = &ad7993_4_7_8_info,
        },
@@ -875,10 +601,10 @@ static int ad799x_probe(struct i2c_client *client,
 
        /* TODO: Add pdata options for filtering and bit delay */
 
-       if (pdata)
-               st->int_vref_mv = pdata->vref_mv;
-       else
-               st->int_vref_mv = st->chip_info->int_vref_mv;
+       if (!pdata)
+               return -EINVAL;
+
+       st->int_vref_mv = pdata->vref_mv;
 
        st->reg = regulator_get(&client->dev, "vcc");
        if (!IS_ERR(st->reg)) {
@@ -946,6 +672,7 @@ static int ad799x_remove(struct i2c_client *client)
                regulator_disable(st->reg);
                regulator_put(st->reg);
        }
+       kfree(st->rx_buf);
        iio_device_free(indio_dev);
 
        return 0;
index 2c5f38475a8edfef700d924f110de25e35263fdd..c2ebae12ee1961852e83f73a818860d7b8af7550 100644 (file)
@@ -36,14 +36,9 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
        struct iio_dev *indio_dev = pf->indio_dev;
        struct ad799x_state *st = iio_priv(indio_dev);
        s64 time_ns;
-       __u8 *rxbuf;
        int b_sent;
        u8 cmd;
 
-       rxbuf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
-       if (rxbuf == NULL)
-               goto out;
-
        switch (st->id) {
        case ad7991:
        case ad7995:
@@ -66,20 +61,17 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
        }
 
        b_sent = i2c_smbus_read_i2c_block_data(st->client,
-                       cmd, bitmap_weight(indio_dev->active_scan_mask,
-                                          indio_dev->masklength) * 2, rxbuf);
+                       cmd, st->transfer_size, st->rx_buf);
        if (b_sent < 0)
-               goto done;
+               goto out;
 
        time_ns = iio_get_time_ns();
 
        if (indio_dev->scan_timestamp)
-               memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64),
+               memcpy(st->rx_buf + indio_dev->scan_bytes - sizeof(s64),
                        &time_ns, sizeof(time_ns));
 
-       iio_push_to_buffers(indio_dev, rxbuf);
-done:
-       kfree(rxbuf);
+       iio_push_to_buffers(indio_dev, st->rx_buf);
 out:
        iio_trigger_notify_done(indio_dev->trig);
 
diff --git a/drivers/staging/iio/adc/adt7410.c b/drivers/staging/iio/adc/adt7410.c
deleted file mode 100644 (file)
index 35455e1..0000000
+++ /dev/null
@@ -1,1102 +0,0 @@
-/*
- * ADT7410 digital temperature sensor driver supporting ADT7310/ADT7410
- *
- * Copyright 2010 Analog Devices Inc.
- *
- * Licensed under the GPL-2 or later.
- */
-
-#include <linux/interrupt.h>
-#include <linux/device.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/sysfs.h>
-#include <linux/list.h>
-#include <linux/i2c.h>
-#include <linux/spi/spi.h>
-#include <linux/module.h>
-
-#include <linux/iio/iio.h>
-#include <linux/iio/sysfs.h>
-#include <linux/iio/events.h>
-
-/*
- * ADT7410 registers definition
- */
-
-#define ADT7410_TEMPERATURE            0
-#define ADT7410_STATUS                 2
-#define ADT7410_CONFIG                 3
-#define ADT7410_T_ALARM_HIGH           4
-#define ADT7410_T_ALARM_LOW            6
-#define ADT7410_T_CRIT                 8
-#define ADT7410_T_HYST                 0xA
-#define ADT7410_ID                     0xB
-#define ADT7410_RESET                  0x2F
-
-/*
- * ADT7310 registers definition
- */
-
-#define ADT7310_STATUS                 0
-#define ADT7310_CONFIG                 1
-#define ADT7310_TEMPERATURE            2
-#define ADT7310_ID                     3
-#define ADT7310_T_CRIT                 4
-#define ADT7310_T_HYST                 5
-#define ADT7310_T_ALARM_HIGH           6
-#define ADT7310_T_ALARM_LOW            7
-
-/*
- * ADT7410 status
- */
-#define ADT7410_STAT_T_LOW             0x10
-#define ADT7410_STAT_T_HIGH            0x20
-#define ADT7410_STAT_T_CRIT            0x40
-#define ADT7410_STAT_NOT_RDY           0x80
-
-/*
- * ADT7410 config
- */
-#define ADT7410_FAULT_QUEUE_MASK       0x3
-#define ADT7410_CT_POLARITY            0x4
-#define ADT7410_INT_POLARITY           0x8
-#define ADT7410_EVENT_MODE             0x10
-#define ADT7410_MODE_MASK              0x60
-#define ADT7410_ONESHOT                        0x20
-#define ADT7410_SPS                    0x40
-#define ADT7410_PD                     0x60
-#define ADT7410_RESOLUTION             0x80
-
-/*
- * ADT7410 masks
- */
-#define ADT7410_T16_VALUE_SIGN                 0x8000
-#define ADT7410_T16_VALUE_FLOAT_OFFSET         7
-#define ADT7410_T16_VALUE_FLOAT_MASK           0x7F
-#define ADT7410_T13_VALUE_SIGN                 0x1000
-#define ADT7410_T13_VALUE_OFFSET               3
-#define ADT7410_T13_VALUE_FLOAT_OFFSET         4
-#define ADT7410_T13_VALUE_FLOAT_MASK           0xF
-#define ADT7410_T_HYST_MASK                    0xF
-#define ADT7410_DEVICE_ID_MASK                 0xF
-#define ADT7410_MANUFACTORY_ID_MASK            0xF0
-#define ADT7410_MANUFACTORY_ID_OFFSET          4
-
-
-#define ADT7310_CMD_REG_MASK                   0x28
-#define ADT7310_CMD_REG_OFFSET                 3
-#define ADT7310_CMD_READ                       0x40
-#define ADT7310_CMD_CON_READ                   0x4
-
-#define ADT7410_IRQS                           2
-
-/*
- * struct adt7410_chip_info - chip specifc information
- */
-
-struct adt7410_chip_info;
-
-struct adt7410_ops {
-       int (*read_word)(struct adt7410_chip_info *, u8 reg, u16 *data);
-       int (*write_word)(struct adt7410_chip_info *, u8 reg, u16 data);
-       int (*read_byte)(struct adt7410_chip_info *, u8 reg, u8 *data);
-       int (*write_byte)(struct adt7410_chip_info *, u8 reg, u8 data);
-};
-
-struct adt7410_chip_info {
-       struct device *dev;
-       u8  config;
-
-       const struct adt7410_ops *ops;
-};
-
-static int adt7410_read_word(struct adt7410_chip_info *chip, u8 reg, u16 *data)
-{
-       return chip->ops->read_word(chip, reg, data);
-}
-
-static int adt7410_write_word(struct adt7410_chip_info *chip, u8 reg, u16 data)
-{
-       return chip->ops->write_word(chip, reg, data);
-}
-
-static int adt7410_read_byte(struct adt7410_chip_info *chip, u8 reg, u8 *data)
-{
-       return chip->ops->read_byte(chip, reg, data);
-}
-
-static int adt7410_write_byte(struct adt7410_chip_info *chip, u8 reg, u8 data)
-{
-       return chip->ops->write_byte(chip, reg, data);
-}
-
-static ssize_t adt7410_show_mode(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       u8 config;
-
-       config = chip->config & ADT7410_MODE_MASK;
-
-       switch (config) {
-       case ADT7410_PD:
-               return sprintf(buf, "power-down\n");
-       case ADT7410_ONESHOT:
-               return sprintf(buf, "one-shot\n");
-       case ADT7410_SPS:
-               return sprintf(buf, "sps\n");
-       default:
-               return sprintf(buf, "full\n");
-       }
-}
-
-static ssize_t adt7410_store_mode(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       u16 config;
-       int ret;
-
-       ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
-       if (ret)
-               return -EIO;
-
-       config = chip->config & (~ADT7410_MODE_MASK);
-       if (strcmp(buf, "power-down"))
-               config |= ADT7410_PD;
-       else if (strcmp(buf, "one-shot"))
-               config |= ADT7410_ONESHOT;
-       else if (strcmp(buf, "sps"))
-               config |= ADT7410_SPS;
-
-       ret = adt7410_write_byte(chip, ADT7410_CONFIG, config);
-       if (ret)
-               return -EIO;
-
-       chip->config = config;
-
-       return len;
-}
-
-static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
-               adt7410_show_mode,
-               adt7410_store_mode,
-               0);
-
-static ssize_t adt7410_show_available_modes(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       return sprintf(buf, "full\none-shot\nsps\npower-down\n");
-}
-
-static IIO_DEVICE_ATTR(available_modes, S_IRUGO, adt7410_show_available_modes, NULL, 0);
-
-static ssize_t adt7410_show_resolution(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       int ret;
-       int bits;
-
-       ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
-       if (ret)
-               return -EIO;
-
-       if (chip->config & ADT7410_RESOLUTION)
-               bits = 16;
-       else
-               bits = 13;
-
-       return sprintf(buf, "%d bits\n", bits);
-}
-
-static ssize_t adt7410_store_resolution(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       unsigned long data;
-       u16 config;
-       int ret;
-
-       ret = strict_strtoul(buf, 10, &data);
-       if (ret)
-               return -EINVAL;
-
-       ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
-       if (ret)
-               return -EIO;
-
-       config = chip->config & (~ADT7410_RESOLUTION);
-       if (data)
-               config |= ADT7410_RESOLUTION;
-
-       ret = adt7410_write_byte(chip, ADT7410_CONFIG, config);
-       if (ret)
-               return -EIO;
-
-       chip->config = config;
-
-       return len;
-}
-
-static IIO_DEVICE_ATTR(resolution, S_IRUGO | S_IWUSR,
-               adt7410_show_resolution,
-               adt7410_store_resolution,
-               0);
-
-static ssize_t adt7410_show_id(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       u8 id;
-       int ret;
-
-       ret = adt7410_read_byte(chip, ADT7410_ID, &id);
-       if (ret)
-               return -EIO;
-
-       return sprintf(buf, "device id: 0x%x\nmanufactory id: 0x%x\n",
-                       id & ADT7410_DEVICE_ID_MASK,
-                       (id & ADT7410_MANUFACTORY_ID_MASK) >> ADT7410_MANUFACTORY_ID_OFFSET);
-}
-
-static IIO_DEVICE_ATTR(id, S_IRUGO | S_IWUSR,
-               adt7410_show_id,
-               NULL,
-               0);
-
-static ssize_t adt7410_convert_temperature(struct adt7410_chip_info *chip,
-               u16 data, char *buf)
-{
-       char sign = ' ';
-
-       if (!(chip->config & ADT7410_RESOLUTION))
-               data &= ~0x7;
-
-       if (data & ADT7410_T16_VALUE_SIGN) {
-               /* convert supplement to positive value */
-               data = (u16)((ADT7410_T16_VALUE_SIGN << 1) - (u32)data);
-               sign = '-';
-       }
-       return sprintf(buf, "%c%d.%.7d\n", sign,
-                       (data >> ADT7410_T16_VALUE_FLOAT_OFFSET),
-                       (data & ADT7410_T16_VALUE_FLOAT_MASK) * 78125);
-}
-
-static ssize_t adt7410_show_value(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       u8 status;
-       u16 data;
-       int ret, i = 0;
-
-       do {
-               ret = adt7410_read_byte(chip, ADT7410_STATUS, &status);
-               if (ret)
-                       return -EIO;
-               i++;
-               if (i == 10000)
-                       return -EIO;
-       } while (status & ADT7410_STAT_NOT_RDY);
-
-       ret = adt7410_read_word(chip, ADT7410_TEMPERATURE, &data);
-       if (ret)
-               return -EIO;
-
-       return adt7410_convert_temperature(chip, data, buf);
-}
-
-static IIO_DEVICE_ATTR(value, S_IRUGO, adt7410_show_value, NULL, 0);
-
-static struct attribute *adt7410_attributes[] = {
-       &iio_dev_attr_available_modes.dev_attr.attr,
-       &iio_dev_attr_mode.dev_attr.attr,
-       &iio_dev_attr_resolution.dev_attr.attr,
-       &iio_dev_attr_id.dev_attr.attr,
-       &iio_dev_attr_value.dev_attr.attr,
-       NULL,
-};
-
-static const struct attribute_group adt7410_attribute_group = {
-       .attrs = adt7410_attributes,
-};
-
-static irqreturn_t adt7410_event_handler(int irq, void *private)
-{
-       struct iio_dev *indio_dev = private;
-       struct adt7410_chip_info *chip = iio_priv(indio_dev);
-       s64 timestamp = iio_get_time_ns();
-       u8 status;
-
-       if (adt7410_read_byte(chip, ADT7410_STATUS, &status))
-               return IRQ_HANDLED;
-
-       if (status & ADT7410_STAT_T_HIGH)
-               iio_push_event(indio_dev,
-                              IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0,
-                                                   IIO_EV_TYPE_THRESH,
-                                                   IIO_EV_DIR_RISING),
-                              timestamp);
-       if (status & ADT7410_STAT_T_LOW)
-               iio_push_event(indio_dev,
-                              IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0,
-                                                   IIO_EV_TYPE_THRESH,
-                                                   IIO_EV_DIR_FALLING),
-                              timestamp);
-       if (status & ADT7410_STAT_T_CRIT)
-               iio_push_event(indio_dev,
-                              IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0,
-                                                   IIO_EV_TYPE_THRESH,
-                                                   IIO_EV_DIR_RISING),
-                              timestamp);
-
-       return IRQ_HANDLED;
-}
-
-static ssize_t adt7410_show_event_mode(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       int ret;
-
-       ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
-       if (ret)
-               return -EIO;
-
-       if (chip->config & ADT7410_EVENT_MODE)
-               return sprintf(buf, "interrupt\n");
-       else
-               return sprintf(buf, "comparator\n");
-}
-
-static ssize_t adt7410_set_event_mode(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       u16 config;
-       int ret;
-
-       ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
-       if (ret)
-               return -EIO;
-
-       config = chip->config &= ~ADT7410_EVENT_MODE;
-       if (strcmp(buf, "comparator") != 0)
-               config |= ADT7410_EVENT_MODE;
-
-       ret = adt7410_write_byte(chip, ADT7410_CONFIG, config);
-       if (ret)
-               return -EIO;
-
-       chip->config = config;
-
-       return ret;
-}
-
-static ssize_t adt7410_show_available_event_modes(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       return sprintf(buf, "comparator\ninterrupt\n");
-}
-
-static ssize_t adt7410_show_fault_queue(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       int ret;
-
-       ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
-       if (ret)
-               return -EIO;
-
-       return sprintf(buf, "%d\n", chip->config & ADT7410_FAULT_QUEUE_MASK);
-}
-
-static ssize_t adt7410_set_fault_queue(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       unsigned long data;
-       int ret;
-       u8 config;
-
-       ret = strict_strtoul(buf, 10, &data);
-       if (ret || data > 3)
-               return -EINVAL;
-
-       ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
-       if (ret)
-               return -EIO;
-
-       config = chip->config & ~ADT7410_FAULT_QUEUE_MASK;
-       config |= data;
-       ret = adt7410_write_byte(chip, ADT7410_CONFIG, config);
-       if (ret)
-               return -EIO;
-
-       chip->config = config;
-
-       return ret;
-}
-
-static inline ssize_t adt7410_show_t_bound(struct device *dev,
-               struct device_attribute *attr,
-               u8 bound_reg,
-               char *buf)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       u16 data;
-       int ret;
-
-       ret = adt7410_read_word(chip, bound_reg, &data);
-       if (ret)
-               return -EIO;
-
-       return adt7410_convert_temperature(chip, data, buf);
-}
-
-static inline ssize_t adt7410_set_t_bound(struct device *dev,
-               struct device_attribute *attr,
-               u8 bound_reg,
-               const char *buf,
-               size_t len)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       long tmp1, tmp2;
-       u16 data;
-       char *pos;
-       int ret;
-
-       pos = strchr(buf, '.');
-
-       ret = strict_strtol(buf, 10, &tmp1);
-
-       if (ret || tmp1 > 127 || tmp1 < -128)
-               return -EINVAL;
-
-       if (pos) {
-               len = strlen(pos);
-
-               if (chip->config & ADT7410_RESOLUTION) {
-                       if (len > ADT7410_T16_VALUE_FLOAT_OFFSET)
-                               len = ADT7410_T16_VALUE_FLOAT_OFFSET;
-                       pos[len] = 0;
-                       ret = strict_strtol(pos, 10, &tmp2);
-
-                       if (!ret)
-                               tmp2 = (tmp2 / 78125) * 78125;
-               } else {
-                       if (len > ADT7410_T13_VALUE_FLOAT_OFFSET)
-                               len = ADT7410_T13_VALUE_FLOAT_OFFSET;
-                       pos[len] = 0;
-                       ret = strict_strtol(pos, 10, &tmp2);
-
-                       if (!ret)
-                               tmp2 = (tmp2 / 625) * 625;
-               }
-       }
-
-       if (tmp1 < 0)
-               data = (u16)(-tmp1);
-       else
-               data = (u16)tmp1;
-
-       if (chip->config & ADT7410_RESOLUTION) {
-               data = (data << ADT7410_T16_VALUE_FLOAT_OFFSET) |
-                       (tmp2 & ADT7410_T16_VALUE_FLOAT_MASK);
-
-               if (tmp1 < 0)
-                       /* convert positive value to supplyment */
-                       data = (u16)((ADT7410_T16_VALUE_SIGN << 1) - (u32)data);
-       } else {
-               data = (data << ADT7410_T13_VALUE_FLOAT_OFFSET) |
-                       (tmp2 & ADT7410_T13_VALUE_FLOAT_MASK);
-
-               if (tmp1 < 0)
-                       /* convert positive value to supplyment */
-                       data = (ADT7410_T13_VALUE_SIGN << 1) - data;
-               data <<= ADT7410_T13_VALUE_OFFSET;
-       }
-
-       ret = adt7410_write_word(chip, bound_reg, data);
-       if (ret)
-               return -EIO;
-
-       return ret;
-}
-
-static ssize_t adt7410_show_t_alarm_high(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       return adt7410_show_t_bound(dev, attr,
-                       ADT7410_T_ALARM_HIGH, buf);
-}
-
-static inline ssize_t adt7410_set_t_alarm_high(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
-{
-       return adt7410_set_t_bound(dev, attr,
-                       ADT7410_T_ALARM_HIGH, buf, len);
-}
-
-static ssize_t adt7410_show_t_alarm_low(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       return adt7410_show_t_bound(dev, attr,
-                       ADT7410_T_ALARM_LOW, buf);
-}
-
-static inline ssize_t adt7410_set_t_alarm_low(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
-{
-       return adt7410_set_t_bound(dev, attr,
-                       ADT7410_T_ALARM_LOW, buf, len);
-}
-
-static ssize_t adt7410_show_t_crit(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       return adt7410_show_t_bound(dev, attr,
-                       ADT7410_T_CRIT, buf);
-}
-
-static inline ssize_t adt7410_set_t_crit(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
-{
-       return adt7410_set_t_bound(dev, attr,
-                       ADT7410_T_CRIT, buf, len);
-}
-
-static ssize_t adt7410_show_t_hyst(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       int ret;
-       u8 t_hyst;
-
-       ret = adt7410_read_byte(chip, ADT7410_T_HYST, &t_hyst);
-       if (ret)
-               return -EIO;
-
-       return sprintf(buf, "%d\n", t_hyst & ADT7410_T_HYST_MASK);
-}
-
-static inline ssize_t adt7410_set_t_hyst(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
-{
-       struct iio_dev *dev_info = dev_to_iio_dev(dev);
-       struct adt7410_chip_info *chip = iio_priv(dev_info);
-       int ret;
-       unsigned long data;
-       u8 t_hyst;
-
-       ret = strict_strtol(buf, 10, &data);
-
-       if (ret || data > ADT7410_T_HYST_MASK)
-               return -EINVAL;
-
-       t_hyst = (u8)data;
-
-       ret = adt7410_write_byte(chip, ADT7410_T_HYST, t_hyst);
-       if (ret)
-               return -EIO;
-
-       return ret;
-}
-
-static IIO_DEVICE_ATTR(event_mode,
-                      S_IRUGO | S_IWUSR,
-                      adt7410_show_event_mode, adt7410_set_event_mode, 0);
-static IIO_DEVICE_ATTR(available_event_modes,
-                      S_IRUGO,
-                      adt7410_show_available_event_modes, NULL, 0);
-static IIO_DEVICE_ATTR(fault_queue,
-                      S_IRUGO | S_IWUSR,
-                      adt7410_show_fault_queue, adt7410_set_fault_queue, 0);
-static IIO_DEVICE_ATTR(t_alarm_high,
-                      S_IRUGO | S_IWUSR,
-                      adt7410_show_t_alarm_high, adt7410_set_t_alarm_high, 0);
-static IIO_DEVICE_ATTR(t_alarm_low,
-                      S_IRUGO | S_IWUSR,
-                      adt7410_show_t_alarm_low, adt7410_set_t_alarm_low, 0);
-static IIO_DEVICE_ATTR(t_crit,
-                      S_IRUGO | S_IWUSR,
-                      adt7410_show_t_crit, adt7410_set_t_crit, 0);
-static IIO_DEVICE_ATTR(t_hyst,
-                      S_IRUGO | S_IWUSR,
-                      adt7410_show_t_hyst, adt7410_set_t_hyst, 0);
-
-static struct attribute *adt7410_event_int_attributes[] = {
-       &iio_dev_attr_event_mode.dev_attr.attr,
-       &iio_dev_attr_available_event_modes.dev_attr.attr,
-       &iio_dev_attr_fault_queue.dev_attr.attr,
-       &iio_dev_attr_t_alarm_high.dev_attr.attr,
-       &iio_dev_attr_t_alarm_low.dev_attr.attr,
-       &iio_dev_attr_t_crit.dev_attr.attr,
-       &iio_dev_attr_t_hyst.dev_attr.attr,
-       NULL,
-};
-
-static struct attribute_group adt7410_event_attribute_group = {
-       .attrs = adt7410_event_int_attributes,
-       .name = "events",
-};
-
-static const struct iio_info adt7410_info = {
-       .attrs = &adt7410_attribute_group,
-       .event_attrs = &adt7410_event_attribute_group,
-       .driver_module = THIS_MODULE,
-};
-
-/*
- * device probe and remove
- */
-
-static int adt7410_probe(struct device *dev, int irq,
-       const char *name, const struct adt7410_ops *ops)
-{
-       unsigned long *adt7410_platform_data = dev->platform_data;
-       unsigned long local_pdata[] = {0, 0};
-       struct adt7410_chip_info *chip;
-       struct iio_dev *indio_dev;
-       int ret = 0;
-
-       indio_dev = iio_device_alloc(sizeof(*chip));
-       if (indio_dev == NULL) {
-               ret = -ENOMEM;
-               goto error_ret;
-       }
-       chip = iio_priv(indio_dev);
-       /* this is only used for device removal purposes */
-       dev_set_drvdata(dev, indio_dev);
-
-       chip->dev = dev;
-       chip->ops = ops;
-
-       indio_dev->name = name;
-       indio_dev->dev.parent = dev;
-       indio_dev->info = &adt7410_info;
-       indio_dev->modes = INDIO_DIRECT_MODE;
-
-       if (!adt7410_platform_data)
-               adt7410_platform_data = local_pdata;
-
-       /* CT critcal temperature event. line 0 */
-       if (irq) {
-               ret = request_threaded_irq(irq,
-                                          NULL,
-                                          &adt7410_event_handler,
-                                          IRQF_TRIGGER_LOW | IRQF_ONESHOT,
-                                          name,
-                                          indio_dev);
-               if (ret)
-                       goto error_free_dev;
-       }
-
-       /* INT bound temperature alarm event. line 1 */
-       if (adt7410_platform_data[0]) {
-               ret = request_threaded_irq(adt7410_platform_data[0],
-                                          NULL,
-                                          &adt7410_event_handler,
-                                          adt7410_platform_data[1] |
-                                          IRQF_ONESHOT,
-                                          name,
-                                          indio_dev);
-               if (ret)
-                       goto error_unreg_ct_irq;
-       }
-
-       ret = adt7410_read_byte(chip, ADT7410_CONFIG, &chip->config);
-       if (ret) {
-               ret = -EIO;
-               goto error_unreg_int_irq;
-       }
-
-       chip->config |= ADT7410_RESOLUTION;
-
-       if (irq && adt7410_platform_data[0]) {
-
-               /* set irq polarity low level */
-               chip->config &= ~ADT7410_CT_POLARITY;
-
-               if (adt7410_platform_data[1] & IRQF_TRIGGER_HIGH)
-                       chip->config |= ADT7410_INT_POLARITY;
-               else
-                       chip->config &= ~ADT7410_INT_POLARITY;
-       }
-
-       ret = adt7410_write_byte(chip, ADT7410_CONFIG, chip->config);
-       if (ret) {
-               ret = -EIO;
-               goto error_unreg_int_irq;
-       }
-       ret = iio_device_register(indio_dev);
-       if (ret)
-               goto error_unreg_int_irq;
-
-       dev_info(dev, "%s temperature sensor registered.\n",
-                        name);
-
-       return 0;
-
-error_unreg_int_irq:
-       free_irq(adt7410_platform_data[0], indio_dev);
-error_unreg_ct_irq:
-       free_irq(irq, indio_dev);
-error_free_dev:
-       iio_device_free(indio_dev);
-error_ret:
-       return ret;
-}
-
-static int adt7410_remove(struct device *dev, int irq)
-{
-       struct iio_dev *indio_dev = dev_get_drvdata(dev);
-       unsigned long *adt7410_platform_data = dev->platform_data;
-
-       iio_device_unregister(indio_dev);
-       if (adt7410_platform_data[0])
-               free_irq(adt7410_platform_data[0], indio_dev);
-       if (irq)
-               free_irq(irq, indio_dev);
-       iio_device_free(indio_dev);
-
-       return 0;
-}
-
-#if IS_ENABLED(CONFIG_I2C)
-
-static int adt7410_i2c_read_word(struct adt7410_chip_info *chip, u8 reg,
-       u16 *data)
-{
-       struct i2c_client *client = to_i2c_client(chip->dev);
-       int ret = 0;
-
-       ret = i2c_smbus_read_word_data(client, reg);
-       if (ret < 0) {
-               dev_err(&client->dev, "I2C read error\n");
-               return ret;
-       }
-
-       *data = swab16((u16)ret);
-
-       return 0;
-}
-
-static int adt7410_i2c_write_word(struct adt7410_chip_info *chip, u8 reg,
-       u16 data)
-{
-       struct i2c_client *client = to_i2c_client(chip->dev);
-       int ret = 0;
-
-       ret = i2c_smbus_write_word_data(client, reg, swab16(data));
-       if (ret < 0)
-               dev_err(&client->dev, "I2C write error\n");
-
-       return ret;
-}
-
-static int adt7410_i2c_read_byte(struct adt7410_chip_info *chip, u8 reg,
-       u8 *data)
-{
-       struct i2c_client *client = to_i2c_client(chip->dev);
-       int ret = 0;
-
-       ret = i2c_smbus_read_byte_data(client, reg);
-       if (ret < 0) {
-               dev_err(&client->dev, "I2C read error\n");
-               return ret;
-       }
-
-       *data = (u8)ret;
-
-       return 0;
-}
-
-static int adt7410_i2c_write_byte(struct adt7410_chip_info *chip, u8 reg,
-       u8 data)
-{
-       struct i2c_client *client = to_i2c_client(chip->dev);
-       int ret = 0;
-
-       ret = i2c_smbus_write_byte_data(client, reg, data);
-       if (ret < 0)
-               dev_err(&client->dev, "I2C write error\n");
-
-       return ret;
-}
-
-static const struct adt7410_ops adt7410_i2c_ops = {
-       .read_word = adt7410_i2c_read_word,
-       .write_word = adt7410_i2c_write_word,
-       .read_byte = adt7410_i2c_read_byte,
-       .write_byte = adt7410_i2c_write_byte,
-};
-
-static int adt7410_i2c_probe(struct i2c_client *client,
-       const struct i2c_device_id *id)
-{
-       return adt7410_probe(&client->dev, client->irq, id->name,
-               &adt7410_i2c_ops);
-}
-
-static int adt7410_i2c_remove(struct i2c_client *client)
-{
-       return adt7410_remove(&client->dev, client->irq);
-}
-
-static const struct i2c_device_id adt7410_id[] = {
-       { "adt7410", 0 },
-       {}
-};
-
-MODULE_DEVICE_TABLE(i2c, adt7410_id);
-
-static struct i2c_driver adt7410_driver = {
-       .driver = {
-               .name = "adt7410",
-       },
-       .probe = adt7410_i2c_probe,
-       .remove = adt7410_i2c_remove,
-       .id_table = adt7410_id,
-};
-
-static int __init adt7410_i2c_init(void)
-{
-       return i2c_add_driver(&adt7410_driver);
-}
-
-static void __exit adt7410_i2c_exit(void)
-{
-       i2c_del_driver(&adt7410_driver);
-}
-
-#else
-
-static int  __init adt7410_i2c_init(void) { return 0; };
-static void __exit adt7410_i2c_exit(void) {};
-
-#endif
-
-#if IS_ENABLED(CONFIG_SPI_MASTER)
-
-static const u8 adt7371_reg_table[] = {
-       [ADT7410_TEMPERATURE]   = ADT7310_TEMPERATURE,
-       [ADT7410_STATUS]        = ADT7310_STATUS,
-       [ADT7410_CONFIG]        = ADT7310_CONFIG,
-       [ADT7410_T_ALARM_HIGH]  = ADT7310_T_ALARM_HIGH,
-       [ADT7410_T_ALARM_LOW]   = ADT7310_T_ALARM_LOW,
-       [ADT7410_T_CRIT]        = ADT7310_T_CRIT,
-       [ADT7410_T_HYST]        = ADT7310_T_HYST,
-       [ADT7410_ID]            = ADT7310_ID,
-};
-
-#define AD7310_COMMAND(reg) (adt7371_reg_table[(reg)] << ADT7310_CMD_REG_OFFSET)
-
-static int adt7310_spi_read_word(struct adt7410_chip_info *chip,
-       u8 reg, u16 *data)
-{
-       struct spi_device *spi = to_spi_device(chip->dev);
-       u8 command = AD7310_COMMAND(reg);
-       int ret = 0;
-
-       command |= ADT7310_CMD_READ;
-       ret = spi_write(spi, &command, sizeof(command));
-       if (ret < 0) {
-               dev_err(&spi->dev, "SPI write command error\n");
-               return ret;
-       }
-
-       ret = spi_read(spi, (u8 *)data, sizeof(*data));
-       if (ret < 0) {
-               dev_err(&spi->dev, "SPI read word error\n");
-               return ret;
-       }
-
-       *data = be16_to_cpu(*data);
-
-       return 0;
-}
-
-static int adt7310_spi_write_word(struct adt7410_chip_info *chip, u8 reg,
-       u16 data)
-{
-       struct spi_device *spi = to_spi_device(chip->dev);
-       u8 buf[3];
-       int ret = 0;
-
-       buf[0] = AD7310_COMMAND(reg);
-       buf[1] = (u8)(data >> 8);
-       buf[2] = (u8)(data & 0xFF);
-
-       ret = spi_write(spi, buf, 3);
-       if (ret < 0) {
-               dev_err(&spi->dev, "SPI write word error\n");
-               return ret;
-       }
-
-       return ret;
-}
-
-static int adt7310_spi_read_byte(struct adt7410_chip_info *chip, u8 reg,
-       u8 *data)
-{
-       struct spi_device *spi = to_spi_device(chip->dev);
-       u8 command = AD7310_COMMAND(reg);
-       int ret = 0;
-
-       command |= ADT7310_CMD_READ;
-       ret = spi_write(spi, &command, sizeof(command));
-       if (ret < 0) {
-               dev_err(&spi->dev, "SPI write command error\n");
-               return ret;
-       }
-
-       ret = spi_read(spi, data, sizeof(*data));
-       if (ret < 0) {
-               dev_err(&spi->dev, "SPI read byte error\n");
-               return ret;
-       }
-
-       return 0;
-}
-
-static int adt7310_spi_write_byte(struct adt7410_chip_info *chip, u8 reg,
-       u8 data)
-{
-       struct spi_device *spi = to_spi_device(chip->dev);
-       u8 buf[2];
-       int ret = 0;
-
-       buf[0] = AD7310_COMMAND(reg);
-       buf[1] = data;
-
-       ret = spi_write(spi, buf, 2);
-       if (ret < 0) {
-               dev_err(&spi->dev, "SPI write byte error\n");
-               return ret;
-       }
-
-       return ret;
-}
-
-static const struct adt7410_ops adt7310_spi_ops = {
-       .read_word = adt7310_spi_read_word,
-       .write_word = adt7310_spi_write_word,
-       .read_byte = adt7310_spi_read_byte,
-       .write_byte = adt7310_spi_write_byte,
-};
-
-static int adt7310_spi_probe(struct spi_device *spi)
-{
-       return adt7410_probe(&spi->dev, spi->irq,
-               spi_get_device_id(spi)->name, &adt7310_spi_ops);
-}
-
-static int adt7310_spi_remove(struct spi_device *spi)
-{
-       return adt7410_remove(&spi->dev, spi->irq);
-}
-
-static const struct spi_device_id adt7310_id[] = {
-       { "adt7310", 0 },
-       {}
-};
-MODULE_DEVICE_TABLE(spi, adt7310_id);
-
-static struct spi_driver adt7310_driver = {
-       .driver = {
-               .name = "adt7310",
-               .owner = THIS_MODULE,
-       },
-       .probe = adt7310_spi_probe,
-       .remove = adt7310_spi_remove,
-       .id_table = adt7310_id,
-};
-
-static int __init adt7310_spi_init(void)
-{
-       return spi_register_driver(&adt7310_driver);
-}
-
-static void adt7310_spi_exit(void)
-{
-       spi_unregister_driver(&adt7310_driver);
-}
-
-#else
-
-static int __init adt7310_spi_init(void) { return 0; };
-static void adt7310_spi_exit(void) {};
-
-#endif
-
-static int __init adt7410_init(void)
-{
-       int ret;
-
-       ret = adt7310_spi_init();
-       if (ret)
-               return ret;
-
-       ret = adt7410_i2c_init();
-       if (ret)
-               adt7310_spi_exit();
-
-       return ret;
-}
-module_init(adt7410_init);
-
-static void __exit adt7410_exit(void)
-{
-       adt7410_i2c_exit();
-       adt7310_spi_exit();
-}
-module_exit(adt7410_exit);
-
-MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
-MODULE_DESCRIPTION("Analog Devices ADT7310/ADT7410 digital temperature sensor driver");
-MODULE_LICENSE("GPL v2");
index 0bf2a6cc79e0507ac93b546306f4fb1d488d09a6..2f2f7fdd06913b7bfbdafd7a077c83deb779b9f5 100644 (file)
@@ -103,7 +103,7 @@ static const struct iio_info lpc32xx_adc_iio_info = {
        .type = IIO_VOLTAGE,                            \
        .indexed = 1,                                   \
        .channel = _index,                              \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,    \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
        .address = AD_IN * _index,                      \
        .scan_index = _index,                           \
 }
index 55a459b619070d1752d2473cd5fe6392b7d976aa..6044e1717b20ec5b8488132ecbd29dd34a527ae0 100644 (file)
@@ -646,7 +646,7 @@ static irqreturn_t mxs_lradc_trigger_handler(int irq, void *p)
 
 static int mxs_lradc_configure_trigger(struct iio_trigger *trig, bool state)
 {
-       struct iio_dev *iio = trig->private_data;
+       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;
 
@@ -670,7 +670,7 @@ static int mxs_lradc_trigger_init(struct iio_dev *iio)
                return -ENOMEM;
 
        trig->dev.parent = iio->dev.parent;
-       trig->private_data = iio;
+       iio_trigger_set_drvdata(trig, iio);
        trig->ops = &mxs_lradc_trigger_ops;
 
        ret = iio_trigger_register(trig);
@@ -822,7 +822,7 @@ static const struct iio_buffer_setup_ops mxs_lradc_buffer_ops = {
        .type = (chan_type),                                    \
        .indexed = 1,                                           \
        .scan_index = (idx),                                    \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,            \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
        .channel = (idx),                                       \
        .scan_type = {                                          \
                .sign = 'u',                                    \
@@ -983,6 +983,9 @@ static int mxs_lradc_probe(struct platform_device *pdev)
        if (ret)
                goto err_trig;
 
+       /* Configure the hardware. */
+       mxs_lradc_hw_init(lradc);
+
        /* Register the touchscreen input device. */
        ret = mxs_lradc_ts_register(lradc);
        if (ret)
@@ -995,9 +998,6 @@ static int mxs_lradc_probe(struct platform_device *pdev)
                goto err_ts;
        }
 
-       /* Configure the hardware. */
-       mxs_lradc_hw_init(lradc);
-
        return 0;
 
 err_ts:
index 13052ceb2f2b062a9f34e86f7fac5fba16fcc0a5..f45da4266950aca0dcfae51aba7b49fea47c40a6 100644 (file)
@@ -180,8 +180,8 @@ static int spear_read_raw(struct iio_dev *indio_dev,
 #define SPEAR_ADC_CHAN(idx) {                          \
        .type = IIO_VOLTAGE,                            \
        .indexed = 1,                                   \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |   \
-       IIO_CHAN_INFO_SCALE_SHARED_BIT,                 \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
        .channel = idx,                                 \
        .scan_type = {                                  \
                .sign = 'u',                            \
index 3c608c14dd998ecb6b45054e9637e26b7ce516bf..687dd2c914378a0a3a77ff4714eff02f77abd0ef 100644 (file)
@@ -429,8 +429,8 @@ static const struct iio_chan_spec ad7150_channels[] = {
                .type = IIO_CAPACITANCE,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_AVERAGE_RAW),
                .event_mask =
                IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |
                IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) |
@@ -442,8 +442,8 @@ static const struct iio_chan_spec ad7150_channels[] = {
                .type = IIO_CAPACITANCE,
                .indexed = 1,
                .channel = 1,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_AVERAGE_RAW),
                .event_mask =
                IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) |
                IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING) |
index 3c92ba3722a81b4c795cb650ff428163feefc5d4..1d7c5283a85c4173d345610c08ad79958bb28414 100644 (file)
@@ -436,38 +436,38 @@ static const struct iio_chan_spec ad7152_channels[] = {
                .type = IIO_CAPACITANCE,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_CALIBSCALE) |
+               BIT(IIO_CHAN_INFO_CALIBBIAS) |
+               BIT(IIO_CHAN_INFO_SCALE),
        }, {
                .type = IIO_CAPACITANCE,
                .differential = 1,
                .indexed = 1,
                .channel = 0,
                .channel2 = 2,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_CALIBSCALE) |
+               BIT(IIO_CHAN_INFO_CALIBBIAS) |
+               BIT(IIO_CHAN_INFO_SCALE),
        }, {
                .type = IIO_CAPACITANCE,
                .indexed = 1,
                .channel = 1,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_CALIBSCALE) |
+               BIT(IIO_CHAN_INFO_CALIBBIAS) |
+               BIT(IIO_CHAN_INFO_SCALE),
        }, {
                .type = IIO_CAPACITANCE,
                .differential = 1,
                .indexed = 1,
                .channel = 1,
                .channel2 = 3,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_CALIBSCALE) |
+               BIT(IIO_CHAN_INFO_CALIBBIAS) |
+               BIT(IIO_CHAN_INFO_SCALE),
        }
 };
 /*
index 466b82ecfbe0bc14fbf75affe2d08d1c0f4e1cb0..94f9ca726d1c1506e51a7672b69550a612f00029 100644 (file)
@@ -123,8 +123,8 @@ static const struct iio_chan_spec ad7746_channels[] = {
                .type = IIO_VOLTAGE,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7746_REG_VT_DATA_HIGH << 8 |
                        AD7746_VTSETUP_VTMD_EXT_VIN,
        },
@@ -133,8 +133,8 @@ static const struct iio_chan_spec ad7746_channels[] = {
                .indexed = 1,
                .channel = 1,
                .extend_name = "supply",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7746_REG_VT_DATA_HIGH << 8 |
                        AD7746_VTSETUP_VTMD_VDD_MON,
        },
@@ -142,7 +142,7 @@ static const struct iio_chan_spec ad7746_channels[] = {
                .type = IIO_TEMP,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
                .address = AD7746_REG_VT_DATA_HIGH << 8 |
                        AD7746_VTSETUP_VTMD_INT_TEMP,
        },
@@ -150,7 +150,7 @@ static const struct iio_chan_spec ad7746_channels[] = {
                .type = IIO_TEMP,
                .indexed = 1,
                .channel = 1,
-               .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
                .address = AD7746_REG_VT_DATA_HIGH << 8 |
                        AD7746_VTSETUP_VTMD_EXT_TEMP,
        },
@@ -158,11 +158,10 @@ static const struct iio_chan_spec ad7746_channels[] = {
                .type = IIO_CAPACITANCE,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT |
-               IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) |
+               BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7746_REG_CAP_DATA_HIGH << 8,
        },
        [CIN1_DIFF] = {
@@ -171,11 +170,10 @@ static const struct iio_chan_spec ad7746_channels[] = {
                .indexed = 1,
                .channel = 0,
                .channel2 = 2,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT |
-               IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) |
+               BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7746_REG_CAP_DATA_HIGH << 8 |
                        AD7746_CAPSETUP_CAPDIFF
        },
@@ -183,11 +181,10 @@ static const struct iio_chan_spec ad7746_channels[] = {
                .type = IIO_CAPACITANCE,
                .indexed = 1,
                .channel = 1,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT |
-               IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) |
+               BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7746_REG_CAP_DATA_HIGH << 8 |
                        AD7746_CAPSETUP_CIN2,
        },
@@ -197,11 +194,10 @@ static const struct iio_chan_spec ad7746_channels[] = {
                .indexed = 1,
                .channel = 1,
                .channel2 = 3,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT |
-               IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) |
+               BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7746_REG_CAP_DATA_HIGH << 8 |
                        AD7746_CAPSETUP_CAPDIFF | AD7746_CAPSETUP_CIN2,
        }
index 687c151f9847961e4880a7612cb0c4136d10b0ec..c67d3a832aef982a62f13c34245e46672ac6d599 100644 (file)
@@ -120,27 +120,26 @@ static const struct iio_chan_spec adis16060_channels[] = {
                .type = IIO_ANGL_VEL,
                .modified = 1,
                .channel2 = IIO_MOD_Z,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .address = ADIS16060_GYRO,
        }, {
                .type = IIO_VOLTAGE,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .address = ADIS16060_AIN1,
        }, {
                .type = IIO_VOLTAGE,
                .indexed = 1,
                .channel = 1,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .address = ADIS16060_AIN2,
        }, {
                .type = IIO_TEMP,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_SCALE),
                .address = ADIS16060_TEMP_OUT,
        }
 };
index 835801ee7e8099327a7c38e692e76d36a754baf3..531b803cb2ac4c79dd79b1681604a0802439a737 100644 (file)
@@ -100,13 +100,13 @@ static const struct iio_chan_spec adis16130_channels[] = {
                .type = IIO_ANGL_VEL,
                .modified = 1,
                .channel2 = IIO_MOD_Z,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .address = ADIS16130_RATEDATA,
        }, {
                .type = IIO_TEMP,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .address = ADIS16130_TEMPDATA,
        }
 };
index 6e80b8c768ae0075b6627e9383d080c09cf3f74d..620d63fd099bcb10089e9ebb1b3a7b86dc53c9ba 100644 (file)
@@ -124,8 +124,8 @@ static IIO_DEVICE_ATTR(sampling_frequency_available,
 #define ADIS16260_GYRO_CHANNEL_SET(axis, mod)                          \
 struct iio_chan_spec adis16260_channels_##axis[] = {           \
        ADIS_GYRO_CHAN(mod, ADIS16260_GYRO_OUT, ADIS16260_SCAN_GYRO, \
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT, 14), \
+               BIT(IIO_CHAN_INFO_CALIBBIAS) | \
+               BIT(IIO_CHAN_INFO_CALIBSCALE), 14), \
        ADIS_INCLI_CHAN(mod, ADIS16260_ANGL_OUT, ADIS16260_SCAN_ANGL, 0, 14), \
        ADIS_TEMP_CHAN(ADIS16260_TEMP_OUT, ADIS16260_SCAN_TEMP, 12), \
        ADIS_SUPPLY_CHAN(ADIS16260_SUPPLY_OUT, ADIS16260_SCAN_SUPPLY, 12), \
diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
deleted file mode 100644 (file)
index 93af756..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-/* Hwmon client for industrial I/O devices
- *
- * Copyright (c) 2011 Jonathan Cameron
- *
- * 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/slab.h>
-#include <linux/module.h>
-#include <linux/err.h>
-#include <linux/platform_device.h>
-#include <linux/hwmon.h>
-#include <linux/hwmon-sysfs.h>
-#include <linux/iio/consumer.h>
-#include <linux/iio/types.h>
-
-/**
- * struct iio_hwmon_state - device instance state
- * @channels:          filled with array of channels from iio
- * @num_channels:      number of channels in channels (saves counting twice)
- * @hwmon_dev:         associated hwmon device
- * @attr_group:        the group of attributes
- * @attrs:             null terminated array of attribute pointers.
- */
-struct iio_hwmon_state {
-       struct iio_channel *channels;
-       int num_channels;
-       struct device *hwmon_dev;
-       struct attribute_group attr_group;
-       struct attribute **attrs;
-};
-
-/*
- * Assumes that IIO and hwmon operate in the same base units.
- * This is supposed to be true, but needs verification for
- * new channel types.
- */
-static ssize_t iio_hwmon_read_val(struct device *dev,
-                                 struct device_attribute *attr,
-                                 char *buf)
-{
-       int result;
-       int ret;
-       struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
-       struct iio_hwmon_state *state = dev_get_drvdata(dev);
-
-       ret = iio_read_channel_processed(&state->channels[sattr->index],
-                                       &result);
-       if (ret < 0)
-               return ret;
-
-       return sprintf(buf, "%d\n", result);
-}
-
-static ssize_t show_name(struct device *dev, struct device_attribute *attr,
-                        char *buf)
-{
-       return sprintf(buf, "iio_hwmon\n");
-}
-
-static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
-
-static int iio_hwmon_probe(struct platform_device *pdev)
-{
-       struct device *dev = &pdev->dev;
-       struct iio_hwmon_state *st;
-       struct sensor_device_attribute *a;
-       int ret, i;
-       int in_i = 1, temp_i = 1, curr_i = 1;
-       enum iio_chan_type type;
-       struct iio_channel *channels;
-
-       channels = iio_channel_get_all(dev);
-       if (IS_ERR(channels))
-               return PTR_ERR(channels);
-
-       st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL);
-       if (st == NULL)
-               return -ENOMEM;
-
-       st->channels = channels;
-
-       /* count how many attributes we have */
-       while (st->channels[st->num_channels].indio_dev)
-               st->num_channels++;
-
-       st->attrs = devm_kzalloc(dev,
-                                sizeof(*st->attrs) * (st->num_channels + 2),
-                                GFP_KERNEL);
-       if (st->attrs == NULL) {
-               ret = -ENOMEM;
-               goto error_release_channels;
-       }
-
-       for (i = 0; i < st->num_channels; i++) {
-               a = devm_kzalloc(dev, sizeof(*a), GFP_KERNEL);
-               if (a == NULL) {
-                       ret = -ENOMEM;
-                       goto error_release_channels;
-               }
-
-               sysfs_attr_init(&a->dev_attr.attr);
-               ret = iio_get_channel_type(&st->channels[i], &type);
-               if (ret < 0)
-                       goto error_release_channels;
-
-               switch (type) {
-               case IIO_VOLTAGE:
-                       a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
-                                                         "in%d_input",
-                                                         in_i++);
-                       break;
-               case IIO_TEMP:
-                       a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
-                                                         "temp%d_input",
-                                                         temp_i++);
-                       break;
-               case IIO_CURRENT:
-                       a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
-                                                         "curr%d_input",
-                                                         curr_i++);
-                       break;
-               default:
-                       ret = -EINVAL;
-                       goto error_release_channels;
-               }
-               if (a->dev_attr.attr.name == NULL) {
-                       ret = -ENOMEM;
-                       goto error_release_channels;
-               }
-               a->dev_attr.show = iio_hwmon_read_val;
-               a->dev_attr.attr.mode = S_IRUGO;
-               a->index = i;
-               st->attrs[i] = &a->dev_attr.attr;
-       }
-       st->attrs[st->num_channels] = &dev_attr_name.attr;
-       st->attr_group.attrs = st->attrs;
-       platform_set_drvdata(pdev, st);
-       ret = sysfs_create_group(&dev->kobj, &st->attr_group);
-       if (ret < 0)
-               goto error_release_channels;
-
-       st->hwmon_dev = hwmon_device_register(dev);
-       if (IS_ERR(st->hwmon_dev)) {
-               ret = PTR_ERR(st->hwmon_dev);
-               goto error_remove_group;
-       }
-       return 0;
-
-error_remove_group:
-       sysfs_remove_group(&dev->kobj, &st->attr_group);
-error_release_channels:
-       iio_channel_release_all(st->channels);
-       return ret;
-}
-
-static int iio_hwmon_remove(struct platform_device *pdev)
-{
-       struct iio_hwmon_state *st = platform_get_drvdata(pdev);
-
-       hwmon_device_unregister(st->hwmon_dev);
-       sysfs_remove_group(&pdev->dev.kobj, &st->attr_group);
-       iio_channel_release_all(st->channels);
-
-       return 0;
-}
-
-static struct of_device_id iio_hwmon_of_match[] = {
-       { .compatible = "iio-hwmon", },
-       { }
-};
-
-static struct platform_driver __refdata iio_hwmon_driver = {
-       .driver = {
-               .name = "iio_hwmon",
-               .owner = THIS_MODULE,
-               .of_match_table = iio_hwmon_of_match,
-       },
-       .probe = iio_hwmon_probe,
-       .remove = iio_hwmon_remove,
-};
-
-module_platform_driver(iio_hwmon_driver);
-
-MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
-MODULE_DESCRIPTION("IIO to hwmon driver");
-MODULE_LICENSE("GPL v2");
index aee76c710a3b5def2f2110b4fcf36f39f2a713de..0193e1796b18d876c8782e2143c275c9afd8acd5 100644 (file)
@@ -71,25 +71,25 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
                .indexed = 1,
                .channel = 0,
                /* What other information is available? */
-               .info_mask =
+               .info_mask_separate =
                /*
                 * in_voltage0_raw
                 * Raw (unscaled no bias removal etc) measurement
                 * from the device.
                 */
-               IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+               BIT(IIO_CHAN_INFO_RAW) |
                /*
                 * in_voltage0_offset
                 * Offset for userspace to apply prior to scale
                 * when converting to standard units (microvolts)
                 */
-               IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
+               BIT(IIO_CHAN_INFO_OFFSET) |
                /*
                 * in_voltage0_scale
                 * Multipler for userspace to apply post offset
                 * when converting to standard units (microvolts)
                 */
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               BIT(IIO_CHAN_INFO_SCALE),
                /* The ordering of elements in the buffer via an enum */
                .scan_index = voltage0,
                .scan_type = { /* Description of storage in buffer */
@@ -118,19 +118,18 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
                .indexed = 1,
                .channel = 1,
                .channel2 = 2,
-               .info_mask =
                /*
                 * in_voltage1-voltage2_raw
                 * Raw (unscaled no bias removal etc) measurement
                 * from the device.
                 */
-               IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                /*
                 * in_voltage-voltage_scale
                 * Shared version of scale - shared by differential
                 * input channels of type IIO_VOLTAGE.
                 */
-               IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .scan_index = diffvoltage1m2,
                .scan_type = { /* Description of storage in buffer */
                        .sign = 's', /* signed */
@@ -146,9 +145,8 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
                .indexed = 1,
                .channel = 3,
                .channel2 = 4,
-               .info_mask =
-               IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .scan_index = diffvoltage3m4,
                .scan_type = {
                        .sign = 's',
@@ -166,15 +164,14 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
                .modified = 1,
                /* Channel 2 is use for modifiers */
                .channel2 = IIO_MOD_X,
-               .info_mask =
-               IIO_CHAN_INFO_RAW_SEPARATE_BIT |
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
                /*
                 * Internal bias correction value. Applied
                 * by the hardware or driver prior to userspace
                 * seeing the readings. Typically part of hardware
                 * calibration.
                 */
-               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
+               BIT(IIO_CHAN_INFO_CALIBBIAS),
                .scan_index = accelx,
                .scan_type = { /* Description of storage in buffer */
                        .sign = 's', /* signed */
@@ -191,7 +188,7 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
        /* DAC channel out_voltage0_raw */
        {
                .type = IIO_VOLTAGE,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .output = 1,
                .indexed = 1,
                .channel = 0,
@@ -204,8 +201,8 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
  * @chan:      the channel whose data is to be read
  * @val:       first element of returned value (typically INT)
  * @val2:      second element of returned value (typically MICRO)
- * @mask:      what we actually want to read. 0 is the channel, everything else
- *             is as per the info_mask in iio_chan_spec.
+ * @mask:      what we actually want to read as per the info_mask_*
+ *             in iio_chan_spec.
  */
 static int iio_dummy_read_raw(struct iio_dev *indio_dev,
                              struct iio_chan_spec const *chan,
@@ -287,8 +284,8 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
  * @chan:      the channel whose data is to be written
  * @val:       first element of value to set (typically INT)
  * @val2:      second element of value to set (typically MICRO)
- * @mask:      what we actually want to write. 0 is the channel, everything else
- *             is as per the info_mask in iio_chan_spec.
+ * @mask:      what we actually want to write as per the info_mask_*
+ *             in iio_chan_spec.
  *
  * Note that all raw writes are assumed IIO_VAL_INT and info mask elements
  * are assumed to be IIO_INT_PLUS_MICRO unless the callback write_raw_get_fmt
index 440e2261e8cb70ee338c5beff46948f23ab6dcf9..6330af656a0f536d6a56580a5503eac75bdd3e53 100644 (file)
@@ -113,7 +113,7 @@ static const struct iio_chan_spec ad5933_channels[] = {
                .type = IIO_TEMP,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
                .address = AD5933_REG_TEMP_DATA,
                .scan_type = {
                        .sign = 's',
@@ -125,8 +125,8 @@ static const struct iio_chan_spec ad5933_channels[] = {
                .indexed = 1,
                .channel = 0,
                .extend_name = "real_raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_SCALE),
                .address = AD5933_REG_REAL_DATA,
                .scan_index = 0,
                .scan_type = {
@@ -139,8 +139,8 @@ static const struct iio_chan_spec ad5933_channels[] = {
                .indexed = 1,
                .channel = 0,
                .extend_name = "imag_raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_SCALE),
                .address = AD5933_REG_IMAG_DATA,
                .scan_index = 1,
                .scan_type = {
index b0adac0bf5d5b20c253a818c54d7124146bf906f..82478a59e42e719588adc20533824a7f31e47271 100644 (file)
@@ -412,17 +412,17 @@ static const struct iio_chan_spec isl29018_channels[] = {
                .type = IIO_LIGHT,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT |
-               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
+               BIT(IIO_CHAN_INFO_CALIBSCALE),
        }, {
                .type = IIO_INTENSITY,
                .modified = 1,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .channel2 = IIO_MOD_LIGHT_IR,
        }, {
                /* Unindexed in current ABI.  But perhaps it should be. */
                .type = IIO_PROXIMITY,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
        }
 };
 
index e52af77f7782c222a417466a4830569f43e6fe90..8bb0d03627f217069516e35ec9541178eeb44f71 100644 (file)
@@ -391,15 +391,15 @@ static const struct attribute_group isl29108_group = {
 static const struct iio_chan_spec isl29028_channels[] = {
        {
                .type = IIO_LIGHT,
-               .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT |
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
+               BIT(IIO_CHAN_INFO_SCALE),
        }, {
                .type = IIO_INTENSITY,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
        }, {
                .type = IIO_PROXIMITY,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-               IIO_CHAN_INFO_SAMP_FREQ_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+               BIT(IIO_CHAN_INFO_SAMP_FREQ),
        }
 };
 
index a58731e70bb9307a44f88bbcdeea62c589951502..d060f2572512af496f094036cfbc9460a19850d3 100644 (file)
@@ -1733,14 +1733,14 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
                        .type = IIO_LIGHT,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
                        }, {
                        .type = IIO_INTENSITY,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-                               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                               BIT(IIO_CHAN_INFO_CALIBSCALE) |
+                               BIT(IIO_CHAN_INFO_CALIBBIAS),
                        .event_mask = TSL2X7X_EVENT_MASK
                        }, {
                        .type = IIO_INTENSITY,
@@ -1757,7 +1757,7 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
                        .type = IIO_PROXIMITY,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                        .event_mask = TSL2X7X_EVENT_MASK
                        },
                },
@@ -1770,25 +1770,25 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
                        .type = IIO_LIGHT,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED)
                        }, {
                        .type = IIO_INTENSITY,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-                               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                               BIT(IIO_CHAN_INFO_CALIBSCALE) |
+                               BIT(IIO_CHAN_INFO_CALIBBIAS),
                        .event_mask = TSL2X7X_EVENT_MASK
                        }, {
                        .type = IIO_INTENSITY,
                        .indexed = 1,
                        .channel = 1,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                        }, {
                        .type = IIO_PROXIMITY,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                        .event_mask = TSL2X7X_EVENT_MASK
                        },
                },
@@ -1801,8 +1801,8 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
                        .type = IIO_PROXIMITY,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                               BIT(IIO_CHAN_INFO_CALIBSCALE),
                        .event_mask = TSL2X7X_EVENT_MASK
                        },
                },
@@ -1815,26 +1815,26 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = {
                        .type = IIO_LIGHT,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
                        }, {
                        .type = IIO_INTENSITY,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT |
-                               IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                               BIT(IIO_CHAN_INFO_CALIBSCALE) |
+                               BIT(IIO_CHAN_INFO_CALIBBIAS),
                        .event_mask = TSL2X7X_EVENT_MASK
                        }, {
                        .type = IIO_INTENSITY,
                        .indexed = 1,
                        .channel = 1,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                        }, {
                        .type = IIO_PROXIMITY,
                        .indexed = 1,
                        .channel = 0,
-                       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                               IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT,
+                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                               BIT(IIO_CHAN_INFO_CALIBSCALE),
                        .event_mask = TSL2X7X_EVENT_MASK
                        },
                },
index 28f080e9eeeeeb9b26ceed78222a50c6ad994d09..b614da1b21f85fb8eac04441b873add5601d382a 100644 (file)
@@ -395,8 +395,8 @@ static int ak8975_read_raw(struct iio_dev *indio_dev,
                .type = IIO_MAGN,                                       \
                .modified = 1,                                          \
                .channel2 = IIO_MOD_##axis,                             \
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |           \
-                            IIO_CHAN_INFO_SCALE_SEPARATE_BIT,          \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |          \
+                            BIT(IIO_CHAN_INFO_SCALE),                  \
                .address = index,                                       \
        }
 
index 1a520ecfa3e239da44292c4044f40f4b9a363d6c..86c6bf9d5dd89c7207edb015534e0cf5c08b0289 100644 (file)
@@ -564,8 +564,8 @@ static int hmc5843_read_raw(struct iio_dev *indio_dev,
                .type = IIO_MAGN,                                       \
                .modified = 1,                                          \
                .channel2 = IIO_MOD_##axis,                             \
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |           \
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,            \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
                .address = add                                          \
        }
 
index 53c68dcc4544567bdd1c0f70401fb867e834defb..8f5bcfab3563a6675d1dd912d3461f83d6d3c9ee 100644 (file)
@@ -649,8 +649,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 0,
                .extend_name = "raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_A, AD7758_VOLTAGE),
                .scan_index = 0,
                .scan_type = {
@@ -663,8 +663,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 0,
                .extend_name = "raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_A, AD7758_CURRENT),
                .scan_index = 1,
                .scan_type = {
@@ -677,8 +677,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 0,
                .extend_name = "apparent_raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_A, AD7758_APP_PWR),
                .scan_index = 2,
                .scan_type = {
@@ -691,8 +691,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 0,
                .extend_name = "active_raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_A, AD7758_ACT_PWR),
                .scan_index = 3,
                .scan_type = {
@@ -705,8 +705,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 0,
                .extend_name = "reactive_raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_A, AD7758_REACT_PWR),
                .scan_index = 4,
                .scan_type = {
@@ -719,8 +719,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 1,
                .extend_name = "raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_B, AD7758_VOLTAGE),
                .scan_index = 5,
                .scan_type = {
@@ -733,8 +733,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 1,
                .extend_name = "raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_B, AD7758_CURRENT),
                .scan_index = 6,
                .scan_type = {
@@ -747,8 +747,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 1,
                .extend_name = "apparent_raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_B, AD7758_APP_PWR),
                .scan_index = 7,
                .scan_type = {
@@ -761,8 +761,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 1,
                .extend_name = "active_raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_B, AD7758_ACT_PWR),
                .scan_index = 8,
                .scan_type = {
@@ -775,8 +775,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 1,
                .extend_name = "reactive_raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_B, AD7758_REACT_PWR),
                .scan_index = 9,
                .scan_type = {
@@ -789,8 +789,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 2,
                .extend_name = "raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_C, AD7758_VOLTAGE),
                .scan_index = 10,
                .scan_type = {
@@ -803,8 +803,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 2,
                .extend_name = "raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_C, AD7758_CURRENT),
                .scan_index = 11,
                .scan_type = {
@@ -817,8 +817,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 2,
                .extend_name = "apparent_raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_C, AD7758_APP_PWR),
                .scan_index = 12,
                .scan_type = {
@@ -831,8 +831,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 2,
                .extend_name = "active_raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_C, AD7758_ACT_PWR),
                .scan_index = 13,
                .scan_type = {
@@ -845,8 +845,8 @@ static const struct iio_chan_spec ade7758_channels[] = {
                .indexed = 1,
                .channel = 2,
                .extend_name = "reactive_raw",
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
-                            IIO_CHAN_INFO_SCALE_SHARED_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .address = AD7758_WT(AD7758_PHASE_C, AD7758_REACT_PWR),
                .scan_index = 14,
                .scan_type = {
index f9c6a340092b42c97c00b35c3f1958a7ef103772..7a94ddd42f593e7bc1355cd06ebfcb6c400ff014 100644 (file)
@@ -32,7 +32,7 @@ static irqreturn_t ade7758_data_rdy_trig_poll(int irq, void *private)
 static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig,
                                                bool state)
 {
-       struct iio_dev *indio_dev = trig->private_data;
+       struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
 
        dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
        return ade7758_set_irq(&indio_dev->dev, state);
@@ -44,7 +44,7 @@ static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig,
  **/
 static int ade7758_trig_try_reen(struct iio_trigger *trig)
 {
-       struct iio_dev *indio_dev = trig->private_data;
+       struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
        struct ade7758_state *st = iio_priv(indio_dev);
 
        enable_irq(st->us->irq);
@@ -81,7 +81,7 @@ int ade7758_probe_trigger(struct iio_dev *indio_dev)
 
        st->trig->dev.parent = &st->us->dev;
        st->trig->ops = &ade7758_trigger_ops;
-       st->trig->private_data = indio_dev;
+       iio_trigger_set_drvdata(st->trig, indio_dev);
        ret = iio_trigger_register(st->trig);
 
        /* select default trigger */
index 4fe349914f9a47dc9f354be44d632358ff89a3f4..71221161aa6b983f37c438755c1d3a5085d34bf5 100644 (file)
@@ -85,12 +85,12 @@ static const struct iio_chan_spec ad2s1200_channels[] = {
                .type = IIO_ANGL,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
        }, {
                .type = IIO_ANGL_VEL,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
        }
 };
 
index 53110b6a3c7401b8b391f45609eab4714e7f1844..0d3356d4b7d2ea9db775e85ec0e9bbd1273cbe31 100644 (file)
@@ -577,12 +577,12 @@ static const struct iio_chan_spec ad2s1210_channels[] = {
                .type = IIO_ANGL,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
        }, {
                .type = IIO_ANGL_VEL,
                .indexed = 1,
                .channel = 0,
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
        }
 };
 
index 0aecfbcdb992694a6e6481fca3123089b8b101db..40b825286d4af65dfe9228baa76c0af392096fa9 100644 (file)
@@ -55,7 +55,7 @@ static const struct iio_chan_spec ad2s90_chan = {
        .type = IIO_ANGL,
        .indexed = 1,
        .channel = 0,
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 };
 
 static int ad2s90_probe(struct spi_device *spi)
index 42798da575c0bf6c3523a9f028cc739519b7c0a7..38a158b77b1d24f3d55ac12c08ae13b0792b8d20 100644 (file)
@@ -65,7 +65,7 @@ struct bfin_tmr_state {
 
 static int iio_bfin_tmr_set_state(struct iio_trigger *trig, bool state)
 {
-       struct bfin_tmr_state *st = trig->private_data;
+       struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig);
 
        if (get_gptimer_period(st->t->id) == 0)
                return -EINVAL;
@@ -82,7 +82,7 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t count)
 {
        struct iio_trigger *trig = to_iio_trigger(dev);
-       struct bfin_tmr_state *st = trig->private_data;
+       struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig);
        unsigned long val;
        bool enabled;
        int ret;
@@ -125,7 +125,7 @@ static ssize_t iio_bfin_tmr_frequency_show(struct device *dev,
                                 char *buf)
 {
        struct iio_trigger *trig = to_iio_trigger(dev);
-       struct bfin_tmr_state *st = trig->private_data;
+       struct bfin_tmr_state *st = iio_trigger_get_drvdata(trig);
        unsigned int period = get_gptimer_period(st->t->id);
        unsigned long val;
 
@@ -213,9 +213,9 @@ static int iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
                goto out1;
        }
 
-       st->trig->private_data = st;
        st->trig->ops = &iio_bfin_tmr_trigger_ops;
        st->trig->dev.groups = iio_bfin_tmr_trigger_attr_groups;
+       iio_trigger_set_drvdata(st->trig, st);
        ret = iio_trigger_register(st->trig);
        if (ret)
                goto out2;
index fcc4cb048c9a90333f6314e3e687be56338f7672..7c593d18a91079fd9fd557596dc1a274bb136eb8 100644 (file)
@@ -83,7 +83,7 @@ static int iio_gpio_trigger_probe(struct platform_device *pdev)
                                ret = -ENOMEM;
                                goto error_put_trigger;
                        }
-                       trig->private_data = trig_info;
+                       iio_trigger_set_drvdata(trig, trig_info);
                        trig_info->irq = irq;
                        trig->ops = &iio_gpio_trigger_ops;
                        ret = request_irq(irq, iio_gpio_trigger_poll,
@@ -121,7 +121,7 @@ error_free_completed_registrations:
                                 trig2,
                                 &iio_gpio_trigger_list,
                                 alloc_list) {
-               trig_info = trig->private_data;
+               trig_info = iio_trigger_get_drvdata(trig);
                free_irq(gpio_to_irq(trig_info->irq), trig);
                kfree(trig_info);
                iio_trigger_unregister(trig);
@@ -140,7 +140,7 @@ static int iio_gpio_trigger_remove(struct platform_device *pdev)
                                 trig2,
                                 &iio_gpio_trigger_list,
                                 alloc_list) {
-               trig_info = trig->private_data;
+               trig_info = iio_trigger_get_drvdata(trig);
                iio_trigger_unregister(trig);
                free_irq(trig_info->irq, trig);
                kfree(trig_info);
index 9102b1ba2530cb6f51616c7f171e7c020189cb43..79695974b1d43dde0a46e1dbf60e00254edd0807 100644 (file)
@@ -30,7 +30,7 @@ struct iio_prtc_trigger_info {
 
 static int iio_trig_periodic_rtc_set_state(struct iio_trigger *trig, bool state)
 {
-       struct iio_prtc_trigger_info *trig_info = trig->private_data;
+       struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig);
        if (trig_info->frequency == 0)
                return -EINVAL;
        printk(KERN_INFO "trigger frequency is %d\n", trig_info->frequency);
@@ -42,7 +42,7 @@ static ssize_t iio_trig_periodic_read_freq(struct device *dev,
                                           char *buf)
 {
        struct iio_trigger *trig = to_iio_trigger(dev);
-       struct iio_prtc_trigger_info *trig_info = trig->private_data;
+       struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig);
        return sprintf(buf, "%u\n", trig_info->frequency);
 }
 
@@ -52,7 +52,7 @@ static ssize_t iio_trig_periodic_write_freq(struct device *dev,
                                            size_t len)
 {
        struct iio_trigger *trig = to_iio_trigger(dev);
-       struct iio_prtc_trigger_info *trig_info = trig->private_data;
+       struct iio_prtc_trigger_info *trig_info = iio_trigger_get_drvdata(trig);
        unsigned long val;
        int ret;
 
@@ -124,7 +124,7 @@ static int iio_trig_periodic_rtc_probe(struct platform_device *dev)
                        ret = -ENOMEM;
                        goto error_put_trigger_and_remove_from_list;
                }
-               trig->private_data = trig_info;
+               iio_trigger_set_drvdata(trig, trig_info);
                trig->ops = &iio_prtc_trigger_ops;
                /* RTC access */
                trig_info->rtc
@@ -158,7 +158,7 @@ error_free_completed_registrations:
                                 trig2,
                                 &iio_prtc_trigger_list,
                                 alloc_list) {
-               trig_info = trig->private_data;
+               trig_info = iio_trigger_get_drvdata(trig);
                rtc_irq_unregister(trig_info->rtc, &trig_info->task);
                rtc_class_close(trig_info->rtc);
                kfree(trig_info);
@@ -176,7 +176,7 @@ static int iio_trig_periodic_rtc_remove(struct platform_device *dev)
                                 trig2,
                                 &iio_prtc_trigger_list,
                                 alloc_list) {
-               trig_info = trig->private_data;
+               trig_info = iio_trigger_get_drvdata(trig);
                rtc_irq_unregister(trig_info->rtc, &trig_info->task);
                rtc_class_close(trig_info->rtc);
                kfree(trig_info);
index 3bac97224bf4c8683e2f8ac6a180435bf1c0a5b5..b727bde8b7fe09babfc8211be0d61d5c210e2d7c 100644 (file)
@@ -103,7 +103,7 @@ static ssize_t iio_sysfs_trigger_poll(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t count)
 {
        struct iio_trigger *trig = to_iio_trigger(dev);
-       struct iio_sysfs_trig *sysfs_trig = trig->private_data;
+       struct iio_sysfs_trig *sysfs_trig = iio_trigger_get_drvdata(trig);
 
        irq_work_queue(&sysfs_trig->work);
 
@@ -160,7 +160,7 @@ static int iio_sysfs_trigger_probe(int id)
        t->trig->dev.groups = iio_sysfs_trigger_attr_groups;
        t->trig->ops = &iio_sysfs_trigger_ops;
        t->trig->dev.parent = &iio_sysfs_trig_dev;
-       t->trig->private_data = t;
+       iio_trigger_set_drvdata(t->trig, t);
 
        init_irq_work(&t->work, iio_sysfs_trigger_work);
 
index 99d1cceaa3de1bc7570132dac142e9bcd004950f..66572d585add6fe6e54f0b7302378ec9bd67e2ee 100644 (file)
@@ -292,7 +292,8 @@ static inline void ipu_cpmem_interlaced_scan(struct ipu_ch_param *p,
 
 void ipu_cpmem_set_yuv_planar(struct ipu_ch_param __iomem *p, u32 pixel_format,
                        int stride, int height);
-void ipu_cpmem_set_yuv_interleaved(struct ipu_ch_param *p, u32 pixel_format);
+void ipu_cpmem_set_yuv_interleaved(struct ipu_ch_param __iomem *p,
+                                  u32 pixel_format);
 void ipu_cpmem_set_yuv_planar_full(struct ipu_ch_param __iomem *p,
                u32 pixel_format, int stride, int u_offset, int v_offset);
 int ipu_cpmem_set_fmt(struct ipu_ch_param __iomem *cpmem, u32 pixelformat);
index 366f259e3756abc4052287bdeafeabda640c3fa3..055b99db50ff7b1fc4b69877a7c992ab46bd0738 100644 (file)
@@ -225,7 +225,8 @@ int ipu_cpmem_set_format_passthrough(struct ipu_ch_param __iomem *p,
 }
 EXPORT_SYMBOL_GPL(ipu_cpmem_set_format_passthrough);
 
-void ipu_cpmem_set_yuv_interleaved(struct ipu_ch_param *p, u32 pixel_format)
+void ipu_cpmem_set_yuv_interleaved(struct ipu_ch_param __iomem *p,
+                                  u32 pixel_format)
 {
        switch (pixel_format) {
        case V4L2_PIX_FMT_UYVY:
index 26aecaf9677f114b16a1200574361269799a7f78..113b046c02259d4ee828ecafbc6fb5b2e0347e1f 100644 (file)
@@ -316,7 +316,6 @@ int ipu_dp_init(struct ipu_soc *ipu, struct device *dev, unsigned long base)
 
        priv->base = devm_ioremap(dev, base, PAGE_SIZE);
        if (!priv->base) {
-               kfree(priv);
                return -ENOMEM;
        }
 
index 74898c3c9f90b4b6c862b48aa028f6f7f2c71c26..699b21725062284ca081ba71ddba0bb978427bb9 100644 (file)
@@ -148,9 +148,8 @@ void line6_pod_process_message(struct usb_line6_pod *pod)
            buf[0] != (LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN)) {
                return;
        }
-       if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) != 0) {
+       if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) != 0)
                return;
-       }
 
        if (buf[5] == POD_SYSEX_SYSTEM && buf[6] == POD_MONITOR_LEVEL) {
                short value = ((int)buf[7] << 12) | ((int)buf[8] << 8) |
index 1dbd564187047f7af2b208f68c148b335a5516f7..a1e91778aa9bbc5fa0440296d6cb08ed866f2924 100644 (file)
@@ -38,7 +38,7 @@ interface to userspace.
        DAVINCI RESIZER A
        DAVINCI RESIZER B
 
-Each possible link in the VPFE is modeled by a link in the Media controller
+Each possible link in the VPFE is modelled by a link in the Media controller
 interface. For an example program see [1].
 
 
index ebeea72e176a49b586263f8224b614320187d789..6d4a93c556e436e19c92a43b3db5a7b8117b4937 100644 (file)
@@ -685,7 +685,7 @@ static void isif_config_bclamp(struct vpfe_isif_device *isif,
        val = (bc->bc_mode_color & ISIF_BC_MODE_COLOR_MASK) <<
                ISIF_BC_MODE_COLOR_SHIFT;
 
-       /* Enable BC and horizontal clamp caculation paramaters */
+       /* Enable BC and horizontal clamp calculation paramaters */
        val = val | 1 | ((bc->horz.mode & ISIF_HORZ_BC_MODE_MASK) <<
              ISIF_HORZ_BC_MODE_SHIFT);
 
@@ -722,7 +722,7 @@ static void isif_config_bclamp(struct vpfe_isif_device *isif,
                isif_write(isif->isif_cfg.base_addr, val, CLHWIN2);
        }
 
-       /* vertical clamp caculation paramaters */
+       /* vertical clamp calculation paramaters */
        /* OB H Valid */
        val = bc->vert.ob_h_sz_calc & ISIF_VERT_BC_OB_H_SZ_MASK;
 
@@ -1569,7 +1569,7 @@ isif_pad_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
                crop->rect.width = format->width;
                crop->rect.height = format->height;
        }
-       /* adjust the width to 16 pixel boundry */
+       /* adjust the width to 16 pixel boundary */
        crop->rect.width = ((crop->rect.width + 15) & ~0xf);
        vpfe_isif->crop = crop->rect;
        if (crop->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
index 99ccbebea598981229c1e5bf8f26c84089f21ee1..c91d356c13df45f6a5084dccbb31e861fef8e38e 100644 (file)
@@ -357,7 +357,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
  *
  * Set the pipeline to the given stream state.
  *
- * Return 0 if successfull, or the return value of the failed video::s_stream
+ * Return 0 if successful, or the return value of the failed video::s_stream
  * operation otherwise.
  */
 static int vpfe_pipeline_set_stream(struct vpfe_pipeline *pipe,
@@ -644,7 +644,7 @@ static int vpfe_g_fmt(struct file *file, void *priv,
  * fills v4l2_fmtdesc structure with output format set on adjacent subdev,
  * only one format is enumearted as subdevs are already configured
  *
- * Return 0 if successfull, error code otherwise
+ * Return 0 if successful, error code otherwise
  */
 static int vpfe_enum_fmt(struct file *file, void  *priv,
                                   struct v4l2_fmtdesc *fmt)
@@ -769,7 +769,7 @@ static int vpfe_try_fmt(struct file *file, void *priv,
  * fills v4l2_input structure with input available on media chain,
  * only one input is enumearted as media chain is setup by this time
  *
- * Return 0 if successfull, -EINVAL is media chain is invalid
+ * Return 0 if successful, -EINVAL is media chain is invalid
  */
 static int vpfe_enum_input(struct file *file, void *priv,
                                 struct v4l2_input *inp)
@@ -779,7 +779,7 @@ static int vpfe_enum_input(struct file *file, void *priv,
        struct vpfe_device *vpfe_dev = video->vpfe_dev;
 
        v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_enum_input\n");
-       /* enumerate from the subdev user has choosen through mc */
+       /* enumerate from the subdev user has chosen through mc */
        if (inp->index < sdinfo->num_inputs) {
                memcpy(inp, &sdinfo->inputs[inp->index],
                       sizeof(struct v4l2_input));
index bf8af01d4a1b29b5068ad1bf4115fc5beba4ec52..df0aeec8b588be79fe7ffe49ad961640bd7801d8 100644 (file)
@@ -138,7 +138,7 @@ struct vpfe_video_device {
        v4l2_std_id                             stdid;
        /*
         * offset where second field starts from the starting of the
-        * buffer for field seperated YCbCr formats
+        * buffer for field separated YCbCr formats
         */
        u32                                     field_off;
 };
diff --git a/drivers/staging/netlogic/Kconfig b/drivers/staging/netlogic/Kconfig
new file mode 100644 (file)
index 0000000..d660de5
--- /dev/null
@@ -0,0 +1,7 @@
+config NETLOGIC_XLR_NET
+       tristate "Netlogic XLR/XLS network device"
+       depends on CPU_XLR
+       select PHYLIB
+       ---help---
+       This driver support Netlogic XLR/XLS on chip gigabit
+       Ethernet.
diff --git a/drivers/staging/netlogic/Makefile b/drivers/staging/netlogic/Makefile
new file mode 100644 (file)
index 0000000..f7355e3
--- /dev/null
@@ -0,0 +1 @@
+obj-$(CONFIG_NETLOGIC_XLR_NET) += xlr_net.o platform_net.o
diff --git a/drivers/staging/netlogic/TODO b/drivers/staging/netlogic/TODO
new file mode 100644 (file)
index 0000000..08e6d52
--- /dev/null
@@ -0,0 +1,12 @@
+* Implementing 64bit stat counter in software
+* All memory allocation should be changed to DMA allocations
+* All the netdev should be linked to single pdev as parent
+* Changing comments in to linux standred format
+
+Please send patches
+To:
+Ganesan Ramalingam <ganesanr@broadcom.com>
+Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Cc:
+Jayachandran Chandrashekaran Nair <jchandra@broadcom.com>
+
diff --git a/drivers/staging/netlogic/platform_net.c b/drivers/staging/netlogic/platform_net.c
new file mode 100644 (file)
index 0000000..61f20e1
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2003-2012 Broadcom Corporation
+ * All Rights Reserved
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * 1. Redistributions of source code must retain the above copyright
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the Broadcom
+ * license below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BROADCOM ``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 BROADCOM 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.
+ */
+
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/ioport.h>
+#include <linux/resource.h>
+#include <linux/phy.h>
+
+#include <asm/netlogic/haldefs.h>
+#include <asm/netlogic/common.h>
+#include <asm/netlogic/xlr/fmn.h>
+#include <asm/netlogic/xlr/xlr.h>
+#include <asm/netlogic/psb-bootinfo.h>
+#include <asm/netlogic/xlr/pic.h>
+#include <asm/netlogic/xlr/iomap.h>
+
+#include "platform_net.h"
+
+/* Linux Net */
+#define MAX_NUM_GMAC           8
+#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,
+       NETLOGIC_IO_GMAC_4_OFFSET, NETLOGIC_IO_GMAC_5_OFFSET,
+       NETLOGIC_IO_GMAC_6_OFFSET, NETLOGIC_IO_GMAC_7_OFFSET
+};
+
+static u32 xlr_gmac_irqs[] = { PIC_GMAC_0_IRQ, PIC_GMAC_1_IRQ,
+       PIC_GMAC_2_IRQ, PIC_GMAC_3_IRQ,
+       PIC_GMAC_4_IRQ, PIC_GMAC_5_IRQ,
+       PIC_GMAC_6_IRQ, PIC_GMAC_7_IRQ
+};
+
+static struct xlr_net_data ndata[MAX_NUM_GMAC];
+static struct resource xlr_net_res[8][2];
+static struct platform_device xlr_net_dev[8];
+static u32 __iomem *gmac0_addr;
+static u32 __iomem *gmac4_addr;
+static u32 __iomem *gpio_addr;
+
+static void config_mac(struct xlr_net_data *nd, int phy, u32 __iomem *serdes,
+               u32 __iomem *pcs, int rfr, int tx, int *bkt_size,
+               struct xlr_fmn_info *gmac_fmn_info, int phy_addr)
+{
+       nd->cpu_mask = nlm_current_node()->coremask;
+       nd->phy_interface = phy;
+       nd->rfr_station = rfr;
+       nd->tx_stnid = tx;
+       nd->mii_addr = gmac0_addr;
+       nd->serdes_addr = serdes;
+       nd->pcs_addr = pcs;
+       nd->gpio_addr = gpio_addr;
+
+       nd->bucket_size = bkt_size;
+       nd->gmac_fmn_info = gmac_fmn_info;
+       nd->phy_addr = phy_addr;
+}
+
+static void net_device_init(int id, struct resource *res, int offset, int irq)
+{
+       res[0].name = "gmac";
+       res[0].start = CPHYSADDR(nlm_mmio_base(offset));
+       res[0].end = res[0].start + 0xfff;
+       res[0].flags = IORESOURCE_MEM;
+
+       res[1].name = "gmac";
+       res[1].start = irq;
+       res[1].end = irq;
+       res[1].flags = IORESOURCE_IRQ;
+
+       xlr_net_dev[id].name = "xlr-net";
+       xlr_net_dev[id].id = id;
+       xlr_net_dev[id].num_resources = 2;
+       xlr_net_dev[id].resource = res;
+       xlr_net_dev[id].dev.platform_data = &ndata[id];
+}
+
+static void xls_gmac_init(void)
+{
+       int mac;
+
+       gmac4_addr = ioremap(CPHYSADDR(
+               nlm_mmio_base(NETLOGIC_IO_GMAC_4_OFFSET)), 0xfff);
+       /* Passing GPIO base for serdes init. Only needed on sgmii ports*/
+       gpio_addr = ioremap(CPHYSADDR(
+               nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET)), 0xfff);
+
+       switch (nlm_prom_info.board_major_version) {
+       case 12:
+               /* first block RGMII or XAUI, use RGMII */
+               config_mac(&ndata[0],
+                       PHY_INTERFACE_MODE_RGMII,
+                       gmac0_addr,     /* serdes */
+                       gmac0_addr,     /* pcs */
+                       FMN_STNID_GMACRFR_0,
+                       FMN_STNID_GMAC0_TX0,
+                       xlr_board_fmn_config.bucket_size,
+                       &xlr_board_fmn_config.gmac[0],
+                       0);
+
+               net_device_init(0, xlr_net_res[0], xlr_gmac_offsets[0],
+                               xlr_gmac_irqs[0]);
+               platform_device_register(&xlr_net_dev[0]);
+
+               /* second block is XAUI, not supported yet */
+               break;
+       default:
+               /* default XLS config, all ports SGMII */
+               for (mac = 0; mac < 4; mac++) {
+                       config_mac(&ndata[mac],
+                               PHY_INTERFACE_MODE_SGMII,
+                               gmac0_addr,     /* serdes */
+                               gmac0_addr,     /* pcs */
+                               FMN_STNID_GMACRFR_0,
+                               FMN_STNID_GMAC0_TX0 + mac,
+                               xlr_board_fmn_config.bucket_size,
+                               &xlr_board_fmn_config.gmac[0],
+                               /* PHY address according to chip/board */
+                               mac + 0x10);
+
+                       net_device_init(mac, xlr_net_res[mac],
+                                       xlr_gmac_offsets[mac],
+                                       xlr_gmac_irqs[mac]);
+                       platform_device_register(&xlr_net_dev[mac]);
+               }
+
+               for (mac = 4; mac < MAX_NUM_XLS_GMAC; mac++) {
+                       config_mac(&ndata[mac],
+                               PHY_INTERFACE_MODE_SGMII,
+                               gmac4_addr,     /* serdes */
+                               gmac4_addr,     /* pcs */
+                               FMN_STNID_GMAC1_FR_0,
+                               FMN_STNID_GMAC1_TX0 + mac - 4,
+                               xlr_board_fmn_config.bucket_size,
+                               &xlr_board_fmn_config.gmac[1],
+                               /* PHY address according to chip/board */
+                               mac + 0x10);
+
+                       net_device_init(mac, xlr_net_res[mac],
+                                       xlr_gmac_offsets[mac],
+                                       xlr_gmac_irqs[mac]);
+                       platform_device_register(&xlr_net_dev[mac]);
+               }
+       }
+}
+
+static void xlr_gmac_init(void)
+{
+       int mac;
+
+       /* assume all GMACs for now */
+       for (mac = 0; mac < MAX_NUM_XLR_GMAC; mac++) {
+               config_mac(&ndata[mac],
+                       PHY_INTERFACE_MODE_RGMII,
+                       0,
+                       0,
+                       FMN_STNID_GMACRFR_0,
+                       FMN_STNID_GMAC0_TX0,
+                       xlr_board_fmn_config.bucket_size,
+                       &xlr_board_fmn_config.gmac[0],
+                       mac);
+
+               net_device_init(mac, xlr_net_res[mac], xlr_gmac_offsets[mac],
+                               xlr_gmac_irqs[mac]);
+               platform_device_register(&xlr_net_dev[mac]);
+       }
+}
+
+static int __init xlr_net_init(void)
+{
+       gmac0_addr = ioremap(CPHYSADDR(
+               nlm_mmio_base(NETLOGIC_IO_GMAC_0_OFFSET)), 0xfff);
+
+       if (nlm_chip_is_xls())
+               xls_gmac_init();
+       else
+               xlr_gmac_init();
+
+       return 0;
+}
+
+arch_initcall(xlr_net_init);
diff --git a/drivers/staging/netlogic/platform_net.h b/drivers/staging/netlogic/platform_net.h
new file mode 100644 (file)
index 0000000..29deeea
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2003-2012 Broadcom Corporation
+ * All Rights Reserved
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the Broadcom
+ * license below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BROADCOM ``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 BROADCOM 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.
+ */
+struct xlr_net_data {
+       int cpu_mask;
+       u32 __iomem *mii_addr;
+       u32 __iomem *serdes_addr;
+       u32 __iomem *pcs_addr;
+       u32 __iomem *gpio_addr;
+       int phy_interface;
+       int rfr_station;
+       int tx_stnid;
+       int *bucket_size;
+       int phy_addr;
+       struct xlr_fmn_info *gmac_fmn_info;
+};
diff --git a/drivers/staging/netlogic/xlr_net.c b/drivers/staging/netlogic/xlr_net.c
new file mode 100644 (file)
index 0000000..dd98cb1
--- /dev/null
@@ -0,0 +1,1114 @@
+/*
+ * Copyright (c) 2003-2012 Broadcom Corporation
+ * All Rights Reserved
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the Broadcom
+ * license below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BROADCOM ``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 BROADCOM 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.
+ */
+#include <linux/phy.h>
+#include <linux/delay.h>
+#include <linux/netdevice.h>
+#include <linux/smp.h>
+#include <linux/ethtool.h>
+#include <linux/module.h>
+#include <linux/etherdevice.h>
+#include <linux/skbuff.h>
+#include <linux/jiffies.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+
+#include <asm/mipsregs.h>
+
+/* fmn.h - For FMN credit configuration and registering fmn_handler.
+ * FMN is communication mechanism that allows processing agents within
+ * XLR/XLS to communicate each other.
+ */
+#include <asm/netlogic/xlr/fmn.h>
+
+#include "platform_net.h"
+#include "xlr_net.h"
+
+/*
+ * The readl/writel implementation byteswaps on XLR/XLS, so
+ * we need to use __raw_ IO to read the NAE registers
+ * because they are in the big-endian MMIO area on the SoC.
+ */
+static inline void xlr_nae_wreg(u32 __iomem *base, unsigned int reg, u32 val)
+{
+       __raw_writel(val, base + reg);
+}
+
+static inline u32 xlr_nae_rdreg(u32 __iomem *base, unsigned int reg)
+{
+       return __raw_readl(base + reg);
+}
+
+static inline void xlr_reg_update(u32 *base_addr,
+               u32 off, u32 val, u32 mask)
+{
+       u32 tmp;
+
+       tmp = xlr_nae_rdreg(base_addr, off);
+       xlr_nae_wreg(base_addr, off, (tmp & ~mask) | (val & mask));
+}
+
+/*
+ * Table of net_device pointers indexed by port, this will be used to
+ * lookup the net_device corresponding to a port by the message ring handler.
+ *
+ * Maximum ports in XLR/XLS is 8(8 GMAC on XLS, 4 GMAC + 2 XGMAC on XLR)
+ */
+static struct net_device *mac_to_ndev[8];
+
+static inline struct sk_buff *mac_get_skb_back_ptr(void *addr)
+{
+       struct sk_buff **back_ptr;
+
+       /* this function should be used only for newly allocated packets.
+        * It assumes the first cacheline is for the back pointer related
+        * book keeping info.
+        */
+       back_ptr = (struct sk_buff **)(addr - MAC_SKB_BACK_PTR_SIZE);
+       return *back_ptr;
+}
+
+static inline void mac_put_skb_back_ptr(struct sk_buff *skb)
+{
+       struct sk_buff **back_ptr = (struct sk_buff **)skb->data;
+
+       /* this function should be used only for newly allocated packets.
+        * It assumes the first cacheline is for the back pointer related
+        * book keeping info.
+        */
+       skb_reserve(skb, MAC_SKB_BACK_PTR_SIZE);
+       *back_ptr = skb;
+}
+
+static int send_to_rfr_fifo(struct xlr_net_priv *priv, void *addr)
+{
+       struct nlm_fmn_msg msg;
+       int ret = 0, num_try = 0, stnid;
+       unsigned long paddr, mflags;
+
+       paddr = virt_to_bus(addr);
+       msg.msg0 = (u64)paddr & 0xffffffffe0ULL;
+       msg.msg1 = 0;
+       msg.msg2 = 0;
+       msg.msg3 = 0;
+       stnid = priv->nd->rfr_station;
+       do {
+               mflags = nlm_cop2_enable();
+               ret = nlm_fmn_send(1, 0, stnid, &msg);
+               nlm_cop2_restore(mflags);
+               if (ret == 0)
+                       return 0;
+       } while (++num_try < 10000);
+
+       pr_err("Send to RFR failed in RX path\n");
+       return ret;
+}
+
+static inline struct sk_buff *xlr_alloc_skb(void)
+{
+       struct sk_buff *skb;
+
+       /* skb->data is cache aligned */
+       skb = alloc_skb(XLR_RX_BUF_SIZE, GFP_ATOMIC);
+       if (!skb) {
+               pr_err("SKB allocation failed\n");
+               return NULL;
+       }
+       mac_put_skb_back_ptr(skb);
+       return skb;
+}
+
+static void xlr_net_fmn_handler(int bkt, int src_stnid, int size,
+               int code, struct nlm_fmn_msg *msg, void *arg)
+{
+       struct sk_buff *skb, *skb_new = NULL;
+       struct net_device *ndev;
+       struct xlr_net_priv *priv;
+       u64 length, port;
+       void *addr;
+
+       length = (msg->msg0 >> 40) & 0x3fff;
+       if (length == 0) {
+               addr = bus_to_virt(msg->msg0 & 0xffffffffffULL);
+               dev_kfree_skb_any(addr);
+       } else if (length) {
+               addr = bus_to_virt(msg->msg0 & 0xffffffffe0ULL);
+               length = length - BYTE_OFFSET - MAC_CRC_LEN;
+               port = msg->msg0 & 0x0f;
+               if (src_stnid == FMN_STNID_GMAC1)
+                       port = port + 4;
+               skb = mac_get_skb_back_ptr(addr);
+               skb->dev = mac_to_ndev[port];
+               ndev = skb->dev;
+               priv = netdev_priv(ndev);
+
+               /* 16 byte IP header align */
+               skb_reserve(skb, BYTE_OFFSET);
+               skb_put(skb, length);
+               skb->protocol = eth_type_trans(skb, skb->dev);
+               skb->dev->last_rx = jiffies;
+               netif_rx(skb);
+               /* Fill rx ring */
+               skb_new = xlr_alloc_skb();
+               if (skb_new)
+                       send_to_rfr_fifo(priv, skb_new->data);
+       }
+       return;
+}
+
+/* Ethtool operation */
+static int xlr_get_settings(struct net_device *ndev, struct ethtool_cmd *ecmd)
+{
+       struct xlr_net_priv *priv = netdev_priv(ndev);
+       struct phy_device *phydev = priv->mii_bus->phy_map[priv->phy_addr];
+
+       if (!phydev)
+               return -ENODEV;
+       return phy_ethtool_gset(phydev, ecmd);
+}
+
+static int xlr_set_settings(struct net_device *ndev, struct ethtool_cmd *ecmd)
+{
+       struct xlr_net_priv *priv = netdev_priv(ndev);
+       struct phy_device *phydev = priv->mii_bus->phy_map[priv->phy_addr];
+
+       if (!phydev)
+               return -ENODEV;
+       return phy_ethtool_sset(phydev, ecmd);
+}
+
+static struct ethtool_ops xlr_ethtool_ops = {
+       .get_settings = xlr_get_settings,
+       .set_settings = xlr_set_settings,
+};
+
+/* Net operations */
+static int xlr_net_fill_rx_ring(struct net_device *ndev)
+{
+       struct sk_buff *skb;
+       struct xlr_net_priv *priv = netdev_priv(ndev);
+       int i;
+
+       for (i = 0; i < MAX_FRIN_SPILL/2; i++) {
+               skb = xlr_alloc_skb();
+               if (!skb)
+                       return -ENOMEM;
+               send_to_rfr_fifo(priv, skb->data);
+       }
+       pr_info("Rx ring setup done\n");
+       return 0;
+}
+
+static int xlr_net_open(struct net_device *ndev)
+{
+       u32 err;
+       struct xlr_net_priv *priv = netdev_priv(ndev);
+       struct phy_device *phydev = priv->mii_bus->phy_map[priv->phy_addr];
+
+       /* schedule a link state check */
+       phy_start(phydev);
+
+       err = phy_start_aneg(phydev);
+       if (err) {
+               pr_err("Autoneg failed\n");
+               return err;
+       }
+
+       /* Setup the speed from PHY to internal reg*/
+       xlr_set_gmac_speed(priv);
+       netif_tx_start_all_queues(ndev);
+       return 0;
+}
+
+static int xlr_net_stop(struct net_device *ndev)
+{
+       struct xlr_net_priv *priv = netdev_priv(ndev);
+       struct phy_device *phydev = priv->mii_bus->phy_map[priv->phy_addr];
+
+       phy_stop(phydev);
+       netif_tx_stop_all_queues(ndev);
+       return 0;
+}
+
+static void xlr_make_tx_desc(struct nlm_fmn_msg *msg, unsigned long addr,
+               struct sk_buff *skb)
+{
+       unsigned long physkb = virt_to_phys(skb);
+       int cpu_core = nlm_core_id();
+       int fr_stn_id = cpu_core * 8 + XLR_FB_STN;      /* FB to 6th bucket */
+       msg->msg0 = (((u64)1 << 63)     |       /* End of packet descriptor */
+               ((u64)127 << 54)        |       /* No Free back */
+               (u64)skb->len << 40     |       /* Length of data */
+               ((u64)addr));
+       msg->msg1 = (((u64)1 << 63)     |
+               ((u64)fr_stn_id << 54)  |       /* Free back id */
+               (u64)0 << 40            |       /* Set len to 0 */
+               ((u64)physkb  & 0xffffffff));   /* 32bit address */
+       msg->msg2 = msg->msg3 = 0;
+}
+
+static void __maybe_unused xlr_wakeup_queue(unsigned long dev)
+{
+       struct net_device *ndev = (struct net_device *) dev;
+       struct xlr_net_priv *priv = netdev_priv(ndev);
+       struct phy_device *phydev = priv->mii_bus->phy_map[priv->phy_addr];
+
+       if (phydev->link)
+               netif_tx_wake_queue(netdev_get_tx_queue(ndev, priv->wakeup_q));
+}
+
+static netdev_tx_t xlr_net_start_xmit(struct sk_buff *skb,
+               struct net_device *ndev)
+{
+       struct nlm_fmn_msg msg;
+       struct xlr_net_priv *priv = netdev_priv(ndev);
+       int ret;
+       u32 flags;
+
+       xlr_make_tx_desc(&msg, virt_to_phys(skb->data), skb);
+       flags = nlm_cop2_enable();
+       ret = nlm_fmn_send(2, 0, priv->nd->tx_stnid, &msg);
+       nlm_cop2_restore(flags);
+       if (ret)
+               dev_kfree_skb_any(skb);
+       return NETDEV_TX_OK;
+}
+
+static u16 xlr_net_select_queue(struct net_device *ndev, struct sk_buff *skb)
+{
+       return (u16)smp_processor_id();
+}
+
+static void xlr_hw_set_mac_addr(struct net_device *ndev)
+{
+       struct xlr_net_priv *priv = netdev_priv(ndev);
+
+       /* set mac station address */
+       xlr_nae_wreg(priv->base_addr, R_MAC_ADDR0,
+               ((ndev->dev_addr[5] << 24) | (ndev->dev_addr[4] << 16) |
+               (ndev->dev_addr[3] << 8) | (ndev->dev_addr[2])));
+       xlr_nae_wreg(priv->base_addr, R_MAC_ADDR0 + 1,
+               ((ndev->dev_addr[1] << 24) | (ndev->dev_addr[0] << 16)));
+
+       xlr_nae_wreg(priv->base_addr, R_MAC_ADDR_MASK2, 0xffffffff);
+       xlr_nae_wreg(priv->base_addr, R_MAC_ADDR_MASK2 + 1, 0xffffffff);
+       xlr_nae_wreg(priv->base_addr, R_MAC_ADDR_MASK3, 0xffffffff);
+       xlr_nae_wreg(priv->base_addr, R_MAC_ADDR_MASK3 + 1, 0xffffffff);
+
+       xlr_nae_wreg(priv->base_addr, R_MAC_FILTER_CONFIG,
+               (1 << O_MAC_FILTER_CONFIG__BROADCAST_EN) |
+               (1 << O_MAC_FILTER_CONFIG__ALL_MCAST_EN) |
+               (1 << O_MAC_FILTER_CONFIG__MAC_ADDR0_VALID));
+
+       if (priv->nd->phy_interface == PHY_INTERFACE_MODE_RGMII ||
+                       priv->nd->phy_interface == PHY_INTERFACE_MODE_SGMII)
+               xlr_reg_update(priv->base_addr, R_IPG_IFG, MAC_B2B_IPG, 0x7f);
+}
+
+static int xlr_net_set_mac_addr(struct net_device *ndev, void *data)
+{
+       int err;
+
+       err = eth_mac_addr(ndev, data);
+       if (err)
+               return err;
+       xlr_hw_set_mac_addr(ndev);
+       return 0;
+}
+
+static void xlr_set_rx_mode(struct net_device *ndev)
+{
+       struct xlr_net_priv *priv = netdev_priv(ndev);
+       u32 regval;
+
+       regval = xlr_nae_rdreg(priv->base_addr, R_MAC_FILTER_CONFIG);
+
+       if (ndev->flags & IFF_PROMISC) {
+               regval |= (1 << O_MAC_FILTER_CONFIG__BROADCAST_EN) |
+               (1 << O_MAC_FILTER_CONFIG__PAUSE_FRAME_EN) |
+               (1 << O_MAC_FILTER_CONFIG__ALL_MCAST_EN) |
+               (1 << O_MAC_FILTER_CONFIG__ALL_UCAST_EN);
+       } else {
+               regval &= ~((1 << O_MAC_FILTER_CONFIG__PAUSE_FRAME_EN) |
+               (1 << O_MAC_FILTER_CONFIG__ALL_UCAST_EN));
+       }
+
+       xlr_nae_wreg(priv->base_addr, R_MAC_FILTER_CONFIG, regval);
+}
+
+static void xlr_stats(struct net_device *ndev, struct rtnl_link_stats64 *stats)
+{
+       struct xlr_net_priv *priv = netdev_priv(ndev);
+
+       stats->rx_packets = xlr_nae_rdreg(priv->base_addr, RX_PACKET_COUNTER);
+       stats->tx_packets = xlr_nae_rdreg(priv->base_addr, TX_PACKET_COUNTER);
+       stats->rx_bytes = xlr_nae_rdreg(priv->base_addr, RX_BYTE_COUNTER);
+       stats->tx_bytes = xlr_nae_rdreg(priv->base_addr, TX_BYTE_COUNTER);
+       stats->tx_errors = xlr_nae_rdreg(priv->base_addr, TX_FCS_ERROR_COUNTER);
+       stats->rx_dropped = xlr_nae_rdreg(priv->base_addr,
+                       RX_DROP_PACKET_COUNTER);
+       stats->tx_dropped = xlr_nae_rdreg(priv->base_addr,
+                       TX_DROP_FRAME_COUNTER);
+
+       stats->multicast = xlr_nae_rdreg(priv->base_addr,
+                       RX_MULTICAST_PACKET_COUNTER);
+       stats->collisions = xlr_nae_rdreg(priv->base_addr,
+                       TX_TOTAL_COLLISION_COUNTER);
+
+       stats->rx_length_errors = xlr_nae_rdreg(priv->base_addr,
+                       RX_FRAME_LENGTH_ERROR_COUNTER);
+       stats->rx_over_errors = xlr_nae_rdreg(priv->base_addr,
+                       RX_DROP_PACKET_COUNTER);
+       stats->rx_crc_errors = xlr_nae_rdreg(priv->base_addr,
+                       RX_FCS_ERROR_COUNTER);
+       stats->rx_frame_errors = xlr_nae_rdreg(priv->base_addr,
+                       RX_ALIGNMENT_ERROR_COUNTER);
+
+       stats->rx_fifo_errors = xlr_nae_rdreg(priv->base_addr,
+                       RX_DROP_PACKET_COUNTER);
+       stats->rx_missed_errors = xlr_nae_rdreg(priv->base_addr,
+                       RX_CARRIER_SENSE_ERROR_COUNTER);
+
+       stats->rx_errors = (stats->rx_over_errors + stats->rx_crc_errors +
+                       stats->rx_frame_errors + stats->rx_fifo_errors +
+                       stats->rx_missed_errors);
+
+       stats->tx_aborted_errors = xlr_nae_rdreg(priv->base_addr,
+                       TX_EXCESSIVE_COLLISION_PACKET_COUNTER);
+       stats->tx_carrier_errors = xlr_nae_rdreg(priv->base_addr,
+                       TX_DROP_FRAME_COUNTER);
+       stats->tx_fifo_errors = xlr_nae_rdreg(priv->base_addr,
+                       TX_DROP_FRAME_COUNTER);
+}
+
+static struct rtnl_link_stats64 *xlr_get_stats64(struct net_device *ndev,
+               struct rtnl_link_stats64 *stats)
+{
+       xlr_stats(ndev, stats);
+       return stats;
+}
+
+static struct net_device_ops xlr_netdev_ops = {
+       .ndo_open = xlr_net_open,
+       .ndo_stop = xlr_net_stop,
+       .ndo_start_xmit = xlr_net_start_xmit,
+       .ndo_select_queue = xlr_net_select_queue,
+       .ndo_set_mac_address = xlr_net_set_mac_addr,
+       .ndo_set_rx_mode = xlr_set_rx_mode,
+       .ndo_get_stats64 = xlr_get_stats64,
+};
+
+/* Gmac init */
+static void *xlr_config_spill(struct xlr_net_priv *priv, int reg_start_0,
+               int reg_start_1, int reg_size, int size)
+{
+       void *spill;
+       u32 *base;
+       unsigned long phys_addr;
+       u32 spill_size;
+
+       base = priv->base_addr;
+       spill_size = size;
+       spill = kmalloc(spill_size + SMP_CACHE_BYTES, GFP_ATOMIC);
+       if (!spill)
+               pr_err("Unable to allocate memory for spill area!\n");
+
+       spill = PTR_ALIGN(spill, SMP_CACHE_BYTES);
+       phys_addr = virt_to_phys(spill);
+       dev_dbg(&priv->ndev->dev, "Allocated spill %d bytes at %lx\n",
+                       size, phys_addr);
+       xlr_nae_wreg(base, reg_start_0, (phys_addr >> 5) & 0xffffffff);
+       xlr_nae_wreg(base, reg_start_1, ((u64)phys_addr >> 37) & 0x07);
+       xlr_nae_wreg(base, reg_size, spill_size);
+
+       return spill;
+}
+
+/*
+ * Configure the 6 FIFO's that are used by the network accelarator to
+ * communicate with the rest of the XLx device. 4 of the FIFO's are for
+ * packets from NA --> cpu (called Class FIFO's) and 2 are for feeding
+ * the NA with free descriptors.
+ */
+static void xlr_config_fifo_spill_area(struct xlr_net_priv *priv)
+{
+       priv->frin_spill = xlr_config_spill(priv,
+                       R_REG_FRIN_SPILL_MEM_START_0,
+                       R_REG_FRIN_SPILL_MEM_START_1,
+                       R_REG_FRIN_SPILL_MEM_SIZE,
+                       MAX_FRIN_SPILL *
+                       sizeof(u64));
+       priv->frout_spill = xlr_config_spill(priv,
+                       R_FROUT_SPILL_MEM_START_0,
+                       R_FROUT_SPILL_MEM_START_1,
+                       R_FROUT_SPILL_MEM_SIZE,
+                       MAX_FROUT_SPILL *
+                       sizeof(u64));
+       priv->class_0_spill = xlr_config_spill(priv,
+                       R_CLASS0_SPILL_MEM_START_0,
+                       R_CLASS0_SPILL_MEM_START_1,
+                       R_CLASS0_SPILL_MEM_SIZE,
+                       MAX_CLASS_0_SPILL *
+                       sizeof(u64));
+       priv->class_1_spill = xlr_config_spill(priv,
+                       R_CLASS1_SPILL_MEM_START_0,
+                       R_CLASS1_SPILL_MEM_START_1,
+                       R_CLASS1_SPILL_MEM_SIZE,
+                       MAX_CLASS_1_SPILL *
+                       sizeof(u64));
+       priv->class_2_spill = xlr_config_spill(priv,
+                       R_CLASS2_SPILL_MEM_START_0,
+                       R_CLASS2_SPILL_MEM_START_1,
+                       R_CLASS2_SPILL_MEM_SIZE,
+                       MAX_CLASS_2_SPILL *
+                       sizeof(u64));
+       priv->class_3_spill = xlr_config_spill(priv,
+                       R_CLASS3_SPILL_MEM_START_0,
+                       R_CLASS3_SPILL_MEM_START_1,
+                       R_CLASS3_SPILL_MEM_SIZE,
+                       MAX_CLASS_3_SPILL *
+                       sizeof(u64));
+}
+
+/* Configure PDE to Round-Robin distribution of packets to the
+ * available cpu */
+static void xlr_config_pde(struct xlr_net_priv *priv)
+{
+       int i = 0;
+       u64 bkt_map = 0;
+
+       /* Each core has 8 buckets(station) */
+       for (i = 0; i < hweight32(priv->nd->cpu_mask); i++)
+               bkt_map |= (0xff << (i * 8));
+
+       xlr_nae_wreg(priv->base_addr, R_PDE_CLASS_0, (bkt_map & 0xffffffff));
+       xlr_nae_wreg(priv->base_addr, R_PDE_CLASS_0 + 1,
+                       ((bkt_map >> 32) & 0xffffffff));
+
+       xlr_nae_wreg(priv->base_addr, R_PDE_CLASS_1, (bkt_map & 0xffffffff));
+       xlr_nae_wreg(priv->base_addr, R_PDE_CLASS_1 + 1,
+                       ((bkt_map >> 32) & 0xffffffff));
+
+       xlr_nae_wreg(priv->base_addr, R_PDE_CLASS_2, (bkt_map & 0xffffffff));
+       xlr_nae_wreg(priv->base_addr, R_PDE_CLASS_2 + 1,
+                       ((bkt_map >> 32) & 0xffffffff));
+
+       xlr_nae_wreg(priv->base_addr, R_PDE_CLASS_3, (bkt_map & 0xffffffff));
+       xlr_nae_wreg(priv->base_addr, R_PDE_CLASS_3 + 1,
+                       ((bkt_map >> 32) & 0xffffffff));
+}
+
+/* Setup the Message ring credits, bucket size and other
+ * common configuration */
+static void xlr_config_common(struct xlr_net_priv *priv)
+{
+       struct xlr_fmn_info *gmac = priv->nd->gmac_fmn_info;
+       int start_stn_id = gmac->start_stn_id;
+       int end_stn_id = gmac->end_stn_id;
+       int *bucket_size = priv->nd->bucket_size;
+       int i, j;
+
+       /* Setting non-core MsgBktSize(0x321 - 0x325) */
+       for (i = start_stn_id; i <= end_stn_id; i++) {
+               xlr_nae_wreg(priv->base_addr,
+                               R_GMAC_RFR0_BUCKET_SIZE + i - start_stn_id,
+                               bucket_size[i]);
+       }
+
+       /* Setting non-core Credit counter register
+        * Distributing Gmac's credit to CPU's*/
+       for (i = 0; i < 8; i++) {
+               for (j = 0; j < 8; j++)
+                       xlr_nae_wreg(priv->base_addr,
+                                       (R_CC_CPU0_0 + (i * 8)) + j,
+                                       gmac->credit_config[(i * 8) + j]);
+       }
+
+       xlr_nae_wreg(priv->base_addr, R_MSG_TX_THRESHOLD, 3);
+       xlr_nae_wreg(priv->base_addr, R_DMACR0, 0xffffffff);
+       xlr_nae_wreg(priv->base_addr, R_DMACR1, 0xffffffff);
+       xlr_nae_wreg(priv->base_addr, R_DMACR2, 0xffffffff);
+       xlr_nae_wreg(priv->base_addr, R_DMACR3, 0xffffffff);
+       xlr_nae_wreg(priv->base_addr, R_FREEQCARVE, 0);
+
+       xlr_net_fill_rx_ring(priv->ndev);
+       nlm_register_fmn_handler(start_stn_id, end_stn_id, xlr_net_fmn_handler,
+                                       NULL);
+}
+
+static void xlr_config_translate_table(struct xlr_net_priv *priv)
+{
+       u32 cpu_mask;
+       u32 val;
+       int bkts[32]; /* one bucket is assumed for each cpu */
+       int b1, b2, c1, c2, i, j, k;
+       int use_bkt;
+
+       use_bkt = 0;
+       cpu_mask = priv->nd->cpu_mask;
+
+       pr_info("Using %s-based distribution\n",
+                       (use_bkt) ? "bucket" : "class");
+       j = 0;
+       for (i = 0; i < 32; i++) {
+               if ((1 << i) & cpu_mask) {
+                       /* for each cpu, mark the 4+threadid bucket */
+                       bkts[j] = ((i / 4) * 8) + (i % 4);
+                       j++;
+               }
+       }
+
+       /*configure the 128 * 9 Translation table to send to available buckets*/
+       k = 0;
+       c1 = 3;
+       c2 = 0;
+       for (i = 0; i < 64; i++) {
+               /* On use_bkt set the b0, b1 are used, else
+                * the 4 classes are used, here implemented
+                * a logic to distribute the packets to the
+                * buckets equally or based on the class
+                */
+               c1 = (c1 + 1) & 3;
+               c2 = (c1 + 1) & 3;
+               b1 = bkts[k];
+               k = (k + 1) % j;
+               b2 = bkts[k];
+               k = (k + 1) % j;
+               val = ((c1 << 23) | (b1 << 17) | (use_bkt << 16) |
+                               (c2 << 7) | (b2 << 1) | (use_bkt << 0));
+
+               val = ((c1 << 23) | (b1 << 17) | (use_bkt << 16) |
+                               (c2 << 7) | (b2 << 1) | (use_bkt << 0));
+               dev_dbg(&priv->ndev->dev, "Table[%d] b1=%d b2=%d c1=%d c2=%d\n",
+                               i, b1, b2, c1, c2);
+               xlr_nae_wreg(priv->base_addr, R_TRANSLATETABLE + i, val);
+               c1 = c2;
+       }
+}
+
+static void xlr_config_parser(struct xlr_net_priv *priv)
+{
+       u32 val;
+
+       /* Mark it as ETHERNET type */
+       xlr_nae_wreg(priv->base_addr, R_L2TYPE_0, 0x01);
+
+       /* Use 7bit CRChash for flow classification with 127 as CRC polynomial*/
+       xlr_nae_wreg(priv->base_addr, R_PARSERCONFIGREG,
+                       ((0x7f << 8) | (1 << 1)));
+
+       /* configure the parser : L2 Type is configured in the bootloader */
+       /* extract IP: src, dest protocol */
+       xlr_nae_wreg(priv->base_addr, R_L3CTABLE,
+                       (9 << 20) | (1 << 19) | (1 << 18) | (0x01 << 16) |
+                       (0x0800 << 0));
+       xlr_nae_wreg(priv->base_addr, R_L3CTABLE + 1,
+                       (9 << 25) | (1 << 21) | (12 << 14) | (4 << 10) |
+                       (16 << 4) | 4);
+
+       /* Configure to extract SRC port and Dest port for TCP and UDP pkts */
+       xlr_nae_wreg(priv->base_addr, R_L4CTABLE, 6);
+       xlr_nae_wreg(priv->base_addr, R_L4CTABLE + 2, 17);
+       val = ((0 << 21) | (2 << 17) | (2 << 11) | (2 << 7));
+       xlr_nae_wreg(priv->base_addr, R_L4CTABLE + 1, val);
+       xlr_nae_wreg(priv->base_addr, R_L4CTABLE + 3, val);
+
+       xlr_config_translate_table(priv);
+}
+
+static int xlr_phy_write(u32 *base_addr, int phy_addr, int regnum, u16 val)
+{
+       unsigned long timeout, stoptime, checktime;
+       int timedout;
+
+       /* 100ms timeout*/
+       timeout = msecs_to_jiffies(100);
+       stoptime = jiffies + timeout;
+       timedout = 0;
+
+       xlr_nae_wreg(base_addr, R_MII_MGMT_ADDRESS, (phy_addr << 8) | regnum);
+
+       /* Write the data which starts the write cycle */
+       xlr_nae_wreg(base_addr, R_MII_MGMT_WRITE_DATA, (u32) val);
+
+       /* poll for the read cycle to complete */
+       while (!timedout) {
+               checktime = jiffies;
+               if (xlr_nae_rdreg(base_addr, R_MII_MGMT_INDICATORS) == 0)
+                       break;
+               timedout = time_after(checktime, stoptime);
+       }
+       if (timedout) {
+               pr_info("Phy device write err: device busy");
+               return -EBUSY;
+       }
+
+       return 0;
+}
+
+static int xlr_phy_read(u32 *base_addr, int phy_addr, int regnum)
+{
+       unsigned long timeout, stoptime, checktime;
+       int timedout;
+
+       /* 100ms timeout*/
+       timeout = msecs_to_jiffies(100);
+       stoptime = jiffies + timeout;
+       timedout = 0;
+
+       /* setup the phy reg to be used */
+       xlr_nae_wreg(base_addr, R_MII_MGMT_ADDRESS,
+                       (phy_addr << 8) | (regnum << 0));
+
+       /* Issue the read command */
+       xlr_nae_wreg(base_addr, R_MII_MGMT_COMMAND,
+                       (1 << O_MII_MGMT_COMMAND__rstat));
+
+
+       /* poll for the read cycle to complete */
+       while (!timedout) {
+               checktime = jiffies;
+               if (xlr_nae_rdreg(base_addr, R_MII_MGMT_INDICATORS) == 0)
+                       break;
+               timedout = time_after(checktime, stoptime);
+       }
+       if (timedout) {
+               pr_info("Phy device read err: device busy");
+               return -EBUSY;
+       }
+
+       /* clear the read cycle */
+       xlr_nae_wreg(base_addr, R_MII_MGMT_COMMAND, 0);
+
+       /* Read the data */
+       return xlr_nae_rdreg(base_addr, R_MII_MGMT_STATUS);
+}
+
+static int xlr_mii_write(struct mii_bus *bus, int phy_addr, int regnum, u16 val)
+{
+       struct xlr_net_priv *priv = bus->priv;
+       int ret;
+
+       ret = xlr_phy_write(priv->mii_addr, phy_addr, regnum, val);
+       dev_dbg(&priv->ndev->dev, "mii_write phy %d : %d <- %x [%x]\n",
+                       phy_addr, regnum, val, ret);
+       return ret;
+}
+
+static int xlr_mii_read(struct mii_bus *bus, int phy_addr, int regnum)
+{
+       struct xlr_net_priv *priv = bus->priv;
+       int ret;
+
+       ret =  xlr_phy_read(priv->mii_addr, phy_addr, regnum);
+       dev_dbg(&priv->ndev->dev, "mii_read phy %d : %d [%x]\n",
+                       phy_addr, regnum, ret);
+       return ret;
+}
+
+/* XLR ports are RGMII. XLS ports are SGMII mostly except the port0,
+ * which can be configured either SGMII or RGMII, considered SGMII
+ * by default, if board setup to RGMII the port_type need to set
+ * accordingly.Serdes and PCS layer need to configured for SGMII
+ */
+static void xlr_sgmii_init(struct xlr_net_priv *priv)
+{
+       int phy;
+
+       xlr_phy_write(priv->serdes_addr, 26, 0, 0x6DB0);
+       xlr_phy_write(priv->serdes_addr, 26, 1, 0xFFFF);
+       xlr_phy_write(priv->serdes_addr, 26, 2, 0xB6D0);
+       xlr_phy_write(priv->serdes_addr, 26, 3, 0x00FF);
+       xlr_phy_write(priv->serdes_addr, 26, 4, 0x0000);
+       xlr_phy_write(priv->serdes_addr, 26, 5, 0x0000);
+       xlr_phy_write(priv->serdes_addr, 26, 6, 0x0005);
+       xlr_phy_write(priv->serdes_addr, 26, 7, 0x0001);
+       xlr_phy_write(priv->serdes_addr, 26, 8, 0x0000);
+       xlr_phy_write(priv->serdes_addr, 26, 9, 0x0000);
+       xlr_phy_write(priv->serdes_addr, 26, 10, 0x0000);
+
+       /* program  GPIO values for serdes init parameters */
+       xlr_nae_wreg(priv->gpio_addr, 0x20, 0x7e6802);
+       xlr_nae_wreg(priv->gpio_addr, 0x10, 0x7104);
+
+       xlr_nae_wreg(priv->gpio_addr, 0x22, 0x7e6802);
+       xlr_nae_wreg(priv->gpio_addr, 0x21, 0x7104);
+
+       /* enable autoneg - more magic */
+       phy = priv->port_id % 4 + 27;
+       xlr_phy_write(priv->pcs_addr, phy, 0, 0x1000);
+       xlr_phy_write(priv->pcs_addr, phy, 0, 0x0200);
+}
+
+void xlr_set_gmac_speed(struct xlr_net_priv *priv)
+{
+       struct phy_device *phydev = priv->mii_bus->phy_map[priv->phy_addr];
+       int speed;
+
+       if (phydev->interface == PHY_INTERFACE_MODE_SGMII)
+               xlr_sgmii_init(priv);
+
+       if (phydev->speed != priv->phy_speed) {
+               pr_info("change %d to %d\n", priv->phy_speed, phydev->speed);
+               speed = phydev->speed;
+               if (speed == SPEED_1000) {
+                       /* Set interface to Byte mode */
+                       xlr_nae_wreg(priv->base_addr, R_MAC_CONFIG_2, 0x7217);
+                       priv->phy_speed = speed;
+               } else if (speed == SPEED_100 || speed == SPEED_10) {
+                       /* Set interface to Nibble mode */
+                       xlr_nae_wreg(priv->base_addr, R_MAC_CONFIG_2, 0x7117);
+                       priv->phy_speed = speed;
+               }
+               /* Set SGMII speed in Interface controll reg */
+               if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
+                       if (speed == SPEED_10)
+                               xlr_nae_wreg(priv->base_addr,
+                                       R_INTERFACE_CONTROL, SGMII_SPEED_10);
+                       if (speed == SPEED_100)
+                               xlr_nae_wreg(priv->base_addr,
+                                       R_INTERFACE_CONTROL, SGMII_SPEED_100);
+                       if (speed == SPEED_1000)
+                               xlr_nae_wreg(priv->base_addr,
+                                       R_INTERFACE_CONTROL, SGMII_SPEED_1000);
+               }
+               if (speed == SPEED_10)
+                       xlr_nae_wreg(priv->base_addr, R_CORECONTROL, 0x2);
+               if (speed == SPEED_100)
+                       xlr_nae_wreg(priv->base_addr, R_CORECONTROL, 0x1);
+               if (speed == SPEED_1000)
+                       xlr_nae_wreg(priv->base_addr, R_CORECONTROL, 0x0);
+       }
+       pr_info("gmac%d : %dMbps\n", priv->port_id, priv->phy_speed);
+}
+
+static void xlr_gmac_link_adjust(struct net_device *ndev)
+{
+       struct xlr_net_priv *priv = netdev_priv(ndev);
+       struct phy_device *phydev = priv->mii_bus->phy_map[priv->phy_addr];
+       u32 intreg;
+
+       intreg = xlr_nae_rdreg(priv->base_addr, R_INTREG);
+       if (phydev->link) {
+               if (phydev->speed != priv->phy_speed) {
+                       pr_info("gmac%d : Link up\n", priv->port_id);
+                       xlr_set_gmac_speed(priv);
+               }
+       } else {
+               pr_info("gmac%d : Link down\n", priv->port_id);
+               xlr_set_gmac_speed(priv);
+       }
+}
+
+static int xlr_mii_probe(struct xlr_net_priv *priv)
+{
+       struct phy_device *phydev = priv->mii_bus->phy_map[priv->phy_addr];
+
+       if (!phydev) {
+               pr_err("no PHY found on phy_addr %d\n", priv->phy_addr);
+               return -ENODEV;
+       }
+
+       /* Attach MAC to PHY */
+       phydev = phy_connect(priv->ndev, dev_name(&phydev->dev),
+                       &xlr_gmac_link_adjust, priv->nd->phy_interface);
+
+       if (IS_ERR(phydev)) {
+               pr_err("could not attach PHY\n");
+               return PTR_ERR(phydev);
+       }
+       phydev->supported &= (ADVERTISED_10baseT_Full
+                               | ADVERTISED_10baseT_Half
+                               | ADVERTISED_100baseT_Full
+                               | ADVERTISED_100baseT_Half
+                               | ADVERTISED_1000baseT_Full
+                               | ADVERTISED_Autoneg
+                               | ADVERTISED_MII);
+
+       phydev->advertising = phydev->supported;
+       pr_info("attached PHY driver [%s] (mii_bus:phy_addr=%s\n",
+               phydev->drv->name, dev_name(&phydev->dev));
+       return 0;
+}
+
+static int xlr_setup_mdio(struct xlr_net_priv *priv,
+               struct platform_device *pdev)
+{
+       int err;
+
+       priv->phy_addr = priv->nd->phy_addr;
+       priv->mii_bus = mdiobus_alloc();
+       if (!priv->mii_bus) {
+               pr_err("mdiobus alloc failed\n");
+               return -ENOMEM;
+       }
+
+       priv->mii_bus->priv = priv;
+       priv->mii_bus->name = "xlr-mdio";
+       snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%d",
+                       priv->mii_bus->name, priv->port_id);
+       priv->mii_bus->read = xlr_mii_read;
+       priv->mii_bus->write = xlr_mii_write;
+       priv->mii_bus->parent = &pdev->dev;
+       priv->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
+       priv->mii_bus->irq[priv->phy_addr] = priv->ndev->irq;
+
+       /* Scan only the enabled address */
+       priv->mii_bus->phy_mask = ~(1 << priv->phy_addr);
+
+       /* setting clock divisor to 54 */
+       xlr_nae_wreg(priv->base_addr, R_MII_MGMT_CONFIG, 0x7);
+
+       err = mdiobus_register(priv->mii_bus);
+       if (err) {
+               mdiobus_free(priv->mii_bus);
+               pr_err("mdio bus registration failed\n");
+               return err;
+       }
+
+       pr_info("Registerd mdio bus id : %s\n", priv->mii_bus->id);
+       err = xlr_mii_probe(priv);
+       if (err) {
+               mdiobus_free(priv->mii_bus);
+               return err;
+       }
+       return 0;
+}
+
+static void xlr_port_enable(struct xlr_net_priv *priv)
+{
+       u32 prid = (read_c0_prid() & 0xf000);
+
+       /* Setup MAC_CONFIG reg if (xls & rgmii) */
+       if ((prid == 0x8000 || prid == 0x4000 || prid == 0xc000) &&
+                       priv->nd->phy_interface == PHY_INTERFACE_MODE_RGMII)
+               xlr_reg_update(priv->base_addr, R_RX_CONTROL,
+                       (1 << O_RX_CONTROL__RGMII), (1 << O_RX_CONTROL__RGMII));
+
+       /* Rx Tx enable */
+       xlr_reg_update(priv->base_addr, R_MAC_CONFIG_1,
+               ((1 << O_MAC_CONFIG_1__rxen) | (1 << O_MAC_CONFIG_1__txen) |
+               (1 << O_MAC_CONFIG_1__rxfc) | (1 << O_MAC_CONFIG_1__txfc)),
+               ((1 << O_MAC_CONFIG_1__rxen) | (1 << O_MAC_CONFIG_1__txen) |
+               (1 << O_MAC_CONFIG_1__rxfc) | (1 << O_MAC_CONFIG_1__txfc)));
+
+       /* Setup tx control reg */
+       xlr_reg_update(priv->base_addr, R_TX_CONTROL,
+               ((1 << O_TX_CONTROL__TxEnable) |
+               (512 << O_TX_CONTROL__TxThreshold)), 0x3fff);
+
+       /* Setup rx control reg */
+       xlr_reg_update(priv->base_addr, R_RX_CONTROL,
+               1 << O_RX_CONTROL__RxEnable, 1 << O_RX_CONTROL__RxEnable);
+}
+
+static void xlr_port_disable(struct xlr_net_priv *priv)
+{
+       /* Setup MAC_CONFIG reg */
+       /* Rx Tx disable*/
+       xlr_reg_update(priv->base_addr, R_MAC_CONFIG_1,
+               ((1 << O_MAC_CONFIG_1__rxen) | (1 << O_MAC_CONFIG_1__txen) |
+               (1 << O_MAC_CONFIG_1__rxfc) | (1 << O_MAC_CONFIG_1__txfc)),
+               0x0);
+
+       /* Setup tx control reg */
+       xlr_reg_update(priv->base_addr, R_TX_CONTROL,
+               ((1 << O_TX_CONTROL__TxEnable) |
+               (512 << O_TX_CONTROL__TxThreshold)), 0);
+
+       /* Setup rx control reg */
+       xlr_reg_update(priv->base_addr, R_RX_CONTROL,
+               1 << O_RX_CONTROL__RxEnable, 0);
+}
+
+/* Initialization of gmac */
+static int xlr_gmac_init(struct xlr_net_priv *priv,
+               struct platform_device *pdev)
+{
+       int ret;
+
+       pr_info("Initializing the gmac%d\n", priv->port_id);
+
+       xlr_port_disable(priv);
+       xlr_nae_wreg(priv->base_addr, R_DESC_PACK_CTRL,
+                       (1 << O_DESC_PACK_CTRL__MaxEntry)
+                       | (BYTE_OFFSET << O_DESC_PACK_CTRL__ByteOffset)
+                       | (1600 << O_DESC_PACK_CTRL__RegularSize));
+
+       ret = xlr_setup_mdio(priv, pdev);
+       if (ret)
+               return ret;
+       xlr_port_enable(priv);
+
+       /* Enable Full-duplex/1000Mbps/CRC */
+       xlr_nae_wreg(priv->base_addr, R_MAC_CONFIG_2, 0x7217);
+       /* speed 2.5Mhz */
+       xlr_nae_wreg(priv->base_addr, R_CORECONTROL, 0x02);
+       /* Setup Interrupt mask reg */
+       xlr_nae_wreg(priv->base_addr, R_INTMASK,
+               (1 << O_INTMASK__TxIllegal)     |
+               (1 << O_INTMASK__MDInt)         |
+               (1 << O_INTMASK__TxFetchError)  |
+               (1 << O_INTMASK__P2PSpillEcc)   |
+               (1 << O_INTMASK__TagFull)       |
+               (1 << O_INTMASK__Underrun)      |
+               (1 << O_INTMASK__Abort)
+               );
+
+       /* Clear all stats */
+       xlr_reg_update(priv->base_addr, R_STATCTRL,
+               0, 1 << O_STATCTRL__ClrCnt);
+       xlr_reg_update(priv->base_addr, R_STATCTRL,
+               1 << O_STATCTRL__ClrCnt, 1 << O_STATCTRL__ClrCnt);
+       return 0;
+}
+
+static int xlr_net_probe(struct platform_device *pdev)
+{
+       struct xlr_net_priv *priv = NULL;
+       struct net_device *ndev;
+       struct resource *res;
+       int mac, err;
+
+       mac = pdev->id;
+       ndev = alloc_etherdev_mq(sizeof(struct xlr_net_priv), 32);
+       if (!ndev) {
+               pr_err("Allocation of Ethernet device failed\n");
+               return -ENOMEM;
+       }
+
+       priv = netdev_priv(ndev);
+       priv->pdev = pdev;
+       priv->ndev = ndev;
+       priv->port_id = mac;
+       priv->nd = (struct xlr_net_data *)pdev->dev.platform_data;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (res == NULL) {
+               pr_err("No memory resource for MAC %d\n", mac);
+               err = -ENODEV;
+               goto err_gmac;
+       }
+
+       ndev->base_addr = (unsigned long) devm_request_and_ioremap
+               (&pdev->dev, res);
+       if (!ndev->base_addr) {
+               dev_err(&pdev->dev,
+                               "devm_request_and_ioremap failed\n");
+               return -EBUSY;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+       if (res == NULL) {
+               pr_err("No irq resource for MAC %d\n", mac);
+               err = -ENODEV;
+               goto err_gmac;
+       }
+       ndev->irq = res->start;
+
+       priv->mii_addr = priv->nd->mii_addr;
+       priv->serdes_addr = priv->nd->serdes_addr;
+       priv->pcs_addr = priv->nd->pcs_addr;
+       priv->gpio_addr = priv->nd->gpio_addr;
+       priv->base_addr = (u32 *) ndev->base_addr;
+
+       mac_to_ndev[mac] = ndev;
+       ndev->netdev_ops = &xlr_netdev_ops;
+       ndev->watchdog_timeo = HZ;
+
+       /* Setup Mac address and Rx mode */
+       eth_hw_addr_random(ndev);
+       xlr_hw_set_mac_addr(ndev);
+       xlr_set_rx_mode(ndev);
+
+       priv->num_rx_desc += MAX_NUM_DESC_SPILL;
+       SET_ETHTOOL_OPS(ndev, &xlr_ethtool_ops);
+       SET_NETDEV_DEV(ndev, &pdev->dev);
+
+       /* Common registers, do one time initialization */
+       if (mac == 0 || mac == 4) {
+               xlr_config_fifo_spill_area(priv);
+               /* Configure PDE to Round-Robin pkt distribution */
+               xlr_config_pde(priv);
+               xlr_config_parser(priv);
+       }
+       /* Call init with respect to port */
+       if (strcmp(res->name, "gmac") == 0) {
+               err = xlr_gmac_init(priv, pdev);
+               if (err) {
+                       pr_err("gmac%d init failed\n", mac);
+                       goto err_gmac;
+               }
+       }
+
+       if (mac == 0 || mac == 4)
+               xlr_config_common(priv);
+
+       err = register_netdev(ndev);
+       if (err)
+               goto err_netdev;
+       platform_set_drvdata(pdev, priv);
+       return 0;
+
+err_netdev:
+       mdiobus_free(priv->mii_bus);
+err_gmac:
+       free_netdev(ndev);
+       return err;
+}
+
+static int xlr_net_remove(struct platform_device *pdev)
+{
+       struct xlr_net_priv *priv = platform_get_drvdata(pdev);
+       unregister_netdev(priv->ndev);
+       mdiobus_unregister(priv->mii_bus);
+       mdiobus_free(priv->mii_bus);
+       free_netdev(priv->ndev);
+       return 0;
+}
+
+static struct platform_driver xlr_net_driver = {
+       .probe          = xlr_net_probe,
+       .remove         = xlr_net_remove,
+       .driver         = {
+               .name   = "xlr-net",
+               .owner  = THIS_MODULE,
+       },
+};
+
+module_platform_driver(xlr_net_driver);
+
+MODULE_AUTHOR("Ganesan Ramalingam <ganesanr@broadcom.com>");
+MODULE_DESCRIPTION("Ethernet driver for Netlogic XLR/XLS");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_ALIAS("platform:xlr-net");
diff --git a/drivers/staging/netlogic/xlr_net.h b/drivers/staging/netlogic/xlr_net.h
new file mode 100644 (file)
index 0000000..f91d27e
--- /dev/null
@@ -0,0 +1,1099 @@
+/*
+ * Copyright (c) 2003-2012 Broadcom Corporation
+ * All Rights Reserved
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the Broadcom
+ * license below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BROADCOM ``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 BROADCOM 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.
+ */
+/* #define MAC_SPLIT_MODE */
+
+#define MAC_SPACING                 0x400
+#define XGMAC_SPACING               0x400
+
+/* PE-MCXMAC register and bit field definitions */
+#define R_MAC_CONFIG_1                                              0x00
+#define   O_MAC_CONFIG_1__srst                                      31
+#define   O_MAC_CONFIG_1__simr                                      30
+#define   O_MAC_CONFIG_1__hrrmc                                     18
+#define   W_MAC_CONFIG_1__hrtmc                                      2
+#define   O_MAC_CONFIG_1__hrrfn                                     16
+#define   W_MAC_CONFIG_1__hrtfn                                      2
+#define   O_MAC_CONFIG_1__intlb                                      8
+#define   O_MAC_CONFIG_1__rxfc                                       5
+#define   O_MAC_CONFIG_1__txfc                                       4
+#define   O_MAC_CONFIG_1__srxen                                      3
+#define   O_MAC_CONFIG_1__rxen                                       2
+#define   O_MAC_CONFIG_1__stxen                                      1
+#define   O_MAC_CONFIG_1__txen                                       0
+#define R_MAC_CONFIG_2                                              0x01
+#define   O_MAC_CONFIG_2__prlen                                     12
+#define   W_MAC_CONFIG_2__prlen                                      4
+#define   O_MAC_CONFIG_2__speed                                      8
+#define   W_MAC_CONFIG_2__speed                                      2
+#define   O_MAC_CONFIG_2__hugen                                      5
+#define   O_MAC_CONFIG_2__flchk                                      4
+#define   O_MAC_CONFIG_2__crce                                       1
+#define   O_MAC_CONFIG_2__fulld                                      0
+#define R_IPG_IFG                                                   0x02
+#define   O_IPG_IFG__ipgr1                                          24
+#define   W_IPG_IFG__ipgr1                                           7
+#define   O_IPG_IFG__ipgr2                                          16
+#define   W_IPG_IFG__ipgr2                                           7
+#define   O_IPG_IFG__mifg                                            8
+#define   W_IPG_IFG__mifg                                            8
+#define   O_IPG_IFG__ipgt                                            0
+#define   W_IPG_IFG__ipgt                                            7
+#define R_HALF_DUPLEX                                               0x03
+#define   O_HALF_DUPLEX__abebt                                      24
+#define   W_HALF_DUPLEX__abebt                                       4
+#define   O_HALF_DUPLEX__abebe                                      19
+#define   O_HALF_DUPLEX__bpnb                                       18
+#define   O_HALF_DUPLEX__nobo                                       17
+#define   O_HALF_DUPLEX__edxsdfr                                    16
+#define   O_HALF_DUPLEX__retry                                      12
+#define   W_HALF_DUPLEX__retry                                       4
+#define   O_HALF_DUPLEX__lcol                                        0
+#define   W_HALF_DUPLEX__lcol                                       10
+#define R_MAXIMUM_FRAME_LENGTH                                      0x04
+#define   O_MAXIMUM_FRAME_LENGTH__maxf                               0
+#define   W_MAXIMUM_FRAME_LENGTH__maxf                              16
+#define R_TEST                                                      0x07
+#define   O_TEST__mbof                                               3
+#define   O_TEST__rthdf                                              2
+#define   O_TEST__tpause                                             1
+#define   O_TEST__sstct                                              0
+#define R_MII_MGMT_CONFIG                                           0x08
+#define   O_MII_MGMT_CONFIG__scinc                                   5
+#define   O_MII_MGMT_CONFIG__spre                                    4
+#define   O_MII_MGMT_CONFIG__clks                                    3
+#define   W_MII_MGMT_CONFIG__clks                                    3
+#define R_MII_MGMT_COMMAND                                          0x09
+#define   O_MII_MGMT_COMMAND__scan                                   1
+#define   O_MII_MGMT_COMMAND__rstat                                  0
+#define R_MII_MGMT_ADDRESS                                          0x0A
+#define   O_MII_MGMT_ADDRESS__fiad                                   8
+#define   W_MII_MGMT_ADDRESS__fiad                                   5
+#define   O_MII_MGMT_ADDRESS__fgad                                   5
+#define   W_MII_MGMT_ADDRESS__fgad                                   0
+#define R_MII_MGMT_WRITE_DATA                                       0x0B
+#define   O_MII_MGMT_WRITE_DATA__ctld                                0
+#define   W_MII_MGMT_WRITE_DATA__ctld                               16
+#define R_MII_MGMT_STATUS                                           0x0C
+#define R_MII_MGMT_INDICATORS                                       0x0D
+#define   O_MII_MGMT_INDICATORS__nvalid                              2
+#define   O_MII_MGMT_INDICATORS__scan                                1
+#define   O_MII_MGMT_INDICATORS__busy                                0
+#define R_INTERFACE_CONTROL                                         0x0E
+#define   O_INTERFACE_CONTROL__hrstint                              31
+#define   O_INTERFACE_CONTROL__tbimode                              27
+#define   O_INTERFACE_CONTROL__ghdmode                              26
+#define   O_INTERFACE_CONTROL__lhdmode                              25
+#define   O_INTERFACE_CONTROL__phymod                               24
+#define   O_INTERFACE_CONTROL__hrrmi                                23
+#define   O_INTERFACE_CONTROL__rspd                                 16
+#define   O_INTERFACE_CONTROL__hr100                                15
+#define   O_INTERFACE_CONTROL__frcq                                 10
+#define   O_INTERFACE_CONTROL__nocfr                                 9
+#define   O_INTERFACE_CONTROL__dlfct                                 8
+#define   O_INTERFACE_CONTROL__enjab                                 0
+#define R_INTERFACE_STATUS                                         0x0F
+#define   O_INTERFACE_STATUS__xsdfr                                  9
+#define   O_INTERFACE_STATUS__ssrr                                   8
+#define   W_INTERFACE_STATUS__ssrr                                   5
+#define   O_INTERFACE_STATUS__miilf                                  3
+#define   O_INTERFACE_STATUS__locar                                  2
+#define   O_INTERFACE_STATUS__sqerr                                  1
+#define   O_INTERFACE_STATUS__jabber                                 0
+#define R_STATION_ADDRESS_LS                                       0x10
+#define R_STATION_ADDRESS_MS                                       0x11
+
+/* A-XGMAC register and bit field definitions */
+#define R_XGMAC_CONFIG_0    0x00
+#define   O_XGMAC_CONFIG_0__hstmacrst               31
+#define   O_XGMAC_CONFIG_0__hstrstrctl              23
+#define   O_XGMAC_CONFIG_0__hstrstrfn               22
+#define   O_XGMAC_CONFIG_0__hstrsttctl              18
+#define   O_XGMAC_CONFIG_0__hstrsttfn               17
+#define   O_XGMAC_CONFIG_0__hstrstmiim              16
+#define   O_XGMAC_CONFIG_0__hstloopback             8
+#define R_XGMAC_CONFIG_1    0x01
+#define   O_XGMAC_CONFIG_1__hsttctlen               31
+#define   O_XGMAC_CONFIG_1__hsttfen                 30
+#define   O_XGMAC_CONFIG_1__hstrctlen               29
+#define   O_XGMAC_CONFIG_1__hstrfen                 28
+#define   O_XGMAC_CONFIG_1__tfen                    26
+#define   O_XGMAC_CONFIG_1__rfen                    24
+#define   O_XGMAC_CONFIG_1__hstrctlshrtp            12
+#define   O_XGMAC_CONFIG_1__hstdlyfcstx             10
+#define   W_XGMAC_CONFIG_1__hstdlyfcstx              2
+#define   O_XGMAC_CONFIG_1__hstdlyfcsrx              8
+#define   W_XGMAC_CONFIG_1__hstdlyfcsrx              2
+#define   O_XGMAC_CONFIG_1__hstppen                  7
+#define   O_XGMAC_CONFIG_1__hstbytswp                6
+#define   O_XGMAC_CONFIG_1__hstdrplt64               5
+#define   O_XGMAC_CONFIG_1__hstprmscrx               4
+#define   O_XGMAC_CONFIG_1__hstlenchk                3
+#define   O_XGMAC_CONFIG_1__hstgenfcs                2
+#define   O_XGMAC_CONFIG_1__hstpadmode               0
+#define   W_XGMAC_CONFIG_1__hstpadmode               2
+#define R_XGMAC_CONFIG_2    0x02
+#define   O_XGMAC_CONFIG_2__hsttctlfrcp             31
+#define   O_XGMAC_CONFIG_2__hstmlnkflth             27
+#define   O_XGMAC_CONFIG_2__hstalnkflth             26
+#define   O_XGMAC_CONFIG_2__rflnkflt                24
+#define   W_XGMAC_CONFIG_2__rflnkflt                 2
+#define   O_XGMAC_CONFIG_2__hstipgextmod            16
+#define   W_XGMAC_CONFIG_2__hstipgextmod             5
+#define   O_XGMAC_CONFIG_2__hstrctlfrcp             15
+#define   O_XGMAC_CONFIG_2__hstipgexten              5
+#define   O_XGMAC_CONFIG_2__hstmipgext               0
+#define   W_XGMAC_CONFIG_2__hstmipgext               5
+#define R_XGMAC_CONFIG_3    0x03
+#define   O_XGMAC_CONFIG_3__hstfltrfrm              31
+#define   W_XGMAC_CONFIG_3__hstfltrfrm              16
+#define   O_XGMAC_CONFIG_3__hstfltrfrmdc            15
+#define   W_XGMAC_CONFIG_3__hstfltrfrmdc            16
+#define R_XGMAC_STATION_ADDRESS_LS      0x04
+#define   O_XGMAC_STATION_ADDRESS_LS__hstmacadr0    0
+#define   W_XGMAC_STATION_ADDRESS_LS__hstmacadr0    32
+#define R_XGMAC_STATION_ADDRESS_MS      0x05
+#define R_XGMAC_MAX_FRAME_LEN           0x08
+#define   O_XGMAC_MAX_FRAME_LEN__hstmxfrmwctx       16
+#define   W_XGMAC_MAX_FRAME_LEN__hstmxfrmwctx       14
+#define   O_XGMAC_MAX_FRAME_LEN__hstmxfrmbcrx        0
+#define   W_XGMAC_MAX_FRAME_LEN__hstmxfrmbcrx       16
+#define R_XGMAC_REV_LEVEL               0x0B
+#define   O_XGMAC_REV_LEVEL__revlvl                  0
+#define   W_XGMAC_REV_LEVEL__revlvl                 15
+#define R_XGMAC_MIIM_COMMAND            0x10
+#define   O_XGMAC_MIIM_COMMAND__hstldcmd             3
+#define   O_XGMAC_MIIM_COMMAND__hstmiimcmd           0
+#define   W_XGMAC_MIIM_COMMAND__hstmiimcmd           3
+#define R_XGMAC_MIIM_FILED              0x11
+#define   O_XGMAC_MIIM_FILED__hststfield            30
+#define   W_XGMAC_MIIM_FILED__hststfield             2
+#define   O_XGMAC_MIIM_FILED__hstopfield            28
+#define   W_XGMAC_MIIM_FILED__hstopfield             2
+#define   O_XGMAC_MIIM_FILED__hstphyadx             23
+#define   W_XGMAC_MIIM_FILED__hstphyadx              5
+#define   O_XGMAC_MIIM_FILED__hstregadx             18
+#define   W_XGMAC_MIIM_FILED__hstregadx              5
+#define   O_XGMAC_MIIM_FILED__hsttafield            16
+#define   W_XGMAC_MIIM_FILED__hsttafield             2
+#define   O_XGMAC_MIIM_FILED__miimrddat              0
+#define   W_XGMAC_MIIM_FILED__miimrddat             16
+#define R_XGMAC_MIIM_CONFIG             0x12
+#define   O_XGMAC_MIIM_CONFIG__hstnopram             7
+#define   O_XGMAC_MIIM_CONFIG__hstclkdiv             0
+#define   W_XGMAC_MIIM_CONFIG__hstclkdiv             7
+#define R_XGMAC_MIIM_LINK_FAIL_VECTOR   0x13
+#define   O_XGMAC_MIIM_LINK_FAIL_VECTOR__miimlfvec   0
+#define   W_XGMAC_MIIM_LINK_FAIL_VECTOR__miimlfvec  32
+#define R_XGMAC_MIIM_INDICATOR          0x14
+#define   O_XGMAC_MIIM_INDICATOR__miimphylf          4
+#define   O_XGMAC_MIIM_INDICATOR__miimmoncplt        3
+#define   O_XGMAC_MIIM_INDICATOR__miimmonvld         2
+#define   O_XGMAC_MIIM_INDICATOR__miimmon            1
+#define   O_XGMAC_MIIM_INDICATOR__miimbusy           0
+
+/* GMAC stats registers */
+#define R_RBYT                                                     0x27
+#define R_RPKT                                                     0x28
+#define R_RFCS                                                     0x29
+#define R_RMCA                                                     0x2A
+#define R_RBCA                                                     0x2B
+#define R_RXCF                                                     0x2C
+#define R_RXPF                                                     0x2D
+#define R_RXUO                                                     0x2E
+#define R_RALN                                                     0x2F
+#define R_RFLR                                                     0x30
+#define R_RCDE                                                     0x31
+#define R_RCSE                                                     0x32
+#define R_RUND                                                     0x33
+#define R_ROVR                                                     0x34
+#define R_TBYT                                                     0x38
+#define R_TPKT                                                     0x39
+#define R_TMCA                                                     0x3A
+#define R_TBCA                                                     0x3B
+#define R_TXPF                                                     0x3C
+#define R_TDFR                                                     0x3D
+#define R_TEDF                                                     0x3E
+#define R_TSCL                                                     0x3F
+#define R_TMCL                                                     0x40
+#define R_TLCL                                                     0x41
+#define R_TXCL                                                     0x42
+#define R_TNCL                                                     0x43
+#define R_TJBR                                                     0x46
+#define R_TFCS                                                     0x47
+#define R_TXCF                                                     0x48
+#define R_TOVR                                                     0x49
+#define R_TUND                                                     0x4A
+#define R_TFRG                                                     0x4B
+
+/* Glue logic register and bit field definitions */
+#define R_MAC_ADDR0                                                 0x50
+#define R_MAC_ADDR1                                                 0x52
+#define R_MAC_ADDR2                                                 0x54
+#define R_MAC_ADDR3                                                 0x56
+#define R_MAC_ADDR_MASK2                                            0x58
+#define R_MAC_ADDR_MASK3                                            0x5A
+#define R_MAC_FILTER_CONFIG                                         0x5C
+#define   O_MAC_FILTER_CONFIG__BROADCAST_EN                         10
+#define   O_MAC_FILTER_CONFIG__PAUSE_FRAME_EN                       9
+#define   O_MAC_FILTER_CONFIG__ALL_MCAST_EN                         8
+#define   O_MAC_FILTER_CONFIG__ALL_UCAST_EN                         7
+#define   O_MAC_FILTER_CONFIG__HASH_MCAST_EN                        6
+#define   O_MAC_FILTER_CONFIG__HASH_UCAST_EN                        5
+#define   O_MAC_FILTER_CONFIG__ADDR_MATCH_DISC                      4
+#define   O_MAC_FILTER_CONFIG__MAC_ADDR3_VALID                      3
+#define   O_MAC_FILTER_CONFIG__MAC_ADDR2_VALID                      2
+#define   O_MAC_FILTER_CONFIG__MAC_ADDR1_VALID                      1
+#define   O_MAC_FILTER_CONFIG__MAC_ADDR0_VALID                      0
+#define R_HASH_TABLE_VECTOR                                         0x30
+#define R_TX_CONTROL                                                 0x0A0
+#define   O_TX_CONTROL__Tx15Halt                                     31
+#define   O_TX_CONTROL__Tx14Halt                                     30
+#define   O_TX_CONTROL__Tx13Halt                                     29
+#define   O_TX_CONTROL__Tx12Halt                                     28
+#define   O_TX_CONTROL__Tx11Halt                                     27
+#define   O_TX_CONTROL__Tx10Halt                                     26
+#define   O_TX_CONTROL__Tx9Halt                                      25
+#define   O_TX_CONTROL__Tx8Halt                                      24
+#define   O_TX_CONTROL__Tx7Halt                                      23
+#define   O_TX_CONTROL__Tx6Halt                                      22
+#define   O_TX_CONTROL__Tx5Halt                                      21
+#define   O_TX_CONTROL__Tx4Halt                                      20
+#define   O_TX_CONTROL__Tx3Halt                                      19
+#define   O_TX_CONTROL__Tx2Halt                                      18
+#define   O_TX_CONTROL__Tx1Halt                                      17
+#define   O_TX_CONTROL__Tx0Halt                                      16
+#define   O_TX_CONTROL__TxIdle                                       15
+#define   O_TX_CONTROL__TxEnable                                     14
+#define   O_TX_CONTROL__TxThreshold                                  0
+#define   W_TX_CONTROL__TxThreshold                                  14
+#define R_RX_CONTROL                                                 0x0A1
+#define   O_RX_CONTROL__RGMII                                        10
+#define   O_RX_CONTROL__SoftReset                                   2
+#define   O_RX_CONTROL__RxHalt                                       1
+#define   O_RX_CONTROL__RxEnable                                     0
+#define R_DESC_PACK_CTRL                                            0x0A2
+#define   O_DESC_PACK_CTRL__ByteOffset                              17
+#define   W_DESC_PACK_CTRL__ByteOffset                              3
+#define   O_DESC_PACK_CTRL__PrePadEnable                            16
+#define   O_DESC_PACK_CTRL__MaxEntry                                14
+#define   W_DESC_PACK_CTRL__MaxEntry                                2
+#define   O_DESC_PACK_CTRL__RegularSize                             0
+#define   W_DESC_PACK_CTRL__RegularSize                             14
+#define R_STATCTRL                                                  0x0A3
+#define   O_STATCTRL__OverFlowEn                                    4
+#define   O_STATCTRL__GIG                                           3
+#define   O_STATCTRL__Sten                                          2
+#define   O_STATCTRL__ClrCnt                                        1
+#define   O_STATCTRL__AutoZ                                         0
+#define R_L2ALLOCCTRL                                               0x0A4
+#define   O_L2ALLOCCTRL__TxL2Allocate                               9
+#define   W_L2ALLOCCTRL__TxL2Allocate                               9
+#define   O_L2ALLOCCTRL__RxL2Allocate                               0
+#define   W_L2ALLOCCTRL__RxL2Allocate                               9
+#define R_INTMASK                                                   0x0A5
+#define   O_INTMASK__Spi4TxError                                     28
+#define   O_INTMASK__Spi4RxError                                     27
+#define   O_INTMASK__RGMIIHalfDupCollision                           27
+#define   O_INTMASK__Abort                                           26
+#define   O_INTMASK__Underrun                                        25
+#define   O_INTMASK__DiscardPacket                                   24
+#define   O_INTMASK__AsyncFifoFull                                   23
+#define   O_INTMASK__TagFull                                         22
+#define   O_INTMASK__Class3Full                                      21
+#define   O_INTMASK__C3EarlyFull                                     20
+#define   O_INTMASK__Class2Full                                      19
+#define   O_INTMASK__C2EarlyFull                                     18
+#define   O_INTMASK__Class1Full                                      17
+#define   O_INTMASK__C1EarlyFull                                     16
+#define   O_INTMASK__Class0Full                                      15
+#define   O_INTMASK__C0EarlyFull                                     14
+#define   O_INTMASK__RxDataFull                                      13
+#define   O_INTMASK__RxEarlyFull                                     12
+#define   O_INTMASK__RFreeEmpty                                      9
+#define   O_INTMASK__RFEarlyEmpty                                    8
+#define   O_INTMASK__P2PSpillEcc                                     7
+#define   O_INTMASK__FreeDescFull                                    5
+#define   O_INTMASK__FreeEarlyFull                                   4
+#define   O_INTMASK__TxFetchError                                    3
+#define   O_INTMASK__StatCarry                                       2
+#define   O_INTMASK__MDInt                                           1
+#define   O_INTMASK__TxIllegal                                       0
+#define R_INTREG                                                    0x0A6
+#define   O_INTREG__Spi4TxError                                     28
+#define   O_INTREG__Spi4RxError                                     27
+#define   O_INTREG__RGMIIHalfDupCollision                           27
+#define   O_INTREG__Abort                                           26
+#define   O_INTREG__Underrun                                        25
+#define   O_INTREG__DiscardPacket                                   24
+#define   O_INTREG__AsyncFifoFull                                   23
+#define   O_INTREG__TagFull                                         22
+#define   O_INTREG__Class3Full                                      21
+#define   O_INTREG__C3EarlyFull                                     20
+#define   O_INTREG__Class2Full                                      19
+#define   O_INTREG__C2EarlyFull                                     18
+#define   O_INTREG__Class1Full                                      17
+#define   O_INTREG__C1EarlyFull                                     16
+#define   O_INTREG__Class0Full                                      15
+#define   O_INTREG__C0EarlyFull                                     14
+#define   O_INTREG__RxDataFull                                      13
+#define   O_INTREG__RxEarlyFull                                     12
+#define   O_INTREG__RFreeEmpty                                      9
+#define   O_INTREG__RFEarlyEmpty                                    8
+#define   O_INTREG__P2PSpillEcc                                     7
+#define   O_INTREG__FreeDescFull                                    5
+#define   O_INTREG__FreeEarlyFull                                   4
+#define   O_INTREG__TxFetchError                                    3
+#define   O_INTREG__StatCarry                                       2
+#define   O_INTREG__MDInt                                           1
+#define   O_INTREG__TxIllegal                                       0
+#define R_TXRETRY                                                   0x0A7
+#define   O_TXRETRY__CollisionRetry                                 6
+#define   O_TXRETRY__BusErrorRetry                                  5
+#define   O_TXRETRY__UnderRunRetry                                  4
+#define   O_TXRETRY__Retries                                        0
+#define   W_TXRETRY__Retries                                        4
+#define R_CORECONTROL                                               0x0A8
+#define   O_CORECONTROL__ErrorThread                                4
+#define   W_CORECONTROL__ErrorThread                                7
+#define   O_CORECONTROL__Shutdown                                   2
+#define   O_CORECONTROL__Speed                                      0
+#define   W_CORECONTROL__Speed                                      2
+#define R_BYTEOFFSET0                                               0x0A9
+#define R_BYTEOFFSET1                                               0x0AA
+#define R_L2TYPE_0                                                  0x0F0
+#define   O_L2TYPE__ExtraHdrProtoSize                               26
+#define   W_L2TYPE__ExtraHdrProtoSize                               5
+#define   O_L2TYPE__ExtraHdrProtoOffset                             20
+#define   W_L2TYPE__ExtraHdrProtoOffset                             6
+#define   O_L2TYPE__ExtraHeaderSize                                 14
+#define   W_L2TYPE__ExtraHeaderSize                                 6
+#define   O_L2TYPE__ProtoOffset                                     8
+#define   W_L2TYPE__ProtoOffset                                     6
+#define   O_L2TYPE__L2HdrOffset                                     2
+#define   W_L2TYPE__L2HdrOffset                                     6
+#define   O_L2TYPE__L2Proto                                         0
+#define   W_L2TYPE__L2Proto                                         2
+#define R_L2TYPE_1                                                  0xF0
+#define R_L2TYPE_2                                                  0xF0
+#define R_L2TYPE_3                                                  0xF0
+#define R_PARSERCONFIGREG                                           0x100
+#define   O_PARSERCONFIGREG__CRCHashPoly                            8
+#define   W_PARSERCONFIGREG__CRCHashPoly                            7
+#define   O_PARSERCONFIGREG__PrePadOffset                           4
+#define   W_PARSERCONFIGREG__PrePadOffset                           4
+#define   O_PARSERCONFIGREG__UseCAM                                 2
+#define   O_PARSERCONFIGREG__UseHASH                                1
+#define   O_PARSERCONFIGREG__UseProto                               0
+#define R_L3CTABLE                                                  0x140
+#define   O_L3CTABLE__Offset0                                       25
+#define   W_L3CTABLE__Offset0                                       7
+#define   O_L3CTABLE__Len0                                          21
+#define   W_L3CTABLE__Len0                                          4
+#define   O_L3CTABLE__Offset1                                       14
+#define   W_L3CTABLE__Offset1                                       7
+#define   O_L3CTABLE__Len1                                          10
+#define   W_L3CTABLE__Len1                                          4
+#define   O_L3CTABLE__Offset2                                       4
+#define   W_L3CTABLE__Offset2                                       6
+#define   O_L3CTABLE__Len2                                          0
+#define   W_L3CTABLE__Len2                                          4
+#define   O_L3CTABLE__L3HdrOffset                                   26
+#define   W_L3CTABLE__L3HdrOffset                                   6
+#define   O_L3CTABLE__L4ProtoOffset                                 20
+#define   W_L3CTABLE__L4ProtoOffset                                 6
+#define   O_L3CTABLE__IPChksumCompute                               19
+#define   O_L3CTABLE__L4Classify                                    18
+#define   O_L3CTABLE__L2Proto                                       16
+#define   W_L3CTABLE__L2Proto                                       2
+#define   O_L3CTABLE__L3ProtoKey                                    0
+#define   W_L3CTABLE__L3ProtoKey                                    16
+#define R_L4CTABLE                                                  0x160
+#define   O_L4CTABLE__Offset0                                       21
+#define   W_L4CTABLE__Offset0                                       6
+#define   O_L4CTABLE__Len0                                          17
+#define   W_L4CTABLE__Len0                                          4
+#define   O_L4CTABLE__Offset1                                       11
+#define   W_L4CTABLE__Offset1                                       6
+#define   O_L4CTABLE__Len1                                          7
+#define   W_L4CTABLE__Len1                                          4
+#define   O_L4CTABLE__TCPChksumEnable                               0
+#define R_CAM4X128TABLE                                             0x172
+#define   O_CAM4X128TABLE__ClassId                                  7
+#define   W_CAM4X128TABLE__ClassId                                  2
+#define   O_CAM4X128TABLE__BucketId                                 1
+#define   W_CAM4X128TABLE__BucketId                                 6
+#define   O_CAM4X128TABLE__UseBucket                                0
+#define R_CAM4X128KEY                                               0x180
+#define R_TRANSLATETABLE                                            0x1A0
+#define R_DMACR0                                                    0x200
+#define   O_DMACR0__Data0WrMaxCr                                    27
+#define   W_DMACR0__Data0WrMaxCr                                    3
+#define   O_DMACR0__Data0RdMaxCr                                    24
+#define   W_DMACR0__Data0RdMaxCr                                    3
+#define   O_DMACR0__Data1WrMaxCr                                    21
+#define   W_DMACR0__Data1WrMaxCr                                    3
+#define   O_DMACR0__Data1RdMaxCr                                    18
+#define   W_DMACR0__Data1RdMaxCr                                    3
+#define   O_DMACR0__Data2WrMaxCr                                    15
+#define   W_DMACR0__Data2WrMaxCr                                    3
+#define   O_DMACR0__Data2RdMaxCr                                    12
+#define   W_DMACR0__Data2RdMaxCr                                    3
+#define   O_DMACR0__Data3WrMaxCr                                    9
+#define   W_DMACR0__Data3WrMaxCr                                    3
+#define   O_DMACR0__Data3RdMaxCr                                    6
+#define   W_DMACR0__Data3RdMaxCr                                    3
+#define   O_DMACR0__Data4WrMaxCr                                    3
+#define   W_DMACR0__Data4WrMaxCr                                    3
+#define   O_DMACR0__Data4RdMaxCr                                    0
+#define   W_DMACR0__Data4RdMaxCr                                    3
+#define R_DMACR1                                                    0x201
+#define   O_DMACR1__Data5WrMaxCr                                    27
+#define   W_DMACR1__Data5WrMaxCr                                    3
+#define   O_DMACR1__Data5RdMaxCr                                    24
+#define   W_DMACR1__Data5RdMaxCr                                    3
+#define   O_DMACR1__Data6WrMaxCr                                    21
+#define   W_DMACR1__Data6WrMaxCr                                    3
+#define   O_DMACR1__Data6RdMaxCr                                    18
+#define   W_DMACR1__Data6RdMaxCr                                    3
+#define   O_DMACR1__Data7WrMaxCr                                    15
+#define   W_DMACR1__Data7WrMaxCr                                    3
+#define   O_DMACR1__Data7RdMaxCr                                    12
+#define   W_DMACR1__Data7RdMaxCr                                    3
+#define   O_DMACR1__Data8WrMaxCr                                    9
+#define   W_DMACR1__Data8WrMaxCr                                    3
+#define   O_DMACR1__Data8RdMaxCr                                    6
+#define   W_DMACR1__Data8RdMaxCr                                    3
+#define   O_DMACR1__Data9WrMaxCr                                    3
+#define   W_DMACR1__Data9WrMaxCr                                    3
+#define   O_DMACR1__Data9RdMaxCr                                    0
+#define   W_DMACR1__Data9RdMaxCr                                    3
+#define R_DMACR2                                                    0x202
+#define   O_DMACR2__Data10WrMaxCr                                   27
+#define   W_DMACR2__Data10WrMaxCr                                   3
+#define   O_DMACR2__Data10RdMaxCr                                   24
+#define   W_DMACR2__Data10RdMaxCr                                   3
+#define   O_DMACR2__Data11WrMaxCr                                   21
+#define   W_DMACR2__Data11WrMaxCr                                   3
+#define   O_DMACR2__Data11RdMaxCr                                   18
+#define   W_DMACR2__Data11RdMaxCr                                   3
+#define   O_DMACR2__Data12WrMaxCr                                   15
+#define   W_DMACR2__Data12WrMaxCr                                   3
+#define   O_DMACR2__Data12RdMaxCr                                   12
+#define   W_DMACR2__Data12RdMaxCr                                   3
+#define   O_DMACR2__Data13WrMaxCr                                   9
+#define   W_DMACR2__Data13WrMaxCr                                   3
+#define   O_DMACR2__Data13RdMaxCr                                   6
+#define   W_DMACR2__Data13RdMaxCr                                   3
+#define   O_DMACR2__Data14WrMaxCr                                   3
+#define   W_DMACR2__Data14WrMaxCr                                   3
+#define   O_DMACR2__Data14RdMaxCr                                   0
+#define   W_DMACR2__Data14RdMaxCr                                   3
+#define R_DMACR3                                                    0x203
+#define   O_DMACR3__Data15WrMaxCr                                   27
+#define   W_DMACR3__Data15WrMaxCr                                   3
+#define   O_DMACR3__Data15RdMaxCr                                   24
+#define   W_DMACR3__Data15RdMaxCr                                   3
+#define   O_DMACR3__SpClassWrMaxCr                                  21
+#define   W_DMACR3__SpClassWrMaxCr                                  3
+#define   O_DMACR3__SpClassRdMaxCr                                  18
+#define   W_DMACR3__SpClassRdMaxCr                                  3
+#define   O_DMACR3__JumFrInWrMaxCr                                  15
+#define   W_DMACR3__JumFrInWrMaxCr                                  3
+#define   O_DMACR3__JumFrInRdMaxCr                                  12
+#define   W_DMACR3__JumFrInRdMaxCr                                  3
+#define   O_DMACR3__RegFrInWrMaxCr                                  9
+#define   W_DMACR3__RegFrInWrMaxCr                                  3
+#define   O_DMACR3__RegFrInRdMaxCr                                  6
+#define   W_DMACR3__RegFrInRdMaxCr                                  3
+#define   O_DMACR3__FrOutWrMaxCr                                    3
+#define   W_DMACR3__FrOutWrMaxCr                                    3
+#define   O_DMACR3__FrOutRdMaxCr                                    0
+#define   W_DMACR3__FrOutRdMaxCr                                    3
+#define R_REG_FRIN_SPILL_MEM_START_0                                0x204
+#define   O_REG_FRIN_SPILL_MEM_START_0__RegFrInSpillMemStart0        0
+#define   W_REG_FRIN_SPILL_MEM_START_0__RegFrInSpillMemStart0       32
+#define R_REG_FRIN_SPILL_MEM_START_1                                0x205
+#define   O_REG_FRIN_SPILL_MEM_START_1__RegFrInSpillMemStart1        0
+#define   W_REG_FRIN_SPILL_MEM_START_1__RegFrInSpillMemStart1        3
+#define R_REG_FRIN_SPILL_MEM_SIZE                                   0x206
+#define   O_REG_FRIN_SPILL_MEM_SIZE__RegFrInSpillMemSize             0
+#define   W_REG_FRIN_SPILL_MEM_SIZE__RegFrInSpillMemSize            32
+#define R_FROUT_SPILL_MEM_START_0                                   0x207
+#define   O_FROUT_SPILL_MEM_START_0__FrOutSpillMemStart0             0
+#define   W_FROUT_SPILL_MEM_START_0__FrOutSpillMemStart0            32
+#define R_FROUT_SPILL_MEM_START_1                                   0x208
+#define   O_FROUT_SPILL_MEM_START_1__FrOutSpillMemStart1             0
+#define   W_FROUT_SPILL_MEM_START_1__FrOutSpillMemStart1             3
+#define R_FROUT_SPILL_MEM_SIZE                                      0x209
+#define   O_FROUT_SPILL_MEM_SIZE__FrOutSpillMemSize                  0
+#define   W_FROUT_SPILL_MEM_SIZE__FrOutSpillMemSize                 32
+#define R_CLASS0_SPILL_MEM_START_0                                  0x20A
+#define   O_CLASS0_SPILL_MEM_START_0__Class0SpillMemStart0           0
+#define   W_CLASS0_SPILL_MEM_START_0__Class0SpillMemStart0          32
+#define R_CLASS0_SPILL_MEM_START_1                                  0x20B
+#define   O_CLASS0_SPILL_MEM_START_1__Class0SpillMemStart1           0
+#define   W_CLASS0_SPILL_MEM_START_1__Class0SpillMemStart1           3
+#define R_CLASS0_SPILL_MEM_SIZE                                     0x20C
+#define   O_CLASS0_SPILL_MEM_SIZE__Class0SpillMemSize                0
+#define   W_CLASS0_SPILL_MEM_SIZE__Class0SpillMemSize               32
+#define R_JUMFRIN_SPILL_MEM_START_0                                 0x20D
+#define   O_JUMFRIN_SPILL_MEM_START_0__JumFrInSpillMemStar0          0
+#define   W_JUMFRIN_SPILL_MEM_START_0__JumFrInSpillMemStar0         32
+#define R_JUMFRIN_SPILL_MEM_START_1                                 0x20E
+#define   O_JUMFRIN_SPILL_MEM_START_1__JumFrInSpillMemStart1         0
+#define   W_JUMFRIN_SPILL_MEM_START_1__JumFrInSpillMemStart1         3
+#define R_JUMFRIN_SPILL_MEM_SIZE                                    0x20F
+#define   O_JUMFRIN_SPILL_MEM_SIZE__JumFrInSpillMemSize              0
+#define   W_JUMFRIN_SPILL_MEM_SIZE__JumFrInSpillMemSize             32
+#define R_CLASS1_SPILL_MEM_START_0                                  0x210
+#define   O_CLASS1_SPILL_MEM_START_0__Class1SpillMemStart0           0
+#define   W_CLASS1_SPILL_MEM_START_0__Class1SpillMemStart0          32
+#define R_CLASS1_SPILL_MEM_START_1                                  0x211
+#define   O_CLASS1_SPILL_MEM_START_1__Class1SpillMemStart1           0
+#define   W_CLASS1_SPILL_MEM_START_1__Class1SpillMemStart1           3
+#define R_CLASS1_SPILL_MEM_SIZE                                     0x212
+#define   O_CLASS1_SPILL_MEM_SIZE__Class1SpillMemSize                0
+#define   W_CLASS1_SPILL_MEM_SIZE__Class1SpillMemSize               32
+#define R_CLASS2_SPILL_MEM_START_0                                  0x213
+#define   O_CLASS2_SPILL_MEM_START_0__Class2SpillMemStart0           0
+#define   W_CLASS2_SPILL_MEM_START_0__Class2SpillMemStart0          32
+#define R_CLASS2_SPILL_MEM_START_1                                  0x214
+#define   O_CLASS2_SPILL_MEM_START_1__Class2SpillMemStart1           0
+#define   W_CLASS2_SPILL_MEM_START_1__Class2SpillMemStart1           3
+#define R_CLASS2_SPILL_MEM_SIZE                                     0x215
+#define   O_CLASS2_SPILL_MEM_SIZE__Class2SpillMemSize                0
+#define   W_CLASS2_SPILL_MEM_SIZE__Class2SpillMemSize               32
+#define R_CLASS3_SPILL_MEM_START_0                                  0x216
+#define   O_CLASS3_SPILL_MEM_START_0__Class3SpillMemStart0           0
+#define   W_CLASS3_SPILL_MEM_START_0__Class3SpillMemStart0          32
+#define R_CLASS3_SPILL_MEM_START_1                                  0x217
+#define   O_CLASS3_SPILL_MEM_START_1__Class3SpillMemStart1           0
+#define   W_CLASS3_SPILL_MEM_START_1__Class3SpillMemStart1           3
+#define R_CLASS3_SPILL_MEM_SIZE                                     0x218
+#define   O_CLASS3_SPILL_MEM_SIZE__Class3SpillMemSize                0
+#define   W_CLASS3_SPILL_MEM_SIZE__Class3SpillMemSize               32
+#define R_REG_FRIN1_SPILL_MEM_START_0                               0x219
+#define R_REG_FRIN1_SPILL_MEM_START_1                               0x21a
+#define R_REG_FRIN1_SPILL_MEM_SIZE                                  0x21b
+#define R_SPIHNGY0                                                  0x219
+#define   O_SPIHNGY0__EG_HNGY_THRESH_0                              24
+#define   W_SPIHNGY0__EG_HNGY_THRESH_0                              7
+#define   O_SPIHNGY0__EG_HNGY_THRESH_1                              16
+#define   W_SPIHNGY0__EG_HNGY_THRESH_1                              7
+#define   O_SPIHNGY0__EG_HNGY_THRESH_2                              8
+#define   W_SPIHNGY0__EG_HNGY_THRESH_2                              7
+#define   O_SPIHNGY0__EG_HNGY_THRESH_3                              0
+#define   W_SPIHNGY0__EG_HNGY_THRESH_3                              7
+#define R_SPIHNGY1                                                  0x21A
+#define   O_SPIHNGY1__EG_HNGY_THRESH_4                              24
+#define   W_SPIHNGY1__EG_HNGY_THRESH_4                              7
+#define   O_SPIHNGY1__EG_HNGY_THRESH_5                              16
+#define   W_SPIHNGY1__EG_HNGY_THRESH_5                              7
+#define   O_SPIHNGY1__EG_HNGY_THRESH_6                              8
+#define   W_SPIHNGY1__EG_HNGY_THRESH_6                              7
+#define   O_SPIHNGY1__EG_HNGY_THRESH_7                              0
+#define   W_SPIHNGY1__EG_HNGY_THRESH_7                              7
+#define R_SPIHNGY2                                                  0x21B
+#define   O_SPIHNGY2__EG_HNGY_THRESH_8                              24
+#define   W_SPIHNGY2__EG_HNGY_THRESH_8                              7
+#define   O_SPIHNGY2__EG_HNGY_THRESH_9                              16
+#define   W_SPIHNGY2__EG_HNGY_THRESH_9                              7
+#define   O_SPIHNGY2__EG_HNGY_THRESH_10                             8
+#define   W_SPIHNGY2__EG_HNGY_THRESH_10                             7
+#define   O_SPIHNGY2__EG_HNGY_THRESH_11                             0
+#define   W_SPIHNGY2__EG_HNGY_THRESH_11                             7
+#define R_SPIHNGY3                                                  0x21C
+#define   O_SPIHNGY3__EG_HNGY_THRESH_12                             24
+#define   W_SPIHNGY3__EG_HNGY_THRESH_12                             7
+#define   O_SPIHNGY3__EG_HNGY_THRESH_13                             16
+#define   W_SPIHNGY3__EG_HNGY_THRESH_13                             7
+#define   O_SPIHNGY3__EG_HNGY_THRESH_14                             8
+#define   W_SPIHNGY3__EG_HNGY_THRESH_14                             7
+#define   O_SPIHNGY3__EG_HNGY_THRESH_15                             0
+#define   W_SPIHNGY3__EG_HNGY_THRESH_15                             7
+#define R_SPISTRV0                                                  0x21D
+#define   O_SPISTRV0__EG_STRV_THRESH_0                              24
+#define   W_SPISTRV0__EG_STRV_THRESH_0                              7
+#define   O_SPISTRV0__EG_STRV_THRESH_1                              16
+#define   W_SPISTRV0__EG_STRV_THRESH_1                              7
+#define   O_SPISTRV0__EG_STRV_THRESH_2                              8
+#define   W_SPISTRV0__EG_STRV_THRESH_2                              7
+#define   O_SPISTRV0__EG_STRV_THRESH_3                              0
+#define   W_SPISTRV0__EG_STRV_THRESH_3                              7
+#define R_SPISTRV1                                                  0x21E
+#define   O_SPISTRV1__EG_STRV_THRESH_4                              24
+#define   W_SPISTRV1__EG_STRV_THRESH_4                              7
+#define   O_SPISTRV1__EG_STRV_THRESH_5                              16
+#define   W_SPISTRV1__EG_STRV_THRESH_5                              7
+#define   O_SPISTRV1__EG_STRV_THRESH_6                              8
+#define   W_SPISTRV1__EG_STRV_THRESH_6                              7
+#define   O_SPISTRV1__EG_STRV_THRESH_7                              0
+#define   W_SPISTRV1__EG_STRV_THRESH_7                              7
+#define R_SPISTRV2                                                  0x21F
+#define   O_SPISTRV2__EG_STRV_THRESH_8                              24
+#define   W_SPISTRV2__EG_STRV_THRESH_8                              7
+#define   O_SPISTRV2__EG_STRV_THRESH_9                              16
+#define   W_SPISTRV2__EG_STRV_THRESH_9                              7
+#define   O_SPISTRV2__EG_STRV_THRESH_10                             8
+#define   W_SPISTRV2__EG_STRV_THRESH_10                             7
+#define   O_SPISTRV2__EG_STRV_THRESH_11                             0
+#define   W_SPISTRV2__EG_STRV_THRESH_11                             7
+#define R_SPISTRV3                                                  0x220
+#define   O_SPISTRV3__EG_STRV_THRESH_12                             24
+#define   W_SPISTRV3__EG_STRV_THRESH_12                             7
+#define   O_SPISTRV3__EG_STRV_THRESH_13                             16
+#define   W_SPISTRV3__EG_STRV_THRESH_13                             7
+#define   O_SPISTRV3__EG_STRV_THRESH_14                             8
+#define   W_SPISTRV3__EG_STRV_THRESH_14                             7
+#define   O_SPISTRV3__EG_STRV_THRESH_15                             0
+#define   W_SPISTRV3__EG_STRV_THRESH_15                             7
+#define R_TXDATAFIFO0                                               0x221
+#define   O_TXDATAFIFO0__Tx0DataFifoStart                           24
+#define   W_TXDATAFIFO0__Tx0DataFifoStart                           7
+#define   O_TXDATAFIFO0__Tx0DataFifoSize                            16
+#define   W_TXDATAFIFO0__Tx0DataFifoSize                            7
+#define   O_TXDATAFIFO0__Tx1DataFifoStart                           8
+#define   W_TXDATAFIFO0__Tx1DataFifoStart                           7
+#define   O_TXDATAFIFO0__Tx1DataFifoSize                            0
+#define   W_TXDATAFIFO0__Tx1DataFifoSize                            7
+#define R_TXDATAFIFO1                                               0x222
+#define   O_TXDATAFIFO1__Tx2DataFifoStart                           24
+#define   W_TXDATAFIFO1__Tx2DataFifoStart                           7
+#define   O_TXDATAFIFO1__Tx2DataFifoSize                            16
+#define   W_TXDATAFIFO1__Tx2DataFifoSize                            7
+#define   O_TXDATAFIFO1__Tx3DataFifoStart                           8
+#define   W_TXDATAFIFO1__Tx3DataFifoStart                           7
+#define   O_TXDATAFIFO1__Tx3DataFifoSize                            0
+#define   W_TXDATAFIFO1__Tx3DataFifoSize                            7
+#define R_TXDATAFIFO2                                               0x223
+#define   O_TXDATAFIFO2__Tx4DataFifoStart                           24
+#define   W_TXDATAFIFO2__Tx4DataFifoStart                           7
+#define   O_TXDATAFIFO2__Tx4DataFifoSize                            16
+#define   W_TXDATAFIFO2__Tx4DataFifoSize                            7
+#define   O_TXDATAFIFO2__Tx5DataFifoStart                           8
+#define   W_TXDATAFIFO2__Tx5DataFifoStart                           7
+#define   O_TXDATAFIFO2__Tx5DataFifoSize                            0
+#define   W_TXDATAFIFO2__Tx5DataFifoSize                            7
+#define R_TXDATAFIFO3                                               0x224
+#define   O_TXDATAFIFO3__Tx6DataFifoStart                           24
+#define   W_TXDATAFIFO3__Tx6DataFifoStart                           7
+#define   O_TXDATAFIFO3__Tx6DataFifoSize                            16
+#define   W_TXDATAFIFO3__Tx6DataFifoSize                            7
+#define   O_TXDATAFIFO3__Tx7DataFifoStart                           8
+#define   W_TXDATAFIFO3__Tx7DataFifoStart                           7
+#define   O_TXDATAFIFO3__Tx7DataFifoSize                            0
+#define   W_TXDATAFIFO3__Tx7DataFifoSize                            7
+#define R_TXDATAFIFO4                                               0x225
+#define   O_TXDATAFIFO4__Tx8DataFifoStart                           24
+#define   W_TXDATAFIFO4__Tx8DataFifoStart                           7
+#define   O_TXDATAFIFO4__Tx8DataFifoSize                            16
+#define   W_TXDATAFIFO4__Tx8DataFifoSize                            7
+#define   O_TXDATAFIFO4__Tx9DataFifoStart                           8
+#define   W_TXDATAFIFO4__Tx9DataFifoStart                           7
+#define   O_TXDATAFIFO4__Tx9DataFifoSize                            0
+#define   W_TXDATAFIFO4__Tx9DataFifoSize                            7
+#define R_TXDATAFIFO5                                               0x226
+#define   O_TXDATAFIFO5__Tx10DataFifoStart                          24
+#define   W_TXDATAFIFO5__Tx10DataFifoStart                          7
+#define   O_TXDATAFIFO5__Tx10DataFifoSize                           16
+#define   W_TXDATAFIFO5__Tx10DataFifoSize                           7
+#define   O_TXDATAFIFO5__Tx11DataFifoStart                          8
+#define   W_TXDATAFIFO5__Tx11DataFifoStart                          7
+#define   O_TXDATAFIFO5__Tx11DataFifoSize                           0
+#define   W_TXDATAFIFO5__Tx11DataFifoSize                           7
+#define R_TXDATAFIFO6                                               0x227
+#define   O_TXDATAFIFO6__Tx12DataFifoStart                          24
+#define   W_TXDATAFIFO6__Tx12DataFifoStart                          7
+#define   O_TXDATAFIFO6__Tx12DataFifoSize                           16
+#define   W_TXDATAFIFO6__Tx12DataFifoSize                           7
+#define   O_TXDATAFIFO6__Tx13DataFifoStart                          8
+#define   W_TXDATAFIFO6__Tx13DataFifoStart                          7
+#define   O_TXDATAFIFO6__Tx13DataFifoSize                           0
+#define   W_TXDATAFIFO6__Tx13DataFifoSize                           7
+#define R_TXDATAFIFO7                                               0x228
+#define   O_TXDATAFIFO7__Tx14DataFifoStart                          24
+#define   W_TXDATAFIFO7__Tx14DataFifoStart                          7
+#define   O_TXDATAFIFO7__Tx14DataFifoSize                           16
+#define   W_TXDATAFIFO7__Tx14DataFifoSize                           7
+#define   O_TXDATAFIFO7__Tx15DataFifoStart                          8
+#define   W_TXDATAFIFO7__Tx15DataFifoStart                          7
+#define   O_TXDATAFIFO7__Tx15DataFifoSize                           0
+#define   W_TXDATAFIFO7__Tx15DataFifoSize                           7
+#define R_RXDATAFIFO0                                               0x229
+#define   O_RXDATAFIFO0__Rx0DataFifoStart                           24
+#define   W_RXDATAFIFO0__Rx0DataFifoStart                           7
+#define   O_RXDATAFIFO0__Rx0DataFifoSize                            16
+#define   W_RXDATAFIFO0__Rx0DataFifoSize                            7
+#define   O_RXDATAFIFO0__Rx1DataFifoStart                           8
+#define   W_RXDATAFIFO0__Rx1DataFifoStart                           7
+#define   O_RXDATAFIFO0__Rx1DataFifoSize                            0
+#define   W_RXDATAFIFO0__Rx1DataFifoSize                            7
+#define R_RXDATAFIFO1                                               0x22A
+#define   O_RXDATAFIFO1__Rx2DataFifoStart                           24
+#define   W_RXDATAFIFO1__Rx2DataFifoStart                           7
+#define   O_RXDATAFIFO1__Rx2DataFifoSize                            16
+#define   W_RXDATAFIFO1__Rx2DataFifoSize                            7
+#define   O_RXDATAFIFO1__Rx3DataFifoStart                           8
+#define   W_RXDATAFIFO1__Rx3DataFifoStart                           7
+#define   O_RXDATAFIFO1__Rx3DataFifoSize                            0
+#define   W_RXDATAFIFO1__Rx3DataFifoSize                            7
+#define R_RXDATAFIFO2                                               0x22B
+#define   O_RXDATAFIFO2__Rx4DataFifoStart                           24
+#define   W_RXDATAFIFO2__Rx4DataFifoStart                           7
+#define   O_RXDATAFIFO2__Rx4DataFifoSize                            16
+#define   W_RXDATAFIFO2__Rx4DataFifoSize                            7
+#define   O_RXDATAFIFO2__Rx5DataFifoStart                           8
+#define   W_RXDATAFIFO2__Rx5DataFifoStart                           7
+#define   O_RXDATAFIFO2__Rx5DataFifoSize                            0
+#define   W_RXDATAFIFO2__Rx5DataFifoSize                            7
+#define R_RXDATAFIFO3                                               0x22C
+#define   O_RXDATAFIFO3__Rx6DataFifoStart                           24
+#define   W_RXDATAFIFO3__Rx6DataFifoStart                           7
+#define   O_RXDATAFIFO3__Rx6DataFifoSize                            16
+#define   W_RXDATAFIFO3__Rx6DataFifoSize                            7
+#define   O_RXDATAFIFO3__Rx7DataFifoStart                           8
+#define   W_RXDATAFIFO3__Rx7DataFifoStart                           7
+#define   O_RXDATAFIFO3__Rx7DataFifoSize                            0
+#define   W_RXDATAFIFO3__Rx7DataFifoSize                            7
+#define R_RXDATAFIFO4                                               0x22D
+#define   O_RXDATAFIFO4__Rx8DataFifoStart                           24
+#define   W_RXDATAFIFO4__Rx8DataFifoStart                           7
+#define   O_RXDATAFIFO4__Rx8DataFifoSize                            16
+#define   W_RXDATAFIFO4__Rx8DataFifoSize                            7
+#define   O_RXDATAFIFO4__Rx9DataFifoStart                           8
+#define   W_RXDATAFIFO4__Rx9DataFifoStart                           7
+#define   O_RXDATAFIFO4__Rx9DataFifoSize                            0
+#define   W_RXDATAFIFO4__Rx9DataFifoSize                            7
+#define R_RXDATAFIFO5                                               0x22E
+#define   O_RXDATAFIFO5__Rx10DataFifoStart                          24
+#define   W_RXDATAFIFO5__Rx10DataFifoStart                          7
+#define   O_RXDATAFIFO5__Rx10DataFifoSize                           16
+#define   W_RXDATAFIFO5__Rx10DataFifoSize                           7
+#define   O_RXDATAFIFO5__Rx11DataFifoStart                          8
+#define   W_RXDATAFIFO5__Rx11DataFifoStart                          7
+#define   O_RXDATAFIFO5__Rx11DataFifoSize                           0
+#define   W_RXDATAFIFO5__Rx11DataFifoSize                           7
+#define R_RXDATAFIFO6                                               0x22F
+#define   O_RXDATAFIFO6__Rx12DataFifoStart                          24
+#define   W_RXDATAFIFO6__Rx12DataFifoStart                          7
+#define   O_RXDATAFIFO6__Rx12DataFifoSize                           16
+#define   W_RXDATAFIFO6__Rx12DataFifoSize                           7
+#define   O_RXDATAFIFO6__Rx13DataFifoStart                          8
+#define   W_RXDATAFIFO6__Rx13DataFifoStart                          7
+#define   O_RXDATAFIFO6__Rx13DataFifoSize                           0
+#define   W_RXDATAFIFO6__Rx13DataFifoSize                           7
+#define R_RXDATAFIFO7                                               0x230
+#define   O_RXDATAFIFO7__Rx14DataFifoStart                          24
+#define   W_RXDATAFIFO7__Rx14DataFifoStart                          7
+#define   O_RXDATAFIFO7__Rx14DataFifoSize                           16
+#define   W_RXDATAFIFO7__Rx14DataFifoSize                           7
+#define   O_RXDATAFIFO7__Rx15DataFifoStart                          8
+#define   W_RXDATAFIFO7__Rx15DataFifoStart                          7
+#define   O_RXDATAFIFO7__Rx15DataFifoSize                           0
+#define   W_RXDATAFIFO7__Rx15DataFifoSize                           7
+#define R_XGMACPADCALIBRATION                                       0x231
+#define R_FREEQCARVE                                                0x233
+#define R_SPI4STATICDELAY0                                          0x240
+#define   O_SPI4STATICDELAY0__DataLine7                             28
+#define   W_SPI4STATICDELAY0__DataLine7                             4
+#define   O_SPI4STATICDELAY0__DataLine6                             24
+#define   W_SPI4STATICDELAY0__DataLine6                             4
+#define   O_SPI4STATICDELAY0__DataLine5                             20
+#define   W_SPI4STATICDELAY0__DataLine5                             4
+#define   O_SPI4STATICDELAY0__DataLine4                             16
+#define   W_SPI4STATICDELAY0__DataLine4                             4
+#define   O_SPI4STATICDELAY0__DataLine3                             12
+#define   W_SPI4STATICDELAY0__DataLine3                             4
+#define   O_SPI4STATICDELAY0__DataLine2                             8
+#define   W_SPI4STATICDELAY0__DataLine2                             4
+#define   O_SPI4STATICDELAY0__DataLine1                             4
+#define   W_SPI4STATICDELAY0__DataLine1                             4
+#define   O_SPI4STATICDELAY0__DataLine0                             0
+#define   W_SPI4STATICDELAY0__DataLine0                             4
+#define R_SPI4STATICDELAY1                                          0x241
+#define   O_SPI4STATICDELAY1__DataLine15                            28
+#define   W_SPI4STATICDELAY1__DataLine15                            4
+#define   O_SPI4STATICDELAY1__DataLine14                            24
+#define   W_SPI4STATICDELAY1__DataLine14                            4
+#define   O_SPI4STATICDELAY1__DataLine13                            20
+#define   W_SPI4STATICDELAY1__DataLine13                            4
+#define   O_SPI4STATICDELAY1__DataLine12                            16
+#define   W_SPI4STATICDELAY1__DataLine12                            4
+#define   O_SPI4STATICDELAY1__DataLine11                            12
+#define   W_SPI4STATICDELAY1__DataLine11                            4
+#define   O_SPI4STATICDELAY1__DataLine10                            8
+#define   W_SPI4STATICDELAY1__DataLine10                            4
+#define   O_SPI4STATICDELAY1__DataLine9                             4
+#define   W_SPI4STATICDELAY1__DataLine9                             4
+#define   O_SPI4STATICDELAY1__DataLine8                             0
+#define   W_SPI4STATICDELAY1__DataLine8                             4
+#define R_SPI4STATICDELAY2                                          0x242
+#define   O_SPI4STATICDELAY0__TxStat1                               8
+#define   W_SPI4STATICDELAY0__TxStat1                               4
+#define   O_SPI4STATICDELAY0__TxStat0                               4
+#define   W_SPI4STATICDELAY0__TxStat0                               4
+#define   O_SPI4STATICDELAY0__RxControl                             0
+#define   W_SPI4STATICDELAY0__RxControl                             4
+#define R_SPI4CONTROL                                               0x243
+#define   O_SPI4CONTROL__StaticDelay                                2
+#define   O_SPI4CONTROL__LVDS_LVTTL                                 1
+#define   O_SPI4CONTROL__SPI4Enable                                 0
+#define R_CLASSWATERMARKS                                           0x244
+#define   O_CLASSWATERMARKS__Class0Watermark                        24
+#define   W_CLASSWATERMARKS__Class0Watermark                        5
+#define   O_CLASSWATERMARKS__Class1Watermark                        16
+#define   W_CLASSWATERMARKS__Class1Watermark                        5
+#define   O_CLASSWATERMARKS__Class3Watermark                        0
+#define   W_CLASSWATERMARKS__Class3Watermark                        5
+#define R_RXWATERMARKS1                                              0x245
+#define   O_RXWATERMARKS__Rx0DataWatermark                          24
+#define   W_RXWATERMARKS__Rx0DataWatermark                          7
+#define   O_RXWATERMARKS__Rx1DataWatermark                          16
+#define   W_RXWATERMARKS__Rx1DataWatermark                          7
+#define   O_RXWATERMARKS__Rx3DataWatermark                          0
+#define   W_RXWATERMARKS__Rx3DataWatermark                          7
+#define R_RXWATERMARKS2                                              0x246
+#define   O_RXWATERMARKS__Rx4DataWatermark                          24
+#define   W_RXWATERMARKS__Rx4DataWatermark                          7
+#define   O_RXWATERMARKS__Rx5DataWatermark                          16
+#define   W_RXWATERMARKS__Rx5DataWatermark                          7
+#define   O_RXWATERMARKS__Rx6DataWatermark                          8
+#define   W_RXWATERMARKS__Rx6DataWatermark                          7
+#define   O_RXWATERMARKS__Rx7DataWatermark                          0
+#define   W_RXWATERMARKS__Rx7DataWatermark                          7
+#define R_RXWATERMARKS3                                              0x247
+#define   O_RXWATERMARKS__Rx8DataWatermark                          24
+#define   W_RXWATERMARKS__Rx8DataWatermark                          7
+#define   O_RXWATERMARKS__Rx9DataWatermark                          16
+#define   W_RXWATERMARKS__Rx9DataWatermark                          7
+#define   O_RXWATERMARKS__Rx10DataWatermark                         8
+#define   W_RXWATERMARKS__Rx10DataWatermark                         7
+#define   O_RXWATERMARKS__Rx11DataWatermark                         0
+#define   W_RXWATERMARKS__Rx11DataWatermark                         7
+#define R_RXWATERMARKS4                                              0x248
+#define   O_RXWATERMARKS__Rx12DataWatermark                         24
+#define   W_RXWATERMARKS__Rx12DataWatermark                         7
+#define   O_RXWATERMARKS__Rx13DataWatermark                         16
+#define   W_RXWATERMARKS__Rx13DataWatermark                         7
+#define   O_RXWATERMARKS__Rx14DataWatermark                         8
+#define   W_RXWATERMARKS__Rx14DataWatermark                         7
+#define   O_RXWATERMARKS__Rx15DataWatermark                         0
+#define   W_RXWATERMARKS__Rx15DataWatermark                         7
+#define R_FREEWATERMARKS                                            0x249
+#define   O_FREEWATERMARKS__FreeOutWatermark                        16
+#define   W_FREEWATERMARKS__FreeOutWatermark                        16
+#define   O_FREEWATERMARKS__JumFrWatermark                          8
+#define   W_FREEWATERMARKS__JumFrWatermark                          7
+#define   O_FREEWATERMARKS__RegFrWatermark                          0
+#define   W_FREEWATERMARKS__RegFrWatermark                          7
+#define R_EGRESSFIFOCARVINGSLOTS                                    0x24a
+
+#define CTRL_RES0           0
+#define CTRL_RES1           1
+#define CTRL_REG_FREE       2
+#define CTRL_JUMBO_FREE     3
+#define CTRL_CONT           4
+#define CTRL_EOP            5
+#define CTRL_START          6
+#define CTRL_SNGL           7
+
+#define CTRL_B0_NOT_EOP     0
+#define CTRL_B0_EOP         1
+
+#define R_ROUND_ROBIN_TABLE                 0
+#define R_PDE_CLASS_0                       0x300
+#define R_PDE_CLASS_1                       0x302
+#define R_PDE_CLASS_2                       0x304
+#define R_PDE_CLASS_3                       0x306
+
+#define R_MSG_TX_THRESHOLD                  0x308
+
+#define R_GMAC_JFR0_BUCKET_SIZE              0x320
+#define R_GMAC_RFR0_BUCKET_SIZE              0x321
+#define R_GMAC_TX0_BUCKET_SIZE              0x322
+#define R_GMAC_TX1_BUCKET_SIZE              0x323
+#define R_GMAC_TX2_BUCKET_SIZE              0x324
+#define R_GMAC_TX3_BUCKET_SIZE              0x325
+#define R_GMAC_JFR1_BUCKET_SIZE              0x326
+#define R_GMAC_RFR1_BUCKET_SIZE              0x327
+
+#define R_XGS_TX0_BUCKET_SIZE               0x320
+#define R_XGS_TX1_BUCKET_SIZE               0x321
+#define R_XGS_TX2_BUCKET_SIZE               0x322
+#define R_XGS_TX3_BUCKET_SIZE               0x323
+#define R_XGS_TX4_BUCKET_SIZE               0x324
+#define R_XGS_TX5_BUCKET_SIZE               0x325
+#define R_XGS_TX6_BUCKET_SIZE               0x326
+#define R_XGS_TX7_BUCKET_SIZE               0x327
+#define R_XGS_TX8_BUCKET_SIZE               0x328
+#define R_XGS_TX9_BUCKET_SIZE               0x329
+#define R_XGS_TX10_BUCKET_SIZE              0x32A
+#define R_XGS_TX11_BUCKET_SIZE              0x32B
+#define R_XGS_TX12_BUCKET_SIZE              0x32C
+#define R_XGS_TX13_BUCKET_SIZE              0x32D
+#define R_XGS_TX14_BUCKET_SIZE              0x32E
+#define R_XGS_TX15_BUCKET_SIZE              0x32F
+#define R_XGS_JFR_BUCKET_SIZE               0x330
+#define R_XGS_RFR_BUCKET_SIZE               0x331
+
+#define R_CC_CPU0_0                         0x380
+#define R_CC_CPU1_0                         0x388
+#define R_CC_CPU2_0                         0x390
+#define R_CC_CPU3_0                         0x398
+#define R_CC_CPU4_0                         0x3a0
+#define R_CC_CPU5_0                         0x3a8
+#define R_CC_CPU6_0                         0x3b0
+#define R_CC_CPU7_0                         0x3b8
+
+#define XLR_GMAC_BLK_SZ                            (XLR_IO_GMAC_1_OFFSET - \
+               XLR_IO_GMAC_0_OFFSET)
+
+/* Constants used for configuring the devices */
+
+#define XLR_FB_STN                     6 /* Bucket used for Tx freeback */
+
+#define MAC_B2B_IPG                     88
+
+#define        XLR_NET_PREPAD_LEN              32
+
+/* frame sizes need to be cacheline aligned */
+#define MAX_FRAME_SIZE                  (1536 + XLR_NET_PREPAD_LEN)
+#define MAX_FRAME_SIZE_JUMBO            9216
+
+#define MAC_SKB_BACK_PTR_SIZE           SMP_CACHE_BYTES
+#define MAC_PREPAD                      0
+#define BYTE_OFFSET                     2
+#define XLR_RX_BUF_SIZE                 (MAX_FRAME_SIZE + BYTE_OFFSET + \
+               MAC_PREPAD + MAC_SKB_BACK_PTR_SIZE + SMP_CACHE_BYTES)
+#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 */
+
+#define MAC_FRIN_TO_BE_SENT_THRESHOLD   16
+
+#define MAX_NUM_DESC_SPILL             1024
+#define MAX_FRIN_SPILL                  (MAX_NUM_DESC_SPILL << 2)
+#define MAX_FROUT_SPILL                 (MAX_NUM_DESC_SPILL << 2)
+#define MAX_CLASS_0_SPILL               (MAX_NUM_DESC_SPILL << 2)
+#define MAX_CLASS_1_SPILL               (MAX_NUM_DESC_SPILL << 2)
+#define MAX_CLASS_2_SPILL               (MAX_NUM_DESC_SPILL << 2)
+#define MAX_CLASS_3_SPILL               (MAX_NUM_DESC_SPILL << 2)
+
+enum {
+       SGMII_SPEED_10 = 0x00000000,
+       SGMII_SPEED_100 = 0x02000000,
+       SGMII_SPEED_1000 = 0x04000000,
+};
+
+enum tsv_rsv_reg {
+       TX_RX_64_BYTE_FRAME = 0x20,
+       TX_RX_64_127_BYTE_FRAME,
+       TX_RX_128_255_BYTE_FRAME,
+       TX_RX_256_511_BYTE_FRAME,
+       TX_RX_512_1023_BYTE_FRAME,
+       TX_RX_1024_1518_BYTE_FRAME,
+       TX_RX_1519_1522_VLAN_BYTE_FRAME,
+
+       RX_BYTE_COUNTER = 0x27,
+       RX_PACKET_COUNTER,
+       RX_FCS_ERROR_COUNTER,
+       RX_MULTICAST_PACKET_COUNTER,
+       RX_BROADCAST_PACKET_COUNTER,
+       RX_CONTROL_FRAME_PACKET_COUNTER,
+       RX_PAUSE_FRAME_PACKET_COUNTER,
+       RX_UNKNOWN_OP_CODE_COUNTER,
+       RX_ALIGNMENT_ERROR_COUNTER,
+       RX_FRAME_LENGTH_ERROR_COUNTER,
+       RX_CODE_ERROR_COUNTER,
+       RX_CARRIER_SENSE_ERROR_COUNTER,
+       RX_UNDERSIZE_PACKET_COUNTER,
+       RX_OVERSIZE_PACKET_COUNTER,
+       RX_FRAGMENTS_COUNTER,
+       RX_JABBER_COUNTER,
+       RX_DROP_PACKET_COUNTER,
+
+       TX_BYTE_COUNTER   = 0x38,
+       TX_PACKET_COUNTER,
+       TX_MULTICAST_PACKET_COUNTER,
+       TX_BROADCAST_PACKET_COUNTER,
+       TX_PAUSE_CONTROL_FRAME_COUNTER,
+       TX_DEFERRAL_PACKET_COUNTER,
+       TX_EXCESSIVE_DEFERRAL_PACKET_COUNTER,
+       TX_SINGLE_COLLISION_PACKET_COUNTER,
+       TX_MULTI_COLLISION_PACKET_COUNTER,
+       TX_LATE_COLLISION_PACKET_COUNTER,
+       TX_EXCESSIVE_COLLISION_PACKET_COUNTER,
+       TX_TOTAL_COLLISION_COUNTER,
+       TX_PAUSE_FRAME_HONERED_COUNTER,
+       TX_DROP_FRAME_COUNTER,
+       TX_JABBER_FRAME_COUNTER,
+       TX_FCS_ERROR_COUNTER,
+       TX_CONTROL_FRAME_COUNTER,
+       TX_OVERSIZE_FRAME_COUNTER,
+       TX_UNDERSIZE_FRAME_COUNTER,
+       TX_FRAGMENT_FRAME_COUNTER,
+
+       CARRY_REG_1 = 0x4c,
+       CARRY_REG_2 = 0x4d,
+};
+
+struct xlr_net_priv {
+       u32 __iomem *base_addr;
+       struct net_device *ndev;
+       struct mii_bus *mii_bus;
+       int num_rx_desc;
+       int phy_addr;   /* PHY addr on MDIO bus */
+       int pcs_id;     /* PCS id on MDIO bus */
+       int port_id;    /* Port(gmac/xgmac) number, i.e 0-7 */
+       u32 __iomem *mii_addr;
+       u32 __iomem *serdes_addr;
+       u32 __iomem *pcs_addr;
+       u32 __iomem *gpio_addr;
+       int phy_speed;
+       int port_type;
+       struct timer_list queue_timer;
+       int wakeup_q;
+       struct platform_device *pdev;
+       struct xlr_net_data *nd;
+
+       u64 *frin_spill;
+       u64 *frout_spill;
+       u64 *class_0_spill;
+       u64 *class_1_spill;
+       u64 *class_2_spill;
+       u64 *class_3_spill;
+};
+
+extern void xlr_set_gmac_speed(struct xlr_net_priv *priv);
index cf159365b0ee19551ff81aa4c5bcbae8b4b055f1..a88959f9a07ab09a82121f81246188d4d1e8aad5 100644 (file)
@@ -352,10 +352,10 @@ static void nvec_toggle_global_events(struct nvec_chip *nvec, bool state)
  */
 static void nvec_event_mask(char *ev, u32 mask)
 {
-       ev[3] = mask >> 16 && 0xff;
-       ev[4] = mask >> 24 && 0xff;
-       ev[5] = mask >> 0  && 0xff;
-       ev[6] = mask >> 8  && 0xff;
+       ev[3] = mask >> 16 & 0xff;
+       ev[4] = mask >> 24 & 0xff;
+       ev[5] = mask >> 0  & 0xff;
+       ev[6] = mask >> 8  & 0xff;
 }
 
 /**
index 54ed6f69e3d47fa4a3c19b9bfa202f422f4d8f8a..193e1c68bb4543a35fcde546c0423d3b99e7df26 100644 (file)
@@ -550,12 +550,12 @@ static int dcon_reboot_notify(struct notifier_block *nb,
        struct dcon_priv *dcon = container_of(nb, struct dcon_priv, reboot_nb);
 
        if (!dcon || !dcon->client)
-               return 0;
+               return NOTIFY_DONE;
 
        /* Turn off the DCON. Entirely. */
        dcon_write(dcon, DCON_REG_MODE, 0x39);
        dcon_write(dcon, DCON_REG_MODE, 0x32);
-       return 0;
+       return NOTIFY_DONE;
 }
 
 static int unfreeze_on_panic(struct notifier_block *nb,
diff --git a/drivers/staging/omap-thermal/Kconfig b/drivers/staging/omap-thermal/Kconfig
deleted file mode 100644 (file)
index 30cbc3b..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-config OMAP_BANDGAP
-       tristate "Texas Instruments OMAP4+ temperature sensor driver"
-       depends on THERMAL
-       depends on ARCH_OMAP4 || SOC_OMAP5
-       help
-         If you say yes here you get support for the Texas Instruments
-         OMAP4460+ on die bandgap temperature sensor support. The register
-         set is part of system control module.
-
-         This includes alert interrupts generation and also the TSHUT
-         support.
-
-config OMAP_THERMAL
-       bool "Texas Instruments OMAP4+ thermal framework support"
-       depends on OMAP_BANDGAP
-       depends on CPU_THERMAL
-       help
-         If you say yes here you want to get support for generic thermal
-         framework for the Texas Instruments OMAP4460+ on die bandgap
-         temperature sensor.
-
-config OMAP4_THERMAL
-       bool "Texas Instruments OMAP4 thermal support"
-       depends on OMAP_BANDGAP
-       depends on ARCH_OMAP4
-       help
-         If you say yes here you get thermal support for the Texas Instruments
-         OMAP4 SoC family. The current chip supported are:
-          - OMAP4430
-          - OMAP4460
-          - OMAP4470
-
-         This includes alert interrupts generation and also the TSHUT
-         support.
-
-config OMAP5_THERMAL
-       bool "Texas Instruments OMAP5 thermal support"
-       depends on OMAP_BANDGAP
-       depends on SOC_OMAP5
-       help
-         If you say yes here you get thermal support for the Texas Instruments
-         OMAP5 SoC family. The current chip supported are:
-          - OMAP5430
-
-         This includes alert interrupts generation and also the TSHUT
-         support.
diff --git a/drivers/staging/omap-thermal/Makefile b/drivers/staging/omap-thermal/Makefile
deleted file mode 100644 (file)
index 091c4d2..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-obj-$(CONFIG_OMAP_BANDGAP)     += omap-thermal.o
-omap-thermal-y                 := omap-bandgap.o
-omap-thermal-$(CONFIG_OMAP_THERMAL)    += omap-thermal-common.o
-omap-thermal-$(CONFIG_OMAP4_THERMAL)   += omap4-thermal.o
-omap-thermal-$(CONFIG_OMAP5_THERMAL)   += omap5-thermal.o
diff --git a/drivers/staging/omap-thermal/TODO b/drivers/staging/omap-thermal/TODO
deleted file mode 100644 (file)
index 9e23cc4..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-List of TODOs (by Eduardo Valentin)
-
-on omap-bandgap.c:
-- Rework locking
-- Improve driver code by adding usage of regmap-mmio
-- Test every exposed API to userland
-- Add support to hwmon
-- Review and revisit all API exposed
-- Revisit PM support
-- Revisit data structures and simplify them
-- Once SCM-core api settles, update this driver accordingly
-
-on omap-thermal-common.c/omap-thermal.h:
-- Revisit extrapolation constants for O4/O5
-- Revisit need for locking
-- Revisit trips and its definitions
-- Revisit trending
-
-on omap5-thermal.c
-- Add support for GPU cooling
-
-generally:
-- write Kconfig dependencies so that omap variants are covered
-- make checkpatch.pl and sparse happy
-- make sure this code works on OMAP4430, OMAP4460 and OMAP5430
-- update documentation
-
-Copy patches to Eduardo Valentin <eduardo.valentin@ti.com>
diff --git a/drivers/staging/omap-thermal/omap-bandgap.c b/drivers/staging/omap-thermal/omap-bandgap.c
deleted file mode 100644 (file)
index dcc1448..0000000
+++ /dev/null
@@ -1,1174 +0,0 @@
-/*
- * OMAP4 Bandgap temperature sensor driver
- *
- * Copyright (C) 2011-2012 Texas Instruments Incorporated - http://www.ti.com/
- * Author: J Keerthy <j-keerthy@ti.com>
- * Author: Moiz Sonasath <m-sonasath@ti.com>
- * Couple of fixes, DT and MFD adaptation:
- *   Eduardo Valentin <eduardo.valentin@ti.com>
- *
- * 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.
- *
- * 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 St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/module.h>
-#include <linux/export.h>
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/interrupt.h>
-#include <linux/clk.h>
-#include <linux/gpio.h>
-#include <linux/platform_device.h>
-#include <linux/err.h>
-#include <linux/types.h>
-#include <linux/mutex.h>
-#include <linux/reboot.h>
-#include <linux/of_device.h>
-#include <linux/of_platform.h>
-#include <linux/of_irq.h>
-#include <linux/io.h>
-
-#include "omap-bandgap.h"
-
-static u32 omap_bandgap_readl(struct omap_bandgap *bg_ptr, u32 reg)
-{
-       return readl(bg_ptr->base + reg);
-}
-
-static void omap_bandgap_writel(struct omap_bandgap *bg_ptr, u32 val, u32 reg)
-{
-       writel(val, bg_ptr->base + reg);
-}
-
-static int omap_bandgap_power(struct omap_bandgap *bg_ptr, bool on)
-{
-       struct temp_sensor_registers *tsr;
-       int i;
-       u32 ctrl;
-
-       if (!OMAP_BANDGAP_HAS(bg_ptr, POWER_SWITCH))
-               return 0;
-
-       for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
-               tsr = bg_ptr->conf->sensors[i].registers;
-               ctrl = omap_bandgap_readl(bg_ptr, tsr->temp_sensor_ctrl);
-               ctrl &= ~tsr->bgap_tempsoff_mask;
-               /* active on 0 */
-               ctrl |= !on << __ffs(tsr->bgap_tempsoff_mask);
-
-               /* write BGAP_TEMPSOFF should be reset to 0 */
-               omap_bandgap_writel(bg_ptr, ctrl, tsr->temp_sensor_ctrl);
-       }
-
-       return 0;
-}
-
-/* This is the Talert handler. Call it only if HAS(TALERT) is set */
-static irqreturn_t talert_irq_handler(int irq, void *data)
-{
-       struct omap_bandgap *bg_ptr = data;
-       struct temp_sensor_registers *tsr;
-       u32 t_hot = 0, t_cold = 0, temp, ctrl;
-       int i;
-
-       bg_ptr = data;
-       /* Read the status of t_hot */
-       for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
-               tsr = bg_ptr->conf->sensors[i].registers;
-               t_hot = omap_bandgap_readl(bg_ptr, tsr->bgap_status);
-               t_hot &= tsr->status_hot_mask;
-
-               /* Read the status of t_cold */
-               t_cold = omap_bandgap_readl(bg_ptr, tsr->bgap_status);
-               t_cold &= tsr->status_cold_mask;
-
-               if (!t_cold && !t_hot)
-                       continue;
-
-               ctrl = omap_bandgap_readl(bg_ptr, tsr->bgap_mask_ctrl);
-               /*
-                * One TALERT interrupt: Two sources
-                * If the interrupt is due to t_hot then mask t_hot and
-                * and unmask t_cold else mask t_cold and unmask t_hot
-                */
-               if (t_hot) {
-                       ctrl &= ~tsr->mask_hot_mask;
-                       ctrl |= tsr->mask_cold_mask;
-               } else if (t_cold) {
-                       ctrl &= ~tsr->mask_cold_mask;
-                       ctrl |= tsr->mask_hot_mask;
-               }
-
-               omap_bandgap_writel(bg_ptr, ctrl, tsr->bgap_mask_ctrl);
-
-               dev_dbg(bg_ptr->dev,
-                       "%s: IRQ from %s sensor: hotevent %d coldevent %d\n",
-                       __func__, bg_ptr->conf->sensors[i].domain,
-                       t_hot, t_cold);
-
-               /* read temperature */
-               temp = omap_bandgap_readl(bg_ptr, tsr->temp_sensor_ctrl);
-               temp &= tsr->bgap_dtemp_mask;
-
-               /* report temperature to whom may concern */
-               if (bg_ptr->conf->report_temperature)
-                       bg_ptr->conf->report_temperature(bg_ptr, i);
-       }
-
-       return IRQ_HANDLED;
-}
-
-/* This is the Tshut handler. Call it only if HAS(TSHUT) is set */
-static irqreturn_t omap_bandgap_tshut_irq_handler(int irq, void *data)
-{
-       orderly_poweroff(true);
-
-       return IRQ_HANDLED;
-}
-
-static
-int adc_to_temp_conversion(struct omap_bandgap *bg_ptr, int id, int adc_val,
-                          int *t)
-{
-       struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[id].ts_data;
-
-       /* look up for temperature in the table and return the temperature */
-       if (adc_val < ts_data->adc_start_val || adc_val > ts_data->adc_end_val)
-               return -ERANGE;
-
-       *t = bg_ptr->conv_table[adc_val - ts_data->adc_start_val];
-
-       return 0;
-}
-
-static int temp_to_adc_conversion(long temp, struct omap_bandgap *bg_ptr, int i,
-                                 int *adc)
-{
-       struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[i].ts_data;
-       int high, low, mid;
-
-       low = 0;
-       high = ts_data->adc_end_val - ts_data->adc_start_val;
-       mid = (high + low) / 2;
-
-       if (temp < bg_ptr->conv_table[low] || temp > bg_ptr->conv_table[high])
-               return -EINVAL;
-
-       while (low < high) {
-               if (temp < bg_ptr->conv_table[mid])
-                       high = mid - 1;
-               else
-                       low = mid + 1;
-               mid = (low + high) / 2;
-       }
-
-       *adc = ts_data->adc_start_val + low;
-
-       return 0;
-}
-
-/* Talert masks. Call it only if HAS(TALERT) is set */
-static int temp_sensor_unmask_interrupts(struct omap_bandgap *bg_ptr, int id,
-                                        u32 t_hot, u32 t_cold)
-{
-       struct temp_sensor_registers *tsr;
-       u32 temp, reg_val;
-
-       /* Read the current on die temperature */
-       tsr = bg_ptr->conf->sensors[id].registers;
-       temp = omap_bandgap_readl(bg_ptr, tsr->temp_sensor_ctrl);
-       temp &= tsr->bgap_dtemp_mask;
-
-       reg_val = omap_bandgap_readl(bg_ptr, tsr->bgap_mask_ctrl);
-       if (temp < t_hot)
-               reg_val |= tsr->mask_hot_mask;
-       else
-               reg_val &= ~tsr->mask_hot_mask;
-
-       if (t_cold < temp)
-               reg_val |= tsr->mask_cold_mask;
-       else
-               reg_val &= ~tsr->mask_cold_mask;
-       omap_bandgap_writel(bg_ptr, reg_val, tsr->bgap_mask_ctrl);
-
-       return 0;
-}
-
-static
-int add_hyst(int adc_val, int hyst_val, struct omap_bandgap *bg_ptr, int i,
-            u32 *sum)
-{
-       int temp, ret;
-
-       ret = adc_to_temp_conversion(bg_ptr, i, adc_val, &temp);
-       if (ret < 0)
-               return ret;
-
-       temp += hyst_val;
-
-       return temp_to_adc_conversion(temp, bg_ptr, i, sum);
-}
-
-/* Talert Thot threshold. Call it only if HAS(TALERT) is set */
-static
-int temp_sensor_configure_thot(struct omap_bandgap *bg_ptr, int id, int t_hot)
-{
-       struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[id].ts_data;
-       struct temp_sensor_registers *tsr;
-       u32 thresh_val, reg_val;
-       int cold, err = 0;
-
-       tsr = bg_ptr->conf->sensors[id].registers;
-
-       /* obtain the T cold value */
-       thresh_val = omap_bandgap_readl(bg_ptr, tsr->bgap_threshold);
-       cold = (thresh_val & tsr->threshold_tcold_mask) >>
-           __ffs(tsr->threshold_tcold_mask);
-       if (t_hot <= cold) {
-               /* change the t_cold to t_hot - 5000 millidegrees */
-               err |= add_hyst(t_hot, -ts_data->hyst_val, bg_ptr, id, &cold);
-               /* write the new t_cold value */
-               reg_val = thresh_val & (~tsr->threshold_tcold_mask);
-               reg_val |= cold << __ffs(tsr->threshold_tcold_mask);
-               omap_bandgap_writel(bg_ptr, reg_val, tsr->bgap_threshold);
-               thresh_val = reg_val;
-       }
-
-       /* write the new t_hot value */
-       reg_val = thresh_val & ~tsr->threshold_thot_mask;
-       reg_val |= (t_hot << __ffs(tsr->threshold_thot_mask));
-       omap_bandgap_writel(bg_ptr, reg_val, tsr->bgap_threshold);
-       if (err) {
-               dev_err(bg_ptr->dev, "failed to reprogram thot threshold\n");
-               return -EIO;
-       }
-
-       return temp_sensor_unmask_interrupts(bg_ptr, id, t_hot, cold);
-}
-
-/* Talert Thot and Tcold thresholds. Call it only if HAS(TALERT) is set */
-static
-int temp_sensor_init_talert_thresholds(struct omap_bandgap *bg_ptr, int id,
-                                      int t_hot, int t_cold)
-{
-       struct temp_sensor_registers *tsr;
-       u32 reg_val, thresh_val;
-
-       tsr = bg_ptr->conf->sensors[id].registers;
-       thresh_val = omap_bandgap_readl(bg_ptr, tsr->bgap_threshold);
-
-       /* write the new t_cold value */
-       reg_val = thresh_val & ~tsr->threshold_tcold_mask;
-       reg_val |= (t_cold << __ffs(tsr->threshold_tcold_mask));
-       omap_bandgap_writel(bg_ptr, reg_val, tsr->bgap_threshold);
-
-       thresh_val = omap_bandgap_readl(bg_ptr, tsr->bgap_threshold);
-
-       /* write the new t_hot value */
-       reg_val = thresh_val & ~tsr->threshold_thot_mask;
-       reg_val |= (t_hot << __ffs(tsr->threshold_thot_mask));
-       omap_bandgap_writel(bg_ptr, reg_val, tsr->bgap_threshold);
-
-       reg_val = omap_bandgap_readl(bg_ptr, tsr->bgap_mask_ctrl);
-       reg_val |= tsr->mask_hot_mask;
-       reg_val |= tsr->mask_cold_mask;
-       omap_bandgap_writel(bg_ptr, reg_val, tsr->bgap_mask_ctrl);
-
-       return 0;
-}
-
-/* Talert Tcold threshold. Call it only if HAS(TALERT) is set */
-static
-int temp_sensor_configure_tcold(struct omap_bandgap *bg_ptr, int id,
-                               int t_cold)
-{
-       struct temp_sensor_data *ts_data = bg_ptr->conf->sensors[id].ts_data;
-       struct temp_sensor_registers *tsr;
-       u32 thresh_val, reg_val;
-       int hot, err = 0;
-
-       tsr = bg_ptr->conf->sensors[id].registers;
-       /* obtain the T cold value */
-       thresh_val = omap_bandgap_readl(bg_ptr, tsr->bgap_threshold);
-       hot = (thresh_val & tsr->threshold_thot_mask) >>
-           __ffs(tsr->threshold_thot_mask);
-
-       if (t_cold >= hot) {
-               /* change the t_hot to t_cold + 5000 millidegrees */
-               err |= add_hyst(t_cold, ts_data->hyst_val, bg_ptr, id, &hot);
-               /* write the new t_hot value */
-               reg_val = thresh_val & (~tsr->threshold_thot_mask);
-               reg_val |= hot << __ffs(tsr->threshold_thot_mask);
-               omap_bandgap_writel(bg_ptr, reg_val, tsr->bgap_threshold);
-               thresh_val = reg_val;
-       }
-
-       /* write the new t_cold value */
-       reg_val = thresh_val & ~tsr->threshold_tcold_mask;
-       reg_val |= (t_cold << __ffs(tsr->threshold_tcold_mask));
-       omap_bandgap_writel(bg_ptr, reg_val, tsr->bgap_threshold);
-       if (err) {
-               dev_err(bg_ptr->dev, "failed to reprogram tcold threshold\n");
-               return -EIO;
-       }
-
-       return temp_sensor_unmask_interrupts(bg_ptr, id, hot, t_cold);
-}
-
-/* This is Tshut Thot config. Call it only if HAS(TSHUT_CONFIG) is set */
-static int temp_sensor_configure_tshut_hot(struct omap_bandgap *bg_ptr,
-                                          int id, int tshut_hot)
-{
-       struct temp_sensor_registers *tsr;
-       u32 reg_val;
-
-       tsr = bg_ptr->conf->sensors[id].registers;
-       reg_val = omap_bandgap_readl(bg_ptr, tsr->tshut_threshold);
-       reg_val &= ~tsr->tshut_hot_mask;
-       reg_val |= tshut_hot << __ffs(tsr->tshut_hot_mask);
-       omap_bandgap_writel(bg_ptr, reg_val, tsr->tshut_threshold);
-
-       return 0;
-}
-
-/* This is Tshut Tcold config. Call it only if HAS(TSHUT_CONFIG) is set */
-static int temp_sensor_configure_tshut_cold(struct omap_bandgap *bg_ptr,
-                                           int id, int tshut_cold)
-{
-       struct temp_sensor_registers *tsr;
-       u32 reg_val;
-
-       tsr = bg_ptr->conf->sensors[id].registers;
-       reg_val = omap_bandgap_readl(bg_ptr, tsr->tshut_threshold);
-       reg_val &= ~tsr->tshut_cold_mask;
-       reg_val |= tshut_cold << __ffs(tsr->tshut_cold_mask);
-       omap_bandgap_writel(bg_ptr, reg_val, tsr->tshut_threshold);
-
-       return 0;
-}
-
-/* This is counter config. Call it only if HAS(COUNTER) is set */
-static int configure_temp_sensor_counter(struct omap_bandgap *bg_ptr, int id,
-                                        u32 counter)
-{
-       struct temp_sensor_registers *tsr;
-       u32 val;
-
-       tsr = bg_ptr->conf->sensors[id].registers;
-       val = omap_bandgap_readl(bg_ptr, tsr->bgap_counter);
-       val &= ~tsr->counter_mask;
-       val |= counter << __ffs(tsr->counter_mask);
-       omap_bandgap_writel(bg_ptr, val, tsr->bgap_counter);
-
-       return 0;
-}
-
-#define bandgap_is_valid(b)                                            \
-                       (!IS_ERR_OR_NULL(b))
-#define bandgap_is_valid_sensor_id(b, i)                               \
-                       ((i) >= 0 && (i) < (b)->conf->sensor_count)
-static inline int omap_bandgap_validate(struct omap_bandgap *bg_ptr, int id)
-{
-       if (!bandgap_is_valid(bg_ptr)) {
-               pr_err("%s: invalid bandgap pointer\n", __func__);
-               return -EINVAL;
-       }
-
-       if (!bandgap_is_valid_sensor_id(bg_ptr, id)) {
-               dev_err(bg_ptr->dev, "%s: sensor id out of range (%d)\n",
-                       __func__, id);
-               return -ERANGE;
-       }
-
-       return 0;
-}
-
-/* Exposed APIs */
-/**
- * omap_bandgap_read_thot() - reads sensor current thot
- * @bg_ptr - pointer to bandgap instance
- * @id - sensor id
- * @thot - resulting current thot value
- *
- * returns 0 on success or the proper error code
- */
-int omap_bandgap_read_thot(struct omap_bandgap *bg_ptr, int id,
-                             int *thot)
-{
-       struct temp_sensor_registers *tsr;
-       u32 temp;
-       int ret;
-
-       ret = omap_bandgap_validate(bg_ptr, id);
-       if (ret)
-               return ret;
-
-       if (!OMAP_BANDGAP_HAS(bg_ptr, TALERT))
-               return -ENOTSUPP;
-
-       tsr = bg_ptr->conf->sensors[id].registers;
-       temp = omap_bandgap_readl(bg_ptr, tsr->bgap_threshold);
-       temp = (temp & tsr->threshold_thot_mask) >>
-               __ffs(tsr->threshold_thot_mask);
-       ret |= adc_to_temp_conversion(bg_ptr, id, temp, &temp);
-       if (ret) {
-               dev_err(bg_ptr->dev, "failed to read thot\n");
-               return -EIO;
-       }
-
-       *thot = temp;
-
-       return 0;
-}
-
-/**
- * omap_bandgap_write_thot() - sets sensor current thot
- * @bg_ptr - pointer to bandgap instance
- * @id - sensor id
- * @val - desired thot value
- *
- * returns 0 on success or the proper error code
- */
-int omap_bandgap_write_thot(struct omap_bandgap *bg_ptr, int id, int val)
-{
-       struct temp_sensor_data *ts_data;
-       struct temp_sensor_registers *tsr;
-       u32 t_hot;
-       int ret;
-
-       ret = omap_bandgap_validate(bg_ptr, id);
-       if (ret)
-               return ret;
-
-       if (!OMAP_BANDGAP_HAS(bg_ptr, TALERT))
-               return -ENOTSUPP;
-
-       ts_data = bg_ptr->conf->sensors[id].ts_data;
-       tsr = bg_ptr->conf->sensors[id].registers;
-
-       if (val < ts_data->min_temp + ts_data->hyst_val)
-               return -EINVAL;
-       ret = temp_to_adc_conversion(val, bg_ptr, id, &t_hot);
-       if (ret < 0)
-               return ret;
-
-       mutex_lock(&bg_ptr->bg_mutex);
-       temp_sensor_configure_thot(bg_ptr, id, t_hot);
-       mutex_unlock(&bg_ptr->bg_mutex);
-
-       return 0;
-}
-
-/**
- * omap_bandgap_read_tcold() - reads sensor current tcold
- * @bg_ptr - pointer to bandgap instance
- * @id - sensor id
- * @tcold - resulting current tcold value
- *
- * returns 0 on success or the proper error code
- */
-int omap_bandgap_read_tcold(struct omap_bandgap *bg_ptr, int id,
-                              int *tcold)
-{
-       struct temp_sensor_registers *tsr;
-       u32 temp;
-       int ret;
-
-       ret = omap_bandgap_validate(bg_ptr, id);
-       if (ret)
-               return ret;
-
-       if (!OMAP_BANDGAP_HAS(bg_ptr, TALERT))
-               return -ENOTSUPP;
-
-       tsr = bg_ptr->conf->sensors[id].registers;
-       temp = omap_bandgap_readl(bg_ptr, tsr->bgap_threshold);
-       temp = (temp & tsr->threshold_tcold_mask)
-           >> __ffs(tsr->threshold_tcold_mask);
-       ret |= adc_to_temp_conversion(bg_ptr, id, temp, &temp);
-       if (ret)
-               return -EIO;
-
-       *tcold = temp;
-
-       return 0;
-}
-
-/**
- * omap_bandgap_write_tcold() - sets the sensor tcold
- * @bg_ptr - pointer to bandgap instance
- * @id - sensor id
- * @val - desired tcold value
- *
- * returns 0 on success or the proper error code
- */
-int omap_bandgap_write_tcold(struct omap_bandgap *bg_ptr, int id, int val)
-{
-       struct temp_sensor_data *ts_data;
-       struct temp_sensor_registers *tsr;
-       u32 t_cold;
-       int ret;
-
-       ret = omap_bandgap_validate(bg_ptr, id);
-       if (ret)
-               return ret;
-
-       if (!OMAP_BANDGAP_HAS(bg_ptr, TALERT))
-               return -ENOTSUPP;
-
-       ts_data = bg_ptr->conf->sensors[id].ts_data;
-       tsr = bg_ptr->conf->sensors[id].registers;
-       if (val > ts_data->max_temp + ts_data->hyst_val)
-               return -EINVAL;
-
-       ret = temp_to_adc_conversion(val, bg_ptr, id, &t_cold);
-       if (ret < 0)
-               return ret;
-
-       mutex_lock(&bg_ptr->bg_mutex);
-       temp_sensor_configure_tcold(bg_ptr, id, t_cold);
-       mutex_unlock(&bg_ptr->bg_mutex);
-
-       return 0;
-}
-
-/**
- * omap_bandgap_read_update_interval() - read the sensor update interval
- * @bg_ptr - pointer to bandgap instance
- * @id - sensor id
- * @interval - resulting update interval in miliseconds
- *
- * returns 0 on success or the proper error code
- */
-int omap_bandgap_read_update_interval(struct omap_bandgap *bg_ptr, int id,
-                                        int *interval)
-{
-       struct temp_sensor_registers *tsr;
-       u32 time;
-       int ret;
-
-       ret = omap_bandgap_validate(bg_ptr, id);
-       if (ret)
-               return ret;
-
-       if (!OMAP_BANDGAP_HAS(bg_ptr, COUNTER))
-               return -ENOTSUPP;
-
-       tsr = bg_ptr->conf->sensors[id].registers;
-       time = omap_bandgap_readl(bg_ptr, tsr->bgap_counter);
-       time = (time & tsr->counter_mask) >> __ffs(tsr->counter_mask);
-       time = time * 1000 / bg_ptr->clk_rate;
-
-       *interval = time;
-
-       return 0;
-}
-
-/**
- * omap_bandgap_write_update_interval() - set the update interval
- * @bg_ptr - pointer to bandgap instance
- * @id - sensor id
- * @interval - desired update interval in miliseconds
- *
- * returns 0 on success or the proper error code
- */
-int omap_bandgap_write_update_interval(struct omap_bandgap *bg_ptr,
-                                         int id, u32 interval)
-{
-       int ret = omap_bandgap_validate(bg_ptr, id);
-       if (ret)
-               return ret;
-
-       if (!OMAP_BANDGAP_HAS(bg_ptr, COUNTER))
-               return -ENOTSUPP;
-
-       interval = interval * bg_ptr->clk_rate / 1000;
-       mutex_lock(&bg_ptr->bg_mutex);
-       configure_temp_sensor_counter(bg_ptr, id, interval);
-       mutex_unlock(&bg_ptr->bg_mutex);
-
-       return 0;
-}
-
-/**
- * omap_bandgap_read_temperature() - report current temperature
- * @bg_ptr - pointer to bandgap instance
- * @id - sensor id
- * @temperature - resulting temperature
- *
- * returns 0 on success or the proper error code
- */
-int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id,
-                                    int *temperature)
-{
-       struct temp_sensor_registers *tsr;
-       u32 temp;
-       int ret;
-
-       ret = omap_bandgap_validate(bg_ptr, id);
-       if (ret)
-               return ret;
-
-       tsr = bg_ptr->conf->sensors[id].registers;
-       temp = omap_bandgap_readl(bg_ptr, tsr->temp_sensor_ctrl);
-       temp &= tsr->bgap_dtemp_mask;
-
-       ret |= adc_to_temp_conversion(bg_ptr, id, temp, &temp);
-       if (ret)
-               return -EIO;
-
-       *temperature = temp;
-
-       return 0;
-}
-
-/**
- * omap_bandgap_set_sensor_data() - helper function to store thermal
- * framework related data.
- * @bg_ptr - pointer to bandgap instance
- * @id - sensor id
- * @data - thermal framework related data to be stored
- *
- * returns 0 on success or the proper error code
- */
-int omap_bandgap_set_sensor_data(struct omap_bandgap *bg_ptr, int id,
-                               void *data)
-{
-       int ret = omap_bandgap_validate(bg_ptr, id);
-       if (ret)
-               return ret;
-
-       bg_ptr->conf->sensors[id].data = data;
-
-       return 0;
-}
-
-/**
- * omap_bandgap_get_sensor_data() - helper function to get thermal
- * framework related data.
- * @bg_ptr - pointer to bandgap instance
- * @id - sensor id
- *
- * returns data stored by set function with sensor id on success or NULL
- */
-void *omap_bandgap_get_sensor_data(struct omap_bandgap *bg_ptr, int id)
-{
-       int ret = omap_bandgap_validate(bg_ptr, id);
-       if (ret)
-               return ERR_PTR(ret);
-
-       return bg_ptr->conf->sensors[id].data;
-}
-
-static int
-omap_bandgap_force_single_read(struct omap_bandgap *bg_ptr, int id)
-{
-       struct temp_sensor_registers *tsr;
-       u32 temp = 0, counter = 1000;
-
-       tsr = bg_ptr->conf->sensors[id].registers;
-       /* Select single conversion mode */
-       if (OMAP_BANDGAP_HAS(bg_ptr, MODE_CONFIG)) {
-               temp = omap_bandgap_readl(bg_ptr, tsr->bgap_mode_ctrl);
-               temp &= ~(1 << __ffs(tsr->mode_ctrl_mask));
-               omap_bandgap_writel(bg_ptr, temp, tsr->bgap_mode_ctrl);
-       }
-
-       /* Start of Conversion = 1 */
-       temp = omap_bandgap_readl(bg_ptr, tsr->temp_sensor_ctrl);
-       temp |= 1 << __ffs(tsr->bgap_soc_mask);
-       omap_bandgap_writel(bg_ptr, temp, tsr->temp_sensor_ctrl);
-       /* Wait until DTEMP is updated */
-       temp = omap_bandgap_readl(bg_ptr, tsr->temp_sensor_ctrl);
-       temp &= (tsr->bgap_dtemp_mask);
-       while ((temp == 0) && --counter) {
-               temp = omap_bandgap_readl(bg_ptr, tsr->temp_sensor_ctrl);
-               temp &= (tsr->bgap_dtemp_mask);
-       }
-       /* Start of Conversion = 0 */
-       temp = omap_bandgap_readl(bg_ptr, tsr->temp_sensor_ctrl);
-       temp &= ~(1 << __ffs(tsr->bgap_soc_mask));
-       omap_bandgap_writel(bg_ptr, temp, tsr->temp_sensor_ctrl);
-
-       return 0;
-}
-
-/**
- * enable_continuous_mode() - One time enabling of continuous conversion mode
- * @bg_ptr - pointer to scm instance
- *
- * Call this function only if HAS(MODE_CONFIG) is set
- */
-static int enable_continuous_mode(struct omap_bandgap *bg_ptr)
-{
-       struct temp_sensor_registers *tsr;
-       int i;
-       u32 val;
-
-       for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
-               /* Perform a single read just before enabling continuous */
-               omap_bandgap_force_single_read(bg_ptr, i);
-               tsr = bg_ptr->conf->sensors[i].registers;
-               val = omap_bandgap_readl(bg_ptr, tsr->bgap_mode_ctrl);
-               val |= 1 << __ffs(tsr->mode_ctrl_mask);
-               omap_bandgap_writel(bg_ptr, val, tsr->bgap_mode_ctrl);
-       }
-
-       return 0;
-}
-
-static int omap_bandgap_tshut_init(struct omap_bandgap *bg_ptr,
-                                     struct platform_device *pdev)
-{
-       int gpio_nr = bg_ptr->tshut_gpio;
-       int status;
-
-       /* Request for gpio_86 line */
-       status = gpio_request(gpio_nr, "tshut");
-       if (status < 0) {
-               dev_err(bg_ptr->dev,
-                       "Could not request for TSHUT GPIO:%i\n", 86);
-               return status;
-       }
-       status = gpio_direction_input(gpio_nr);
-       if (status) {
-               dev_err(bg_ptr->dev,
-                       "Cannot set input TSHUT GPIO %d\n", gpio_nr);
-               return status;
-       }
-
-       status = request_irq(gpio_to_irq(gpio_nr),
-                            omap_bandgap_tshut_irq_handler,
-                            IRQF_TRIGGER_RISING, "tshut",
-                            NULL);
-       if (status) {
-               gpio_free(gpio_nr);
-               dev_err(bg_ptr->dev, "request irq failed for TSHUT");
-       }
-
-       return 0;
-}
-
-/* Initialization of Talert. Call it only if HAS(TALERT) is set */
-static int omap_bandgap_talert_init(struct omap_bandgap *bg_ptr,
-                                      struct platform_device *pdev)
-{
-       int ret;
-
-       bg_ptr->irq = platform_get_irq(pdev, 0);
-       if (bg_ptr->irq < 0) {
-               dev_err(&pdev->dev, "get_irq failed\n");
-               return bg_ptr->irq;
-       }
-       ret = request_threaded_irq(bg_ptr->irq, NULL,
-                                  talert_irq_handler,
-                                  IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
-                                  "talert", bg_ptr);
-       if (ret) {
-               dev_err(&pdev->dev, "Request threaded irq failed.\n");
-               return ret;
-       }
-
-       return 0;
-}
-
-static const struct of_device_id of_omap_bandgap_match[];
-static struct omap_bandgap *omap_bandgap_build(struct platform_device *pdev)
-{
-       struct device_node *node = pdev->dev.of_node;
-       const struct of_device_id *of_id;
-       struct omap_bandgap *bg_ptr;
-       struct resource *res;
-       u32 prop;
-       int i;
-
-       /* just for the sake */
-       if (!node) {
-               dev_err(&pdev->dev, "no platform information available\n");
-               return ERR_PTR(-EINVAL);
-       }
-
-       bg_ptr = devm_kzalloc(&pdev->dev, sizeof(struct omap_bandgap),
-                                   GFP_KERNEL);
-       if (!bg_ptr) {
-               dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n");
-               return ERR_PTR(-ENOMEM);
-       }
-
-       of_id = of_match_device(of_omap_bandgap_match, &pdev->dev);
-       if (of_id)
-               bg_ptr->conf = of_id->data;
-
-       i = 0;
-       do {
-               void __iomem *chunk;
-
-               res = platform_get_resource(pdev, IORESOURCE_MEM, i);
-               if (!res)
-                       break;
-               chunk = devm_ioremap_resource(&pdev->dev, res);
-               if (i == 0)
-                       bg_ptr->base = chunk;
-               if (IS_ERR(chunk))
-                       return ERR_CAST(chunk);
-               
-               i++;
-       } while (res);
-
-       if (OMAP_BANDGAP_HAS(bg_ptr, TSHUT)) {
-               if (of_property_read_u32(node, "ti,tshut-gpio", &prop) < 0) {
-                       dev_err(&pdev->dev, "missing tshut gpio in device tree\n");
-                       return ERR_PTR(-EINVAL);
-               }
-               bg_ptr->tshut_gpio = prop;
-               if (!gpio_is_valid(bg_ptr->tshut_gpio)) {
-                       dev_err(&pdev->dev, "invalid gpio for tshut (%d)\n",
-                               bg_ptr->tshut_gpio);
-                       return ERR_PTR(-EINVAL);
-               }
-       }
-
-       return bg_ptr;
-}
-
-static
-int omap_bandgap_probe(struct platform_device *pdev)
-{
-       struct omap_bandgap *bg_ptr;
-       int clk_rate, ret = 0, i;
-
-       bg_ptr = omap_bandgap_build(pdev);
-       if (IS_ERR_OR_NULL(bg_ptr)) {
-               dev_err(&pdev->dev, "failed to fetch platform data\n");
-               return PTR_ERR(bg_ptr);
-       }
-       bg_ptr->dev = &pdev->dev;
-
-       if (OMAP_BANDGAP_HAS(bg_ptr, TSHUT)) {
-               ret = omap_bandgap_tshut_init(bg_ptr, pdev);
-               if (ret) {
-                       dev_err(&pdev->dev,
-                               "failed to initialize system tshut IRQ\n");
-                       return ret;
-               }
-       }
-
-       bg_ptr->fclock = clk_get(NULL, bg_ptr->conf->fclock_name);
-       ret = IS_ERR_OR_NULL(bg_ptr->fclock);
-       if (ret) {
-               dev_err(&pdev->dev, "failed to request fclock reference\n");
-               goto free_irqs;
-       }
-
-       bg_ptr->div_clk = clk_get(NULL,  bg_ptr->conf->div_ck_name);
-       ret = IS_ERR_OR_NULL(bg_ptr->div_clk);
-       if (ret) {
-               dev_err(&pdev->dev,
-                       "failed to request div_ts_ck clock ref\n");
-               goto free_irqs;
-       }
-
-       bg_ptr->conv_table = bg_ptr->conf->conv_table;
-       for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
-               struct temp_sensor_registers *tsr;
-               u32 val;
-
-               tsr = bg_ptr->conf->sensors[i].registers;
-               /*
-                * check if the efuse has a non-zero value if not
-                * it is an untrimmed sample and the temperatures
-                * may not be accurate
-                */
-               val = omap_bandgap_readl(bg_ptr, tsr->bgap_efuse);
-               if (ret || !val)
-                       dev_info(&pdev->dev,
-                                "Non-trimmed BGAP, Temp not accurate\n");
-       }
-
-       clk_rate = clk_round_rate(bg_ptr->div_clk,
-                                 bg_ptr->conf->sensors[0].ts_data->max_freq);
-       if (clk_rate < bg_ptr->conf->sensors[0].ts_data->min_freq ||
-           clk_rate == 0xffffffff) {
-               ret = -ENODEV;
-               dev_err(&pdev->dev, "wrong clock rate (%d)\n", clk_rate);
-               goto put_clks;
-       }
-
-       ret = clk_set_rate(bg_ptr->div_clk, clk_rate);
-       if (ret)
-               dev_err(&pdev->dev, "Cannot re-set clock rate. Continuing\n");
-
-       bg_ptr->clk_rate = clk_rate;
-       clk_enable(bg_ptr->fclock);
-
-       mutex_init(&bg_ptr->bg_mutex);
-       bg_ptr->dev = &pdev->dev;
-       platform_set_drvdata(pdev, bg_ptr);
-
-       omap_bandgap_power(bg_ptr, true);
-
-       /* Set default counter to 1 for now */
-       if (OMAP_BANDGAP_HAS(bg_ptr, COUNTER))
-               for (i = 0; i < bg_ptr->conf->sensor_count; i++)
-                       configure_temp_sensor_counter(bg_ptr, i, 1);
-
-       for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
-               struct temp_sensor_data *ts_data;
-
-               ts_data = bg_ptr->conf->sensors[i].ts_data;
-
-               if (OMAP_BANDGAP_HAS(bg_ptr, TALERT))
-                       temp_sensor_init_talert_thresholds(bg_ptr, i,
-                                                          ts_data->t_hot,
-                                                          ts_data->t_cold);
-               if (OMAP_BANDGAP_HAS(bg_ptr, TSHUT_CONFIG)) {
-                       temp_sensor_configure_tshut_hot(bg_ptr, i,
-                                                       ts_data->tshut_hot);
-                       temp_sensor_configure_tshut_cold(bg_ptr, i,
-                                                        ts_data->tshut_cold);
-               }
-       }
-
-       if (OMAP_BANDGAP_HAS(bg_ptr, MODE_CONFIG))
-               enable_continuous_mode(bg_ptr);
-
-       /* Set .250 seconds time as default counter */
-       if (OMAP_BANDGAP_HAS(bg_ptr, COUNTER))
-               for (i = 0; i < bg_ptr->conf->sensor_count; i++)
-                       configure_temp_sensor_counter(bg_ptr, i,
-                                                     bg_ptr->clk_rate / 4);
-
-       /* Every thing is good? Then expose the sensors */
-       for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
-               char *domain;
-
-               if (bg_ptr->conf->sensors[i].register_cooling)
-                       bg_ptr->conf->sensors[i].register_cooling(bg_ptr, i);
-
-               domain = bg_ptr->conf->sensors[i].domain;
-               if (bg_ptr->conf->expose_sensor)
-                       bg_ptr->conf->expose_sensor(bg_ptr, i, domain);
-       }
-
-       /*
-        * Enable the Interrupts once everything is set. Otherwise irq handler
-        * might be called as soon as it is enabled where as rest of framework
-        * is still getting initialised.
-        */
-       if (OMAP_BANDGAP_HAS(bg_ptr, TALERT)) {
-               ret = omap_bandgap_talert_init(bg_ptr, pdev);
-               if (ret) {
-                       dev_err(&pdev->dev, "failed to initialize Talert IRQ\n");
-                       i = bg_ptr->conf->sensor_count;
-                       goto disable_clk;
-               }
-       }
-
-       return 0;
-
-disable_clk:
-       clk_disable(bg_ptr->fclock);
-put_clks:
-       clk_put(bg_ptr->fclock);
-       clk_put(bg_ptr->div_clk);
-free_irqs:
-       if (OMAP_BANDGAP_HAS(bg_ptr, TSHUT)) {
-               free_irq(gpio_to_irq(bg_ptr->tshut_gpio), NULL);
-               gpio_free(bg_ptr->tshut_gpio);
-       }
-
-       return ret;
-}
-
-static
-int omap_bandgap_remove(struct platform_device *pdev)
-{
-       struct omap_bandgap *bg_ptr = platform_get_drvdata(pdev);
-       int i;
-
-       /* First thing is to remove sensor interfaces */
-       for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
-               if (bg_ptr->conf->sensors[i].register_cooling)
-                       bg_ptr->conf->sensors[i].unregister_cooling(bg_ptr, i);
-
-               if (bg_ptr->conf->remove_sensor)
-                       bg_ptr->conf->remove_sensor(bg_ptr, i);
-       }
-
-       omap_bandgap_power(bg_ptr, false);
-
-       clk_disable(bg_ptr->fclock);
-       clk_put(bg_ptr->fclock);
-       clk_put(bg_ptr->div_clk);
-
-       if (OMAP_BANDGAP_HAS(bg_ptr, TALERT))
-               free_irq(bg_ptr->irq, bg_ptr);
-
-       if (OMAP_BANDGAP_HAS(bg_ptr, TSHUT)) {
-               free_irq(gpio_to_irq(bg_ptr->tshut_gpio), NULL);
-               gpio_free(bg_ptr->tshut_gpio);
-       }
-
-       return 0;
-}
-
-#ifdef CONFIG_PM
-static int omap_bandgap_save_ctxt(struct omap_bandgap *bg_ptr)
-{
-       int i;
-
-       for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
-               struct temp_sensor_registers *tsr;
-               struct temp_sensor_regval *rval;
-
-               rval = &bg_ptr->conf->sensors[i].regval;
-               tsr = bg_ptr->conf->sensors[i].registers;
-
-               if (OMAP_BANDGAP_HAS(bg_ptr, MODE_CONFIG))
-                       rval->bg_mode_ctrl = omap_bandgap_readl(bg_ptr,
-                                                       tsr->bgap_mode_ctrl);
-               if (OMAP_BANDGAP_HAS(bg_ptr, COUNTER))
-                       rval->bg_counter = omap_bandgap_readl(bg_ptr,
-                                                       tsr->bgap_counter);
-               if (OMAP_BANDGAP_HAS(bg_ptr, TALERT)) {
-                       rval->bg_threshold = omap_bandgap_readl(bg_ptr,
-                                                       tsr->bgap_threshold);
-                       rval->bg_ctrl = omap_bandgap_readl(bg_ptr,
-                                                  tsr->bgap_mask_ctrl);
-               }
-
-               if (OMAP_BANDGAP_HAS(bg_ptr, TSHUT_CONFIG))
-                       rval->tshut_threshold = omap_bandgap_readl(bg_ptr,
-                                                  tsr->tshut_threshold);
-       }
-
-       return 0;
-}
-
-static int omap_bandgap_restore_ctxt(struct omap_bandgap *bg_ptr)
-{
-       int i;
-
-       for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
-               struct temp_sensor_registers *tsr;
-               struct temp_sensor_regval *rval;
-               u32 val = 0;
-
-               rval = &bg_ptr->conf->sensors[i].regval;
-               tsr = bg_ptr->conf->sensors[i].registers;
-
-               if (OMAP_BANDGAP_HAS(bg_ptr, COUNTER))
-                       val = omap_bandgap_readl(bg_ptr, tsr->bgap_counter);
-
-               if (OMAP_BANDGAP_HAS(bg_ptr, TSHUT_CONFIG))
-                       omap_bandgap_writel(bg_ptr,
-                               rval->tshut_threshold,
-                                          tsr->tshut_threshold);
-               /* Force immediate temperature measurement and update
-                * of the DTEMP field
-                */
-               omap_bandgap_force_single_read(bg_ptr, i);
-
-               if (OMAP_BANDGAP_HAS(bg_ptr, COUNTER))
-                       omap_bandgap_writel(bg_ptr, rval->bg_counter,
-                                                  tsr->bgap_counter);
-               if (OMAP_BANDGAP_HAS(bg_ptr, MODE_CONFIG))
-                       omap_bandgap_writel(bg_ptr, rval->bg_mode_ctrl,
-                                                  tsr->bgap_mode_ctrl);
-               if (OMAP_BANDGAP_HAS(bg_ptr, TALERT)) {
-                       omap_bandgap_writel(bg_ptr,
-                                                  rval->bg_threshold,
-                                                  tsr->bgap_threshold);
-                       omap_bandgap_writel(bg_ptr, rval->bg_ctrl,
-                                                  tsr->bgap_mask_ctrl);
-               }
-       }
-
-       return 0;
-}
-
-static int omap_bandgap_suspend(struct device *dev)
-{
-       struct omap_bandgap *bg_ptr = dev_get_drvdata(dev);
-       int err;
-
-       err = omap_bandgap_save_ctxt(bg_ptr);
-       omap_bandgap_power(bg_ptr, false);
-       clk_disable(bg_ptr->fclock);
-
-       return err;
-}
-
-static int omap_bandgap_resume(struct device *dev)
-{
-       struct omap_bandgap *bg_ptr = dev_get_drvdata(dev);
-
-       clk_enable(bg_ptr->fclock);
-       omap_bandgap_power(bg_ptr, true);
-
-       return omap_bandgap_restore_ctxt(bg_ptr);
-}
-static const struct dev_pm_ops omap_bandgap_dev_pm_ops = {
-       SET_SYSTEM_SLEEP_PM_OPS(omap_bandgap_suspend,
-                               omap_bandgap_resume)
-};
-
-#define DEV_PM_OPS     (&omap_bandgap_dev_pm_ops)
-#else
-#define DEV_PM_OPS     NULL
-#endif
-
-static const struct of_device_id of_omap_bandgap_match[] = {
-#ifdef CONFIG_OMAP4_THERMAL
-       {
-               .compatible = "ti,omap4430-bandgap",
-               .data = (void *)&omap4430_data,
-       },
-       {
-               .compatible = "ti,omap4460-bandgap",
-               .data = (void *)&omap4460_data,
-       },
-       {
-               .compatible = "ti,omap4470-bandgap",
-               .data = (void *)&omap4470_data,
-       },
-#endif
-#ifdef CONFIG_OMAP5_THERMAL
-       {
-               .compatible = "ti,omap5430-bandgap",
-               .data = (void *)&omap5430_data,
-       },
-#endif
-       /* Sentinel */
-       { },
-};
-MODULE_DEVICE_TABLE(of, of_omap_bandgap_match);
-
-static struct platform_driver omap_bandgap_sensor_driver = {
-       .probe = omap_bandgap_probe,
-       .remove = omap_bandgap_remove,
-       .driver = {
-                       .name = "omap-bandgap",
-                       .pm = DEV_PM_OPS,
-                       .of_match_table = of_omap_bandgap_match,
-       },
-};
-
-module_platform_driver(omap_bandgap_sensor_driver);
-
-MODULE_DESCRIPTION("OMAP4+ bandgap temperature sensor driver");
-MODULE_LICENSE("GPL v2");
-MODULE_ALIAS("platform:omap-bandgap");
-MODULE_AUTHOR("Texas Instrument Inc.");
diff --git a/drivers/staging/omap-thermal/omap-bandgap.h b/drivers/staging/omap-thermal/omap-bandgap.h
deleted file mode 100644 (file)
index 2bb14bd..0000000
+++ /dev/null
@@ -1,432 +0,0 @@
-/*
- * OMAP4 Bandgap temperature sensor driver
- *
- * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
- * Contact:
- *   Eduardo Valentin <eduardo.valentin@ti.com>
- *
- * 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.
- *
- * 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 St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-#ifndef __OMAP_BANDGAP_H
-#define __OMAP_BANDGAP_H
-
-#include <linux/mutex.h>
-#include <linux/types.h>
-#include <linux/err.h>
-
-/* TEMP_SENSOR OMAP4430 */
-#define OMAP4430_BGAP_TSHUT_SHIFT                      11
-#define OMAP4430_BGAP_TSHUT_MASK                       (1 << 11)
-
-/* TEMP_SENSOR OMAP4430 */
-#define OMAP4430_BGAP_TEMPSOFF_SHIFT                   12
-#define OMAP4430_BGAP_TEMPSOFF_MASK                    (1 << 12)
-#define OMAP4430_SINGLE_MODE_SHIFT                     10
-#define OMAP4430_SINGLE_MODE_MASK                      (1 << 10)
-#define OMAP4430_BGAP_TEMP_SENSOR_SOC_SHIFT            9
-#define OMAP4430_BGAP_TEMP_SENSOR_SOC_MASK             (1 << 9)
-#define OMAP4430_BGAP_TEMP_SENSOR_EOCZ_SHIFT           8
-#define OMAP4430_BGAP_TEMP_SENSOR_EOCZ_MASK            (1 << 8)
-#define OMAP4430_BGAP_TEMP_SENSOR_DTEMP_SHIFT          0
-#define OMAP4430_BGAP_TEMP_SENSOR_DTEMP_MASK           (0xff << 0)
-
-#define OMAP4430_ADC_START_VALUE                       0
-#define OMAP4430_ADC_END_VALUE                         127
-#define OMAP4430_MAX_FREQ                              32768
-#define OMAP4430_MIN_FREQ                              32768
-#define OMAP4430_MIN_TEMP                              -40000
-#define OMAP4430_MAX_TEMP                              125000
-#define OMAP4430_HYST_VAL                              5000
-
-/* TEMP_SENSOR OMAP4460 */
-#define OMAP4460_BGAP_TEMPSOFF_SHIFT                   13
-#define OMAP4460_BGAP_TEMPSOFF_MASK                    (1 << 13)
-#define OMAP4460_BGAP_TEMP_SENSOR_SOC_SHIFT            11
-#define OMAP4460_BGAP_TEMP_SENSOR_SOC_MASK             (1 << 11)
-#define OMAP4460_BGAP_TEMP_SENSOR_EOCZ_SHIFT           10
-#define OMAP4460_BGAP_TEMP_SENSOR_EOCZ_MASK            (1 << 10)
-#define OMAP4460_BGAP_TEMP_SENSOR_DTEMP_SHIFT          0
-#define OMAP4460_BGAP_TEMP_SENSOR_DTEMP_MASK           (0x3ff << 0)
-
-/* BANDGAP_CTRL */
-#define OMAP4460_SINGLE_MODE_SHIFT                     31
-#define OMAP4460_SINGLE_MODE_MASK                      (1 << 31)
-#define OMAP4460_MASK_HOT_SHIFT                                1
-#define OMAP4460_MASK_HOT_MASK                         (1 << 1)
-#define OMAP4460_MASK_COLD_SHIFT                       0
-#define OMAP4460_MASK_COLD_MASK                                (1 << 0)
-
-/* BANDGAP_COUNTER */
-#define OMAP4460_COUNTER_SHIFT                         0
-#define OMAP4460_COUNTER_MASK                          (0xffffff << 0)
-
-/* BANDGAP_THRESHOLD */
-#define OMAP4460_T_HOT_SHIFT                           16
-#define OMAP4460_T_HOT_MASK                            (0x3ff << 16)
-#define OMAP4460_T_COLD_SHIFT                          0
-#define OMAP4460_T_COLD_MASK                           (0x3ff << 0)
-
-/* TSHUT_THRESHOLD */
-#define OMAP4460_TSHUT_HOT_SHIFT                       16
-#define OMAP4460_TSHUT_HOT_MASK                                (0x3ff << 16)
-#define OMAP4460_TSHUT_COLD_SHIFT                      0
-#define OMAP4460_TSHUT_COLD_MASK                       (0x3ff << 0)
-
-/* BANDGAP_STATUS */
-#define OMAP4460_CLEAN_STOP_SHIFT                      3
-#define OMAP4460_CLEAN_STOP_MASK                       (1 << 3)
-#define OMAP4460_BGAP_ALERT_SHIFT                      2
-#define OMAP4460_BGAP_ALERT_MASK                       (1 << 2)
-#define OMAP4460_HOT_FLAG_SHIFT                                1
-#define OMAP4460_HOT_FLAG_MASK                         (1 << 1)
-#define OMAP4460_COLD_FLAG_SHIFT                       0
-#define OMAP4460_COLD_FLAG_MASK                                (1 << 0)
-
-/* TEMP_SENSOR OMAP5430 */
-#define OMAP5430_BGAP_TEMP_SENSOR_SOC_SHIFT            12
-#define OMAP5430_BGAP_TEMP_SENSOR_SOC_MASK             (1 << 12)
-#define OMAP5430_BGAP_TEMPSOFF_SHIFT                   11
-#define OMAP5430_BGAP_TEMPSOFF_MASK                    (1 << 11)
-#define OMAP5430_BGAP_TEMP_SENSOR_EOCZ_SHIFT           10
-#define OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK            (1 << 10)
-#define OMAP5430_BGAP_TEMP_SENSOR_DTEMP_SHIFT          0
-#define OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK           (0x3ff << 0)
-
-/* BANDGAP_CTRL */
-#define OMAP5430_MASK_HOT_CORE_SHIFT                   5
-#define OMAP5430_MASK_HOT_CORE_MASK                    (1 << 5)
-#define OMAP5430_MASK_COLD_CORE_SHIFT                  4
-#define OMAP5430_MASK_COLD_CORE_MASK                   (1 << 4)
-#define OMAP5430_MASK_HOT_MM_SHIFT                     3
-#define OMAP5430_MASK_HOT_MM_MASK                      (1 << 3)
-#define OMAP5430_MASK_COLD_MM_SHIFT                    2
-#define OMAP5430_MASK_COLD_MM_MASK                     (1 << 2)
-#define OMAP5430_MASK_HOT_MPU_SHIFT                    1
-#define OMAP5430_MASK_HOT_MPU_MASK                     (1 << 1)
-#define OMAP5430_MASK_COLD_MPU_SHIFT                   0
-#define OMAP5430_MASK_COLD_MPU_MASK                    (1 << 0)
-
-/* BANDGAP_COUNTER */
-#define OMAP5430_REPEAT_MODE_SHIFT                     31
-#define OMAP5430_REPEAT_MODE_MASK                      (1 << 31)
-#define OMAP5430_COUNTER_SHIFT                         0
-#define OMAP5430_COUNTER_MASK                          (0xffffff << 0)
-
-/* BANDGAP_THRESHOLD */
-#define OMAP5430_T_HOT_SHIFT                           16
-#define OMAP5430_T_HOT_MASK                            (0x3ff << 16)
-#define OMAP5430_T_COLD_SHIFT                          0
-#define OMAP5430_T_COLD_MASK                           (0x3ff << 0)
-
-/* TSHUT_THRESHOLD */
-#define OMAP5430_TSHUT_HOT_SHIFT                       16
-#define OMAP5430_TSHUT_HOT_MASK                                (0x3ff << 16)
-#define OMAP5430_TSHUT_COLD_SHIFT                      0
-#define OMAP5430_TSHUT_COLD_MASK                       (0x3ff << 0)
-
-/* BANDGAP_STATUS */
-#define OMAP5430_BGAP_ALERT_SHIFT                      31
-#define OMAP5430_BGAP_ALERT_MASK                       (1 << 31)
-#define OMAP5430_HOT_CORE_FLAG_SHIFT                   5
-#define OMAP5430_HOT_CORE_FLAG_MASK                    (1 << 5)
-#define OMAP5430_COLD_CORE_FLAG_SHIFT                  4
-#define OMAP5430_COLD_CORE_FLAG_MASK                   (1 << 4)
-#define OMAP5430_HOT_MM_FLAG_SHIFT                     3
-#define OMAP5430_HOT_MM_FLAG_MASK                      (1 << 3)
-#define OMAP5430_COLD_MM_FLAG_SHIFT                    2
-#define OMAP5430_COLD_MM_FLAG_MASK                     (1 << 2)
-#define OMAP5430_HOT_MPU_FLAG_SHIFT                    1
-#define OMAP5430_HOT_MPU_FLAG_MASK                     (1 << 1)
-#define OMAP5430_COLD_MPU_FLAG_SHIFT                   0
-#define OMAP5430_COLD_MPU_FLAG_MASK                    (1 << 0)
-
-/* Offsets from the base of temperature sensor registers */
-
-/* 4430 - All goes relative to OPP_BGAP */
-#define OMAP4430_FUSE_OPP_BGAP                         0x0
-#define OMAP4430_TEMP_SENSOR_CTRL_OFFSET               0xCC
-
-/* 4460 - All goes relative to OPP_BGAP */
-#define OMAP4460_FUSE_OPP_BGAP                         0x0
-#define OMAP4460_TEMP_SENSOR_CTRL_OFFSET               0xCC
-#define OMAP4460_BGAP_CTRL_OFFSET                      0x118
-#define OMAP4460_BGAP_COUNTER_OFFSET                   0x11C
-#define OMAP4460_BGAP_THRESHOLD_OFFSET                 0x120
-#define OMAP4460_BGAP_TSHUT_OFFSET                     0x124
-#define OMAP4460_BGAP_STATUS_OFFSET                    0x128
-
-/* 5430 - All goes relative to OPP_BGAP_GPU */
-#define OMAP5430_FUSE_OPP_BGAP_GPU                     0x0
-#define OMAP5430_TEMP_SENSOR_GPU_OFFSET                        0x150
-#define OMAP5430_BGAP_COUNTER_GPU_OFFSET               0x1C0
-#define OMAP5430_BGAP_THRESHOLD_GPU_OFFSET             0x1A8
-#define OMAP5430_BGAP_TSHUT_GPU_OFFSET                 0x1B4
-
-#define OMAP5430_FUSE_OPP_BGAP_MPU                     0x4
-#define OMAP5430_TEMP_SENSOR_MPU_OFFSET                        0x14C
-#define OMAP5430_BGAP_CTRL_OFFSET                      0x1A0
-#define OMAP5430_BGAP_COUNTER_MPU_OFFSET               0x1BC
-#define OMAP5430_BGAP_THRESHOLD_MPU_OFFSET             0x1A4
-#define OMAP5430_BGAP_TSHUT_MPU_OFFSET                 0x1B0
-#define OMAP5430_BGAP_STATUS_OFFSET                    0x1C8
-
-#define OMAP5430_FUSE_OPP_BGAP_CORE                    0x8
-#define OMAP5430_TEMP_SENSOR_CORE_OFFSET               0x154
-#define OMAP5430_BGAP_COUNTER_CORE_OFFSET              0x1C4
-#define OMAP5430_BGAP_THRESHOLD_CORE_OFFSET            0x1AC
-#define OMAP5430_BGAP_TSHUT_CORE_OFFSET                        0x1B8
-
-#define OMAP4460_TSHUT_HOT                             900     /* 122 deg C */
-#define OMAP4460_TSHUT_COLD                            895     /* 100 deg C */
-#define OMAP4460_T_HOT                                 800     /* 73 deg C */
-#define OMAP4460_T_COLD                                        795     /* 71 deg C */
-#define OMAP4460_MAX_FREQ                              1500000
-#define OMAP4460_MIN_FREQ                              1000000
-#define OMAP4460_MIN_TEMP                              -40000
-#define OMAP4460_MAX_TEMP                              123000
-#define OMAP4460_HYST_VAL                              5000
-#define OMAP4460_ADC_START_VALUE                       530
-#define OMAP4460_ADC_END_VALUE                         932
-
-#define OMAP5430_MPU_TSHUT_HOT                         915
-#define OMAP5430_MPU_TSHUT_COLD                                900
-#define OMAP5430_MPU_T_HOT                             800
-#define OMAP5430_MPU_T_COLD                            795
-#define OMAP5430_MPU_MAX_FREQ                          1500000
-#define OMAP5430_MPU_MIN_FREQ                          1000000
-#define OMAP5430_MPU_MIN_TEMP                          -40000
-#define OMAP5430_MPU_MAX_TEMP                          125000
-#define OMAP5430_MPU_HYST_VAL                          5000
-#define OMAP5430_ADC_START_VALUE                       532
-#define OMAP5430_ADC_END_VALUE                         934
-
-
-#define OMAP5430_GPU_TSHUT_HOT                         915
-#define OMAP5430_GPU_TSHUT_COLD                                900
-#define OMAP5430_GPU_T_HOT                             800
-#define OMAP5430_GPU_T_COLD                            795
-#define OMAP5430_GPU_MAX_FREQ                          1500000
-#define OMAP5430_GPU_MIN_FREQ                          1000000
-#define OMAP5430_GPU_MIN_TEMP                          -40000
-#define OMAP5430_GPU_MAX_TEMP                          125000
-#define OMAP5430_GPU_HYST_VAL                          5000
-
-#define OMAP5430_CORE_TSHUT_HOT                                915
-#define OMAP5430_CORE_TSHUT_COLD                       900
-#define OMAP5430_CORE_T_HOT                            800
-#define OMAP5430_CORE_T_COLD                           795
-#define OMAP5430_CORE_MAX_FREQ                         1500000
-#define OMAP5430_CORE_MIN_FREQ                         1000000
-#define OMAP5430_CORE_MIN_TEMP                         -40000
-#define OMAP5430_CORE_MAX_TEMP                         125000
-#define OMAP5430_CORE_HYST_VAL                         5000
-
-/**
- * The register offsets and bit fields might change across
- * OMAP versions hence populating them in this structure.
- */
-
-struct temp_sensor_registers {
-       u32     temp_sensor_ctrl;
-       u32     bgap_tempsoff_mask;
-       u32     bgap_soc_mask;
-       u32     bgap_eocz_mask;
-       u32     bgap_dtemp_mask;
-
-       u32     bgap_mask_ctrl;
-       u32     mask_hot_mask;
-       u32     mask_cold_mask;
-
-       u32     bgap_mode_ctrl;
-       u32     mode_ctrl_mask;
-
-       u32     bgap_counter;
-       u32     counter_mask;
-
-       u32     bgap_threshold;
-       u32     threshold_thot_mask;
-       u32     threshold_tcold_mask;
-
-       u32     tshut_threshold;
-       u32     tshut_hot_mask;
-       u32     tshut_cold_mask;
-
-       u32     bgap_status;
-       u32     status_clean_stop_mask;
-       u32     status_bgap_alert_mask;
-       u32     status_hot_mask;
-       u32     status_cold_mask;
-
-       u32     bgap_efuse;
-};
-
-/**
- * The thresholds and limits for temperature sensors.
- */
-struct temp_sensor_data {
-       u32     tshut_hot;
-       u32     tshut_cold;
-       u32     t_hot;
-       u32     t_cold;
-       u32     min_freq;
-       u32     max_freq;
-       int     max_temp;
-       int     min_temp;
-       int     hyst_val;
-       u32     adc_start_val;
-       u32     adc_end_val;
-       u32     update_int1;
-       u32     update_int2;
-};
-
-struct omap_bandgap_data;
-
-/**
- * struct omap_bandgap - bandgap device structure
- * @dev: device pointer
- * @conf: platform data with sensor data
- * @fclock: pointer to functional clock of temperature sensor
- * @div_clk: pointer to parent clock of temperature sensor fclk
- * @conv_table: Pointer to adc to temperature conversion table
- * @bg_mutex: Mutex for sysfs, irq and PM
- * @irq: MPU Irq number for thermal alert
- * @tshut_gpio: GPIO where Tshut signal is routed
- * @clk_rate: Holds current clock rate
- */
-struct omap_bandgap {
-       struct device                   *dev;
-       void __iomem                    *base;
-       struct omap_bandgap_data        *conf;
-       struct clk                      *fclock;
-       struct clk                      *div_clk;
-       const int                       *conv_table;
-       struct mutex                    bg_mutex; /* Mutex for irq and PM */
-       int                             irq;
-       int                             tshut_gpio;
-       u32                             clk_rate;
-};
-
-/**
- * struct temp_sensor_regval - temperature sensor register values
- * @bg_mode_ctrl: temp sensor control register value
- * @bg_ctrl: bandgap ctrl register value
- * @bg_counter: bandgap counter value
- * @bg_threshold: bandgap threshold register value
- * @tshut_threshold: bandgap tshut register value
- */
-struct temp_sensor_regval {
-       u32                     bg_mode_ctrl;
-       u32                     bg_ctrl;
-       u32                     bg_counter;
-       u32                     bg_threshold;
-       u32                     tshut_threshold;
-};
-
-/**
- * struct omap_temp_sensor - bandgap temperature sensor platform data
- * @ts_data: pointer to struct with thresholds, limits of temperature sensor
- * @registers: pointer to the list of register offsets and bitfields
- * @regval: temperature sensor register values
- * @domain: the name of the domain where the sensor is located
- * @cooling_data: description on how the zone should be cooled off.
- * @slope: sensor gradient slope info for hotspot extrapolation
- * @const: sensor gradient const info for hotspot extrapolation
- * @slope_pcb: sensor gradient slope info for hotspot extrapolation
- *             with no external influence
- * @const_pcb: sensor gradient const info for hotspot extrapolation
- *             with no external influence
- * @data: private data
- * @register_cooling: function to describe how this sensor is going to be cooled
- * @unregister_cooling: function to release cooling data
- */
-struct omap_temp_sensor {
-       struct temp_sensor_data         *ts_data;
-       struct temp_sensor_registers    *registers;
-       struct temp_sensor_regval       regval;
-       char                            *domain;
-       /* for hotspot extrapolation */
-       const int                       slope;
-       const int                       constant;
-       const int                       slope_pcb;
-       const int                       constant_pcb;
-       void                            *data;
-       int (*register_cooling)(struct omap_bandgap *bg_ptr, int id);
-       int (*unregister_cooling)(struct omap_bandgap *bg_ptr, int id);
-};
-
-/**
- * struct omap_bandgap_data - bandgap platform data structure
- * @features: a bitwise flag set to describe the device features
- * @conv_table: Pointer to adc to temperature conversion table
- * @fclock_name: clock name of the functional clock
- * @div_ck_nme: clock name of the clock divisor
- * @sensor_count: count of temperature sensor device in scm
- * @sensors: array of sensors present in this bandgap instance
- * @expose_sensor: callback to export sensor to thermal API
- */
-struct omap_bandgap_data {
-#define OMAP_BANDGAP_FEATURE_TSHUT             (1 << 0)
-#define OMAP_BANDGAP_FEATURE_TSHUT_CONFIG      (1 << 1)
-#define OMAP_BANDGAP_FEATURE_TALERT            (1 << 2)
-#define OMAP_BANDGAP_FEATURE_MODE_CONFIG       (1 << 3)
-#define OMAP_BANDGAP_FEATURE_COUNTER           (1 << 4)
-#define OMAP_BANDGAP_FEATURE_POWER_SWITCH      (1 << 5)
-#define OMAP_BANDGAP_HAS(b, f)                 \
-                       ((b)->conf->features & OMAP_BANDGAP_FEATURE_ ## f)
-       unsigned int                    features;
-       const int                       *conv_table;
-       char                            *fclock_name;
-       char                            *div_ck_name;
-       int                             sensor_count;
-       int (*report_temperature)(struct omap_bandgap *bg_ptr, int id);
-       int (*expose_sensor)(struct omap_bandgap *bg_ptr, int id, char *domain);
-       int (*remove_sensor)(struct omap_bandgap *bg_ptr, int id);
-
-       /* this needs to be at the end */
-       struct omap_temp_sensor         sensors[];
-};
-
-int omap_bandgap_read_thot(struct omap_bandgap *bg_ptr, int id, int *thot);
-int omap_bandgap_write_thot(struct omap_bandgap *bg_ptr, int id, int val);
-int omap_bandgap_read_tcold(struct omap_bandgap *bg_ptr, int id, int *tcold);
-int omap_bandgap_write_tcold(struct omap_bandgap *bg_ptr, int id, int val);
-int omap_bandgap_read_update_interval(struct omap_bandgap *bg_ptr, int id,
-                                     int *interval);
-int omap_bandgap_write_update_interval(struct omap_bandgap *bg_ptr, int id,
-                                      u32 interval);
-int omap_bandgap_read_temperature(struct omap_bandgap *bg_ptr, int id,
-                                 int *temperature);
-int omap_bandgap_set_sensor_data(struct omap_bandgap *bg_ptr, int id,
-                                void *data);
-void *omap_bandgap_get_sensor_data(struct omap_bandgap *bg_ptr, int id);
-
-#ifdef CONFIG_OMAP4_THERMAL
-extern const struct omap_bandgap_data omap4430_data;
-extern const struct omap_bandgap_data omap4460_data;
-extern const struct omap_bandgap_data omap4470_data;
-#else
-#define omap4430_data                                  NULL
-#define omap4460_data                                  NULL
-#define omap4470_data                                  NULL
-#endif
-
-#ifdef CONFIG_OMAP5_THERMAL
-extern const struct omap_bandgap_data omap5430_data;
-#else
-#define omap5430_data                                  NULL
-#endif
-
-#endif
diff --git a/drivers/staging/omap-thermal/omap-thermal-common.c b/drivers/staging/omap-thermal/omap-thermal-common.c
deleted file mode 100644 (file)
index 79a55aa..0000000
+++ /dev/null
@@ -1,338 +0,0 @@
-/*
- * OMAP thermal driver interface
- *
- * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
- * Contact:
- *   Eduardo Valentin <eduardo.valentin@ti.com>
- *
- * 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.
- *
- * 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 St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/device.h>
-#include <linux/err.h>
-#include <linux/mutex.h>
-#include <linux/gfp.h>
-#include <linux/kernel.h>
-#include <linux/workqueue.h>
-#include <linux/thermal.h>
-#include <linux/cpufreq.h>
-#include <linux/cpumask.h>
-#include <linux/cpu_cooling.h>
-
-#include "omap-thermal.h"
-#include "omap-bandgap.h"
-
-/* common data structures */
-struct omap_thermal_data {
-       struct thermal_zone_device *omap_thermal;
-       struct thermal_cooling_device *cool_dev;
-       struct omap_bandgap *bg_ptr;
-       enum thermal_device_mode mode;
-       struct work_struct thermal_wq;
-       int sensor_id;
-};
-
-static void omap_thermal_work(struct work_struct *work)
-{
-       struct omap_thermal_data *data = container_of(work,
-                                       struct omap_thermal_data, thermal_wq);
-
-       thermal_zone_device_update(data->omap_thermal);
-
-       dev_dbg(&data->omap_thermal->device, "updated thermal zone %s\n",
-               data->omap_thermal->type);
-}
-
-/**
- * omap_thermal_hotspot_temperature - returns sensor extrapolated temperature
- * @t: omap sensor temperature
- * @s: omap sensor slope value
- * @c: omap sensor const value
- */
-static inline int omap_thermal_hotspot_temperature(int t, int s, int c)
-{
-       int delta = t * s / 1000 + c;
-
-       if (delta < 0)
-               delta = 0;
-
-       return t + delta;
-}
-
-/* thermal zone ops */
-/* Get temperature callback function for thermal zone*/
-static inline int omap_thermal_get_temp(struct thermal_zone_device *thermal,
-                                        unsigned long *temp)
-{
-       struct omap_thermal_data *data = thermal->devdata;
-       struct omap_bandgap *bg_ptr;
-       struct omap_temp_sensor *s;
-       int ret, tmp, pcb_temp, slope, constant;
-
-       if (!data)
-               return 0;
-
-       bg_ptr = data->bg_ptr;
-       s = &bg_ptr->conf->sensors[data->sensor_id];
-
-       ret = omap_bandgap_read_temperature(bg_ptr, data->sensor_id, &tmp);
-       if (ret)
-               return ret;
-
-       pcb_temp = 0;
-       /* TODO: Introduce pcb temperature lookup */
-       /* In case pcb zone is available, use the extrapolation rule with it */
-       if (pcb_temp) {
-               tmp -= pcb_temp;
-               slope = s->slope_pcb;
-               constant = s->constant_pcb;
-       } else {
-               slope = s->slope;
-               constant = s->constant;
-       }
-       *temp = omap_thermal_hotspot_temperature(tmp, slope, constant);
-
-       return ret;
-}
-
-/* Bind callback functions for thermal zone */
-static int omap_thermal_bind(struct thermal_zone_device *thermal,
-                             struct thermal_cooling_device *cdev)
-{
-       struct omap_thermal_data *data = thermal->devdata;
-       int id;
-
-       if (IS_ERR_OR_NULL(data))
-               return -ENODEV;
-
-       /* check if this is the cooling device we registered */
-       if (data->cool_dev != cdev)
-               return 0;
-
-       id = data->sensor_id;
-
-       /* TODO: bind with min and max states */
-       /* Simple thing, two trips, one passive another critical */
-       return thermal_zone_bind_cooling_device(thermal, 0, cdev,
-                                               THERMAL_NO_LIMIT,
-                                               THERMAL_NO_LIMIT);
-}
-
-/* Unbind callback functions for thermal zone */
-static int omap_thermal_unbind(struct thermal_zone_device *thermal,
-                               struct thermal_cooling_device *cdev)
-{
-       struct omap_thermal_data *data = thermal->devdata;
-
-       if (IS_ERR_OR_NULL(data))
-               return -ENODEV;
-
-       /* check if this is the cooling device we registered */
-       if (data->cool_dev != cdev)
-               return 0;
-
-       /* Simple thing, two trips, one passive another critical */
-       return thermal_zone_unbind_cooling_device(thermal, 0, cdev);
-}
-
-/* Get mode callback functions for thermal zone */
-static int omap_thermal_get_mode(struct thermal_zone_device *thermal,
-                                 enum thermal_device_mode *mode)
-{
-       struct omap_thermal_data *data = thermal->devdata;
-
-       if (data)
-               *mode = data->mode;
-
-       return 0;
-}
-
-/* Set mode callback functions for thermal zone */
-static int omap_thermal_set_mode(struct thermal_zone_device *thermal,
-                                 enum thermal_device_mode mode)
-{
-       struct omap_thermal_data *data = thermal->devdata;
-
-       if (!data->omap_thermal) {
-               dev_notice(&thermal->device, "thermal zone not registered\n");
-               return 0;
-       }
-
-       mutex_lock(&data->omap_thermal->lock);
-
-       if (mode == THERMAL_DEVICE_ENABLED)
-               data->omap_thermal->polling_delay = FAST_TEMP_MONITORING_RATE;
-       else
-               data->omap_thermal->polling_delay = 0;
-
-       mutex_unlock(&data->omap_thermal->lock);
-
-       data->mode = mode;
-       thermal_zone_device_update(data->omap_thermal);
-       dev_dbg(&thermal->device, "thermal polling set for duration=%d msec\n",
-               data->omap_thermal->polling_delay);
-
-       return 0;
-}
-
-/* Get trip type callback functions for thermal zone */
-static int omap_thermal_get_trip_type(struct thermal_zone_device *thermal,
-                                      int trip, enum thermal_trip_type *type)
-{
-       if (!omap_thermal_is_valid_trip(trip))
-               return -EINVAL;
-
-       if (trip + 1 == OMAP_TRIP_NUMBER)
-               *type = THERMAL_TRIP_CRITICAL;
-       else
-               *type = THERMAL_TRIP_PASSIVE;
-
-       return 0;
-}
-
-/* Get trip temperature callback functions for thermal zone */
-static int omap_thermal_get_trip_temp(struct thermal_zone_device *thermal,
-                                      int trip, unsigned long *temp)
-{
-       if (!omap_thermal_is_valid_trip(trip))
-               return -EINVAL;
-
-       *temp = omap_thermal_get_trip_value(trip);
-
-       return 0;
-}
-
-/* Get critical temperature callback functions for thermal zone */
-static int omap_thermal_get_crit_temp(struct thermal_zone_device *thermal,
-                                      unsigned long *temp)
-{
-       /* shutdown zone */
-       return omap_thermal_get_trip_temp(thermal, OMAP_TRIP_NUMBER - 1, temp);
-}
-
-static struct thermal_zone_device_ops omap_thermal_ops = {
-       .get_temp = omap_thermal_get_temp,
-       /* TODO: add .get_trend */
-       .bind = omap_thermal_bind,
-       .unbind = omap_thermal_unbind,
-       .get_mode = omap_thermal_get_mode,
-       .set_mode = omap_thermal_set_mode,
-       .get_trip_type = omap_thermal_get_trip_type,
-       .get_trip_temp = omap_thermal_get_trip_temp,
-       .get_crit_temp = omap_thermal_get_crit_temp,
-};
-
-static struct omap_thermal_data
-*omap_thermal_build_data(struct omap_bandgap *bg_ptr, int id)
-{
-       struct omap_thermal_data *data;
-
-       data = devm_kzalloc(bg_ptr->dev, sizeof(*data), GFP_KERNEL);
-       if (!data) {
-               dev_err(bg_ptr->dev, "kzalloc fail\n");
-               return NULL;
-       }
-       data->sensor_id = id;
-       data->bg_ptr = bg_ptr;
-       data->mode = THERMAL_DEVICE_ENABLED;
-       INIT_WORK(&data->thermal_wq, omap_thermal_work);
-
-       return data;
-}
-
-int omap_thermal_expose_sensor(struct omap_bandgap *bg_ptr, int id,
-                              char *domain)
-{
-       struct omap_thermal_data *data;
-
-       data = omap_bandgap_get_sensor_data(bg_ptr, id);
-
-       if (IS_ERR(data))
-               data = omap_thermal_build_data(bg_ptr, id);
-
-       if (!data)
-               return -EINVAL;
-
-       /* TODO: remove TC1 TC2 */
-       /* Create thermal zone */
-       data->omap_thermal = thermal_zone_device_register(domain,
-                               OMAP_TRIP_NUMBER, 0, data, &omap_thermal_ops,
-                               NULL, FAST_TEMP_MONITORING_RATE,
-                               FAST_TEMP_MONITORING_RATE);
-       if (IS_ERR_OR_NULL(data->omap_thermal)) {
-               dev_err(bg_ptr->dev, "thermal zone device is NULL\n");
-               return PTR_ERR(data->omap_thermal);
-       }
-       data->omap_thermal->polling_delay = FAST_TEMP_MONITORING_RATE;
-       omap_bandgap_set_sensor_data(bg_ptr, id, data);
-
-       return 0;
-}
-
-int omap_thermal_remove_sensor(struct omap_bandgap *bg_ptr, int id)
-{
-       struct omap_thermal_data *data;
-
-       data = omap_bandgap_get_sensor_data(bg_ptr, id);
-
-       thermal_zone_device_unregister(data->omap_thermal);
-
-       return 0;
-}
-
-int omap_thermal_report_sensor_temperature(struct omap_bandgap *bg_ptr, int id)
-{
-       struct omap_thermal_data *data;
-
-       data = omap_bandgap_get_sensor_data(bg_ptr, id);
-
-       schedule_work(&data->thermal_wq);
-
-       return 0;
-}
-
-int omap_thermal_register_cpu_cooling(struct omap_bandgap *bg_ptr, int id)
-{
-       struct omap_thermal_data *data;
-
-       data = omap_bandgap_get_sensor_data(bg_ptr, id);
-       if (IS_ERR(data))
-               data = omap_thermal_build_data(bg_ptr, id);
-
-       if (!data)
-               return -EINVAL;
-
-       /* Register cooling device */
-       data->cool_dev = cpufreq_cooling_register(cpu_present_mask);
-       if (IS_ERR_OR_NULL(data->cool_dev)) {
-               dev_err(bg_ptr->dev,
-                       "Failed to register cpufreq cooling device\n");
-               return PTR_ERR(data->cool_dev);
-       }
-       omap_bandgap_set_sensor_data(bg_ptr, id, data);
-
-       return 0;
-}
-
-int omap_thermal_unregister_cpu_cooling(struct omap_bandgap *bg_ptr, int id)
-{
-       struct omap_thermal_data *data;
-
-       data = omap_bandgap_get_sensor_data(bg_ptr, id);
-       cpufreq_cooling_unregister(data->cool_dev);
-
-       return 0;
-}
diff --git a/drivers/staging/omap-thermal/omap-thermal.h b/drivers/staging/omap-thermal/omap-thermal.h
deleted file mode 100644 (file)
index 0dd2184..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * OMAP thermal definitions
- *
- * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
- * Contact:
- *   Eduardo Valentin <eduardo.valentin@ti.com>
- *
- * 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.
- *
- * 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 St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-#ifndef __OMAP_THERMAL_H
-#define __OMAP_THERMAL_H
-
-#include "omap-bandgap.h"
-
-/* sensors gradient and offsets */
-#define OMAP_GRADIENT_SLOPE_4460                               348
-#define OMAP_GRADIENT_CONST_4460                               -9301
-#define OMAP_GRADIENT_SLOPE_4470                               308
-#define OMAP_GRADIENT_CONST_4470                               -7896
-
-#define OMAP_GRADIENT_SLOPE_5430_CPU                           196
-#define OMAP_GRADIENT_CONST_5430_CPU                           -6822
-#define OMAP_GRADIENT_SLOPE_5430_GPU                           64
-#define OMAP_GRADIENT_CONST_5430_GPU                           978
-
-/* PCB sensor calculation constants */
-#define OMAP_GRADIENT_SLOPE_W_PCB_4460                         1142
-#define OMAP_GRADIENT_CONST_W_PCB_4460                         -393
-#define OMAP_GRADIENT_SLOPE_W_PCB_4470                         1063
-#define OMAP_GRADIENT_CONST_W_PCB_4470                         -477
-
-#define OMAP_GRADIENT_SLOPE_W_PCB_5430_CPU                     469
-#define OMAP_GRADIENT_CONST_W_PCB_5430_CPU                     -1272
-#define OMAP_GRADIENT_SLOPE_W_PCB_5430_GPU                     378
-#define OMAP_GRADIENT_CONST_W_PCB_5430_GPU                     154
-
-/* trip points of interest in milicelsius (at hotspot level) */
-#define OMAP_TRIP_COLD                                         100000
-#define OMAP_TRIP_HOT                                          110000
-#define OMAP_TRIP_SHUTDOWN                                     125000
-#define OMAP_TRIP_NUMBER                                       2
-#define OMAP_TRIP_STEP                                                 \
-       ((OMAP_TRIP_SHUTDOWN - OMAP_TRIP_HOT) / (OMAP_TRIP_NUMBER - 1))
-
-/* Update rates */
-#define FAST_TEMP_MONITORING_RATE                              250
-
-/* helper macros */
-/**
- * omap_thermal_get_trip_value - returns trip temperature based on index
- * @i: trip index
- */
-#define omap_thermal_get_trip_value(i)                                 \
-       (OMAP_TRIP_HOT + ((i) * OMAP_TRIP_STEP))
-
-/**
- * omap_thermal_is_valid_trip - check for trip index
- * @i: trip index
- */
-#define omap_thermal_is_valid_trip(trip)                               \
-       ((trip) >= 0 && (trip) < OMAP_TRIP_NUMBER)
-
-#ifdef CONFIG_OMAP_THERMAL
-int omap_thermal_expose_sensor(struct omap_bandgap *bg_ptr, int id,
-                              char *domain);
-int omap_thermal_remove_sensor(struct omap_bandgap *bg_ptr, int id);
-int omap_thermal_register_cpu_cooling(struct omap_bandgap *bg_ptr, int id);
-int omap_thermal_unregister_cpu_cooling(struct omap_bandgap *bg_ptr, int id);
-#else
-static inline
-int omap_thermal_expose_sensor(struct omap_bandgap *bg_ptr, int id,
-                              char *domain)
-{
-       return 0;
-}
-
-static inline
-int omap_thermal_remove_sensor(struct omap_bandgap *bg_ptr, int id)
-{
-       return 0;
-}
-
-static inline
-int omap_thermal_register_cpu_cooling(struct omap_bandgap *bg_ptr, int id)
-{
-       return 0;
-}
-
-static inline
-int omap_thermal_unregister_cpu_cooling(struct omap_bandgap *bg_ptr, int id)
-{
-       return 0;
-}
-#endif
-#endif
diff --git a/drivers/staging/omap-thermal/omap4-thermal.c b/drivers/staging/omap-thermal/omap4-thermal.c
deleted file mode 100644 (file)
index 04c02b6..0000000
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * OMAP4 thermal driver.
- *
- * Copyright (C) 2011-2012 Texas Instruments Inc.
- * Contact:
- *     Eduardo Valentin <eduardo.valentin@ti.com>
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * 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 "omap-thermal.h"
-#include "omap-bandgap.h"
-
-/*
- * OMAP4430 has one instance of thermal sensor for MPU
- * need to describe the individual bit fields
- */
-static struct temp_sensor_registers
-omap4430_mpu_temp_sensor_registers = {
-       .temp_sensor_ctrl = OMAP4430_TEMP_SENSOR_CTRL_OFFSET,
-       .bgap_tempsoff_mask = OMAP4430_BGAP_TEMPSOFF_MASK,
-       .bgap_soc_mask = OMAP4430_BGAP_TEMP_SENSOR_SOC_MASK,
-       .bgap_eocz_mask = OMAP4430_BGAP_TEMP_SENSOR_EOCZ_MASK,
-       .bgap_dtemp_mask = OMAP4430_BGAP_TEMP_SENSOR_DTEMP_MASK,
-
-       .bgap_mode_ctrl = OMAP4430_TEMP_SENSOR_CTRL_OFFSET,
-       .mode_ctrl_mask = OMAP4430_SINGLE_MODE_MASK,
-
-       .bgap_efuse = OMAP4430_FUSE_OPP_BGAP,
-};
-
-/* Thresholds and limits for OMAP4430 MPU temperature sensor */
-static struct temp_sensor_data omap4430_mpu_temp_sensor_data = {
-       .min_freq = OMAP4430_MIN_FREQ,
-       .max_freq = OMAP4430_MAX_FREQ,
-       .max_temp = OMAP4430_MAX_TEMP,
-       .min_temp = OMAP4430_MIN_TEMP,
-       .hyst_val = OMAP4430_HYST_VAL,
-       .adc_start_val = OMAP4430_ADC_START_VALUE,
-       .adc_end_val = OMAP4430_ADC_END_VALUE,
-};
-
-/*
- * Temperature values in milli degree celsius
- * ADC code values from 530 to 923
- */
-static const int
-omap4430_adc_to_temp[OMAP4430_ADC_END_VALUE - OMAP4430_ADC_START_VALUE + 1] = {
-       -38000, -35000, -34000, -32000, -30000, -28000, -26000, -24000, -22000,
-       -20000, -18000, -17000, -15000, -13000, -12000, -10000, -8000, -6000,
-       -5000, -3000, -1000, 0, 2000, 3000, 5000, 6000, 8000, 10000, 12000,
-       13000, 15000, 17000, 19000, 21000, 23000, 25000, 27000, 28000, 30000,
-       32000, 33000, 35000, 37000, 38000, 40000, 42000, 43000, 45000, 47000,
-       48000, 50000, 52000, 53000, 55000, 57000, 58000, 60000, 62000, 64000,
-       66000, 68000, 70000, 71000, 73000, 75000, 77000, 78000, 80000, 82000,
-       83000, 85000, 87000, 88000, 90000, 92000, 93000, 95000, 97000, 98000,
-       100000, 102000, 103000, 105000, 107000, 109000, 111000, 113000, 115000,
-       117000, 118000, 120000, 122000, 123000,
-};
-
-/* OMAP4430 data */
-const struct omap_bandgap_data omap4430_data = {
-       .features = OMAP_BANDGAP_FEATURE_MODE_CONFIG |
-                       OMAP_BANDGAP_FEATURE_POWER_SWITCH,
-       .fclock_name = "bandgap_fclk",
-       .div_ck_name = "bandgap_fclk",
-       .conv_table = omap4430_adc_to_temp,
-       .expose_sensor = omap_thermal_expose_sensor,
-       .remove_sensor = omap_thermal_remove_sensor,
-       .sensors = {
-               {
-               .registers = &omap4430_mpu_temp_sensor_registers,
-               .ts_data = &omap4430_mpu_temp_sensor_data,
-               .domain = "cpu",
-               .slope = 0,
-               .constant = 20000,
-               .slope_pcb = 0,
-               .constant_pcb = 20000,
-               .register_cooling = omap_thermal_register_cpu_cooling,
-               .unregister_cooling = omap_thermal_unregister_cpu_cooling,
-               },
-       },
-       .sensor_count = 1,
-};
-/*
- * OMAP4460 has one instance of thermal sensor for MPU
- * need to describe the individual bit fields
- */
-static struct temp_sensor_registers
-omap4460_mpu_temp_sensor_registers = {
-       .temp_sensor_ctrl = OMAP4460_TEMP_SENSOR_CTRL_OFFSET,
-       .bgap_tempsoff_mask = OMAP4460_BGAP_TEMPSOFF_MASK,
-       .bgap_soc_mask = OMAP4460_BGAP_TEMP_SENSOR_SOC_MASK,
-       .bgap_eocz_mask = OMAP4460_BGAP_TEMP_SENSOR_EOCZ_MASK,
-       .bgap_dtemp_mask = OMAP4460_BGAP_TEMP_SENSOR_DTEMP_MASK,
-
-       .bgap_mask_ctrl = OMAP4460_BGAP_CTRL_OFFSET,
-       .mask_hot_mask = OMAP4460_MASK_HOT_MASK,
-       .mask_cold_mask = OMAP4460_MASK_COLD_MASK,
-
-       .bgap_mode_ctrl = OMAP4460_BGAP_CTRL_OFFSET,
-       .mode_ctrl_mask = OMAP4460_SINGLE_MODE_MASK,
-
-       .bgap_counter = OMAP4460_BGAP_COUNTER_OFFSET,
-       .counter_mask = OMAP4460_COUNTER_MASK,
-
-       .bgap_threshold = OMAP4460_BGAP_THRESHOLD_OFFSET,
-       .threshold_thot_mask = OMAP4460_T_HOT_MASK,
-       .threshold_tcold_mask = OMAP4460_T_COLD_MASK,
-
-       .tshut_threshold = OMAP4460_BGAP_TSHUT_OFFSET,
-       .tshut_hot_mask = OMAP4460_TSHUT_HOT_MASK,
-       .tshut_cold_mask = OMAP4460_TSHUT_COLD_MASK,
-
-       .bgap_status = OMAP4460_BGAP_STATUS_OFFSET,
-       .status_clean_stop_mask = OMAP4460_CLEAN_STOP_MASK,
-       .status_bgap_alert_mask = OMAP4460_BGAP_ALERT_MASK,
-       .status_hot_mask = OMAP4460_HOT_FLAG_MASK,
-       .status_cold_mask = OMAP4460_COLD_FLAG_MASK,
-
-       .bgap_efuse = OMAP4460_FUSE_OPP_BGAP,
-};
-
-/* Thresholds and limits for OMAP4460 MPU temperature sensor */
-static struct temp_sensor_data omap4460_mpu_temp_sensor_data = {
-       .tshut_hot = OMAP4460_TSHUT_HOT,
-       .tshut_cold = OMAP4460_TSHUT_COLD,
-       .t_hot = OMAP4460_T_HOT,
-       .t_cold = OMAP4460_T_COLD,
-       .min_freq = OMAP4460_MIN_FREQ,
-       .max_freq = OMAP4460_MAX_FREQ,
-       .max_temp = OMAP4460_MAX_TEMP,
-       .min_temp = OMAP4460_MIN_TEMP,
-       .hyst_val = OMAP4460_HYST_VAL,
-       .adc_start_val = OMAP4460_ADC_START_VALUE,
-       .adc_end_val = OMAP4460_ADC_END_VALUE,
-       .update_int1 = 1000,
-       .update_int2 = 2000,
-};
-
-/*
- * Temperature values in milli degree celsius
- * ADC code values from 530 to 923
- */
-static const int
-omap4460_adc_to_temp[OMAP4460_ADC_END_VALUE - OMAP4460_ADC_START_VALUE + 1] = {
-       -40000, -40000, -40000, -40000, -39800, -39400, -39000, -38600, -38200,
-       -37800, -37300, -36800, -36400, -36000, -35600, -35200, -34800,
-       -34300, -33800, -33400, -33000, -32600, -32200, -31800, -31300,
-       -30800, -30400, -30000, -29600, -29200, -28700, -28200, -27800,
-       -27400, -27000, -26600, -26200, -25700, -25200, -24800, -24400,
-       -24000, -23600, -23200, -22700, -22200, -21800, -21400, -21000,
-       -20600, -20200, -19700, -19200, -18800, -18400, -18000, -17600,
-       -17200, -16700, -16200, -15800, -15400, -15000, -14600, -14200,
-       -13700, -13200, -12800, -12400, -12000, -11600, -11200, -10700,
-       -10200, -9800, -9400, -9000, -8600, -8200, -7700, -7200, -6800,
-       -6400, -6000, -5600, -5200, -4800, -4300, -3800, -3400, -3000,
-       -2600, -2200, -1800, -1300, -800, -400, 0, 400, 800, 1200, 1600,
-       2100, 2600, 3000, 3400, 3800, 4200, 4600, 5100, 5600, 6000, 6400,
-       6800, 7200, 7600, 8000, 8500, 9000, 9400, 9800, 10200, 10600, 11000,
-       11400, 11900, 12400, 12800, 13200, 13600, 14000, 14400, 14800,
-       15300, 15800, 16200, 16600, 17000, 17400, 17800, 18200, 18700,
-       19200, 19600, 20000, 20400, 20800, 21200, 21600, 22100, 22600,
-       23000, 23400, 23800, 24200, 24600, 25000, 25400, 25900, 26400,
-       26800, 27200, 27600, 28000, 28400, 28800, 29300, 29800, 30200,
-       30600, 31000, 31400, 31800, 32200, 32600, 33100, 33600, 34000,
-       34400, 34800, 35200, 35600, 36000, 36400, 36800, 37300, 37800,
-       38200, 38600, 39000, 39400, 39800, 40200, 40600, 41100, 41600,
-       42000, 42400, 42800, 43200, 43600, 44000, 44400, 44800, 45300,
-       45800, 46200, 46600, 47000, 47400, 47800, 48200, 48600, 49000,
-       49500, 50000, 50400, 50800, 51200, 51600, 52000, 52400, 52800,
-       53200, 53700, 54200, 54600, 55000, 55400, 55800, 56200, 56600,
-       57000, 57400, 57800, 58200, 58700, 59200, 59600, 60000, 60400,
-       60800, 61200, 61600, 62000, 62400, 62800, 63300, 63800, 64200,
-       64600, 65000, 65400, 65800, 66200, 66600, 67000, 67400, 67800,
-       68200, 68700, 69200, 69600, 70000, 70400, 70800, 71200, 71600,
-       72000, 72400, 72800, 73200, 73600, 74100, 74600, 75000, 75400,
-       75800, 76200, 76600, 77000, 77400, 77800, 78200, 78600, 79000,
-       79400, 79800, 80300, 80800, 81200, 81600, 82000, 82400, 82800,
-       83200, 83600, 84000, 84400, 84800, 85200, 85600, 86000, 86400,
-       86800, 87300, 87800, 88200, 88600, 89000, 89400, 89800, 90200,
-       90600, 91000, 91400, 91800, 92200, 92600, 93000, 93400, 93800,
-       94200, 94600, 95000, 95500, 96000, 96400, 96800, 97200, 97600,
-       98000, 98400, 98800, 99200, 99600, 100000, 100400, 100800, 101200,
-       101600, 102000, 102400, 102800, 103200, 103600, 104000, 104400,
-       104800, 105200, 105600, 106100, 106600, 107000, 107400, 107800,
-       108200, 108600, 109000, 109400, 109800, 110200, 110600, 111000,
-       111400, 111800, 112200, 112600, 113000, 113400, 113800, 114200,
-       114600, 115000, 115400, 115800, 116200, 116600, 117000, 117400,
-       117800, 118200, 118600, 119000, 119400, 119800, 120200, 120600,
-       121000, 121400, 121800, 122200, 122600, 123000, 123400, 123800, 124200,
-       124600, 124900, 125000, 125000, 125000, 125000
-};
-
-/* OMAP4460 data */
-const struct omap_bandgap_data omap4460_data = {
-       .features = OMAP_BANDGAP_FEATURE_TSHUT |
-                       OMAP_BANDGAP_FEATURE_TSHUT_CONFIG |
-                       OMAP_BANDGAP_FEATURE_TALERT |
-                       OMAP_BANDGAP_FEATURE_MODE_CONFIG |
-                       OMAP_BANDGAP_FEATURE_POWER_SWITCH |
-                       OMAP_BANDGAP_FEATURE_COUNTER,
-       .fclock_name = "bandgap_ts_fclk",
-       .div_ck_name = "div_ts_ck",
-       .conv_table = omap4460_adc_to_temp,
-       .expose_sensor = omap_thermal_expose_sensor,
-       .remove_sensor = omap_thermal_remove_sensor,
-       .sensors = {
-               {
-               .registers = &omap4460_mpu_temp_sensor_registers,
-               .ts_data = &omap4460_mpu_temp_sensor_data,
-               .domain = "cpu",
-               .slope = OMAP_GRADIENT_SLOPE_4460,
-               .constant = OMAP_GRADIENT_CONST_4460,
-               .slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_4460,
-               .constant_pcb = OMAP_GRADIENT_CONST_W_PCB_4460,
-               .register_cooling = omap_thermal_register_cpu_cooling,
-               .unregister_cooling = omap_thermal_unregister_cpu_cooling,
-               },
-       },
-       .sensor_count = 1,
-};
-
-/* OMAP4470 data */
-const struct omap_bandgap_data omap4470_data = {
-       .features = OMAP_BANDGAP_FEATURE_TSHUT |
-                       OMAP_BANDGAP_FEATURE_TSHUT_CONFIG |
-                       OMAP_BANDGAP_FEATURE_TALERT |
-                       OMAP_BANDGAP_FEATURE_MODE_CONFIG |
-                       OMAP_BANDGAP_FEATURE_POWER_SWITCH |
-                       OMAP_BANDGAP_FEATURE_COUNTER,
-       .fclock_name = "bandgap_ts_fclk",
-       .div_ck_name = "div_ts_ck",
-       .conv_table = omap4460_adc_to_temp,
-       .expose_sensor = omap_thermal_expose_sensor,
-       .remove_sensor = omap_thermal_remove_sensor,
-       .sensors = {
-               {
-               .registers = &omap4460_mpu_temp_sensor_registers,
-               .ts_data = &omap4460_mpu_temp_sensor_data,
-               .domain = "cpu",
-               .slope = OMAP_GRADIENT_SLOPE_4470,
-               .constant = OMAP_GRADIENT_CONST_4470,
-               .slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_4470,
-               .constant_pcb = OMAP_GRADIENT_CONST_W_PCB_4470,
-               .register_cooling = omap_thermal_register_cpu_cooling,
-               .unregister_cooling = omap_thermal_unregister_cpu_cooling,
-               },
-       },
-       .sensor_count = 1,
-};
diff --git a/drivers/staging/omap-thermal/omap5-thermal.c b/drivers/staging/omap-thermal/omap5-thermal.c
deleted file mode 100644 (file)
index 2f3a498..0000000
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * OMAP5 thermal driver.
- *
- * Copyright (C) 2011-2012 Texas Instruments Inc.
- * Contact:
- *     Eduardo Valentin <eduardo.valentin@ti.com>
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * 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 "omap-bandgap.h"
-#include "omap-thermal.h"
-
-/*
- * omap5430 has one instance of thermal sensor for MPU
- * need to describe the individual bit fields
- */
-static struct temp_sensor_registers
-omap5430_mpu_temp_sensor_registers = {
-       .temp_sensor_ctrl = OMAP5430_TEMP_SENSOR_MPU_OFFSET,
-       .bgap_tempsoff_mask = OMAP5430_BGAP_TEMPSOFF_MASK,
-       .bgap_soc_mask = OMAP5430_BGAP_TEMP_SENSOR_SOC_MASK,
-       .bgap_eocz_mask = OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK,
-       .bgap_dtemp_mask = OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK,
-
-       .bgap_mask_ctrl = OMAP5430_BGAP_CTRL_OFFSET,
-       .mask_hot_mask = OMAP5430_MASK_HOT_MPU_MASK,
-       .mask_cold_mask = OMAP5430_MASK_COLD_MPU_MASK,
-
-       .bgap_mode_ctrl = OMAP5430_BGAP_COUNTER_MPU_OFFSET,
-       .mode_ctrl_mask = OMAP5430_REPEAT_MODE_MASK,
-
-       .bgap_counter = OMAP5430_BGAP_COUNTER_MPU_OFFSET,
-       .counter_mask = OMAP5430_COUNTER_MASK,
-
-       .bgap_threshold = OMAP5430_BGAP_THRESHOLD_MPU_OFFSET,
-       .threshold_thot_mask = OMAP5430_T_HOT_MASK,
-       .threshold_tcold_mask = OMAP5430_T_COLD_MASK,
-
-       .tshut_threshold = OMAP5430_BGAP_TSHUT_MPU_OFFSET,
-       .tshut_hot_mask = OMAP5430_TSHUT_HOT_MASK,
-       .tshut_cold_mask = OMAP5430_TSHUT_COLD_MASK,
-
-       .bgap_status = OMAP5430_BGAP_STATUS_OFFSET,
-       .status_clean_stop_mask = 0x0,
-       .status_bgap_alert_mask = OMAP5430_BGAP_ALERT_MASK,
-       .status_hot_mask = OMAP5430_HOT_MPU_FLAG_MASK,
-       .status_cold_mask = OMAP5430_COLD_MPU_FLAG_MASK,
-
-       .bgap_efuse = OMAP5430_FUSE_OPP_BGAP_MPU,
-};
-
-/*
- * omap5430 has one instance of thermal sensor for GPU
- * need to describe the individual bit fields
- */
-static struct temp_sensor_registers
-omap5430_gpu_temp_sensor_registers = {
-       .temp_sensor_ctrl = OMAP5430_TEMP_SENSOR_GPU_OFFSET,
-       .bgap_tempsoff_mask = OMAP5430_BGAP_TEMPSOFF_MASK,
-       .bgap_soc_mask = OMAP5430_BGAP_TEMP_SENSOR_SOC_MASK,
-       .bgap_eocz_mask = OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK,
-       .bgap_dtemp_mask = OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK,
-
-       .bgap_mask_ctrl = OMAP5430_BGAP_CTRL_OFFSET,
-       .mask_hot_mask = OMAP5430_MASK_HOT_MM_MASK,
-       .mask_cold_mask = OMAP5430_MASK_COLD_MM_MASK,
-
-       .bgap_mode_ctrl = OMAP5430_BGAP_COUNTER_GPU_OFFSET,
-       .mode_ctrl_mask = OMAP5430_REPEAT_MODE_MASK,
-
-       .bgap_counter = OMAP5430_BGAP_COUNTER_GPU_OFFSET,
-       .counter_mask = OMAP5430_COUNTER_MASK,
-
-       .bgap_threshold = OMAP5430_BGAP_THRESHOLD_GPU_OFFSET,
-       .threshold_thot_mask = OMAP5430_T_HOT_MASK,
-       .threshold_tcold_mask = OMAP5430_T_COLD_MASK,
-
-       .tshut_threshold = OMAP5430_BGAP_TSHUT_GPU_OFFSET,
-       .tshut_hot_mask = OMAP5430_TSHUT_HOT_MASK,
-       .tshut_cold_mask = OMAP5430_TSHUT_COLD_MASK,
-
-       .bgap_status = OMAP5430_BGAP_STATUS_OFFSET,
-       .status_clean_stop_mask = 0x0,
-       .status_bgap_alert_mask = OMAP5430_BGAP_ALERT_MASK,
-       .status_hot_mask = OMAP5430_HOT_MM_FLAG_MASK,
-       .status_cold_mask = OMAP5430_COLD_MM_FLAG_MASK,
-
-       .bgap_efuse = OMAP5430_FUSE_OPP_BGAP_GPU,
-};
-
-/*
- * omap5430 has one instance of thermal sensor for CORE
- * need to describe the individual bit fields
- */
-static struct temp_sensor_registers
-omap5430_core_temp_sensor_registers = {
-       .temp_sensor_ctrl = OMAP5430_TEMP_SENSOR_CORE_OFFSET,
-       .bgap_tempsoff_mask = OMAP5430_BGAP_TEMPSOFF_MASK,
-       .bgap_soc_mask = OMAP5430_BGAP_TEMP_SENSOR_SOC_MASK,
-       .bgap_eocz_mask = OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK,
-       .bgap_dtemp_mask = OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK,
-
-       .bgap_mask_ctrl = OMAP5430_BGAP_CTRL_OFFSET,
-       .mask_hot_mask = OMAP5430_MASK_HOT_CORE_MASK,
-       .mask_cold_mask = OMAP5430_MASK_COLD_CORE_MASK,
-
-       .bgap_mode_ctrl = OMAP5430_BGAP_COUNTER_CORE_OFFSET,
-       .mode_ctrl_mask = OMAP5430_REPEAT_MODE_MASK,
-
-       .bgap_counter = OMAP5430_BGAP_COUNTER_CORE_OFFSET,
-       .counter_mask = OMAP5430_COUNTER_MASK,
-
-       .bgap_threshold = OMAP5430_BGAP_THRESHOLD_CORE_OFFSET,
-       .threshold_thot_mask = OMAP5430_T_HOT_MASK,
-       .threshold_tcold_mask = OMAP5430_T_COLD_MASK,
-
-       .tshut_threshold = OMAP5430_BGAP_TSHUT_CORE_OFFSET,
-       .tshut_hot_mask = OMAP5430_TSHUT_HOT_MASK,
-       .tshut_cold_mask = OMAP5430_TSHUT_COLD_MASK,
-
-       .bgap_status = OMAP5430_BGAP_STATUS_OFFSET,
-       .status_clean_stop_mask = 0x0,
-       .status_bgap_alert_mask = OMAP5430_BGAP_ALERT_MASK,
-       .status_hot_mask = OMAP5430_HOT_CORE_FLAG_MASK,
-       .status_cold_mask = OMAP5430_COLD_CORE_FLAG_MASK,
-
-       .bgap_efuse = OMAP5430_FUSE_OPP_BGAP_CORE,
-};
-
-/* Thresholds and limits for OMAP5430 MPU temperature sensor */
-static struct temp_sensor_data omap5430_mpu_temp_sensor_data = {
-       .tshut_hot = OMAP5430_MPU_TSHUT_HOT,
-       .tshut_cold = OMAP5430_MPU_TSHUT_COLD,
-       .t_hot = OMAP5430_MPU_T_HOT,
-       .t_cold = OMAP5430_MPU_T_COLD,
-       .min_freq = OMAP5430_MPU_MIN_FREQ,
-       .max_freq = OMAP5430_MPU_MAX_FREQ,
-       .max_temp = OMAP5430_MPU_MAX_TEMP,
-       .min_temp = OMAP5430_MPU_MIN_TEMP,
-       .hyst_val = OMAP5430_MPU_HYST_VAL,
-       .adc_start_val = OMAP5430_ADC_START_VALUE,
-       .adc_end_val = OMAP5430_ADC_END_VALUE,
-       .update_int1 = 1000,
-       .update_int2 = 2000,
-};
-
-/* Thresholds and limits for OMAP5430 GPU temperature sensor */
-static struct temp_sensor_data omap5430_gpu_temp_sensor_data = {
-       .tshut_hot = OMAP5430_GPU_TSHUT_HOT,
-       .tshut_cold = OMAP5430_GPU_TSHUT_COLD,
-       .t_hot = OMAP5430_GPU_T_HOT,
-       .t_cold = OMAP5430_GPU_T_COLD,
-       .min_freq = OMAP5430_GPU_MIN_FREQ,
-       .max_freq = OMAP5430_GPU_MAX_FREQ,
-       .max_temp = OMAP5430_GPU_MAX_TEMP,
-       .min_temp = OMAP5430_GPU_MIN_TEMP,
-       .hyst_val = OMAP5430_GPU_HYST_VAL,
-       .adc_start_val = OMAP5430_ADC_START_VALUE,
-       .adc_end_val = OMAP5430_ADC_END_VALUE,
-       .update_int1 = 1000,
-       .update_int2 = 2000,
-};
-
-/* Thresholds and limits for OMAP5430 CORE temperature sensor */
-static struct temp_sensor_data omap5430_core_temp_sensor_data = {
-       .tshut_hot = OMAP5430_CORE_TSHUT_HOT,
-       .tshut_cold = OMAP5430_CORE_TSHUT_COLD,
-       .t_hot = OMAP5430_CORE_T_HOT,
-       .t_cold = OMAP5430_CORE_T_COLD,
-       .min_freq = OMAP5430_CORE_MIN_FREQ,
-       .max_freq = OMAP5430_CORE_MAX_FREQ,
-       .max_temp = OMAP5430_CORE_MAX_TEMP,
-       .min_temp = OMAP5430_CORE_MIN_TEMP,
-       .hyst_val = OMAP5430_CORE_HYST_VAL,
-       .adc_start_val = OMAP5430_ADC_START_VALUE,
-       .adc_end_val = OMAP5430_ADC_END_VALUE,
-       .update_int1 = 1000,
-       .update_int2 = 2000,
-};
-
-static const int
-omap5430_adc_to_temp[OMAP5430_ADC_END_VALUE - OMAP5430_ADC_START_VALUE + 1] = {
-       -40000, -40000, -40000, -40000, -39800, -39400, -39000, -38600,
-       -38200, -37800, -37300, -36800,
-       -36400, -36000, -35600, -35200, -34800, -34300, -33800, -33400, -33000,
-       -32600,
-       -32200, -31800, -31300, -30800, -30400, -30000, -29600, -29200, -28700,
-       -28200, -27800, -27400, -27000, -26600, -26200, -25700, -25200, -24800,
-       -24400, -24000, -23600, -23200, -22700, -22200, -21800, -21400, -21000,
-       -20600, -20200, -19700, -19200, -9300, -18400, -18000, -17600, -17200,
-       -16700, -16200, -15800, -15400, -15000, -14600, -14200, -13700, -13200,
-       -12800, -12400, -12000, -11600, -11200, -10700, -10200, -9800, -9400,
-       -9000,
-       -8600, -8200, -7700, -7200, -6800, -6400, -6000, -5600, -5200, -4800,
-       -4300,
-       -3800, -3400, -3000, -2600, -2200, -1800, -1300, -800, -400, 0, 400,
-       800,
-       1200, 1600, 2100, 2600, 3000, 3400, 3800, 4200, 4600, 5100, 5600, 6000,
-       6400, 6800, 7200, 7600, 8000, 8500, 9000, 9400, 9800, 10200, 10800,
-       11100,
-       11400, 11900, 12400, 12800, 13200, 13600, 14000, 14400, 14800, 15300,
-       15800,
-       16200, 16600, 17000, 17400, 17800, 18200, 18700, 19200, 19600, 20000,
-       20400,
-       20800, 21200, 21600, 22100, 22600, 23000, 23400, 23800, 24200, 24600,
-       25000,
-       25400, 25900, 26400, 26800, 27200, 27600, 28000, 28400, 28800, 29300,
-       29800,
-       30200, 30600, 31000, 31400, 31800, 32200, 32600, 33100, 33600, 34000,
-       34400,
-       34800, 35200, 35600, 36000, 36400, 36800, 37300, 37800, 38200, 38600,
-       39000,
-       39400, 39800, 40200, 40600, 41100, 41600, 42000, 42400, 42800, 43200,
-       43600,
-       44000, 44400, 44800, 45300, 45800, 46200, 46600, 47000, 47400, 47800,
-       48200,
-       48600, 49000, 49500, 50000, 50400, 50800, 51200, 51600, 52000, 52400,
-       52800,
-       53200, 53700, 54200, 54600, 55000, 55400, 55800, 56200, 56600, 57000,
-       57400,
-       57800, 58200, 58700, 59200, 59600, 60000, 60400, 60800, 61200, 61600,
-       62000,
-       62400, 62800, 63300, 63800, 64200, 64600, 65000, 65400, 65800, 66200,
-       66600,
-       67000, 67400, 67800, 68200, 68700, 69200, 69600, 70000, 70400, 70800,
-       71200,
-       71600, 72000, 72400, 72800, 73200, 73600, 74100, 74600, 75000, 75400,
-       75800,
-       76200, 76600, 77000, 77400, 77800, 78200, 78600, 79000, 79400, 79800,
-       80300,
-       80800, 81200, 81600, 82000, 82400, 82800, 83200, 83600, 84000, 84400,
-       84800,
-       85200, 85600, 86000, 86400, 86800, 87300, 87800, 88200, 88600, 89000,
-       89400,
-       89800, 90200, 90600, 91000, 91400, 91800, 92200, 92600, 93000, 93400,
-       93800,
-       94200, 94600, 95000, 95500, 96000, 96400, 96800, 97200, 97600, 98000,
-       98400,
-       98800, 99200, 99600, 100000, 100400, 100800, 101200, 101600, 102000,
-       102400,
-       102800, 103200, 103600, 104000, 104400, 104800, 105200, 105600, 106100,
-       106600, 107000, 107400, 107800, 108200, 108600, 109000, 109400, 109800,
-       110200, 110600, 111000, 111400, 111800, 112200, 112600, 113000, 113400,
-       113800, 114200, 114600, 115000, 115400, 115800, 116200, 116600, 117000,
-       117400, 117800, 118200, 118600, 119000, 119400, 119800, 120200, 120600,
-       121000, 121400, 121800, 122200, 122600, 123000, 123400, 123800, 124200,
-       124600, 124900, 125000, 125000, 125000, 125000,
-};
-
-const struct omap_bandgap_data omap5430_data = {
-       .features = OMAP_BANDGAP_FEATURE_TSHUT_CONFIG |
-                       OMAP_BANDGAP_FEATURE_TALERT |
-                       OMAP_BANDGAP_FEATURE_MODE_CONFIG |
-                       OMAP_BANDGAP_FEATURE_COUNTER,
-       .fclock_name = "ts_clk_div_ck",
-       .div_ck_name = "ts_clk_div_ck",
-       .conv_table = omap5430_adc_to_temp,
-       .expose_sensor = omap_thermal_expose_sensor,
-       .remove_sensor = omap_thermal_remove_sensor,
-       .sensors = {
-               {
-               .registers = &omap5430_mpu_temp_sensor_registers,
-               .ts_data = &omap5430_mpu_temp_sensor_data,
-               .domain = "cpu",
-               .register_cooling = omap_thermal_register_cpu_cooling,
-               .unregister_cooling = omap_thermal_unregister_cpu_cooling,
-               .slope = OMAP_GRADIENT_SLOPE_5430_CPU,
-               .constant = OMAP_GRADIENT_CONST_5430_CPU,
-               .slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_5430_CPU,
-               .constant_pcb = OMAP_GRADIENT_CONST_W_PCB_5430_CPU,
-               },
-               {
-               .registers = &omap5430_gpu_temp_sensor_registers,
-               .ts_data = &omap5430_gpu_temp_sensor_data,
-               .domain = "gpu",
-               .slope = OMAP_GRADIENT_SLOPE_5430_GPU,
-               .constant = OMAP_GRADIENT_CONST_5430_GPU,
-               .slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_5430_GPU,
-               .constant_pcb = OMAP_GRADIENT_CONST_W_PCB_5430_GPU,
-               },
-               {
-               .registers = &omap5430_core_temp_sensor_registers,
-               .ts_data = &omap5430_core_temp_sensor_data,
-               .domain = "core",
-               },
-       },
-       .sensor_count = 3,
-};
diff --git a/drivers/staging/omap-thermal/omap_bandgap.txt b/drivers/staging/omap-thermal/omap_bandgap.txt
deleted file mode 100644 (file)
index 6008a14..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-* Texas Instrument OMAP SCM bandgap bindings
-
-In the System Control Module, OMAP supplies a voltage reference
-and a temperature sensor feature that are gathered in the band
-gap voltage and temperature sensor (VBGAPTS) module. The band
-gap provides current and voltage reference for its internal
-circuits and other analog IP blocks. The analog-to-digital
-converter (ADC) produces an output value that is proportional
-to the silicon temperature.
-
-Required properties:
-- compatible : Should be:
-  - "ti,omap4460-control-bandgap" : for OMAP4460 bandgap
-  - "ti,omap5430-control-bandgap" : for OMAP5430 bandgap
-- interrupts : this entry should indicate which interrupt line
-the talert signal is routed to;
-Specific:
-- ti,tshut-gpio : this entry should be used to inform which GPIO
-line the tshut signal is routed to;
-
-Example:
-
-bandgap {
-       reg = <0x4a002260 0x4
-               0x4a00232C 0x4
-               0x4a002378 0x18>;
-       compatible = "ti,omap4460-control-bandgap";
-       interrupts = <0 126 4>; /* talert */
-       ti,tshut-gpio = <86>;
-};
index ffb083c958ad52de919fc0b4b97850a7dcf9ba9d..ae550520311bd98d7732a48c0881154f2455205f 100644 (file)
 #define                VeryLowRSSI                                     15
 #define                CTSToSelfTHVal                                  30
 
-//defined by vivi, for tx power track
+/* defined by vivi, for tx power track */
 #define                E_FOR_TX_POWER_TRACK               300
-//Dynamic Tx Power Control Threshold
+/* Dynamic Tx Power Control Threshold */
 #define                TX_POWER_NEAR_FIELD_THRESH_HIGH         68
 #define                TX_POWER_NEAR_FIELD_THRESH_LOW          62
-//added by amy for atheros AP
+/* added by amy for atheros AP */
 #define         TX_POWER_ATHEROAP_THRESH_HIGH           78
 #define                TX_POWER_ATHEROAP_THRESH_LOW            72
 
-//defined by vivi, for showing on UI
+/* defined by vivi, for showing on UI */
 #define                        Current_Tx_Rate_Reg         0x1b8
 #define                        Initial_Tx_Rate_Reg               0x1b9
 #define                        Tx_Retry_Count_Reg         0x1ac
@@ -98,28 +98,25 @@ typedef struct _dynamic_initial_gain_threshold_ {
        bool            initialgain_lowerbound_state;
 
        long            rssi_val;
-}dig_t;
+} dig_t;
 
-typedef enum tag_dynamic_init_gain_state_definition
-{
+typedef enum tag_dynamic_init_gain_state_definition {
        DM_STA_DIG_OFF = 0,
        DM_STA_DIG_ON,
        DM_STA_DIG_MAX
-}dm_dig_sta_e;
+} dm_dig_sta_e;
 
 
 /* 2007/10/08 MH Define RATR state. */
-typedef enum tag_dynamic_ratr_state_definition
-{
+typedef enum tag_dynamic_ratr_state_definition {
        DM_RATR_STA_HIGH = 0,
        DM_RATR_STA_MIDDLE = 1,
        DM_RATR_STA_LOW = 2,
        DM_RATR_STA_MAX
-}dm_ratr_sta_e;
+} dm_ratr_sta_e;
 
 /* 2007/10/11 MH Define DIG operation type. */
-typedef enum tag_dynamic_init_gain_operation_type_definition
-{
+typedef enum tag_dynamic_init_gain_operation_type_definition {
        DIG_TYPE_THRESH_HIGH    = 0,
        DIG_TYPE_THRESH_LOW     = 1,
        DIG_TYPE_THRESH_HIGHPWR_HIGH    = 2,
@@ -134,43 +131,38 @@ typedef enum tag_dynamic_init_gain_operation_type_definition
        DIG_TYPE_ENABLE                 = 20,
        DIG_TYPE_DISABLE                = 30,
        DIG_OP_TYPE_MAX
-}dm_dig_op_e;
+} dm_dig_op_e;
 
-typedef enum tag_dig_algorithm_definition
-{
+typedef enum tag_dig_algorithm_definition {
        DIG_ALGO_BY_FALSE_ALARM = 0,
        DIG_ALGO_BY_RSSI        = 1,
        DIG_ALGO_MAX
-}dm_dig_alg_e;
+} dm_dig_alg_e;
 
-typedef enum tag_dig_dbgmode_definition
-{
+typedef enum tag_dig_dbgmode_definition {
        DIG_DBG_OFF = 0,
        DIG_DBG_ON = 1,
        DIG_DBG_MAX
-}dm_dig_dbg_e;
+} dm_dig_dbg_e;
 
-typedef enum tag_dig_connect_definition
-{
+typedef enum tag_dig_connect_definition {
        DIG_DISCONNECT = 0,
        DIG_CONNECT = 1,
        DIG_CONNECT_MAX
-}dm_dig_connect_e;
+} dm_dig_connect_e;
 
-typedef enum tag_dig_packetdetection_threshold_definition
-{
+typedef enum tag_dig_packetdetection_threshold_definition {
        DIG_PD_AT_LOW_POWER = 0,
        DIG_PD_AT_NORMAL_POWER = 1,
        DIG_PD_AT_HIGH_POWER = 2,
        DIG_PD_MAX
-}dm_dig_pd_th_e;
+} dm_dig_pd_th_e;
 
-typedef enum tag_dig_cck_cs_ratio_state_definition
-{
+typedef enum tag_dig_cck_cs_ratio_state_definition {
        DIG_CS_RATIO_LOWER = 0,
        DIG_CS_RATIO_HIGHER = 1,
        DIG_CS_MAX
-}dm_dig_cs_ratio_e;
+} dm_dig_cs_ratio_e;
 typedef struct _Dynamic_Rx_Path_Selection_ {
        u8              Enable;
        u8              DbgMode;
@@ -185,27 +177,25 @@ typedef struct _Dynamic_Rx_Path_Selection_ {
        u8              rf_rssi[4];
        u8              rf_enable_rssi_th[4];
        long            cck_pwdb_sta[4];
-}DRxPathSel;
+} DRxPathSel;
 
-typedef enum tag_CCK_Rx_Path_Method_Definition
-{
+typedef enum tag_CCK_Rx_Path_Method_Definition {
        CCK_Rx_Version_1 = 0,
-       CCK_Rx_Version_2= 1,
+       CCK_Rx_Version_2 = 1,
        CCK_Rx_Version_MAX
-}DM_CCK_Rx_Path_Method;
+} DM_CCK_Rx_Path_Method;
 
-typedef enum tag_DM_DbgMode_Definition
-{
+typedef enum tag_DM_DbgMode_Definition {
        DM_DBG_OFF = 0,
        DM_DBG_ON = 1,
        DM_DBG_MAX
-}DM_DBG_E;
+} DM_DBG_E;
 
 typedef struct tag_Tx_Config_Cmd_Format {
-       u32     Op;                                                                             /* Command packet type. */
-       u32     Length;                                                                 /* Command packet length. */
+       u32     Op;                     /* Command packet type. */
+       u32     Length;                 /* Command packet length. */
        u32     Value;
-}DCMD_TXCMD_T, *PDCMD_TXCMD_T;
+} DCMD_TXCMD_T, *PDCMD_TXCMD_T;
 /*------------------------------Define structure----------------------------*/
 
 
@@ -232,13 +222,14 @@ extern  void    dm_txpower_trackingcallback(struct work_struct *work);
 extern  void    dm_restore_dynamic_mechanism_state(struct net_device *dev);
 extern  void    dm_backup_dynamic_mechanism_state(struct net_device *dev);
 extern  void    dm_change_dynamic_initgain_thresh(struct net_device *dev,
-                                                               u32 dm_type, u32 dm_value);
-extern  void    dm_force_tx_fw_info(struct net_device *dev,u32 force_type, u32 force_value);
+                                               u32 dm_type, u32 dm_value);
+extern  void    dm_force_tx_fw_info(struct net_device *dev,
+                                       u32 force_type, u32 force_value);
 extern  void    dm_init_edca_turbo(struct net_device *dev);
 extern  void    dm_rf_operation_test_callback(unsigned long data);
 extern  void    dm_rf_pathcheck_workitemcallback(struct work_struct *work);
 extern  void dm_fsync_timer_callback(unsigned long data);
-extern void    dm_cck_txpower_adjust(struct net_device *dev,bool  binch14);
+extern void    dm_cck_txpower_adjust(struct net_device *dev, bool  binch14);
 extern  void    dm_shadow_init(struct net_device *dev);
 extern void dm_initialize_txpower_tracking(struct net_device *dev);
 /*--------------------------Exported Function prototype---------------------*/
index c9eb4b74799b86800360051103bfb3153bc00518..6cb1a0af5177efe783bc7175546aae0810c934c8 100644 (file)
@@ -267,12 +267,8 @@ static void SwLedBlink(struct LED_871x *pLed)
                                   LED_BLINK_SLOWLY_INTERVAL);
                        break;
                case LED_BLINK_WPS:
-                       if (pLed->BlinkingLedState == LED_ON)
-                               _set_timer(&(pLed->BlinkTimer),
-                                          LED_BLINK_LONG_INTERVAL);
-                       else
-                               _set_timer(&(pLed->BlinkTimer),
-                                          LED_BLINK_LONG_INTERVAL);
+                       _set_timer(&(pLed->BlinkTimer),
+                                       LED_BLINK_LONG_INTERVAL);
                        break;
                default:
                        _set_timer(&(pLed->BlinkTimer),
index e42e6f0a15e674963df05a53170d6d9246a00e91..92ca8997e5bc48f957ce752c7a56731930faee45 100644 (file)
@@ -9,9 +9,6 @@
 #define RXFRAME_ALIGN  8
 #define RXFRAME_ALIGN_SZ       (1 << RXFRAME_ALIGN)
 
-#define MAX_RXFRAME_CNT        512
-#define MAX_RX_NUMBLKS         (32)
-#define RECVFRAME_HDR_ALIGN 128
 #define MAX_SUBFRAME_COUNT     64
 
 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
@@ -130,15 +127,10 @@ struct sta_recv_priv {
 
 /* get a free recv_frame from pfree_recv_queue */
 union recv_frame *r8712_alloc_recvframe(struct  __queue *pfree_recv_queue);
-union recv_frame *r8712_dequeue_recvframe(struct  __queue *queue);
-int r8712_enqueue_recvframe(union recv_frame *precvframe,
-                            struct  __queue *queue);
 int r8712_free_recvframe(union recv_frame *precvframe,
                          struct  __queue *pfree_recv_queue);
 void r8712_free_recvframe_queue(struct  __queue *pframequeue,
                                 struct  __queue *pfree_recv_queue);
-void r8712_init_recvframe(union recv_frame *precvframe,
-                          struct recv_priv *precvpriv);
 int r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe);
 int recv_func(struct _adapter *padapter, void *pcontext);
 
@@ -150,11 +142,6 @@ static inline u8 *get_rxmem(union recv_frame *precvframe)
        return precvframe->u.hdr.rx_head;
 }
 
-static inline u8 *get_rx_status(union recv_frame *precvframe)
-{
-       return get_rxmem(precvframe);
-}
-
 static inline u8 *get_recvframe_data(union recv_frame *precvframe)
 {
        /* always return rx_data */
@@ -163,28 +150,6 @@ static inline u8 *get_recvframe_data(union recv_frame *precvframe)
        return precvframe->u.hdr.rx_data;
 }
 
-static inline u8 *recvframe_push(union recv_frame *precvframe, sint sz)
-{
-       /* append data before rx_data */
-
-       /* add data to the start of recv_frame
-        *
-        * This function extends the used data area of the recv_frame at the
-        * buffer start. rx_data must be still larger than rx_head, after
-        * pushing.
-        */
-
-       if (precvframe == NULL)
-               return NULL;
-       precvframe->u.hdr.rx_data -= sz ;
-       if (precvframe->u.hdr.rx_data < precvframe->u.hdr.rx_head) {
-               precvframe->u.hdr.rx_data += sz ;
-               return NULL;
-       }
-       precvframe->u.hdr.len += sz;
-       return precvframe->u.hdr.rx_data;
-}
-
 static inline u8 *recvframe_pull(union recv_frame *precvframe, sint sz)
 {
        /* used for extract sz bytes from rx_data, update rx_data and return
@@ -236,53 +201,6 @@ static inline u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz)
        return precvframe->u.hdr.rx_tail;
 }
 
-static inline _buffer *get_rxbuf_desc(union recv_frame *precvframe)
-{
-       _buffer *buf_desc;
-       if (precvframe == NULL)
-               return NULL;
-       return buf_desc;
-}
-
-static inline union recv_frame *rxmem_to_recvframe(u8 *rxmem)
-{
-       /* due to the design of 2048 bytes alignment of recv_frame, we can
-        * reference the union recv_frame from any given member of recv_frame.
-        * rxmem indicates the any member/address in recv_frame */
-       return (union recv_frame *)(((addr_t)rxmem >> RXFRAME_ALIGN) <<
-                                 RXFRAME_ALIGN);
-}
-
-static inline union recv_frame *pkt_to_recvframe(_pkt *pkt)
-{
-       u8 *buf_star;
-       union recv_frame *precv_frame;
-
-       precv_frame = rxmem_to_recvframe((unsigned char *)buf_star);
-       return precv_frame;
-}
-
-static inline u8 *pkt_to_recvmem(_pkt *pkt)
-{
-       /* return the rx_head */
-       union recv_frame *precv_frame = pkt_to_recvframe(pkt);
-
-       return  precv_frame->u.hdr.rx_head;
-}
-
-static inline u8 *pkt_to_recvdata(_pkt *pkt)
-{
-       /* return the rx_data */
-       union recv_frame *precv_frame = pkt_to_recvframe(pkt);
-
-       return  precv_frame->u.hdr.rx_data;
-}
-
-static inline sint get_recvframe_len(union recv_frame *precvframe)
-{
-       return precvframe->u.hdr.len;
-}
-
 struct sta_info;
 
 void   _r8712_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
@@ -292,36 +210,10 @@ union recv_frame *r8712_decryptor(struct _adapter *adapter,
                                  union recv_frame *precv_frame);
 union recv_frame *r8712_recvframe_chk_defrag(struct _adapter *adapter,
                                             union recv_frame *precv_frame);
-union recv_frame *r8712_recvframe_defrag(struct _adapter *adapter,
-                                        struct  __queue *defrag_q);
-union recv_frame *r8712_recvframe_chk_defrag_new(struct _adapter *adapter,
-                                       union recv_frame *precv_frame);
-union recv_frame *r8712_recvframe_defrag_new(struct _adapter *adapter,
-                                       struct  __queue *defrag_q,
-                                       union recv_frame *precv_frame);
-int r8712_recv_decache(union recv_frame *precv_frame, u8 bretry,
-                      struct stainfo_rxcache *prxcache);
-int r8712_sta2sta_data_frame(struct _adapter *adapter,
-                            union recv_frame *precv_frame,
-                            struct sta_info **psta);
-int r8712_ap2sta_data_frame(struct _adapter *adapter,
-                           union recv_frame *precv_frame,
-                           struct sta_info **psta);
-int r8712_sta2ap_data_frame(struct _adapter *adapter,
-                           union recv_frame *precv_frame,
-                           struct sta_info **psta);
-int r8712_validate_recv_ctrl_frame(struct _adapter *adapter,
-                                  union recv_frame *precv_frame);
-int r8712_validate_recv_mgnt_frame(struct _adapter *adapter,
-                                  union recv_frame *precv_frame);
-int r8712_validate_recv_data_frame(struct _adapter *adapter,
-                                  union recv_frame *precv_frame);
 int r8712_validate_recv_frame(struct _adapter *adapter,
                              union recv_frame *precv_frame);
 union recv_frame *r8712_portctrl(struct _adapter *adapter,
                                 union recv_frame *precv_frame);
-void  r8712_mgt_dispatcher(struct _adapter *padapter, u8 *pframe, uint len);
-int r8712_amsdu_to_msdu(struct _adapter *padapter, union recv_frame *prframe);
 
 #endif
 
index a2087f5b0d1abdfbd03186f899556d50eda61528..304e1bcd1e3b2c78f89704ee2e65c2da353163ee 100644 (file)
@@ -19,7 +19,7 @@
  * option register 
  */
 
-/* Device Infomation Register */
+/* Device Information Register */
 #define MP_OPTR_DIR0           0x04    /* port0 ~ port8 */
 #define MP_OPTR_DIR1           0x05    /* port8 ~ port15 */
 #define MP_OPTR_DIR2           0x06    /* port16 ~ port23 */
@@ -47,7 +47,7 @@
 #define IIR_RS485              0x20            /* RS485 type */
 #define IIR_TYPE_MASK          0x30
 
-/* Interrrupt Mask Register */
+/* Interrupt Mask Register */
 #define MP_OPTR_IMR0           0x0C    /* port0 ~ port8 */
 #define MP_OPTR_IMR1           0x0D    /* port8 ~ port15 */
 #define MP_OPTR_IMR2           0x0E    /* port16 ~ port23 */
index f75ee1dd475c6e1b9ead392a1e43e5ea6177747b..cd94f6c2772319bc289ead11aebb1e34c26955ef 100644 (file)
@@ -2248,7 +2248,7 @@ static irqreturn_t multi_interrupt(int irq, void *dev_id)
                mtpt = list_entry(lhead, struct mp_port, list);
                
                iir = serial_in(mtpt, UART_IIR);
-               printk("intrrupt! port %d, iir 0x%x\n", mtpt->port.line, iir); //wlee
+               printk("interrupt! port %d, iir 0x%x\n", mtpt->port.line, iir); //wlee
                if (!(iir & UART_IIR_NO_INT)) 
                {
                        printk("interrupt handle\n");
@@ -2830,7 +2830,7 @@ static void __init multi_init_ports(void)
 
                        mtpt->port.uartclk  = BASE_BAUD * 16;
 
-                       /* get input clock infomation */
+                       /* get input clock information */
                        osc = inb(sbdev->option_reg_addr + MP_OPTR_DIR0 + i/8) & 0x0F;
                        if (osc==0x0f)
                                osc = 0;
index f33efde07b97439a0501c2cec351d5803fd6ec3c..a15f470a172807b3fcbd04ffd49462e6772496b2 100644 (file)
@@ -174,7 +174,7 @@ static DEFINE_MUTEX(mp_mutex);
 #define DEBUG_INTR(fmt...)  do { } while (0)
 #endif
 
-#if defined(__i386__) && (defined(CONFIG_M386) || defined(CONFIG_M486))
+#if defined(__i386__) && defined(CONFIG_M486)
 #define SERIAL_INLINE
 #endif
 #ifdef SERIAL_INLINE
index cd3bb39e42556477d66c7b098e42711cd2f41d7e..490a31e0fd4345369028380ef4f94ac3d40b481a 100644 (file)
@@ -1206,7 +1206,7 @@ static int sep_crypto_block_data(struct ablkcipher_request *req)
 
                if (copy_result != crypto_ablkcipher_blocksize(tfm)) {
                        dev_warn(&ta_ctx->sep_used->pdev->dev,
-                               "des block copy faild\n");
+                               "des block copy failed\n");
                        return -ENOMEM;
                }
 
@@ -1637,7 +1637,7 @@ static u32 crypto_post_op(struct sep_device *sep)
                                        crypto_ablkcipher_blocksize(tfm)) {
 
                                        dev_warn(&ta_ctx->sep_used->pdev->dev,
-                                               "des block copy faild\n");
+                                               "des block copy failed\n");
                                        sep_crypto_release(sctx, ta_ctx,
                                                -ENOMEM);
                                        return -ENOMEM;
index 7d7c7ab610b7d53f00539575d670272eb156422e..4b6e30743634b90b4d7869d1e083883714243bdc 100644 (file)
@@ -219,7 +219,7 @@ held by the process (struct file) */
 /* maximum number of entries in the caller id table */
 #define SEP_CALLER_ID_TABLE_NUM_ENTRIES                       20
 
-/* maximum number of symetric operation (that require DMA resource)
+/* maximum number of symmetric operation (that require DMA resource)
        per one message */
 #define SEP_MAX_NUM_SYNC_DMA_OPS                       16
 
index 30e8d25113e4ab09cf331c6859f8493b521c417d..6a98a208bbf2895b0a978cd10658edf7e7f51ae0 100644 (file)
@@ -1986,7 +1986,7 @@ static int sep_prepare_input_dma_table(struct sep_device *sep,
                                        dma_ctx,
                                        sep_lli_entries);
                if (error)
-                       return error;
+                       goto end_function_error;
                lli_table_alloc_addr = *dmatables_region;
        }
 
@@ -2276,7 +2276,7 @@ static int sep_construct_dma_tables_from_lli(
                        table_data_size);
 
                /* If info entry is null - this is the first table built */
-               if (info_in_entry_ptr == NULL) {
+               if (info_in_entry_ptr == NULL || info_out_entry_ptr == NULL) {
                        /* Set the output parameters to physical addresses */
                        *lli_table_in_ptr =
                        sep_shared_area_virt_to_bus(sep, dma_in_lli_table_ptr);
@@ -2880,6 +2880,8 @@ static int sep_free_dma_tables_and_dcb(struct sep_device *sep, bool isapplet,
 
        dev_dbg(&sep->pdev->dev, "[PID%d] sep_free_dma_tables_and_dcb\n",
                                        current->pid);
+       if (!dma_ctx || !*dma_ctx) /* nothing to be done here*/
+               return 0;
 
        if (((*dma_ctx)->secure_dma == false) && (isapplet == true)) {
                dev_dbg(&sep->pdev->dev, "[PID%d] handling applet\n",
@@ -2895,8 +2897,7 @@ static int sep_free_dma_tables_and_dcb(struct sep_device *sep, bool isapplet,
                 * Go over each DCB and see if
                 * tail pointer must be updated
                 */
-               for (i = 0; dma_ctx && *dma_ctx &&
-                       i < (*dma_ctx)->nr_dcb_creat; i++, dcb_table_ptr++) {
+               for (i = 0; i < (*dma_ctx)->nr_dcb_creat; i++, dcb_table_ptr++) {
                        if (dcb_table_ptr->out_vr_tail_pt) {
                                pt_hold = (unsigned long)dcb_table_ptr->
                                        out_vr_tail_pt;
index 2b053a93afe69665a46e06098d5eb9619df30534..74f4c9a2b5be361bebff0342a70c714fa880a334 100644 (file)
  */
 #include <linux/tracepoint.h>
 
+/*
+ * Since use str*cpy in header file, better to include string.h, directly.
+ */
+#include <linux/string.h>
+
 /*
  * The TRACE_EVENT macro is broken up into 5 parts.
  *
@@ -97,7 +102,7 @@ TRACE_EVENT(sep_func_start,
        ),
 
        TP_fast_assign(
-               strncpy(__entry->name, name, 20);
+               strlcpy(__entry->name, name, 20);
                __entry->branch = branch;
        ),
 
@@ -116,7 +121,7 @@ TRACE_EVENT(sep_func_end,
        ),
 
        TP_fast_assign(
-               strncpy(__entry->name, name, 20);
+               strlcpy(__entry->name, name, 20);
                __entry->branch = branch;
        ),
 
@@ -135,7 +140,7 @@ TRACE_EVENT(sep_misc_event,
        ),
 
        TP_fast_assign(
-               strncpy(__entry->name, name, 20);
+               strlcpy(__entry->name, name, 20);
                __entry->branch = branch;
        ),
 
index 58c5f5cf4cec00ccdaa74c32aef388e8a5250ec7..45a222723207280cf6abd0d6a5b3963b4dda4c49 100644 (file)
@@ -6983,7 +6983,7 @@ static void __exit bypass_cleanup_module(void)
 /*     spin_lock_irqsave(&bpvm_lock, flags);
        rcu_read_lock(); */
                bypass_proc_remove_dev_sd(&bpctl_dev_arr[i]);
-/*     spin_unlock_irqrestore(&bpvm_lock, flags);        
+/*     spin_unlock_irqrestore(&bpvm_lock, flags);
        rcu_read_unlock(); */
 #endif
                remove_bypass_wd_auto(&bpctl_dev_arr[i]);
@@ -6995,18 +6995,16 @@ static void __exit bypass_cleanup_module(void)
        /* unmap all devices */
        for (i = 0; i < device_num; i++) {
 #ifdef BP_SELF_TEST
-               if (bpctl_dev_arr[i].bp_tx_data)
-                       kfree(bpctl_dev_arr[i].bp_tx_data);
+               kfree(bpctl_dev_arr[i].bp_tx_data);
 #endif
                iounmap((void *)(bpctl_dev_arr[i].mem_map));
        }
 
        /* free all devices space */
-       if (bpctl_dev_arr)
-               kfree(bpctl_dev_arr);
+       kfree(bpctl_dev_arr);
 
 /*
-* Unregister the device                             
+* Unregister the device
 */
        unregister_chrdev(major_num, DEVICE_NAME);
 }
index 95a1f1815d9072f9fa10c37cef89d2cfe97c6259..9ed250848e8123035625b6a1db8542200a3be638 100644 (file)
@@ -134,7 +134,7 @@ static int is_dev_sd(int if_index)
        return (ret >= 0 ? 1 : 0);
 }
 
-int is_bypass_dev(int if_index)
+static int is_bypass_dev(int if_index)
 {
        struct pci_dev *pdev = NULL;
        struct net_device *dev = NULL;
@@ -179,7 +179,7 @@ int is_bypass_dev(int if_index)
        return (ret < 0 ? -1 : ret);
 }
 
-int is_bypass(int if_index)
+static int is_bypass(int if_index)
 {
        int ret = 0;
        SET_BPLIB_INT_FN(is_bypass, int, if_index, ret);
@@ -189,70 +189,70 @@ int is_bypass(int if_index)
        return ret;
 }
 
-int get_bypass_slave(int if_index)
+static int get_bypass_slave(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_bypass_slave, GET_BYPASS_SLAVE, if_index);
 }
 
-int get_bypass_caps(int if_index)
+static int get_bypass_caps(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_bypass_caps, GET_BYPASS_CAPS, if_index);
 }
 
-int get_wd_set_caps(int if_index)
+static int get_wd_set_caps(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_wd_set_caps, GET_WD_SET_CAPS, if_index);
 }
 
-int set_bypass(int if_index, int bypass_mode)
+static int set_bypass(int if_index, int bypass_mode)
 {
        DO_BPLIB_SET_ARG_FN(set_bypass, SET_BYPASS, if_index, bypass_mode);
 }
 
-int get_bypass(int if_index)
+static int get_bypass(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_bypass, GET_BYPASS, if_index);
 }
 
-int get_bypass_change(int if_index)
+static int get_bypass_change(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_bypass_change, GET_BYPASS_CHANGE, if_index);
 }
 
-int set_dis_bypass(int if_index, int dis_bypass)
+static int set_dis_bypass(int if_index, int dis_bypass)
 {
        DO_BPLIB_SET_ARG_FN(set_dis_bypass, SET_DIS_BYPASS, if_index,
                            dis_bypass);
 }
 
-int get_dis_bypass(int if_index)
+static int get_dis_bypass(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_dis_bypass, GET_DIS_BYPASS, if_index);
 }
 
-int set_bypass_pwoff(int if_index, int bypass_mode)
+static int set_bypass_pwoff(int if_index, int bypass_mode)
 {
        DO_BPLIB_SET_ARG_FN(set_bypass_pwoff, SET_BYPASS_PWOFF, if_index,
                            bypass_mode);
 }
 
-int get_bypass_pwoff(int if_index)
+static int get_bypass_pwoff(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_bypass_pwoff, GET_BYPASS_PWOFF, if_index);
 }
 
-int set_bypass_pwup(int if_index, int bypass_mode)
+static int set_bypass_pwup(int if_index, int bypass_mode)
 {
        DO_BPLIB_SET_ARG_FN(set_bypass_pwup, SET_BYPASS_PWUP, if_index,
                            bypass_mode);
 }
 
-int get_bypass_pwup(int if_index)
+static int get_bypass_pwup(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_bypass_pwup, GET_BYPASS_PWUP, if_index);
 }
 
-int set_bypass_wd(int if_index, int ms_timeout, int *ms_timeout_set)
+static int set_bypass_wd(int if_index, int ms_timeout, int *ms_timeout_set)
 {
        int data = ms_timeout, ret = 0;
        if (is_dev_sd(if_index))
@@ -268,7 +268,7 @@ int set_bypass_wd(int if_index, int ms_timeout, int *ms_timeout_set)
        return ret;
 }
 
-int get_bypass_wd(int if_index, int *ms_timeout_set)
+static int get_bypass_wd(int if_index, int *ms_timeout_set)
 {
        int *data = ms_timeout_set, ret = 0;
        if (is_dev_sd(if_index))
@@ -279,7 +279,7 @@ int get_bypass_wd(int if_index, int *ms_timeout_set)
        return ret;
 }
 
-int get_wd_expire_time(int if_index, int *ms_time_left)
+static int get_wd_expire_time(int if_index, int *ms_time_left)
 {
        int *data = ms_time_left, ret = 0;
        if (is_dev_sd(if_index))
@@ -293,144 +293,144 @@ int get_wd_expire_time(int if_index, int *ms_time_left)
        return ret;
 }
 
-int reset_bypass_wd_timer(int if_index)
+static int reset_bypass_wd_timer(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(reset_bypass_wd_timer, RESET_BYPASS_WD_TIMER,
                            if_index);
 }
 
-int set_std_nic(int if_index, int bypass_mode)
+static int set_std_nic(int if_index, int bypass_mode)
 {
        DO_BPLIB_SET_ARG_FN(set_std_nic, SET_STD_NIC, if_index, bypass_mode);
 }
 
-int get_std_nic(int if_index)
+static int get_std_nic(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_std_nic, GET_STD_NIC, if_index);
 }
 
-int set_tx(int if_index, int tx_state)
+static int set_tx(int if_index, int tx_state)
 {
        DO_BPLIB_SET_ARG_FN(set_tx, SET_TX, if_index, tx_state);
 }
 
-int get_tx(int if_index)
+static int get_tx(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_tx, GET_TX, if_index);
 }
 
-int set_tap(int if_index, int tap_mode)
+static int set_tap(int if_index, int tap_mode)
 {
        DO_BPLIB_SET_ARG_FN(set_tap, SET_TAP, if_index, tap_mode);
 }
 
-int get_tap(int if_index)
+static int get_tap(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_tap, GET_TAP, if_index);
 }
 
-int get_tap_change(int if_index)
+static int get_tap_change(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_tap_change, GET_TAP_CHANGE, if_index);
 }
 
-int set_dis_tap(int if_index, int dis_tap)
+static int set_dis_tap(int if_index, int dis_tap)
 {
        DO_BPLIB_SET_ARG_FN(set_dis_tap, SET_DIS_TAP, if_index, dis_tap);
 }
 
-int get_dis_tap(int if_index)
+static int get_dis_tap(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_dis_tap, GET_DIS_TAP, if_index);
 }
 
-int set_tap_pwup(int if_index, int tap_mode)
+static int set_tap_pwup(int if_index, int tap_mode)
 {
        DO_BPLIB_SET_ARG_FN(set_tap_pwup, SET_TAP_PWUP, if_index, tap_mode);
 }
 
-int get_tap_pwup(int if_index)
+static int get_tap_pwup(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_tap_pwup, GET_TAP_PWUP, if_index);
 }
 
-int set_bp_disc(int if_index, int disc_mode)
+static int set_bp_disc(int if_index, int disc_mode)
 {
        DO_BPLIB_SET_ARG_FN(set_bp_disc, SET_DISC, if_index, disc_mode);
 }
 
-int get_bp_disc(int if_index)
+static int get_bp_disc(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_bp_disc, GET_DISC, if_index);
 }
 
-int get_bp_disc_change(int if_index)
+static int get_bp_disc_change(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_bp_disc_change, GET_DISC_CHANGE, if_index);
 }
 
-int set_bp_dis_disc(int if_index, int dis_disc)
+static int set_bp_dis_disc(int if_index, int dis_disc)
 {
        DO_BPLIB_SET_ARG_FN(set_bp_dis_disc, SET_DIS_DISC, if_index, dis_disc);
 }
 
-int get_bp_dis_disc(int if_index)
+static int get_bp_dis_disc(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_bp_dis_disc, GET_DIS_DISC, if_index);
 }
 
-int set_bp_disc_pwup(int if_index, int disc_mode)
+static int set_bp_disc_pwup(int if_index, int disc_mode)
 {
        DO_BPLIB_SET_ARG_FN(set_bp_disc_pwup, SET_DISC_PWUP, if_index,
                            disc_mode);
 }
 
-int get_bp_disc_pwup(int if_index)
+static int get_bp_disc_pwup(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_bp_disc_pwup, GET_DISC_PWUP, if_index);
 }
 
-int set_wd_exp_mode(int if_index, int mode)
+static int set_wd_exp_mode(int if_index, int mode)
 {
        DO_BPLIB_SET_ARG_FN(set_wd_exp_mode, SET_WD_EXP_MODE, if_index, mode);
 }
 
-int get_wd_exp_mode(int if_index)
+static int get_wd_exp_mode(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_wd_exp_mode, GET_WD_EXP_MODE, if_index);
 }
 
-int set_wd_autoreset(int if_index, int time)
+static int set_wd_autoreset(int if_index, int time)
 {
        DO_BPLIB_SET_ARG_FN(set_wd_autoreset, SET_WD_AUTORESET, if_index, time);
 }
 
-int get_wd_autoreset(int if_index)
+static int get_wd_autoreset(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_wd_autoreset, GET_WD_AUTORESET, if_index);
 }
 
-int set_tpl(int if_index, int tpl_mode)
+static int set_tpl(int if_index, int tpl_mode)
 {
        DO_BPLIB_SET_ARG_FN(set_tpl, SET_TPL, if_index, tpl_mode);
 }
 
-int get_tpl(int if_index)
+static int get_tpl(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_tpl, GET_TPL, if_index);
 }
 
-int set_bp_hw_reset(int if_index, int mode)
+static int set_bp_hw_reset(int if_index, int mode)
 {
        DO_BPLIB_SET_ARG_FN(set_tpl, SET_BP_HW_RESET, if_index, mode);
 }
 
-int get_bp_hw_reset(int if_index)
+static int get_bp_hw_reset(int if_index)
 {
        DO_BPLIB_GET_ARG_FN(get_tpl, GET_BP_HW_RESET, if_index);
 }
 
-int get_bypass_info(int if_index, struct bp_info *bp_info)
+static int get_bypass_info(int if_index, struct bp_info *bp_info)
 {
        int ret = 0;
        if (is_dev_sd(if_index)) {
@@ -468,14 +468,14 @@ int get_bypass_info(int if_index, struct bp_info *bp_info)
        return ret;
 }
 
-int init_lib_module()
+int init_lib_module(void)
 {
 
        printk(VERSION);
        return 0;
 }
 
-void cleanup_lib_module()
+void cleanup_lib_module(void)
 {
 }
 
index 76fc2e554f3522453c2d1b9a3058a129d8e2f3a0..c8375a26816b2b1799c760c40e2a4e441f93713f 100644 (file)
@@ -76,6 +76,7 @@
 #include <linux/bitops.h>
 #include <linux/io.h>
 #include <linux/netdevice.h>
+#include <linux/crc32.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
 #include <linux/delay.h>
@@ -189,76 +190,14 @@ static inline void slic_reg64_write(struct adapter *adapter, void __iomem *reg,
                                adapter->bit64reglock.flags);
 }
 
-/*
- * Functions to obtain the CRC corresponding to the destination mac address.
- * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
- * the polynomial:
- *   x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 +
- *   x^4 + x^2 + x^1.
- *
- * After the CRC for the 6 bytes is generated (but before the value is
- * complemented),
- * we must then transpose the value and return bits 30-23.
- *
- */
-static u32 slic_crc_table[256];        /* Table of CRCs for all possible byte values */
-static u32 slic_crc_init;      /* Is table initialized */
-
-/*
- *  Contruct the CRC32 table
- */
-static void slic_mcast_init_crc32(void)
-{
-       u32 c;                  /*  CRC reg                      */
-       u32 e = 0;              /*  Poly X-or pattern            */
-       int i;                  /*  counter                      */
-       int k;                  /*  byte being shifted into crc  */
-
-       static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
-
-       for (i = 0; i < ARRAY_SIZE(p); i++)
-               e |= 1L << (31 - p[i]);
-
-       for (i = 1; i < 256; i++) {
-               c = i;
-               for (k = 8; k; k--)
-                       c = c & 1 ? (c >> 1) ^ e : c >> 1;
-               slic_crc_table[i] = c;
-       }
-}
-
-/*
- *  Return the MAC hast as described above.
- */
-static unsigned char slic_mcast_get_mac_hash(char *macaddr)
-{
-       u32 crc;
-       char *p;
-       int i;
-       unsigned char machash = 0;
-
-       if (!slic_crc_init) {
-               slic_mcast_init_crc32();
-               slic_crc_init = 1;
-       }
-
-       crc = 0xFFFFFFFF;       /* Preload shift register, per crc-32 spec */
-       for (i = 0, p = macaddr; i < 6; ++p, ++i)
-               crc = (crc >> 8) ^ slic_crc_table[(crc ^ *p) & 0xFF];
-
-       /* Return bits 1-8, transposed */
-       for (i = 1; i < 9; i++)
-               machash |= (((crc >> i) & 1) << (8 - i));
-
-       return machash;
-}
-
 static void slic_mcast_set_bit(struct adapter *adapter, char *address)
 {
        unsigned char crcpoly;
 
        /* Get the CRC polynomial for the mac address */
-       crcpoly = slic_mcast_get_mac_hash(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 only have space on the SLIC for 64 entries.  Lop
         * off the top two bits. (2^6 = 64)
@@ -901,10 +840,9 @@ static void slic_timer_load_check(ulong cardaddr)
        u32 load = card->events;
        u32 level = 0;
 
-       intagg = &adapter->slic_regs->slic_intagg;
-
        if ((adapter) && (adapter->state == ADAPT_UP) &&
            (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
+               intagg = &adapter->slic_regs->slic_intagg;
                if (adapter->devid == SLIC_1GB_DEVICE_ID) {
                        if (adapter->linkspeed == LINK_1000MB)
                                level = 100;
@@ -1061,7 +999,8 @@ static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
        if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
                struct slic_shmem *pshmem;
 
-               pshmem = (struct slic_shmem *)adapter->phys_shmem;
+               pshmem = (struct slic_shmem *)(unsigned long)
+                        adapter->phys_shmem;
 #if BITS_PER_LONG == 64
                slic_upr_queue_request(adapter,
                                       SLIC_UPR_RLSR,
@@ -1415,7 +1354,7 @@ static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
                slic_reg64_write(adapter, &adapter->slic_regs->slic_rbar64,
                        (rspq->paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
                        &adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
-               rspq->pageindex = (++rspq->pageindex) % rspq->num_pages;
+               rspq->pageindex = (rspq->pageindex + 1) % rspq->num_pages;
                rspq->offset = 0;
                rspq->rspbuf = (struct slic_rspbuf *)
                                                rspq->vaddr[rspq->pageindex];
@@ -1693,10 +1632,11 @@ retry_rcvqfill:
 #endif
                skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
                if (skb) {
-                       paddr = (void *)pci_map_single(adapter->pcidev,
-                                                         skb->data,
-                                                         SLIC_RCVQ_RCVBUFSIZE,
-                                                         PCI_DMA_FROMDEVICE);
+                       paddr = (void *)(unsigned long)
+                               pci_map_single(adapter->pcidev,
+                                              skb->data,
+                                              SLIC_RCVQ_RCVBUFSIZE,
+                                              PCI_DMA_FROMDEVICE);
                        paddrl = SLIC_GET_ADDR_LOW(paddr);
                        paddrh = SLIC_GET_ADDR_HIGH(paddr);
 
@@ -1843,8 +1783,9 @@ static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
        struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
        struct device *dev;
 
-       paddr = (void *)pci_map_single(adapter->pcidev, skb->head,
-                                 SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
+       paddr = (void *)(unsigned long)
+               pci_map_single(adapter->pcidev, skb->head,
+                              SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
        rcvbuf->status = 0;
        skb->next = NULL;
 
@@ -2341,7 +2282,7 @@ static void slic_link_event_handler(struct adapter *adapter)
                return;
        }
 
-       pshmem = (struct slic_shmem *)adapter->phys_shmem;
+       pshmem = (struct slic_shmem *)(unsigned long)adapter->phys_shmem;
 
 #if BITS_PER_LONG == 64
        status = slic_upr_request(adapter,
@@ -2368,7 +2309,7 @@ static void slic_init_cleanup(struct adapter *adapter)
                                    sizeof(struct slic_shmem),
                                    adapter->pshmem, adapter->phys_shmem);
                adapter->pshmem = NULL;
-               adapter->phys_shmem = (dma_addr_t) NULL;
+               adapter->phys_shmem = (dma_addr_t)(unsigned long)NULL;
        }
 
        if (adapter->pingtimerset) {
@@ -2787,7 +2728,6 @@ static netdev_tx_t slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
        struct adapter *adapter = netdev_priv(dev);
        struct slic_hostcmd *hcmd = NULL;
        u32 status = 0;
-       u32 skbtype = NORMAL_ETHFRAME;
        void *offloadcmd = NULL;
 
        card = adapter->card;
@@ -2801,19 +2741,16 @@ static netdev_tx_t slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
                goto xmit_fail;
        }
 
-       if (skbtype == NORMAL_ETHFRAME) {
-               hcmd = slic_cmdq_getfree(adapter);
-               if (!hcmd) {
-                       adapter->xmitq_full = 1;
-                       status = XMIT_FAIL_HOSTCMD_FAIL;
-                       goto xmit_fail;
-               }
-               hcmd->skb = skb;
-               hcmd->busy = 1;
-               hcmd->type = SLIC_CMD_DUMB;
-               if (skbtype == NORMAL_ETHFRAME)
-                       slic_xmit_build_request(adapter, hcmd, skb);
+       hcmd = slic_cmdq_getfree(adapter);
+       if (!hcmd) {
+               adapter->xmitq_full = 1;
+               status = XMIT_FAIL_HOSTCMD_FAIL;
+               goto xmit_fail;
        }
+       hcmd->skb = skb;
+       hcmd->busy = 1;
+       hcmd->type = SLIC_CMD_DUMB;
+       slic_xmit_build_request(adapter, hcmd, skb);
        dev->stats.tx_packets++;
        dev->stats.tx_bytes += skb->len;
 
@@ -2839,7 +2776,7 @@ static netdev_tx_t slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
 xmit_done:
        return NETDEV_TX_OK;
 xmit_fail:
-       slic_xmit_fail(adapter, skb, offloadcmd, skbtype, status);
+       slic_xmit_fail(adapter, skb, offloadcmd, NORMAL_ETHFRAME, status);
        goto xmit_done;
 }
 
@@ -2946,7 +2883,8 @@ static int slic_if_init(struct adapter *adapter)
        mdelay(1);
 
        if (!adapter->isp_initialized) {
-               pshmem = (struct slic_shmem *)adapter->phys_shmem;
+               pshmem = (struct slic_shmem *)(unsigned long)
+                        adapter->phys_shmem;
 
                spin_lock_irqsave(&adapter->bit64reglock.lock,
                                        adapter->bit64reglock.flags);
@@ -3348,7 +3286,8 @@ static int slic_card_init(struct sliccard *card, struct adapter *adapter)
                }
                slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
                mdelay(1);
-               pshmem = (struct slic_shmem *)adapter->phys_shmem;
+               pshmem = (struct slic_shmem *)(unsigned long)
+                        adapter->phys_shmem;
 
                spin_lock_irqsave(&adapter->bit64reglock.lock,
                                        adapter->bit64reglock.flags);
@@ -3648,11 +3587,12 @@ static u32 slic_card_locate(struct adapter *adapter)
 
        while (physcard) {
                for (i = 0; i < SLIC_MAX_PORTS; i++) {
-                       if (!physcard->adapter[i])
-                               continue;
-                       else
+                       if (physcard->adapter[i])
                                break;
                }
+               if (i == SLIC_MAX_PORTS)
+                       break;
+
                if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
                        break;
                physcard = physcard->next;
index 0764bbbfd497d78696f139e10d99e588cb2da431..8add64b1cb0940f69d783083588d65994c5c0e5c 100644 (file)
@@ -1006,15 +1006,7 @@ static int smtcfb_pci_resume(struct device *device)
        return 0;
 }
 
-static const struct dev_pm_ops sm7xx_pm_ops = {
-       .suspend = smtcfb_pci_suspend,
-       .resume = smtcfb_pci_resume,
-       .freeze = smtcfb_pci_suspend,
-       .thaw = smtcfb_pci_resume,
-       .poweroff = smtcfb_pci_suspend,
-       .restore = smtcfb_pci_resume,
-};
-
+static SIMPLE_DEV_PM_OPS(sm7xx_pm_ops, smtcfb_pci_suspend, smtcfb_pci_resume);
 #define SM7XX_PM_OPS (&sm7xx_pm_ops)
 
 #else  /* !CONFIG_PM */
index 35f647ce1f1e476763668dbeadc5936063ad87cf..d6d9264e4ca7992e994bb19ecb08f836d40b1619 100644 (file)
@@ -617,9 +617,9 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
                        len = E_INC;
                else
                        len = E_SET;
-               speakup_s2i(cp, &value);
+               value = simple_strtol(cp, NULL, 10);
                ret = spk_set_num_var(value, param, len);
-               if (ret == E_RANGE) {
+               if (ret == -ERANGE) {
                        var_data = param->data;
                        pr_warn("value for %s out of range, expect %d to %d\n",
                                attr->attr.name,
@@ -637,7 +637,7 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
                cp = (char *) buf;
                cp[len] = '\0';
                ret = spk_set_string_var(buf, param, len);
-               if (ret == E_TOOLONG)
+               if (ret == -E2BIG)
                        pr_warn("value too long for %s\n",
                                        attr->attr.name);
                break;
@@ -670,7 +670,7 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
        }
        spk_unlock(flags);
 
-       if (ret == SET_DEFAULT)
+       if (ret == -ERESTART)
                pr_info("%s reset to default value\n", attr->attr.name);
        return count;
 }
index 9916e94aa3612323f55206cb42c11b75ca56e5df..6c7b55c2947d0f0f872b6d5dca65af7fd518ba65 100644 (file)
@@ -1892,7 +1892,7 @@ oops:
                spk_special_handler = NULL;
                return 1;
        }
-       cp = speakup_s2i(goto_buf, &go_pos);
+       go_pos = simple_strtol(goto_buf, &cp, 10);
        goto_pos = (u_long) go_pos;
        if (*cp == 'x') {
                if (*goto_buf < '0')
index 22f0fbb85f42da201c47a70040808278ecff7779..c387a02fc1c2bdf97fe8f21892b95311ab7d5c21 100644 (file)
 #define IS_CHAR(x, type) (spk_chartab[((u_char)x)]&type)
 #define IS_TYPE(x, type) ((spk_chartab[((u_char)x)]&type) == type)
 
-#define SET_DEFAULT -4
-#define E_RANGE -3
-#define E_TOOLONG -2
-#define E_UNDEF -1
-
 extern int speakup_thread(void *data);
 extern void spk_reset_default_chars(void);
 extern void spk_reset_default_chartab(void);
@@ -58,7 +53,6 @@ void spk_reset_index_count(int sc);
 void spk_get_index_count(int *linecount, int *sentcount);
 extern int spk_set_key_info(const u_char *key_info, u_char *k_buffer);
 extern char *spk_strlwr(char *s);
-extern char *speakup_s2i(char *start, int *dest);
 extern char *spk_s2uchar(char *start, char *dest);
 extern char *spk_xlate(char *s);
 extern int speakup_kobj_init(void);
index f8c1e457d389c7ff626312dead450441fc5d55ca..be61a4ee78dd4bd3ca26c9e493a9e25c207c6e29 100644 (file)
@@ -184,19 +184,19 @@ int spk_set_num_var(int input, struct st_var_header *var, int how)
        char buf[32];
        char *cp;
        struct var_t *var_data = var->data;
+
        if (var_data == NULL)
-               return E_UNDEF;
+               return -ENODATA;
 
        if (how == E_NEW_DEFAULT) {
                if (input < var_data->u.n.low || input > var_data->u.n.high)
-                       ret = E_RANGE;
-               else
-                       var_data->u.n.default_val = input;
-               return ret;
+                       return -ERANGE;
+               var_data->u.n.default_val = input;
+               return 0;
        }
        if (how == E_DEFAULT) {
                val = var_data->u.n.default_val;
-               ret = SET_DEFAULT;
+               ret = -ERESTART;
        } else {
                if (how == E_SET)
                        val = input;
@@ -207,7 +207,7 @@ int spk_set_num_var(int input, struct st_var_header *var, int how)
                else if (how == E_DEC)
                        val -= input;
                if (val < var_data->u.n.low || val > var_data->u.n.high)
-                       return E_RANGE;
+                       return -ERANGE;
        }
        var_data->u.n.value = val;
        if (var->var_type == VAR_TIME && p_val != NULL) {
@@ -246,25 +246,25 @@ int spk_set_num_var(int input, struct st_var_header *var, int how)
 
 int spk_set_string_var(const char *page, struct st_var_header *var, int len)
 {
-       int ret = 0;
        struct var_t *var_data = var->data;
+
        if (var_data == NULL)
-               return E_UNDEF;
+               return -ENODATA;
        if (len > MAXVARLEN)
-               return -E_TOOLONG;
+               return -E2BIG;
        if (!len) {
                if (!var_data->u.s.default_val)
                        return 0;
-               ret = SET_DEFAULT;
                if (!var->p_val)
                        var->p_val = var_data->u.s.default_val;
                if (var->p_val != var_data->u.s.default_val)
                        strcpy((char *)var->p_val, var_data->u.s.default_val);
+               return -ERESTART;
        } else if (var->p_val)
                strcpy((char *)var->p_val, page);
        else
-               return -E_TOOLONG;
-       return ret;
+               return -E2BIG;
+       return 0;
 }
 
 /* spk_set_mask_bits sets or clears the punc/delim/repeat bits,
@@ -319,38 +319,10 @@ char *spk_strlwr(char *s)
        return s;
 }
 
-char *speakup_s2i(char *start, int *dest)
-{
-       int val;
-       char ch = *start;
-       if (ch == '-' || ch == '+')
-               start++;
-       if (*start < '0' || *start > '9')
-               return start;
-       val = (*start) - '0';
-       start++;
-       while (*start >= '0' && *start <= '9') {
-               val *= 10;
-               val += (*start) - '0';
-               start++;
-       }
-       if (ch == '-')
-               *dest = -val;
-       else
-               *dest = val;
-       return start;
-}
-
 char *spk_s2uchar(char *start, char *dest)
 {
        int val = 0;
-       while (*start && *start <= SPACE)
-               start++;
-       while (*start >= '0' && *start <= '9') {
-               val *= 10;
-               val += (*start) - '0';
-               start++;
-       }
+       val = simple_strtoul(skip_spaces(start), &start, 10);
        if (*start == ',')
                start++;
        *dest = (u_char)val;
index 6a21f67af086f47d969b8d096d64b9fdf1d61b7b..a126b25c82d52dd1de7ae670654206fece97f8cc 100644 (file)
@@ -649,7 +649,7 @@ static int synpatics_rmi4_touchpad_detect(struct synaptics_rmi4_data *pdata,
  *
  * This function calls to configures the rmi4 touchpad device
  */
-int synaptics_rmi4_touchpad_config(struct synaptics_rmi4_data *pdata,
+static int synaptics_rmi4_touchpad_config(struct synaptics_rmi4_data *pdata,
                                                struct synaptics_rmi4_fn *rfi)
 {
        /*
diff --git a/drivers/staging/ti-soc-thermal/Kconfig b/drivers/staging/ti-soc-thermal/Kconfig
new file mode 100644 (file)
index 0000000..e81375f
--- /dev/null
@@ -0,0 +1,48 @@
+config TI_SOC_THERMAL
+       tristate "Texas Instruments SoCs temperature sensor driver"
+       depends on THERMAL
+       depends on ARCH_HAS_BANDGAP
+       help
+         If you say yes here you get support for the Texas Instruments
+         OMAP4460+ on die bandgap temperature sensor support. The register
+         set is part of system control module.
+
+         This includes alert interrupts generation and also the TSHUT
+         support.
+
+config TI_THERMAL
+       bool "Texas Instruments SoCs thermal framework support"
+       depends on TI_SOC_THERMAL
+       depends on CPU_THERMAL
+       help
+         If you say yes here you want to get support for generic thermal
+         framework for the Texas Instruments on die bandgap temperature sensor.
+
+         This includes trip points definitions, extrapolation rules and
+         CPU cooling device bindings.
+
+config OMAP4_THERMAL
+       bool "Texas Instruments OMAP4 thermal support"
+       depends on TI_SOC_THERMAL
+       depends on ARCH_OMAP4
+       help
+         If you say yes here you get thermal support for the Texas Instruments
+         OMAP4 SoC family. The current chip supported are:
+          - OMAP4430
+          - OMAP4460
+          - OMAP4470
+
+         This includes alert interrupts generation and also the TSHUT
+         support.
+
+config OMAP5_THERMAL
+       bool "Texas Instruments OMAP5 thermal support"
+       depends on TI_SOC_THERMAL
+       depends on SOC_OMAP5
+       help
+         If you say yes here you get thermal support for the Texas Instruments
+         OMAP5 SoC family. The current chip supported are:
+          - OMAP5430
+
+         This includes alert interrupts generation and also the TSHUT
+         support.
diff --git a/drivers/staging/ti-soc-thermal/Makefile b/drivers/staging/ti-soc-thermal/Makefile
new file mode 100644 (file)
index 0000000..0ca034f
--- /dev/null
@@ -0,0 +1,5 @@
+obj-$(CONFIG_TI_SOC_THERMAL)           += ti-soc-thermal.o
+ti-soc-thermal-y                       := ti-bandgap.o
+ti-soc-thermal-$(CONFIG_TI_THERMAL)    += ti-thermal-common.o
+ti-soc-thermal-$(CONFIG_OMAP4_THERMAL) += omap4-thermal-data.o
+ti-soc-thermal-$(CONFIG_OMAP5_THERMAL) += omap5-thermal-data.o
diff --git a/drivers/staging/ti-soc-thermal/TODO b/drivers/staging/ti-soc-thermal/TODO
new file mode 100644 (file)
index 0000000..9b4c841
--- /dev/null
@@ -0,0 +1,24 @@
+List of TODOs (by Eduardo Valentin)
+
+on ti-bandgap.c:
+- Test every exposed API to userland
+- Add support to hwmon
+- Revisit PM support
+- Revisit data structures and simplify them
+- Once SCM-core api settles, update this driver accordingly
+
+on ti-thermal-common.c/ti-thermal.h:
+- Revisit extrapolation constants for O4/O5
+- Revisit need for locking
+- Revisit trips and its definitions
+- Revisit trending
+
+on omap5-thermal.c
+- Add support for GPU cooling
+
+generally:
+- make checkpatch.pl and sparse happy
+- make sure this code works on OMAP4430, OMAP4460 and OMAP5430
+- update documentation
+
+Copy patches to Eduardo Valentin <eduardo.valentin@ti.com>
diff --git a/drivers/staging/ti-soc-thermal/omap4-thermal-data.c b/drivers/staging/ti-soc-thermal/omap4-thermal-data.c
new file mode 100644 (file)
index 0000000..49d0324
--- /dev/null
@@ -0,0 +1,265 @@
+/*
+ * OMAP4 thermal driver.
+ *
+ * Copyright (C) 2011-2012 Texas Instruments Inc.
+ * Contact:
+ *     Eduardo Valentin <eduardo.valentin@ti.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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 "ti-thermal.h"
+#include "ti-bandgap.h"
+#include "omap4xxx-bandgap.h"
+
+/*
+ * OMAP4430 has one instance of thermal sensor for MPU
+ * need to describe the individual bit fields
+ */
+static struct temp_sensor_registers
+omap4430_mpu_temp_sensor_registers = {
+       .temp_sensor_ctrl = OMAP4430_TEMP_SENSOR_CTRL_OFFSET,
+       .bgap_tempsoff_mask = OMAP4430_BGAP_TEMPSOFF_MASK,
+       .bgap_soc_mask = OMAP4430_BGAP_TEMP_SENSOR_SOC_MASK,
+       .bgap_eocz_mask = OMAP4430_BGAP_TEMP_SENSOR_EOCZ_MASK,
+       .bgap_dtemp_mask = OMAP4430_BGAP_TEMP_SENSOR_DTEMP_MASK,
+
+       .bgap_mode_ctrl = OMAP4430_TEMP_SENSOR_CTRL_OFFSET,
+       .mode_ctrl_mask = OMAP4430_SINGLE_MODE_MASK,
+
+       .bgap_efuse = OMAP4430_FUSE_OPP_BGAP,
+};
+
+/* Thresholds and limits for OMAP4430 MPU temperature sensor */
+static struct temp_sensor_data omap4430_mpu_temp_sensor_data = {
+       .min_freq = OMAP4430_MIN_FREQ,
+       .max_freq = OMAP4430_MAX_FREQ,
+       .max_temp = OMAP4430_MAX_TEMP,
+       .min_temp = OMAP4430_MIN_TEMP,
+       .hyst_val = OMAP4430_HYST_VAL,
+};
+
+/*
+ * Temperature values in milli degree celsius
+ * ADC code values from 530 to 923
+ */
+static const int
+omap4430_adc_to_temp[OMAP4430_ADC_END_VALUE - OMAP4430_ADC_START_VALUE + 1] = {
+       -38000, -35000, -34000, -32000, -30000, -28000, -26000, -24000, -22000,
+       -20000, -18000, -17000, -15000, -13000, -12000, -10000, -8000, -6000,
+       -5000, -3000, -1000, 0, 2000, 3000, 5000, 6000, 8000, 10000, 12000,
+       13000, 15000, 17000, 19000, 21000, 23000, 25000, 27000, 28000, 30000,
+       32000, 33000, 35000, 37000, 38000, 40000, 42000, 43000, 45000, 47000,
+       48000, 50000, 52000, 53000, 55000, 57000, 58000, 60000, 62000, 64000,
+       66000, 68000, 70000, 71000, 73000, 75000, 77000, 78000, 80000, 82000,
+       83000, 85000, 87000, 88000, 90000, 92000, 93000, 95000, 97000, 98000,
+       100000, 102000, 103000, 105000, 107000, 109000, 111000, 113000, 115000,
+       117000, 118000, 120000, 122000, 123000,
+};
+
+/* OMAP4430 data */
+const struct ti_bandgap_data omap4430_data = {
+       .features = TI_BANDGAP_FEATURE_MODE_CONFIG |
+                       TI_BANDGAP_FEATURE_CLK_CTRL |
+                       TI_BANDGAP_FEATURE_POWER_SWITCH,
+       .fclock_name = "bandgap_fclk",
+       .div_ck_name = "bandgap_fclk",
+       .conv_table = omap4430_adc_to_temp,
+       .adc_start_val = OMAP4430_ADC_START_VALUE,
+       .adc_end_val = OMAP4430_ADC_END_VALUE,
+       .expose_sensor = ti_thermal_expose_sensor,
+       .remove_sensor = ti_thermal_remove_sensor,
+       .sensors = {
+               {
+               .registers = &omap4430_mpu_temp_sensor_registers,
+               .ts_data = &omap4430_mpu_temp_sensor_data,
+               .domain = "cpu",
+               .slope = 0,
+               .constant = 20000,
+               .slope_pcb = 0,
+               .constant_pcb = 20000,
+               .register_cooling = ti_thermal_register_cpu_cooling,
+               .unregister_cooling = ti_thermal_unregister_cpu_cooling,
+               },
+       },
+       .sensor_count = 1,
+};
+/*
+ * OMAP4460 has one instance of thermal sensor for MPU
+ * need to describe the individual bit fields
+ */
+static struct temp_sensor_registers
+omap4460_mpu_temp_sensor_registers = {
+       .temp_sensor_ctrl = OMAP4460_TEMP_SENSOR_CTRL_OFFSET,
+       .bgap_tempsoff_mask = OMAP4460_BGAP_TEMPSOFF_MASK,
+       .bgap_soc_mask = OMAP4460_BGAP_TEMP_SENSOR_SOC_MASK,
+       .bgap_eocz_mask = OMAP4460_BGAP_TEMP_SENSOR_EOCZ_MASK,
+       .bgap_dtemp_mask = OMAP4460_BGAP_TEMP_SENSOR_DTEMP_MASK,
+
+       .bgap_mask_ctrl = OMAP4460_BGAP_CTRL_OFFSET,
+       .mask_hot_mask = OMAP4460_MASK_HOT_MASK,
+       .mask_cold_mask = OMAP4460_MASK_COLD_MASK,
+
+       .bgap_mode_ctrl = OMAP4460_BGAP_CTRL_OFFSET,
+       .mode_ctrl_mask = OMAP4460_SINGLE_MODE_MASK,
+
+       .bgap_counter = OMAP4460_BGAP_COUNTER_OFFSET,
+       .counter_mask = OMAP4460_COUNTER_MASK,
+
+       .bgap_threshold = OMAP4460_BGAP_THRESHOLD_OFFSET,
+       .threshold_thot_mask = OMAP4460_T_HOT_MASK,
+       .threshold_tcold_mask = OMAP4460_T_COLD_MASK,
+
+       .tshut_threshold = OMAP4460_BGAP_TSHUT_OFFSET,
+       .tshut_hot_mask = OMAP4460_TSHUT_HOT_MASK,
+       .tshut_cold_mask = OMAP4460_TSHUT_COLD_MASK,
+
+       .bgap_status = OMAP4460_BGAP_STATUS_OFFSET,
+       .status_clean_stop_mask = OMAP4460_CLEAN_STOP_MASK,
+       .status_bgap_alert_mask = OMAP4460_BGAP_ALERT_MASK,
+       .status_hot_mask = OMAP4460_HOT_FLAG_MASK,
+       .status_cold_mask = OMAP4460_COLD_FLAG_MASK,
+
+       .bgap_efuse = OMAP4460_FUSE_OPP_BGAP,
+};
+
+/* Thresholds and limits for OMAP4460 MPU temperature sensor */
+static struct temp_sensor_data omap4460_mpu_temp_sensor_data = {
+       .tshut_hot = OMAP4460_TSHUT_HOT,
+       .tshut_cold = OMAP4460_TSHUT_COLD,
+       .t_hot = OMAP4460_T_HOT,
+       .t_cold = OMAP4460_T_COLD,
+       .min_freq = OMAP4460_MIN_FREQ,
+       .max_freq = OMAP4460_MAX_FREQ,
+       .max_temp = OMAP4460_MAX_TEMP,
+       .min_temp = OMAP4460_MIN_TEMP,
+       .hyst_val = OMAP4460_HYST_VAL,
+       .update_int1 = 1000,
+       .update_int2 = 2000,
+};
+
+/*
+ * Temperature values in milli degree celsius
+ * ADC code values from 530 to 923
+ */
+static const int
+omap4460_adc_to_temp[OMAP4460_ADC_END_VALUE - OMAP4460_ADC_START_VALUE + 1] = {
+       -40000, -40000, -40000, -40000, -39800, -39400, -39000, -38600, -38200,
+       -37800, -37300, -36800, -36400, -36000, -35600, -35200, -34800,
+       -34300, -33800, -33400, -33000, -32600, -32200, -31800, -31300,
+       -30800, -30400, -30000, -29600, -29200, -28700, -28200, -27800,
+       -27400, -27000, -26600, -26200, -25700, -25200, -24800, -24400,
+       -24000, -23600, -23200, -22700, -22200, -21800, -21400, -21000,
+       -20600, -20200, -19700, -19200, -18800, -18400, -18000, -17600,
+       -17200, -16700, -16200, -15800, -15400, -15000, -14600, -14200,
+       -13700, -13200, -12800, -12400, -12000, -11600, -11200, -10700,
+       -10200, -9800, -9400, -9000, -8600, -8200, -7700, -7200, -6800,
+       -6400, -6000, -5600, -5200, -4800, -4300, -3800, -3400, -3000,
+       -2600, -2200, -1800, -1300, -800, -400, 0, 400, 800, 1200, 1600,
+       2100, 2600, 3000, 3400, 3800, 4200, 4600, 5100, 5600, 6000, 6400,
+       6800, 7200, 7600, 8000, 8500, 9000, 9400, 9800, 10200, 10600, 11000,
+       11400, 11900, 12400, 12800, 13200, 13600, 14000, 14400, 14800,
+       15300, 15800, 16200, 16600, 17000, 17400, 17800, 18200, 18700,
+       19200, 19600, 20000, 20400, 20800, 21200, 21600, 22100, 22600,
+       23000, 23400, 23800, 24200, 24600, 25000, 25400, 25900, 26400,
+       26800, 27200, 27600, 28000, 28400, 28800, 29300, 29800, 30200,
+       30600, 31000, 31400, 31800, 32200, 32600, 33100, 33600, 34000,
+       34400, 34800, 35200, 35600, 36000, 36400, 36800, 37300, 37800,
+       38200, 38600, 39000, 39400, 39800, 40200, 40600, 41100, 41600,
+       42000, 42400, 42800, 43200, 43600, 44000, 44400, 44800, 45300,
+       45800, 46200, 46600, 47000, 47400, 47800, 48200, 48600, 49000,
+       49500, 50000, 50400, 50800, 51200, 51600, 52000, 52400, 52800,
+       53200, 53700, 54200, 54600, 55000, 55400, 55800, 56200, 56600,
+       57000, 57400, 57800, 58200, 58700, 59200, 59600, 60000, 60400,
+       60800, 61200, 61600, 62000, 62400, 62800, 63300, 63800, 64200,
+       64600, 65000, 65400, 65800, 66200, 66600, 67000, 67400, 67800,
+       68200, 68700, 69200, 69600, 70000, 70400, 70800, 71200, 71600,
+       72000, 72400, 72800, 73200, 73600, 74100, 74600, 75000, 75400,
+       75800, 76200, 76600, 77000, 77400, 77800, 78200, 78600, 79000,
+       79400, 79800, 80300, 80800, 81200, 81600, 82000, 82400, 82800,
+       83200, 83600, 84000, 84400, 84800, 85200, 85600, 86000, 86400,
+       86800, 87300, 87800, 88200, 88600, 89000, 89400, 89800, 90200,
+       90600, 91000, 91400, 91800, 92200, 92600, 93000, 93400, 93800,
+       94200, 94600, 95000, 95500, 96000, 96400, 96800, 97200, 97600,
+       98000, 98400, 98800, 99200, 99600, 100000, 100400, 100800, 101200,
+       101600, 102000, 102400, 102800, 103200, 103600, 104000, 104400,
+       104800, 105200, 105600, 106100, 106600, 107000, 107400, 107800,
+       108200, 108600, 109000, 109400, 109800, 110200, 110600, 111000,
+       111400, 111800, 112200, 112600, 113000, 113400, 113800, 114200,
+       114600, 115000, 115400, 115800, 116200, 116600, 117000, 117400,
+       117800, 118200, 118600, 119000, 119400, 119800, 120200, 120600,
+       121000, 121400, 121800, 122200, 122600, 123000, 123400, 123800, 124200,
+       124600, 124900, 125000, 125000, 125000, 125000
+};
+
+/* OMAP4460 data */
+const struct ti_bandgap_data omap4460_data = {
+       .features = TI_BANDGAP_FEATURE_TSHUT |
+                       TI_BANDGAP_FEATURE_TSHUT_CONFIG |
+                       TI_BANDGAP_FEATURE_TALERT |
+                       TI_BANDGAP_FEATURE_MODE_CONFIG |
+                       TI_BANDGAP_FEATURE_POWER_SWITCH |
+                       TI_BANDGAP_FEATURE_CLK_CTRL |
+                       TI_BANDGAP_FEATURE_COUNTER,
+       .fclock_name = "bandgap_ts_fclk",
+       .div_ck_name = "div_ts_ck",
+       .conv_table = omap4460_adc_to_temp,
+       .adc_start_val = OMAP4460_ADC_START_VALUE,
+       .adc_end_val = OMAP4460_ADC_END_VALUE,
+       .expose_sensor = ti_thermal_expose_sensor,
+       .remove_sensor = ti_thermal_remove_sensor,
+       .sensors = {
+               {
+               .registers = &omap4460_mpu_temp_sensor_registers,
+               .ts_data = &omap4460_mpu_temp_sensor_data,
+               .domain = "cpu",
+               .slope = OMAP_GRADIENT_SLOPE_4460,
+               .constant = OMAP_GRADIENT_CONST_4460,
+               .slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_4460,
+               .constant_pcb = OMAP_GRADIENT_CONST_W_PCB_4460,
+               .register_cooling = ti_thermal_register_cpu_cooling,
+               .unregister_cooling = ti_thermal_unregister_cpu_cooling,
+               },
+       },
+       .sensor_count = 1,
+};
+
+/* OMAP4470 data */
+const struct ti_bandgap_data omap4470_data = {
+       .features = TI_BANDGAP_FEATURE_TSHUT |
+                       TI_BANDGAP_FEATURE_TSHUT_CONFIG |
+                       TI_BANDGAP_FEATURE_TALERT |
+                       TI_BANDGAP_FEATURE_MODE_CONFIG |
+                       TI_BANDGAP_FEATURE_POWER_SWITCH |
+                       TI_BANDGAP_FEATURE_CLK_CTRL |
+                       TI_BANDGAP_FEATURE_COUNTER,
+       .fclock_name = "bandgap_ts_fclk",
+       .div_ck_name = "div_ts_ck",
+       .conv_table = omap4460_adc_to_temp,
+       .adc_start_val = OMAP4460_ADC_START_VALUE,
+       .adc_end_val = OMAP4460_ADC_END_VALUE,
+       .expose_sensor = ti_thermal_expose_sensor,
+       .remove_sensor = ti_thermal_remove_sensor,
+       .sensors = {
+               {
+               .registers = &omap4460_mpu_temp_sensor_registers,
+               .ts_data = &omap4460_mpu_temp_sensor_data,
+               .domain = "cpu",
+               .slope = OMAP_GRADIENT_SLOPE_4470,
+               .constant = OMAP_GRADIENT_CONST_4470,
+               .slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_4470,
+               .constant_pcb = OMAP_GRADIENT_CONST_W_PCB_4470,
+               .register_cooling = ti_thermal_register_cpu_cooling,
+               .unregister_cooling = ti_thermal_unregister_cpu_cooling,
+               },
+       },
+       .sensor_count = 1,
+};
diff --git a/drivers/staging/ti-soc-thermal/omap4xxx-bandgap.h b/drivers/staging/ti-soc-thermal/omap4xxx-bandgap.h
new file mode 100644 (file)
index 0000000..6f2de3a
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ * OMAP4xxx bandgap registers, bitfields and temperature definitions
+ *
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
+ * Contact:
+ *   Eduardo Valentin <eduardo.valentin@ti.com>
+ *
+ * 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.
+ *
+ * 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 St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#ifndef __OMAP4XXX_BANDGAP_H
+#define __OMAP4XXX_BANDGAP_H
+
+/**
+ * *** OMAP4430 ***
+ *
+ * Below, in sequence, are the Register definitions,
+ * the bitfields and the temperature definitions for OMAP4430.
+ */
+
+/**
+ * OMAP4430 register definitions
+ *
+ * Registers are defined as offsets. The offsets are
+ * relative to FUSE_OPP_BGAP on 4430.
+ */
+
+/* OMAP4430.FUSE_OPP_BGAP */
+#define OMAP4430_FUSE_OPP_BGAP                         0x0
+
+/* OMAP4430.TEMP_SENSOR  */
+#define OMAP4430_TEMP_SENSOR_CTRL_OFFSET               0xCC
+
+/**
+ * Register and bit definitions for OMAP4430
+ *
+ * All the macros bellow define the required bits for
+ * controlling temperature on OMAP4430. Bit defines are
+ * grouped by register.
+ */
+
+/* OMAP4430.TEMP_SENSOR bits */
+#define OMAP4430_BGAP_TEMPSOFF_MASK                    BIT(12)
+#define OMAP4430_BGAP_TSHUT_MASK                       BIT(11)
+#define OMAP4430_SINGLE_MODE_MASK                      BIT(10)
+#define OMAP4430_BGAP_TEMP_SENSOR_SOC_MASK             BIT(9)
+#define OMAP4430_BGAP_TEMP_SENSOR_EOCZ_MASK            BIT(8)
+#define OMAP4430_BGAP_TEMP_SENSOR_DTEMP_MASK           (0xff << 0)
+
+/**
+ * Temperature limits and thresholds for OMAP4430
+ *
+ * All the macros bellow are definitions for handling the
+ * ADC conversions and representation of temperature limits
+ * and thresholds for OMAP4430.
+ */
+
+/* ADC conversion table limits */
+#define OMAP4430_ADC_START_VALUE                       0
+#define OMAP4430_ADC_END_VALUE                         127
+/* bandgap clock limits (no control on 4430) */
+#define OMAP4430_MAX_FREQ                              32768
+#define OMAP4430_MIN_FREQ                              32768
+/* sensor limits */
+#define OMAP4430_MIN_TEMP                              -40000
+#define OMAP4430_MAX_TEMP                              125000
+#define OMAP4430_HYST_VAL                              5000
+
+/**
+ * *** OMAP4460 *** Applicable for OMAP4470
+ *
+ * Below, in sequence, are the Register definitions,
+ * the bitfields and the temperature definitions for OMAP4460.
+ */
+
+/**
+ * OMAP4460 register definitions
+ *
+ * Registers are defined as offsets. The offsets are
+ * relative to FUSE_OPP_BGAP on 4460.
+ */
+
+/* OMAP4460.FUSE_OPP_BGAP */
+#define OMAP4460_FUSE_OPP_BGAP                         0x0
+
+/* OMAP4460.TEMP_SENSOR */
+#define OMAP4460_TEMP_SENSOR_CTRL_OFFSET               0xCC
+
+/* OMAP4460.BANDGAP_CTRL */
+#define OMAP4460_BGAP_CTRL_OFFSET                      0x118
+
+/* OMAP4460.BANDGAP_COUNTER */
+#define OMAP4460_BGAP_COUNTER_OFFSET                   0x11C
+
+/* OMAP4460.BANDGAP_THRESHOLD */
+#define OMAP4460_BGAP_THRESHOLD_OFFSET                 0x120
+
+/* OMAP4460.TSHUT_THRESHOLD */
+#define OMAP4460_BGAP_TSHUT_OFFSET                     0x124
+
+/* OMAP4460.BANDGAP_STATUS */
+#define OMAP4460_BGAP_STATUS_OFFSET                    0x128
+
+/**
+ * Register bitfields for OMAP4460
+ *
+ * All the macros bellow define the required bits for
+ * controlling temperature on OMAP4460. Bit defines are
+ * grouped by register.
+ */
+/* OMAP4460.TEMP_SENSOR bits */
+#define OMAP4460_BGAP_TEMPSOFF_MASK                    BIT(13)
+#define OMAP4460_BGAP_TEMP_SENSOR_SOC_MASK             BIT(11)
+#define OMAP4460_BGAP_TEMP_SENSOR_EOCZ_MASK            BIT(10)
+#define OMAP4460_BGAP_TEMP_SENSOR_DTEMP_MASK           (0x3ff << 0)
+
+/* OMAP4460.BANDGAP_CTRL bits */
+#define OMAP4460_SINGLE_MODE_MASK                      BIT(31)
+#define OMAP4460_MASK_HOT_MASK                         BIT(1)
+#define OMAP4460_MASK_COLD_MASK                                BIT(0)
+
+/* OMAP4460.BANDGAP_COUNTER bits */
+#define OMAP4460_COUNTER_MASK                          (0xffffff << 0)
+
+/* OMAP4460.BANDGAP_THRESHOLD bits */
+#define OMAP4460_T_HOT_MASK                            (0x3ff << 16)
+#define OMAP4460_T_COLD_MASK                           (0x3ff << 0)
+
+/* OMAP4460.TSHUT_THRESHOLD bits */
+#define OMAP4460_TSHUT_HOT_MASK                                (0x3ff << 16)
+#define OMAP4460_TSHUT_COLD_MASK                       (0x3ff << 0)
+
+/* OMAP4460.BANDGAP_STATUS bits */
+#define OMAP4460_CLEAN_STOP_MASK                       BIT(3)
+#define OMAP4460_BGAP_ALERT_MASK                       BIT(2)
+#define OMAP4460_HOT_FLAG_MASK                         BIT(1)
+#define OMAP4460_COLD_FLAG_MASK                                BIT(0)
+
+/**
+ * Temperature limits and thresholds for OMAP4460
+ *
+ * All the macros bellow are definitions for handling the
+ * ADC conversions and representation of temperature limits
+ * and thresholds for OMAP4460.
+ */
+
+/* ADC conversion table limits */
+#define OMAP4460_ADC_START_VALUE                       530
+#define OMAP4460_ADC_END_VALUE                         932
+/* bandgap clock limits */
+#define OMAP4460_MAX_FREQ                              1500000
+#define OMAP4460_MIN_FREQ                              1000000
+/* sensor limits */
+#define OMAP4460_MIN_TEMP                              -40000
+#define OMAP4460_MAX_TEMP                              123000
+#define OMAP4460_HYST_VAL                              5000
+/* interrupts thresholds */
+#define OMAP4460_TSHUT_HOT                             900     /* 122 deg C */
+#define OMAP4460_TSHUT_COLD                            895     /* 100 deg C */
+#define OMAP4460_T_HOT                                 800     /* 73 deg C */
+#define OMAP4460_T_COLD                                        795     /* 71 deg C */
+
+#endif /* __OMAP4XXX_BANDGAP_H */
diff --git a/drivers/staging/ti-soc-thermal/omap5-thermal-data.c b/drivers/staging/ti-soc-thermal/omap5-thermal-data.c
new file mode 100644 (file)
index 0000000..0afe9c8
--- /dev/null
@@ -0,0 +1,354 @@
+/*
+ * OMAP5 thermal driver.
+ *
+ * Copyright (C) 2011-2012 Texas Instruments Inc.
+ * Contact:
+ *     Eduardo Valentin <eduardo.valentin@ti.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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 "ti-thermal.h"
+#include "ti-bandgap.h"
+#include "omap5xxx-bandgap.h"
+
+/*
+ * OMAP5430 has three instances of thermal sensor for MPU, GPU & CORE,
+ * need to describe the individual registers and bit fields.
+ */
+
+/*
+ * OMAP5430 MPU thermal sensor register offset and bit-fields
+ */
+static struct temp_sensor_registers
+omap5430_mpu_temp_sensor_registers = {
+       .temp_sensor_ctrl = OMAP5430_TEMP_SENSOR_MPU_OFFSET,
+       .bgap_tempsoff_mask = OMAP5430_BGAP_TEMPSOFF_MASK,
+       .bgap_eocz_mask = OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK,
+       .bgap_dtemp_mask = OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK,
+
+       .bgap_mask_ctrl = OMAP5430_BGAP_CTRL_OFFSET,
+       .mask_hot_mask = OMAP5430_MASK_HOT_MPU_MASK,
+       .mask_cold_mask = OMAP5430_MASK_COLD_MPU_MASK,
+       .mask_sidlemode_mask = OMAP5430_MASK_SIDLEMODE_MASK,
+       .mask_freeze_mask = OMAP5430_MASK_FREEZE_MPU_MASK,
+       .mask_clear_mask = OMAP5430_MASK_CLEAR_MPU_MASK,
+       .mask_clear_accum_mask = OMAP5430_MASK_CLEAR_ACCUM_MPU_MASK,
+
+
+       .bgap_counter = OMAP5430_BGAP_CTRL_OFFSET,
+       .counter_mask = OMAP5430_COUNTER_MASK,
+
+       .bgap_threshold = OMAP5430_BGAP_THRESHOLD_MPU_OFFSET,
+       .threshold_thot_mask = OMAP5430_T_HOT_MASK,
+       .threshold_tcold_mask = OMAP5430_T_COLD_MASK,
+
+       .tshut_threshold = OMAP5430_BGAP_TSHUT_MPU_OFFSET,
+       .tshut_hot_mask = OMAP5430_TSHUT_HOT_MASK,
+       .tshut_cold_mask = OMAP5430_TSHUT_COLD_MASK,
+
+       .bgap_status = OMAP5430_BGAP_STATUS_OFFSET,
+       .status_clean_stop_mask = 0x0,
+       .status_bgap_alert_mask = OMAP5430_BGAP_ALERT_MASK,
+       .status_hot_mask = OMAP5430_HOT_MPU_FLAG_MASK,
+       .status_cold_mask = OMAP5430_COLD_MPU_FLAG_MASK,
+
+       .bgap_cumul_dtemp = OMAP5430_BGAP_CUMUL_DTEMP_MPU_OFFSET,
+       .ctrl_dtemp_0 = OMAP5430_BGAP_DTEMP_MPU_0_OFFSET,
+       .ctrl_dtemp_1 = OMAP5430_BGAP_DTEMP_MPU_1_OFFSET,
+       .ctrl_dtemp_2 = OMAP5430_BGAP_DTEMP_MPU_2_OFFSET,
+       .ctrl_dtemp_3 = OMAP5430_BGAP_DTEMP_MPU_3_OFFSET,
+       .ctrl_dtemp_4 = OMAP5430_BGAP_DTEMP_MPU_4_OFFSET,
+       .bgap_efuse = OMAP5430_FUSE_OPP_BGAP_MPU,
+};
+
+/*
+ * OMAP5430 GPU thermal sensor register offset and bit-fields
+ */
+static struct temp_sensor_registers
+omap5430_gpu_temp_sensor_registers = {
+       .temp_sensor_ctrl = OMAP5430_TEMP_SENSOR_GPU_OFFSET,
+       .bgap_tempsoff_mask = OMAP5430_BGAP_TEMPSOFF_MASK,
+       .bgap_eocz_mask = OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK,
+       .bgap_dtemp_mask = OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK,
+
+       .bgap_mask_ctrl = OMAP5430_BGAP_CTRL_OFFSET,
+       .mask_hot_mask = OMAP5430_MASK_HOT_GPU_MASK,
+       .mask_cold_mask = OMAP5430_MASK_COLD_GPU_MASK,
+       .mask_sidlemode_mask = OMAP5430_MASK_SIDLEMODE_MASK,
+       .mask_freeze_mask = OMAP5430_MASK_FREEZE_GPU_MASK,
+       .mask_clear_mask = OMAP5430_MASK_CLEAR_GPU_MASK,
+       .mask_clear_accum_mask = OMAP5430_MASK_CLEAR_ACCUM_GPU_MASK,
+
+       .bgap_counter = OMAP5430_BGAP_CTRL_OFFSET,
+       .counter_mask = OMAP5430_COUNTER_MASK,
+
+       .bgap_threshold = OMAP5430_BGAP_THRESHOLD_GPU_OFFSET,
+       .threshold_thot_mask = OMAP5430_T_HOT_MASK,
+       .threshold_tcold_mask = OMAP5430_T_COLD_MASK,
+
+       .tshut_threshold = OMAP5430_BGAP_TSHUT_GPU_OFFSET,
+       .tshut_hot_mask = OMAP5430_TSHUT_HOT_MASK,
+       .tshut_cold_mask = OMAP5430_TSHUT_COLD_MASK,
+
+       .bgap_status = OMAP5430_BGAP_STATUS_OFFSET,
+       .status_clean_stop_mask = 0x0,
+       .status_bgap_alert_mask = OMAP5430_BGAP_ALERT_MASK,
+       .status_hot_mask = OMAP5430_HOT_GPU_FLAG_MASK,
+       .status_cold_mask = OMAP5430_COLD_GPU_FLAG_MASK,
+
+       .bgap_cumul_dtemp = OMAP5430_BGAP_CUMUL_DTEMP_GPU_OFFSET,
+       .ctrl_dtemp_0 = OMAP5430_BGAP_DTEMP_GPU_0_OFFSET,
+       .ctrl_dtemp_1 = OMAP5430_BGAP_DTEMP_GPU_1_OFFSET,
+       .ctrl_dtemp_2 = OMAP5430_BGAP_DTEMP_GPU_2_OFFSET,
+       .ctrl_dtemp_3 = OMAP5430_BGAP_DTEMP_GPU_3_OFFSET,
+       .ctrl_dtemp_4 = OMAP5430_BGAP_DTEMP_GPU_4_OFFSET,
+
+       .bgap_efuse = OMAP5430_FUSE_OPP_BGAP_GPU,
+};
+
+/*
+ * OMAP5430 CORE thermal sensor register offset and bit-fields
+ */
+static struct temp_sensor_registers
+omap5430_core_temp_sensor_registers = {
+       .temp_sensor_ctrl = OMAP5430_TEMP_SENSOR_CORE_OFFSET,
+       .bgap_tempsoff_mask = OMAP5430_BGAP_TEMPSOFF_MASK,
+       .bgap_eocz_mask = OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK,
+       .bgap_dtemp_mask = OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK,
+
+       .bgap_mask_ctrl = OMAP5430_BGAP_CTRL_OFFSET,
+       .mask_hot_mask = OMAP5430_MASK_HOT_CORE_MASK,
+       .mask_cold_mask = OMAP5430_MASK_COLD_CORE_MASK,
+       .mask_sidlemode_mask = OMAP5430_MASK_SIDLEMODE_MASK,
+       .mask_freeze_mask = OMAP5430_MASK_FREEZE_CORE_MASK,
+       .mask_clear_mask = OMAP5430_MASK_CLEAR_CORE_MASK,
+       .mask_clear_accum_mask = OMAP5430_MASK_CLEAR_ACCUM_CORE_MASK,
+
+       .bgap_counter = OMAP5430_BGAP_CTRL_OFFSET,
+       .counter_mask = OMAP5430_COUNTER_MASK,
+
+       .bgap_threshold = OMAP5430_BGAP_THRESHOLD_CORE_OFFSET,
+       .threshold_thot_mask = OMAP5430_T_HOT_MASK,
+       .threshold_tcold_mask = OMAP5430_T_COLD_MASK,
+
+       .tshut_threshold = OMAP5430_BGAP_TSHUT_CORE_OFFSET,
+       .tshut_hot_mask = OMAP5430_TSHUT_HOT_MASK,
+       .tshut_cold_mask = OMAP5430_TSHUT_COLD_MASK,
+
+       .bgap_status = OMAP5430_BGAP_STATUS_OFFSET,
+       .status_clean_stop_mask = 0x0,
+       .status_bgap_alert_mask = OMAP5430_BGAP_ALERT_MASK,
+       .status_hot_mask = OMAP5430_HOT_CORE_FLAG_MASK,
+       .status_cold_mask = OMAP5430_COLD_CORE_FLAG_MASK,
+
+       .bgap_cumul_dtemp = OMAP5430_BGAP_CUMUL_DTEMP_CORE_OFFSET,
+       .ctrl_dtemp_0 = OMAP5430_BGAP_DTEMP_CORE_0_OFFSET,
+       .ctrl_dtemp_1 = OMAP5430_BGAP_DTEMP_CORE_1_OFFSET,
+       .ctrl_dtemp_2 = OMAP5430_BGAP_DTEMP_CORE_2_OFFSET,
+       .ctrl_dtemp_3 = OMAP5430_BGAP_DTEMP_CORE_3_OFFSET,
+       .ctrl_dtemp_4 = OMAP5430_BGAP_DTEMP_CORE_4_OFFSET,
+
+       .bgap_efuse = OMAP5430_FUSE_OPP_BGAP_CORE,
+};
+
+/* Thresholds and limits for OMAP5430 MPU temperature sensor */
+static struct temp_sensor_data omap5430_mpu_temp_sensor_data = {
+       .tshut_hot = OMAP5430_MPU_TSHUT_HOT,
+       .tshut_cold = OMAP5430_MPU_TSHUT_COLD,
+       .t_hot = OMAP5430_MPU_T_HOT,
+       .t_cold = OMAP5430_MPU_T_COLD,
+       .min_freq = OMAP5430_MPU_MIN_FREQ,
+       .max_freq = OMAP5430_MPU_MAX_FREQ,
+       .max_temp = OMAP5430_MPU_MAX_TEMP,
+       .min_temp = OMAP5430_MPU_MIN_TEMP,
+       .hyst_val = OMAP5430_MPU_HYST_VAL,
+       .update_int1 = 1000,
+       .update_int2 = 2000,
+};
+
+/* Thresholds and limits for OMAP5430 GPU temperature sensor */
+static struct temp_sensor_data omap5430_gpu_temp_sensor_data = {
+       .tshut_hot = OMAP5430_GPU_TSHUT_HOT,
+       .tshut_cold = OMAP5430_GPU_TSHUT_COLD,
+       .t_hot = OMAP5430_GPU_T_HOT,
+       .t_cold = OMAP5430_GPU_T_COLD,
+       .min_freq = OMAP5430_GPU_MIN_FREQ,
+       .max_freq = OMAP5430_GPU_MAX_FREQ,
+       .max_temp = OMAP5430_GPU_MAX_TEMP,
+       .min_temp = OMAP5430_GPU_MIN_TEMP,
+       .hyst_val = OMAP5430_GPU_HYST_VAL,
+       .update_int1 = 1000,
+       .update_int2 = 2000,
+};
+
+/* Thresholds and limits for OMAP5430 CORE temperature sensor */
+static struct temp_sensor_data omap5430_core_temp_sensor_data = {
+       .tshut_hot = OMAP5430_CORE_TSHUT_HOT,
+       .tshut_cold = OMAP5430_CORE_TSHUT_COLD,
+       .t_hot = OMAP5430_CORE_T_HOT,
+       .t_cold = OMAP5430_CORE_T_COLD,
+       .min_freq = OMAP5430_CORE_MIN_FREQ,
+       .max_freq = OMAP5430_CORE_MAX_FREQ,
+       .max_temp = OMAP5430_CORE_MAX_TEMP,
+       .min_temp = OMAP5430_CORE_MIN_TEMP,
+       .hyst_val = OMAP5430_CORE_HYST_VAL,
+       .update_int1 = 1000,
+       .update_int2 = 2000,
+};
+
+/*
+ * OMAP54xx ES2.0 : Temperature values in milli degree celsius
+ * ADC code values from 540 to 945
+ */
+static int
+omap5430_adc_to_temp[
+       OMAP5430_ADC_END_VALUE - OMAP5430_ADC_START_VALUE + 1] = {
+       /* Index 540 - 549 */
+       -40000, -40000, -40000, -40000, -39800, -39400, -39000, -38600, -38200,
+       -37800,
+       /* Index 550 - 559 */
+       -37400, -37000, -36600, -36200, -35800, -35300, -34700, -34200, -33800,
+       -33400,
+       /* Index 560 - 569 */
+       -33000, -32600, -32200, -31800, -31400, -31000, -30600, -30200, -29800,
+       -29400,
+       /* Index 570 - 579 */
+       -29000, -28600, -28200, -27700, -27100, -26600, -26200, -25800, -25400,
+       -25000,
+       /* Index 580 - 589 */
+       -24600, -24200, -23800, -23400, -23000, -22600, -22200, -21600, -21400,
+       -21000,
+       /* Index 590 - 599 */
+       -20500, -19900, -19400, -19000, -18600, -18200, -17800, -17400, -17000,
+       -16600,
+       /* Index 600 - 609 */
+       -16200, -15800, -15400, -15000, -14600, -14200, -13800, -13400, -13000,
+       -12500,
+       /* Index 610 - 619 */
+       -11900, -11400, -11000, -10600, -10200, -9800, -9400, -9000, -8600,
+       -8200,
+       /* Index 620 - 629 */
+       -7800, -7400, -7000, -6600, -6200, -5800, -5400, -5000, -4500, -3900,
+       /* Index 630 - 639 */
+       -3400, -3000, -2600, -2200, -1800, -1400, -1000, -600, -200, 200,
+       /* Index 640 - 649 */
+       600, 1000, 1400, 1800, 2200, 2600, 3000, 3400, 3900, 4500,
+       /* Index 650 - 659 */
+       5000, 5400, 5800, 6200, 6600, 7000, 7400, 7800, 8200, 8600,
+       /* Index 660 - 669 */
+       9000, 9400, 9800, 10200, 10600, 11000, 11400, 11800, 12200, 12700,
+       /* Index 670 - 679 */
+       13300, 13800, 14200, 14600, 15000, 15400, 15800, 16200, 16600, 17000,
+       /* Index 680 - 689 */
+       17400, 17800, 18200, 18600, 19000, 19400, 19800, 20200, 20600, 21100,
+       /* Index 690 - 699 */
+       21400, 21900, 22500, 23000, 23400, 23800, 24200, 24600, 25000, 25400,
+       /* Index 700 - 709 */
+       25800, 26200, 26600, 27000, 27400, 27800, 28200, 28600, 29000, 29400,
+       /* Index 710 - 719 */
+       29800, 30200, 30600, 31000, 31400, 31900, 32500, 33000, 33400, 33800,
+       /* Index 720 - 729 */
+       34200, 34600, 35000, 35400, 35800, 36200, 36600, 37000, 37400, 37800,
+       /* Index 730 - 739 */
+       38200, 38600, 39000, 39400, 39800, 40200, 40600, 41000, 41400, 41800,
+       /* Index 740 - 749 */
+       42200, 42600, 43100, 43700, 44200, 44600, 45000, 45400, 45800, 46200,
+       /* Index 750 - 759 */
+       46600, 47000, 47400, 47800, 48200, 48600, 49000, 49400, 49800, 50200,
+       /* Index 760 - 769 */
+       50600, 51000, 51400, 51800, 52200, 52600, 53000, 53400, 53800, 54200,
+       /* Index 770 - 779 */
+       54600, 55000, 55400, 55900, 56500, 57000, 57400, 57800, 58200, 58600,
+       /* Index 780 - 789 */
+       59000, 59400, 59800, 60200, 60600, 61000, 61400, 61800, 62200, 62600,
+       /* Index 790 - 799 */
+       63000, 63400, 63800, 64200, 64600, 65000, 65400, 65800, 66200, 66600,
+       /* Index 800 - 809 */
+       67000, 67400, 67800, 68200, 68600, 69000, 69400, 69800, 70200, 70600,
+       /* Index 810 - 819 */
+       71000, 71500, 72100, 72600, 73000, 73400, 73800, 74200, 74600, 75000,
+       /* Index 820 - 829 */
+       75400, 75800, 76200, 76600, 77000, 77400, 77800, 78200, 78600, 79000,
+       /* Index 830 - 839 */
+       79400, 79800, 80200, 80600, 81000, 81400, 81800, 82200, 82600, 83000,
+       /* Index 840 - 849 */
+       83400, 83800, 84200, 84600, 85000, 85400, 85800, 86200, 86600, 87000,
+       /* Index 850 - 859 */
+       87400, 87800, 88200, 88600, 89000, 89400, 89800, 90200, 90600, 91000,
+       /* Index 860 - 869 */
+       91400, 91800, 92200, 92600, 93000, 93400, 93800, 94200, 94600, 95000,
+       /* Index 870 - 879 */
+       95400, 95800, 96200, 96600, 97000, 97500, 98100, 98600, 99000, 99400,
+       /* Index 880 - 889 */
+       99800, 100200, 100600, 101000, 101400, 101800, 102200, 102600, 103000,
+       103400,
+       /* Index 890 - 899 */
+       103800, 104200, 104600, 105000, 105400, 105800, 106200, 106600, 107000,
+       107400,
+       /* Index 900 - 909 */
+       107800, 108200, 108600, 109000, 109400, 109800, 110200, 110600, 111000,
+       111400,
+       /* Index 910 - 919 */
+       111800, 112200, 112600, 113000, 113400, 113800, 114200, 114600, 115000,
+       115400,
+       /* Index 920 - 929 */
+       115800, 116200, 116600, 117000, 117400, 117800, 118200, 118600, 119000,
+       119400,
+       /* Index 930 - 939 */
+       119800, 120200, 120600, 121000, 121400, 121800, 122400, 122600, 123000,
+       123400,
+       /* Index 940 - 945 */
+       123800, 1242000, 124600, 124900, 125000, 125000,
+};
+
+/* OMAP54xx ES2.0 data */
+/* TODO : Need to update the slope/constant for ES2.0 silicon */
+const struct ti_bandgap_data omap5430_data = {
+       .features = TI_BANDGAP_FEATURE_TSHUT_CONFIG |
+                       TI_BANDGAP_FEATURE_FREEZE_BIT |
+                       TI_BANDGAP_FEATURE_TALERT,
+       .fclock_name = "l3instr_ts_gclk_div",
+       .div_ck_name = "l3instr_ts_gclk_div",
+       .conv_table = omap5430_adc_to_temp,
+       .adc_start_val = OMAP5430_ADC_START_VALUE,
+       .adc_end_val = OMAP5430_ADC_END_VALUE,
+       .expose_sensor = ti_thermal_expose_sensor,
+       .remove_sensor = ti_thermal_remove_sensor,
+       .sensors = {
+               {
+               .registers = &omap5430_mpu_temp_sensor_registers,
+               .ts_data = &omap5430_mpu_temp_sensor_data,
+               .domain = "cpu",
+               .register_cooling = ti_thermal_register_cpu_cooling,
+               .unregister_cooling = ti_thermal_unregister_cpu_cooling,
+               .slope = OMAP_GRADIENT_SLOPE_5430_CPU,
+               .constant = OMAP_GRADIENT_CONST_5430_CPU,
+               .slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_5430_CPU,
+               .constant_pcb = OMAP_GRADIENT_CONST_W_PCB_5430_CPU,
+               },
+               {
+               .registers = &omap5430_gpu_temp_sensor_registers,
+               .ts_data = &omap5430_gpu_temp_sensor_data,
+               .domain = "gpu",
+               .slope = OMAP_GRADIENT_SLOPE_5430_GPU,
+               .constant = OMAP_GRADIENT_CONST_5430_GPU,
+               .slope_pcb = OMAP_GRADIENT_SLOPE_W_PCB_5430_GPU,
+               .constant_pcb = OMAP_GRADIENT_CONST_W_PCB_5430_GPU,
+               },
+               {
+               .registers = &omap5430_core_temp_sensor_registers,
+               .ts_data = &omap5430_core_temp_sensor_data,
+               .domain = "core",
+               },
+       },
+       .sensor_count = 3,
+};
diff --git a/drivers/staging/ti-soc-thermal/omap5xxx-bandgap.h b/drivers/staging/ti-soc-thermal/omap5xxx-bandgap.h
new file mode 100644 (file)
index 0000000..8824db4
--- /dev/null
@@ -0,0 +1,199 @@
+/*
+ * OMAP5xxx bandgap registers, bitfields and temperature definitions
+ *
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
+ * Contact:
+ *   Eduardo Valentin <eduardo.valentin@ti.com>
+ *
+ * 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.
+ *
+ * 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 St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#ifndef __OMAP5XXX_BANDGAP_H
+#define __OMAP5XXX_BANDGAP_H
+
+/**
+ * *** OMAP5430 ***
+ *
+ * Below, in sequence, are the Register definitions,
+ * the bitfields and the temperature definitions for OMAP5430.
+ */
+
+/**
+ * OMAP5430 register definitions
+ *
+ * Registers are defined as offsets. The offsets are
+ * relative to FUSE_OPP_BGAP_GPU on 5430.
+ *
+ * Register below are grouped by domain (not necessarily in offset order)
+ */
+
+/* OMAP5430.GPU register offsets */
+#define OMAP5430_FUSE_OPP_BGAP_GPU                     0x0
+#define OMAP5430_TEMP_SENSOR_GPU_OFFSET                        0x150
+#define OMAP5430_BGAP_THRESHOLD_GPU_OFFSET             0x1A8
+#define OMAP5430_BGAP_TSHUT_GPU_OFFSET                 0x1B4
+#define OMAP5430_BGAP_CUMUL_DTEMP_GPU_OFFSET           0x1C0
+#define OMAP5430_BGAP_DTEMP_GPU_0_OFFSET               0x1F4
+#define OMAP5430_BGAP_DTEMP_GPU_1_OFFSET               0x1F8
+#define OMAP5430_BGAP_DTEMP_GPU_2_OFFSET               0x1FC
+#define OMAP5430_BGAP_DTEMP_GPU_3_OFFSET               0x200
+#define OMAP5430_BGAP_DTEMP_GPU_4_OFFSET               0x204
+
+/* OMAP5430.MPU register offsets */
+#define OMAP5430_FUSE_OPP_BGAP_MPU                     0x4
+#define OMAP5430_TEMP_SENSOR_MPU_OFFSET                        0x14C
+#define OMAP5430_BGAP_THRESHOLD_MPU_OFFSET             0x1A4
+#define OMAP5430_BGAP_TSHUT_MPU_OFFSET                 0x1B0
+#define OMAP5430_BGAP_CUMUL_DTEMP_MPU_OFFSET           0x1BC
+#define OMAP5430_BGAP_DTEMP_MPU_0_OFFSET               0x1E0
+#define OMAP5430_BGAP_DTEMP_MPU_1_OFFSET               0x1E4
+#define OMAP5430_BGAP_DTEMP_MPU_2_OFFSET               0x1E8
+#define OMAP5430_BGAP_DTEMP_MPU_3_OFFSET               0x1EC
+#define OMAP5430_BGAP_DTEMP_MPU_4_OFFSET               0x1F0
+
+/* OMAP5430.MPU register offsets */
+#define OMAP5430_FUSE_OPP_BGAP_CORE                    0x8
+#define OMAP5430_TEMP_SENSOR_CORE_OFFSET               0x154
+#define OMAP5430_BGAP_THRESHOLD_CORE_OFFSET            0x1AC
+#define OMAP5430_BGAP_TSHUT_CORE_OFFSET                        0x1B8
+#define OMAP5430_BGAP_CUMUL_DTEMP_CORE_OFFSET          0x1C4
+#define OMAP5430_BGAP_DTEMP_CORE_0_OFFSET              0x208
+#define OMAP5430_BGAP_DTEMP_CORE_1_OFFSET              0x20C
+#define OMAP5430_BGAP_DTEMP_CORE_2_OFFSET              0x210
+#define OMAP5430_BGAP_DTEMP_CORE_3_OFFSET              0x214
+#define OMAP5430_BGAP_DTEMP_CORE_4_OFFSET              0x218
+
+/* OMAP5430.common register offsets */
+#define OMAP5430_BGAP_CTRL_OFFSET                      0x1A0
+#define OMAP5430_BGAP_STATUS_OFFSET                    0x1C8
+
+/**
+ * Register bitfields for OMAP5430
+ *
+ * All the macros bellow define the required bits for
+ * controlling temperature on OMAP5430. Bit defines are
+ * grouped by register.
+ */
+
+/* OMAP5430.TEMP_SENSOR */
+#define OMAP5430_BGAP_TEMP_SENSOR_SOC_MASK             BIT(12)
+#define OMAP5430_BGAP_TEMPSOFF_MASK                    BIT(11)
+#define OMAP5430_BGAP_TEMP_SENSOR_EOCZ_MASK            BIT(10)
+#define OMAP5430_BGAP_TEMP_SENSOR_DTEMP_MASK           (0x3ff << 0)
+
+/* OMAP5430.BANDGAP_CTRL */
+#define OMAP5430_MASK_SIDLEMODE_MASK                   (0x3 << 30)
+#define OMAP5430_MASK_FREEZE_CORE_MASK                 BIT(23)
+#define OMAP5430_MASK_FREEZE_GPU_MASK                  BIT(22)
+#define OMAP5430_MASK_FREEZE_MPU_MASK                  BIT(21)
+#define OMAP5430_MASK_CLEAR_CORE_MASK                  BIT(20)
+#define OMAP5430_MASK_CLEAR_GPU_MASK                   BIT(19)
+#define OMAP5430_MASK_CLEAR_MPU_MASK                   BIT(18)
+#define OMAP5430_MASK_CLEAR_ACCUM_CORE_MASK            BIT(17)
+#define OMAP5430_MASK_CLEAR_ACCUM_GPU_MASK             BIT(16)
+#define OMAP5430_MASK_CLEAR_ACCUM_MPU_MASK             BIT(15)
+#define OMAP5430_MASK_HOT_CORE_MASK                    BIT(5)
+#define OMAP5430_MASK_COLD_CORE_MASK                   BIT(4)
+#define OMAP5430_MASK_HOT_GPU_MASK                     BIT(3)
+#define OMAP5430_MASK_COLD_GPU_MASK                    BIT(2)
+#define OMAP5430_MASK_HOT_MPU_MASK                     BIT(1)
+#define OMAP5430_MASK_COLD_MPU_MASK                    BIT(0)
+
+/* OMAP5430.BANDGAP_COUNTER */
+#define OMAP5430_COUNTER_MASK                          (0xffffff << 0)
+
+/* OMAP5430.BANDGAP_THRESHOLD */
+#define OMAP5430_T_HOT_MASK                            (0x3ff << 16)
+#define OMAP5430_T_COLD_MASK                           (0x3ff << 0)
+
+/* OMAP5430.TSHUT_THRESHOLD */
+#define OMAP5430_TSHUT_HOT_MASK                                (0x3ff << 16)
+#define OMAP5430_TSHUT_COLD_MASK                       (0x3ff << 0)
+
+/* OMAP5430.BANDGAP_CUMUL_DTEMP_MPU */
+#define OMAP5430_CUMUL_DTEMP_MPU_MASK                  (0xffffffff << 0)
+
+/* OMAP5430.BANDGAP_CUMUL_DTEMP_GPU */
+#define OMAP5430_CUMUL_DTEMP_GPU_MASK                  (0xffffffff << 0)
+
+/* OMAP5430.BANDGAP_CUMUL_DTEMP_CORE */
+#define OMAP5430_CUMUL_DTEMP_CORE_MASK                 (0xffffffff << 0)
+
+/* OMAP5430.BANDGAP_STATUS */
+#define OMAP5430_BGAP_ALERT_MASK                       BIT(31)
+#define OMAP5430_HOT_CORE_FLAG_MASK                    BIT(5)
+#define OMAP5430_COLD_CORE_FLAG_MASK                   BIT(4)
+#define OMAP5430_HOT_GPU_FLAG_MASK                     BIT(3)
+#define OMAP5430_COLD_GPU_FLAG_MASK                    BIT(2)
+#define OMAP5430_HOT_MPU_FLAG_MASK                     BIT(1)
+#define OMAP5430_COLD_MPU_FLAG_MASK                    BIT(0)
+
+/**
+ * Temperature limits and thresholds for OMAP5430
+ *
+ * All the macros bellow are definitions for handling the
+ * ADC conversions and representation of temperature limits
+ * and thresholds for OMAP5430. Definitions are grouped
+ * by temperature domain.
+ */
+
+/* OMAP5430.common temperature definitions */
+/* ADC conversion table limits */
+#define OMAP5430_ADC_START_VALUE                       540
+#define OMAP5430_ADC_END_VALUE                         945
+
+/* OMAP5430.GPU temperature definitions */
+/* bandgap clock limits */
+#define OMAP5430_GPU_MAX_FREQ                          1500000
+#define OMAP5430_GPU_MIN_FREQ                          1000000
+/* sensor limits */
+#define OMAP5430_GPU_MIN_TEMP                          -40000
+#define OMAP5430_GPU_MAX_TEMP                          125000
+#define OMAP5430_GPU_HYST_VAL                          5000
+/* interrupts thresholds */
+#define OMAP5430_GPU_TSHUT_HOT                         915
+#define OMAP5430_GPU_TSHUT_COLD                                900
+#define OMAP5430_GPU_T_HOT                             800
+#define OMAP5430_GPU_T_COLD                            795
+
+/* OMAP5430.MPU temperature definitions */
+/* bandgap clock limits */
+#define OMAP5430_MPU_MAX_FREQ                          1500000
+#define OMAP5430_MPU_MIN_FREQ                          1000000
+/* sensor limits */
+#define OMAP5430_MPU_MIN_TEMP                          -40000
+#define OMAP5430_MPU_MAX_TEMP                          125000
+#define OMAP5430_MPU_HYST_VAL                          5000
+/* interrupts thresholds */
+#define OMAP5430_MPU_TSHUT_HOT                         915
+#define OMAP5430_MPU_TSHUT_COLD                                900
+#define OMAP5430_MPU_T_HOT                             800
+#define OMAP5430_MPU_T_COLD                            795
+
+/* OMAP5430.CORE temperature definitions */
+/* bandgap clock limits */
+#define OMAP5430_CORE_MAX_FREQ                         1500000
+#define OMAP5430_CORE_MIN_FREQ                         1000000
+/* sensor limits */
+#define OMAP5430_CORE_MIN_TEMP                         -40000
+#define OMAP5430_CORE_MAX_TEMP                         125000
+#define OMAP5430_CORE_HYST_VAL                         5000
+/* interrupts thresholds */
+#define OMAP5430_CORE_TSHUT_HOT                                915
+#define OMAP5430_CORE_TSHUT_COLD                       900
+#define OMAP5430_CORE_T_HOT                            800
+#define OMAP5430_CORE_T_COLD                           795
+
+#endif /* __OMAP5XXX_BANDGAP_H */
diff --git a/drivers/staging/ti-soc-thermal/ti-bandgap.c b/drivers/staging/ti-soc-thermal/ti-bandgap.c
new file mode 100644 (file)
index 0000000..d479e50
--- /dev/null
@@ -0,0 +1,1297 @@
+/*
+ * TI Bandgap temperature sensor driver
+ *
+ * Copyright (C) 2011-2012 Texas Instruments Incorporated - http://www.ti.com/
+ * Author: J Keerthy <j-keerthy@ti.com>
+ * Author: Moiz Sonasath <m-sonasath@ti.com>
+ * Couple of fixes, DT and MFD adaptation:
+ *   Eduardo Valentin <eduardo.valentin@ti.com>
+ *
+ * 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.
+ *
+ * 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 St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/export.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/interrupt.h>
+#include <linux/clk.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/err.h>
+#include <linux/types.h>
+#include <linux/spinlock.h>
+#include <linux/reboot.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#include <linux/of_irq.h>
+#include <linux/io.h>
+
+#include "ti-bandgap.h"
+
+/***   Helper functions to access registers and their bitfields   ***/
+
+/**
+ * ti_bandgap_readl() - simple read helper function
+ * @bgp: pointer to ti_bandgap structure
+ * @reg: desired register (offset) to be read
+ *
+ * Helper function to read bandgap registers. It uses the io remapped area.
+ * Returns the register value.
+ */
+static u32 ti_bandgap_readl(struct ti_bandgap *bgp, u32 reg)
+{
+       return readl(bgp->base + reg);
+}
+
+/**
+ * ti_bandgap_writel() - simple write helper function
+ * @bgp: pointer to ti_bandgap structure
+ * @val: desired register value to be written
+ * @reg: desired register (offset) to be written
+ *
+ * Helper function to write bandgap registers. It uses the io remapped area.
+ */
+static void ti_bandgap_writel(struct ti_bandgap *bgp, u32 val, u32 reg)
+{
+       writel(val, bgp->base + reg);
+}
+
+/**
+ * DOC: macro to update bits.
+ *
+ * RMW_BITS() - used to read, modify and update bandgap bitfields.
+ *            The value passed will be shifted.
+ */
+#define RMW_BITS(bgp, id, reg, mask, val)                      \
+do {                                                           \
+       struct temp_sensor_registers *t;                        \
+       u32 r;                                                  \
+                                                               \
+       t = bgp->conf->sensors[(id)].registers;         \
+       r = ti_bandgap_readl(bgp, t->reg);                      \
+       r &= ~t->mask;                                          \
+       r |= (val) << __ffs(t->mask);                           \
+       ti_bandgap_writel(bgp, r, t->reg);                      \
+} while (0)
+
+/***   Basic helper functions   ***/
+
+/**
+ * ti_bandgap_power() - controls the power state of a bandgap device
+ * @bgp: pointer to ti_bandgap structure
+ * @on: desired power state (1 - on, 0 - off)
+ *
+ * Used to power on/off a bandgap device instance. Only used on those
+ * that features tempsoff bit.
+ */
+static int ti_bandgap_power(struct ti_bandgap *bgp, bool on)
+{
+       int i;
+
+       if (!TI_BANDGAP_HAS(bgp, POWER_SWITCH))
+               goto exit;
+
+       for (i = 0; i < bgp->conf->sensor_count; i++)
+               /* active on 0 */
+               RMW_BITS(bgp, i, temp_sensor_ctrl, bgap_tempsoff_mask, !on);
+
+exit:
+       return 0;
+}
+
+/**
+ * ti_bandgap_read_temp() - helper function to read sensor temperature
+ * @bgp: pointer to ti_bandgap structure
+ * @id: bandgap sensor id
+ *
+ * Function to concentrate the steps to read sensor temperature register.
+ * This function is desired because, depending on bandgap device version,
+ * it might be needed to freeze the bandgap state machine, before fetching
+ * the register value.
+ */
+static u32 ti_bandgap_read_temp(struct ti_bandgap *bgp, int id)
+{
+       struct temp_sensor_registers *tsr;
+       u32 temp, reg;
+
+       tsr = bgp->conf->sensors[id].registers;
+       reg = tsr->temp_sensor_ctrl;
+
+       if (TI_BANDGAP_HAS(bgp, FREEZE_BIT)) {
+               RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 1);
+               /*
+                * In case we cannot read from cur_dtemp / dtemp_0,
+                * then we read from the last valid temp read
+                */
+               reg = tsr->ctrl_dtemp_1;
+       }
+
+       /* read temperature */
+       temp = ti_bandgap_readl(bgp, reg);
+       temp &= tsr->bgap_dtemp_mask;
+
+       if (TI_BANDGAP_HAS(bgp, FREEZE_BIT))
+               RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 0);
+
+       return temp;
+}
+
+/***   IRQ handlers   ***/
+
+/**
+ * ti_bandgap_talert_irq_handler() - handles Temperature alert IRQs
+ * @irq: IRQ number
+ * @data: private data (struct ti_bandgap *)
+ *
+ * This is the Talert handler. Use it only if bandgap device features
+ * HAS(TALERT). This handler goes over all sensors and checks their
+ * conditions and acts accordingly. In case there are events pending,
+ * it will reset the event mask to wait for the opposite event (next event).
+ * Every time there is a new event, it will be reported to thermal layer.
+ */
+static irqreturn_t ti_bandgap_talert_irq_handler(int irq, void *data)
+{
+       struct ti_bandgap *bgp = data;
+       struct temp_sensor_registers *tsr;
+       u32 t_hot = 0, t_cold = 0, ctrl;
+       int i;
+
+       spin_lock(&bgp->lock);
+       for (i = 0; i < bgp->conf->sensor_count; i++) {
+               tsr = bgp->conf->sensors[i].registers;
+               ctrl = ti_bandgap_readl(bgp, tsr->bgap_status);
+
+               /* Read the status of t_hot */
+               t_hot = ctrl & tsr->status_hot_mask;
+
+               /* Read the status of t_cold */
+               t_cold = ctrl & tsr->status_cold_mask;
+
+               if (!t_cold && !t_hot)
+                       continue;
+
+               ctrl = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl);
+               /*
+                * One TALERT interrupt: Two sources
+                * If the interrupt is due to t_hot then mask t_hot and
+                * and unmask t_cold else mask t_cold and unmask t_hot
+                */
+               if (t_hot) {
+                       ctrl &= ~tsr->mask_hot_mask;
+                       ctrl |= tsr->mask_cold_mask;
+               } else if (t_cold) {
+                       ctrl &= ~tsr->mask_cold_mask;
+                       ctrl |= tsr->mask_hot_mask;
+               }
+
+               ti_bandgap_writel(bgp, ctrl, tsr->bgap_mask_ctrl);
+
+               dev_dbg(bgp->dev,
+                       "%s: IRQ from %s sensor: hotevent %d coldevent %d\n",
+                       __func__, bgp->conf->sensors[i].domain,
+                       t_hot, t_cold);
+
+               /* report temperature to whom may concern */
+               if (bgp->conf->report_temperature)
+                       bgp->conf->report_temperature(bgp, i);
+       }
+       spin_unlock(&bgp->lock);
+
+       return IRQ_HANDLED;
+}
+
+/**
+ * ti_bandgap_tshut_irq_handler() - handles Temperature shutdown signal
+ * @irq: IRQ number
+ * @data: private data (unused)
+ *
+ * This is the Tshut handler. Use it only if bandgap device features
+ * HAS(TSHUT). If any sensor fires the Tshut signal, we simply shutdown
+ * the system.
+ */
+static irqreturn_t ti_bandgap_tshut_irq_handler(int irq, void *data)
+{
+       pr_emerg("%s: TSHUT temperature reached. Needs shut down...\n",
+                __func__);
+
+       orderly_poweroff(true);
+
+       return IRQ_HANDLED;
+}
+
+/***   Helper functions which manipulate conversion ADC <-> mi Celsius   ***/
+
+/**
+ * ti_bandgap_adc_to_mcelsius() - converts an ADC value to mCelsius scale
+ * @bgp: struct ti_bandgap pointer
+ * @adc_val: value in ADC representation
+ * @t: address where to write the resulting temperature in mCelsius
+ *
+ * Simple conversion from ADC representation to mCelsius. In case the ADC value
+ * is out of the ADC conv table range, it returns -ERANGE, 0 on success.
+ * The conversion table is indexed by the ADC values.
+ */
+static
+int ti_bandgap_adc_to_mcelsius(struct ti_bandgap *bgp, int adc_val, int *t)
+{
+       const struct ti_bandgap_data *conf = bgp->conf;
+       int ret = 0;
+
+       /* look up for temperature in the table and return the temperature */
+       if (adc_val < conf->adc_start_val || adc_val > conf->adc_end_val) {
+               ret = -ERANGE;
+               goto exit;
+       }
+
+       *t = bgp->conf->conv_table[adc_val - conf->adc_start_val];
+
+exit:
+       return ret;
+}
+
+/**
+ * ti_bandgap_mcelsius_to_adc() - converts a mCelsius value to ADC scale
+ * @bgp: struct ti_bandgap pointer
+ * @temp: value in mCelsius
+ * @adc: address where to write the resulting temperature in ADC representation
+ *
+ * Simple conversion from mCelsius to ADC values. In case the temp value
+ * is out of the ADC conv table range, it returns -ERANGE, 0 on success.
+ * The conversion table is indexed by the ADC values.
+ */
+static
+int ti_bandgap_mcelsius_to_adc(struct ti_bandgap *bgp, long temp, int *adc)
+{
+       const struct ti_bandgap_data *conf = bgp->conf;
+       const int *conv_table = bgp->conf->conv_table;
+       int high, low, mid, ret = 0;
+
+       low = 0;
+       high = conf->adc_end_val - conf->adc_start_val;
+       mid = (high + low) / 2;
+
+       if (temp < conv_table[low] || temp > conv_table[high]) {
+               ret = -ERANGE;
+               goto exit;
+       }
+
+       while (low < high) {
+               if (temp < conv_table[mid])
+                       high = mid - 1;
+               else
+                       low = mid + 1;
+               mid = (low + high) / 2;
+       }
+
+       *adc = conf->adc_start_val + low;
+
+exit:
+       return ret;
+}
+
+/**
+ * ti_bandgap_add_hyst() - add hysteresis (in mCelsius) to an ADC value
+ * @bgp: struct ti_bandgap pointer
+ * @adc_val: temperature value in ADC representation
+ * @hyst_val: hysteresis value in mCelsius
+ * @sum: address where to write the resulting temperature (in ADC scale)
+ *
+ * Adds an hysteresis value (in mCelsius) to a ADC temperature value.
+ * Returns 0 on success, -ERANGE otherwise.
+ */
+static
+int ti_bandgap_add_hyst(struct ti_bandgap *bgp, int adc_val, int hyst_val,
+                       u32 *sum)
+{
+       int temp, ret;
+
+       /*
+        * Need to add in the mcelsius domain, so we have a temperature
+        * the conv_table range
+        */
+       ret = ti_bandgap_adc_to_mcelsius(bgp, adc_val, &temp);
+       if (ret < 0)
+               goto exit;
+
+       temp += hyst_val;
+
+       ret = ti_bandgap_mcelsius_to_adc(bgp, temp, sum);
+
+exit:
+       return ret;
+}
+
+/***   Helper functions handling device Alert/Shutdown signals   ***/
+
+/**
+ * ti_bandgap_unmask_interrupts() - unmasks the events of thot & tcold
+ * @bgp: struct ti_bandgap pointer
+ * @id: bandgap sensor id
+ * @t_hot: hot temperature value to trigger alert signal
+ * @t_cold: cold temperature value to trigger alert signal
+ *
+ * Checks the requested t_hot and t_cold values and configures the IRQ event
+ * masks accordingly. Call this function only if bandgap features HAS(TALERT).
+ */
+static void ti_bandgap_unmask_interrupts(struct ti_bandgap *bgp, int id,
+                                        u32 t_hot, u32 t_cold)
+{
+       struct temp_sensor_registers *tsr;
+       u32 temp, reg_val;
+
+       /* Read the current on die temperature */
+       temp = ti_bandgap_read_temp(bgp, id);
+
+       tsr = bgp->conf->sensors[id].registers;
+       reg_val = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl);
+
+       if (temp < t_hot)
+               reg_val |= tsr->mask_hot_mask;
+       else
+               reg_val &= ~tsr->mask_hot_mask;
+
+       if (t_cold < temp)
+               reg_val |= tsr->mask_cold_mask;
+       else
+               reg_val &= ~tsr->mask_cold_mask;
+       ti_bandgap_writel(bgp, reg_val, tsr->bgap_mask_ctrl);
+}
+
+/**
+ * ti_bandgap_update_alert_threshold() - sequence to update thresholds
+ * @bgp: struct ti_bandgap pointer
+ * @id: bandgap sensor id
+ * @val: value (ADC) of a new threshold
+ * @hot: desired threshold to be updated. true if threshold hot, false if
+ *       threshold cold
+ *
+ * It will program the required thresholds (hot and cold) for TALERT signal.
+ * This function can be used to update t_hot or t_cold, depending on @hot value.
+ * It checks the resulting t_hot and t_cold values, based on the new passed @val
+ * and configures the thresholds so that t_hot is always greater than t_cold.
+ * Call this function only if bandgap features HAS(TALERT).
+ */
+static int ti_bandgap_update_alert_threshold(struct ti_bandgap *bgp, int id,
+                                            int val, bool hot)
+{
+       struct temp_sensor_data *ts_data = bgp->conf->sensors[id].ts_data;
+       struct temp_sensor_registers *tsr;
+       u32 thresh_val, reg_val, t_hot, t_cold;
+       int err = 0;
+
+       tsr = bgp->conf->sensors[id].registers;
+
+       /* obtain the current value */
+       thresh_val = ti_bandgap_readl(bgp, tsr->bgap_threshold);
+       t_cold = (thresh_val & tsr->threshold_tcold_mask) >>
+               __ffs(tsr->threshold_tcold_mask);
+       t_hot = (thresh_val & tsr->threshold_thot_mask) >>
+               __ffs(tsr->threshold_thot_mask);
+       if (hot)
+               t_hot = val;
+       else
+               t_cold = val;
+
+       if (t_cold > t_hot) {
+               if (hot)
+                       err = ti_bandgap_add_hyst(bgp, t_hot,
+                                                 -ts_data->hyst_val,
+                                                 &t_cold);
+               else
+                       err = ti_bandgap_add_hyst(bgp, t_cold,
+                                                 ts_data->hyst_val,
+                                                 &t_hot);
+       }
+
+       /* write the new threshold values */
+       reg_val = thresh_val &
+                 ~(tsr->threshold_thot_mask | tsr->threshold_tcold_mask);
+       reg_val |= (t_hot << __ffs(tsr->threshold_thot_mask)) |
+                  (t_cold << __ffs(tsr->threshold_tcold_mask));
+       ti_bandgap_writel(bgp, reg_val, tsr->bgap_threshold);
+
+       if (err) {
+               dev_err(bgp->dev, "failed to reprogram thot threshold\n");
+               err = -EIO;
+               goto exit;
+       }
+
+       ti_bandgap_unmask_interrupts(bgp, id, t_hot, t_cold);
+exit:
+       return err;
+}
+
+/**
+ * ti_bandgap_validate() - helper to check the sanity of a struct ti_bandgap
+ * @bgp: struct ti_bandgap pointer
+ * @id: bandgap sensor id
+ *
+ * Checks if the bandgap pointer is valid and if the sensor id is also
+ * applicable.
+ */
+static inline int ti_bandgap_validate(struct ti_bandgap *bgp, int id)
+{
+       int ret = 0;
+
+       if (IS_ERR_OR_NULL(bgp)) {
+               pr_err("%s: invalid bandgap pointer\n", __func__);
+               ret = -EINVAL;
+               goto exit;
+       }
+
+       if ((id < 0) || (id >= bgp->conf->sensor_count)) {
+               dev_err(bgp->dev, "%s: sensor id out of range (%d)\n",
+                       __func__, id);
+               ret = -ERANGE;
+       }
+
+exit:
+       return ret;
+}
+
+/**
+ * _ti_bandgap_write_threshold() - helper to update TALERT t_cold or t_hot
+ * @bgp: struct ti_bandgap pointer
+ * @id: bandgap sensor id
+ * @val: value (mCelsius) of a new threshold
+ * @hot: desired threshold to be updated. true if threshold hot, false if
+ *       threshold cold
+ *
+ * It will update the required thresholds (hot and cold) for TALERT signal.
+ * This function can be used to update t_hot or t_cold, depending on @hot value.
+ * Validates the mCelsius range and update the requested threshold.
+ * Call this function only if bandgap features HAS(TALERT).
+ */
+static int _ti_bandgap_write_threshold(struct ti_bandgap *bgp, int id, int val,
+                                      bool hot)
+{
+       struct temp_sensor_data *ts_data;
+       struct temp_sensor_registers *tsr;
+       u32 adc_val;
+       int ret;
+
+       ret = ti_bandgap_validate(bgp, id);
+       if (ret)
+               goto exit;
+
+       if (!TI_BANDGAP_HAS(bgp, TALERT)) {
+               ret = -ENOTSUPP;
+               goto exit;
+       }
+
+       ts_data = bgp->conf->sensors[id].ts_data;
+       tsr = bgp->conf->sensors[id].registers;
+       if (hot) {
+               if (val < ts_data->min_temp + ts_data->hyst_val)
+                       ret = -EINVAL;
+       } else {
+               if (val > ts_data->max_temp + ts_data->hyst_val)
+                       ret = -EINVAL;
+       }
+
+       if (ret)
+               goto exit;
+
+       ret = ti_bandgap_mcelsius_to_adc(bgp, val, &adc_val);
+       if (ret < 0)
+               goto exit;
+
+       spin_lock(&bgp->lock);
+       ret = ti_bandgap_update_alert_threshold(bgp, id, adc_val, hot);
+       spin_unlock(&bgp->lock);
+
+exit:
+       return ret;
+}
+
+/**
+ * _ti_bandgap_read_threshold() - helper to read TALERT t_cold or t_hot
+ * @bgp: struct ti_bandgap pointer
+ * @id: bandgap sensor id
+ * @val: value (mCelsius) of a threshold
+ * @hot: desired threshold to be read. true if threshold hot, false if
+ *       threshold cold
+ *
+ * It will fetch the required thresholds (hot and cold) for TALERT signal.
+ * This function can be used to read t_hot or t_cold, depending on @hot value.
+ * Call this function only if bandgap features HAS(TALERT).
+ */
+static int _ti_bandgap_read_threshold(struct ti_bandgap *bgp, int id,
+                                     int *val, bool hot)
+{
+       struct temp_sensor_registers *tsr;
+       u32 temp, mask;
+       int ret = 0;
+
+       ret = ti_bandgap_validate(bgp, id);
+       if (ret)
+               goto exit;
+
+       if (!TI_BANDGAP_HAS(bgp, TALERT)) {
+               ret = -ENOTSUPP;
+               goto exit;
+       }
+
+       tsr = bgp->conf->sensors[id].registers;
+       if (hot)
+               mask = tsr->threshold_thot_mask;
+       else
+               mask = tsr->threshold_tcold_mask;
+
+       temp = ti_bandgap_readl(bgp, tsr->bgap_threshold);
+       temp = (temp & mask) >> __ffs(mask);
+       ret |= ti_bandgap_adc_to_mcelsius(bgp, temp, &temp);
+       if (ret) {
+               dev_err(bgp->dev, "failed to read thot\n");
+               ret = -EIO;
+               goto exit;
+       }
+
+       *val = temp;
+
+exit:
+       return ret;
+}
+
+/***   Exposed APIs   ***/
+
+/**
+ * ti_bandgap_read_thot() - reads sensor current thot
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @thot: resulting current thot value
+ *
+ * returns 0 on success or the proper error code
+ */
+int ti_bandgap_read_thot(struct ti_bandgap *bgp, int id, int *thot)
+{
+       return _ti_bandgap_read_threshold(bgp, id, thot, true);
+}
+
+/**
+ * ti_bandgap_write_thot() - sets sensor current thot
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @val: desired thot value
+ *
+ * returns 0 on success or the proper error code
+ */
+int ti_bandgap_write_thot(struct ti_bandgap *bgp, int id, int val)
+{
+       return _ti_bandgap_write_threshold(bgp, id, val, true);
+}
+
+/**
+ * ti_bandgap_read_tcold() - reads sensor current tcold
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @tcold: resulting current tcold value
+ *
+ * returns 0 on success or the proper error code
+ */
+int ti_bandgap_read_tcold(struct ti_bandgap *bgp, int id, int *tcold)
+{
+       return _ti_bandgap_read_threshold(bgp, id, tcold, false);
+}
+
+/**
+ * ti_bandgap_write_tcold() - sets the sensor tcold
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @val: desired tcold value
+ *
+ * returns 0 on success or the proper error code
+ */
+int ti_bandgap_write_tcold(struct ti_bandgap *bgp, int id, int val)
+{
+       return _ti_bandgap_write_threshold(bgp, id, val, false);
+}
+
+/**
+ * ti_bandgap_read_update_interval() - read the sensor update interval
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @interval: resulting update interval in miliseconds
+ *
+ * returns 0 on success or the proper error code
+ */
+int ti_bandgap_read_update_interval(struct ti_bandgap *bgp, int id,
+                                   int *interval)
+{
+       struct temp_sensor_registers *tsr;
+       u32 time;
+       int ret;
+
+       ret = ti_bandgap_validate(bgp, id);
+       if (ret)
+               return ret;
+
+       if (!TI_BANDGAP_HAS(bgp, COUNTER))
+               return -ENOTSUPP;
+
+       tsr = bgp->conf->sensors[id].registers;
+       time = ti_bandgap_readl(bgp, tsr->bgap_counter);
+       time = (time & tsr->counter_mask) >> __ffs(tsr->counter_mask);
+       time = time * 1000 / bgp->clk_rate;
+
+       *interval = time;
+
+       return 0;
+}
+
+/**
+ * ti_bandgap_write_update_interval() - set the update interval
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @interval: desired update interval in miliseconds
+ *
+ * returns 0 on success or the proper error code
+ */
+int ti_bandgap_write_update_interval(struct ti_bandgap *bgp,
+                                    int id, u32 interval)
+{
+       int ret = ti_bandgap_validate(bgp, id);
+       if (ret)
+               return ret;
+
+       if (!TI_BANDGAP_HAS(bgp, COUNTER))
+               return -ENOTSUPP;
+
+       interval = interval * bgp->clk_rate / 1000;
+       spin_lock(&bgp->lock);
+       RMW_BITS(bgp, id, bgap_counter, counter_mask, interval);
+       spin_unlock(&bgp->lock);
+
+       return 0;
+}
+
+/**
+ * ti_bandgap_read_temperature() - report current temperature
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @temperature: resulting temperature
+ *
+ * returns 0 on success or the proper error code
+ */
+int ti_bandgap_read_temperature(struct ti_bandgap *bgp, int id,
+                               int *temperature)
+{
+       u32 temp;
+       int ret;
+
+       ret = ti_bandgap_validate(bgp, id);
+       if (ret)
+               return ret;
+
+       spin_lock(&bgp->lock);
+       temp = ti_bandgap_read_temp(bgp, id);
+       spin_unlock(&bgp->lock);
+
+       ret |= ti_bandgap_adc_to_mcelsius(bgp, temp, &temp);
+       if (ret)
+               return -EIO;
+
+       *temperature = temp;
+
+       return 0;
+}
+
+/**
+ * ti_bandgap_set_sensor_data() - helper function to store thermal
+ * framework related data.
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ * @data: thermal framework related data to be stored
+ *
+ * returns 0 on success or the proper error code
+ */
+int ti_bandgap_set_sensor_data(struct ti_bandgap *bgp, int id, void *data)
+{
+       int ret = ti_bandgap_validate(bgp, id);
+       if (ret)
+               return ret;
+
+       bgp->regval[id].data = data;
+
+       return 0;
+}
+
+/**
+ * ti_bandgap_get_sensor_data() - helper function to get thermal
+ * framework related data.
+ * @bgp: pointer to bandgap instance
+ * @id: sensor id
+ *
+ * returns data stored by set function with sensor id on success or NULL
+ */
+void *ti_bandgap_get_sensor_data(struct ti_bandgap *bgp, int id)
+{
+       int ret = ti_bandgap_validate(bgp, id);
+       if (ret)
+               return ERR_PTR(ret);
+
+       return bgp->regval[id].data;
+}
+
+/***   Helper functions used during device initialization   ***/
+
+/**
+ * ti_bandgap_force_single_read() - executes 1 single ADC conversion
+ * @bgp: pointer to struct ti_bandgap
+ * @id: sensor id which it is desired to read 1 temperature
+ *
+ * Used to initialize the conversion state machine and set it to a valid
+ * state. Called during device initialization and context restore events.
+ */
+static int
+ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id)
+{
+       u32 temp = 0, counter = 1000;
+
+       /* Select single conversion mode */
+       if (TI_BANDGAP_HAS(bgp, MODE_CONFIG))
+               RMW_BITS(bgp, id, bgap_mode_ctrl, mode_ctrl_mask, 0);
+
+       /* Start of Conversion = 1 */
+       RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 1);
+       /* Wait until DTEMP is updated */
+       temp = ti_bandgap_read_temp(bgp, id);
+
+       while ((temp == 0) && --counter)
+               temp = ti_bandgap_read_temp(bgp, id);
+       /* REVISIT: Check correct condition for end of conversion */
+
+       /* Start of Conversion = 0 */
+       RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 0);
+
+       return 0;
+}
+
+/**
+ * ti_bandgap_set_continous_mode() - One time enabling of continuous mode
+ * @bgp: pointer to struct ti_bandgap
+ *
+ * Call this function only if HAS(MODE_CONFIG) is set. As this driver may
+ * be used for junction temperature monitoring, it is desirable that the
+ * sensors are operational all the time, so that alerts are generated
+ * properly.
+ */
+static int ti_bandgap_set_continuous_mode(struct ti_bandgap *bgp)
+{
+       int i;
+
+       for (i = 0; i < bgp->conf->sensor_count; i++) {
+               /* Perform a single read just before enabling continuous */
+               ti_bandgap_force_single_read(bgp, i);
+               RMW_BITS(bgp, i, bgap_mode_ctrl, mode_ctrl_mask, 1);
+       }
+
+       return 0;
+}
+
+/**
+ * ti_bandgap_tshut_init() - setup and initialize tshut handling
+ * @bgp: pointer to struct ti_bandgap
+ * @pdev: pointer to device struct platform_device
+ *
+ * Call this function only in case the bandgap features HAS(TSHUT).
+ * In this case, the driver needs to handle the TSHUT signal as an IRQ.
+ * The IRQ is wired as a GPIO, and for this purpose, it is required
+ * to specify which GPIO line is used. TSHUT IRQ is fired anytime
+ * one of the bandgap sensors violates the TSHUT high/hot threshold.
+ * And in that case, the system must go off.
+ */
+static int ti_bandgap_tshut_init(struct ti_bandgap *bgp,
+                                struct platform_device *pdev)
+{
+       int gpio_nr = bgp->tshut_gpio;
+       int status;
+
+       /* Request for gpio_86 line */
+       status = gpio_request(gpio_nr, "tshut");
+       if (status < 0) {
+               dev_err(bgp->dev, "Could not request for TSHUT GPIO:%i\n", 86);
+               return status;
+       }
+       status = gpio_direction_input(gpio_nr);
+       if (status) {
+               dev_err(bgp->dev, "Cannot set input TSHUT GPIO %d\n", gpio_nr);
+               return status;
+       }
+
+       status = request_irq(gpio_to_irq(gpio_nr), ti_bandgap_tshut_irq_handler,
+                            IRQF_TRIGGER_RISING, "tshut", NULL);
+       if (status) {
+               gpio_free(gpio_nr);
+               dev_err(bgp->dev, "request irq failed for TSHUT");
+       }
+
+       return 0;
+}
+
+/**
+ * ti_bandgap_alert_init() - setup and initialize talert handling
+ * @bgp: pointer to struct ti_bandgap
+ * @pdev: pointer to device struct platform_device
+ *
+ * Call this function only in case the bandgap features HAS(TALERT).
+ * In this case, the driver needs to handle the TALERT signals as an IRQs.
+ * TALERT is a normal IRQ and it is fired any time thresholds (hot or cold)
+ * are violated. In these situation, the driver must reprogram the thresholds,
+ * accordingly to specified policy.
+ */
+static int ti_bandgap_talert_init(struct ti_bandgap *bgp,
+                                 struct platform_device *pdev)
+{
+       int ret;
+
+       bgp->irq = platform_get_irq(pdev, 0);
+       if (bgp->irq < 0) {
+               dev_err(&pdev->dev, "get_irq failed\n");
+               return bgp->irq;
+       }
+       ret = request_threaded_irq(bgp->irq, NULL,
+                                  ti_bandgap_talert_irq_handler,
+                                  IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+                                  "talert", bgp);
+       if (ret) {
+               dev_err(&pdev->dev, "Request threaded irq failed.\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+static const struct of_device_id of_ti_bandgap_match[];
+/**
+ * ti_bandgap_build() - parse DT and setup a struct ti_bandgap
+ * @pdev: pointer to device struct platform_device
+ *
+ * Used to read the device tree properties accordingly to the bandgap
+ * matching version. Based on bandgap version and its capabilities it
+ * will build a struct ti_bandgap out of the required DT entries.
+ */
+static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
+{
+       struct device_node *node = pdev->dev.of_node;
+       const struct of_device_id *of_id;
+       struct ti_bandgap *bgp;
+       struct resource *res;
+       u32 prop;
+       int i;
+
+       /* just for the sake */
+       if (!node) {
+               dev_err(&pdev->dev, "no platform information available\n");
+               return ERR_PTR(-EINVAL);
+       }
+
+       bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL);
+       if (!bgp) {
+               dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       of_id = of_match_device(of_ti_bandgap_match, &pdev->dev);
+       if (of_id)
+               bgp->conf = of_id->data;
+
+       /* register shadow for context save and restore */
+       bgp->regval = devm_kzalloc(&pdev->dev, sizeof(*bgp->regval) *
+                                  bgp->conf->sensor_count, GFP_KERNEL);
+       if (!bgp) {
+               dev_err(&pdev->dev, "Unable to allocate mem for driver ref\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       i = 0;
+       do {
+               void __iomem *chunk;
+
+               res = platform_get_resource(pdev, IORESOURCE_MEM, i);
+               if (!res)
+                       break;
+               chunk = devm_ioremap_resource(&pdev->dev, res);
+               if (i == 0)
+                       bgp->base = chunk;
+               if (IS_ERR(chunk))
+                       return ERR_CAST(chunk);
+
+               i++;
+       } while (res);
+
+       if (TI_BANDGAP_HAS(bgp, TSHUT)) {
+               if (of_property_read_u32(node, "ti,tshut-gpio", &prop) < 0) {
+                       dev_err(&pdev->dev, "missing tshut gpio in device tree\n");
+                       return ERR_PTR(-EINVAL);
+               }
+               bgp->tshut_gpio = prop;
+               if (!gpio_is_valid(bgp->tshut_gpio)) {
+                       dev_err(&pdev->dev, "invalid gpio for tshut (%d)\n",
+                               bgp->tshut_gpio);
+                       return ERR_PTR(-EINVAL);
+               }
+       }
+
+       return bgp;
+}
+
+/***   Device driver call backs   ***/
+
+static
+int ti_bandgap_probe(struct platform_device *pdev)
+{
+       struct ti_bandgap *bgp;
+       int clk_rate, ret = 0, i;
+
+       bgp = ti_bandgap_build(pdev);
+       if (IS_ERR_OR_NULL(bgp)) {
+               dev_err(&pdev->dev, "failed to fetch platform data\n");
+               return PTR_ERR(bgp);
+       }
+       bgp->dev = &pdev->dev;
+
+       if (TI_BANDGAP_HAS(bgp, TSHUT)) {
+               ret = ti_bandgap_tshut_init(bgp, pdev);
+               if (ret) {
+                       dev_err(&pdev->dev,
+                               "failed to initialize system tshut IRQ\n");
+                       return ret;
+               }
+       }
+
+       bgp->fclock = clk_get(NULL, bgp->conf->fclock_name);
+       ret = IS_ERR_OR_NULL(bgp->fclock);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to request fclock reference\n");
+               goto free_irqs;
+       }
+
+       bgp->div_clk = clk_get(NULL,  bgp->conf->div_ck_name);
+       ret = IS_ERR_OR_NULL(bgp->div_clk);
+       if (ret) {
+               dev_err(&pdev->dev,
+                       "failed to request div_ts_ck clock ref\n");
+               goto free_irqs;
+       }
+
+       for (i = 0; i < bgp->conf->sensor_count; i++) {
+               struct temp_sensor_registers *tsr;
+               u32 val;
+
+               tsr = bgp->conf->sensors[i].registers;
+               /*
+                * check if the efuse has a non-zero value if not
+                * it is an untrimmed sample and the temperatures
+                * may not be accurate
+                */
+               val = ti_bandgap_readl(bgp, tsr->bgap_efuse);
+               if (ret || !val)
+                       dev_info(&pdev->dev,
+                                "Non-trimmed BGAP, Temp not accurate\n");
+       }
+
+       clk_rate = clk_round_rate(bgp->div_clk,
+                                 bgp->conf->sensors[0].ts_data->max_freq);
+       if (clk_rate < bgp->conf->sensors[0].ts_data->min_freq ||
+           clk_rate == 0xffffffff) {
+               ret = -ENODEV;
+               dev_err(&pdev->dev, "wrong clock rate (%d)\n", clk_rate);
+               goto put_clks;
+       }
+
+       ret = clk_set_rate(bgp->div_clk, clk_rate);
+       if (ret)
+               dev_err(&pdev->dev, "Cannot re-set clock rate. Continuing\n");
+
+       bgp->clk_rate = clk_rate;
+       if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
+               clk_prepare_enable(bgp->fclock);
+
+
+       spin_lock_init(&bgp->lock);
+       bgp->dev = &pdev->dev;
+       platform_set_drvdata(pdev, bgp);
+
+       ti_bandgap_power(bgp, true);
+
+       /* Set default counter to 1 for now */
+       if (TI_BANDGAP_HAS(bgp, COUNTER))
+               for (i = 0; i < bgp->conf->sensor_count; i++)
+                       RMW_BITS(bgp, i, bgap_counter, counter_mask, 1);
+
+       /* Set default thresholds for alert and shutdown */
+       for (i = 0; i < bgp->conf->sensor_count; i++) {
+               struct temp_sensor_data *ts_data;
+
+               ts_data = bgp->conf->sensors[i].ts_data;
+
+               if (TI_BANDGAP_HAS(bgp, TALERT)) {
+                       /* Set initial Talert thresholds */
+                       RMW_BITS(bgp, i, bgap_threshold,
+                                threshold_tcold_mask, ts_data->t_cold);
+                       RMW_BITS(bgp, i, bgap_threshold,
+                                threshold_thot_mask, ts_data->t_hot);
+                       /* Enable the alert events */
+                       RMW_BITS(bgp, i, bgap_mask_ctrl, mask_hot_mask, 1);
+                       RMW_BITS(bgp, i, bgap_mask_ctrl, mask_cold_mask, 1);
+               }
+
+               if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG)) {
+                       /* Set initial Tshut thresholds */
+                       RMW_BITS(bgp, i, tshut_threshold,
+                                tshut_hot_mask, ts_data->tshut_hot);
+                       RMW_BITS(bgp, i, tshut_threshold,
+                                tshut_cold_mask, ts_data->tshut_cold);
+               }
+       }
+
+       if (TI_BANDGAP_HAS(bgp, MODE_CONFIG))
+               ti_bandgap_set_continuous_mode(bgp);
+
+       /* Set .250 seconds time as default counter */
+       if (TI_BANDGAP_HAS(bgp, COUNTER))
+               for (i = 0; i < bgp->conf->sensor_count; i++)
+                       RMW_BITS(bgp, i, bgap_counter, counter_mask,
+                                bgp->clk_rate / 4);
+
+       /* Every thing is good? Then expose the sensors */
+       for (i = 0; i < bgp->conf->sensor_count; i++) {
+               char *domain;
+
+               if (bgp->conf->sensors[i].register_cooling)
+                       bgp->conf->sensors[i].register_cooling(bgp, i);
+
+               domain = bgp->conf->sensors[i].domain;
+               if (bgp->conf->expose_sensor)
+                       bgp->conf->expose_sensor(bgp, i, domain);
+       }
+
+       /*
+        * Enable the Interrupts once everything is set. Otherwise irq handler
+        * might be called as soon as it is enabled where as rest of framework
+        * is still getting initialised.
+        */
+       if (TI_BANDGAP_HAS(bgp, TALERT)) {
+               ret = ti_bandgap_talert_init(bgp, pdev);
+               if (ret) {
+                       dev_err(&pdev->dev, "failed to initialize Talert IRQ\n");
+                       i = bgp->conf->sensor_count;
+                       goto disable_clk;
+               }
+       }
+
+       return 0;
+
+disable_clk:
+       if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
+               clk_disable_unprepare(bgp->fclock);
+put_clks:
+       clk_put(bgp->fclock);
+       clk_put(bgp->div_clk);
+free_irqs:
+       if (TI_BANDGAP_HAS(bgp, TSHUT)) {
+               free_irq(gpio_to_irq(bgp->tshut_gpio), NULL);
+               gpio_free(bgp->tshut_gpio);
+       }
+
+       return ret;
+}
+
+static
+int ti_bandgap_remove(struct platform_device *pdev)
+{
+       struct ti_bandgap *bgp = platform_get_drvdata(pdev);
+       int i;
+
+       /* First thing is to remove sensor interfaces */
+       for (i = 0; i < bgp->conf->sensor_count; i++) {
+               if (bgp->conf->sensors[i].register_cooling)
+                       bgp->conf->sensors[i].unregister_cooling(bgp, i);
+
+               if (bgp->conf->remove_sensor)
+                       bgp->conf->remove_sensor(bgp, i);
+       }
+
+       ti_bandgap_power(bgp, false);
+
+       if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
+               clk_disable_unprepare(bgp->fclock);
+       clk_put(bgp->fclock);
+       clk_put(bgp->div_clk);
+
+       if (TI_BANDGAP_HAS(bgp, TALERT))
+               free_irq(bgp->irq, bgp);
+
+       if (TI_BANDGAP_HAS(bgp, TSHUT)) {
+               free_irq(gpio_to_irq(bgp->tshut_gpio), NULL);
+               gpio_free(bgp->tshut_gpio);
+       }
+
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int ti_bandgap_save_ctxt(struct ti_bandgap *bgp)
+{
+       int i;
+
+       for (i = 0; i < bgp->conf->sensor_count; i++) {
+               struct temp_sensor_registers *tsr;
+               struct temp_sensor_regval *rval;
+
+               rval = &bgp->regval[i];
+               tsr = bgp->conf->sensors[i].registers;
+
+               if (TI_BANDGAP_HAS(bgp, MODE_CONFIG))
+                       rval->bg_mode_ctrl = ti_bandgap_readl(bgp,
+                                                       tsr->bgap_mode_ctrl);
+               if (TI_BANDGAP_HAS(bgp, COUNTER))
+                       rval->bg_counter = ti_bandgap_readl(bgp,
+                                                       tsr->bgap_counter);
+               if (TI_BANDGAP_HAS(bgp, TALERT)) {
+                       rval->bg_threshold = ti_bandgap_readl(bgp,
+                                                       tsr->bgap_threshold);
+                       rval->bg_ctrl = ti_bandgap_readl(bgp,
+                                                  tsr->bgap_mask_ctrl);
+               }
+
+               if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG))
+                       rval->tshut_threshold = ti_bandgap_readl(bgp,
+                                                  tsr->tshut_threshold);
+       }
+
+       return 0;
+}
+
+static int ti_bandgap_restore_ctxt(struct ti_bandgap *bgp)
+{
+       int i;
+
+       for (i = 0; i < bgp->conf->sensor_count; i++) {
+               struct temp_sensor_registers *tsr;
+               struct temp_sensor_regval *rval;
+               u32 val = 0;
+
+               rval = &bgp->regval[i];
+               tsr = bgp->conf->sensors[i].registers;
+
+               if (TI_BANDGAP_HAS(bgp, COUNTER))
+                       val = ti_bandgap_readl(bgp, tsr->bgap_counter);
+
+               if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG))
+                       ti_bandgap_writel(bgp, rval->tshut_threshold,
+                                         tsr->tshut_threshold);
+               /* Force immediate temperature measurement and update
+                * of the DTEMP field
+                */
+               ti_bandgap_force_single_read(bgp, i);
+
+               if (TI_BANDGAP_HAS(bgp, COUNTER))
+                       ti_bandgap_writel(bgp, rval->bg_counter,
+                                         tsr->bgap_counter);
+               if (TI_BANDGAP_HAS(bgp, MODE_CONFIG))
+                       ti_bandgap_writel(bgp, rval->bg_mode_ctrl,
+                                         tsr->bgap_mode_ctrl);
+               if (TI_BANDGAP_HAS(bgp, TALERT)) {
+                       ti_bandgap_writel(bgp, rval->bg_threshold,
+                                         tsr->bgap_threshold);
+                       ti_bandgap_writel(bgp, rval->bg_ctrl,
+                                         tsr->bgap_mask_ctrl);
+               }
+       }
+
+       return 0;
+}
+
+static int ti_bandgap_suspend(struct device *dev)
+{
+       struct ti_bandgap *bgp = dev_get_drvdata(dev);
+       int err;
+
+       err = ti_bandgap_save_ctxt(bgp);
+       ti_bandgap_power(bgp, false);
+
+       if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
+               clk_disable_unprepare(bgp->fclock);
+
+       return err;
+}
+
+static int ti_bandgap_resume(struct device *dev)
+{
+       struct ti_bandgap *bgp = dev_get_drvdata(dev);
+
+       if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
+               clk_prepare_enable(bgp->fclock);
+
+       ti_bandgap_power(bgp, true);
+
+       return ti_bandgap_restore_ctxt(bgp);
+}
+static const struct dev_pm_ops ti_bandgap_dev_pm_ops = {
+       SET_SYSTEM_SLEEP_PM_OPS(ti_bandgap_suspend,
+                               ti_bandgap_resume)
+};
+
+#define DEV_PM_OPS     (&ti_bandgap_dev_pm_ops)
+#else
+#define DEV_PM_OPS     NULL
+#endif
+
+static const struct of_device_id of_ti_bandgap_match[] = {
+#ifdef CONFIG_OMAP4_THERMAL
+       {
+               .compatible = "ti,omap4430-bandgap",
+               .data = (void *)&omap4430_data,
+       },
+       {
+               .compatible = "ti,omap4460-bandgap",
+               .data = (void *)&omap4460_data,
+       },
+       {
+               .compatible = "ti,omap4470-bandgap",
+               .data = (void *)&omap4470_data,
+       },
+#endif
+#ifdef CONFIG_OMAP5_THERMAL
+       {
+               .compatible = "ti,omap5430-bandgap",
+               .data = (void *)&omap5430_data,
+       },
+#endif
+       /* Sentinel */
+       { },
+};
+MODULE_DEVICE_TABLE(of, of_ti_bandgap_match);
+
+static struct platform_driver ti_bandgap_sensor_driver = {
+       .probe = ti_bandgap_probe,
+       .remove = ti_bandgap_remove,
+       .driver = {
+                       .name = "ti-soc-thermal",
+                       .pm = DEV_PM_OPS,
+                       .of_match_table = of_ti_bandgap_match,
+       },
+};
+
+module_platform_driver(ti_bandgap_sensor_driver);
+
+MODULE_DESCRIPTION("OMAP4+ bandgap temperature sensor driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:ti-soc-thermal");
+MODULE_AUTHOR("Texas Instrument Inc.");
diff --git a/drivers/staging/ti-soc-thermal/ti-bandgap.h b/drivers/staging/ti-soc-thermal/ti-bandgap.h
new file mode 100644 (file)
index 0000000..04c6ec2
--- /dev/null
@@ -0,0 +1,392 @@
+/*
+ * OMAP4 Bandgap temperature sensor driver
+ *
+ * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
+ * Contact:
+ *   Eduardo Valentin <eduardo.valentin@ti.com>
+ *
+ * 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.
+ *
+ * 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 St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#ifndef __TI_BANDGAP_H
+#define __TI_BANDGAP_H
+
+#include <linux/spinlock.h>
+#include <linux/types.h>
+#include <linux/err.h>
+
+/**
+ * DOC: bandgap driver data structure
+ * ==================================
+ *
+ *   +----------+----------------+
+ *   | struct temp_sensor_regval |
+ *   +---------------------------+
+ *              * (Array of)
+ *              |
+ *              |
+ *   +-------------------+   +-----------------+
+ *   | struct ti_bandgap |-->| struct device * |
+ *   +----------+--------+   +-----------------+
+ *              |
+ *              |
+ *              V
+ *   +------------------------+
+ *   | struct ti_bandgap_data |
+ *   +------------------------+
+ *              |
+ *              |
+ *              * (Array of)
+ * +------------+------------------------------------------------------+
+ * | +----------+------------+   +-------------------------+           |
+ * | | struct ti_temp_sensor |-->| struct temp_sensor_data |           |
+ * | +-----------------------+   +------------+------------+           |
+ * |            |                                                      |
+ * |            +                                                      |
+ * |            V                                                      |
+ * | +----------+-------------------+                                  |
+ * | | struct temp_sensor_registers |                                  |
+ * | +------------------------------+                                  |
+ * |                                                                   |
+ * +-------------------------------------------------------------------+
+ *
+ * Above is a simple diagram describing how the data structure below
+ * are organized. For each bandgap device there should be a ti_bandgap_data
+ * containing the device instance configuration, as well as, an array of
+ * sensors, representing every sensor instance present in this bandgap.
+ */
+
+/**
+ * struct temp_sensor_registers - descriptor to access registers and bitfields
+ * @temp_sensor_ctrl: TEMP_SENSOR_CTRL register offset
+ * @bgap_tempsoff_mask: mask to temp_sensor_ctrl.tempsoff
+ * @bgap_soc_mask: mask to temp_sensor_ctrl.soc
+ * @bgap_eocz_mask: mask to temp_sensor_ctrl.eocz
+ * @bgap_dtemp_mask: mask to temp_sensor_ctrl.dtemp
+ * @bgap_mask_ctrl: BANDGAP_MASK_CTRL register offset
+ * @mask_hot_mask: mask to bandgap_mask_ctrl.mask_hot
+ * @mask_cold_mask: mask to bandgap_mask_ctrl.mask_cold
+ * @mask_sidlemode_mask: mask to bandgap_mask_ctrl.mask_sidlemode
+ * @mask_freeze_mask: mask to bandgap_mask_ctrl.mask_free
+ * @mask_clear_mask: mask to bandgap_mask_ctrl.mask_clear
+ * @mask_clear_accum_mask: mask to bandgap_mask_ctrl.mask_clear_accum
+ * @bgap_mode_ctrl: BANDGAP_MODE_CTRL register offset
+ * @mode_ctrl_mask: mask to bandgap_mode_ctrl.mode_ctrl
+ * @bgap_counter: BANDGAP_COUNTER register offset
+ * @counter_mask: mask to bandgap_counter.counter
+ * @bgap_threshold: BANDGAP_THRESHOLD register offset (TALERT thresholds)
+ * @threshold_thot_mask: mask to bandgap_threhold.thot
+ * @threshold_tcold_mask: mask to bandgap_threhold.tcold
+ * @tshut_threshold: TSHUT_THRESHOLD register offset (TSHUT thresholds)
+ * @tshut_efuse_mask: mask to tshut_threshold.tshut_efuse
+ * @tshut_efuse_shift: shift to tshut_threshold.tshut_efuse
+ * @tshut_hot_mask: mask to tshut_threhold.thot
+ * @tshut_cold_mask: mask to tshut_threhold.thot
+ * @bgap_status: BANDGAP_STATUS register offset
+ * @status_clean_stop_mask: mask to bandgap_status.clean_stop
+ * @status_bgap_alert_mask: mask to bandgap_status.bandgap_alert
+ * @status_hot_mask: mask to bandgap_status.hot
+ * @status_cold_mask: mask to bandgap_status.cold
+ * @bgap_cumul_dtemp: BANDGAP_CUMUL_DTEMP register offset
+ * @ctrl_dtemp_0: CTRL_DTEMP0 register offset
+ * @ctrl_dtemp_1: CTRL_DTEMP1 register offset
+ * @ctrl_dtemp_2: CTRL_DTEMP2 register offset
+ * @ctrl_dtemp_3: CTRL_DTEMP3 register offset
+ * @ctrl_dtemp_4: CTRL_DTEMP4 register offset
+ * @bgap_efuse: BANDGAP_EFUSE register offset
+ *
+ * The register offsets and bitfields might change across
+ * OMAP and variants versions. Hence this struct serves as a
+ * descriptor map on how to access the registers and the bitfields.
+ *
+ * This descriptor contains registers of all versions of bandgap chips.
+ * Not all versions will use all registers, depending on the available
+ * features. Please read TRMs for descriptive explanation on each bitfield.
+ */
+
+struct temp_sensor_registers {
+       u32     temp_sensor_ctrl;
+       u32     bgap_tempsoff_mask;
+       u32     bgap_soc_mask;
+       u32     bgap_eocz_mask; /* not used: but needs revisit */
+       u32     bgap_dtemp_mask;
+
+       u32     bgap_mask_ctrl;
+       u32     mask_hot_mask;
+       u32     mask_cold_mask;
+       u32     mask_sidlemode_mask; /* not used: but may be needed for pm */
+       u32     mask_freeze_mask;
+       u32     mask_clear_mask; /* not used: but needed for trending */
+       u32     mask_clear_accum_mask; /* not used: but needed for trending */
+
+       u32     bgap_mode_ctrl;
+       u32     mode_ctrl_mask;
+
+       u32     bgap_counter;
+       u32     counter_mask;
+
+       u32     bgap_threshold;
+       u32     threshold_thot_mask;
+       u32     threshold_tcold_mask;
+
+       u32     tshut_threshold;
+       u32     tshut_efuse_mask; /* not used */
+       u32     tshut_efuse_shift; /* not used */
+       u32     tshut_hot_mask;
+       u32     tshut_cold_mask;
+
+       u32     bgap_status;
+       u32     status_clean_stop_mask; /* not used: but needed for trending */
+       u32     status_bgap_alert_mask; /* not used */
+       u32     status_hot_mask;
+       u32     status_cold_mask;
+
+       u32     bgap_cumul_dtemp; /* not used: but needed for trending */
+       u32     ctrl_dtemp_0; /* not used: but needed for trending */
+       u32     ctrl_dtemp_1; /* not used: but needed for trending */
+       u32     ctrl_dtemp_2; /* not used: but needed for trending */
+       u32     ctrl_dtemp_3; /* not used: but needed for trending */
+       u32     ctrl_dtemp_4; /* not used: but needed for trending */
+       u32     bgap_efuse;
+};
+
+/**
+ * struct temp_sensor_data - The thresholds and limits for temperature sensors.
+ * @tshut_hot: temperature to trigger a thermal reset (initial value)
+ * @tshut_cold: temp to get the plat out of reset due to thermal (init val)
+ * @t_hot: temperature to trigger a thermal alert (high initial value)
+ * @t_cold: temperature to trigger a thermal alert (low initial value)
+ * @min_freq: sensor minimum clock rate
+ * @max_freq: sensor maximum clock rate
+ * @max_temp: sensor maximum temperature
+ * @min_temp: sensor minimum temperature
+ * @hyst_val: temperature hysteresis considered while converting ADC values
+ * @update_int1: update interval
+ * @update_int2: update interval
+ *
+ * This data structure will hold the required thresholds and temperature limits
+ * for a specific temperature sensor, like shutdown temperature, alert
+ * temperature, clock / rate used, ADC conversion limits and update intervals
+ */
+struct temp_sensor_data {
+       u32     tshut_hot;
+       u32     tshut_cold;
+       u32     t_hot;
+       u32     t_cold;
+       u32     min_freq;
+       u32     max_freq;
+       int     max_temp;
+       int     min_temp;
+       int     hyst_val;
+       u32     update_int1; /* not used */
+       u32     update_int2; /* not used */
+};
+
+struct ti_bandgap_data;
+
+/**
+ * struct temp_sensor_regval - temperature sensor register values and priv data
+ * @bg_mode_ctrl: temp sensor control register value
+ * @bg_ctrl: bandgap ctrl register value
+ * @bg_counter: bandgap counter value
+ * @bg_threshold: bandgap threshold register value
+ * @tshut_threshold: bandgap tshut register value
+ * @data: private data
+ *
+ * Data structure to save and restore bandgap register set context. Only
+ * required registers are shadowed, when needed.
+ */
+struct temp_sensor_regval {
+       u32                     bg_mode_ctrl;
+       u32                     bg_ctrl;
+       u32                     bg_counter;
+       u32                     bg_threshold;
+       u32                     tshut_threshold;
+       void                    *data;
+};
+
+/**
+ * struct ti_bandgap - bandgap device structure
+ * @dev: struct device pointer
+ * @base: io memory base address
+ * @conf: struct with bandgap configuration set (# sensors, conv_table, etc)
+ * @regval: temperature sensor register values
+ * @fclock: pointer to functional clock of temperature sensor
+ * @div_clk: pointer to divider clock of temperature sensor fclk
+ * @lock: spinlock for ti_bandgap structure
+ * @irq: MPU IRQ number for thermal alert
+ * @tshut_gpio: GPIO where Tshut signal is routed
+ * @clk_rate: Holds current clock rate
+ *
+ * The bandgap device structure representing the bandgap device instance.
+ * It holds most of the dynamic stuff. Configurations and sensor specific
+ * entries are inside the @conf structure.
+ */
+struct ti_bandgap {
+       struct device                   *dev;
+       void __iomem                    *base;
+       const struct ti_bandgap_data    *conf;
+       struct temp_sensor_regval       *regval;
+       struct clk                      *fclock;
+       struct clk                      *div_clk;
+       spinlock_t                      lock; /* shields this struct */
+       int                             irq;
+       int                             tshut_gpio;
+       u32                             clk_rate;
+};
+
+/**
+ * struct ti_temp_sensor - bandgap temperature sensor configuration data
+ * @ts_data: pointer to struct with thresholds, limits of temperature sensor
+ * @registers: pointer to the list of register offsets and bitfields
+ * @domain: the name of the domain where the sensor is located
+ * @slope: sensor gradient slope info for hotspot extrapolation equation
+ * @constant: sensor gradient const info for hotspot extrapolation equation
+ * @slope_pcb: sensor gradient slope info for hotspot extrapolation equation
+ *             with no external influence
+ * @constant_pcb: sensor gradient const info for hotspot extrapolation equation
+ *             with no external influence
+ * @register_cooling: function to describe how this sensor is going to be cooled
+ * @unregister_cooling: function to release cooling data
+ *
+ * Data structure to describe a temperature sensor handled by a bandgap device.
+ * It should provide configuration details on this sensor, such as how to
+ * access the registers affecting this sensor, shadow register buffer, how to
+ * assess the gradient from hotspot, how to cooldown the domain when sensor
+ * reports too hot temperature.
+ */
+struct ti_temp_sensor {
+       struct temp_sensor_data         *ts_data;
+       struct temp_sensor_registers    *registers;
+       char                            *domain;
+       /* for hotspot extrapolation */
+       const int                       slope;
+       const int                       constant;
+       const int                       slope_pcb;
+       const int                       constant_pcb;
+       int (*register_cooling)(struct ti_bandgap *bgp, int id);
+       int (*unregister_cooling)(struct ti_bandgap *bgp, int id);
+};
+
+/**
+ * DOC: ti bandgap feature types
+ *
+ * TI_BANDGAP_FEATURE_TSHUT - used when the thermal shutdown signal output
+ *      of a bandgap device instance is routed to the processor. This means
+ *      the system must react and perform the shutdown by itself (handle an
+ *      IRQ, for instance).
+ *
+ * TI_BANDGAP_FEATURE_TSHUT_CONFIG - used when the bandgap device has control
+ *      over the thermal shutdown configuration. This means that the thermal
+ *      shutdown thresholds are programmable, for instance.
+ *
+ * TI_BANDGAP_FEATURE_TALERT - used when the bandgap device instance outputs
+ *      a signal representing violation of programmable alert thresholds.
+ *
+ * TI_BANDGAP_FEATURE_MODE_CONFIG - used when it is possible to choose which
+ *      mode, continuous or one shot, the bandgap device instance will operate.
+ *
+ * TI_BANDGAP_FEATURE_COUNTER - used when the bandgap device instance allows
+ *      programming the update interval of its internal state machine.
+ *
+ * TI_BANDGAP_FEATURE_POWER_SWITCH - used when the bandgap device allows
+ *      itself to be switched on/off.
+ *
+ * TI_BANDGAP_FEATURE_CLK_CTRL - used when the clocks feeding the bandgap
+ *      device are gateable or not.
+ *
+ * TI_BANDGAP_FEATURE_FREEZE_BIT - used when the bandgap device features
+ *      a history buffer that its update can be freezed/unfreezed.
+ *
+ * TI_BANDGAP_HAS(b, f) - macro to check if a bandgap device is capable of a
+ *      specific feature (above) or not. Return non-zero, if yes.
+ */
+#define TI_BANDGAP_FEATURE_TSHUT               BIT(0)
+#define TI_BANDGAP_FEATURE_TSHUT_CONFIG                BIT(1)
+#define TI_BANDGAP_FEATURE_TALERT              BIT(2)
+#define TI_BANDGAP_FEATURE_MODE_CONFIG         BIT(3)
+#define TI_BANDGAP_FEATURE_COUNTER             BIT(4)
+#define TI_BANDGAP_FEATURE_POWER_SWITCH                BIT(5)
+#define TI_BANDGAP_FEATURE_CLK_CTRL            BIT(6)
+#define TI_BANDGAP_FEATURE_FREEZE_BIT          BIT(7)
+#define TI_BANDGAP_HAS(b, f)                   \
+                       ((b)->conf->features & TI_BANDGAP_FEATURE_ ## f)
+
+/**
+ * struct ti_bandgap_data - ti bandgap data configuration structure
+ * @features: a bitwise flag set to describe the device features
+ * @conv_table: Pointer to ADC to temperature conversion table
+ * @adc_start_val: ADC conversion table starting value
+ * @adc_end_val: ADC conversion table ending value
+ * @fclock_name: clock name of the functional clock
+ * @div_ck_name: clock name of the clock divisor
+ * @sensor_count: count of temperature sensor within this bandgap device
+ * @report_temperature: callback to report thermal alert to thermal API
+ * @expose_sensor: callback to export sensor to thermal API
+ * @remove_sensor: callback to destroy sensor from thermal API
+ * @sensors: array of sensors present in this bandgap instance
+ *
+ * This is a data structure which should hold most of the static configuration
+ * of a bandgap device instance. It should describe which features this instance
+ * is capable of, the clock names to feed this device, the amount of sensors and
+ * their configuration representation, and how to export and unexport them to
+ * a thermal API.
+ */
+struct ti_bandgap_data {
+       unsigned int                    features;
+       const int                       *conv_table;
+       u32                             adc_start_val;
+       u32                             adc_end_val;
+       char                            *fclock_name;
+       char                            *div_ck_name;
+       int                             sensor_count;
+       int (*report_temperature)(struct ti_bandgap *bgp, int id);
+       int (*expose_sensor)(struct ti_bandgap *bgp, int id, char *domain);
+       int (*remove_sensor)(struct ti_bandgap *bgp, int id);
+
+       /* this needs to be at the end */
+       struct ti_temp_sensor           sensors[];
+};
+
+int ti_bandgap_read_thot(struct ti_bandgap *bgp, int id, int *thot);
+int ti_bandgap_write_thot(struct ti_bandgap *bgp, int id, int val);
+int ti_bandgap_read_tcold(struct ti_bandgap *bgp, int id, int *tcold);
+int ti_bandgap_write_tcold(struct ti_bandgap *bgp, int id, int val);
+int ti_bandgap_read_update_interval(struct ti_bandgap *bgp, int id,
+                                   int *interval);
+int ti_bandgap_write_update_interval(struct ti_bandgap *bgp, int id,
+                                    u32 interval);
+int ti_bandgap_read_temperature(struct ti_bandgap *bgp, int id,
+                                 int *temperature);
+int ti_bandgap_set_sensor_data(struct ti_bandgap *bgp, int id, void *data);
+void *ti_bandgap_get_sensor_data(struct ti_bandgap *bgp, int id);
+
+#ifdef CONFIG_OMAP4_THERMAL
+extern const struct ti_bandgap_data omap4430_data;
+extern const struct ti_bandgap_data omap4460_data;
+extern const struct ti_bandgap_data omap4470_data;
+#else
+#define omap4430_data                                  NULL
+#define omap4460_data                                  NULL
+#define omap4470_data                                  NULL
+#endif
+
+#ifdef CONFIG_OMAP5_THERMAL
+extern const struct ti_bandgap_data omap5430_data;
+#else
+#define omap5430_data                                  NULL
+#endif
+
+#endif
diff --git a/drivers/staging/ti-soc-thermal/ti-thermal-common.c b/drivers/staging/ti-soc-thermal/ti-thermal-common.c
new file mode 100644 (file)
index 0000000..231c549
--- /dev/null
@@ -0,0 +1,338 @@
+/*
+ * OMAP thermal driver interface
+ *
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ * Contact:
+ *   Eduardo Valentin <eduardo.valentin@ti.com>
+ *
+ * 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.
+ *
+ * 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 St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/gfp.h>
+#include <linux/kernel.h>
+#include <linux/workqueue.h>
+#include <linux/thermal.h>
+#include <linux/cpufreq.h>
+#include <linux/cpumask.h>
+#include <linux/cpu_cooling.h>
+
+#include "ti-thermal.h"
+#include "ti-bandgap.h"
+
+/* common data structures */
+struct ti_thermal_data {
+       struct thermal_zone_device *ti_thermal;
+       struct thermal_cooling_device *cool_dev;
+       struct ti_bandgap *bgp;
+       enum thermal_device_mode mode;
+       struct work_struct thermal_wq;
+       int sensor_id;
+};
+
+static void ti_thermal_work(struct work_struct *work)
+{
+       struct ti_thermal_data *data = container_of(work,
+                                       struct ti_thermal_data, thermal_wq);
+
+       thermal_zone_device_update(data->ti_thermal);
+
+       dev_dbg(&data->ti_thermal->device, "updated thermal zone %s\n",
+               data->ti_thermal->type);
+}
+
+/**
+ * ti_thermal_hotspot_temperature - returns sensor extrapolated temperature
+ * @t: omap sensor temperature
+ * @s: omap sensor slope value
+ * @c: omap sensor const value
+ */
+static inline int ti_thermal_hotspot_temperature(int t, int s, int c)
+{
+       int delta = t * s / 1000 + c;
+
+       if (delta < 0)
+               delta = 0;
+
+       return t + delta;
+}
+
+/* thermal zone ops */
+/* Get temperature callback function for thermal zone*/
+static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal,
+                                     unsigned long *temp)
+{
+       struct ti_thermal_data *data = thermal->devdata;
+       struct ti_bandgap *bgp;
+       const struct ti_temp_sensor *s;
+       int ret, tmp, pcb_temp, slope, constant;
+
+       if (!data)
+               return 0;
+
+       bgp = data->bgp;
+       s = &bgp->conf->sensors[data->sensor_id];
+
+       ret = ti_bandgap_read_temperature(bgp, data->sensor_id, &tmp);
+       if (ret)
+               return ret;
+
+       pcb_temp = 0;
+       /* TODO: Introduce pcb temperature lookup */
+       /* In case pcb zone is available, use the extrapolation rule with it */
+       if (pcb_temp) {
+               tmp -= pcb_temp;
+               slope = s->slope_pcb;
+               constant = s->constant_pcb;
+       } else {
+               slope = s->slope;
+               constant = s->constant;
+       }
+       *temp = ti_thermal_hotspot_temperature(tmp, slope, constant);
+
+       return ret;
+}
+
+/* Bind callback functions for thermal zone */
+static int ti_thermal_bind(struct thermal_zone_device *thermal,
+                          struct thermal_cooling_device *cdev)
+{
+       struct ti_thermal_data *data = thermal->devdata;
+       int id;
+
+       if (IS_ERR_OR_NULL(data))
+               return -ENODEV;
+
+       /* check if this is the cooling device we registered */
+       if (data->cool_dev != cdev)
+               return 0;
+
+       id = data->sensor_id;
+
+       /* TODO: bind with min and max states */
+       /* Simple thing, two trips, one passive another critical */
+       return thermal_zone_bind_cooling_device(thermal, 0, cdev,
+                                               THERMAL_NO_LIMIT,
+                                               THERMAL_NO_LIMIT);
+}
+
+/* Unbind callback functions for thermal zone */
+static int ti_thermal_unbind(struct thermal_zone_device *thermal,
+                            struct thermal_cooling_device *cdev)
+{
+       struct ti_thermal_data *data = thermal->devdata;
+
+       if (IS_ERR_OR_NULL(data))
+               return -ENODEV;
+
+       /* check if this is the cooling device we registered */
+       if (data->cool_dev != cdev)
+               return 0;
+
+       /* Simple thing, two trips, one passive another critical */
+       return thermal_zone_unbind_cooling_device(thermal, 0, cdev);
+}
+
+/* Get mode callback functions for thermal zone */
+static int ti_thermal_get_mode(struct thermal_zone_device *thermal,
+                              enum thermal_device_mode *mode)
+{
+       struct ti_thermal_data *data = thermal->devdata;
+
+       if (data)
+               *mode = data->mode;
+
+       return 0;
+}
+
+/* Set mode callback functions for thermal zone */
+static int ti_thermal_set_mode(struct thermal_zone_device *thermal,
+                              enum thermal_device_mode mode)
+{
+       struct ti_thermal_data *data = thermal->devdata;
+
+       if (!data->ti_thermal) {
+               dev_notice(&thermal->device, "thermal zone not registered\n");
+               return 0;
+       }
+
+       mutex_lock(&data->ti_thermal->lock);
+
+       if (mode == THERMAL_DEVICE_ENABLED)
+               data->ti_thermal->polling_delay = FAST_TEMP_MONITORING_RATE;
+       else
+               data->ti_thermal->polling_delay = 0;
+
+       mutex_unlock(&data->ti_thermal->lock);
+
+       data->mode = mode;
+       thermal_zone_device_update(data->ti_thermal);
+       dev_dbg(&thermal->device, "thermal polling set for duration=%d msec\n",
+               data->ti_thermal->polling_delay);
+
+       return 0;
+}
+
+/* Get trip type callback functions for thermal zone */
+static int ti_thermal_get_trip_type(struct thermal_zone_device *thermal,
+                                   int trip, enum thermal_trip_type *type)
+{
+       if (!ti_thermal_is_valid_trip(trip))
+               return -EINVAL;
+
+       if (trip + 1 == OMAP_TRIP_NUMBER)
+               *type = THERMAL_TRIP_CRITICAL;
+       else
+               *type = THERMAL_TRIP_PASSIVE;
+
+       return 0;
+}
+
+/* Get trip temperature callback functions for thermal zone */
+static int ti_thermal_get_trip_temp(struct thermal_zone_device *thermal,
+                                   int trip, unsigned long *temp)
+{
+       if (!ti_thermal_is_valid_trip(trip))
+               return -EINVAL;
+
+       *temp = ti_thermal_get_trip_value(trip);
+
+       return 0;
+}
+
+/* Get critical temperature callback functions for thermal zone */
+static int ti_thermal_get_crit_temp(struct thermal_zone_device *thermal,
+                                   unsigned long *temp)
+{
+       /* shutdown zone */
+       return ti_thermal_get_trip_temp(thermal, OMAP_TRIP_NUMBER - 1, temp);
+}
+
+static struct thermal_zone_device_ops ti_thermal_ops = {
+       .get_temp = ti_thermal_get_temp,
+       /* TODO: add .get_trend */
+       .bind = ti_thermal_bind,
+       .unbind = ti_thermal_unbind,
+       .get_mode = ti_thermal_get_mode,
+       .set_mode = ti_thermal_set_mode,
+       .get_trip_type = ti_thermal_get_trip_type,
+       .get_trip_temp = ti_thermal_get_trip_temp,
+       .get_crit_temp = ti_thermal_get_crit_temp,
+};
+
+static struct ti_thermal_data
+*ti_thermal_build_data(struct ti_bandgap *bgp, int id)
+{
+       struct ti_thermal_data *data;
+
+       data = devm_kzalloc(bgp->dev, sizeof(*data), GFP_KERNEL);
+       if (!data) {
+               dev_err(bgp->dev, "kzalloc fail\n");
+               return NULL;
+       }
+       data->sensor_id = id;
+       data->bgp = bgp;
+       data->mode = THERMAL_DEVICE_ENABLED;
+       INIT_WORK(&data->thermal_wq, ti_thermal_work);
+
+       return data;
+}
+
+int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id,
+                            char *domain)
+{
+       struct ti_thermal_data *data;
+
+       data = ti_bandgap_get_sensor_data(bgp, id);
+
+       if (IS_ERR_OR_NULL(data))
+               data = ti_thermal_build_data(bgp, id);
+
+       if (!data)
+               return -EINVAL;
+
+       /* TODO: remove TC1 TC2 */
+       /* Create thermal zone */
+       data->ti_thermal = thermal_zone_device_register(domain,
+                               OMAP_TRIP_NUMBER, 0, data, &ti_thermal_ops,
+                               NULL, FAST_TEMP_MONITORING_RATE,
+                               FAST_TEMP_MONITORING_RATE);
+       if (IS_ERR_OR_NULL(data->ti_thermal)) {
+               dev_err(bgp->dev, "thermal zone device is NULL\n");
+               return PTR_ERR(data->ti_thermal);
+       }
+       data->ti_thermal->polling_delay = FAST_TEMP_MONITORING_RATE;
+       ti_bandgap_set_sensor_data(bgp, id, data);
+
+       return 0;
+}
+
+int ti_thermal_remove_sensor(struct ti_bandgap *bgp, int id)
+{
+       struct ti_thermal_data *data;
+
+       data = ti_bandgap_get_sensor_data(bgp, id);
+
+       thermal_zone_device_unregister(data->ti_thermal);
+
+       return 0;
+}
+
+int ti_thermal_report_sensor_temperature(struct ti_bandgap *bgp, int id)
+{
+       struct ti_thermal_data *data;
+
+       data = ti_bandgap_get_sensor_data(bgp, id);
+
+       schedule_work(&data->thermal_wq);
+
+       return 0;
+}
+
+int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id)
+{
+       struct ti_thermal_data *data;
+
+       data = ti_bandgap_get_sensor_data(bgp, id);
+       if (IS_ERR_OR_NULL(data))
+               data = ti_thermal_build_data(bgp, id);
+
+       if (!data)
+               return -EINVAL;
+
+       /* Register cooling device */
+       data->cool_dev = cpufreq_cooling_register(cpu_present_mask);
+       if (IS_ERR_OR_NULL(data->cool_dev)) {
+               dev_err(bgp->dev,
+                       "Failed to register cpufreq cooling device\n");
+               return PTR_ERR(data->cool_dev);
+       }
+       ti_bandgap_set_sensor_data(bgp, id, data);
+
+       return 0;
+}
+
+int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id)
+{
+       struct ti_thermal_data *data;
+
+       data = ti_bandgap_get_sensor_data(bgp, id);
+       cpufreq_cooling_unregister(data->cool_dev);
+
+       return 0;
+}
diff --git a/drivers/staging/ti-soc-thermal/ti-thermal.h b/drivers/staging/ti-soc-thermal/ti-thermal.h
new file mode 100644 (file)
index 0000000..ef6981c
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * OMAP thermal definitions
+ *
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
+ * Contact:
+ *   Eduardo Valentin <eduardo.valentin@ti.com>
+ *
+ * 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.
+ *
+ * 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 St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#ifndef __TI_THERMAL_H
+#define __TI_THERMAL_H
+
+#include "ti-bandgap.h"
+
+/* sensors gradient and offsets */
+#define OMAP_GRADIENT_SLOPE_4460                               348
+#define OMAP_GRADIENT_CONST_4460                               -9301
+#define OMAP_GRADIENT_SLOPE_4470                               308
+#define OMAP_GRADIENT_CONST_4470                               -7896
+
+#define OMAP_GRADIENT_SLOPE_5430_CPU                           196
+#define OMAP_GRADIENT_CONST_5430_CPU                           -6822
+#define OMAP_GRADIENT_SLOPE_5430_GPU                           64
+#define OMAP_GRADIENT_CONST_5430_GPU                           978
+
+/* PCB sensor calculation constants */
+#define OMAP_GRADIENT_SLOPE_W_PCB_4460                         1142
+#define OMAP_GRADIENT_CONST_W_PCB_4460                         -393
+#define OMAP_GRADIENT_SLOPE_W_PCB_4470                         1063
+#define OMAP_GRADIENT_CONST_W_PCB_4470                         -477
+
+#define OMAP_GRADIENT_SLOPE_W_PCB_5430_CPU                     469
+#define OMAP_GRADIENT_CONST_W_PCB_5430_CPU                     -1272
+#define OMAP_GRADIENT_SLOPE_W_PCB_5430_GPU                     378
+#define OMAP_GRADIENT_CONST_W_PCB_5430_GPU                     154
+
+/* trip points of interest in milicelsius (at hotspot level) */
+#define OMAP_TRIP_COLD                                         100000
+#define OMAP_TRIP_HOT                                          110000
+#define OMAP_TRIP_SHUTDOWN                                     125000
+#define OMAP_TRIP_NUMBER                                       2
+#define OMAP_TRIP_STEP                                                 \
+       ((OMAP_TRIP_SHUTDOWN - OMAP_TRIP_HOT) / (OMAP_TRIP_NUMBER - 1))
+
+/* Update rates */
+#define FAST_TEMP_MONITORING_RATE                              250
+
+/* helper macros */
+/**
+ * ti_thermal_get_trip_value - returns trip temperature based on index
+ * @i: trip index
+ */
+#define ti_thermal_get_trip_value(i)                                   \
+       (OMAP_TRIP_HOT + ((i) * OMAP_TRIP_STEP))
+
+/**
+ * ti_thermal_is_valid_trip - check for trip index
+ * @i: trip index
+ */
+#define ti_thermal_is_valid_trip(trip)                         \
+       ((trip) >= 0 && (trip) < OMAP_TRIP_NUMBER)
+
+#ifdef CONFIG_TI_THERMAL
+int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id, char *domain);
+int ti_thermal_remove_sensor(struct ti_bandgap *bgp, int id);
+int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id);
+int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id);
+#else
+static inline
+int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id, char *domain)
+{
+       return 0;
+}
+
+static inline
+int ti_thermal_remove_sensor(struct ti_bandgap *bgp, int id)
+{
+       return 0;
+}
+
+static inline
+int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id)
+{
+       return 0;
+}
+
+static inline
+int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id)
+{
+       return 0;
+}
+#endif
+#endif
diff --git a/drivers/staging/ti-soc-thermal/ti_soc_thermal.txt b/drivers/staging/ti-soc-thermal/ti_soc_thermal.txt
new file mode 100644 (file)
index 0000000..a4a33d1
--- /dev/null
@@ -0,0 +1,60 @@
+* Texas Instrument OMAP SCM bandgap bindings
+
+In the System Control Module, OMAP supplies a voltage reference
+and a temperature sensor feature that are gathered in the band
+gap voltage and temperature sensor (VBGAPTS) module. The band
+gap provides current and voltage reference for its internal
+circuits and other analog IP blocks. The analog-to-digital
+converter (ADC) produces an output value that is proportional
+to the silicon temperature.
+
+Required properties:
+- compatible : Should be:
+  - "ti,omap4430-bandgap" : for OMAP4430 bandgap
+  - "ti,omap4460-bandgap" : for OMAP4460 bandgap
+  - "ti,omap4470-bandgap" : for OMAP4470 bandgap
+  - "ti,omap5430-bandgap" : for OMAP5430 bandgap
+- interrupts : this entry should indicate which interrupt line
+the talert signal is routed to;
+Specific:
+- ti,tshut-gpio : this entry should be used to inform which GPIO
+line the tshut signal is routed to;
+- regs : this entry must also be specified and it is specific
+to each bandgap version, because the mapping may change from
+soc to soc, apart of depending on available features.
+
+Example:
+OMAP4430:
+bandgap {
+       reg = <0x4a002260 0x4 0x4a00232C 0x4>;
+       compatible = "ti,omap4430-bandgap";
+};
+
+OMAP4460:
+bandgap {
+       reg = <0x4a002260 0x4
+               0x4a00232C 0x4
+               0x4a002378 0x18>;
+       compatible = "ti,omap4460-bandgap";
+       interrupts = <0 126 4>; /* talert */
+       ti,tshut-gpio = <86>;
+};
+
+OMAP4470:
+bandgap {
+       reg = <0x4a002260 0x4
+               0x4a00232C 0x4
+               0x4a002378 0x18>;
+       compatible = "ti,omap4470-bandgap";
+       interrupts = <0 126 4>; /* talert */
+       ti,tshut-gpio = <86>;
+};
+
+OMAP5430:
+bandgap {
+       reg = <0x4a0021e0 0xc
+               0x4a00232c 0xc
+               0x4a002380 0x2c
+               0x4a0023C0 0x3c>;
+       compatible = "ti,omap5430-bandgap";
+};
index 0df55bd5bde48bbb2fd8f9a96349f3fb463b9b57..cd5235a4f77c855a183cae9dca8437d97010a4ca 100644 (file)
@@ -488,7 +488,7 @@ func_end:
  *      Call the bridge_dev_ctrl fxn with the Argument. This is a Synchronous
  *      Operation. arg can be null.
  */
-int proc_ctrl(void *hprocessor, u32 dw_cmd, struct dsp_cbdata * arg)
+int proc_ctrl(void *hprocessor, u32 dw_cmd, struct dsp_cbdata *arg)
 {
        int status = 0;
        struct proc_object *p_proc_object = hprocessor;
@@ -982,7 +982,7 @@ int proc_get_state(void *hprocessor,
  *      This call is destructive, meaning the processor is placed in the monitor
  *      state as a result of this function.
  */
-int proc_get_trace(void *hprocessor, u8 * pbuf, u32 max_size)
+int proc_get_trace(void *hprocessor, u8 *pbuf, u32 max_size)
 {
        int status;
        status = -ENOSYS;
@@ -1338,7 +1338,7 @@ func_end:
  */
 int proc_register_notify(void *hprocessor, u32 event_mask,
                                u32 notify_type, struct dsp_notification
-                               * hnotification)
+                               *hnotification)
 {
        int status = 0;
        struct proc_object *p_proc_object = (struct proc_object *)hprocessor;
@@ -1549,8 +1549,8 @@ int proc_stop(void *hprocessor)
                status = node_enum_nodes(hnode_mgr, &hnode, node_tab_size,
                                         &num_nodes, &nodes_allocated);
                if ((status == -EINVAL) || (nodes_allocated > 0)) {
-                       pr_err("%s: Can't stop device, active nodes = %d \n",
-                              __func__, nodes_allocated);
+                       pr_err("%s: Can't stop device, active nodes = %d\n",
+                               __func__, nodes_allocated);
                        return -EBADR;
                }
        }
@@ -1819,7 +1819,7 @@ func_end:
  *  Purpose:
  *      Retrieves the processor ID.
  */
-int proc_get_processor_id(void *proc, u32 * proc_id)
+int proc_get_processor_id(void *proc, u32 *proc_id)
 {
        int status = 0;
        struct proc_object *p_proc_object = (struct proc_object *)proc;
index 34cc934e0c3d2e3d3ba7df63ef3434f6a6b44521..b88b27bbe2e7a4f791e959c37ad79af2b229a474 100644 (file)
@@ -223,7 +223,7 @@ void strm_delete(struct strm_mgr *strm_mgr_obj)
  *  Purpose:
  *      Frees the buffers allocated for a stream.
  */
-int strm_free_buffer(struct strm_res_object *strmres, u8 ** ap_buffer,
+int strm_free_buffer(struct strm_res_object *strmres, u8 **ap_buffer,
                            u32 num_bufs, struct process_context *pr_ctxt)
 {
        int status = 0;
@@ -523,7 +523,7 @@ func_cont:
  *  Purpose:
  *      Relcaims a buffer from a stream.
  */
-int strm_reclaim(struct strm_object *stream_obj, u8 ** buf_ptr,
+int strm_reclaim(struct strm_object *stream_obj, u8 **buf_ptr,
                        u32 *nbytes, u32 *buff_size, u32 *pdw_arg)
 {
        struct bridge_drv_interface *intf_fxns;
@@ -599,7 +599,7 @@ func_end:
  */
 int strm_register_notify(struct strm_object *stream_obj, u32 event_mask,
                                u32 notify_type, struct dsp_notification
-                               * hnotification)
+                               *hnotification)
 {
        struct bridge_drv_interface *intf_fxns;
        int status = 0;
index 67556acd151479122ff0728c5c3eefa1e7cc93c3..0a70b8ea920959201626008cd8eddc95da704fd5 100644 (file)
@@ -114,8 +114,10 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
 
                spin_unlock_irq(&sdev->ud.lock);
 
-               sdev->ud.tcp_rx = kthread_get_run(stub_rx_loop, &sdev->ud, "stub_rx");
-               sdev->ud.tcp_tx = kthread_get_run(stub_tx_loop, &sdev->ud, "stub_tx");
+               sdev->ud.tcp_rx = kthread_get_run(stub_rx_loop, &sdev->ud,
+                                                 "stub_rx");
+               sdev->ud.tcp_tx = kthread_get_run(stub_tx_loop, &sdev->ud,
+                                                 "stub_tx");
 
                spin_lock_irq(&sdev->ud.lock);
                sdev->ud.status = SDEV_ST_USED;
index b4de18b4bb9cd5deb4c7c246e39a4595dfb95cf6..3b151dff85a6d4821d050297791fd57494b3284f 100644 (file)
@@ -22,8 +22,8 @@
  */
 
 /*
- *     Copyright (C) 2005 Takahiro Hirofuchi
- *             - names_deinit() is added.
+ *     Copyright (C) 2005 Takahiro Hirofuchi
+ *             - names_deinit() is added.
  */
 
 /*****************************************************************************/
@@ -82,9 +82,9 @@ struct audioterminal {
 };
 
 struct genericstrtable {
-        struct genericstrtable *next;
-        unsigned int num;
-        char name[1];
+       struct genericstrtable *next;
+       unsigned int num;
+       char name[1];
 };
 
 /* ---------------------------------------------------------------------- */
@@ -122,14 +122,15 @@ static struct genericstrtable *countrycodes[HASHSZ] = { NULL, };
 
 /* ---------------------------------------------------------------------- */
 
-static const char *names_genericstrtable(struct genericstrtable *t[HASHSZ], unsigned int index)
+static const char *names_genericstrtable(struct genericstrtable *t[HASHSZ],
+                                        unsigned int index)
 {
-        struct genericstrtable *h;
+       struct genericstrtable *h;
 
-        for (h = t[hashnum(index)]; h; h = h->next)
-                if (h->num == index)
-                        return h->name;
-        return NULL;
+       for (h = t[hashnum(index)]; h; h = h->next)
+               if (h->num == index)
+                       return h->name;
+       return NULL;
 }
 
 const char *names_hid(u_int8_t hidd)
@@ -216,13 +217,16 @@ const char *names_subclass(u_int8_t classid, u_int8_t subclassid)
        return NULL;
 }
 
-const char *names_protocol(u_int8_t classid, u_int8_t subclassid, u_int8_t protocolid)
+const char *names_protocol(u_int8_t classid, u_int8_t subclassid,
+                          u_int8_t protocolid)
 {
        struct protocol *p;
 
-       p = protocols[hashnum((classid << 16) | (subclassid << 8) | protocolid)];
+       p = protocols[hashnum((classid << 16) | (subclassid << 8)
+                             | protocolid)];
        for (; p; p = p->next)
-               if (p->classid == classid && p->subclassid == subclassid && p->protocolid == protocolid)
+               if (p->classid == classid && p->subclassid == subclassid &&
+                   p->protocolid == protocolid)
                        return p->name;
        return NULL;
 }
@@ -246,7 +250,7 @@ struct pool {
        void *mem;
 };
 
-static struct pool *pool_head = NULL;
+static struct pool *pool_head;
 
 static void *my_malloc(size_t size)
 {
@@ -308,7 +312,8 @@ static int new_vendor(const char *name, u_int16_t vendorid)
        return 0;
 }
 
-static int new_product(const char *name, u_int16_t vendorid, u_int16_t productid)
+static int new_product(const char *name, u_int16_t vendorid,
+                      u_int16_t productid)
 {
        struct product *p;
        unsigned int h = hashnum((vendorid << 16) | productid);
@@ -367,14 +372,17 @@ static int new_subclass(const char *name, u_int8_t classid, u_int8_t subclassid)
        return 0;
 }
 
-static int new_protocol(const char *name, u_int8_t classid, u_int8_t subclassid, u_int8_t protocolid)
+static int new_protocol(const char *name, u_int8_t classid, u_int8_t subclassid,
+                       u_int8_t protocolid)
 {
        struct protocol *p;
-       unsigned int h = hashnum((classid << 16) | (subclassid << 8) | protocolid);
+       unsigned int h = hashnum((classid << 16) | (subclassid << 8)
+                                | protocolid);
 
        p = protocols[h];
        for (; p; p = p->next)
-               if (p->classid == classid && p->subclassid == subclassid && p->protocolid == protocolid)
+               if (p->classid == classid && p->subclassid == subclassid
+                   && p->protocolid == protocolid)
                        return -1;
        p = my_malloc(sizeof(struct protocol) + strlen(name));
        if (!p)
@@ -407,22 +415,23 @@ static int new_audioterminal(const char *name, u_int16_t termt)
        return 0;
 }
 
-static int new_genericstrtable(struct genericstrtable *t[HASHSZ], const char *name, unsigned int index)
+static int new_genericstrtable(struct genericstrtable *t[HASHSZ],
+                              const char *name, unsigned int index)
 {
-        struct genericstrtable *g;
+       struct genericstrtable *g;
        unsigned int h = hashnum(index);
 
-        for (g = t[h]; g; g = g->next)
-                if (g->num == index)
-                        return -1;
-        g = my_malloc(sizeof(struct genericstrtable) + strlen(name));
-        if (!g)
-                return -1;
-        strcpy(g->name, name);
-        g->num = index;
-        g->next = t[h];
-        t[h] = g;
-        return 0;
+       for (g = t[h]; g; g = g->next)
+               if (g->num == index)
+                       return -1;
+       g = my_malloc(sizeof(struct genericstrtable) + strlen(name));
+       if (!g)
+               return -1;
+       strcpy(g->name, name);
+       g->num = index;
+       g->next = t[h];
+       t[h] = g;
+       return 0;
 }
 
 static int new_hid(const char *name, u_int8_t hidd)
@@ -472,123 +481,151 @@ static void parse(FILE *f)
 {
        char buf[512], *cp;
        unsigned int linectr = 0;
-       int lastvendor = -1, lastclass = -1, lastsubclass = -1, lasthut=-1, lastlang=-1;
+       int lastvendor = -1;
+       int lastclass = -1;
+       int lastsubclass = -1;
+       int lasthut = -1;
+       int lastlang = -1;
        unsigned int u;
 
        while (fgets(buf, sizeof(buf), f)) {
                linectr++;
                /* remove line ends */
-               if ((cp = strchr(buf, 13)))
+               cp = strchr(buf, 13);
+               if (cp)
                        *cp = 0;
-               if ((cp = strchr(buf, 10)))
+               cp = strchr(buf, 10);
+               if (cp)
                        *cp = 0;
                if (buf[0] == '#' || !buf[0])
                        continue;
                cp = buf;
-                if (buf[0] == 'P' && buf[1] == 'H' && buf[2] == 'Y' && buf[3] == 'S' && buf[4] == 'D' &&
-                    buf[5] == 'E' && buf[6] == 'S' && /*isspace(buf[7])*/ buf[7] == ' ') {
-                        cp = buf + 8;
-                        while (isspace(*cp))
-                                cp++;
-                        if (!isxdigit(*cp)) {
-                                fprintf(stderr, "Invalid Physdes type at line %u\n", linectr);
-                                continue;
-                        }
-                        u = strtoul(cp, &cp, 16);
-                        while (isspace(*cp))
-                                cp++;
-                        if (!*cp) {
-                                fprintf(stderr, "Invalid Physdes type at line %u\n", linectr);
-                                continue;
-                        }
-                        if (new_physdes(cp, u))
-                                fprintf(stderr, "Duplicate Physdes  type spec at line %u terminal type %04x %s\n", linectr, u, cp);
-                        DBG(printf("line %5u physdes type %02x %s\n", linectr, u, cp));
-                        continue;
-
-                }
-                if (buf[0] == 'P' && buf[1] == 'H' && buf[2] == 'Y' && /*isspace(buf[3])*/ buf[3] == ' ') {
-                        cp = buf + 4;
-                        while (isspace(*cp))
-                                cp++;
-                        if (!isxdigit(*cp)) {
-                                fprintf(stderr, "Invalid PHY type at line %u\n", linectr);
-                                continue;
-                        }
-                        u = strtoul(cp, &cp, 16);
-                        while (isspace(*cp))
-                                cp++;
-                        if (!*cp) {
-                                fprintf(stderr, "Invalid PHY type at line %u\n", linectr);
-                                continue;
-                        }
-                        if (new_physdes(cp, u))
-                                fprintf(stderr, "Duplicate PHY type spec at line %u terminal type %04x %s\n", linectr, u, cp);
-                        DBG(printf("line %5u PHY type %02x %s\n", linectr, u, cp));
-                        continue;
-
-                }
-                if (buf[0] == 'B' && buf[1] == 'I' && buf[2] == 'A' && buf[3] == 'S' && /*isspace(buf[4])*/ buf[4] == ' ') {
-                        cp = buf + 5;
-                        while (isspace(*cp))
-                                cp++;
-                        if (!isxdigit(*cp)) {
-                                fprintf(stderr, "Invalid BIAS type at line %u\n", linectr);
-                                continue;
-                        }
-                        u = strtoul(cp, &cp, 16);
-                        while (isspace(*cp))
-                                cp++;
-                        if (!*cp) {
-                                fprintf(stderr, "Invalid BIAS type at line %u\n", linectr);
-                                continue;
-                        }
-                        if (new_bias(cp, u))
-                                fprintf(stderr, "Duplicate BIAS  type spec at line %u terminal type %04x %s\n", linectr, u, cp);
-                        DBG(printf("line %5u BIAS type %02x %s\n", linectr, u, cp));
-                        continue;
-
-                }
-                if (buf[0] == 'L' && /*isspace(buf[1])*/ buf[1] == ' ') {
-                        cp =  buf+2;
-                        while (isspace(*cp))
-                                cp++;
-                        if (!isxdigit(*cp)) {
-                                fprintf(stderr, "Invalid LANGID spec at line %u\n", linectr);
-                                continue;
-                        }
-                        u = strtoul(cp, &cp, 16);
-                        while (isspace(*cp))
-                                cp++;
-                        if (!*cp) {
-                                fprintf(stderr, "Invalid LANGID spec at line %u\n", linectr);
-                                continue;
-                        }
-                        if (new_langid(cp, u))
-                                fprintf(stderr, "Duplicate LANGID spec at line %u language-id %04x %s\n", linectr, u, cp);
-                        DBG(printf("line %5u LANGID %02x %s\n", linectr, u, cp));
-                        lasthut = lastclass = lastvendor = lastsubclass = -1;
-                        lastlang = u;
-                        continue;
-                }
+               if (buf[0] == 'P' && buf[1] == 'H' && buf[2] == 'Y'
+                   && buf[3] == 'S' && buf[4] == 'D' && buf[5] == 'E'
+                   && buf[6] == 'S' && /*isspace(buf[7])*/ buf[7] == ' ') {
+                       cp = buf + 8;
+                       while (isspace(*cp))
+                               cp++;
+                       if (!isxdigit(*cp)) {
+                               fprintf(stderr, "Invalid Physdes type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       u = strtoul(cp, &cp, 16);
+                       while (isspace(*cp))
+                               cp++;
+                       if (!*cp) {
+                               fprintf(stderr, "Invalid Physdes type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       if (new_physdes(cp, u))
+                               fprintf(stderr, "Duplicate Physdes  type spec at line %u terminal type %04x %s\n",
+                                       linectr, u, cp);
+                       DBG(printf("line %5u physdes type %02x %s\n", linectr,
+                                  u, cp));
+                       continue;
+
+               }
+               if (buf[0] == 'P' && buf[1] == 'H' && buf[2] == 'Y'
+                   && /*isspace(buf[3])*/ buf[3] == ' ') {
+                       cp = buf + 4;
+                       while (isspace(*cp))
+                               cp++;
+                       if (!isxdigit(*cp)) {
+                               fprintf(stderr, "Invalid PHY type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       u = strtoul(cp, &cp, 16);
+                       while (isspace(*cp))
+                               cp++;
+                       if (!*cp) {
+                               fprintf(stderr, "Invalid PHY type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       if (new_physdes(cp, u))
+                               fprintf(stderr, "Duplicate PHY type spec at line %u terminal type %04x %s\n",
+                                       linectr, u, cp);
+                       DBG(printf("line %5u PHY type %02x %s\n", linectr, u,
+                                  cp));
+                       continue;
+
+               }
+               if (buf[0] == 'B' && buf[1] == 'I' && buf[2] == 'A'
+                   && buf[3] == 'S' && /*isspace(buf[4])*/ buf[4] == ' ') {
+                       cp = buf + 5;
+                       while (isspace(*cp))
+                               cp++;
+                       if (!isxdigit(*cp)) {
+                               fprintf(stderr, "Invalid BIAS type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       u = strtoul(cp, &cp, 16);
+                       while (isspace(*cp))
+                               cp++;
+                       if (!*cp) {
+                               fprintf(stderr, "Invalid BIAS type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       if (new_bias(cp, u))
+                               fprintf(stderr, "Duplicate BIAS  type spec at line %u terminal type %04x %s\n",
+                                       linectr, u, cp);
+                       DBG(printf("line %5u BIAS type %02x %s\n", linectr, u,
+                                  cp));
+                       continue;
+
+               }
+               if (buf[0] == 'L' && /*isspace(buf[1])*/ buf[1] == ' ') {
+                       cp =  buf+2;
+                       while (isspace(*cp))
+                               cp++;
+                       if (!isxdigit(*cp)) {
+                               fprintf(stderr, "Invalid LANGID spec at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       u = strtoul(cp, &cp, 16);
+                       while (isspace(*cp))
+                               cp++;
+                       if (!*cp) {
+                               fprintf(stderr, "Invalid LANGID spec at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       if (new_langid(cp, u))
+                               fprintf(stderr, "Duplicate LANGID spec at line %u language-id %04x %s\n",
+                                       linectr, u, cp);
+                       DBG(printf("line %5u LANGID %02x %s\n", linectr, u,
+                                  cp));
+                       lasthut = lastclass = lastvendor = lastsubclass = -1;
+                       lastlang = u;
+                       continue;
+               }
                if (buf[0] == 'C' && /*isspace(buf[1])*/ buf[1] == ' ') {
                        /* class spec */
                        cp = buf+2;
                        while (isspace(*cp))
                                cp++;
                        if (!isxdigit(*cp)) {
-                               fprintf(stderr, "Invalid class spec at line %u\n", linectr);
+                               fprintf(stderr, "Invalid class spec at line %u\n",
+                                       linectr);
                                continue;
                        }
                        u = strtoul(cp, &cp, 16);
                        while (isspace(*cp))
                                cp++;
                        if (!*cp) {
-                               fprintf(stderr, "Invalid class spec at line %u\n", linectr);
+                               fprintf(stderr, "Invalid class spec at line %u\n",
+                                       linectr);
                                continue;
                        }
                        if (new_class(cp, u))
-                               fprintf(stderr, "Duplicate class spec at line %u class %04x %s\n", linectr, u, cp);
+                               fprintf(stderr, "Duplicate class spec at line %u class %04x %s\n",
+                                       linectr, u, cp);
                        DBG(printf("line %5u class %02x %s\n", linectr, u, cp));
                        lasthut = lastlang = lastvendor = lastsubclass = -1;
                        lastclass = u;
@@ -600,41 +637,50 @@ static void parse(FILE *f)
                        while (isspace(*cp))
                                cp++;
                        if (!isxdigit(*cp)) {
-                               fprintf(stderr, "Invalid audio terminal type at line %u\n", linectr);
+                               fprintf(stderr, "Invalid audio terminal type at line %u\n",
+                                       linectr);
                                continue;
                        }
                        u = strtoul(cp, &cp, 16);
                        while (isspace(*cp))
                                cp++;
                        if (!*cp) {
-                               fprintf(stderr, "Invalid audio terminal type at line %u\n", linectr);
+                               fprintf(stderr, "Invalid audio terminal type at line %u\n",
+                                       linectr);
                                continue;
                        }
                        if (new_audioterminal(cp, u))
-                               fprintf(stderr, "Duplicate audio terminal type spec at line %u terminal type %04x %s\n", linectr, u, cp);
-                       DBG(printf("line %5u audio terminal type %02x %s\n", linectr, u, cp));
+                               fprintf(stderr, "Duplicate audio terminal type spec at line %u terminal type %04x %s\n",
+                                       linectr, u, cp);
+                       DBG(printf("line %5u audio terminal type %02x %s\n",
+                                  linectr, u, cp));
                        continue;
                }
-               if (buf[0] == 'H' && buf[1] == 'C' && buf[2] == 'C' && isspace(buf[3])) {
+               if (buf[0] == 'H' && buf[1] == 'C' && buf[2] == 'C'
+                   && isspace(buf[3])) {
                        /* HID Descriptor bCountryCode */
-                        cp =  buf+3;
-                        while (isspace(*cp))
-                                cp++;
-                        if (!isxdigit(*cp)) {
-                                fprintf(stderr, "Invalid HID country code at line %u\n", linectr);
-                                continue;
-                        }
-                        u = strtoul(cp, &cp, 10);
-                        while (isspace(*cp))
-                                cp++;
-                        if (!*cp) {
-                                fprintf(stderr, "Invalid HID country code at line %u\n", linectr);
-                                continue;
-                        }
-                        if (new_countrycode(cp, u))
-                                fprintf(stderr, "Duplicate HID country code at line %u country %02u %s\n", linectr, u, cp);
-                        DBG(printf("line %5u keyboard country code %02u %s\n", linectr, u, cp));
-                        continue;
+                       cp =  buf+3;
+                       while (isspace(*cp))
+                               cp++;
+                       if (!isxdigit(*cp)) {
+                               fprintf(stderr, "Invalid HID country code at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       u = strtoul(cp, &cp, 10);
+                       while (isspace(*cp))
+                               cp++;
+                       if (!*cp) {
+                               fprintf(stderr, "Invalid HID country code at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       if (new_countrycode(cp, u))
+                               fprintf(stderr, "Duplicate HID country code at line %u country %02u %s\n",
+                                       linectr, u, cp);
+                       DBG(printf("line %5u keyboard country code %02u %s\n",
+                                  linectr, u, cp));
+                       continue;
                }
                if (isxdigit(*cp)) {
                        /* vendor */
@@ -642,12 +688,15 @@ static void parse(FILE *f)
                        while (isspace(*cp))
                                cp++;
                        if (!*cp) {
-                               fprintf(stderr, "Invalid vendor spec at line %u\n", linectr);
+                               fprintf(stderr, "Invalid vendor spec at line %u\n",
+                                       linectr);
                                continue;
                        }
                        if (new_vendor(cp, u))
-                               fprintf(stderr, "Duplicate vendor spec at line %u vendor %04x %s\n", linectr, u, cp);
-                       DBG(printf("line %5u vendor %04x %s\n", linectr, u, cp));
+                               fprintf(stderr, "Duplicate vendor spec at line %u vendor %04x %s\n",
+                                       linectr, u, cp);
+                       DBG(printf("line %5u vendor %04x %s\n", linectr, u,
+                                  cp));
                        lastvendor = u;
                        lasthut = lastlang = lastclass = lastsubclass = -1;
                        continue;
@@ -658,33 +707,41 @@ static void parse(FILE *f)
                        while (isspace(*cp))
                                cp++;
                        if (!*cp) {
-                               fprintf(stderr, "Invalid product/subclass spec at line %u\n", linectr);
+                               fprintf(stderr, "Invalid product/subclass spec at line %u\n",
+                                       linectr);
                                continue;
                        }
                        if (lastvendor != -1) {
                                if (new_product(cp, lastvendor, u))
-                                       fprintf(stderr, "Duplicate product spec at line %u product %04x:%04x %s\n", linectr, lastvendor, u, cp);
-                               DBG(printf("line %5u product %04x:%04x %s\n", linectr, lastvendor, u, cp));
+                                       fprintf(stderr, "Duplicate product spec at line %u product %04x:%04x %s\n",
+                                               linectr, lastvendor, u, cp);
+                               DBG(printf("line %5u product %04x:%04x %s\n",
+                                          linectr, lastvendor, u, cp));
                                continue;
                        }
                        if (lastclass != -1) {
                                if (new_subclass(cp, lastclass, u))
-                                       fprintf(stderr, "Duplicate subclass spec at line %u class %02x:%02x %s\n", linectr, lastclass, u, cp);
-                               DBG(printf("line %5u subclass %02x:%02x %s\n", linectr, lastclass, u, cp));
+                                       fprintf(stderr, "Duplicate subclass spec at line %u class %02x:%02x %s\n",
+                                               linectr, lastclass, u, cp);
+                               DBG(printf("line %5u subclass %02x:%02x %s\n",
+                                          linectr, lastclass, u, cp));
                                lastsubclass = u;
                                continue;
                        }
                        if (lasthut != -1) {
                                if (new_hutus(cp, (lasthut << 16)+u))
-                                       fprintf(stderr, "Duplicate HUT Usage Spec at line %u\n", linectr);
+                                       fprintf(stderr, "Duplicate HUT Usage Spec at line %u\n",
+                                               linectr);
                                continue;
                        }
                        if (lastlang != -1) {
-                                if (new_langid(cp, lastlang+(u<<10)))
-                                        fprintf(stderr, "Duplicate LANGID Usage Spec at line %u\n", linectr);
-                                continue;
-                        }
-                       fprintf(stderr, "Product/Subclass spec without prior Vendor/Class spec at line %u\n", linectr);
+                               if (new_langid(cp, lastlang+(u<<10)))
+                                       fprintf(stderr, "Duplicate LANGID Usage Spec at line %u\n",
+                                               linectr);
+                               continue;
+                       }
+                       fprintf(stderr, "Product/Subclass spec without prior Vendor/Class spec at line %u\n",
+                               linectr);
                        continue;
                }
                if (buf[0] == '\t' && buf[1] == '\t' && isxdigit(buf[2])) {
@@ -693,84 +750,102 @@ static void parse(FILE *f)
                        while (isspace(*cp))
                                cp++;
                        if (!*cp) {
-                               fprintf(stderr, "Invalid protocol spec at line %u\n", linectr);
+                               fprintf(stderr, "Invalid protocol spec at line %u\n",
+                                       linectr);
                                continue;
                        }
                        if (lastclass != -1 && lastsubclass != -1) {
                                if (new_protocol(cp, lastclass, lastsubclass, u))
-                                       fprintf(stderr, "Duplicate protocol spec at line %u class %02x:%02x:%02x %s\n", linectr, lastclass, lastsubclass, u, cp);
-                               DBG(printf("line %5u protocol %02x:%02x:%02x %s\n", linectr, lastclass, lastsubclass, u, cp));
+                                       fprintf(stderr, "Duplicate protocol spec at line %u class %02x:%02x:%02x %s\n",
+                                               linectr, lastclass, lastsubclass, u, cp);
+                               DBG(printf("line %5u protocol %02x:%02x:%02x %s\n",
+                                          linectr, lastclass, lastsubclass, u, cp));
                                continue;
                        }
-                       fprintf(stderr, "Protocol spec without prior Class and Subclass spec at line %u\n", linectr);
+                       fprintf(stderr, "Protocol spec without prior Class and Subclass spec at line %u\n",
+                               linectr);
                        continue;
                }
-               if (buf[0] == 'H' && buf[1] == 'I' && buf[2] == 'D' && /*isspace(buf[3])*/ buf[3] == ' ') {
+               if (buf[0] == 'H' && buf[1] == 'I' && buf[2] == 'D'
+                   && /*isspace(buf[3])*/ buf[3] == ' ') {
                        cp = buf + 4;
-                        while (isspace(*cp))
-                                cp++;
-                        if (!isxdigit(*cp)) {
-                                fprintf(stderr, "Invalid HID type at line %u\n", linectr);
-                                continue;
-                        }
-                        u = strtoul(cp, &cp, 16);
-                        while (isspace(*cp))
-                                cp++;
-                        if (!*cp) {
-                                fprintf(stderr, "Invalid HID type at line %u\n", linectr);
-                                continue;
-                        }
-                        if (new_hid(cp, u))
-                                fprintf(stderr, "Duplicate HID type spec at line %u terminal type %04x %s\n", linectr, u, cp);
-                        DBG(printf("line %5u HID type %02x %s\n", linectr, u, cp));
-                        continue;
+                       while (isspace(*cp))
+                               cp++;
+                       if (!isxdigit(*cp)) {
+                               fprintf(stderr, "Invalid HID type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       u = strtoul(cp, &cp, 16);
+                       while (isspace(*cp))
+                               cp++;
+                       if (!*cp) {
+                               fprintf(stderr, "Invalid HID type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       if (new_hid(cp, u))
+                               fprintf(stderr, "Duplicate HID type spec at line %u terminal type %04x %s\n",
+                                       linectr, u, cp);
+                       DBG(printf("line %5u HID type %02x %s\n", linectr, u,
+                                  cp));
+                       continue;
 
                }
-                if (buf[0] == 'H' && buf[1] == 'U' && buf[2] == 'T' && /*isspace(buf[3])*/ buf[3] == ' ') {
-                        cp = buf + 4;
-                        while (isspace(*cp))
-                                cp++;
-                        if (!isxdigit(*cp)) {
-                                fprintf(stderr, "Invalid HUT type at line %u\n", linectr);
-                                continue;
-                        }
-                        u = strtoul(cp, &cp, 16);
-                        while (isspace(*cp))
-                                cp++;
-                        if (!*cp) {
-                                fprintf(stderr, "Invalid HUT type at line %u\n", linectr);
-                                continue;
-                        }
-                        if (new_huts(cp, u))
-                                fprintf(stderr, "Duplicate HUT type spec at line %u terminal type %04x %s\n", linectr, u, cp);
+               if (buf[0] == 'H' && buf[1] == 'U' && buf[2] == 'T'
+                   && /*isspace(buf[3])*/ buf[3] == ' ') {
+                       cp = buf + 4;
+                       while (isspace(*cp))
+                               cp++;
+                       if (!isxdigit(*cp)) {
+                               fprintf(stderr, "Invalid HUT type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       u = strtoul(cp, &cp, 16);
+                       while (isspace(*cp))
+                               cp++;
+                       if (!*cp) {
+                               fprintf(stderr, "Invalid HUT type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       if (new_huts(cp, u))
+                               fprintf(stderr, "Duplicate HUT type spec at line %u terminal type %04x %s\n",
+                                       linectr, u, cp);
                        lastlang = lastclass = lastvendor = lastsubclass = -1;
                        lasthut = u;
-                        DBG(printf("line %5u HUT type %02x %s\n", linectr, u, cp));
-                        continue;
-
-                }
-                if (buf[0] == 'R' && buf[1] == ' ') {
-                        cp = buf + 2;
-                        while (isspace(*cp))
-                                cp++;
-                        if (!isxdigit(*cp)) {
-                                fprintf(stderr, "Invalid Report type at line %u\n", linectr);
-                                continue;
-                        }
-                        u = strtoul(cp, &cp, 16);
-                        while (isspace(*cp))
-                                cp++;
-                        if (!*cp) {
-                                fprintf(stderr, "Invalid Report type at line %u\n", linectr);
-                                continue;
-                        }
-                        if (new_reporttag(cp, u))
-                                fprintf(stderr, "Duplicate Report type spec at line %u terminal type %04x %s\n", linectr, u, cp);
-                        DBG(printf("line %5u Report type %02x %s\n", linectr, u, cp));
-                        continue;
-
-                }
-                if (buf[0] == 'V' && buf[1] == 'T') {
+                       DBG(printf("line %5u HUT type %02x %s\n", linectr, u,
+                                  cp));
+                       continue;
+
+               }
+               if (buf[0] == 'R' && buf[1] == ' ') {
+                       cp = buf + 2;
+                       while (isspace(*cp))
+                               cp++;
+                       if (!isxdigit(*cp)) {
+                               fprintf(stderr, "Invalid Report type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       u = strtoul(cp, &cp, 16);
+                       while (isspace(*cp))
+                               cp++;
+                       if (!*cp) {
+                               fprintf(stderr, "Invalid Report type at line %u\n",
+                                       linectr);
+                               continue;
+                       }
+                       if (new_reporttag(cp, u))
+                               fprintf(stderr, "Duplicate Report type spec at line %u terminal type %04x %s\n",
+                                       linectr, u, cp);
+                       DBG(printf("line %5u Report type %02x %s\n", linectr,
+                                  u, cp));
+                       continue;
+
+               }
+               if (buf[0] == 'V' && buf[1] == 'T') {
                        /* add here */
                        continue;
                }
@@ -784,9 +859,10 @@ int names_init(char *n)
 {
        FILE *f;
 
-       if (!(f = fopen(n, "r"))) {
+       f = fopen(n, "r");
+       if (!f)
                return errno;
-       }
+
        parse(f);
        fclose(f);
        return 0;
index 3a269fecc02ac88da0b870b123c2ef6fdf21e8bc..28dafc59f5b0752ccb7a11926d3fb6b60ac9d361 100644 (file)
@@ -40,7 +40,8 @@ extern const char *names_vendor(u_int16_t vendorid);
 extern const char *names_product(u_int16_t vendorid, u_int16_t productid);
 extern const char *names_class(u_int8_t classid);
 extern const char *names_subclass(u_int8_t classid, u_int8_t subclassid);
-extern const char *names_protocol(u_int8_t classid, u_int8_t subclassid, u_int8_t protocolid);
+extern const char *names_protocol(u_int8_t classid, u_int8_t subclassid,
+                                 u_int8_t protocolid);
 extern const char *names_audioterminal(u_int16_t termt);
 extern const char *names_hid(u_int8_t hidd);
 extern const char *names_reporttag(u_int8_t rt);
index 154b4b1103ec0f59d14c3f75da57a268ce6586cb..17e08e022c009e1ce49044229c1cf9747b1c74f0 100644 (file)
@@ -8,9 +8,9 @@
 #undef  PROGNAME
 #define PROGNAME "libusbip"
 
-int usbip_use_syslog = 0;
-int usbip_use_stderr = 0;
-int usbip_use_debug  = 0;
+int usbip_use_syslog;
+int usbip_use_stderr;
+int usbip_use_debug;
 
 struct speed_string {
        int num;
@@ -44,7 +44,7 @@ static struct portst_string portst_strings[] = {
 
 const char *usbip_status_string(int32_t status)
 {
-       for (int i=0; portst_strings[i].desc != NULL; i++)
+       for (int i = 0; portst_strings[i].desc != NULL; i++)
                if (portst_strings[i].num == status)
                        return portst_strings[i].desc;
 
@@ -53,7 +53,7 @@ const char *usbip_status_string(int32_t status)
 
 const char *usbip_speed_string(int num)
 {
-       for (int i=0; speed_strings[i].speed != NULL; i++)
+       for (int i = 0; speed_strings[i].speed != NULL; i++)
                if (speed_strings[i].num == num)
                        return speed_strings[i].desc;
 
@@ -109,7 +109,8 @@ void dump_usb_device(struct usbip_usb_device *udev)
 }
 
 
-int read_attr_value(struct sysfs_device *dev, const char *name, const char *format)
+int read_attr_value(struct sysfs_device *dev, const char *name,
+                   const char *format)
 {
        char attrpath[SYSFS_PATH_MAX];
        struct sysfs_attribute *attr;
@@ -172,7 +173,7 @@ int read_attr_speed(struct sysfs_device *dev)
 err:
        sysfs_close_attribute(attr);
 
-       for (int i=0; speed_strings[i].speed != NULL; i++) {
+       for (int i = 0; speed_strings[i].speed != NULL; i++) {
                if (!strcmp(speed, speed_strings[i].speed))
                        return speed_strings[i].num;
        }
@@ -180,8 +181,11 @@ err:
        return USB_SPEED_UNKNOWN;
 }
 
-#define READ_ATTR(object, type, dev, name, format)\
-       do { (object)->name = (type) read_attr_value(dev, to_string(name), format); } while (0)
+#define READ_ATTR(object, type, dev, name, format)                           \
+       do {                                                                  \
+               (object)->name = (type) read_attr_value(dev, to_string(name), \
+                                                       format);              \
+       } while (0)
 
 
 int read_usb_device(struct sysfs_device *sdev, struct usbip_usb_device *udev)
@@ -245,7 +249,8 @@ void usbip_names_free()
        names_free();
 }
 
-void usbip_names_get_product(char *buff, size_t size, uint16_t vendor, uint16_t product)
+void usbip_names_get_product(char *buff, size_t size, uint16_t vendor,
+                            uint16_t product)
 {
        const char *prod, *vend;
 
@@ -261,7 +266,8 @@ void usbip_names_get_product(char *buff, size_t size, uint16_t vendor, uint16_t
        snprintf(buff, size, "%s : %s (%04x:%04x)", vend, prod, vendor, product);
 }
 
-void usbip_names_get_class(char *buff, size_t size, uint8_t class, uint8_t subclass, uint8_t protocol)
+void usbip_names_get_class(char *buff, size_t size, uint8_t class,
+                          uint8_t subclass, uint8_t protocol)
 {
        const char *c, *s, *p;
 
index eedefbd12ea66b25b4f1f209c84edc1bb924371d..938ad1c369471357c393c03873f6388c7c96f161 100644 (file)
@@ -84,7 +84,7 @@ enum usb_device_speed {
 };
 
 /* FIXME: how to sync with drivers/usbip_common.h ? */
-enum usbip_device_status{
+enum usbip_device_status {
        /* sdev is available. */
        SDEV_ST_AVAILABLE = 0x01,
        /* sdev is now used. */
@@ -132,7 +132,8 @@ struct usbip_usb_device {
 void dump_usb_interface(struct usbip_usb_interface *);
 void dump_usb_device(struct usbip_usb_device *);
 int read_usb_device(struct sysfs_device *sdev, struct usbip_usb_device *udev);
-int read_attr_value(struct sysfs_device *dev, const char *name, const char *format);
+int read_attr_value(struct sysfs_device *dev, const char *name,
+                   const char *format);
 int read_usb_interface(struct usbip_usb_device *udev, int i,
                       struct usbip_usb_interface *uinf);
 
@@ -141,7 +142,9 @@ const char *usbip_status_string(int32_t status);
 
 int usbip_names_init(char *);
 void usbip_names_free(void);
-void usbip_names_get_product(char *buff, size_t size, uint16_t vendor, uint16_t product);
-void usbip_names_get_class(char *buff, size_t size, uint8_t class, uint8_t subclass, uint8_t protocol);
+void usbip_names_get_product(char *buff, size_t size, uint16_t vendor,
+                            uint16_t product);
+void usbip_names_get_class(char *buff, size_t size, uint8_t class,
+                          uint8_t subclass, uint8_t protocol);
 
 #endif /* __USBIP_COMMON_H */
index 0958ba53e94ad77e50a840c1785c73c336b5b01d..25e62e9f0a335c9c13893ff369f5796214e2a66a 100644 (file)
@@ -10,7 +10,8 @@
 
 struct usbip_vhci_driver *vhci_driver;
 
-static struct usbip_imported_device *imported_device_init(struct usbip_imported_device *idev, char *busid)
+static struct usbip_imported_device *
+imported_device_init(struct usbip_imported_device *idev, char *busid)
 {
        struct sysfs_device *sudev;
 
@@ -29,14 +30,16 @@ static struct usbip_imported_device *imported_device_init(struct usbip_imported_
                if (!strncmp(cdev->dev_path, idev->udev.path,
                             strlen(idev->udev.path))) {
                        struct usbip_class_device *new_cdev;
-
-                       /* alloc and copy because dlist is linked from only one list */
+                       /*
+                        * alloc and copy because dlist is linked
+                        * from only one list
+                        */
                        new_cdev = calloc(1, sizeof(*new_cdev));
                        if (!new_cdev)
                                goto err;
 
                        memcpy(new_cdev, cdev, sizeof(*new_cdev));
-                       dlist_unshift(idev->cdev_list, (void*) new_cdev);
+                       dlist_unshift(idev->cdev_list, (void *) new_cdev);
                }
        }
 
@@ -101,7 +104,8 @@ static int parse_status(char *value)
                                return -1;
                        }
 
-                       if (idev->status != VDEV_ST_NULL && idev->status != VDEV_ST_NOTASSIGNED) {
+                       if (idev->status != VDEV_ST_NULL
+                           && idev->status != VDEV_ST_NOTASSIGNED) {
                                idev = imported_device_init(idev, lbusid);
                                if (!idev) {
                                        dbg("imported_device_init failed");
@@ -126,8 +130,10 @@ static int parse_status(char *value)
 
 static int check_usbip_device(struct sysfs_class_device *cdev)
 {
-       char class_path[SYSFS_PATH_MAX]; /* /sys/class/video4linux/video0/device */
-       char dev_path[SYSFS_PATH_MAX];   /* /sys/devices/platform/vhci_hcd/usb6/6-1:1.1 */
+       /* /sys/class/video4linux/video0/device */
+       char class_path[SYSFS_PATH_MAX];
+       /* /sys/devices/platform/vhci_hcd/usb6/6-1:1.1 */
+       char dev_path[SYSFS_PATH_MAX];
        int ret;
        struct usbip_class_device *usbip_cdev;
 
@@ -289,25 +295,25 @@ static int get_nports(void)
 
 static int get_hc_busid(char *sysfs_mntpath, char *hc_busid)
 {
-        struct sysfs_driver *sdriver;
-        char sdriver_path[SYSFS_PATH_MAX];
+       struct sysfs_driver *sdriver;
+       char sdriver_path[SYSFS_PATH_MAX];
 
        struct sysfs_device *hc_dev;
        struct dlist *hc_devs;
 
        int found = 0;
 
-        snprintf(sdriver_path, SYSFS_PATH_MAX, "%s/%s/%s/%s/%s", sysfs_mntpath,
-                SYSFS_BUS_NAME, USBIP_VHCI_BUS_TYPE, SYSFS_DRIVERS_NAME,
-                USBIP_VHCI_DRV_NAME);
+       snprintf(sdriver_path, SYSFS_PATH_MAX, "%s/%s/%s/%s/%s", sysfs_mntpath,
+       SYSFS_BUS_NAME, USBIP_VHCI_BUS_TYPE, SYSFS_DRIVERS_NAME,
+       USBIP_VHCI_DRV_NAME);
 
-        sdriver = sysfs_open_driver_path(sdriver_path);
-        if (!sdriver) {
+       sdriver = sysfs_open_driver_path(sdriver_path);
+       if (!sdriver) {
                dbg("sysfs_open_driver_path failed: %s", sdriver_path);
-                dbg("make sure " USBIP_CORE_MOD_NAME ".ko and "
+               dbg("make sure " USBIP_CORE_MOD_NAME ".ko and "
                    USBIP_VHCI_DRV_NAME ".ko are loaded!");
-                return -1;
-        }
+               return -1;
+       }
 
        hc_devs = sysfs_get_driver_devices(sdriver);
        if (!hc_devs) {
index dac5f065755adbfaab00278e4f35403440db3d10..13308df613a260147b43c9aa9a37d52837cc3a42 100644 (file)
@@ -49,7 +49,7 @@ static int detach_port(char *port)
        uint8_t portnum;
        char path[PATH_MAX+1];
 
-       for (unsigned int i=0; i < strlen(port); i++)
+       for (unsigned int i = 0; i < strlen(port); i++)
                if (!isdigit(port[i])) {
                        err("invalid port %s", port);
                        return -1;
index 1a84dd37e125ad884d5b24f5dc9395250a50f603..4cb76e5d71c8e915997e7a8b9483f722da3b155a 100644 (file)
@@ -56,7 +56,7 @@ void usbip_net_pack_usb_device(int pack, struct usbip_usb_device *udev)
 {
        usbip_net_pack_uint32_t(pack, &udev->busnum);
        usbip_net_pack_uint32_t(pack, &udev->devnum);
-       usbip_net_pack_uint32_t(pack, &udev->speed );
+       usbip_net_pack_uint32_t(pack, &udev->speed);
 
        usbip_net_pack_uint16_t(pack, &udev->idVendor);
        usbip_net_pack_uint16_t(pack, &udev->idProduct);
index 2d1e070fb7b8b9bdf72cf2b8cea2310065f63857..1bbefc993fb1f4bd9926990b554510cbc1fa0037 100644 (file)
@@ -35,8 +35,8 @@ struct op_common {
 
 #define PACK_OP_COMMON(pack, op_common)  do {\
        usbip_net_pack_uint16_t(pack, &(op_common)->version);\
-       usbip_net_pack_uint16_t(pack, &(op_common)->code   );\
-       usbip_net_pack_uint32_t(pack, &(op_common)->status );\
+       usbip_net_pack_uint16_t(pack, &(op_common)->code);\
+       usbip_net_pack_uint32_t(pack, &(op_common)->status);\
 } while (0)
 
 /* ---------------------------------------------------------------------- */
index 34760cc1d10e1777f234c3ac6e5102ce4b827163..cc3be17b9e240dce8b50bd2e2615d210f5226d73 100644 (file)
@@ -60,7 +60,7 @@ static const char usbipd_help_string[] =
        "       -d, --debug                             \n"
        "               Print debugging information.    \n"
        "                                               \n"
-       "       -h, --help                              \n"
+       "       -h, --help                              \n"
        "               Print this help.                \n"
        "                                               \n"
        "       -v, --version                           \n"
@@ -446,7 +446,7 @@ static int do_standalone_mode(int daemonize)
        }
 
        if (daemonize) {
-               if (daemon(0,0) < 0) {
+               if (daemon(0, 0) < 0) {
                        err("daemonizing failed: %s", strerror(errno));
                        return -1;
                }
index f1ca08478da8717910df803e59318479e58d1590..d7974cb2cc6f7f499cac46297e41e8f43240f8af 100644 (file)
@@ -956,11 +956,10 @@ static int vhci_bus_resume(struct usb_hcd *hcd)
        dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
 
        spin_lock(&vhci->lock);
-       if (!HCD_HW_ACCESSIBLE(hcd)) {
+       if (!HCD_HW_ACCESSIBLE(hcd))
                rc = -ESHUTDOWN;
-       } else {
+       else
                hcd->state = HC_STATE_RUNNING;
-       }
        spin_unlock(&vhci->lock);
 
        return rc;
index d074b1ecb41a8e21e5c0852b6777fb1dceaf632d..da7f759849792060678671cb3a5f70b17a8c4373 100644 (file)
@@ -710,6 +710,10 @@ static int vme_user_probe(struct vme_dev *vdev)
 
        /* Register the driver as a char device */
        vme_user_cdev = cdev_alloc();
+       if (!vme_user_cdev) {
+               err = -ENOMEM;
+               goto err_char;
+       }
        vme_user_cdev->ops = &vme_user_fops;
        vme_user_cdev->owner = THIS_MODULE;
        err = cdev_add(vme_user_cdev, MKDEV(VME_MAJOR, 0), VME_DEVS);
index c4d2349260ea0de6ab162754727a82ed1061b101..28078a114d4fe1cbcc2e4304164b911259befea0 100644 (file)
@@ -86,7 +86,6 @@
 #define WLAN_DATA_MAXLEN            2312
 #define WLAN_A3FR_MAXLEN            (WLAN_HDR_ADDR3_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
 
-
 #define WLAN_BEACON_FR_MAXLEN       WLAN_A3FR_MAXLEN
 #define WLAN_ATIM_FR_MAXLEN         (WLAN_HDR_ADDR3_LEN + 0)
 #define WLAN_NULLDATA_FR_MAXLEN     (WLAN_HDR_ADDR3_LEN + 0)
 #define WLAN_AUTHEN_FR_MAXLEN       WLAN_A3FR_MAXLEN
 #define WLAN_DEAUTHEN_FR_MAXLEN     (WLAN_HDR_ADDR3_LEN + 2)
 
-
 #define WLAN_WEP_NKEYS              4
 #define WLAN_WEP40_KEYLEN           5
 #define WLAN_WEP104_KEYLEN          13
 #define WLAN_FTYPE_CTL  0x01
 #define WLAN_FTYPE_DATA 0x02
 
-
 /* Frame Subtypes */
 #define WLAN_FSTYPE_ASSOCREQ        0x00
 #define WLAN_FSTYPE_ASSOCRESP       0x01
 #define WLAN_FSTYPE_CFPOLL          0x06
 #define WLAN_FSTYPE_CFACK_CFPOLL    0x07
 
-
 #ifdef __BIG_ENDIAN
 
 /* GET & SET Frame Control bit */
 #define WLAN_GET_SEQ_FRGNUM(n) (((unsigned short)(n) >> 8) & (BIT0|BIT1|BIT2|BIT3))
 #define WLAN_GET_SEQ_SEQNUM(n) ((((unsigned short)(n) >> 8) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
 
-
 /* Capability Field bit */
 #define WLAN_GET_CAP_INFO_ESS(n)           (((n) >> 8) & BIT0)
 #define WLAN_GET_CAP_INFO_IBSS(n)          ((((n) >> 8) & BIT1) >> 1)
 #define WLAN_GET_CAP_INFO_DSSSOFDM(n)      ((((n))      & BIT13) >> 13)
 #define WLAN_GET_CAP_INFO_GRPACK(n)        ((((n))      & BIT14) >> 14)
 
-
 #else
 
 /* GET & SET Frame Control bit */
 #define WLAN_GET_FC_ISWEP(n)    ((((unsigned short)(n)) & (BIT14)) >> 14)
 #define WLAN_GET_FC_ORDER(n)    ((((unsigned short)(n)) & (BIT15)) >> 15)
 
-
 /* Sequence Field bit */
 #define WLAN_GET_SEQ_FRGNUM(n) (((unsigned short)(n)) & (BIT0|BIT1|BIT2|BIT3))
 #define WLAN_GET_SEQ_SEQNUM(n) ((((unsigned short)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
 
-
 /* Capability Field bit */
 #define WLAN_GET_CAP_INFO_ESS(n)           ((n) & BIT0)
 #define WLAN_GET_CAP_INFO_IBSS(n)          (((n) & BIT1) >> 1)
 #define WLAN_GET_CAP_INFO_DSSSOFDM(n)      (((n) & BIT13) >> 13)
 #define WLAN_GET_CAP_INFO_GRPACK(n)        (((n) & BIT14) >> 14)
 
-
 #endif /*#ifdef __BIG_ENDIAN */
 
-
 #define WLAN_SET_CAP_INFO_ESS(n)           (n)
 #define WLAN_SET_CAP_INFO_IBSS(n)          ((n) << 1)
 #define WLAN_SET_CAP_INFO_CFPOLLABLE(n)    ((n) << 2)
 #define WLAN_SET_CAP_INFO_DSSSOFDM(n)      ((n) << 13)
 #define WLAN_SET_CAP_INFO_GRPACK(n)        ((n) << 14)
 
-
 #define WLAN_SET_FC_PRVER(n)    ((unsigned short)(n))
 #define WLAN_SET_FC_FTYPE(n)    (((unsigned short)(n)) << 2)
 #define WLAN_SET_FC_FSTYPE(n)   (((unsigned short)(n)) << 4)
 #define WLAN_SET_ERP_USE_PROTECTION(n)     ((n) << 1)
 #define WLAN_SET_ERP_BARKER_MODE(n)        ((n) << 2)
 
-
-
 /* Support & Basic Rates field */
 #define WLAN_MGMT_IS_BASICRATE(b)    ((b) & BIT7)
 #define WLAN_MGMT_GET_RATE(b)        ((b) & ~BIT7)
 #define IEEE_ADDR_GROUP             0x01
 
 typedef struct {
-    unsigned char abyAddr[6];
+       unsigned char abyAddr[6];
 } IEEE_ADDR, *PIEEE_ADDR;
 
 /* 802.11 Header Format */
 
 typedef struct tagWLAN_80211HDR_A2 {
-
-    unsigned short wFrameCtl;
-    unsigned short wDurationID;
-    unsigned char abyAddr1[WLAN_ADDR_LEN];
-    unsigned char abyAddr2[WLAN_ADDR_LEN];
-
+       unsigned short wFrameCtl;
+       unsigned short wDurationID;
+       unsigned char abyAddr1[WLAN_ADDR_LEN];
+       unsigned char abyAddr2[WLAN_ADDR_LEN];
 } __attribute__ ((__packed__))
 WLAN_80211HDR_A2, *PWLAN_80211HDR_A2;
 
 typedef struct tagWLAN_80211HDR_A3 {
-
-    unsigned short wFrameCtl;
-    unsigned short wDurationID;
-    unsigned char abyAddr1[WLAN_ADDR_LEN];
-    unsigned char abyAddr2[WLAN_ADDR_LEN];
-    unsigned char abyAddr3[WLAN_ADDR_LEN];
-    unsigned short wSeqCtl;
-
-}__attribute__ ((__packed__))
+       unsigned short wFrameCtl;
+       unsigned short wDurationID;
+       unsigned char abyAddr1[WLAN_ADDR_LEN];
+       unsigned char abyAddr2[WLAN_ADDR_LEN];
+       unsigned char abyAddr3[WLAN_ADDR_LEN];
+       unsigned short wSeqCtl;
+} __attribute__ ((__packed__))
 WLAN_80211HDR_A3, *PWLAN_80211HDR_A3;
 
 typedef struct tagWLAN_80211HDR_A4 {
-
-    unsigned short wFrameCtl;
-    unsigned short wDurationID;
-    unsigned char abyAddr1[WLAN_ADDR_LEN];
-    unsigned char abyAddr2[WLAN_ADDR_LEN];
-    unsigned char abyAddr3[WLAN_ADDR_LEN];
-    unsigned short wSeqCtl;
-    unsigned char abyAddr4[WLAN_ADDR_LEN];
-
+       unsigned short wFrameCtl;
+       unsigned short wDurationID;
+       unsigned char abyAddr1[WLAN_ADDR_LEN];
+       unsigned char abyAddr2[WLAN_ADDR_LEN];
+       unsigned char abyAddr3[WLAN_ADDR_LEN];
+       unsigned short wSeqCtl;
+       unsigned char abyAddr4[WLAN_ADDR_LEN];
 } __attribute__ ((__packed__))
 WLAN_80211HDR_A4, *PWLAN_80211HDR_A4;
 
-
 typedef union tagUWLAN_80211HDR {
-
-    WLAN_80211HDR_A2        sA2;
-    WLAN_80211HDR_A3        sA3;
-    WLAN_80211HDR_A4        sA4;
-
+       WLAN_80211HDR_A2        sA2;
+       WLAN_80211HDR_A3        sA3;
+       WLAN_80211HDR_A4        sA4;
 } UWLAN_80211HDR, *PUWLAN_80211HDR;
 
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 
 /*---------------------  Export Functions  --------------------------*/
 
-
-
 #endif /* __80211HDR_H__ */
-
-
index 1ed0f260b1620f657f6c881d8a66ee651b678d22..4cb26f3faf26e5aeb1597d480cc898bd8a0b0303 100644 (file)
 
 /*---------------------  Static Definitions -------------------------*/
 
-
-
 /*---------------------  Static Classes  ----------------------------*/
 
 /*---------------------  Static Variables  --------------------------*/
 
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 /*---------------------  Static Functions  --------------------------*/
 
-
-
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
-
 /*+
  *
  * Routine Description:
@@ -87,26 +81,26 @@ static int          msglevel                =MSG_LEVEL_INFO;
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrEncodeBeacon(
-    PWLAN_FR_BEACON  pFrame
-     )
+       PWLAN_FR_BEACON  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
-    // Fixed Fields
-    pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                    + WLAN_BEACON_OFF_TS);
-    pFrame->pwBeaconInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                       + WLAN_BEACON_OFF_BCN_INT);
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_BEACON_OFF_CAPINFO);
+       // Fixed Fields
+       pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                       + WLAN_BEACON_OFF_TS);
+       pFrame->pwBeaconInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                     + WLAN_BEACON_OFF_BCN_INT);
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_BEACON_OFF_CAPINFO);
 
-    pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_BEACON_OFF_SSID;
+       pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_BEACON_OFF_SSID;
 
-    return;
+       return;
 }
 
 /*+
@@ -118,118 +112,115 @@ vMgrEncodeBeacon(
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 void
 vMgrDecodeBeacon(
-    PWLAN_FR_BEACON  pFrame
-    )
+       PWLAN_FR_BEACON  pFrame
+)
 {
-    PWLAN_IE        pItem;
-
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-
-    // Fixed Fields
-    pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                    + WLAN_BEACON_OFF_TS);
-    pFrame->pwBeaconInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                       + WLAN_BEACON_OFF_BCN_INT);
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_BEACON_OFF_CAPINFO);
-
-    // Information elements
-    pItem = (PWLAN_IE)((unsigned char *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)))
-                       + WLAN_BEACON_OFF_SSID);
-    while( ((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len) ){
-
-        switch (pItem->byElementID) {
-            case WLAN_EID_SSID:
-                if (pFrame->pSSID == NULL)
-                    pFrame->pSSID = (PWLAN_IE_SSID)pItem;
-                break;
-            case WLAN_EID_SUPP_RATES:
-                if (pFrame->pSuppRates == NULL)
-                    pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-                break;
-            case WLAN_EID_FH_PARMS:
-                //pFrame->pFHParms = (PWLAN_IE_FH_PARMS)pItem;
-                break;
-            case WLAN_EID_DS_PARMS:
-                if (pFrame->pDSParms == NULL)
-                    pFrame->pDSParms = (PWLAN_IE_DS_PARMS)pItem;
-                break;
-            case WLAN_EID_CF_PARMS:
-                if (pFrame->pCFParms == NULL)
-                    pFrame->pCFParms = (PWLAN_IE_CF_PARMS)pItem;
-                break;
-            case WLAN_EID_IBSS_PARMS:
-                if (pFrame->pIBSSParms == NULL)
-                    pFrame->pIBSSParms = (PWLAN_IE_IBSS_PARMS)pItem;
-                break;
-            case WLAN_EID_TIM:
-                if (pFrame->pTIM == NULL)
-                    pFrame->pTIM = (PWLAN_IE_TIM)pItem;
-                break;
-
-            case WLAN_EID_RSN:
-                if (pFrame->pRSN == NULL) {
-                    pFrame->pRSN = (PWLAN_IE_RSN)pItem;
-                }
-                break;
-            case WLAN_EID_RSN_WPA:
-                if (pFrame->pRSNWPA == NULL) {
-                    if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
-                        pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
-                }
-                break;
-
-            case WLAN_EID_ERP:
-                if (pFrame->pERP == NULL)
-                    pFrame->pERP = (PWLAN_IE_ERP)pItem;
-                break;
-            case WLAN_EID_EXTSUPP_RATES:
-                if (pFrame->pExtSuppRates == NULL)
-                    pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-                break;
-
-            case WLAN_EID_COUNTRY:      //7
-                if (pFrame->pIE_Country == NULL)
-                    pFrame->pIE_Country = (PWLAN_IE_COUNTRY)pItem;
-                break;
-
-            case WLAN_EID_PWR_CONSTRAINT:   //32
-                if (pFrame->pIE_PowerConstraint == NULL)
-                    pFrame->pIE_PowerConstraint = (PWLAN_IE_PW_CONST)pItem;
-                break;
-
-            case WLAN_EID_CH_SWITCH:    //37
-                if (pFrame->pIE_CHSW == NULL)
-                    pFrame->pIE_CHSW = (PWLAN_IE_CH_SW)pItem;
-                break;
-
-            case WLAN_EID_QUIET:        //40
-                if (pFrame->pIE_Quiet == NULL)
-                    pFrame->pIE_Quiet = (PWLAN_IE_QUIET)pItem;
-                break;
-
-            case WLAN_EID_IBSS_DFS:
-                if (pFrame->pIE_IBSSDFS == NULL)
-                    pFrame->pIE_IBSSDFS = (PWLAN_IE_IBSS_DFS)pItem;
-                break;
-
-            default:
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unrecognized EID=%dd in beacon decode.\n", pItem->byElementID);
-                break;
-
-        }
-        pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
-    }
-
-    return;
+       PWLAN_IE        pItem;
+
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+
+       // Fixed Fields
+       pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                       + WLAN_BEACON_OFF_TS);
+       pFrame->pwBeaconInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                     + WLAN_BEACON_OFF_BCN_INT);
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_BEACON_OFF_CAPINFO);
+
+       // Information elements
+       pItem = (PWLAN_IE)((unsigned char *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)))
+                          + WLAN_BEACON_OFF_SSID);
+       while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
+               switch (pItem->byElementID) {
+               case WLAN_EID_SSID:
+                       if (pFrame->pSSID == NULL)
+                               pFrame->pSSID = (PWLAN_IE_SSID)pItem;
+                       break;
+               case WLAN_EID_SUPP_RATES:
+                       if (pFrame->pSuppRates == NULL)
+                               pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+                       break;
+               case WLAN_EID_FH_PARMS:
+                       //pFrame->pFHParms = (PWLAN_IE_FH_PARMS)pItem;
+                       break;
+               case WLAN_EID_DS_PARMS:
+                       if (pFrame->pDSParms == NULL)
+                               pFrame->pDSParms = (PWLAN_IE_DS_PARMS)pItem;
+                       break;
+               case WLAN_EID_CF_PARMS:
+                       if (pFrame->pCFParms == NULL)
+                               pFrame->pCFParms = (PWLAN_IE_CF_PARMS)pItem;
+                       break;
+               case WLAN_EID_IBSS_PARMS:
+                       if (pFrame->pIBSSParms == NULL)
+                               pFrame->pIBSSParms = (PWLAN_IE_IBSS_PARMS)pItem;
+                       break;
+               case WLAN_EID_TIM:
+                       if (pFrame->pTIM == NULL)
+                               pFrame->pTIM = (PWLAN_IE_TIM)pItem;
+                       break;
+
+               case WLAN_EID_RSN:
+                       if (pFrame->pRSN == NULL) {
+                               pFrame->pRSN = (PWLAN_IE_RSN)pItem;
+                       }
+                       break;
+               case WLAN_EID_RSN_WPA:
+                       if (pFrame->pRSNWPA == NULL) {
+                               if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
+                                       pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
+                       }
+                       break;
+
+               case WLAN_EID_ERP:
+                       if (pFrame->pERP == NULL)
+                               pFrame->pERP = (PWLAN_IE_ERP)pItem;
+                       break;
+               case WLAN_EID_EXTSUPP_RATES:
+                       if (pFrame->pExtSuppRates == NULL)
+                               pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+                       break;
+
+               case WLAN_EID_COUNTRY:      //7
+                       if (pFrame->pIE_Country == NULL)
+                               pFrame->pIE_Country = (PWLAN_IE_COUNTRY)pItem;
+                       break;
+
+               case WLAN_EID_PWR_CONSTRAINT:   //32
+                       if (pFrame->pIE_PowerConstraint == NULL)
+                               pFrame->pIE_PowerConstraint = (PWLAN_IE_PW_CONST)pItem;
+                       break;
+
+               case WLAN_EID_CH_SWITCH:    //37
+                       if (pFrame->pIE_CHSW == NULL)
+                               pFrame->pIE_CHSW = (PWLAN_IE_CH_SW)pItem;
+                       break;
+
+               case WLAN_EID_QUIET:        //40
+                       if (pFrame->pIE_Quiet == NULL)
+                               pFrame->pIE_Quiet = (PWLAN_IE_QUIET)pItem;
+                       break;
+
+               case WLAN_EID_IBSS_DFS:
+                       if (pFrame->pIE_IBSSDFS == NULL)
+                               pFrame->pIE_IBSSDFS = (PWLAN_IE_IBSS_DFS)pItem;
+                       break;
+
+               default:
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unrecognized EID=%dd in beacon decode.\n", pItem->byElementID);
+                       break;
+
+               }
+               pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
+       }
+
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -239,21 +230,19 @@ vMgrDecodeBeacon(
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 void
 vMgrEncodeIBSSATIM(
-    PWLAN_FR_IBSSATIM   pFrame
-    )
+       PWLAN_FR_IBSSATIM   pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-    pFrame->len = WLAN_HDR_ADDR3_LEN;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       pFrame->len = WLAN_HDR_ADDR3_LEN;
 
-    return;
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -263,19 +252,18 @@ vMgrEncodeIBSSATIM(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrDecodeIBSSATIM(
-    PWLAN_FR_IBSSATIM   pFrame
-    )
+       PWLAN_FR_IBSSATIM   pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
-    return;
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -285,25 +273,23 @@ vMgrDecodeIBSSATIM(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrEncodeDisassociation(
-    PWLAN_FR_DISASSOC  pFrame
-    )
+       PWLAN_FR_DISASSOC  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
+       // Fixed Fields
+       pFrame->pwReason = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                             + WLAN_DISASSOC_OFF_REASON);
+       pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DISASSOC_OFF_REASON + sizeof(*(pFrame->pwReason));
 
-    // Fixed Fields
-    pFrame->pwReason = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                               + WLAN_DISASSOC_OFF_REASON);
-    pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DISASSOC_OFF_REASON + sizeof(*(pFrame->pwReason));
-
-    return;
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -313,20 +299,20 @@ vMgrEncodeDisassociation(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrDecodeDisassociation(
-    PWLAN_FR_DISASSOC  pFrame
-    )
+       PWLAN_FR_DISASSOC  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
-    // Fixed Fields
-    pFrame->pwReason = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                               + WLAN_DISASSOC_OFF_REASON);
+       // Fixed Fields
+       pFrame->pwReason = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                             + WLAN_DISASSOC_OFF_REASON);
 
-    return;
+       return;
 }
 
 /*+
@@ -338,25 +324,23 @@ vMgrDecodeDisassociation(
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 void
 vMgrEncodeAssocRequest(
-    PWLAN_FR_ASSOCREQ  pFrame
-    )
+       PWLAN_FR_ASSOCREQ  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-    // Fixed Fields
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_ASSOCREQ_OFF_CAP_INFO);
-    pFrame->pwListenInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                       + WLAN_ASSOCREQ_OFF_LISTEN_INT);
-    pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCREQ_OFF_LISTEN_INT + sizeof(*(pFrame->pwListenInterval));
-    return;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       // Fixed Fields
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_ASSOCREQ_OFF_CAP_INFO);
+       pFrame->pwListenInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                     + WLAN_ASSOCREQ_OFF_LISTEN_INT);
+       pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCREQ_OFF_LISTEN_INT + sizeof(*(pFrame->pwListenInterval));
+       return;
 }
 
-
 /*+
  *
  * Routine Description: (AP)
@@ -366,61 +350,61 @@ vMgrEncodeAssocRequest(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrDecodeAssocRequest(
-    PWLAN_FR_ASSOCREQ  pFrame
-    )
+       PWLAN_FR_ASSOCREQ  pFrame
+)
 {
-    PWLAN_IE   pItem;
-
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-    // Fixed Fields
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_ASSOCREQ_OFF_CAP_INFO);
-    pFrame->pwListenInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_ASSOCREQ_OFF_LISTEN_INT);
-
-    // Information elements
-    pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                            + WLAN_ASSOCREQ_OFF_SSID);
-
-    while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
-        switch (pItem->byElementID){
-            case WLAN_EID_SSID:
-                if (pFrame->pSSID == NULL)
-                    pFrame->pSSID = (PWLAN_IE_SSID)pItem;
-                break;
-            case WLAN_EID_SUPP_RATES:
-                if (pFrame->pSuppRates == NULL)
-                    pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-                break;
-
-            case WLAN_EID_RSN:
-                if (pFrame->pRSN == NULL) {
-                    pFrame->pRSN = (PWLAN_IE_RSN)pItem;
-                }
-                break;
-            case WLAN_EID_RSN_WPA:
-                if (pFrame->pRSNWPA == NULL) {
-                    if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
-                        pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
-                }
-                break;
-            case WLAN_EID_EXTSUPP_RATES:
-                if (pFrame->pExtSuppRates == NULL)
-                    pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-                break;
-
-            default:
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unrecognized EID=%dd in assocreq decode.\n",
-                        pItem->byElementID);
-                break;
-        }
-        pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
-    }
-    return;
+       PWLAN_IE   pItem;
+
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       // Fixed Fields
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_ASSOCREQ_OFF_CAP_INFO);
+       pFrame->pwListenInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                     + WLAN_ASSOCREQ_OFF_LISTEN_INT);
+
+       // Information elements
+       pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                          + WLAN_ASSOCREQ_OFF_SSID);
+
+       while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
+               switch (pItem->byElementID) {
+               case WLAN_EID_SSID:
+                       if (pFrame->pSSID == NULL)
+                               pFrame->pSSID = (PWLAN_IE_SSID)pItem;
+                       break;
+               case WLAN_EID_SUPP_RATES:
+                       if (pFrame->pSuppRates == NULL)
+                               pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+                       break;
+
+               case WLAN_EID_RSN:
+                       if (pFrame->pRSN == NULL) {
+                               pFrame->pRSN = (PWLAN_IE_RSN)pItem;
+                       }
+                       break;
+               case WLAN_EID_RSN_WPA:
+                       if (pFrame->pRSNWPA == NULL) {
+                               if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
+                                       pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
+                       }
+                       break;
+               case WLAN_EID_EXTSUPP_RATES:
+                       if (pFrame->pExtSuppRates == NULL)
+                               pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+                       break;
+
+               default:
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unrecognized EID=%dd in assocreq decode.\n",
+                               pItem->byElementID);
+                       break;
+               }
+               pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
+       }
+       return;
 }
 
 /*+
@@ -432,29 +416,28 @@ vMgrDecodeAssocRequest(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrEncodeAssocResponse(
-    PWLAN_FR_ASSOCRESP  pFrame
-     )
+       PWLAN_FR_ASSOCRESP  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-
-    // Fixed Fields
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_ASSOCRESP_OFF_CAP_INFO);
-    pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                               + WLAN_ASSOCRESP_OFF_STATUS);
-    pFrame->pwAid = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                            + WLAN_ASSOCRESP_OFF_AID);
-    pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCRESP_OFF_AID
-                  + sizeof(*(pFrame->pwAid));
-
-    return;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+
+       // Fixed Fields
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_ASSOCRESP_OFF_CAP_INFO);
+       pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                             + WLAN_ASSOCRESP_OFF_STATUS);
+       pFrame->pwAid = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                          + WLAN_ASSOCRESP_OFF_AID);
+       pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCRESP_OFF_AID
+               + sizeof(*(pFrame->pwAid));
+
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -464,44 +447,42 @@ vMgrEncodeAssocResponse(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrDecodeAssocResponse(
-    PWLAN_FR_ASSOCRESP  pFrame
-     )
+       PWLAN_FR_ASSOCRESP  pFrame
+)
 {
-    PWLAN_IE   pItem;
-
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-
-    // Fixed Fields
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_ASSOCRESP_OFF_CAP_INFO);
-    pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                               + WLAN_ASSOCRESP_OFF_STATUS);
-    pFrame->pwAid = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                            + WLAN_ASSOCRESP_OFF_AID);
-
-    // Information elements
-    pFrame->pSuppRates  = (PWLAN_IE_SUPP_RATES)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                           + WLAN_ASSOCRESP_OFF_SUPP_RATES);
-
-    pItem = (PWLAN_IE)(pFrame->pSuppRates);
-    pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
-
-    if ((((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) &&
-                   (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
-        pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pFrame->pExtSuppRates=[%p].\n", pItem);
-    }
-    else {
-        pFrame->pExtSuppRates = NULL;
-    }
-    return;
+       PWLAN_IE   pItem;
+
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+
+       // Fixed Fields
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_ASSOCRESP_OFF_CAP_INFO);
+       pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                             + WLAN_ASSOCRESP_OFF_STATUS);
+       pFrame->pwAid = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                          + WLAN_ASSOCRESP_OFF_AID);
+
+       // Information elements
+       pFrame->pSuppRates  = (PWLAN_IE_SUPP_RATES)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                   + WLAN_ASSOCRESP_OFF_SUPP_RATES);
+
+       pItem = (PWLAN_IE)(pFrame->pSuppRates);
+       pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
+
+       if ((((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) &&
+           (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
+               pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pFrame->pExtSuppRates=[%p].\n", pItem);
+       } else {
+               pFrame->pExtSuppRates = NULL;
+       }
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -511,28 +492,27 @@ vMgrDecodeAssocResponse(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrEncodeReassocRequest(
-    PWLAN_FR_REASSOCREQ  pFrame
-     )
+       PWLAN_FR_REASSOCREQ  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-
-    // Fixed Fields
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_REASSOCREQ_OFF_CAP_INFO);
-    pFrame->pwListenInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                      + WLAN_REASSOCREQ_OFF_LISTEN_INT);
-    pFrame->pAddrCurrAP = (PIEEE_ADDR)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                       + WLAN_REASSOCREQ_OFF_CURR_AP);
-    pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCREQ_OFF_CURR_AP + sizeof(*(pFrame->pAddrCurrAP));
-
-    return;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+
+       // Fixed Fields
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_REASSOCREQ_OFF_CAP_INFO);
+       pFrame->pwListenInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                     + WLAN_REASSOCREQ_OFF_LISTEN_INT);
+       pFrame->pAddrCurrAP = (PIEEE_ADDR)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                          + WLAN_REASSOCREQ_OFF_CURR_AP);
+       pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCREQ_OFF_CURR_AP + sizeof(*(pFrame->pAddrCurrAP));
+
+       return;
 }
 
-
 /*+
  *
  * Routine Description: (AP)
@@ -542,69 +522,65 @@ vMgrEncodeReassocRequest(
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 void
 vMgrDecodeReassocRequest(
-    PWLAN_FR_REASSOCREQ  pFrame
-     )
+       PWLAN_FR_REASSOCREQ  pFrame
+)
 {
-    PWLAN_IE   pItem;
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-
-    // Fixed Fields
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_REASSOCREQ_OFF_CAP_INFO);
-    pFrame->pwListenInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                      + WLAN_REASSOCREQ_OFF_LISTEN_INT);
-    pFrame->pAddrCurrAP = (PIEEE_ADDR)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                       + WLAN_REASSOCREQ_OFF_CURR_AP);
-
-    // Information elements
-    pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                       + WLAN_REASSOCREQ_OFF_SSID);
-
-    while(((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
-
-        switch (pItem->byElementID){
-            case WLAN_EID_SSID:
-                if (pFrame->pSSID == NULL)
-                    pFrame->pSSID = (PWLAN_IE_SSID)pItem;
-                break;
-            case WLAN_EID_SUPP_RATES:
-                if (pFrame->pSuppRates == NULL)
-                    pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-                break;
-
-            case WLAN_EID_RSN:
-                if (pFrame->pRSN == NULL) {
-                    pFrame->pRSN = (PWLAN_IE_RSN)pItem;
-                }
-                break;
-            case WLAN_EID_RSN_WPA:
-                if (pFrame->pRSNWPA == NULL) {
-                    if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
-                        pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
-                }
-                break;
-
-            case WLAN_EID_EXTSUPP_RATES:
-                if (pFrame->pExtSuppRates == NULL)
-                    pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-                break;
-            default:
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unrecognized EID=%dd in reassocreq decode.\n",
-                            pItem->byElementID);
-                break;
-        }
-        pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
-    }
-    return;
+       PWLAN_IE   pItem;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+
+       // Fixed Fields
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_REASSOCREQ_OFF_CAP_INFO);
+       pFrame->pwListenInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                     + WLAN_REASSOCREQ_OFF_LISTEN_INT);
+       pFrame->pAddrCurrAP = (PIEEE_ADDR)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                          + WLAN_REASSOCREQ_OFF_CURR_AP);
+
+       // Information elements
+       pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                          + WLAN_REASSOCREQ_OFF_SSID);
+
+       while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
+               switch (pItem->byElementID) {
+               case WLAN_EID_SSID:
+                       if (pFrame->pSSID == NULL)
+                               pFrame->pSSID = (PWLAN_IE_SSID)pItem;
+                       break;
+               case WLAN_EID_SUPP_RATES:
+                       if (pFrame->pSuppRates == NULL)
+                               pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+                       break;
+
+               case WLAN_EID_RSN:
+                       if (pFrame->pRSN == NULL) {
+                               pFrame->pRSN = (PWLAN_IE_RSN)pItem;
+                       }
+                       break;
+               case WLAN_EID_RSN_WPA:
+                       if (pFrame->pRSNWPA == NULL) {
+                               if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
+                                       pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
+                       }
+                       break;
+
+               case WLAN_EID_EXTSUPP_RATES:
+                       if (pFrame->pExtSuppRates == NULL)
+                               pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+                       break;
+               default:
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unrecognized EID=%dd in reassocreq decode.\n",
+                               pItem->byElementID);
+                       break;
+               }
+               pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
+       }
+       return;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -614,17 +590,16 @@ vMgrDecodeReassocRequest(
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 void
 vMgrEncodeProbeRequest(
-    PWLAN_FR_PROBEREQ  pFrame
-     )
+       PWLAN_FR_PROBEREQ  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-    pFrame->len = WLAN_HDR_ADDR3_LEN;
-    return;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       pFrame->len = WLAN_HDR_ADDR3_LEN;
+       return;
 }
 
 /*+
@@ -636,49 +611,47 @@ vMgrEncodeProbeRequest(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrDecodeProbeRequest(
-    PWLAN_FR_PROBEREQ  pFrame
-     )
+       PWLAN_FR_PROBEREQ  pFrame
+)
 {
-    PWLAN_IE   pItem;
-
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-
-    // Information elements
-    pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)));
-
-    while( ((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len) ) {
-
-        switch (pItem->byElementID) {
-            case WLAN_EID_SSID:
-                if (pFrame->pSSID == NULL)
-                    pFrame->pSSID = (PWLAN_IE_SSID)pItem;
-                break;
-
-            case WLAN_EID_SUPP_RATES:
-                if (pFrame->pSuppRates == NULL)
-                    pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-                break;
-
-            case WLAN_EID_EXTSUPP_RATES:
-                if (pFrame->pExtSuppRates == NULL)
-                    pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-                break;
-
-            default:
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Bad EID=%dd in probereq\n", pItem->byElementID);
-                break;
-        }
-
-        pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 +  pItem->len);
-    }
-    return;
+       PWLAN_IE   pItem;
+
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+
+       // Information elements
+       pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)));
+
+       while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
+               switch (pItem->byElementID) {
+               case WLAN_EID_SSID:
+                       if (pFrame->pSSID == NULL)
+                               pFrame->pSSID = (PWLAN_IE_SSID)pItem;
+                       break;
+
+               case WLAN_EID_SUPP_RATES:
+                       if (pFrame->pSuppRates == NULL)
+                               pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+                       break;
+
+               case WLAN_EID_EXTSUPP_RATES:
+                       if (pFrame->pExtSuppRates == NULL)
+                               pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+                       break;
+
+               default:
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Bad EID=%dd in probereq\n", pItem->byElementID);
+                       break;
+               }
+
+               pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 +  pItem->len);
+       }
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -688,32 +661,29 @@ vMgrDecodeProbeRequest(
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 void
 vMgrEncodeProbeResponse(
-    PWLAN_FR_PROBERESP  pFrame
-    )
+       PWLAN_FR_PROBERESP  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
-    // Fixed Fields
-    pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                    + WLAN_PROBERESP_OFF_TS);
-    pFrame->pwBeaconInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                       + WLAN_PROBERESP_OFF_BCN_INT);
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_PROBERESP_OFF_CAP_INFO);
+       // Fixed Fields
+       pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                       + WLAN_PROBERESP_OFF_TS);
+       pFrame->pwBeaconInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                     + WLAN_PROBERESP_OFF_BCN_INT);
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_PROBERESP_OFF_CAP_INFO);
 
-    pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_PROBERESP_OFF_CAP_INFO +
-                  sizeof(*(pFrame->pwCapInfo));
+       pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_PROBERESP_OFF_CAP_INFO +
+               sizeof(*(pFrame->pwCapInfo));
 
-    return;
+       return;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -723,111 +693,109 @@ vMgrEncodeProbeResponse(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrDecodeProbeResponse(
-    PWLAN_FR_PROBERESP  pFrame
-    )
+       PWLAN_FR_PROBERESP  pFrame
+)
 {
-    PWLAN_IE    pItem;
-
-
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-
-    // Fixed Fields
-    pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                    + WLAN_PROBERESP_OFF_TS);
-    pFrame->pwBeaconInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                       + WLAN_PROBERESP_OFF_BCN_INT);
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_PROBERESP_OFF_CAP_INFO);
-
-    // Information elements
-    pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                       + WLAN_PROBERESP_OFF_SSID);
-
-    while( ((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len) ) {
-        switch (pItem->byElementID) {
-            case WLAN_EID_SSID:
-                if (pFrame->pSSID == NULL)
-                pFrame->pSSID = (PWLAN_IE_SSID)pItem;
-                break;
-            case WLAN_EID_SUPP_RATES:
-                if (pFrame->pSuppRates == NULL)
-                pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-                break;
-            case WLAN_EID_FH_PARMS:
-                break;
-            case WLAN_EID_DS_PARMS:
-                if (pFrame->pDSParms == NULL)
-                    pFrame->pDSParms = (PWLAN_IE_DS_PARMS)pItem;
-                break;
-            case WLAN_EID_CF_PARMS:
-                if (pFrame->pCFParms == NULL)
-                    pFrame->pCFParms = (PWLAN_IE_CF_PARMS)pItem;
-                break;
-            case WLAN_EID_IBSS_PARMS:
-                if (pFrame->pIBSSParms == NULL)
-                    pFrame->pIBSSParms = (PWLAN_IE_IBSS_PARMS)pItem;
-                break;
-
-            case WLAN_EID_RSN:
-                if (pFrame->pRSN == NULL) {
-                    pFrame->pRSN = (PWLAN_IE_RSN)pItem;
-                }
-                break;
-            case WLAN_EID_RSN_WPA:
-                if (pFrame->pRSNWPA == NULL) {
-                    if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
-                        pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
-                }
-                break;
-            case WLAN_EID_ERP:
-                if (pFrame->pERP == NULL)
-                    pFrame->pERP = (PWLAN_IE_ERP)pItem;
-                break;
-            case WLAN_EID_EXTSUPP_RATES:
-                if (pFrame->pExtSuppRates == NULL)
-                    pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-                break;
-
-            case WLAN_EID_COUNTRY:      //7
-                if (pFrame->pIE_Country == NULL)
-                    pFrame->pIE_Country = (PWLAN_IE_COUNTRY)pItem;
-                break;
-
-            case WLAN_EID_PWR_CONSTRAINT:   //32
-                if (pFrame->pIE_PowerConstraint == NULL)
-                    pFrame->pIE_PowerConstraint = (PWLAN_IE_PW_CONST)pItem;
-                break;
-
-            case WLAN_EID_CH_SWITCH:    //37
-                if (pFrame->pIE_CHSW == NULL)
-                    pFrame->pIE_CHSW = (PWLAN_IE_CH_SW)pItem;
-                break;
-
-            case WLAN_EID_QUIET:        //40
-                if (pFrame->pIE_Quiet == NULL)
-                    pFrame->pIE_Quiet = (PWLAN_IE_QUIET)pItem;
-                break;
-
-            case WLAN_EID_IBSS_DFS:
-                if (pFrame->pIE_IBSSDFS == NULL)
-                    pFrame->pIE_IBSSDFS = (PWLAN_IE_IBSS_DFS)pItem;
-                break;
-
-            default:
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Bad EID=%dd in proberesp\n", pItem->byElementID);
-                break;
-        }
-
-        pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 +  pItem->len);
-    }
-    return;
+       PWLAN_IE    pItem;
+
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+
+       // Fixed Fields
+       pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                       + WLAN_PROBERESP_OFF_TS);
+       pFrame->pwBeaconInterval = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                     + WLAN_PROBERESP_OFF_BCN_INT);
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_PROBERESP_OFF_CAP_INFO);
+
+       // Information elements
+       pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                          + WLAN_PROBERESP_OFF_SSID);
+
+       while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
+               switch (pItem->byElementID) {
+               case WLAN_EID_SSID:
+                       if (pFrame->pSSID == NULL)
+                               pFrame->pSSID = (PWLAN_IE_SSID)pItem;
+                       break;
+               case WLAN_EID_SUPP_RATES:
+                       if (pFrame->pSuppRates == NULL)
+                               pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+                       break;
+               case WLAN_EID_FH_PARMS:
+                       break;
+               case WLAN_EID_DS_PARMS:
+                       if (pFrame->pDSParms == NULL)
+                               pFrame->pDSParms = (PWLAN_IE_DS_PARMS)pItem;
+                       break;
+               case WLAN_EID_CF_PARMS:
+                       if (pFrame->pCFParms == NULL)
+                               pFrame->pCFParms = (PWLAN_IE_CF_PARMS)pItem;
+                       break;
+               case WLAN_EID_IBSS_PARMS:
+                       if (pFrame->pIBSSParms == NULL)
+                               pFrame->pIBSSParms = (PWLAN_IE_IBSS_PARMS)pItem;
+                       break;
+
+               case WLAN_EID_RSN:
+                       if (pFrame->pRSN == NULL) {
+                               pFrame->pRSN = (PWLAN_IE_RSN)pItem;
+                       }
+                       break;
+               case WLAN_EID_RSN_WPA:
+                       if (pFrame->pRSNWPA == NULL) {
+                               if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
+                                       pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
+                       }
+                       break;
+               case WLAN_EID_ERP:
+                       if (pFrame->pERP == NULL)
+                               pFrame->pERP = (PWLAN_IE_ERP)pItem;
+                       break;
+               case WLAN_EID_EXTSUPP_RATES:
+                       if (pFrame->pExtSuppRates == NULL)
+                               pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+                       break;
+
+               case WLAN_EID_COUNTRY:      //7
+                       if (pFrame->pIE_Country == NULL)
+                               pFrame->pIE_Country = (PWLAN_IE_COUNTRY)pItem;
+                       break;
+
+               case WLAN_EID_PWR_CONSTRAINT:   //32
+                       if (pFrame->pIE_PowerConstraint == NULL)
+                               pFrame->pIE_PowerConstraint = (PWLAN_IE_PW_CONST)pItem;
+                       break;
+
+               case WLAN_EID_CH_SWITCH:    //37
+                       if (pFrame->pIE_CHSW == NULL)
+                               pFrame->pIE_CHSW = (PWLAN_IE_CH_SW)pItem;
+                       break;
+
+               case WLAN_EID_QUIET:        //40
+                       if (pFrame->pIE_Quiet == NULL)
+                               pFrame->pIE_Quiet = (PWLAN_IE_QUIET)pItem;
+                       break;
+
+               case WLAN_EID_IBSS_DFS:
+                       if (pFrame->pIE_IBSSDFS == NULL)
+                               pFrame->pIE_IBSSDFS = (PWLAN_IE_IBSS_DFS)pItem;
+                       break;
+
+               default:
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Bad EID=%dd in proberesp\n", pItem->byElementID);
+                       break;
+               }
+
+               pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 +  pItem->len);
+       }
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -837,28 +805,27 @@ vMgrDecodeProbeResponse(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrEncodeAuthen(
-    PWLAN_FR_AUTHEN  pFrame
-    )
+       PWLAN_FR_AUTHEN  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-
-    // Fixed Fields
-    pFrame->pwAuthAlgorithm = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                      + WLAN_AUTHEN_OFF_AUTH_ALG);
-    pFrame->pwAuthSequence = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                     + WLAN_AUTHEN_OFF_AUTH_SEQ);
-    pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                               + WLAN_AUTHEN_OFF_STATUS);
-    pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_AUTHEN_OFF_STATUS + sizeof(*(pFrame->pwStatus));
-
-    return;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+
+       // Fixed Fields
+       pFrame->pwAuthAlgorithm = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                    + WLAN_AUTHEN_OFF_AUTH_ALG);
+       pFrame->pwAuthSequence = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                   + WLAN_AUTHEN_OFF_AUTH_SEQ);
+       pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                             + WLAN_AUTHEN_OFF_STATUS);
+       pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_AUTHEN_OFF_STATUS + sizeof(*(pFrame->pwStatus));
+
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -868,37 +835,36 @@ vMgrEncodeAuthen(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrDecodeAuthen(
-    PWLAN_FR_AUTHEN  pFrame
-    )
+       PWLAN_FR_AUTHEN  pFrame
+)
 {
-    PWLAN_IE    pItem;
+       PWLAN_IE    pItem;
 
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
-    // Fixed Fields
-    pFrame->pwAuthAlgorithm = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                      + WLAN_AUTHEN_OFF_AUTH_ALG);
-    pFrame->pwAuthSequence = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                     + WLAN_AUTHEN_OFF_AUTH_SEQ);
-    pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                               + WLAN_AUTHEN_OFF_STATUS);
+       // Fixed Fields
+       pFrame->pwAuthAlgorithm = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                    + WLAN_AUTHEN_OFF_AUTH_ALG);
+       pFrame->pwAuthSequence = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                   + WLAN_AUTHEN_OFF_AUTH_SEQ);
+       pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                             + WLAN_AUTHEN_OFF_STATUS);
 
-    // Information elements
-    pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                       + WLAN_AUTHEN_OFF_CHALLENGE);
+       // Information elements
+       pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                          + WLAN_AUTHEN_OFF_CHALLENGE);
 
-    if ((((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) && (pItem->byElementID == WLAN_EID_CHALLENGE)) {
-        pFrame->pChallenge = (PWLAN_IE_CHALLENGE)pItem;
-    }
+       if ((((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) && (pItem->byElementID == WLAN_EID_CHALLENGE)) {
+               pFrame->pChallenge = (PWLAN_IE_CHALLENGE)pItem;
+       }
 
-    return;
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -908,24 +874,23 @@ vMgrDecodeAuthen(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrEncodeDeauthen(
-    PWLAN_FR_DEAUTHEN  pFrame
-    )
+       PWLAN_FR_DEAUTHEN  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
-    // Fixed Fields
-    pFrame->pwReason = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                               + WLAN_DEAUTHEN_OFF_REASON);
-    pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DEAUTHEN_OFF_REASON + sizeof(*(pFrame->pwReason));
+       // Fixed Fields
+       pFrame->pwReason = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                             + WLAN_DEAUTHEN_OFF_REASON);
+       pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DEAUTHEN_OFF_REASON + sizeof(*(pFrame->pwReason));
 
-    return;
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -935,23 +900,22 @@ vMgrEncodeDeauthen(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrDecodeDeauthen(
-    PWLAN_FR_DEAUTHEN  pFrame
-    )
+       PWLAN_FR_DEAUTHEN  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
-    // Fixed Fields
-    pFrame->pwReason = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                               + WLAN_DEAUTHEN_OFF_REASON);
+       // Fixed Fields
+       pFrame->pwReason = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                             + WLAN_DEAUTHEN_OFF_REASON);
 
-    return;
+       return;
 }
 
-
 /*+
  *
  * Routine Description: (AP)
@@ -961,29 +925,28 @@ vMgrDecodeDeauthen(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrEncodeReassocResponse(
-    PWLAN_FR_REASSOCRESP  pFrame
-     )
+       PWLAN_FR_REASSOCRESP  pFrame
+)
 {
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
-    // Fixed Fields
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_REASSOCRESP_OFF_CAP_INFO);
-    pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                               + WLAN_REASSOCRESP_OFF_STATUS);
-    pFrame->pwAid = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                            + WLAN_REASSOCRESP_OFF_AID);
+       // Fixed Fields
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_REASSOCRESP_OFF_CAP_INFO);
+       pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                             + WLAN_REASSOCRESP_OFF_STATUS);
+       pFrame->pwAid = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                          + WLAN_REASSOCRESP_OFF_AID);
 
-    pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCRESP_OFF_AID + sizeof(*(pFrame->pwAid));
+       pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCRESP_OFF_AID + sizeof(*(pFrame->pwAid));
 
-    return;
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -993,36 +956,35 @@ vMgrEncodeReassocResponse(
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 void
 vMgrDecodeReassocResponse(
-    PWLAN_FR_REASSOCRESP  pFrame
-     )
+       PWLAN_FR_REASSOCRESP  pFrame
+)
 {
-    PWLAN_IE   pItem;
-
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-
-    // Fixed Fields
-    pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_REASSOCRESP_OFF_CAP_INFO);
-    pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                               + WLAN_REASSOCRESP_OFF_STATUS);
-    pFrame->pwAid = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                            + WLAN_REASSOCRESP_OFF_AID);
-
-    //Information elements
-    pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                               + WLAN_REASSOCRESP_OFF_SUPP_RATES);
-
-    pItem = (PWLAN_IE)(pFrame->pSuppRates);
-    pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
-
-    if ((((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) &&
-                   (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
-        pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-    }
-    return;
+       PWLAN_IE   pItem;
+
+       pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
+
+       // Fixed Fields
+       pFrame->pwCapInfo = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                              + WLAN_REASSOCRESP_OFF_CAP_INFO);
+       pFrame->pwStatus = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                             + WLAN_REASSOCRESP_OFF_STATUS);
+       pFrame->pwAid = (unsigned short *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                          + WLAN_REASSOCRESP_OFF_AID);
+
+       //Information elements
+       pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+                                                  + WLAN_REASSOCRESP_OFF_SUPP_RATES);
+
+       pItem = (PWLAN_IE)(pFrame->pSuppRates);
+       pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
+
+       if ((((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) &&
+           (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
+               pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
+       }
+       return;
 }
index 65780f28db416c377ee5fb0f2be9ac44daa34903..16402cf5d25efdc6b54ed3fc969844c63fd738be 100644 (file)
@@ -65,7 +65,6 @@
 // reference WiFi WPA spec.
 #define WLAN_EID_RSN_WPA        221
 
-
 #define WLAN_EID_ERP_NONERP_PRESENT             0x01
 #define WLAN_EID_ERP_USE_PROTECTION             0x02
 #define WLAN_EID_ERP_BARKER_MODE                0x04
 #define WLAN_MGMT_STATUS_INVALID_RSN_IE_CAP             45
 #define WLAN_MGMT_STATUS_CIPHER_REJECT                  46
 
-
-
 // Auth Algorithm
 #define WLAN_AUTH_ALG_OPENSYSTEM                0
 #define WLAN_AUTH_ALG_SHAREDKEY                 1
 
-
-
 // Management Frame Field Offsets
 // Note: Not all fields are listed because of variable lengths.
 // Note: These offsets are from the start of the frame data
 
 #define WLAN_DEAUTHEN_OFF_REASON            0
 
-
 //
 // Cipher Suite Selectors defined in 802.11i
 //
 #define MEASURE_MODE_INCAPABLE  0x02
 #define MEASURE_MODE_REFUSED    0x04
 
-
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 
 /*---------------------  Export Types  ------------------------------*/
 
-
 // Information Element Types
 
 #pragma pack(1)
 typedef struct tagWLAN_IE {
-    unsigned char byElementID;
-    unsigned char len;
-}__attribute__ ((__packed__))
+       unsigned char byElementID;
+       unsigned char len;
+} __attribute__ ((__packed__))
 WLAN_IE, *PWLAN_IE;
 
-
 // Service Set Identity (SSID)
 #pragma pack(1)
 typedef struct tagWLAN_IE_SSID {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char abySSID[1];
-}__attribute__ ((__packed__))
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char abySSID[1];
+} __attribute__ ((__packed__))
 WLAN_IE_SSID, *PWLAN_IE_SSID;
 
-
 // Supported Rates
 #pragma pack(1)
 typedef struct tagWLAN_IE_SUPP_RATES {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char abyRates[1];
-}__attribute__ ((__packed__))
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char abyRates[1];
+} __attribute__ ((__packed__))
 WLAN_IE_SUPP_RATES,  *PWLAN_IE_SUPP_RATES;
 
-
-
 // FH Parameter Set
 #pragma pack(1)
 typedef struct _WLAN_IE_FH_PARMS {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned short wDwellTime;
-    unsigned char byHopSet;
-    unsigned char byHopPattern;
-    unsigned char byHopIndex;
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned short wDwellTime;
+       unsigned char byHopSet;
+       unsigned char byHopPattern;
+       unsigned char byHopIndex;
 } WLAN_IE_FH_PARMS,  *PWLAN_IE_FH_PARMS;
 
 // DS Parameter Set
 #pragma pack(1)
 typedef struct tagWLAN_IE_DS_PARMS {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char byCurrChannel;
-}__attribute__ ((__packed__))
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char byCurrChannel;
+} __attribute__ ((__packed__))
 WLAN_IE_DS_PARMS,  *PWLAN_IE_DS_PARMS;
 
-
 // CF Parameter Set
 #pragma pack(1)
 typedef struct tagWLAN_IE_CF_PARMS {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char byCFPCount;
-    unsigned char byCFPPeriod;
-    unsigned short wCFPMaxDuration;
-    unsigned short wCFPDurRemaining;
-}__attribute__ ((__packed__))
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char byCFPCount;
+       unsigned char byCFPPeriod;
+       unsigned short wCFPMaxDuration;
+       unsigned short wCFPDurRemaining;
+} __attribute__ ((__packed__))
 WLAN_IE_CF_PARMS,  *PWLAN_IE_CF_PARMS;
 
-
 // TIM
 #pragma pack(1)
 typedef struct tagWLAN_IE_TIM {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char byDTIMCount;
-    unsigned char byDTIMPeriod;
-    unsigned char byBitMapCtl;
-    unsigned char byVirtBitMap[1];
-}__attribute__ ((__packed__))
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char byDTIMCount;
+       unsigned char byDTIMPeriod;
+       unsigned char byBitMapCtl;
+       unsigned char byVirtBitMap[1];
+} __attribute__ ((__packed__))
 WLAN_IE_TIM,  *PWLAN_IE_TIM;
 
-
 // IBSS Parameter Set
 #pragma pack(1)
 typedef struct tagWLAN_IE_IBSS_PARMS {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned short wATIMWindow;
-}__attribute__ ((__packed__))
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned short wATIMWindow;
+} __attribute__ ((__packed__))
 WLAN_IE_IBSS_PARMS, *PWLAN_IE_IBSS_PARMS;
 
-
 // Challenge Text
 #pragma pack(1)
 typedef struct tagWLAN_IE_CHALLENGE {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char abyChallenge[1];
-}__attribute__ ((__packed__))
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char abyChallenge[1];
+} __attribute__ ((__packed__))
 WLAN_IE_CHALLENGE,  *PWLAN_IE_CHALLENGE;
 
-
 #pragma pack(1)
 typedef struct tagWLAN_IE_RSN_EXT {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char abyOUI[4];
-    unsigned short wVersion;
-    unsigned char abyMulticast[4];
-    unsigned short wPKCount;
-    struct {
-        unsigned char abyOUI[4];
-    } PKSList[1]; // the rest is variable so need to
-    // overlay ieauth structure
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char abyOUI[4];
+       unsigned short wVersion;
+       unsigned char abyMulticast[4];
+       unsigned short wPKCount;
+       struct {
+               unsigned char abyOUI[4];
+       } PKSList[1]; // the rest is variable so need to
+       // overlay ieauth structure
 } WLAN_IE_RSN_EXT, *PWLAN_IE_RSN_EXT;
 
 #pragma pack(1)
 typedef struct tagWLAN_IE_RSN_AUTH {
-    unsigned short wAuthCount;
-    struct {
-        unsigned char abyOUI[4];
-    } AuthKSList[1];
+       unsigned short wAuthCount;
+       struct {
+               unsigned char abyOUI[4];
+       } AuthKSList[1];
 } WLAN_IE_RSN_AUTH, *PWLAN_IE_RSN_AUTH;
 
 // RSN Identity
 #pragma pack(1)
 typedef struct tagWLAN_IE_RSN {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned short wVersion;
-    unsigned char abyRSN[WLAN_MIN_ARRAY];
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned short wVersion;
+       unsigned char abyRSN[WLAN_MIN_ARRAY];
 } WLAN_IE_RSN, *PWLAN_IE_RSN;
 
-
 // ERP
 #pragma pack(1)
 typedef struct tagWLAN_IE_ERP {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char byContext;
-}__attribute__ ((__packed__))
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char byContext;
+} __attribute__ ((__packed__))
 WLAN_IE_ERP,  *PWLAN_IE_ERP;
 
-
 #pragma pack(1)
 typedef struct _MEASEURE_REQ {
-    unsigned char byChannel;
-    unsigned char abyStartTime[8];
-    unsigned char abyDuration[2];
+       unsigned char byChannel;
+       unsigned char abyStartTime[8];
+       unsigned char abyDuration[2];
 } MEASEURE_REQ, *PMEASEURE_REQ,
-  MEASEURE_REQ_BASIC, *PMEASEURE_REQ_BASIC,
-  MEASEURE_REQ_CCA, *PMEASEURE_REQ_CCA,
-  MEASEURE_REQ_RPI, *PMEASEURE_REQ_RPI;
+       MEASEURE_REQ_BASIC, *PMEASEURE_REQ_BASIC,
+       MEASEURE_REQ_CCA, *PMEASEURE_REQ_CCA,
+       MEASEURE_REQ_RPI, *PMEASEURE_REQ_RPI;
 
 typedef struct _MEASEURE_REP_BASIC {
-    unsigned char byChannel;
-    unsigned char abyStartTime[8];
-    unsigned char abyDuration[2];
-    unsigned char byMap;
+       unsigned char byChannel;
+       unsigned char abyStartTime[8];
+       unsigned char abyDuration[2];
+       unsigned char byMap;
 } MEASEURE_REP_BASIC, *PMEASEURE_REP_BASIC;
 
 typedef struct _MEASEURE_REP_CCA {
-    unsigned char byChannel;
-    unsigned char abyStartTime[8];
-    unsigned char abyDuration[2];
-    unsigned char byCCABusyFraction;
+       unsigned char byChannel;
+       unsigned char abyStartTime[8];
+       unsigned char abyDuration[2];
+       unsigned char byCCABusyFraction;
 } MEASEURE_REP_CCA, *PMEASEURE_REP_CCA;
 
 typedef struct _MEASEURE_REP_RPI {
-    unsigned char byChannel;
-    unsigned char abyStartTime[8];
-    unsigned char abyDuration[2];
-    unsigned char abyRPIdensity[8];
+       unsigned char byChannel;
+       unsigned char abyStartTime[8];
+       unsigned char abyDuration[2];
+       unsigned char abyRPIdensity[8];
 } MEASEURE_REP_RPI, *PMEASEURE_REP_RPI;
 
 typedef union _MEASEURE_REP {
-
-    MEASEURE_REP_BASIC  sBasic;
-    MEASEURE_REP_CCA    sCCA;
-    MEASEURE_REP_RPI    sRPI;
-
+       MEASEURE_REP_BASIC  sBasic;
+       MEASEURE_REP_CCA    sCCA;
+       MEASEURE_REP_RPI    sRPI;
 } MEASEURE_REP, *PMEASEURE_REP;
 
 typedef struct _WLAN_IE_MEASURE_REQ {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char byToken;
-    unsigned char byMode;
-    unsigned char byType;
-    MEASEURE_REQ        sReq;
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char byToken;
+       unsigned char byMode;
+       unsigned char byType;
+       MEASEURE_REQ        sReq;
 } WLAN_IE_MEASURE_REQ, *PWLAN_IE_MEASURE_REQ;
 
 typedef struct _WLAN_IE_MEASURE_REP {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char byToken;
-    unsigned char byMode;
-    unsigned char byType;
-    MEASEURE_REP        sRep;
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char byToken;
+       unsigned char byMode;
+       unsigned char byType;
+       MEASEURE_REP        sRep;
 } WLAN_IE_MEASURE_REP, *PWLAN_IE_MEASURE_REP;
 
 typedef struct _WLAN_IE_CH_SW {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char byMode;
-    unsigned char byChannel;
-    unsigned char byCount;
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char byMode;
+       unsigned char byChannel;
+       unsigned char byCount;
 } WLAN_IE_CH_SW, *PWLAN_IE_CH_SW;
 
 typedef struct _WLAN_IE_QUIET {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char byQuietCount;
-    unsigned char byQuietPeriod;
-    unsigned char abyQuietDuration[2];
-    unsigned char abyQuietOffset[2];
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char byQuietCount;
+       unsigned char byQuietPeriod;
+       unsigned char abyQuietDuration[2];
+       unsigned char abyQuietOffset[2];
 } WLAN_IE_QUIET, *PWLAN_IE_QUIET;
 
 typedef struct _WLAN_IE_COUNTRY {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char abyCountryString[3];
-    unsigned char abyCountryInfo[3];
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char abyCountryString[3];
+       unsigned char abyCountryInfo[3];
 } WLAN_IE_COUNTRY, *PWLAN_IE_COUNTRY;
 
 typedef struct _WLAN_IE_PW_CONST {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char byPower;
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char byPower;
 } WLAN_IE_PW_CONST, *PWLAN_IE_PW_CONST;
 
 typedef struct _WLAN_IE_PW_CAP {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char byMinPower;
-    unsigned char byMaxPower;
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char byMinPower;
+       unsigned char byMaxPower;
 } WLAN_IE_PW_CAP, *PWLAN_IE_PW_CAP;
 
 typedef struct _WLAN_IE_SUPP_CH {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char abyChannelTuple[2];
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char abyChannelTuple[2];
 } WLAN_IE_SUPP_CH, *PWLAN_IE_SUPP_CH;
 
 typedef struct _WLAN_IE_TPC_REQ {
-    unsigned char byElementID;
-    unsigned char len;
+       unsigned char byElementID;
+       unsigned char len;
 } WLAN_IE_TPC_REQ, *PWLAN_IE_TPC_REQ;
 
 typedef struct _WLAN_IE_TPC_REP {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char byTxPower;
-    unsigned char byLinkMargin;
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char byTxPower;
+       unsigned char byLinkMargin;
 } WLAN_IE_TPC_REP, *PWLAN_IE_TPC_REP;
 
-
 typedef struct _WLAN_IE_IBSS_DFS {
-    unsigned char byElementID;
-    unsigned char len;
-    unsigned char abyDFSOwner[6];
-    unsigned char byDFSRecovery;
-    unsigned char abyChannelMap[2];
+       unsigned char byElementID;
+       unsigned char len;
+       unsigned char abyDFSOwner[6];
+       unsigned char byDFSRecovery;
+       unsigned char abyChannelMap[2];
 } WLAN_IE_IBSS_DFS, *PWLAN_IE_IBSS_DFS;
 
 #pragma pack()
 
-
-
 // Frame Types
 // prototype structure, all mgmt frame types will start with these members
 typedef struct tagWLAN_FR_MGMT {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR       pHdr;
-
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR       pHdr;
 } WLAN_FR_MGMT,  *PWLAN_FR_MGMT;
 
 // Beacon frame
 typedef struct tagWLAN_FR_BEACON {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR         pHdr;
-    // fixed fields
-    PQWORD                  pqwTimestamp;
-    unsigned short *pwBeaconInterval;
-    unsigned short *pwCapInfo;
-    /*-- info elements ----------*/
-    PWLAN_IE_SSID           pSSID;
-    PWLAN_IE_SUPP_RATES     pSuppRates;
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR         pHdr;
+       // fixed fields
+       PQWORD                  pqwTimestamp;
+       unsigned short *pwBeaconInterval;
+       unsigned short *pwCapInfo;
+       /*-- info elements ----------*/
+       PWLAN_IE_SSID           pSSID;
+       PWLAN_IE_SUPP_RATES     pSuppRates;
 //  PWLAN_IE_FH_PARMS       pFHParms;
-    PWLAN_IE_DS_PARMS       pDSParms;
-    PWLAN_IE_CF_PARMS       pCFParms;
-    PWLAN_IE_TIM            pTIM;
-    PWLAN_IE_IBSS_PARMS     pIBSSParms;
-    PWLAN_IE_RSN            pRSN;
-    PWLAN_IE_RSN_EXT        pRSNWPA;
-    PWLAN_IE_ERP            pERP;
-    PWLAN_IE_SUPP_RATES     pExtSuppRates;
-    PWLAN_IE_COUNTRY        pIE_Country;
-    PWLAN_IE_PW_CONST       pIE_PowerConstraint;
-    PWLAN_IE_CH_SW          pIE_CHSW;
-    PWLAN_IE_IBSS_DFS       pIE_IBSSDFS;
-    PWLAN_IE_QUIET          pIE_Quiet;
-
+       PWLAN_IE_DS_PARMS       pDSParms;
+       PWLAN_IE_CF_PARMS       pCFParms;
+       PWLAN_IE_TIM            pTIM;
+       PWLAN_IE_IBSS_PARMS     pIBSSParms;
+       PWLAN_IE_RSN            pRSN;
+       PWLAN_IE_RSN_EXT        pRSNWPA;
+       PWLAN_IE_ERP            pERP;
+       PWLAN_IE_SUPP_RATES     pExtSuppRates;
+       PWLAN_IE_COUNTRY        pIE_Country;
+       PWLAN_IE_PW_CONST       pIE_PowerConstraint;
+       PWLAN_IE_CH_SW          pIE_CHSW;
+       PWLAN_IE_IBSS_DFS       pIE_IBSSDFS;
+       PWLAN_IE_QUIET          pIE_Quiet;
 } WLAN_FR_BEACON, *PWLAN_FR_BEACON;
 
-
 // IBSS ATIM frame
 typedef struct tagWLAN_FR_IBSSATIM {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR         pHdr;
-
-    // fixed fields
-    // info elements
-    // this frame type has a null body
-
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR         pHdr;
+
+       // fixed fields
+       // info elements
+       // this frame type has a null body
 } WLAN_FR_IBSSATIM, *PWLAN_FR_IBSSATIM;
 
 // Disassociation
 typedef struct tagWLAN_FR_DISASSOC {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR         pHdr;
-    /*-- fixed fields -----------*/
-    unsigned short *pwReason;
-    /*-- info elements ----------*/
-
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR         pHdr;
+       /*-- fixed fields -----------*/
+       unsigned short *pwReason;
+       /*-- info elements ----------*/
 } WLAN_FR_DISASSOC, *PWLAN_FR_DISASSOC;
 
 // Association Request
 typedef struct tagWLAN_FR_ASSOCREQ {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR         pHdr;
-    /*-- fixed fields -----------*/
-    unsigned short *pwCapInfo;
-    unsigned short *pwListenInterval;
-    /*-- info elements ----------*/
-    PWLAN_IE_SSID           pSSID;
-    PWLAN_IE_SUPP_RATES     pSuppRates;
-    PWLAN_IE_RSN            pRSN;
-    PWLAN_IE_RSN_EXT        pRSNWPA;
-    PWLAN_IE_SUPP_RATES     pExtSuppRates;
-    PWLAN_IE_PW_CAP         pCurrPowerCap;
-    PWLAN_IE_SUPP_CH        pCurrSuppCh;
-
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR         pHdr;
+       /*-- fixed fields -----------*/
+       unsigned short *pwCapInfo;
+       unsigned short *pwListenInterval;
+       /*-- info elements ----------*/
+       PWLAN_IE_SSID           pSSID;
+       PWLAN_IE_SUPP_RATES     pSuppRates;
+       PWLAN_IE_RSN            pRSN;
+       PWLAN_IE_RSN_EXT        pRSNWPA;
+       PWLAN_IE_SUPP_RATES     pExtSuppRates;
+       PWLAN_IE_PW_CAP         pCurrPowerCap;
+       PWLAN_IE_SUPP_CH        pCurrSuppCh;
 } WLAN_FR_ASSOCREQ, *PWLAN_FR_ASSOCREQ;
 
 // Association Response
 typedef struct tagWLAN_FR_ASSOCRESP {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR         pHdr;
-    /*-- fixed fields -----------*/
-    unsigned short *pwCapInfo;
-    unsigned short *pwStatus;
-    unsigned short *pwAid;
-    /*-- info elements ----------*/
-    PWLAN_IE_SUPP_RATES     pSuppRates;
-    PWLAN_IE_SUPP_RATES     pExtSuppRates;
-
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR         pHdr;
+       /*-- fixed fields -----------*/
+       unsigned short *pwCapInfo;
+       unsigned short *pwStatus;
+       unsigned short *pwAid;
+       /*-- info elements ----------*/
+       PWLAN_IE_SUPP_RATES     pSuppRates;
+       PWLAN_IE_SUPP_RATES     pExtSuppRates;
 } WLAN_FR_ASSOCRESP, *PWLAN_FR_ASSOCRESP;
 
 // Reassociation Request
 typedef struct tagWLAN_FR_REASSOCREQ {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR         pHdr;
-
-    /*-- fixed fields -----------*/
-    unsigned short *pwCapInfo;
-    unsigned short *pwListenInterval;
-    PIEEE_ADDR              pAddrCurrAP;
-
-    /*-- info elements ----------*/
-    PWLAN_IE_SSID           pSSID;
-    PWLAN_IE_SUPP_RATES     pSuppRates;
-    PWLAN_IE_RSN            pRSN;
-    PWLAN_IE_RSN_EXT        pRSNWPA;
-    PWLAN_IE_SUPP_RATES     pExtSuppRates;
-
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR         pHdr;
+
+       /*-- fixed fields -----------*/
+       unsigned short *pwCapInfo;
+       unsigned short *pwListenInterval;
+       PIEEE_ADDR              pAddrCurrAP;
+
+       /*-- info elements ----------*/
+       PWLAN_IE_SSID           pSSID;
+       PWLAN_IE_SUPP_RATES     pSuppRates;
+       PWLAN_IE_RSN            pRSN;
+       PWLAN_IE_RSN_EXT        pRSNWPA;
+       PWLAN_IE_SUPP_RATES     pExtSuppRates;
 } WLAN_FR_REASSOCREQ, *PWLAN_FR_REASSOCREQ;
 
 // Reassociation Response
 typedef struct tagWLAN_FR_REASSOCRESP {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR         pHdr;
-    /*-- fixed fields -----------*/
-    unsigned short *pwCapInfo;
-    unsigned short *pwStatus;
-    unsigned short *pwAid;
-    /*-- info elements ----------*/
-    PWLAN_IE_SUPP_RATES     pSuppRates;
-    PWLAN_IE_SUPP_RATES     pExtSuppRates;
-
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR         pHdr;
+       /*-- fixed fields -----------*/
+       unsigned short *pwCapInfo;
+       unsigned short *pwStatus;
+       unsigned short *pwAid;
+       /*-- info elements ----------*/
+       PWLAN_IE_SUPP_RATES     pSuppRates;
+       PWLAN_IE_SUPP_RATES     pExtSuppRates;
 } WLAN_FR_REASSOCRESP, *PWLAN_FR_REASSOCRESP;
 
 // Probe Request
 typedef struct tagWLAN_FR_PROBEREQ {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR         pHdr;
-    /*-- fixed fields -----------*/
-    /*-- info elements ----------*/
-    PWLAN_IE_SSID           pSSID;
-    PWLAN_IE_SUPP_RATES     pSuppRates;
-    PWLAN_IE_SUPP_RATES     pExtSuppRates;
-
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR         pHdr;
+       /*-- fixed fields -----------*/
+       /*-- info elements ----------*/
+       PWLAN_IE_SSID           pSSID;
+       PWLAN_IE_SUPP_RATES     pSuppRates;
+       PWLAN_IE_SUPP_RATES     pExtSuppRates;
 } WLAN_FR_PROBEREQ, *PWLAN_FR_PROBEREQ;
 
 // Probe Response
 typedef struct tagWLAN_FR_PROBERESP {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR         pHdr;
-    /*-- fixed fields -----------*/
-    PQWORD                  pqwTimestamp;
-    unsigned short *pwBeaconInterval;
-    unsigned short *pwCapInfo;
-    /*-- info elements ----------*/
-    PWLAN_IE_SSID           pSSID;
-    PWLAN_IE_SUPP_RATES     pSuppRates;
-    PWLAN_IE_DS_PARMS       pDSParms;
-    PWLAN_IE_CF_PARMS       pCFParms;
-    PWLAN_IE_IBSS_PARMS     pIBSSParms;
-    PWLAN_IE_RSN            pRSN;
-    PWLAN_IE_RSN_EXT        pRSNWPA;
-    PWLAN_IE_ERP            pERP;
-    PWLAN_IE_SUPP_RATES     pExtSuppRates;
-    PWLAN_IE_COUNTRY        pIE_Country;
-    PWLAN_IE_PW_CONST       pIE_PowerConstraint;
-    PWLAN_IE_CH_SW          pIE_CHSW;
-    PWLAN_IE_IBSS_DFS       pIE_IBSSDFS;
-    PWLAN_IE_QUIET          pIE_Quiet;
-
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR         pHdr;
+       /*-- fixed fields -----------*/
+       PQWORD                  pqwTimestamp;
+       unsigned short *pwBeaconInterval;
+       unsigned short *pwCapInfo;
+       /*-- info elements ----------*/
+       PWLAN_IE_SSID           pSSID;
+       PWLAN_IE_SUPP_RATES     pSuppRates;
+       PWLAN_IE_DS_PARMS       pDSParms;
+       PWLAN_IE_CF_PARMS       pCFParms;
+       PWLAN_IE_IBSS_PARMS     pIBSSParms;
+       PWLAN_IE_RSN            pRSN;
+       PWLAN_IE_RSN_EXT        pRSNWPA;
+       PWLAN_IE_ERP            pERP;
+       PWLAN_IE_SUPP_RATES     pExtSuppRates;
+       PWLAN_IE_COUNTRY        pIE_Country;
+       PWLAN_IE_PW_CONST       pIE_PowerConstraint;
+       PWLAN_IE_CH_SW          pIE_CHSW;
+       PWLAN_IE_IBSS_DFS       pIE_IBSSDFS;
+       PWLAN_IE_QUIET          pIE_Quiet;
 } WLAN_FR_PROBERESP, *PWLAN_FR_PROBERESP;
 
 // Authentication
 typedef struct tagWLAN_FR_AUTHEN {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR         pHdr;
-    /*-- fixed fields -----------*/
-    unsigned short *pwAuthAlgorithm;
-    unsigned short *pwAuthSequence;
-    unsigned short *pwStatus;
-    /*-- info elements ----------*/
-    PWLAN_IE_CHALLENGE      pChallenge;
-
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR         pHdr;
+       /*-- fixed fields -----------*/
+       unsigned short *pwAuthAlgorithm;
+       unsigned short *pwAuthSequence;
+       unsigned short *pwStatus;
+       /*-- info elements ----------*/
+       PWLAN_IE_CHALLENGE      pChallenge;
 } WLAN_FR_AUTHEN, *PWLAN_FR_AUTHEN;
 
 // Deauthenication
 typedef struct tagWLAN_FR_DEAUTHEN {
-
-    unsigned int       uType;
-    unsigned int       len;
-    unsigned char *pBuf;
-    PUWLAN_80211HDR         pHdr;
-    /*-- fixed fields -----------*/
-    unsigned short *pwReason;
-
-    /*-- info elements ----------*/
-
+       unsigned int    uType;
+       unsigned int    len;
+       unsigned char *pBuf;
+       PUWLAN_80211HDR         pHdr;
+       /*-- fixed fields -----------*/
+       unsigned short *pwReason;
+
+       /*-- info elements ----------*/
 } WLAN_FR_DEAUTHEN, *PWLAN_FR_DEAUTHEN;
 
 /*---------------------  Export Functions  --------------------------*/
 
 void
 vMgrEncodeBeacon(
-    PWLAN_FR_BEACON  pFrame
-     );
+       PWLAN_FR_BEACON  pFrame
+);
 
 void
 vMgrDecodeBeacon(
-    PWLAN_FR_BEACON  pFrame
-    );
+       PWLAN_FR_BEACON  pFrame
+);
 
 void
 vMgrEncodeIBSSATIM(
-    PWLAN_FR_IBSSATIM   pFrame
-    );
+       PWLAN_FR_IBSSATIM   pFrame
+);
 
 void
 vMgrDecodeIBSSATIM(
-    PWLAN_FR_IBSSATIM   pFrame
-    );
+       PWLAN_FR_IBSSATIM   pFrame
+);
 
 void
 vMgrEncodeDisassociation(
-    PWLAN_FR_DISASSOC  pFrame
-    );
+       PWLAN_FR_DISASSOC  pFrame
+);
 
 void
 vMgrDecodeDisassociation(
-    PWLAN_FR_DISASSOC  pFrame
-    );
+       PWLAN_FR_DISASSOC  pFrame
+);
 
 void
 vMgrEncodeAssocRequest(
-    PWLAN_FR_ASSOCREQ  pFrame
-    );
+       PWLAN_FR_ASSOCREQ  pFrame
+);
 
 void
 vMgrDecodeAssocRequest(
-    PWLAN_FR_ASSOCREQ  pFrame
-    );
+       PWLAN_FR_ASSOCREQ  pFrame
+);
 
 void
 vMgrEncodeAssocResponse(
-    PWLAN_FR_ASSOCRESP  pFrame
-    );
+       PWLAN_FR_ASSOCRESP  pFrame
+);
 
 void
 vMgrDecodeAssocResponse(
-    PWLAN_FR_ASSOCRESP  pFrame
-    );
+       PWLAN_FR_ASSOCRESP  pFrame
+);
 
 void
 vMgrEncodeReassocRequest(
-    PWLAN_FR_REASSOCREQ  pFrame
-    );
+       PWLAN_FR_REASSOCREQ  pFrame
+);
 
 void
 vMgrDecodeReassocRequest(
-    PWLAN_FR_REASSOCREQ  pFrame
-    );
+       PWLAN_FR_REASSOCREQ  pFrame
+);
 
 void
 vMgrEncodeProbeRequest(
-    PWLAN_FR_PROBEREQ  pFrame
-    );
+       PWLAN_FR_PROBEREQ  pFrame
+);
 
 void
 vMgrDecodeProbeRequest(
-    PWLAN_FR_PROBEREQ  pFrame
-    );
+       PWLAN_FR_PROBEREQ  pFrame
+);
 
 void
 vMgrEncodeProbeResponse(
-    PWLAN_FR_PROBERESP  pFrame
-    );
+       PWLAN_FR_PROBERESP  pFrame
+);
 
 void
 vMgrDecodeProbeResponse(
-    PWLAN_FR_PROBERESP  pFrame
-    );
+       PWLAN_FR_PROBERESP  pFrame
+);
 
 void
 vMgrEncodeAuthen(
-    PWLAN_FR_AUTHEN  pFrame
-    );
+       PWLAN_FR_AUTHEN  pFrame
+);
 
 void
 vMgrDecodeAuthen(
-    PWLAN_FR_AUTHEN  pFrame
-    );
+       PWLAN_FR_AUTHEN  pFrame
+);
 
 void
 vMgrEncodeDeauthen(
-    PWLAN_FR_DEAUTHEN  pFrame
-    );
+       PWLAN_FR_DEAUTHEN  pFrame
+);
 
 void
 vMgrDecodeDeauthen(
-    PWLAN_FR_DEAUTHEN  pFrame
-    );
+       PWLAN_FR_DEAUTHEN  pFrame
+);
 
 void
 vMgrEncodeReassocResponse(
-    PWLAN_FR_REASSOCRESP  pFrame
-    );
+       PWLAN_FR_REASSOCRESP  pFrame
+);
 
 void
 vMgrDecodeReassocResponse(
-    PWLAN_FR_REASSOCRESP  pFrame
-    );
+       PWLAN_FR_REASSOCRESP  pFrame
+);
 
 #endif// __80211MGR_H__
index cf7364d65263abebbe802b8ed426727fbc1cab00..dfda3c82906cb2c73bc8785af86694858229faba 100644 (file)
@@ -99,7 +99,7 @@ typedef struct _WLAN_FRAME_TPCREP {
 
 /*---------------------  Static Functions  --------------------------*/
 static bool s_bRxMSRReq(PSMgmtObject pMgmt, PWLAN_FRAME_MSRREQ pMSRReq,
-               unsigned int uLength)
+                       unsigned int uLength)
 {
        size_t    uNumOfEIDs = 0;
        bool bResult = true;
@@ -107,20 +107,19 @@ static bool s_bRxMSRReq(PSMgmtObject pMgmt, PWLAN_FRAME_MSRREQ pMSRReq,
        if (uLength <= WLAN_A3FR_MAXLEN)
                memcpy(pMgmt->abyCurrentMSRReq, pMSRReq, uLength);
        uNumOfEIDs = ((uLength - offsetof(WLAN_FRAME_MSRREQ,
-                       sMSRReqEIDs))/
-                       (sizeof(WLAN_IE_MEASURE_REQ)));
+                                         sMSRReqEIDs))/
+                     (sizeof(WLAN_IE_MEASURE_REQ)));
        pMgmt->pCurrMeasureEIDRep = &(((PWLAN_FRAME_MSRREP)
-                       (pMgmt->abyCurrentMSRRep))->sMSRRepEIDs[0]);
+                                      (pMgmt->abyCurrentMSRRep))->sMSRRepEIDs[0]);
        pMgmt->uLengthOfRepEIDs = 0;
        bResult = CARDbStartMeasure(pMgmt->pAdapter,
-                               ((PWLAN_FRAME_MSRREQ)
-                               (pMgmt->abyCurrentMSRReq))->sMSRReqEIDs,
-                               uNumOfEIDs
-                               );
+                                   ((PWLAN_FRAME_MSRREQ)
+                                    (pMgmt->abyCurrentMSRReq))->sMSRReqEIDs,
+                                   uNumOfEIDs
+);
        return bResult;
 }
 
-
 static bool s_bRxTPCReq(PSMgmtObject pMgmt,
                        PWLAN_FRAME_TPCREQ pTPCReq,
                        unsigned char byRate,
@@ -132,29 +131,29 @@ static bool s_bRxTPCReq(PSMgmtObject pMgmt,
        pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
        memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket +
-sizeof(STxMgmtPacket));
+                                                   sizeof(STxMgmtPacket));
 
        pFrame = (PWLAN_FRAME_TPCREP)((unsigned char *)pTxPacket +
-sizeof(STxMgmtPacket));
+                                     sizeof(STxMgmtPacket));
 
        pFrame->Header.wFrameCtl = (WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) |
-                               WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ACTION)
-                               );
+                                   WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ACTION)
+);
 
        memcpy(pFrame->Header.abyAddr1,
-               pTPCReq->Header.abyAddr2,
-               WLAN_ADDR_LEN);
+              pTPCReq->Header.abyAddr2,
+              WLAN_ADDR_LEN);
        memcpy(pFrame->Header.abyAddr2,
-               CARDpGetCurrentAddress(pMgmt->pAdapter),
-               WLAN_ADDR_LEN);
+              CARDpGetCurrentAddress(pMgmt->pAdapter),
+              WLAN_ADDR_LEN);
        memcpy(pFrame->Header.abyAddr3,
-               pMgmt->abyCurrBSSID,
-               WLAN_BSSID_LEN);
+              pMgmt->abyCurrBSSID,
+              WLAN_BSSID_LEN);
 
        pFrame->byCategory = 0;
        pFrame->byAction = 3;
        pFrame->byDialogToken = ((PWLAN_FRAME_MSRREQ)
-(pMgmt->abyCurrentMSRReq))->byDialogToken;
+                                (pMgmt->abyCurrentMSRReq))->byDialogToken;
 
        pFrame->sTPCRepEIDs.byElementID = WLAN_EID_TPC_REP;
        pFrame->sTPCRepEIDs.len = 2;
@@ -185,25 +184,22 @@ sizeof(STxMgmtPacket));
        default:
                pFrame->sTPCRepEIDs.byLinkMargin = 82 - byRSSI;
                break;
-}
+       }
 
        pTxPacket->cbMPDULen = sizeof(WLAN_FRAME_TPCREP);
        pTxPacket->cbPayloadLen = sizeof(WLAN_FRAME_TPCREP) -
-WLAN_HDR_ADDR3_LEN;
+               WLAN_HDR_ADDR3_LEN;
        if (csMgmt_xmit(pMgmt->pAdapter, pTxPacket) != CMD_STATUS_PENDING)
                return false;
        return true;
-/*    return (CARDbSendPacket(pMgmt->pAdapter, pFrame, PKT_TYPE_802_11_MNG,
-sizeof(WLAN_FRAME_TPCREP))); */
-
+/*    return CARDbSendPacket(pMgmt->pAdapter, pFrame, PKT_TYPE_802_11_MNG,
+      sizeof(WLAN_FRAME_TPCREP)); */
 }
 
-
 /*---------------------  Export Variables  --------------------------*/
 
 /*---------------------  Export Functions  --------------------------*/
 
-
 /*+
  *
  * Description:
@@ -218,7 +214,7 @@ sizeof(WLAN_FRAME_TPCREP))); */
  *
  * Return Value: None.
  *
--*/
+ -*/
 bool
 IEEE11hbMgrRxAction(void *pMgmtHandle, void *pRxPacket)
 {
@@ -233,86 +229,85 @@ IEEE11hbMgrRxAction(void *pMgmtHandle, void *pRxPacket)
                return false;
 
        pAction = (PWLAN_FRAME_ACTION)
-(((PSRxMgmtPacket)pRxPacket)->p80211Header);
+               (((PSRxMgmtPacket)pRxPacket)->p80211Header);
 
        if (pAction->byCategory == 0) {
                switch (pAction->byAction) {
                case ACTION_MSRREQ:
                        return s_bRxMSRReq(pMgmt,
-                                       (PWLAN_FRAME_MSRREQ)
-                                       pAction,
-                                       uLength);
+                                          (PWLAN_FRAME_MSRREQ)
+                                          pAction,
+                                          uLength);
                        break;
                case ACTION_MSRREP:
                        break;
                case ACTION_TPCREQ:
                        return s_bRxTPCReq(pMgmt,
-                               (PWLAN_FRAME_TPCREQ) pAction,
-                               ((PSRxMgmtPacket)pRxPacket)->byRxRate,
-                               (unsigned char)
-                               ((PSRxMgmtPacket)pRxPacket)->uRSSI);
+                                          (PWLAN_FRAME_TPCREQ) pAction,
+                                          ((PSRxMgmtPacket)pRxPacket)->byRxRate,
+                                          (unsigned char)
+                                          ((PSRxMgmtPacket)pRxPacket)->uRSSI);
                        break;
                case ACTION_TPCREP:
                        break;
                case ACTION_CHSW:
                        pChannelSwitch = (PWLAN_IE_CH_SW) (pAction->abyVars);
                        if ((pChannelSwitch->byElementID == WLAN_EID_CH_SWITCH)
-                       && (pChannelSwitch->len == 3)) {
+                           && (pChannelSwitch->len == 3)) {
                                /* valid element id */
                                CARDbChannelSwitch(pMgmt->pAdapter,
-                               pChannelSwitch->byMode,
-                               get_channel_mapping(pMgmt->pAdapter,
-                               pChannelSwitch->byChannel,
-                               pMgmt->eCurrentPHYMode),
-                               pChannelSwitch->byCount);
+                                                  pChannelSwitch->byMode,
+                                                  get_channel_mapping(pMgmt->pAdapter,
+                                                                      pChannelSwitch->byChannel,
+                                                                      pMgmt->eCurrentPHYMode),
+                                                  pChannelSwitch->byCount);
                        }
                        break;
                default:
                        DBG_PRT(MSG_LEVEL_DEBUG,
-                               KERN_INFO"Unknown Action = %d\n",
+                               KERN_INFO "Unknown Action = %d\n",
                                pAction->byAction);
                        break;
                }
        } else {
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown Category = %d\n",
-pAction->byCategory);
-       pAction->byCategory |= 0x80;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unknown Category = %d\n",
+                       pAction->byCategory);
+               pAction->byCategory |= 0x80;
 
-       /*return (CARDbSendPacket(pMgmt->pAdapter, pAction, PKT_TYPE_802_11_MNG,
-uLength));*/
-       return true;
+               /*return CARDbSendPacket(pMgmt->pAdapter, pAction, PKT_TYPE_802_11_MNG,
+                 uLength);*/
+               return true;
        }
        return true;
 }
 
-
 bool IEEE11hbMSRRepTx(void *pMgmtHandle)
 {
        PSMgmtObject            pMgmt = (PSMgmtObject) pMgmtHandle;
        PWLAN_FRAME_MSRREP      pMSRRep = (PWLAN_FRAME_MSRREP)
-(pMgmt->abyCurrentMSRRep + sizeof(STxMgmtPacket));
+               (pMgmt->abyCurrentMSRRep + sizeof(STxMgmtPacket));
        size_t                    uLength = 0;
        PSTxMgmtPacket          pTxPacket = NULL;
 
        pTxPacket = (PSTxMgmtPacket)pMgmt->abyCurrentMSRRep;
        memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket +
-sizeof(STxMgmtPacket));
+                                                   sizeof(STxMgmtPacket));
 
        pMSRRep->Header.wFrameCtl = (WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) |
-                               WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ACTION)
-                               );
+                                    WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ACTION)
+);
 
        memcpy(pMSRRep->Header.abyAddr1, ((PWLAN_FRAME_MSRREQ)
-               (pMgmt->abyCurrentMSRReq))->Header.abyAddr2, WLAN_ADDR_LEN);
+                                         (pMgmt->abyCurrentMSRReq))->Header.abyAddr2, WLAN_ADDR_LEN);
        memcpy(pMSRRep->Header.abyAddr2,
-               CARDpGetCurrentAddress(pMgmt->pAdapter), WLAN_ADDR_LEN);
+              CARDpGetCurrentAddress(pMgmt->pAdapter), WLAN_ADDR_LEN);
        memcpy(pMSRRep->Header.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
 
        pMSRRep->byCategory = 0;
        pMSRRep->byAction = 1;
        pMSRRep->byDialogToken = ((PWLAN_FRAME_MSRREQ)
-               (pMgmt->abyCurrentMSRReq))->byDialogToken;
+                                 (pMgmt->abyCurrentMSRReq))->byDialogToken;
 
        uLength = pMgmt->uLengthOfRepEIDs + offsetof(WLAN_FRAME_MSRREP,
                                                     sMSRRepEIDs);
@@ -322,8 +317,6 @@ sizeof(STxMgmtPacket));
        if (csMgmt_xmit(pMgmt->pAdapter, pTxPacket) != CMD_STATUS_PENDING)
                return false;
        return true;
-/*    return (CARDbSendPacket(pMgmt->pAdapter, pMSRRep, PKT_TYPE_802_11_MNG,
-uLength)); */
-
+/*    return CARDbSendPacket(pMgmt->pAdapter, pMSRRep, PKT_TYPE_802_11_MNG,
+      uLength); */
 }
-
index 542340b96e3868b25d42c30f473a7850eb904dee..8819fa1563b75743826a8e66efcaec738ed057fd 100644 (file)
@@ -45,8 +45,8 @@
 
 /*---------------------  Export Functions  --------------------------*/
 
-bool IEEE11hbMSRRepTx (
-    void *pMgmtHandle
-    );
+bool IEEE11hbMSRRepTx(
+       void *pMgmtHandle
+);
 
 #endif // __IEEE11h_H__
index e30168f2da2f58a02f72dd46343fb54b86f1f285..36081481c6d17f13ff88b25a915ffa49f0dbfaa9 100644 (file)
 
 unsigned char sbox_table[256] =
 {
-0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
-0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
-0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
-0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
-0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
-0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
-0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
-0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
-0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
-0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
-0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
-0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
-0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
-0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
-0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
-0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
+       0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
+       0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
+       0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
+       0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
+       0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
+       0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
+       0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
+       0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
+       0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
+       0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
+       0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
+       0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
+       0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
+       0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
+       0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
+       0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
 };
 
 unsigned char dot2_table[256] = {
-0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
-0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e,
-0x40, 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e,
-0x60, 0x62, 0x64, 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7e,
-0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9c, 0x9e,
-0xa0, 0xa2, 0xa4, 0xa6, 0xa8, 0xaa, 0xac, 0xae, 0xb0, 0xb2, 0xb4, 0xb6, 0xb8, 0xba, 0xbc, 0xbe,
-0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce, 0xd0, 0xd2, 0xd4, 0xd6, 0xd8, 0xda, 0xdc, 0xde,
-0xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xec, 0xee, 0xf0, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfc, 0xfe,
-0x1b, 0x19, 0x1f, 0x1d, 0x13, 0x11, 0x17, 0x15, 0x0b, 0x09, 0x0f, 0x0d, 0x03, 0x01, 0x07, 0x05,
-0x3b, 0x39, 0x3f, 0x3d, 0x33, 0x31, 0x37, 0x35, 0x2b, 0x29, 0x2f, 0x2d, 0x23, 0x21, 0x27, 0x25,
-0x5b, 0x59, 0x5f, 0x5d, 0x53, 0x51, 0x57, 0x55, 0x4b, 0x49, 0x4f, 0x4d, 0x43, 0x41, 0x47, 0x45,
-0x7b, 0x79, 0x7f, 0x7d, 0x73, 0x71, 0x77, 0x75, 0x6b, 0x69, 0x6f, 0x6d, 0x63, 0x61, 0x67, 0x65,
-0x9b, 0x99, 0x9f, 0x9d, 0x93, 0x91, 0x97, 0x95, 0x8b, 0x89, 0x8f, 0x8d, 0x83, 0x81, 0x87, 0x85,
-0xbb, 0xb9, 0xbf, 0xbd, 0xb3, 0xb1, 0xb7, 0xb5, 0xab, 0xa9, 0xaf, 0xad, 0xa3, 0xa1, 0xa7, 0xa5,
-0xdb, 0xd9, 0xdf, 0xdd, 0xd3, 0xd1, 0xd7, 0xd5, 0xcb, 0xc9, 0xcf, 0xcd, 0xc3, 0xc1, 0xc7, 0xc5,
-0xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, 0xf5, 0xeb, 0xe9, 0xef, 0xed, 0xe3, 0xe1, 0xe7, 0xe5
+       0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
+       0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e,
+       0x40, 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e,
+       0x60, 0x62, 0x64, 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7e,
+       0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9c, 0x9e,
+       0xa0, 0xa2, 0xa4, 0xa6, 0xa8, 0xaa, 0xac, 0xae, 0xb0, 0xb2, 0xb4, 0xb6, 0xb8, 0xba, 0xbc, 0xbe,
+       0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce, 0xd0, 0xd2, 0xd4, 0xd6, 0xd8, 0xda, 0xdc, 0xde,
+       0xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xec, 0xee, 0xf0, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfc, 0xfe,
+       0x1b, 0x19, 0x1f, 0x1d, 0x13, 0x11, 0x17, 0x15, 0x0b, 0x09, 0x0f, 0x0d, 0x03, 0x01, 0x07, 0x05,
+       0x3b, 0x39, 0x3f, 0x3d, 0x33, 0x31, 0x37, 0x35, 0x2b, 0x29, 0x2f, 0x2d, 0x23, 0x21, 0x27, 0x25,
+       0x5b, 0x59, 0x5f, 0x5d, 0x53, 0x51, 0x57, 0x55, 0x4b, 0x49, 0x4f, 0x4d, 0x43, 0x41, 0x47, 0x45,
+       0x7b, 0x79, 0x7f, 0x7d, 0x73, 0x71, 0x77, 0x75, 0x6b, 0x69, 0x6f, 0x6d, 0x63, 0x61, 0x67, 0x65,
+       0x9b, 0x99, 0x9f, 0x9d, 0x93, 0x91, 0x97, 0x95, 0x8b, 0x89, 0x8f, 0x8d, 0x83, 0x81, 0x87, 0x85,
+       0xbb, 0xb9, 0xbf, 0xbd, 0xb3, 0xb1, 0xb7, 0xb5, 0xab, 0xa9, 0xaf, 0xad, 0xa3, 0xa1, 0xa7, 0xa5,
+       0xdb, 0xd9, 0xdf, 0xdd, 0xd3, 0xd1, 0xd7, 0xd5, 0xcb, 0xc9, 0xcf, 0xcd, 0xc3, 0xc1, 0xc7, 0xc5,
+       0xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, 0xf5, 0xeb, 0xe9, 0xef, 0xed, 0xe3, 0xe1, 0xe7, 0xe5
 };
 
 unsigned char dot3_table[256] = {
-0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x18, 0x1b, 0x1e, 0x1d, 0x14, 0x17, 0x12, 0x11,
-0x30, 0x33, 0x36, 0x35, 0x3c, 0x3f, 0x3a, 0x39, 0x28, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21,
-0x60, 0x63, 0x66, 0x65, 0x6c, 0x6f, 0x6a, 0x69, 0x78, 0x7b, 0x7e, 0x7d, 0x74, 0x77, 0x72, 0x71,
-0x50, 0x53, 0x56, 0x55, 0x5c, 0x5f, 0x5a, 0x59, 0x48, 0x4b, 0x4e, 0x4d, 0x44, 0x47, 0x42, 0x41,
-0xc0, 0xc3, 0xc6, 0xc5, 0xcc, 0xcf, 0xca, 0xc9, 0xd8, 0xdb, 0xde, 0xdd, 0xd4, 0xd7, 0xd2, 0xd1,
-0xf0, 0xf3, 0xf6, 0xf5, 0xfc, 0xff, 0xfa, 0xf9, 0xe8, 0xeb, 0xee, 0xed, 0xe4, 0xe7, 0xe2, 0xe1,
-0xa0, 0xa3, 0xa6, 0xa5, 0xac, 0xaf, 0xaa, 0xa9, 0xb8, 0xbb, 0xbe, 0xbd, 0xb4, 0xb7, 0xb2, 0xb1,
-0x90, 0x93, 0x96, 0x95, 0x9c, 0x9f, 0x9a, 0x99, 0x88, 0x8b, 0x8e, 0x8d, 0x84, 0x87, 0x82, 0x81,
-0x9b, 0x98, 0x9d, 0x9e, 0x97, 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8f, 0x8c, 0x89, 0x8a,
-0xab, 0xa8, 0xad, 0xae, 0xa7, 0xa4, 0xa1, 0xa2, 0xb3, 0xb0, 0xb5, 0xb6, 0xbf, 0xbc, 0xb9, 0xba,
-0xfb, 0xf8, 0xfd, 0xfe, 0xf7, 0xf4, 0xf1, 0xf2, 0xe3, 0xe0, 0xe5, 0xe6, 0xef, 0xec, 0xe9, 0xea,
-0xcb, 0xc8, 0xcd, 0xce, 0xc7, 0xc4, 0xc1, 0xc2, 0xd3, 0xd0, 0xd5, 0xd6, 0xdf, 0xdc, 0xd9, 0xda,
-0x5b, 0x58, 0x5d, 0x5e, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 0x46, 0x4f, 0x4c, 0x49, 0x4a,
-0x6b, 0x68, 0x6d, 0x6e, 0x67, 0x64, 0x61, 0x62, 0x73, 0x70, 0x75, 0x76, 0x7f, 0x7c, 0x79, 0x7a,
-0x3b, 0x38, 0x3d, 0x3e, 0x37, 0x34, 0x31, 0x32, 0x23, 0x20, 0x25, 0x26, 0x2f, 0x2c, 0x29, 0x2a,
-0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a
+       0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x18, 0x1b, 0x1e, 0x1d, 0x14, 0x17, 0x12, 0x11,
+       0x30, 0x33, 0x36, 0x35, 0x3c, 0x3f, 0x3a, 0x39, 0x28, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21,
+       0x60, 0x63, 0x66, 0x65, 0x6c, 0x6f, 0x6a, 0x69, 0x78, 0x7b, 0x7e, 0x7d, 0x74, 0x77, 0x72, 0x71,
+       0x50, 0x53, 0x56, 0x55, 0x5c, 0x5f, 0x5a, 0x59, 0x48, 0x4b, 0x4e, 0x4d, 0x44, 0x47, 0x42, 0x41,
+       0xc0, 0xc3, 0xc6, 0xc5, 0xcc, 0xcf, 0xca, 0xc9, 0xd8, 0xdb, 0xde, 0xdd, 0xd4, 0xd7, 0xd2, 0xd1,
+       0xf0, 0xf3, 0xf6, 0xf5, 0xfc, 0xff, 0xfa, 0xf9, 0xe8, 0xeb, 0xee, 0xed, 0xe4, 0xe7, 0xe2, 0xe1,
+       0xa0, 0xa3, 0xa6, 0xa5, 0xac, 0xaf, 0xaa, 0xa9, 0xb8, 0xbb, 0xbe, 0xbd, 0xb4, 0xb7, 0xb2, 0xb1,
+       0x90, 0x93, 0x96, 0x95, 0x9c, 0x9f, 0x9a, 0x99, 0x88, 0x8b, 0x8e, 0x8d, 0x84, 0x87, 0x82, 0x81,
+       0x9b, 0x98, 0x9d, 0x9e, 0x97, 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8f, 0x8c, 0x89, 0x8a,
+       0xab, 0xa8, 0xad, 0xae, 0xa7, 0xa4, 0xa1, 0xa2, 0xb3, 0xb0, 0xb5, 0xb6, 0xbf, 0xbc, 0xb9, 0xba,
+       0xfb, 0xf8, 0xfd, 0xfe, 0xf7, 0xf4, 0xf1, 0xf2, 0xe3, 0xe0, 0xe5, 0xe6, 0xef, 0xec, 0xe9, 0xea,
+       0xcb, 0xc8, 0xcd, 0xce, 0xc7, 0xc4, 0xc1, 0xc2, 0xd3, 0xd0, 0xd5, 0xd6, 0xdf, 0xdc, 0xd9, 0xda,
+       0x5b, 0x58, 0x5d, 0x5e, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 0x46, 0x4f, 0x4c, 0x49, 0x4a,
+       0x6b, 0x68, 0x6d, 0x6e, 0x67, 0x64, 0x61, 0x62, 0x73, 0x70, 0x75, 0x76, 0x7f, 0x7c, 0x79, 0x7a,
+       0x3b, 0x38, 0x3d, 0x3e, 0x37, 0x34, 0x31, 0x32, 0x23, 0x20, 0x25, 0x26, 0x2f, 0x2c, 0x29, 0x2a,
+       0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a
 };
 
 /*---------------------  Static Functions  --------------------------*/
@@ -112,121 +112,111 @@ unsigned char dot3_table[256] = {
 
 void xor_128(unsigned char *a, unsigned char *b, unsigned char *out)
 {
-unsigned long *dwPtrA = (unsigned long *) a;
-unsigned long *dwPtrB = (unsigned long *) b;
-unsigned long *dwPtrOut =(unsigned long *) out;
-
-    (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
-    (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
-    (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
-    (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
+       unsigned long *dwPtrA = (unsigned long *)a;
+       unsigned long *dwPtrB = (unsigned long *)b;
+       unsigned long *dwPtrOut = (unsigned long *)out;
+
+       (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
+       (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
+       (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
+       (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
 }
 
-
 void xor_32(unsigned char *a, unsigned char *b, unsigned char *out)
 {
-unsigned long *dwPtrA = (unsigned long *) a;
-unsigned long *dwPtrB = (unsigned long *) b;
-unsigned long *dwPtrOut =(unsigned long *) out;
+       unsigned long *dwPtrA = (unsigned long *)a;
+       unsigned long *dwPtrB = (unsigned long *)b;
+       unsigned long *dwPtrOut = (unsigned long *)out;
 
-    (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
+       (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
 }
 
 void AddRoundKey(unsigned char *key, int round)
 {
-unsigned char sbox_key[4];
-unsigned char rcon_table[10] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36};
+       unsigned char sbox_key[4];
+       unsigned char rcon_table[10] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36};
 
-    sbox_key[0] = sbox_table[key[13]];
-    sbox_key[1] = sbox_table[key[14]];
-    sbox_key[2] = sbox_table[key[15]];
-    sbox_key[3] = sbox_table[key[12]];
+       sbox_key[0] = sbox_table[key[13]];
+       sbox_key[1] = sbox_table[key[14]];
+       sbox_key[2] = sbox_table[key[15]];
+       sbox_key[3] = sbox_table[key[12]];
 
-    key[0] = key[0] ^ rcon_table[round];
-    xor_32(&key[0], sbox_key, &key[0]);
+       key[0] = key[0] ^ rcon_table[round];
+       xor_32(&key[0], sbox_key, &key[0]);
 
-    xor_32(&key[4], &key[0], &key[4]);
-    xor_32(&key[8], &key[4], &key[8]);
-    xor_32(&key[12], &key[8], &key[12]);
+       xor_32(&key[4], &key[0], &key[4]);
+       xor_32(&key[8], &key[4], &key[8]);
+       xor_32(&key[12], &key[8], &key[12]);
 }
 
 void SubBytes(unsigned char *in, unsigned char *out)
 {
-int i;
+       int i;
 
-    for (i=0; i< 16; i++)
-    {
-        out[i] = sbox_table[in[i]];
-    }
+       for (i = 0; i < 16; i++) {
+               out[i] = sbox_table[in[i]];
+       }
 }
 
 void ShiftRows(unsigned char *in, unsigned char *out)
 {
-    out[0]  = in[0];
-    out[1]  = in[5];
-    out[2]  = in[10];
-    out[3]  = in[15];
-    out[4]  = in[4];
-    out[5]  = in[9];
-    out[6]  = in[14];
-    out[7]  = in[3];
-    out[8]  = in[8];
-    out[9]  = in[13];
-    out[10] = in[2];
-    out[11] = in[7];
-    out[12] = in[12];
-    out[13] = in[1];
-    out[14] = in[6];
-    out[15] = in[11];
+       out[0]  = in[0];
+       out[1]  = in[5];
+       out[2]  = in[10];
+       out[3]  = in[15];
+       out[4]  = in[4];
+       out[5]  = in[9];
+       out[6]  = in[14];
+       out[7]  = in[3];
+       out[8]  = in[8];
+       out[9]  = in[13];
+       out[10] = in[2];
+       out[11] = in[7];
+       out[12] = in[12];
+       out[13] = in[1];
+       out[14] = in[6];
+       out[15] = in[11];
 }
 
 void MixColumns(unsigned char *in, unsigned char *out)
 {
-
-    out[0] = dot2_table[in[0]] ^ dot3_table[in[1]] ^ in[2] ^ in[3];
-    out[1] = in[0] ^ dot2_table[in[1]] ^ dot3_table[in[2]] ^ in[3];
-    out[2] = in[0] ^ in[1] ^ dot2_table[in[2]] ^ dot3_table[in[3]];
-    out[3] = dot3_table[in[0]] ^ in[1] ^ in[2] ^ dot2_table[in[3]];
+       out[0] = dot2_table[in[0]] ^ dot3_table[in[1]] ^ in[2] ^ in[3];
+       out[1] = in[0] ^ dot2_table[in[1]] ^ dot3_table[in[2]] ^ in[3];
+       out[2] = in[0] ^ in[1] ^ dot2_table[in[2]] ^ dot3_table[in[3]];
+       out[3] = dot3_table[in[0]] ^ in[1] ^ in[2] ^ dot2_table[in[3]];
 }
 
-
 void AESv128(unsigned char *key, unsigned char *data, unsigned char *ciphertext)
 {
-int  i;
-int  round;
-unsigned char TmpdataA[16];
-unsigned char TmpdataB[16];
-unsigned char abyRoundKey[16];
-
-    for(i=0; i<16; i++)
-        abyRoundKey[i] = key[i];
-
-    for (round = 0; round < 11; round++)
-    {
-        if (round == 0)
-        {
-            xor_128(abyRoundKey, data, ciphertext);
-            AddRoundKey(abyRoundKey, round);
-        }
-        else if (round == 10)
-        {
-            SubBytes(ciphertext, TmpdataA);
-            ShiftRows(TmpdataA, TmpdataB);
-            xor_128(TmpdataB, abyRoundKey, ciphertext);
-        }
-        else // round 1 ~ 9
-        {
-            SubBytes(ciphertext, TmpdataA);
-            ShiftRows(TmpdataA, TmpdataB);
-            MixColumns(&TmpdataB[0], &TmpdataA[0]);
-            MixColumns(&TmpdataB[4], &TmpdataA[4]);
-            MixColumns(&TmpdataB[8], &TmpdataA[8]);
-            MixColumns(&TmpdataB[12], &TmpdataA[12]);
-            xor_128(TmpdataA, abyRoundKey, ciphertext);
-            AddRoundKey(abyRoundKey, round);
-        }
-    }
-
+       int  i;
+       int  round;
+       unsigned char TmpdataA[16];
+       unsigned char TmpdataB[16];
+       unsigned char abyRoundKey[16];
+
+       for (i = 0; i < 16; i++)
+               abyRoundKey[i] = key[i];
+
+       for (round = 0; round < 11; round++) {
+               if (round == 0) {
+                       xor_128(abyRoundKey, data, ciphertext);
+                       AddRoundKey(abyRoundKey, round);
+               } else if (round == 10) {
+                       SubBytes(ciphertext, TmpdataA);
+                       ShiftRows(TmpdataA, TmpdataB);
+                       xor_128(TmpdataB, abyRoundKey, ciphertext);
+               } else // round 1 ~ 9
+               {
+                       SubBytes(ciphertext, TmpdataA);
+                       ShiftRows(TmpdataA, TmpdataB);
+                       MixColumns(&TmpdataB[0], &TmpdataA[0]);
+                       MixColumns(&TmpdataB[4], &TmpdataA[4]);
+                       MixColumns(&TmpdataB[8], &TmpdataA[8]);
+                       MixColumns(&TmpdataB[12], &TmpdataA[12]);
+                       xor_128(TmpdataA, abyRoundKey, ciphertext);
+                       AddRoundKey(abyRoundKey, round);
+               }
+       }
 }
 
 /*
@@ -245,158 +235,155 @@ unsigned char abyRoundKey[16];
  */
 bool AESbGenCCMP(unsigned char *pbyRxKey, unsigned char *pbyFrame, unsigned short wFrameSize)
 {
-unsigned char abyNonce[13];
-unsigned char MIC_IV[16];
-unsigned char MIC_HDR1[16];
-unsigned char MIC_HDR2[16];
-unsigned char abyMIC[16];
-unsigned char abyCTRPLD[16];
-unsigned char abyTmp[16];
-unsigned char abyPlainText[16];
-unsigned char abyLastCipher[16];
-
-PS802_11Header  pMACHeader = (PS802_11Header) pbyFrame;
-unsigned char *pbyIV;
-unsigned char *pbyPayload;
-unsigned short wHLen = 22;
-unsigned short wPayloadSize = wFrameSize - 8 - 8 - 4 - WLAN_HDR_ADDR3_LEN;//8 is IV, 8 is MIC, 4 is CRC
-bool bA4 = false;
-unsigned char byTmp;
-unsigned short wCnt;
-int             ii,jj,kk;
-
-
-    pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
-    if ( WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame) &&
-         WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame) ) {
-         bA4 = true;
-         pbyIV += 6;             // 6 is 802.11 address4
-         wHLen += 6;
-         wPayloadSize -= 6;
-    }
-    pbyPayload = pbyIV + 8; //IV-length
-
-    abyNonce[0]  = 0x00; //now is 0, if Qos here will be priority
-    memcpy(&(abyNonce[1]), pMACHeader->abyAddr2, ETH_ALEN);
-    abyNonce[7]  = pbyIV[7];
-    abyNonce[8]  = pbyIV[6];
-    abyNonce[9]  = pbyIV[5];
-    abyNonce[10] = pbyIV[4];
-    abyNonce[11] = pbyIV[1];
-    abyNonce[12] = pbyIV[0];
-
-    //MIC_IV
-    MIC_IV[0] = 0x59;
-    memcpy(&(MIC_IV[1]), &(abyNonce[0]), 13);
-    MIC_IV[14] = (unsigned char)(wPayloadSize >> 8);
-    MIC_IV[15] = (unsigned char)(wPayloadSize & 0xff);
-
-    //MIC_HDR1
-    MIC_HDR1[0] = (unsigned char)(wHLen >> 8);
-    MIC_HDR1[1] = (unsigned char)(wHLen & 0xff);
-    byTmp = (unsigned char)(pMACHeader->wFrameCtl & 0xff);
-    MIC_HDR1[2] = byTmp & 0x8f;
-    byTmp = (unsigned char)(pMACHeader->wFrameCtl >> 8);
-    byTmp &= 0x87;
-    MIC_HDR1[3] = byTmp | 0x40;
-    memcpy(&(MIC_HDR1[4]), pMACHeader->abyAddr1, ETH_ALEN);
-    memcpy(&(MIC_HDR1[10]), pMACHeader->abyAddr2, ETH_ALEN);
-
-    //MIC_HDR2
-    memcpy(&(MIC_HDR2[0]), pMACHeader->abyAddr3, ETH_ALEN);
-    byTmp = (unsigned char)(pMACHeader->wSeqCtl & 0xff);
-    MIC_HDR2[6] = byTmp & 0x0f;
-    MIC_HDR2[7] = 0;
-    if ( bA4 ) {
-        memcpy(&(MIC_HDR2[8]), pMACHeader->abyAddr4, ETH_ALEN);
-    } else {
-        MIC_HDR2[8]  = 0x00;
-        MIC_HDR2[9]  = 0x00;
-        MIC_HDR2[10] = 0x00;
-        MIC_HDR2[11] = 0x00;
-        MIC_HDR2[12] = 0x00;
-        MIC_HDR2[13] = 0x00;
-    }
-    MIC_HDR2[14] = 0x00;
-    MIC_HDR2[15] = 0x00;
-
-    //CCMP
-    AESv128(pbyRxKey,MIC_IV,abyMIC);
-    for ( kk=0; kk<16; kk++ ) {
-        abyTmp[kk] = MIC_HDR1[kk] ^ abyMIC[kk];
-    }
-    AESv128(pbyRxKey,abyTmp,abyMIC);
-    for ( kk=0; kk<16; kk++ ) {
-        abyTmp[kk] = MIC_HDR2[kk] ^ abyMIC[kk];
-    }
-    AESv128(pbyRxKey,abyTmp,abyMIC);
-
-    wCnt = 1;
-    abyCTRPLD[0] = 0x01;
-    memcpy(&(abyCTRPLD[1]), &(abyNonce[0]), 13);
-
-    for(jj=wPayloadSize; jj>16; jj=jj-16) {
-
-        abyCTRPLD[14] = (unsigned char) (wCnt >> 8);
-        abyCTRPLD[15] = (unsigned char) (wCnt & 0xff);
-
-        AESv128(pbyRxKey,abyCTRPLD,abyTmp);
-
-        for ( kk=0; kk<16; kk++ ) {
-            abyPlainText[kk] = abyTmp[kk] ^ pbyPayload[kk];
-        }
-        for ( kk=0; kk<16; kk++ ) {
-            abyTmp[kk] = abyMIC[kk] ^ abyPlainText[kk];
-        }
-        AESv128(pbyRxKey,abyTmp,abyMIC);
-
-        memcpy(pbyPayload, abyPlainText, 16);
-        wCnt++;
-        pbyPayload += 16;
-    } //for wPayloadSize
-
-    //last payload
-    memcpy(&(abyLastCipher[0]), pbyPayload, jj);
-    for ( ii=jj; ii<16; ii++ ) {
-        abyLastCipher[ii] = 0x00;
-    }
-
-    abyCTRPLD[14] = (unsigned char) (wCnt >> 8);
-    abyCTRPLD[15] = (unsigned char) (wCnt & 0xff);
-
-    AESv128(pbyRxKey,abyCTRPLD,abyTmp);
-    for ( kk=0; kk<16; kk++ ) {
-        abyPlainText[kk] = abyTmp[kk] ^ abyLastCipher[kk];
-    }
-    memcpy(pbyPayload, abyPlainText, jj);
-    pbyPayload += jj;
-
-    //for MIC calculation
-    for ( ii=jj; ii<16; ii++ ) {
-        abyPlainText[ii] = 0x00;
-    }
-    for ( kk=0; kk<16; kk++ ) {
-        abyTmp[kk] = abyMIC[kk] ^ abyPlainText[kk];
-    }
-    AESv128(pbyRxKey,abyTmp,abyMIC);
-
-    //=>above is the calculate MIC
-    //--------------------------------------------
-
-    wCnt = 0;
-    abyCTRPLD[14] = (unsigned char) (wCnt >> 8);
-    abyCTRPLD[15] = (unsigned char) (wCnt & 0xff);
-    AESv128(pbyRxKey,abyCTRPLD,abyTmp);
-    for ( kk=0; kk<8; kk++ ) {
-        abyTmp[kk] = abyTmp[kk] ^ pbyPayload[kk];
-    }
-    //=>above is the dec-MIC from packet
-    //--------------------------------------------
-
-    if ( !memcmp(abyMIC,abyTmp,8) ) {
-        return true;
-    } else {
-        return false;
-    }
-
+       unsigned char abyNonce[13];
+       unsigned char MIC_IV[16];
+       unsigned char MIC_HDR1[16];
+       unsigned char MIC_HDR2[16];
+       unsigned char abyMIC[16];
+       unsigned char abyCTRPLD[16];
+       unsigned char abyTmp[16];
+       unsigned char abyPlainText[16];
+       unsigned char abyLastCipher[16];
+
+       PS802_11Header  pMACHeader = (PS802_11Header) pbyFrame;
+       unsigned char *pbyIV;
+       unsigned char *pbyPayload;
+       unsigned short wHLen = 22;
+       unsigned short wPayloadSize = wFrameSize - 8 - 8 - 4 - WLAN_HDR_ADDR3_LEN;//8 is IV, 8 is MIC, 4 is CRC
+       bool bA4 = false;
+       unsigned char byTmp;
+       unsigned short wCnt;
+       int ii, jj, kk;
+
+       pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
+       if (WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame) &&
+           WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame)) {
+               bA4 = true;
+               pbyIV += 6;             // 6 is 802.11 address4
+               wHLen += 6;
+               wPayloadSize -= 6;
+       }
+       pbyPayload = pbyIV + 8; //IV-length
+
+       abyNonce[0]  = 0x00; //now is 0, if Qos here will be priority
+       memcpy(&(abyNonce[1]), pMACHeader->abyAddr2, ETH_ALEN);
+       abyNonce[7]  = pbyIV[7];
+       abyNonce[8]  = pbyIV[6];
+       abyNonce[9]  = pbyIV[5];
+       abyNonce[10] = pbyIV[4];
+       abyNonce[11] = pbyIV[1];
+       abyNonce[12] = pbyIV[0];
+
+       //MIC_IV
+       MIC_IV[0] = 0x59;
+       memcpy(&(MIC_IV[1]), &(abyNonce[0]), 13);
+       MIC_IV[14] = (unsigned char)(wPayloadSize >> 8);
+       MIC_IV[15] = (unsigned char)(wPayloadSize & 0xff);
+
+       //MIC_HDR1
+       MIC_HDR1[0] = (unsigned char)(wHLen >> 8);
+       MIC_HDR1[1] = (unsigned char)(wHLen & 0xff);
+       byTmp = (unsigned char)(pMACHeader->wFrameCtl & 0xff);
+       MIC_HDR1[2] = byTmp & 0x8f;
+       byTmp = (unsigned char)(pMACHeader->wFrameCtl >> 8);
+       byTmp &= 0x87;
+       MIC_HDR1[3] = byTmp | 0x40;
+       memcpy(&(MIC_HDR1[4]), pMACHeader->abyAddr1, ETH_ALEN);
+       memcpy(&(MIC_HDR1[10]), pMACHeader->abyAddr2, ETH_ALEN);
+
+       //MIC_HDR2
+       memcpy(&(MIC_HDR2[0]), pMACHeader->abyAddr3, ETH_ALEN);
+       byTmp = (unsigned char)(pMACHeader->wSeqCtl & 0xff);
+       MIC_HDR2[6] = byTmp & 0x0f;
+       MIC_HDR2[7] = 0;
+       if (bA4) {
+               memcpy(&(MIC_HDR2[8]), pMACHeader->abyAddr4, ETH_ALEN);
+       } else {
+               MIC_HDR2[8]  = 0x00;
+               MIC_HDR2[9]  = 0x00;
+               MIC_HDR2[10] = 0x00;
+               MIC_HDR2[11] = 0x00;
+               MIC_HDR2[12] = 0x00;
+               MIC_HDR2[13] = 0x00;
+       }
+       MIC_HDR2[14] = 0x00;
+       MIC_HDR2[15] = 0x00;
+
+       //CCMP
+       AESv128(pbyRxKey, MIC_IV, abyMIC);
+       for (kk = 0; kk < 16; kk++) {
+               abyTmp[kk] = MIC_HDR1[kk] ^ abyMIC[kk];
+       }
+       AESv128(pbyRxKey, abyTmp, abyMIC);
+       for (kk = 0; kk < 16; kk++) {
+               abyTmp[kk] = MIC_HDR2[kk] ^ abyMIC[kk];
+       }
+       AESv128(pbyRxKey, abyTmp, abyMIC);
+
+       wCnt = 1;
+       abyCTRPLD[0] = 0x01;
+       memcpy(&(abyCTRPLD[1]), &(abyNonce[0]), 13);
+
+       for (jj = wPayloadSize; jj > 16; jj = jj - 16) {
+               abyCTRPLD[14] = (unsigned char)(wCnt >> 8);
+               abyCTRPLD[15] = (unsigned char)(wCnt & 0xff);
+
+               AESv128(pbyRxKey, abyCTRPLD, abyTmp);
+
+               for (kk = 0; kk < 16; kk++) {
+                       abyPlainText[kk] = abyTmp[kk] ^ pbyPayload[kk];
+               }
+               for (kk = 0; kk < 16; kk++) {
+                       abyTmp[kk] = abyMIC[kk] ^ abyPlainText[kk];
+               }
+               AESv128(pbyRxKey, abyTmp, abyMIC);
+
+               memcpy(pbyPayload, abyPlainText, 16);
+               wCnt++;
+               pbyPayload += 16;
+       } //for wPayloadSize
+
+       //last payload
+       memcpy(&(abyLastCipher[0]), pbyPayload, jj);
+       for (ii = jj; ii < 16; ii++) {
+               abyLastCipher[ii] = 0x00;
+       }
+
+       abyCTRPLD[14] = (unsigned char)(wCnt >> 8);
+       abyCTRPLD[15] = (unsigned char)(wCnt & 0xff);
+
+       AESv128(pbyRxKey, abyCTRPLD, abyTmp);
+       for (kk = 0; kk < 16; kk++) {
+               abyPlainText[kk] = abyTmp[kk] ^ abyLastCipher[kk];
+       }
+       memcpy(pbyPayload, abyPlainText, jj);
+       pbyPayload += jj;
+
+       //for MIC calculation
+       for (ii = jj; ii < 16; ii++) {
+               abyPlainText[ii] = 0x00;
+       }
+       for (kk = 0; kk < 16; kk++) {
+               abyTmp[kk] = abyMIC[kk] ^ abyPlainText[kk];
+       }
+       AESv128(pbyRxKey, abyTmp, abyMIC);
+
+       //=>above is the calculate MIC
+       //--------------------------------------------
+
+       wCnt = 0;
+       abyCTRPLD[14] = (unsigned char)(wCnt >> 8);
+       abyCTRPLD[15] = (unsigned char)(wCnt & 0xff);
+       AESv128(pbyRxKey, abyCTRPLD, abyTmp);
+       for (kk = 0; kk < 8; kk++) {
+               abyTmp[kk] = abyTmp[kk] ^ pbyPayload[kk];
+       }
+       //=>above is the dec-MIC from packet
+       //--------------------------------------------
+
+       if (!memcmp(abyMIC, abyTmp, 8)) {
+               return true;
+       } else {
+               return false;
+       }
 }
index 8d2c6a789ab25fe9c2ca28a80e46a8c2791c206c..c26418d806fb335851bb7a688ad1294094cc8a6d 100644 (file)
@@ -58,7 +58,7 @@
 
 /*---------------------  Static Definitions -------------------------*/
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 
 /*---------------------  Static Classes  ----------------------------*/
 
@@ -74,1646 +74,1641 @@ static int          msglevel                =MSG_LEVEL_INFO;
 
 /*---------------------  Static Variables  --------------------------*/
 
-
-
 #define CB_VT3253_INIT_FOR_RFMD 446
 unsigned char byVT3253InitTab_RFMD[CB_VT3253_INIT_FOR_RFMD][2] = {
-    {0x00, 0x30},
-    {0x01, 0x00},
-    {0x02, 0x00},
-    {0x03, 0x00},
-    {0x04, 0x00},
-    {0x05, 0x00},
-    {0x06, 0x00},
-    {0x07, 0x00},
-    {0x08, 0x70},
-    {0x09, 0x45},
-    {0x0a, 0x2a},
-    {0x0b, 0x76},
-    {0x0c, 0x00},
-    {0x0d, 0x01},
-    {0x0e, 0x80},
-    {0x0f, 0x00},
-    {0x10, 0x00},
-    {0x11, 0x00},
-    {0x12, 0x00},
-    {0x13, 0x00},
-    {0x14, 0x00},
-    {0x15, 0x00},
-    {0x16, 0x00},
-    {0x17, 0x00},
-    {0x18, 0x00},
-    {0x19, 0x00},
-    {0x1a, 0x00},
-    {0x1b, 0x9d},
-    {0x1c, 0x05},
-    {0x1d, 0x00},
-    {0x1e, 0x00},
-    {0x1f, 0x00},
-    {0x20, 0x00},
-    {0x21, 0x00},
-    {0x22, 0x00},
-    {0x23, 0x00},
-    {0x24, 0x00},
-    {0x25, 0x4a},
-    {0x26, 0x00},
-    {0x27, 0x00},
-    {0x28, 0x00},
-    {0x29, 0x00},
-    {0x2a, 0x00},
-    {0x2b, 0x00},
-    {0x2c, 0x00},
-    {0x2d, 0xa8},
-    {0x2e, 0x1a},
-    {0x2f, 0x0c},
-    {0x30, 0x26},
-    {0x31, 0x5b},
-    {0x32, 0x00},
-    {0x33, 0x00},
-    {0x34, 0x00},
-    {0x35, 0x00},
-    {0x36, 0xaa},
-    {0x37, 0xaa},
-    {0x38, 0xff},
-    {0x39, 0xff},
-    {0x3a, 0x00},
-    {0x3b, 0x00},
-    {0x3c, 0x00},
-    {0x3d, 0x0d},
-    {0x3e, 0x51},
-    {0x3f, 0x04},
-    {0x40, 0x00},
-    {0x41, 0x08},
-    {0x42, 0x00},
-    {0x43, 0x08},
-    {0x44, 0x06},
-    {0x45, 0x14},
-    {0x46, 0x05},
-    {0x47, 0x08},
-    {0x48, 0x00},
-    {0x49, 0x00},
-    {0x4a, 0x00},
-    {0x4b, 0x00},
-    {0x4c, 0x09},
-    {0x4d, 0x80},
-    {0x4e, 0x00},
-    {0x4f, 0xc5},
-    {0x50, 0x14},
-    {0x51, 0x19},
-    {0x52, 0x00},
-    {0x53, 0x00},
-    {0x54, 0x00},
-    {0x55, 0x00},
-    {0x56, 0x00},
-    {0x57, 0x00},
-    {0x58, 0x00},
-    {0x59, 0xb0},
-    {0x5a, 0x00},
-    {0x5b, 0x00},
-    {0x5c, 0x00},
-    {0x5d, 0x00},
-    {0x5e, 0x00},
-    {0x5f, 0x00},
-    {0x60, 0x44},
-    {0x61, 0x04},
-    {0x62, 0x00},
-    {0x63, 0x00},
-    {0x64, 0x00},
-    {0x65, 0x00},
-    {0x66, 0x04},
-    {0x67, 0xb7},
-    {0x68, 0x00},
-    {0x69, 0x00},
-    {0x6a, 0x00},
-    {0x6b, 0x00},
-    {0x6c, 0x00},
-    {0x6d, 0x03},
-    {0x6e, 0x01},
-    {0x6f, 0x00},
-    {0x70, 0x00},
-    {0x71, 0x00},
-    {0x72, 0x00},
-    {0x73, 0x00},
-    {0x74, 0x00},
-    {0x75, 0x00},
-    {0x76, 0x00},
-    {0x77, 0x00},
-    {0x78, 0x00},
-    {0x79, 0x00},
-    {0x7a, 0x00},
-    {0x7b, 0x00},
-    {0x7c, 0x00},
-    {0x7d, 0x00},
-    {0x7e, 0x00},
-    {0x7f, 0x00},
-    {0x80, 0x0b},
-    {0x81, 0x00},
-    {0x82, 0x3c},
-    {0x83, 0x00},
-    {0x84, 0x00},
-    {0x85, 0x00},
-    {0x86, 0x00},
-    {0x87, 0x00},
-    {0x88, 0x08},
-    {0x89, 0x00},
-    {0x8a, 0x08},
-    {0x8b, 0xa6},
-    {0x8c, 0x84},
-    {0x8d, 0x47},
-    {0x8e, 0xbb},
-    {0x8f, 0x02},
-    {0x90, 0x21},
-    {0x91, 0x0c},
-    {0x92, 0x04},
-    {0x93, 0x22},
-    {0x94, 0x00},
-    {0x95, 0x00},
-    {0x96, 0x00},
-    {0x97, 0xeb},
-    {0x98, 0x00},
-    {0x99, 0x00},
-    {0x9a, 0x00},
-    {0x9b, 0x00},
-    {0x9c, 0x00},
-    {0x9d, 0x00},
-    {0x9e, 0x00},
-    {0x9f, 0x00},
-    {0xa0, 0x00},
-    {0xa1, 0x00},
-    {0xa2, 0x00},
-    {0xa3, 0x00},
-    {0xa4, 0x00},
-    {0xa5, 0x00},
-    {0xa6, 0x10},
-    {0xa7, 0x04},
-    {0xa8, 0x10},
-    {0xa9, 0x00},
-    {0xaa, 0x8f},
-    {0xab, 0x00},
-    {0xac, 0x00},
-    {0xad, 0x00},
-    {0xae, 0x00},
-    {0xaf, 0x80},
-    {0xb0, 0x38},
-    {0xb1, 0x00},
-    {0xb2, 0x00},
-    {0xb3, 0x00},
-    {0xb4, 0xee},
-    {0xb5, 0xff},
-    {0xb6, 0x10},
-    {0xb7, 0x00},
-    {0xb8, 0x00},
-    {0xb9, 0x00},
-    {0xba, 0x00},
-    {0xbb, 0x03},
-    {0xbc, 0x00},
-    {0xbd, 0x00},
-    {0xbe, 0x00},
-    {0xbf, 0x00},
-    {0xc0, 0x10},
-    {0xc1, 0x10},
-    {0xc2, 0x18},
-    {0xc3, 0x20},
-    {0xc4, 0x10},
-    {0xc5, 0x00},
-    {0xc6, 0x22},
-    {0xc7, 0x14},
-    {0xc8, 0x0f},
-    {0xc9, 0x08},
-    {0xca, 0xa4},
-    {0xcb, 0xa7},
-    {0xcc, 0x3c},
-    {0xcd, 0x10},
-    {0xce, 0x20},
-    {0xcf, 0x00},
-    {0xd0, 0x00},
-    {0xd1, 0x10},
-    {0xd2, 0x00},
-    {0xd3, 0x00},
-    {0xd4, 0x10},
-    {0xd5, 0x33},
-    {0xd6, 0x70},
-    {0xd7, 0x01},
-    {0xd8, 0x00},
-    {0xd9, 0x00},
-    {0xda, 0x00},
-    {0xdb, 0x00},
-    {0xdc, 0x00},
-    {0xdd, 0x00},
-    {0xde, 0x00},
-    {0xdf, 0x00},
-    {0xe0, 0x00},
-    {0xe1, 0x00},
-    {0xe2, 0xcc},
-    {0xe3, 0x04},
-    {0xe4, 0x08},
-    {0xe5, 0x10},
-    {0xe6, 0x00},
-    {0xe7, 0x0e},
-    {0xe8, 0x88},
-    {0xe9, 0xd4},
-    {0xea, 0x05},
-    {0xeb, 0xf0},
-    {0xec, 0x79},
-    {0xed, 0x0f},
-    {0xee, 0x04},
-    {0xef, 0x04},
-    {0xf0, 0x00},
-    {0xf1, 0x00},
-    {0xf2, 0x00},
-    {0xf3, 0x00},
-    {0xf4, 0x00},
-    {0xf5, 0x00},
-    {0xf6, 0x00},
-    {0xf7, 0x00},
-    {0xf8, 0x00},
-    {0xf9, 0x00},
-    {0xF0, 0x00},
-    {0xF1, 0xF8},
-    {0xF0, 0x80},
-    {0xF0, 0x00},
-    {0xF1, 0xF4},
-    {0xF0, 0x81},
-    {0xF0, 0x01},
-    {0xF1, 0xF0},
-    {0xF0, 0x82},
-    {0xF0, 0x02},
-    {0xF1, 0xEC},
-    {0xF0, 0x83},
-    {0xF0, 0x03},
-    {0xF1, 0xE8},
-    {0xF0, 0x84},
-    {0xF0, 0x04},
-    {0xF1, 0xE4},
-    {0xF0, 0x85},
-    {0xF0, 0x05},
-    {0xF1, 0xE0},
-    {0xF0, 0x86},
-    {0xF0, 0x06},
-    {0xF1, 0xDC},
-    {0xF0, 0x87},
-    {0xF0, 0x07},
-    {0xF1, 0xD8},
-    {0xF0, 0x88},
-    {0xF0, 0x08},
-    {0xF1, 0xD4},
-    {0xF0, 0x89},
-    {0xF0, 0x09},
-    {0xF1, 0xD0},
-    {0xF0, 0x8A},
-    {0xF0, 0x0A},
-    {0xF1, 0xCC},
-    {0xF0, 0x8B},
-    {0xF0, 0x0B},
-    {0xF1, 0xC8},
-    {0xF0, 0x8C},
-    {0xF0, 0x0C},
-    {0xF1, 0xC4},
-    {0xF0, 0x8D},
-    {0xF0, 0x0D},
-    {0xF1, 0xC0},
-    {0xF0, 0x8E},
-    {0xF0, 0x0E},
-    {0xF1, 0xBC},
-    {0xF0, 0x8F},
-    {0xF0, 0x0F},
-    {0xF1, 0xB8},
-    {0xF0, 0x90},
-    {0xF0, 0x10},
-    {0xF1, 0xB4},
-    {0xF0, 0x91},
-    {0xF0, 0x11},
-    {0xF1, 0xB0},
-    {0xF0, 0x92},
-    {0xF0, 0x12},
-    {0xF1, 0xAC},
-    {0xF0, 0x93},
-    {0xF0, 0x13},
-    {0xF1, 0xA8},
-    {0xF0, 0x94},
-    {0xF0, 0x14},
-    {0xF1, 0xA4},
-    {0xF0, 0x95},
-    {0xF0, 0x15},
-    {0xF1, 0xA0},
-    {0xF0, 0x96},
-    {0xF0, 0x16},
-    {0xF1, 0x9C},
-    {0xF0, 0x97},
-    {0xF0, 0x17},
-    {0xF1, 0x98},
-    {0xF0, 0x98},
-    {0xF0, 0x18},
-    {0xF1, 0x94},
-    {0xF0, 0x99},
-    {0xF0, 0x19},
-    {0xF1, 0x90},
-    {0xF0, 0x9A},
-    {0xF0, 0x1A},
-    {0xF1, 0x8C},
-    {0xF0, 0x9B},
-    {0xF0, 0x1B},
-    {0xF1, 0x88},
-    {0xF0, 0x9C},
-    {0xF0, 0x1C},
-    {0xF1, 0x84},
-    {0xF0, 0x9D},
-    {0xF0, 0x1D},
-    {0xF1, 0x80},
-    {0xF0, 0x9E},
-    {0xF0, 0x1E},
-    {0xF1, 0x7C},
-    {0xF0, 0x9F},
-    {0xF0, 0x1F},
-    {0xF1, 0x78},
-    {0xF0, 0xA0},
-    {0xF0, 0x20},
-    {0xF1, 0x74},
-    {0xF0, 0xA1},
-    {0xF0, 0x21},
-    {0xF1, 0x70},
-    {0xF0, 0xA2},
-    {0xF0, 0x22},
-    {0xF1, 0x6C},
-    {0xF0, 0xA3},
-    {0xF0, 0x23},
-    {0xF1, 0x68},
-    {0xF0, 0xA4},
-    {0xF0, 0x24},
-    {0xF1, 0x64},
-    {0xF0, 0xA5},
-    {0xF0, 0x25},
-    {0xF1, 0x60},
-    {0xF0, 0xA6},
-    {0xF0, 0x26},
-    {0xF1, 0x5C},
-    {0xF0, 0xA7},
-    {0xF0, 0x27},
-    {0xF1, 0x58},
-    {0xF0, 0xA8},
-    {0xF0, 0x28},
-    {0xF1, 0x54},
-    {0xF0, 0xA9},
-    {0xF0, 0x29},
-    {0xF1, 0x50},
-    {0xF0, 0xAA},
-    {0xF0, 0x2A},
-    {0xF1, 0x4C},
-    {0xF0, 0xAB},
-    {0xF0, 0x2B},
-    {0xF1, 0x48},
-    {0xF0, 0xAC},
-    {0xF0, 0x2C},
-    {0xF1, 0x44},
-    {0xF0, 0xAD},
-    {0xF0, 0x2D},
-    {0xF1, 0x40},
-    {0xF0, 0xAE},
-    {0xF0, 0x2E},
-    {0xF1, 0x3C},
-    {0xF0, 0xAF},
-    {0xF0, 0x2F},
-    {0xF1, 0x38},
-    {0xF0, 0xB0},
-    {0xF0, 0x30},
-    {0xF1, 0x34},
-    {0xF0, 0xB1},
-    {0xF0, 0x31},
-    {0xF1, 0x30},
-    {0xF0, 0xB2},
-    {0xF0, 0x32},
-    {0xF1, 0x2C},
-    {0xF0, 0xB3},
-    {0xF0, 0x33},
-    {0xF1, 0x28},
-    {0xF0, 0xB4},
-    {0xF0, 0x34},
-    {0xF1, 0x24},
-    {0xF0, 0xB5},
-    {0xF0, 0x35},
-    {0xF1, 0x20},
-    {0xF0, 0xB6},
-    {0xF0, 0x36},
-    {0xF1, 0x1C},
-    {0xF0, 0xB7},
-    {0xF0, 0x37},
-    {0xF1, 0x18},
-    {0xF0, 0xB8},
-    {0xF0, 0x38},
-    {0xF1, 0x14},
-    {0xF0, 0xB9},
-    {0xF0, 0x39},
-    {0xF1, 0x10},
-    {0xF0, 0xBA},
-    {0xF0, 0x3A},
-    {0xF1, 0x0C},
-    {0xF0, 0xBB},
-    {0xF0, 0x3B},
-    {0xF1, 0x08},
-    {0xF0, 0x00},
-    {0xF0, 0x3C},
-    {0xF1, 0x04},
-    {0xF0, 0xBD},
-    {0xF0, 0x3D},
-    {0xF1, 0x00},
-    {0xF0, 0xBE},
-    {0xF0, 0x3E},
-    {0xF1, 0x00},
-    {0xF0, 0xBF},
-    {0xF0, 0x3F},
-    {0xF1, 0x00},
-    {0xF0, 0xC0},
-    {0xF0, 0x00},
+       {0x00, 0x30},
+       {0x01, 0x00},
+       {0x02, 0x00},
+       {0x03, 0x00},
+       {0x04, 0x00},
+       {0x05, 0x00},
+       {0x06, 0x00},
+       {0x07, 0x00},
+       {0x08, 0x70},
+       {0x09, 0x45},
+       {0x0a, 0x2a},
+       {0x0b, 0x76},
+       {0x0c, 0x00},
+       {0x0d, 0x01},
+       {0x0e, 0x80},
+       {0x0f, 0x00},
+       {0x10, 0x00},
+       {0x11, 0x00},
+       {0x12, 0x00},
+       {0x13, 0x00},
+       {0x14, 0x00},
+       {0x15, 0x00},
+       {0x16, 0x00},
+       {0x17, 0x00},
+       {0x18, 0x00},
+       {0x19, 0x00},
+       {0x1a, 0x00},
+       {0x1b, 0x9d},
+       {0x1c, 0x05},
+       {0x1d, 0x00},
+       {0x1e, 0x00},
+       {0x1f, 0x00},
+       {0x20, 0x00},
+       {0x21, 0x00},
+       {0x22, 0x00},
+       {0x23, 0x00},
+       {0x24, 0x00},
+       {0x25, 0x4a},
+       {0x26, 0x00},
+       {0x27, 0x00},
+       {0x28, 0x00},
+       {0x29, 0x00},
+       {0x2a, 0x00},
+       {0x2b, 0x00},
+       {0x2c, 0x00},
+       {0x2d, 0xa8},
+       {0x2e, 0x1a},
+       {0x2f, 0x0c},
+       {0x30, 0x26},
+       {0x31, 0x5b},
+       {0x32, 0x00},
+       {0x33, 0x00},
+       {0x34, 0x00},
+       {0x35, 0x00},
+       {0x36, 0xaa},
+       {0x37, 0xaa},
+       {0x38, 0xff},
+       {0x39, 0xff},
+       {0x3a, 0x00},
+       {0x3b, 0x00},
+       {0x3c, 0x00},
+       {0x3d, 0x0d},
+       {0x3e, 0x51},
+       {0x3f, 0x04},
+       {0x40, 0x00},
+       {0x41, 0x08},
+       {0x42, 0x00},
+       {0x43, 0x08},
+       {0x44, 0x06},
+       {0x45, 0x14},
+       {0x46, 0x05},
+       {0x47, 0x08},
+       {0x48, 0x00},
+       {0x49, 0x00},
+       {0x4a, 0x00},
+       {0x4b, 0x00},
+       {0x4c, 0x09},
+       {0x4d, 0x80},
+       {0x4e, 0x00},
+       {0x4f, 0xc5},
+       {0x50, 0x14},
+       {0x51, 0x19},
+       {0x52, 0x00},
+       {0x53, 0x00},
+       {0x54, 0x00},
+       {0x55, 0x00},
+       {0x56, 0x00},
+       {0x57, 0x00},
+       {0x58, 0x00},
+       {0x59, 0xb0},
+       {0x5a, 0x00},
+       {0x5b, 0x00},
+       {0x5c, 0x00},
+       {0x5d, 0x00},
+       {0x5e, 0x00},
+       {0x5f, 0x00},
+       {0x60, 0x44},
+       {0x61, 0x04},
+       {0x62, 0x00},
+       {0x63, 0x00},
+       {0x64, 0x00},
+       {0x65, 0x00},
+       {0x66, 0x04},
+       {0x67, 0xb7},
+       {0x68, 0x00},
+       {0x69, 0x00},
+       {0x6a, 0x00},
+       {0x6b, 0x00},
+       {0x6c, 0x00},
+       {0x6d, 0x03},
+       {0x6e, 0x01},
+       {0x6f, 0x00},
+       {0x70, 0x00},
+       {0x71, 0x00},
+       {0x72, 0x00},
+       {0x73, 0x00},
+       {0x74, 0x00},
+       {0x75, 0x00},
+       {0x76, 0x00},
+       {0x77, 0x00},
+       {0x78, 0x00},
+       {0x79, 0x00},
+       {0x7a, 0x00},
+       {0x7b, 0x00},
+       {0x7c, 0x00},
+       {0x7d, 0x00},
+       {0x7e, 0x00},
+       {0x7f, 0x00},
+       {0x80, 0x0b},
+       {0x81, 0x00},
+       {0x82, 0x3c},
+       {0x83, 0x00},
+       {0x84, 0x00},
+       {0x85, 0x00},
+       {0x86, 0x00},
+       {0x87, 0x00},
+       {0x88, 0x08},
+       {0x89, 0x00},
+       {0x8a, 0x08},
+       {0x8b, 0xa6},
+       {0x8c, 0x84},
+       {0x8d, 0x47},
+       {0x8e, 0xbb},
+       {0x8f, 0x02},
+       {0x90, 0x21},
+       {0x91, 0x0c},
+       {0x92, 0x04},
+       {0x93, 0x22},
+       {0x94, 0x00},
+       {0x95, 0x00},
+       {0x96, 0x00},
+       {0x97, 0xeb},
+       {0x98, 0x00},
+       {0x99, 0x00},
+       {0x9a, 0x00},
+       {0x9b, 0x00},
+       {0x9c, 0x00},
+       {0x9d, 0x00},
+       {0x9e, 0x00},
+       {0x9f, 0x00},
+       {0xa0, 0x00},
+       {0xa1, 0x00},
+       {0xa2, 0x00},
+       {0xa3, 0x00},
+       {0xa4, 0x00},
+       {0xa5, 0x00},
+       {0xa6, 0x10},
+       {0xa7, 0x04},
+       {0xa8, 0x10},
+       {0xa9, 0x00},
+       {0xaa, 0x8f},
+       {0xab, 0x00},
+       {0xac, 0x00},
+       {0xad, 0x00},
+       {0xae, 0x00},
+       {0xaf, 0x80},
+       {0xb0, 0x38},
+       {0xb1, 0x00},
+       {0xb2, 0x00},
+       {0xb3, 0x00},
+       {0xb4, 0xee},
+       {0xb5, 0xff},
+       {0xb6, 0x10},
+       {0xb7, 0x00},
+       {0xb8, 0x00},
+       {0xb9, 0x00},
+       {0xba, 0x00},
+       {0xbb, 0x03},
+       {0xbc, 0x00},
+       {0xbd, 0x00},
+       {0xbe, 0x00},
+       {0xbf, 0x00},
+       {0xc0, 0x10},
+       {0xc1, 0x10},
+       {0xc2, 0x18},
+       {0xc3, 0x20},
+       {0xc4, 0x10},
+       {0xc5, 0x00},
+       {0xc6, 0x22},
+       {0xc7, 0x14},
+       {0xc8, 0x0f},
+       {0xc9, 0x08},
+       {0xca, 0xa4},
+       {0xcb, 0xa7},
+       {0xcc, 0x3c},
+       {0xcd, 0x10},
+       {0xce, 0x20},
+       {0xcf, 0x00},
+       {0xd0, 0x00},
+       {0xd1, 0x10},
+       {0xd2, 0x00},
+       {0xd3, 0x00},
+       {0xd4, 0x10},
+       {0xd5, 0x33},
+       {0xd6, 0x70},
+       {0xd7, 0x01},
+       {0xd8, 0x00},
+       {0xd9, 0x00},
+       {0xda, 0x00},
+       {0xdb, 0x00},
+       {0xdc, 0x00},
+       {0xdd, 0x00},
+       {0xde, 0x00},
+       {0xdf, 0x00},
+       {0xe0, 0x00},
+       {0xe1, 0x00},
+       {0xe2, 0xcc},
+       {0xe3, 0x04},
+       {0xe4, 0x08},
+       {0xe5, 0x10},
+       {0xe6, 0x00},
+       {0xe7, 0x0e},
+       {0xe8, 0x88},
+       {0xe9, 0xd4},
+       {0xea, 0x05},
+       {0xeb, 0xf0},
+       {0xec, 0x79},
+       {0xed, 0x0f},
+       {0xee, 0x04},
+       {0xef, 0x04},
+       {0xf0, 0x00},
+       {0xf1, 0x00},
+       {0xf2, 0x00},
+       {0xf3, 0x00},
+       {0xf4, 0x00},
+       {0xf5, 0x00},
+       {0xf6, 0x00},
+       {0xf7, 0x00},
+       {0xf8, 0x00},
+       {0xf9, 0x00},
+       {0xF0, 0x00},
+       {0xF1, 0xF8},
+       {0xF0, 0x80},
+       {0xF0, 0x00},
+       {0xF1, 0xF4},
+       {0xF0, 0x81},
+       {0xF0, 0x01},
+       {0xF1, 0xF0},
+       {0xF0, 0x82},
+       {0xF0, 0x02},
+       {0xF1, 0xEC},
+       {0xF0, 0x83},
+       {0xF0, 0x03},
+       {0xF1, 0xE8},
+       {0xF0, 0x84},
+       {0xF0, 0x04},
+       {0xF1, 0xE4},
+       {0xF0, 0x85},
+       {0xF0, 0x05},
+       {0xF1, 0xE0},
+       {0xF0, 0x86},
+       {0xF0, 0x06},
+       {0xF1, 0xDC},
+       {0xF0, 0x87},
+       {0xF0, 0x07},
+       {0xF1, 0xD8},
+       {0xF0, 0x88},
+       {0xF0, 0x08},
+       {0xF1, 0xD4},
+       {0xF0, 0x89},
+       {0xF0, 0x09},
+       {0xF1, 0xD0},
+       {0xF0, 0x8A},
+       {0xF0, 0x0A},
+       {0xF1, 0xCC},
+       {0xF0, 0x8B},
+       {0xF0, 0x0B},
+       {0xF1, 0xC8},
+       {0xF0, 0x8C},
+       {0xF0, 0x0C},
+       {0xF1, 0xC4},
+       {0xF0, 0x8D},
+       {0xF0, 0x0D},
+       {0xF1, 0xC0},
+       {0xF0, 0x8E},
+       {0xF0, 0x0E},
+       {0xF1, 0xBC},
+       {0xF0, 0x8F},
+       {0xF0, 0x0F},
+       {0xF1, 0xB8},
+       {0xF0, 0x90},
+       {0xF0, 0x10},
+       {0xF1, 0xB4},
+       {0xF0, 0x91},
+       {0xF0, 0x11},
+       {0xF1, 0xB0},
+       {0xF0, 0x92},
+       {0xF0, 0x12},
+       {0xF1, 0xAC},
+       {0xF0, 0x93},
+       {0xF0, 0x13},
+       {0xF1, 0xA8},
+       {0xF0, 0x94},
+       {0xF0, 0x14},
+       {0xF1, 0xA4},
+       {0xF0, 0x95},
+       {0xF0, 0x15},
+       {0xF1, 0xA0},
+       {0xF0, 0x96},
+       {0xF0, 0x16},
+       {0xF1, 0x9C},
+       {0xF0, 0x97},
+       {0xF0, 0x17},
+       {0xF1, 0x98},
+       {0xF0, 0x98},
+       {0xF0, 0x18},
+       {0xF1, 0x94},
+       {0xF0, 0x99},
+       {0xF0, 0x19},
+       {0xF1, 0x90},
+       {0xF0, 0x9A},
+       {0xF0, 0x1A},
+       {0xF1, 0x8C},
+       {0xF0, 0x9B},
+       {0xF0, 0x1B},
+       {0xF1, 0x88},
+       {0xF0, 0x9C},
+       {0xF0, 0x1C},
+       {0xF1, 0x84},
+       {0xF0, 0x9D},
+       {0xF0, 0x1D},
+       {0xF1, 0x80},
+       {0xF0, 0x9E},
+       {0xF0, 0x1E},
+       {0xF1, 0x7C},
+       {0xF0, 0x9F},
+       {0xF0, 0x1F},
+       {0xF1, 0x78},
+       {0xF0, 0xA0},
+       {0xF0, 0x20},
+       {0xF1, 0x74},
+       {0xF0, 0xA1},
+       {0xF0, 0x21},
+       {0xF1, 0x70},
+       {0xF0, 0xA2},
+       {0xF0, 0x22},
+       {0xF1, 0x6C},
+       {0xF0, 0xA3},
+       {0xF0, 0x23},
+       {0xF1, 0x68},
+       {0xF0, 0xA4},
+       {0xF0, 0x24},
+       {0xF1, 0x64},
+       {0xF0, 0xA5},
+       {0xF0, 0x25},
+       {0xF1, 0x60},
+       {0xF0, 0xA6},
+       {0xF0, 0x26},
+       {0xF1, 0x5C},
+       {0xF0, 0xA7},
+       {0xF0, 0x27},
+       {0xF1, 0x58},
+       {0xF0, 0xA8},
+       {0xF0, 0x28},
+       {0xF1, 0x54},
+       {0xF0, 0xA9},
+       {0xF0, 0x29},
+       {0xF1, 0x50},
+       {0xF0, 0xAA},
+       {0xF0, 0x2A},
+       {0xF1, 0x4C},
+       {0xF0, 0xAB},
+       {0xF0, 0x2B},
+       {0xF1, 0x48},
+       {0xF0, 0xAC},
+       {0xF0, 0x2C},
+       {0xF1, 0x44},
+       {0xF0, 0xAD},
+       {0xF0, 0x2D},
+       {0xF1, 0x40},
+       {0xF0, 0xAE},
+       {0xF0, 0x2E},
+       {0xF1, 0x3C},
+       {0xF0, 0xAF},
+       {0xF0, 0x2F},
+       {0xF1, 0x38},
+       {0xF0, 0xB0},
+       {0xF0, 0x30},
+       {0xF1, 0x34},
+       {0xF0, 0xB1},
+       {0xF0, 0x31},
+       {0xF1, 0x30},
+       {0xF0, 0xB2},
+       {0xF0, 0x32},
+       {0xF1, 0x2C},
+       {0xF0, 0xB3},
+       {0xF0, 0x33},
+       {0xF1, 0x28},
+       {0xF0, 0xB4},
+       {0xF0, 0x34},
+       {0xF1, 0x24},
+       {0xF0, 0xB5},
+       {0xF0, 0x35},
+       {0xF1, 0x20},
+       {0xF0, 0xB6},
+       {0xF0, 0x36},
+       {0xF1, 0x1C},
+       {0xF0, 0xB7},
+       {0xF0, 0x37},
+       {0xF1, 0x18},
+       {0xF0, 0xB8},
+       {0xF0, 0x38},
+       {0xF1, 0x14},
+       {0xF0, 0xB9},
+       {0xF0, 0x39},
+       {0xF1, 0x10},
+       {0xF0, 0xBA},
+       {0xF0, 0x3A},
+       {0xF1, 0x0C},
+       {0xF0, 0xBB},
+       {0xF0, 0x3B},
+       {0xF1, 0x08},
+       {0xF0, 0x00},
+       {0xF0, 0x3C},
+       {0xF1, 0x04},
+       {0xF0, 0xBD},
+       {0xF0, 0x3D},
+       {0xF1, 0x00},
+       {0xF0, 0xBE},
+       {0xF0, 0x3E},
+       {0xF1, 0x00},
+       {0xF0, 0xBF},
+       {0xF0, 0x3F},
+       {0xF1, 0x00},
+       {0xF0, 0xC0},
+       {0xF0, 0x00},
 };
 
 #define CB_VT3253B0_INIT_FOR_RFMD 256
 unsigned char byVT3253B0_RFMD[CB_VT3253B0_INIT_FOR_RFMD][2] = {
-    {0x00, 0x31},
-    {0x01, 0x00},
-    {0x02, 0x00},
-    {0x03, 0x00},
-    {0x04, 0x00},
-    {0x05, 0x81},
-    {0x06, 0x00},
-    {0x07, 0x00},
-    {0x08, 0x38},
-    {0x09, 0x45},
-    {0x0a, 0x2a},
-    {0x0b, 0x76},
-    {0x0c, 0x00},
-    {0x0d, 0x00},
-    {0x0e, 0x80},
-    {0x0f, 0x00},
-    {0x10, 0x00},
-    {0x11, 0x00},
-    {0x12, 0x00},
-    {0x13, 0x00},
-    {0x14, 0x00},
-    {0x15, 0x00},
-    {0x16, 0x00},
-    {0x17, 0x00},
-    {0x18, 0x00},
-    {0x19, 0x00},
-    {0x1a, 0x00},
-    {0x1b, 0x8e},
-    {0x1c, 0x06},
-    {0x1d, 0x00},
-    {0x1e, 0x00},
-    {0x1f, 0x00},
-    {0x20, 0x00},
-    {0x21, 0x00},
-    {0x22, 0x00},
-    {0x23, 0x00},
-    {0x24, 0x00},
-    {0x25, 0x4a},
-    {0x26, 0x00},
-    {0x27, 0x00},
-    {0x28, 0x00},
-    {0x29, 0x00},
-    {0x2a, 0x00},
-    {0x2b, 0x00},
-    {0x2c, 0x00},
-    {0x2d, 0x34},
-    {0x2e, 0x18},
-    {0x2f, 0x0c},
-    {0x30, 0x26},
-    {0x31, 0x5b},
-    {0x32, 0x00},
-    {0x33, 0x00},
-    {0x34, 0x00},
-    {0x35, 0x00},
-    {0x36, 0xaa},
-    {0x37, 0xaa},
-    {0x38, 0xff},
-    {0x39, 0xff},
-    {0x3a, 0xf8},
-    {0x3b, 0x00},
-    {0x3c, 0x00},
-    {0x3d, 0x09},
-    {0x3e, 0x0d},
-    {0x3f, 0x04},
-    {0x40, 0x00},
-    {0x41, 0x08},
-    {0x42, 0x00},
-    {0x43, 0x08},
-    {0x44, 0x08},
-    {0x45, 0x14},
-    {0x46, 0x05},
-    {0x47, 0x08},
-    {0x48, 0x00},
-    {0x49, 0x00},
-    {0x4a, 0x00},
-    {0x4b, 0x00},
-    {0x4c, 0x09},
-    {0x4d, 0x80},
-    {0x4e, 0x00},
-    {0x4f, 0xc5},
-    {0x50, 0x14},
-    {0x51, 0x19},
-    {0x52, 0x00},
-    {0x53, 0x00},
-    {0x54, 0x00},
-    {0x55, 0x00},
-    {0x56, 0x00},
-    {0x57, 0x00},
-    {0x58, 0x00},
-    {0x59, 0xb0},
-    {0x5a, 0x00},
-    {0x5b, 0x00},
-    {0x5c, 0x00},
-    {0x5d, 0x00},
-    {0x5e, 0x00},
-    {0x5f, 0x00},
-    {0x60, 0x39},
-    {0x61, 0x83},
-    {0x62, 0x00},
-    {0x63, 0x00},
-    {0x64, 0x00},
-    {0x65, 0x00},
-    {0x66, 0xc0},
-    {0x67, 0x49},
-    {0x68, 0x00},
-    {0x69, 0x00},
-    {0x6a, 0x00},
-    {0x6b, 0x00},
-    {0x6c, 0x00},
-    {0x6d, 0x03},
-    {0x6e, 0x01},
-    {0x6f, 0x00},
-    {0x70, 0x00},
-    {0x71, 0x00},
-    {0x72, 0x00},
-    {0x73, 0x00},
-    {0x74, 0x00},
-    {0x75, 0x00},
-    {0x76, 0x00},
-    {0x77, 0x00},
-    {0x78, 0x00},
-    {0x79, 0x00},
-    {0x7a, 0x00},
-    {0x7b, 0x00},
-    {0x7c, 0x00},
-    {0x7d, 0x00},
-    {0x7e, 0x00},
-    {0x7f, 0x00},
-    {0x80, 0x89},
-    {0x81, 0x00},
-    {0x82, 0x0e},
-    {0x83, 0x00},
-    {0x84, 0x00},
-    {0x85, 0x00},
-    {0x86, 0x00},
-    {0x87, 0x00},
-    {0x88, 0x08},
-    {0x89, 0x00},
-    {0x8a, 0x0e},
-    {0x8b, 0xa7},
-    {0x8c, 0x88},
-    {0x8d, 0x47},
-    {0x8e, 0xaa},
-    {0x8f, 0x02},
-    {0x90, 0x23},
-    {0x91, 0x0c},
-    {0x92, 0x06},
-    {0x93, 0x08},
-    {0x94, 0x00},
-    {0x95, 0x00},
-    {0x96, 0x00},
-    {0x97, 0xeb},
-    {0x98, 0x00},
-    {0x99, 0x00},
-    {0x9a, 0x00},
-    {0x9b, 0x00},
-    {0x9c, 0x00},
-    {0x9d, 0x00},
-    {0x9e, 0x00},
-    {0x9f, 0x00},
-    {0xa0, 0x00},
-    {0xa1, 0x00},
-    {0xa2, 0x00},
-    {0xa3, 0xcd},
-    {0xa4, 0x07},
-    {0xa5, 0x33},
-    {0xa6, 0x18},
-    {0xa7, 0x00},
-    {0xa8, 0x18},
-    {0xa9, 0x00},
-    {0xaa, 0x28},
-    {0xab, 0x00},
-    {0xac, 0x00},
-    {0xad, 0x00},
-    {0xae, 0x00},
-    {0xaf, 0x18},
-    {0xb0, 0x38},
-    {0xb1, 0x30},
-    {0xb2, 0x00},
-    {0xb3, 0x00},
-    {0xb4, 0x00},
-    {0xb5, 0x00},
-    {0xb6, 0x84},
-    {0xb7, 0xfd},
-    {0xb8, 0x00},
-    {0xb9, 0x00},
-    {0xba, 0x00},
-    {0xbb, 0x03},
-    {0xbc, 0x00},
-    {0xbd, 0x00},
-    {0xbe, 0x00},
-    {0xbf, 0x00},
-    {0xc0, 0x10},
-    {0xc1, 0x20},
-    {0xc2, 0x18},
-    {0xc3, 0x20},
-    {0xc4, 0x10},
-    {0xc5, 0x2c},
-    {0xc6, 0x1e},
-    {0xc7, 0x10},
-    {0xc8, 0x12},
-    {0xc9, 0x01},
-    {0xca, 0x6f},
-    {0xcb, 0xa7},
-    {0xcc, 0x3c},
-    {0xcd, 0x10},
-    {0xce, 0x00},
-    {0xcf, 0x22},
-    {0xd0, 0x00},
-    {0xd1, 0x10},
-    {0xd2, 0x00},
-    {0xd3, 0x00},
-    {0xd4, 0x10},
-    {0xd5, 0x33},
-    {0xd6, 0x80},
-    {0xd7, 0x21},
-    {0xd8, 0x00},
-    {0xd9, 0x00},
-    {0xda, 0x00},
-    {0xdb, 0x00},
-    {0xdc, 0x00},
-    {0xdd, 0x00},
-    {0xde, 0x00},
-    {0xdf, 0x00},
-    {0xe0, 0x00},
-    {0xe1, 0xB3},
-    {0xe2, 0x00},
-    {0xe3, 0x00},
-    {0xe4, 0x00},
-    {0xe5, 0x10},
-    {0xe6, 0x00},
-    {0xe7, 0x18},
-    {0xe8, 0x08},
-    {0xe9, 0xd4},
-    {0xea, 0x00},
-    {0xeb, 0xff},
-    {0xec, 0x79},
-    {0xed, 0x10},
-    {0xee, 0x30},
-    {0xef, 0x02},
-    {0xf0, 0x00},
-    {0xf1, 0x09},
-    {0xf2, 0x00},
-    {0xf3, 0x00},
-    {0xf4, 0x00},
-    {0xf5, 0x00},
-    {0xf6, 0x00},
-    {0xf7, 0x00},
-    {0xf8, 0x00},
-    {0xf9, 0x00},
-    {0xfa, 0x00},
-    {0xfb, 0x00},
-    {0xfc, 0x00},
-    {0xfd, 0x00},
-    {0xfe, 0x00},
-    {0xff, 0x00},
+       {0x00, 0x31},
+       {0x01, 0x00},
+       {0x02, 0x00},
+       {0x03, 0x00},
+       {0x04, 0x00},
+       {0x05, 0x81},
+       {0x06, 0x00},
+       {0x07, 0x00},
+       {0x08, 0x38},
+       {0x09, 0x45},
+       {0x0a, 0x2a},
+       {0x0b, 0x76},
+       {0x0c, 0x00},
+       {0x0d, 0x00},
+       {0x0e, 0x80},
+       {0x0f, 0x00},
+       {0x10, 0x00},
+       {0x11, 0x00},
+       {0x12, 0x00},
+       {0x13, 0x00},
+       {0x14, 0x00},
+       {0x15, 0x00},
+       {0x16, 0x00},
+       {0x17, 0x00},
+       {0x18, 0x00},
+       {0x19, 0x00},
+       {0x1a, 0x00},
+       {0x1b, 0x8e},
+       {0x1c, 0x06},
+       {0x1d, 0x00},
+       {0x1e, 0x00},
+       {0x1f, 0x00},
+       {0x20, 0x00},
+       {0x21, 0x00},
+       {0x22, 0x00},
+       {0x23, 0x00},
+       {0x24, 0x00},
+       {0x25, 0x4a},
+       {0x26, 0x00},
+       {0x27, 0x00},
+       {0x28, 0x00},
+       {0x29, 0x00},
+       {0x2a, 0x00},
+       {0x2b, 0x00},
+       {0x2c, 0x00},
+       {0x2d, 0x34},
+       {0x2e, 0x18},
+       {0x2f, 0x0c},
+       {0x30, 0x26},
+       {0x31, 0x5b},
+       {0x32, 0x00},
+       {0x33, 0x00},
+       {0x34, 0x00},
+       {0x35, 0x00},
+       {0x36, 0xaa},
+       {0x37, 0xaa},
+       {0x38, 0xff},
+       {0x39, 0xff},
+       {0x3a, 0xf8},
+       {0x3b, 0x00},
+       {0x3c, 0x00},
+       {0x3d, 0x09},
+       {0x3e, 0x0d},
+       {0x3f, 0x04},
+       {0x40, 0x00},
+       {0x41, 0x08},
+       {0x42, 0x00},
+       {0x43, 0x08},
+       {0x44, 0x08},
+       {0x45, 0x14},
+       {0x46, 0x05},
+       {0x47, 0x08},
+       {0x48, 0x00},
+       {0x49, 0x00},
+       {0x4a, 0x00},
+       {0x4b, 0x00},
+       {0x4c, 0x09},
+       {0x4d, 0x80},
+       {0x4e, 0x00},
+       {0x4f, 0xc5},
+       {0x50, 0x14},
+       {0x51, 0x19},
+       {0x52, 0x00},
+       {0x53, 0x00},
+       {0x54, 0x00},
+       {0x55, 0x00},
+       {0x56, 0x00},
+       {0x57, 0x00},
+       {0x58, 0x00},
+       {0x59, 0xb0},
+       {0x5a, 0x00},
+       {0x5b, 0x00},
+       {0x5c, 0x00},
+       {0x5d, 0x00},
+       {0x5e, 0x00},
+       {0x5f, 0x00},
+       {0x60, 0x39},
+       {0x61, 0x83},
+       {0x62, 0x00},
+       {0x63, 0x00},
+       {0x64, 0x00},
+       {0x65, 0x00},
+       {0x66, 0xc0},
+       {0x67, 0x49},
+       {0x68, 0x00},
+       {0x69, 0x00},
+       {0x6a, 0x00},
+       {0x6b, 0x00},
+       {0x6c, 0x00},
+       {0x6d, 0x03},
+       {0x6e, 0x01},
+       {0x6f, 0x00},
+       {0x70, 0x00},
+       {0x71, 0x00},
+       {0x72, 0x00},
+       {0x73, 0x00},
+       {0x74, 0x00},
+       {0x75, 0x00},
+       {0x76, 0x00},
+       {0x77, 0x00},
+       {0x78, 0x00},
+       {0x79, 0x00},
+       {0x7a, 0x00},
+       {0x7b, 0x00},
+       {0x7c, 0x00},
+       {0x7d, 0x00},
+       {0x7e, 0x00},
+       {0x7f, 0x00},
+       {0x80, 0x89},
+       {0x81, 0x00},
+       {0x82, 0x0e},
+       {0x83, 0x00},
+       {0x84, 0x00},
+       {0x85, 0x00},
+       {0x86, 0x00},
+       {0x87, 0x00},
+       {0x88, 0x08},
+       {0x89, 0x00},
+       {0x8a, 0x0e},
+       {0x8b, 0xa7},
+       {0x8c, 0x88},
+       {0x8d, 0x47},
+       {0x8e, 0xaa},
+       {0x8f, 0x02},
+       {0x90, 0x23},
+       {0x91, 0x0c},
+       {0x92, 0x06},
+       {0x93, 0x08},
+       {0x94, 0x00},
+       {0x95, 0x00},
+       {0x96, 0x00},
+       {0x97, 0xeb},
+       {0x98, 0x00},
+       {0x99, 0x00},
+       {0x9a, 0x00},
+       {0x9b, 0x00},
+       {0x9c, 0x00},
+       {0x9d, 0x00},
+       {0x9e, 0x00},
+       {0x9f, 0x00},
+       {0xa0, 0x00},
+       {0xa1, 0x00},
+       {0xa2, 0x00},
+       {0xa3, 0xcd},
+       {0xa4, 0x07},
+       {0xa5, 0x33},
+       {0xa6, 0x18},
+       {0xa7, 0x00},
+       {0xa8, 0x18},
+       {0xa9, 0x00},
+       {0xaa, 0x28},
+       {0xab, 0x00},
+       {0xac, 0x00},
+       {0xad, 0x00},
+       {0xae, 0x00},
+       {0xaf, 0x18},
+       {0xb0, 0x38},
+       {0xb1, 0x30},
+       {0xb2, 0x00},
+       {0xb3, 0x00},
+       {0xb4, 0x00},
+       {0xb5, 0x00},
+       {0xb6, 0x84},
+       {0xb7, 0xfd},
+       {0xb8, 0x00},
+       {0xb9, 0x00},
+       {0xba, 0x00},
+       {0xbb, 0x03},
+       {0xbc, 0x00},
+       {0xbd, 0x00},
+       {0xbe, 0x00},
+       {0xbf, 0x00},
+       {0xc0, 0x10},
+       {0xc1, 0x20},
+       {0xc2, 0x18},
+       {0xc3, 0x20},
+       {0xc4, 0x10},
+       {0xc5, 0x2c},
+       {0xc6, 0x1e},
+       {0xc7, 0x10},
+       {0xc8, 0x12},
+       {0xc9, 0x01},
+       {0xca, 0x6f},
+       {0xcb, 0xa7},
+       {0xcc, 0x3c},
+       {0xcd, 0x10},
+       {0xce, 0x00},
+       {0xcf, 0x22},
+       {0xd0, 0x00},
+       {0xd1, 0x10},
+       {0xd2, 0x00},
+       {0xd3, 0x00},
+       {0xd4, 0x10},
+       {0xd5, 0x33},
+       {0xd6, 0x80},
+       {0xd7, 0x21},
+       {0xd8, 0x00},
+       {0xd9, 0x00},
+       {0xda, 0x00},
+       {0xdb, 0x00},
+       {0xdc, 0x00},
+       {0xdd, 0x00},
+       {0xde, 0x00},
+       {0xdf, 0x00},
+       {0xe0, 0x00},
+       {0xe1, 0xB3},
+       {0xe2, 0x00},
+       {0xe3, 0x00},
+       {0xe4, 0x00},
+       {0xe5, 0x10},
+       {0xe6, 0x00},
+       {0xe7, 0x18},
+       {0xe8, 0x08},
+       {0xe9, 0xd4},
+       {0xea, 0x00},
+       {0xeb, 0xff},
+       {0xec, 0x79},
+       {0xed, 0x10},
+       {0xee, 0x30},
+       {0xef, 0x02},
+       {0xf0, 0x00},
+       {0xf1, 0x09},
+       {0xf2, 0x00},
+       {0xf3, 0x00},
+       {0xf4, 0x00},
+       {0xf5, 0x00},
+       {0xf6, 0x00},
+       {0xf7, 0x00},
+       {0xf8, 0x00},
+       {0xf9, 0x00},
+       {0xfa, 0x00},
+       {0xfb, 0x00},
+       {0xfc, 0x00},
+       {0xfd, 0x00},
+       {0xfe, 0x00},
+       {0xff, 0x00},
 };
 
 #define CB_VT3253B0_AGC_FOR_RFMD2959 195
 // For RFMD2959
 unsigned char byVT3253B0_AGC4_RFMD2959[CB_VT3253B0_AGC_FOR_RFMD2959][2] = {
-    {0xF0, 0x00},
-    {0xF1, 0x3E},
-    {0xF0, 0x80},
-    {0xF0, 0x00},
-    {0xF1, 0x3E},
-    {0xF0, 0x81},
-    {0xF0, 0x01},
-    {0xF1, 0x3E},
-    {0xF0, 0x82},
-    {0xF0, 0x02},
-    {0xF1, 0x3E},
-    {0xF0, 0x83},
-    {0xF0, 0x03},
-    {0xF1, 0x3B},
-    {0xF0, 0x84},
-    {0xF0, 0x04},
-    {0xF1, 0x39},
-    {0xF0, 0x85},
-    {0xF0, 0x05},
-    {0xF1, 0x38},
-    {0xF0, 0x86},
-    {0xF0, 0x06},
-    {0xF1, 0x37},
-    {0xF0, 0x87},
-    {0xF0, 0x07},
-    {0xF1, 0x36},
-    {0xF0, 0x88},
-    {0xF0, 0x08},
-    {0xF1, 0x35},
-    {0xF0, 0x89},
-    {0xF0, 0x09},
-    {0xF1, 0x35},
-    {0xF0, 0x8A},
-    {0xF0, 0x0A},
-    {0xF1, 0x34},
-    {0xF0, 0x8B},
-    {0xF0, 0x0B},
-    {0xF1, 0x34},
-    {0xF0, 0x8C},
-    {0xF0, 0x0C},
-    {0xF1, 0x33},
-    {0xF0, 0x8D},
-    {0xF0, 0x0D},
-    {0xF1, 0x32},
-    {0xF0, 0x8E},
-    {0xF0, 0x0E},
-    {0xF1, 0x31},
-    {0xF0, 0x8F},
-    {0xF0, 0x0F},
-    {0xF1, 0x30},
-    {0xF0, 0x90},
-    {0xF0, 0x10},
-    {0xF1, 0x2F},
-    {0xF0, 0x91},
-    {0xF0, 0x11},
-    {0xF1, 0x2F},
-    {0xF0, 0x92},
-    {0xF0, 0x12},
-    {0xF1, 0x2E},
-    {0xF0, 0x93},
-    {0xF0, 0x13},
-    {0xF1, 0x2D},
-    {0xF0, 0x94},
-    {0xF0, 0x14},
-    {0xF1, 0x2C},
-    {0xF0, 0x95},
-    {0xF0, 0x15},
-    {0xF1, 0x2B},
-    {0xF0, 0x96},
-    {0xF0, 0x16},
-    {0xF1, 0x2B},
-    {0xF0, 0x97},
-    {0xF0, 0x17},
-    {0xF1, 0x2A},
-    {0xF0, 0x98},
-    {0xF0, 0x18},
-    {0xF1, 0x29},
-    {0xF0, 0x99},
-    {0xF0, 0x19},
-    {0xF1, 0x28},
-    {0xF0, 0x9A},
-    {0xF0, 0x1A},
-    {0xF1, 0x27},
-    {0xF0, 0x9B},
-    {0xF0, 0x1B},
-    {0xF1, 0x26},
-    {0xF0, 0x9C},
-    {0xF0, 0x1C},
-    {0xF1, 0x25},
-    {0xF0, 0x9D},
-    {0xF0, 0x1D},
-    {0xF1, 0x24},
-    {0xF0, 0x9E},
-    {0xF0, 0x1E},
-    {0xF1, 0x24},
-    {0xF0, 0x9F},
-    {0xF0, 0x1F},
-    {0xF1, 0x23},
-    {0xF0, 0xA0},
-    {0xF0, 0x20},
-    {0xF1, 0x22},
-    {0xF0, 0xA1},
-    {0xF0, 0x21},
-    {0xF1, 0x21},
-    {0xF0, 0xA2},
-    {0xF0, 0x22},
-    {0xF1, 0x20},
-    {0xF0, 0xA3},
-    {0xF0, 0x23},
-    {0xF1, 0x20},
-    {0xF0, 0xA4},
-    {0xF0, 0x24},
-    {0xF1, 0x1F},
-    {0xF0, 0xA5},
-    {0xF0, 0x25},
-    {0xF1, 0x1E},
-    {0xF0, 0xA6},
-    {0xF0, 0x26},
-    {0xF1, 0x1D},
-    {0xF0, 0xA7},
-    {0xF0, 0x27},
-    {0xF1, 0x1C},
-    {0xF0, 0xA8},
-    {0xF0, 0x28},
-    {0xF1, 0x1B},
-    {0xF0, 0xA9},
-    {0xF0, 0x29},
-    {0xF1, 0x1B},
-    {0xF0, 0xAA},
-    {0xF0, 0x2A},
-    {0xF1, 0x1A},
-    {0xF0, 0xAB},
-    {0xF0, 0x2B},
-    {0xF1, 0x1A},
-    {0xF0, 0xAC},
-    {0xF0, 0x2C},
-    {0xF1, 0x19},
-    {0xF0, 0xAD},
-    {0xF0, 0x2D},
-    {0xF1, 0x18},
-    {0xF0, 0xAE},
-    {0xF0, 0x2E},
-    {0xF1, 0x17},
-    {0xF0, 0xAF},
-    {0xF0, 0x2F},
-    {0xF1, 0x16},
-    {0xF0, 0xB0},
-    {0xF0, 0x30},
-    {0xF1, 0x15},
-    {0xF0, 0xB1},
-    {0xF0, 0x31},
-    {0xF1, 0x15},
-    {0xF0, 0xB2},
-    {0xF0, 0x32},
-    {0xF1, 0x15},
-    {0xF0, 0xB3},
-    {0xF0, 0x33},
-    {0xF1, 0x14},
-    {0xF0, 0xB4},
-    {0xF0, 0x34},
-    {0xF1, 0x13},
-    {0xF0, 0xB5},
-    {0xF0, 0x35},
-    {0xF1, 0x12},
-    {0xF0, 0xB6},
-    {0xF0, 0x36},
-    {0xF1, 0x11},
-    {0xF0, 0xB7},
-    {0xF0, 0x37},
-    {0xF1, 0x10},
-    {0xF0, 0xB8},
-    {0xF0, 0x38},
-    {0xF1, 0x0F},
-    {0xF0, 0xB9},
-    {0xF0, 0x39},
-    {0xF1, 0x0E},
-    {0xF0, 0xBA},
-    {0xF0, 0x3A},
-    {0xF1, 0x0D},
-    {0xF0, 0xBB},
-    {0xF0, 0x3B},
-    {0xF1, 0x0C},
-    {0xF0, 0xBC},
-    {0xF0, 0x3C},
-    {0xF1, 0x0B},
-    {0xF0, 0xBD},
-    {0xF0, 0x3D},
-    {0xF1, 0x0B},
-    {0xF0, 0xBE},
-    {0xF0, 0x3E},
-    {0xF1, 0x0A},
-    {0xF0, 0xBF},
-    {0xF0, 0x3F},
-    {0xF1, 0x09},
-    {0xF0, 0x00},
+       {0xF0, 0x00},
+       {0xF1, 0x3E},
+       {0xF0, 0x80},
+       {0xF0, 0x00},
+       {0xF1, 0x3E},
+       {0xF0, 0x81},
+       {0xF0, 0x01},
+       {0xF1, 0x3E},
+       {0xF0, 0x82},
+       {0xF0, 0x02},
+       {0xF1, 0x3E},
+       {0xF0, 0x83},
+       {0xF0, 0x03},
+       {0xF1, 0x3B},
+       {0xF0, 0x84},
+       {0xF0, 0x04},
+       {0xF1, 0x39},
+       {0xF0, 0x85},
+       {0xF0, 0x05},
+       {0xF1, 0x38},
+       {0xF0, 0x86},
+       {0xF0, 0x06},
+       {0xF1, 0x37},
+       {0xF0, 0x87},
+       {0xF0, 0x07},
+       {0xF1, 0x36},
+       {0xF0, 0x88},
+       {0xF0, 0x08},
+       {0xF1, 0x35},
+       {0xF0, 0x89},
+       {0xF0, 0x09},
+       {0xF1, 0x35},
+       {0xF0, 0x8A},
+       {0xF0, 0x0A},
+       {0xF1, 0x34},
+       {0xF0, 0x8B},
+       {0xF0, 0x0B},
+       {0xF1, 0x34},
+       {0xF0, 0x8C},
+       {0xF0, 0x0C},
+       {0xF1, 0x33},
+       {0xF0, 0x8D},
+       {0xF0, 0x0D},
+       {0xF1, 0x32},
+       {0xF0, 0x8E},
+       {0xF0, 0x0E},
+       {0xF1, 0x31},
+       {0xF0, 0x8F},
+       {0xF0, 0x0F},
+       {0xF1, 0x30},
+       {0xF0, 0x90},
+       {0xF0, 0x10},
+       {0xF1, 0x2F},
+       {0xF0, 0x91},
+       {0xF0, 0x11},
+       {0xF1, 0x2F},
+       {0xF0, 0x92},
+       {0xF0, 0x12},
+       {0xF1, 0x2E},
+       {0xF0, 0x93},
+       {0xF0, 0x13},
+       {0xF1, 0x2D},
+       {0xF0, 0x94},
+       {0xF0, 0x14},
+       {0xF1, 0x2C},
+       {0xF0, 0x95},
+       {0xF0, 0x15},
+       {0xF1, 0x2B},
+       {0xF0, 0x96},
+       {0xF0, 0x16},
+       {0xF1, 0x2B},
+       {0xF0, 0x97},
+       {0xF0, 0x17},
+       {0xF1, 0x2A},
+       {0xF0, 0x98},
+       {0xF0, 0x18},
+       {0xF1, 0x29},
+       {0xF0, 0x99},
+       {0xF0, 0x19},
+       {0xF1, 0x28},
+       {0xF0, 0x9A},
+       {0xF0, 0x1A},
+       {0xF1, 0x27},
+       {0xF0, 0x9B},
+       {0xF0, 0x1B},
+       {0xF1, 0x26},
+       {0xF0, 0x9C},
+       {0xF0, 0x1C},
+       {0xF1, 0x25},
+       {0xF0, 0x9D},
+       {0xF0, 0x1D},
+       {0xF1, 0x24},
+       {0xF0, 0x9E},
+       {0xF0, 0x1E},
+       {0xF1, 0x24},
+       {0xF0, 0x9F},
+       {0xF0, 0x1F},
+       {0xF1, 0x23},
+       {0xF0, 0xA0},
+       {0xF0, 0x20},
+       {0xF1, 0x22},
+       {0xF0, 0xA1},
+       {0xF0, 0x21},
+       {0xF1, 0x21},
+       {0xF0, 0xA2},
+       {0xF0, 0x22},
+       {0xF1, 0x20},
+       {0xF0, 0xA3},
+       {0xF0, 0x23},
+       {0xF1, 0x20},
+       {0xF0, 0xA4},
+       {0xF0, 0x24},
+       {0xF1, 0x1F},
+       {0xF0, 0xA5},
+       {0xF0, 0x25},
+       {0xF1, 0x1E},
+       {0xF0, 0xA6},
+       {0xF0, 0x26},
+       {0xF1, 0x1D},
+       {0xF0, 0xA7},
+       {0xF0, 0x27},
+       {0xF1, 0x1C},
+       {0xF0, 0xA8},
+       {0xF0, 0x28},
+       {0xF1, 0x1B},
+       {0xF0, 0xA9},
+       {0xF0, 0x29},
+       {0xF1, 0x1B},
+       {0xF0, 0xAA},
+       {0xF0, 0x2A},
+       {0xF1, 0x1A},
+       {0xF0, 0xAB},
+       {0xF0, 0x2B},
+       {0xF1, 0x1A},
+       {0xF0, 0xAC},
+       {0xF0, 0x2C},
+       {0xF1, 0x19},
+       {0xF0, 0xAD},
+       {0xF0, 0x2D},
+       {0xF1, 0x18},
+       {0xF0, 0xAE},
+       {0xF0, 0x2E},
+       {0xF1, 0x17},
+       {0xF0, 0xAF},
+       {0xF0, 0x2F},
+       {0xF1, 0x16},
+       {0xF0, 0xB0},
+       {0xF0, 0x30},
+       {0xF1, 0x15},
+       {0xF0, 0xB1},
+       {0xF0, 0x31},
+       {0xF1, 0x15},
+       {0xF0, 0xB2},
+       {0xF0, 0x32},
+       {0xF1, 0x15},
+       {0xF0, 0xB3},
+       {0xF0, 0x33},
+       {0xF1, 0x14},
+       {0xF0, 0xB4},
+       {0xF0, 0x34},
+       {0xF1, 0x13},
+       {0xF0, 0xB5},
+       {0xF0, 0x35},
+       {0xF1, 0x12},
+       {0xF0, 0xB6},
+       {0xF0, 0x36},
+       {0xF1, 0x11},
+       {0xF0, 0xB7},
+       {0xF0, 0x37},
+       {0xF1, 0x10},
+       {0xF0, 0xB8},
+       {0xF0, 0x38},
+       {0xF1, 0x0F},
+       {0xF0, 0xB9},
+       {0xF0, 0x39},
+       {0xF1, 0x0E},
+       {0xF0, 0xBA},
+       {0xF0, 0x3A},
+       {0xF1, 0x0D},
+       {0xF0, 0xBB},
+       {0xF0, 0x3B},
+       {0xF1, 0x0C},
+       {0xF0, 0xBC},
+       {0xF0, 0x3C},
+       {0xF1, 0x0B},
+       {0xF0, 0xBD},
+       {0xF0, 0x3D},
+       {0xF1, 0x0B},
+       {0xF0, 0xBE},
+       {0xF0, 0x3E},
+       {0xF1, 0x0A},
+       {0xF0, 0xBF},
+       {0xF0, 0x3F},
+       {0xF1, 0x09},
+       {0xF0, 0x00},
 };
 
 #define CB_VT3253B0_INIT_FOR_AIROHA2230 256
 // For AIROHA
 unsigned char byVT3253B0_AIROHA2230[CB_VT3253B0_INIT_FOR_AIROHA2230][2] = {
-    {0x00, 0x31},
-    {0x01, 0x00},
-    {0x02, 0x00},
-    {0x03, 0x00},
-    {0x04, 0x00},
-    {0x05, 0x80},
-    {0x06, 0x00},
-    {0x07, 0x00},
-    {0x08, 0x70},
-    {0x09, 0x41},
-    {0x0a, 0x2A},
-    {0x0b, 0x76},
-    {0x0c, 0x00},
-    {0x0d, 0x00},
-    {0x0e, 0x80},
-    {0x0f, 0x00},
-    {0x10, 0x00},
-    {0x11, 0x00},
-    {0x12, 0x00},
-    {0x13, 0x00},
-    {0x14, 0x00},
-    {0x15, 0x00},
-    {0x16, 0x00},
-    {0x17, 0x00},
-    {0x18, 0x00},
-    {0x19, 0x00},
-    {0x1a, 0x00},
-    {0x1b, 0x8f},
-    {0x1c, 0x09},
-    {0x1d, 0x00},
-    {0x1e, 0x00},
-    {0x1f, 0x00},
-    {0x20, 0x00},
-    {0x21, 0x00},
-    {0x22, 0x00},
-    {0x23, 0x00},
-    {0x24, 0x00},
-    {0x25, 0x4a},
-    {0x26, 0x00},
-    {0x27, 0x00},
-    {0x28, 0x00},
-    {0x29, 0x00},
-    {0x2a, 0x00},
-    {0x2b, 0x00},
-    {0x2c, 0x00},
-    {0x2d, 0x4a},
-    {0x2e, 0x00},
-    {0x2f, 0x0a},
-    {0x30, 0x26},
-    {0x31, 0x5b},
-    {0x32, 0x00},
-    {0x33, 0x00},
-    {0x34, 0x00},
-    {0x35, 0x00},
-    {0x36, 0xaa},
-    {0x37, 0xaa},
-    {0x38, 0xff},
-    {0x39, 0xff},
-    {0x3a, 0x79},
-    {0x3b, 0x00},
-    {0x3c, 0x00},
-    {0x3d, 0x0b},
-    {0x3e, 0x48},
-    {0x3f, 0x04},
-    {0x40, 0x00},
-    {0x41, 0x08},
-    {0x42, 0x00},
-    {0x43, 0x08},
-    {0x44, 0x08},
-    {0x45, 0x14},
-    {0x46, 0x05},
-    {0x47, 0x09},
-    {0x48, 0x00},
-    {0x49, 0x00},
-    {0x4a, 0x00},
-    {0x4b, 0x00},
-    {0x4c, 0x09},
-    {0x4d, 0x73},
-    {0x4e, 0x00},
-    {0x4f, 0xc5},
-    {0x50, 0x15},
-    {0x51, 0x19},
-    {0x52, 0x00},
-    {0x53, 0x00},
-    {0x54, 0x00},
-    {0x55, 0x00},
-    {0x56, 0x00},
-    {0x57, 0x00},
-    {0x58, 0x00},
-    {0x59, 0xb0},
-    {0x5a, 0x00},
-    {0x5b, 0x00},
-    {0x5c, 0x00},
-    {0x5d, 0x00},
-    {0x5e, 0x00},
-    {0x5f, 0x00},
-    {0x60, 0xe4},
-    {0x61, 0x80},
-    {0x62, 0x00},
-    {0x63, 0x00},
-    {0x64, 0x00},
-    {0x65, 0x00},
-    {0x66, 0x98},
-    {0x67, 0x0a},
-    {0x68, 0x00},
-    {0x69, 0x00},
-    {0x6a, 0x00},
-    {0x6b, 0x00},
-    //{0x6c, 0x80},
-    {0x6c, 0x00}, //RobertYu:20050125, request by JJSue
-    {0x6d, 0x03},
-    {0x6e, 0x01},
-    {0x6f, 0x00},
-    {0x70, 0x00},
-    {0x71, 0x00},
-    {0x72, 0x00},
-    {0x73, 0x00},
-    {0x74, 0x00},
-    {0x75, 0x00},
-    {0x76, 0x00},
-    {0x77, 0x00},
-    {0x78, 0x00},
-    {0x79, 0x00},
-    {0x7a, 0x00},
-    {0x7b, 0x00},
-    {0x7c, 0x00},
-    {0x7d, 0x00},
-    {0x7e, 0x00},
-    {0x7f, 0x00},
-    {0x80, 0x8c},
-    {0x81, 0x01},
-    {0x82, 0x09},
-    {0x83, 0x00},
-    {0x84, 0x00},
-    {0x85, 0x00},
-    {0x86, 0x00},
-    {0x87, 0x00},
-    {0x88, 0x08},
-    {0x89, 0x00},
-    {0x8a, 0x0f},
-    {0x8b, 0xb7},
-    {0x8c, 0x88},
-    {0x8d, 0x47},
-    {0x8e, 0xaa},
-    {0x8f, 0x02},
-    {0x90, 0x22},
-    {0x91, 0x00},
-    {0x92, 0x00},
-    {0x93, 0x00},
-    {0x94, 0x00},
-    {0x95, 0x00},
-    {0x96, 0x00},
-    {0x97, 0xeb},
-    {0x98, 0x00},
-    {0x99, 0x00},
-    {0x9a, 0x00},
-    {0x9b, 0x00},
-    {0x9c, 0x00},
-    {0x9d, 0x00},
-    {0x9e, 0x00},
-    {0x9f, 0x01},
-    {0xa0, 0x00},
-    {0xa1, 0x00},
-    {0xa2, 0x00},
-    {0xa3, 0x00},
-    {0xa4, 0x00},
-    {0xa5, 0x00},
-    {0xa6, 0x10},
-    {0xa7, 0x00},
-    {0xa8, 0x18},
-    {0xa9, 0x00},
-    {0xaa, 0x00},
-    {0xab, 0x00},
-    {0xac, 0x00},
-    {0xad, 0x00},
-    {0xae, 0x00},
-    {0xaf, 0x18},
-    {0xb0, 0x38},
-    {0xb1, 0x30},
-    {0xb2, 0x00},
-    {0xb3, 0x00},
-    {0xb4, 0xff},
-    {0xb5, 0x0f},
-    {0xb6, 0xe4},
-    {0xb7, 0xe2},
-    {0xb8, 0x00},
-    {0xb9, 0x00},
-    {0xba, 0x00},
-    {0xbb, 0x03},
-    {0xbc, 0x01},
-    {0xbd, 0x00},
-    {0xbe, 0x00},
-    {0xbf, 0x00},
-    {0xc0, 0x18},
-    {0xc1, 0x20},
-    {0xc2, 0x07},
-    {0xc3, 0x18},
-    {0xc4, 0xff},
-    {0xc5, 0x2c},
-    {0xc6, 0x0c},
-    {0xc7, 0x0a},
-    {0xc8, 0x0e},
-    {0xc9, 0x01},
-    {0xca, 0x68},
-    {0xcb, 0xa7},
-    {0xcc, 0x3c},
-    {0xcd, 0x10},
-    {0xce, 0x00},
-    {0xcf, 0x25},
-    {0xd0, 0x40},
-    {0xd1, 0x12},
-    {0xd2, 0x00},
-    {0xd3, 0x00},
-    {0xd4, 0x10},
-    {0xd5, 0x28},
-    {0xd6, 0x80},
-    {0xd7, 0x2A},
-    {0xd8, 0x00},
-    {0xd9, 0x00},
-    {0xda, 0x00},
-    {0xdb, 0x00},
-    {0xdc, 0x00},
-    {0xdd, 0x00},
-    {0xde, 0x00},
-    {0xdf, 0x00},
-    {0xe0, 0x00},
-    {0xe1, 0xB3},
-    {0xe2, 0x00},
-    {0xe3, 0x00},
-    {0xe4, 0x00},
-    {0xe5, 0x10},
-    {0xe6, 0x00},
-    {0xe7, 0x1C},
-    {0xe8, 0x00},
-    {0xe9, 0xf4},
-    {0xea, 0x00},
-    {0xeb, 0xff},
-    {0xec, 0x79},
-    {0xed, 0x20},
-    {0xee, 0x30},
-    {0xef, 0x01},
-    {0xf0, 0x00},
-    {0xf1, 0x3e},
-    {0xf2, 0x00},
-    {0xf3, 0x00},
-    {0xf4, 0x00},
-    {0xf5, 0x00},
-    {0xf6, 0x00},
-    {0xf7, 0x00},
-    {0xf8, 0x00},
-    {0xf9, 0x00},
-    {0xfa, 0x00},
-    {0xfb, 0x00},
-    {0xfc, 0x00},
-    {0xfd, 0x00},
-    {0xfe, 0x00},
-    {0xff, 0x00},
+       {0x00, 0x31},
+       {0x01, 0x00},
+       {0x02, 0x00},
+       {0x03, 0x00},
+       {0x04, 0x00},
+       {0x05, 0x80},
+       {0x06, 0x00},
+       {0x07, 0x00},
+       {0x08, 0x70},
+       {0x09, 0x41},
+       {0x0a, 0x2A},
+       {0x0b, 0x76},
+       {0x0c, 0x00},
+       {0x0d, 0x00},
+       {0x0e, 0x80},
+       {0x0f, 0x00},
+       {0x10, 0x00},
+       {0x11, 0x00},
+       {0x12, 0x00},
+       {0x13, 0x00},
+       {0x14, 0x00},
+       {0x15, 0x00},
+       {0x16, 0x00},
+       {0x17, 0x00},
+       {0x18, 0x00},
+       {0x19, 0x00},
+       {0x1a, 0x00},
+       {0x1b, 0x8f},
+       {0x1c, 0x09},
+       {0x1d, 0x00},
+       {0x1e, 0x00},
+       {0x1f, 0x00},
+       {0x20, 0x00},
+       {0x21, 0x00},
+       {0x22, 0x00},
+       {0x23, 0x00},
+       {0x24, 0x00},
+       {0x25, 0x4a},
+       {0x26, 0x00},
+       {0x27, 0x00},
+       {0x28, 0x00},
+       {0x29, 0x00},
+       {0x2a, 0x00},
+       {0x2b, 0x00},
+       {0x2c, 0x00},
+       {0x2d, 0x4a},
+       {0x2e, 0x00},
+       {0x2f, 0x0a},
+       {0x30, 0x26},
+       {0x31, 0x5b},
+       {0x32, 0x00},
+       {0x33, 0x00},
+       {0x34, 0x00},
+       {0x35, 0x00},
+       {0x36, 0xaa},
+       {0x37, 0xaa},
+       {0x38, 0xff},
+       {0x39, 0xff},
+       {0x3a, 0x79},
+       {0x3b, 0x00},
+       {0x3c, 0x00},
+       {0x3d, 0x0b},
+       {0x3e, 0x48},
+       {0x3f, 0x04},
+       {0x40, 0x00},
+       {0x41, 0x08},
+       {0x42, 0x00},
+       {0x43, 0x08},
+       {0x44, 0x08},
+       {0x45, 0x14},
+       {0x46, 0x05},
+       {0x47, 0x09},
+       {0x48, 0x00},
+       {0x49, 0x00},
+       {0x4a, 0x00},
+       {0x4b, 0x00},
+       {0x4c, 0x09},
+       {0x4d, 0x73},
+       {0x4e, 0x00},
+       {0x4f, 0xc5},
+       {0x50, 0x15},
+       {0x51, 0x19},
+       {0x52, 0x00},
+       {0x53, 0x00},
+       {0x54, 0x00},
+       {0x55, 0x00},
+       {0x56, 0x00},
+       {0x57, 0x00},
+       {0x58, 0x00},
+       {0x59, 0xb0},
+       {0x5a, 0x00},
+       {0x5b, 0x00},
+       {0x5c, 0x00},
+       {0x5d, 0x00},
+       {0x5e, 0x00},
+       {0x5f, 0x00},
+       {0x60, 0xe4},
+       {0x61, 0x80},
+       {0x62, 0x00},
+       {0x63, 0x00},
+       {0x64, 0x00},
+       {0x65, 0x00},
+       {0x66, 0x98},
+       {0x67, 0x0a},
+       {0x68, 0x00},
+       {0x69, 0x00},
+       {0x6a, 0x00},
+       {0x6b, 0x00},
+       //{0x6c, 0x80},
+       {0x6c, 0x00}, //RobertYu:20050125, request by JJSue
+       {0x6d, 0x03},
+       {0x6e, 0x01},
+       {0x6f, 0x00},
+       {0x70, 0x00},
+       {0x71, 0x00},
+       {0x72, 0x00},
+       {0x73, 0x00},
+       {0x74, 0x00},
+       {0x75, 0x00},
+       {0x76, 0x00},
+       {0x77, 0x00},
+       {0x78, 0x00},
+       {0x79, 0x00},
+       {0x7a, 0x00},
+       {0x7b, 0x00},
+       {0x7c, 0x00},
+       {0x7d, 0x00},
+       {0x7e, 0x00},
+       {0x7f, 0x00},
+       {0x80, 0x8c},
+       {0x81, 0x01},
+       {0x82, 0x09},
+       {0x83, 0x00},
+       {0x84, 0x00},
+       {0x85, 0x00},
+       {0x86, 0x00},
+       {0x87, 0x00},
+       {0x88, 0x08},
+       {0x89, 0x00},
+       {0x8a, 0x0f},
+       {0x8b, 0xb7},
+       {0x8c, 0x88},
+       {0x8d, 0x47},
+       {0x8e, 0xaa},
+       {0x8f, 0x02},
+       {0x90, 0x22},
+       {0x91, 0x00},
+       {0x92, 0x00},
+       {0x93, 0x00},
+       {0x94, 0x00},
+       {0x95, 0x00},
+       {0x96, 0x00},
+       {0x97, 0xeb},
+       {0x98, 0x00},
+       {0x99, 0x00},
+       {0x9a, 0x00},
+       {0x9b, 0x00},
+       {0x9c, 0x00},
+       {0x9d, 0x00},
+       {0x9e, 0x00},
+       {0x9f, 0x01},
+       {0xa0, 0x00},
+       {0xa1, 0x00},
+       {0xa2, 0x00},
+       {0xa3, 0x00},
+       {0xa4, 0x00},
+       {0xa5, 0x00},
+       {0xa6, 0x10},
+       {0xa7, 0x00},
+       {0xa8, 0x18},
+       {0xa9, 0x00},
+       {0xaa, 0x00},
+       {0xab, 0x00},
+       {0xac, 0x00},
+       {0xad, 0x00},
+       {0xae, 0x00},
+       {0xaf, 0x18},
+       {0xb0, 0x38},
+       {0xb1, 0x30},
+       {0xb2, 0x00},
+       {0xb3, 0x00},
+       {0xb4, 0xff},
+       {0xb5, 0x0f},
+       {0xb6, 0xe4},
+       {0xb7, 0xe2},
+       {0xb8, 0x00},
+       {0xb9, 0x00},
+       {0xba, 0x00},
+       {0xbb, 0x03},
+       {0xbc, 0x01},
+       {0xbd, 0x00},
+       {0xbe, 0x00},
+       {0xbf, 0x00},
+       {0xc0, 0x18},
+       {0xc1, 0x20},
+       {0xc2, 0x07},
+       {0xc3, 0x18},
+       {0xc4, 0xff},
+       {0xc5, 0x2c},
+       {0xc6, 0x0c},
+       {0xc7, 0x0a},
+       {0xc8, 0x0e},
+       {0xc9, 0x01},
+       {0xca, 0x68},
+       {0xcb, 0xa7},
+       {0xcc, 0x3c},
+       {0xcd, 0x10},
+       {0xce, 0x00},
+       {0xcf, 0x25},
+       {0xd0, 0x40},
+       {0xd1, 0x12},
+       {0xd2, 0x00},
+       {0xd3, 0x00},
+       {0xd4, 0x10},
+       {0xd5, 0x28},
+       {0xd6, 0x80},
+       {0xd7, 0x2A},
+       {0xd8, 0x00},
+       {0xd9, 0x00},
+       {0xda, 0x00},
+       {0xdb, 0x00},
+       {0xdc, 0x00},
+       {0xdd, 0x00},
+       {0xde, 0x00},
+       {0xdf, 0x00},
+       {0xe0, 0x00},
+       {0xe1, 0xB3},
+       {0xe2, 0x00},
+       {0xe3, 0x00},
+       {0xe4, 0x00},
+       {0xe5, 0x10},
+       {0xe6, 0x00},
+       {0xe7, 0x1C},
+       {0xe8, 0x00},
+       {0xe9, 0xf4},
+       {0xea, 0x00},
+       {0xeb, 0xff},
+       {0xec, 0x79},
+       {0xed, 0x20},
+       {0xee, 0x30},
+       {0xef, 0x01},
+       {0xf0, 0x00},
+       {0xf1, 0x3e},
+       {0xf2, 0x00},
+       {0xf3, 0x00},
+       {0xf4, 0x00},
+       {0xf5, 0x00},
+       {0xf6, 0x00},
+       {0xf7, 0x00},
+       {0xf8, 0x00},
+       {0xf9, 0x00},
+       {0xfa, 0x00},
+       {0xfb, 0x00},
+       {0xfc, 0x00},
+       {0xfd, 0x00},
+       {0xfe, 0x00},
+       {0xff, 0x00},
 };
 
-
-
 #define CB_VT3253B0_INIT_FOR_UW2451 256
 //For UW2451
 unsigned char byVT3253B0_UW2451[CB_VT3253B0_INIT_FOR_UW2451][2] = {
-    {0x00, 0x31},
-    {0x01, 0x00},
-    {0x02, 0x00},
-    {0x03, 0x00},
-    {0x04, 0x00},
-    {0x05, 0x81},
-    {0x06, 0x00},
-    {0x07, 0x00},
-    {0x08, 0x38},
-    {0x09, 0x45},
-    {0x0a, 0x28},
-    {0x0b, 0x76},
-    {0x0c, 0x00},
-    {0x0d, 0x00},
-    {0x0e, 0x80},
-    {0x0f, 0x00},
-    {0x10, 0x00},
-    {0x11, 0x00},
-    {0x12, 0x00},
-    {0x13, 0x00},
-    {0x14, 0x00},
-    {0x15, 0x00},
-    {0x16, 0x00},
-    {0x17, 0x00},
-    {0x18, 0x00},
-    {0x19, 0x00},
-    {0x1a, 0x00},
-    {0x1b, 0x8f},
-    {0x1c, 0x0f},
-    {0x1d, 0x00},
-    {0x1e, 0x00},
-    {0x1f, 0x00},
-    {0x20, 0x00},
-    {0x21, 0x00},
-    {0x22, 0x00},
-    {0x23, 0x00},
-    {0x24, 0x00},
-    {0x25, 0x4a},
-    {0x26, 0x00},
-    {0x27, 0x00},
-    {0x28, 0x00},
-    {0x29, 0x00},
-    {0x2a, 0x00},
-    {0x2b, 0x00},
-    {0x2c, 0x00},
-    {0x2d, 0x18},
-    {0x2e, 0x00},
-    {0x2f, 0x0a},
-    {0x30, 0x26},
-    {0x31, 0x5b},
-    {0x32, 0x00},
-    {0x33, 0x00},
-    {0x34, 0x00},
-    {0x35, 0x00},
-    {0x36, 0xaa},
-    {0x37, 0xaa},
-    {0x38, 0xff},
-    {0x39, 0xff},
-    {0x3a, 0x00},
-    {0x3b, 0x00},
-    {0x3c, 0x00},
-    {0x3d, 0x03},
-    {0x3e, 0x1d},
-    {0x3f, 0x04},
-    {0x40, 0x00},
-    {0x41, 0x08},
-    {0x42, 0x00},
-    {0x43, 0x08},
-    {0x44, 0x08},
-    {0x45, 0x14},
-    {0x46, 0x05},
-    {0x47, 0x09},
-    {0x48, 0x00},
-    {0x49, 0x00},
-    {0x4a, 0x00},
-    {0x4b, 0x00},
-    {0x4c, 0x09},
-    {0x4d, 0x90},
-    {0x4e, 0x00},
-    {0x4f, 0xc5},
-    {0x50, 0x15},
-    {0x51, 0x19},
-    {0x52, 0x00},
-    {0x53, 0x00},
-    {0x54, 0x00},
-    {0x55, 0x00},
-    {0x56, 0x00},
-    {0x57, 0x00},
-    {0x58, 0x00},
-    {0x59, 0xb0},
-    {0x5a, 0x00},
-    {0x5b, 0x00},
-    {0x5c, 0x00},
-    {0x5d, 0x00},
-    {0x5e, 0x00},
-    {0x5f, 0x00},
-    {0x60, 0xb3},
-    {0x61, 0x81},
-    {0x62, 0x00},
-    {0x63, 0x00},
-    {0x64, 0x00},
-    {0x65, 0x00},
-    {0x66, 0x57},
-    {0x67, 0x6c},
-    {0x68, 0x00},
-    {0x69, 0x00},
-    {0x6a, 0x00},
-    {0x6b, 0x00},
-    //{0x6c, 0x80},
-    {0x6c, 0x00}, //RobertYu:20050125, request by JJSue
-    {0x6d, 0x03},
-    {0x6e, 0x01},
-    {0x6f, 0x00},
-    {0x70, 0x00},
-    {0x71, 0x00},
-    {0x72, 0x00},
-    {0x73, 0x00},
-    {0x74, 0x00},
-    {0x75, 0x00},
-    {0x76, 0x00},
-    {0x77, 0x00},
-    {0x78, 0x00},
-    {0x79, 0x00},
-    {0x7a, 0x00},
-    {0x7b, 0x00},
-    {0x7c, 0x00},
-    {0x7d, 0x00},
-    {0x7e, 0x00},
-    {0x7f, 0x00},
-    {0x80, 0x8c},
-    {0x81, 0x00},
-    {0x82, 0x0e},
-    {0x83, 0x00},
-    {0x84, 0x00},
-    {0x85, 0x00},
-    {0x86, 0x00},
-    {0x87, 0x00},
-    {0x88, 0x08},
-    {0x89, 0x00},
-    {0x8a, 0x0e},
-    {0x8b, 0xa7},
-    {0x8c, 0x88},
-    {0x8d, 0x47},
-    {0x8e, 0xaa},
-    {0x8f, 0x02},
-    {0x90, 0x00},
-    {0x91, 0x00},
-    {0x92, 0x00},
-    {0x93, 0x00},
-    {0x94, 0x00},
-    {0x95, 0x00},
-    {0x96, 0x00},
-    {0x97, 0xe3},
-    {0x98, 0x00},
-    {0x99, 0x00},
-    {0x9a, 0x00},
-    {0x9b, 0x00},
-    {0x9c, 0x00},
-    {0x9d, 0x00},
-    {0x9e, 0x00},
-    {0x9f, 0x00},
-    {0xa0, 0x00},
-    {0xa1, 0x00},
-    {0xa2, 0x00},
-    {0xa3, 0x00},
-    {0xa4, 0x00},
-    {0xa5, 0x00},
-    {0xa6, 0x10},
-    {0xa7, 0x00},
-    {0xa8, 0x18},
-    {0xa9, 0x00},
-    {0xaa, 0x00},
-    {0xab, 0x00},
-    {0xac, 0x00},
-    {0xad, 0x00},
-    {0xae, 0x00},
-    {0xaf, 0x18},
-    {0xb0, 0x18},
-    {0xb1, 0x30},
-    {0xb2, 0x00},
-    {0xb3, 0x00},
-    {0xb4, 0x00},
-    {0xb5, 0x00},
-    {0xb6, 0x00},
-    {0xb7, 0x00},
-    {0xb8, 0x00},
-    {0xb9, 0x00},
-    {0xba, 0x00},
-    {0xbb, 0x03},
-    {0xbc, 0x01},
-    {0xbd, 0x00},
-    {0xbe, 0x00},
-    {0xbf, 0x00},
-    {0xc0, 0x10},
-    {0xc1, 0x20},
-    {0xc2, 0x00},
-    {0xc3, 0x20},
-    {0xc4, 0x00},
-    {0xc5, 0x2c},
-    {0xc6, 0x1c},
-    {0xc7, 0x10},
-    {0xc8, 0x10},
-    {0xc9, 0x01},
-    {0xca, 0x68},
-    {0xcb, 0xa7},
-    {0xcc, 0x3c},
-    {0xcd, 0x09},
-    {0xce, 0x00},
-    {0xcf, 0x20},
-    {0xd0, 0x40},
-    {0xd1, 0x10},
-    {0xd2, 0x00},
-    {0xd3, 0x00},
-    {0xd4, 0x20},
-    {0xd5, 0x28},
-    {0xd6, 0xa0},
-    {0xd7, 0x2a},
-    {0xd8, 0x00},
-    {0xd9, 0x00},
-    {0xda, 0x00},
-    {0xdb, 0x00},
-    {0xdc, 0x00},
-    {0xdd, 0x00},
-    {0xde, 0x00},
-    {0xdf, 0x00},
-    {0xe0, 0x00},
-    {0xe1, 0xd3},
-    {0xe2, 0xc0},
-    {0xe3, 0x00},
-    {0xe4, 0x00},
-    {0xe5, 0x10},
-    {0xe6, 0x00},
-    {0xe7, 0x12},
-    {0xe8, 0x12},
-    {0xe9, 0x34},
-    {0xea, 0x00},
-    {0xeb, 0xff},
-    {0xec, 0x79},
-    {0xed, 0x20},
-    {0xee, 0x30},
-    {0xef, 0x01},
-    {0xf0, 0x00},
-    {0xf1, 0x3e},
-    {0xf2, 0x00},
-    {0xf3, 0x00},
-    {0xf4, 0x00},
-    {0xf5, 0x00},
-    {0xf6, 0x00},
-    {0xf7, 0x00},
-    {0xf8, 0x00},
-    {0xf9, 0x00},
-    {0xfa, 0x00},
-    {0xfb, 0x00},
-    {0xfc, 0x00},
-    {0xfd, 0x00},
-    {0xfe, 0x00},
-    {0xff, 0x00},
+       {0x00, 0x31},
+       {0x01, 0x00},
+       {0x02, 0x00},
+       {0x03, 0x00},
+       {0x04, 0x00},
+       {0x05, 0x81},
+       {0x06, 0x00},
+       {0x07, 0x00},
+       {0x08, 0x38},
+       {0x09, 0x45},
+       {0x0a, 0x28},
+       {0x0b, 0x76},
+       {0x0c, 0x00},
+       {0x0d, 0x00},
+       {0x0e, 0x80},
+       {0x0f, 0x00},
+       {0x10, 0x00},
+       {0x11, 0x00},
+       {0x12, 0x00},
+       {0x13, 0x00},
+       {0x14, 0x00},
+       {0x15, 0x00},
+       {0x16, 0x00},
+       {0x17, 0x00},
+       {0x18, 0x00},
+       {0x19, 0x00},
+       {0x1a, 0x00},
+       {0x1b, 0x8f},
+       {0x1c, 0x0f},
+       {0x1d, 0x00},
+       {0x1e, 0x00},
+       {0x1f, 0x00},
+       {0x20, 0x00},
+       {0x21, 0x00},
+       {0x22, 0x00},
+       {0x23, 0x00},
+       {0x24, 0x00},
+       {0x25, 0x4a},
+       {0x26, 0x00},
+       {0x27, 0x00},
+       {0x28, 0x00},
+       {0x29, 0x00},
+       {0x2a, 0x00},
+       {0x2b, 0x00},
+       {0x2c, 0x00},
+       {0x2d, 0x18},
+       {0x2e, 0x00},
+       {0x2f, 0x0a},
+       {0x30, 0x26},
+       {0x31, 0x5b},
+       {0x32, 0x00},
+       {0x33, 0x00},
+       {0x34, 0x00},
+       {0x35, 0x00},
+       {0x36, 0xaa},
+       {0x37, 0xaa},
+       {0x38, 0xff},
+       {0x39, 0xff},
+       {0x3a, 0x00},
+       {0x3b, 0x00},
+       {0x3c, 0x00},
+       {0x3d, 0x03},
+       {0x3e, 0x1d},
+       {0x3f, 0x04},
+       {0x40, 0x00},
+       {0x41, 0x08},
+       {0x42, 0x00},
+       {0x43, 0x08},
+       {0x44, 0x08},
+       {0x45, 0x14},
+       {0x46, 0x05},
+       {0x47, 0x09},
+       {0x48, 0x00},
+       {0x49, 0x00},
+       {0x4a, 0x00},
+       {0x4b, 0x00},
+       {0x4c, 0x09},
+       {0x4d, 0x90},
+       {0x4e, 0x00},
+       {0x4f, 0xc5},
+       {0x50, 0x15},
+       {0x51, 0x19},
+       {0x52, 0x00},
+       {0x53, 0x00},
+       {0x54, 0x00},
+       {0x55, 0x00},
+       {0x56, 0x00},
+       {0x57, 0x00},
+       {0x58, 0x00},
+       {0x59, 0xb0},
+       {0x5a, 0x00},
+       {0x5b, 0x00},
+       {0x5c, 0x00},
+       {0x5d, 0x00},
+       {0x5e, 0x00},
+       {0x5f, 0x00},
+       {0x60, 0xb3},
+       {0x61, 0x81},
+       {0x62, 0x00},
+       {0x63, 0x00},
+       {0x64, 0x00},
+       {0x65, 0x00},
+       {0x66, 0x57},
+       {0x67, 0x6c},
+       {0x68, 0x00},
+       {0x69, 0x00},
+       {0x6a, 0x00},
+       {0x6b, 0x00},
+       //{0x6c, 0x80},
+       {0x6c, 0x00}, //RobertYu:20050125, request by JJSue
+       {0x6d, 0x03},
+       {0x6e, 0x01},
+       {0x6f, 0x00},
+       {0x70, 0x00},
+       {0x71, 0x00},
+       {0x72, 0x00},
+       {0x73, 0x00},
+       {0x74, 0x00},
+       {0x75, 0x00},
+       {0x76, 0x00},
+       {0x77, 0x00},
+       {0x78, 0x00},
+       {0x79, 0x00},
+       {0x7a, 0x00},
+       {0x7b, 0x00},
+       {0x7c, 0x00},
+       {0x7d, 0x00},
+       {0x7e, 0x00},
+       {0x7f, 0x00},
+       {0x80, 0x8c},
+       {0x81, 0x00},
+       {0x82, 0x0e},
+       {0x83, 0x00},
+       {0x84, 0x00},
+       {0x85, 0x00},
+       {0x86, 0x00},
+       {0x87, 0x00},
+       {0x88, 0x08},
+       {0x89, 0x00},
+       {0x8a, 0x0e},
+       {0x8b, 0xa7},
+       {0x8c, 0x88},
+       {0x8d, 0x47},
+       {0x8e, 0xaa},
+       {0x8f, 0x02},
+       {0x90, 0x00},
+       {0x91, 0x00},
+       {0x92, 0x00},
+       {0x93, 0x00},
+       {0x94, 0x00},
+       {0x95, 0x00},
+       {0x96, 0x00},
+       {0x97, 0xe3},
+       {0x98, 0x00},
+       {0x99, 0x00},
+       {0x9a, 0x00},
+       {0x9b, 0x00},
+       {0x9c, 0x00},
+       {0x9d, 0x00},
+       {0x9e, 0x00},
+       {0x9f, 0x00},
+       {0xa0, 0x00},
+       {0xa1, 0x00},
+       {0xa2, 0x00},
+       {0xa3, 0x00},
+       {0xa4, 0x00},
+       {0xa5, 0x00},
+       {0xa6, 0x10},
+       {0xa7, 0x00},
+       {0xa8, 0x18},
+       {0xa9, 0x00},
+       {0xaa, 0x00},
+       {0xab, 0x00},
+       {0xac, 0x00},
+       {0xad, 0x00},
+       {0xae, 0x00},
+       {0xaf, 0x18},
+       {0xb0, 0x18},
+       {0xb1, 0x30},
+       {0xb2, 0x00},
+       {0xb3, 0x00},
+       {0xb4, 0x00},
+       {0xb5, 0x00},
+       {0xb6, 0x00},
+       {0xb7, 0x00},
+       {0xb8, 0x00},
+       {0xb9, 0x00},
+       {0xba, 0x00},
+       {0xbb, 0x03},
+       {0xbc, 0x01},
+       {0xbd, 0x00},
+       {0xbe, 0x00},
+       {0xbf, 0x00},
+       {0xc0, 0x10},
+       {0xc1, 0x20},
+       {0xc2, 0x00},
+       {0xc3, 0x20},
+       {0xc4, 0x00},
+       {0xc5, 0x2c},
+       {0xc6, 0x1c},
+       {0xc7, 0x10},
+       {0xc8, 0x10},
+       {0xc9, 0x01},
+       {0xca, 0x68},
+       {0xcb, 0xa7},
+       {0xcc, 0x3c},
+       {0xcd, 0x09},
+       {0xce, 0x00},
+       {0xcf, 0x20},
+       {0xd0, 0x40},
+       {0xd1, 0x10},
+       {0xd2, 0x00},
+       {0xd3, 0x00},
+       {0xd4, 0x20},
+       {0xd5, 0x28},
+       {0xd6, 0xa0},
+       {0xd7, 0x2a},
+       {0xd8, 0x00},
+       {0xd9, 0x00},
+       {0xda, 0x00},
+       {0xdb, 0x00},
+       {0xdc, 0x00},
+       {0xdd, 0x00},
+       {0xde, 0x00},
+       {0xdf, 0x00},
+       {0xe0, 0x00},
+       {0xe1, 0xd3},
+       {0xe2, 0xc0},
+       {0xe3, 0x00},
+       {0xe4, 0x00},
+       {0xe5, 0x10},
+       {0xe6, 0x00},
+       {0xe7, 0x12},
+       {0xe8, 0x12},
+       {0xe9, 0x34},
+       {0xea, 0x00},
+       {0xeb, 0xff},
+       {0xec, 0x79},
+       {0xed, 0x20},
+       {0xee, 0x30},
+       {0xef, 0x01},
+       {0xf0, 0x00},
+       {0xf1, 0x3e},
+       {0xf2, 0x00},
+       {0xf3, 0x00},
+       {0xf4, 0x00},
+       {0xf5, 0x00},
+       {0xf6, 0x00},
+       {0xf7, 0x00},
+       {0xf8, 0x00},
+       {0xf9, 0x00},
+       {0xfa, 0x00},
+       {0xfb, 0x00},
+       {0xfc, 0x00},
+       {0xfd, 0x00},
+       {0xfe, 0x00},
+       {0xff, 0x00},
 };
 
 #define CB_VT3253B0_AGC 193
 // For AIROHA
 unsigned char byVT3253B0_AGC[CB_VT3253B0_AGC][2] = {
-    {0xF0, 0x00},
-    {0xF1, 0x00},
-    {0xF0, 0x80},
-    {0xF0, 0x01},
-    {0xF1, 0x00},
-    {0xF0, 0x81},
-    {0xF0, 0x02},
-    {0xF1, 0x02},
-    {0xF0, 0x82},
-    {0xF0, 0x03},
-    {0xF1, 0x04},
-    {0xF0, 0x83},
-    {0xF0, 0x03},
-    {0xF1, 0x04},
-    {0xF0, 0x84},
-    {0xF0, 0x04},
-    {0xF1, 0x06},
-    {0xF0, 0x85},
-    {0xF0, 0x05},
-    {0xF1, 0x06},
-    {0xF0, 0x86},
-    {0xF0, 0x06},
-    {0xF1, 0x06},
-    {0xF0, 0x87},
-    {0xF0, 0x07},
-    {0xF1, 0x08},
-    {0xF0, 0x88},
-    {0xF0, 0x08},
-    {0xF1, 0x08},
-    {0xF0, 0x89},
-    {0xF0, 0x09},
-    {0xF1, 0x0A},
-    {0xF0, 0x8A},
-    {0xF0, 0x0A},
-    {0xF1, 0x0A},
-    {0xF0, 0x8B},
-    {0xF0, 0x0B},
-    {0xF1, 0x0C},
-    {0xF0, 0x8C},
-    {0xF0, 0x0C},
-    {0xF1, 0x0C},
-    {0xF0, 0x8D},
-    {0xF0, 0x0D},
-    {0xF1, 0x0E},
-    {0xF0, 0x8E},
-    {0xF0, 0x0E},
-    {0xF1, 0x0E},
-    {0xF0, 0x8F},
-    {0xF0, 0x0F},
-    {0xF1, 0x10},
-    {0xF0, 0x90},
-    {0xF0, 0x10},
-    {0xF1, 0x10},
-    {0xF0, 0x91},
-    {0xF0, 0x11},
-    {0xF1, 0x12},
-    {0xF0, 0x92},
-    {0xF0, 0x12},
-    {0xF1, 0x12},
-    {0xF0, 0x93},
-    {0xF0, 0x13},
-    {0xF1, 0x14},
-    {0xF0, 0x94},
-    {0xF0, 0x14},
-    {0xF1, 0x14},
-    {0xF0, 0x95},
-    {0xF0, 0x15},
-    {0xF1, 0x16},
-    {0xF0, 0x96},
-    {0xF0, 0x16},
-    {0xF1, 0x16},
-    {0xF0, 0x97},
-    {0xF0, 0x17},
-    {0xF1, 0x18},
-    {0xF0, 0x98},
-    {0xF0, 0x18},
-    {0xF1, 0x18},
-    {0xF0, 0x99},
-    {0xF0, 0x19},
-    {0xF1, 0x1A},
-    {0xF0, 0x9A},
-    {0xF0, 0x1A},
-    {0xF1, 0x1A},
-    {0xF0, 0x9B},
-    {0xF0, 0x1B},
-    {0xF1, 0x1C},
-    {0xF0, 0x9C},
-    {0xF0, 0x1C},
-    {0xF1, 0x1C},
-    {0xF0, 0x9D},
-    {0xF0, 0x1D},
-    {0xF1, 0x1E},
-    {0xF0, 0x9E},
-    {0xF0, 0x1E},
-    {0xF1, 0x1E},
-    {0xF0, 0x9F},
-    {0xF0, 0x1F},
-    {0xF1, 0x20},
-    {0xF0, 0xA0},
-    {0xF0, 0x20},
-    {0xF1, 0x20},
-    {0xF0, 0xA1},
-    {0xF0, 0x21},
-    {0xF1, 0x22},
-    {0xF0, 0xA2},
-    {0xF0, 0x22},
-    {0xF1, 0x22},
-    {0xF0, 0xA3},
-    {0xF0, 0x23},
-    {0xF1, 0x24},
-    {0xF0, 0xA4},
-    {0xF0, 0x24},
-    {0xF1, 0x24},
-    {0xF0, 0xA5},
-    {0xF0, 0x25},
-    {0xF1, 0x26},
-    {0xF0, 0xA6},
-    {0xF0, 0x26},
-    {0xF1, 0x26},
-    {0xF0, 0xA7},
-    {0xF0, 0x27},
-    {0xF1, 0x28},
-    {0xF0, 0xA8},
-    {0xF0, 0x28},
-    {0xF1, 0x28},
-    {0xF0, 0xA9},
-    {0xF0, 0x29},
-    {0xF1, 0x2A},
-    {0xF0, 0xAA},
-    {0xF0, 0x2A},
-    {0xF1, 0x2A},
-    {0xF0, 0xAB},
-    {0xF0, 0x2B},
-    {0xF1, 0x2C},
-    {0xF0, 0xAC},
-    {0xF0, 0x2C},
-    {0xF1, 0x2C},
-    {0xF0, 0xAD},
-    {0xF0, 0x2D},
-    {0xF1, 0x2E},
-    {0xF0, 0xAE},
-    {0xF0, 0x2E},
-    {0xF1, 0x2E},
-    {0xF0, 0xAF},
-    {0xF0, 0x2F},
-    {0xF1, 0x30},
-    {0xF0, 0xB0},
-    {0xF0, 0x30},
-    {0xF1, 0x30},
-    {0xF0, 0xB1},
-    {0xF0, 0x31},
-    {0xF1, 0x32},
-    {0xF0, 0xB2},
-    {0xF0, 0x32},
-    {0xF1, 0x32},
-    {0xF0, 0xB3},
-    {0xF0, 0x33},
-    {0xF1, 0x34},
-    {0xF0, 0xB4},
-    {0xF0, 0x34},
-    {0xF1, 0x34},
-    {0xF0, 0xB5},
-    {0xF0, 0x35},
-    {0xF1, 0x36},
-    {0xF0, 0xB6},
-    {0xF0, 0x36},
-    {0xF1, 0x36},
-    {0xF0, 0xB7},
-    {0xF0, 0x37},
-    {0xF1, 0x38},
-    {0xF0, 0xB8},
-    {0xF0, 0x38},
-    {0xF1, 0x38},
-    {0xF0, 0xB9},
-    {0xF0, 0x39},
-    {0xF1, 0x3A},
-    {0xF0, 0xBA},
-    {0xF0, 0x3A},
-    {0xF1, 0x3A},
-    {0xF0, 0xBB},
-    {0xF0, 0x3B},
-    {0xF1, 0x3C},
-    {0xF0, 0xBC},
-    {0xF0, 0x3C},
-    {0xF1, 0x3C},
-    {0xF0, 0xBD},
-    {0xF0, 0x3D},
-    {0xF1, 0x3E},
-    {0xF0, 0xBE},
-    {0xF0, 0x3E},
-    {0xF1, 0x3E},
-    {0xF0, 0xBF},
-    {0xF0, 0x00},
+       {0xF0, 0x00},
+       {0xF1, 0x00},
+       {0xF0, 0x80},
+       {0xF0, 0x01},
+       {0xF1, 0x00},
+       {0xF0, 0x81},
+       {0xF0, 0x02},
+       {0xF1, 0x02},
+       {0xF0, 0x82},
+       {0xF0, 0x03},
+       {0xF1, 0x04},
+       {0xF0, 0x83},
+       {0xF0, 0x03},
+       {0xF1, 0x04},
+       {0xF0, 0x84},
+       {0xF0, 0x04},
+       {0xF1, 0x06},
+       {0xF0, 0x85},
+       {0xF0, 0x05},
+       {0xF1, 0x06},
+       {0xF0, 0x86},
+       {0xF0, 0x06},
+       {0xF1, 0x06},
+       {0xF0, 0x87},
+       {0xF0, 0x07},
+       {0xF1, 0x08},
+       {0xF0, 0x88},
+       {0xF0, 0x08},
+       {0xF1, 0x08},
+       {0xF0, 0x89},
+       {0xF0, 0x09},
+       {0xF1, 0x0A},
+       {0xF0, 0x8A},
+       {0xF0, 0x0A},
+       {0xF1, 0x0A},
+       {0xF0, 0x8B},
+       {0xF0, 0x0B},
+       {0xF1, 0x0C},
+       {0xF0, 0x8C},
+       {0xF0, 0x0C},
+       {0xF1, 0x0C},
+       {0xF0, 0x8D},
+       {0xF0, 0x0D},
+       {0xF1, 0x0E},
+       {0xF0, 0x8E},
+       {0xF0, 0x0E},
+       {0xF1, 0x0E},
+       {0xF0, 0x8F},
+       {0xF0, 0x0F},
+       {0xF1, 0x10},
+       {0xF0, 0x90},
+       {0xF0, 0x10},
+       {0xF1, 0x10},
+       {0xF0, 0x91},
+       {0xF0, 0x11},
+       {0xF1, 0x12},
+       {0xF0, 0x92},
+       {0xF0, 0x12},
+       {0xF1, 0x12},
+       {0xF0, 0x93},
+       {0xF0, 0x13},
+       {0xF1, 0x14},
+       {0xF0, 0x94},
+       {0xF0, 0x14},
+       {0xF1, 0x14},
+       {0xF0, 0x95},
+       {0xF0, 0x15},
+       {0xF1, 0x16},
+       {0xF0, 0x96},
+       {0xF0, 0x16},
+       {0xF1, 0x16},
+       {0xF0, 0x97},
+       {0xF0, 0x17},
+       {0xF1, 0x18},
+       {0xF0, 0x98},
+       {0xF0, 0x18},
+       {0xF1, 0x18},
+       {0xF0, 0x99},
+       {0xF0, 0x19},
+       {0xF1, 0x1A},
+       {0xF0, 0x9A},
+       {0xF0, 0x1A},
+       {0xF1, 0x1A},
+       {0xF0, 0x9B},
+       {0xF0, 0x1B},
+       {0xF1, 0x1C},
+       {0xF0, 0x9C},
+       {0xF0, 0x1C},
+       {0xF1, 0x1C},
+       {0xF0, 0x9D},
+       {0xF0, 0x1D},
+       {0xF1, 0x1E},
+       {0xF0, 0x9E},
+       {0xF0, 0x1E},
+       {0xF1, 0x1E},
+       {0xF0, 0x9F},
+       {0xF0, 0x1F},
+       {0xF1, 0x20},
+       {0xF0, 0xA0},
+       {0xF0, 0x20},
+       {0xF1, 0x20},
+       {0xF0, 0xA1},
+       {0xF0, 0x21},
+       {0xF1, 0x22},
+       {0xF0, 0xA2},
+       {0xF0, 0x22},
+       {0xF1, 0x22},
+       {0xF0, 0xA3},
+       {0xF0, 0x23},
+       {0xF1, 0x24},
+       {0xF0, 0xA4},
+       {0xF0, 0x24},
+       {0xF1, 0x24},
+       {0xF0, 0xA5},
+       {0xF0, 0x25},
+       {0xF1, 0x26},
+       {0xF0, 0xA6},
+       {0xF0, 0x26},
+       {0xF1, 0x26},
+       {0xF0, 0xA7},
+       {0xF0, 0x27},
+       {0xF1, 0x28},
+       {0xF0, 0xA8},
+       {0xF0, 0x28},
+       {0xF1, 0x28},
+       {0xF0, 0xA9},
+       {0xF0, 0x29},
+       {0xF1, 0x2A},
+       {0xF0, 0xAA},
+       {0xF0, 0x2A},
+       {0xF1, 0x2A},
+       {0xF0, 0xAB},
+       {0xF0, 0x2B},
+       {0xF1, 0x2C},
+       {0xF0, 0xAC},
+       {0xF0, 0x2C},
+       {0xF1, 0x2C},
+       {0xF0, 0xAD},
+       {0xF0, 0x2D},
+       {0xF1, 0x2E},
+       {0xF0, 0xAE},
+       {0xF0, 0x2E},
+       {0xF1, 0x2E},
+       {0xF0, 0xAF},
+       {0xF0, 0x2F},
+       {0xF1, 0x30},
+       {0xF0, 0xB0},
+       {0xF0, 0x30},
+       {0xF1, 0x30},
+       {0xF0, 0xB1},
+       {0xF0, 0x31},
+       {0xF1, 0x32},
+       {0xF0, 0xB2},
+       {0xF0, 0x32},
+       {0xF1, 0x32},
+       {0xF0, 0xB3},
+       {0xF0, 0x33},
+       {0xF1, 0x34},
+       {0xF0, 0xB4},
+       {0xF0, 0x34},
+       {0xF1, 0x34},
+       {0xF0, 0xB5},
+       {0xF0, 0x35},
+       {0xF1, 0x36},
+       {0xF0, 0xB6},
+       {0xF0, 0x36},
+       {0xF1, 0x36},
+       {0xF0, 0xB7},
+       {0xF0, 0x37},
+       {0xF1, 0x38},
+       {0xF0, 0xB8},
+       {0xF0, 0x38},
+       {0xF1, 0x38},
+       {0xF0, 0xB9},
+       {0xF0, 0x39},
+       {0xF1, 0x3A},
+       {0xF0, 0xBA},
+       {0xF0, 0x3A},
+       {0xF1, 0x3A},
+       {0xF0, 0xBB},
+       {0xF0, 0x3B},
+       {0xF1, 0x3C},
+       {0xF0, 0xBC},
+       {0xF0, 0x3C},
+       {0xF1, 0x3C},
+       {0xF0, 0xBD},
+       {0xF0, 0x3D},
+       {0xF1, 0x3E},
+       {0xF0, 0xBE},
+       {0xF0, 0x3E},
+       {0xF1, 0x3E},
+       {0xF0, 0xBF},
+       {0xF0, 0x00},
 };
 
 const unsigned short awcFrameTime[MAX_RATE] =
 {10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216};
 
-
 /*---------------------  Static Functions  --------------------------*/
 
 static
@@ -1723,42 +1718,37 @@ s_ulGetRatio(PSDevice pDevice);
 static
 void
 s_vChangeAntenna(
-    PSDevice pDevice
-    );
+       PSDevice pDevice
+);
 
 static
 void
-s_vChangeAntenna (
-    PSDevice pDevice
-    )
+s_vChangeAntenna(
+       PSDevice pDevice
+)
 {
-
-#ifdef PLICE_DEBUG
-       //printk("Enter s_vChangeAntenna:original RxMode is %d,TxMode is %d\n",pDevice->byRxAntennaMode,pDevice->byTxAntennaMode);
-#endif
-    if ( pDevice->dwRxAntennaSel == 0) {
-        pDevice->dwRxAntennaSel=1;
-        if (pDevice->bTxRxAntInv == true)
-            BBvSetRxAntennaMode(pDevice->PortOffset, ANT_A);
-        else
-            BBvSetRxAntennaMode(pDevice->PortOffset, ANT_B);
-    } else {
-        pDevice->dwRxAntennaSel=0;
-        if (pDevice->bTxRxAntInv == true)
-            BBvSetRxAntennaMode(pDevice->PortOffset, ANT_B);
-        else
-            BBvSetRxAntennaMode(pDevice->PortOffset, ANT_A);
-    }
-    if ( pDevice->dwTxAntennaSel == 0) {
-        pDevice->dwTxAntennaSel=1;
-        BBvSetTxAntennaMode(pDevice->PortOffset, ANT_B);
-    } else {
-        pDevice->dwTxAntennaSel=0;
-        BBvSetTxAntennaMode(pDevice->PortOffset, ANT_A);
-    }
+       if (pDevice->dwRxAntennaSel == 0) {
+               pDevice->dwRxAntennaSel = 1;
+               if (pDevice->bTxRxAntInv == true)
+                       BBvSetRxAntennaMode(pDevice->PortOffset, ANT_A);
+               else
+                       BBvSetRxAntennaMode(pDevice->PortOffset, ANT_B);
+       } else {
+               pDevice->dwRxAntennaSel = 0;
+               if (pDevice->bTxRxAntInv == true)
+                       BBvSetRxAntennaMode(pDevice->PortOffset, ANT_B);
+               else
+                       BBvSetRxAntennaMode(pDevice->PortOffset, ANT_A);
+       }
+       if (pDevice->dwTxAntennaSel == 0) {
+               pDevice->dwTxAntennaSel = 1;
+               BBvSetTxAntennaMode(pDevice->PortOffset, ANT_B);
+       } else {
+               pDevice->dwTxAntennaSel = 0;
+               BBvSetTxAntennaMode(pDevice->PortOffset, ANT_A);
+       }
 }
 
-
 /*---------------------  Export Variables  --------------------------*/
 /*
  * Description: Calculate data frame transmitting time
@@ -1775,54 +1765,52 @@ s_vChangeAntenna (
  *
  */
 unsigned int
-BBuGetFrameTime (
-    unsigned char byPreambleType,
-    unsigned char byPktType,
-    unsigned int cbFrameLength,
-    unsigned short wRate
-    )
+BBuGetFrameTime(
+       unsigned char byPreambleType,
+       unsigned char byPktType,
+       unsigned int cbFrameLength,
+       unsigned short wRate
+)
 {
-    unsigned int uFrameTime;
-    unsigned int uPreamble;
-    unsigned int uTmp;
-    unsigned int uRateIdx = (unsigned int) wRate;
-    unsigned int uRate = 0;
-
-
-    if (uRateIdx > RATE_54M) {
-           ASSERT(0);
-        return 0;
-    }
-
-    uRate = (unsigned int) awcFrameTime[uRateIdx];
-
-    if (uRateIdx <= 3) {          //CCK mode
-
-        if (byPreambleType == 1) {//Short
-            uPreamble = 96;
-        } else {
-            uPreamble = 192;
-        }
-        uFrameTime = (cbFrameLength * 80) / uRate;  //?????
-        uTmp = (uFrameTime * uRate) / 80;
-        if (cbFrameLength != uTmp) {
-            uFrameTime ++;
-        }
-
-        return (uPreamble + uFrameTime);
-    }
-    else {
-        uFrameTime = (cbFrameLength * 8 + 22) / uRate;   //????????
-        uTmp = ((uFrameTime * uRate) - 22) / 8;
-        if(cbFrameLength != uTmp) {
-            uFrameTime ++;
-        }
-        uFrameTime = uFrameTime * 4;    //???????
-        if(byPktType != PK_TYPE_11A) {
-            uFrameTime += 6;     //??????
-        }
-        return (20 + uFrameTime); //??????
-    }
+       unsigned int uFrameTime;
+       unsigned int uPreamble;
+       unsigned int uTmp;
+       unsigned int uRateIdx = (unsigned int) wRate;
+       unsigned int uRate = 0;
+
+       if (uRateIdx > RATE_54M) {
+               ASSERT(0);
+               return 0;
+       }
+
+       uRate = (unsigned int)awcFrameTime[uRateIdx];
+
+       if (uRateIdx <= 3) {          //CCK mode
+
+               if (byPreambleType == 1) {//Short
+                       uPreamble = 96;
+               } else {
+                       uPreamble = 192;
+               }
+               uFrameTime = (cbFrameLength * 80) / uRate;  //?????
+               uTmp = (uFrameTime * uRate) / 80;
+               if (cbFrameLength != uTmp) {
+                       uFrameTime++;
+               }
+
+               return uPreamble + uFrameTime;
+       } else {
+               uFrameTime = (cbFrameLength * 8 + 22) / uRate;   //????????
+               uTmp = ((uFrameTime * uRate) - 22) / 8;
+               if (cbFrameLength != uTmp) {
+                       uFrameTime++;
+               }
+               uFrameTime = uFrameTime * 4;    //???????
+               if (byPktType != PK_TYPE_11A) {
+                       uFrameTime += 6;     //??????
+               }
+               return 20 + uFrameTime; //??????
+       }
 }
 
 /*
@@ -1842,162 +1830,152 @@ BBuGetFrameTime (
  *
  */
 void
-BBvCalculateParameter (
-    PSDevice pDevice,
-    unsigned int cbFrameLength,
-    unsigned short wRate,
-    unsigned char byPacketType,
-    unsigned short *pwPhyLen,
-    unsigned char *pbyPhySrv,
-    unsigned char *pbyPhySgn
-    )
+BBvCalculateParameter(
+       PSDevice pDevice,
+       unsigned int cbFrameLength,
+       unsigned short wRate,
+       unsigned char byPacketType,
+       unsigned short *pwPhyLen,
+       unsigned char *pbyPhySrv,
+       unsigned char *pbyPhySgn
+)
 {
-    unsigned int cbBitCount;
-    unsigned int cbUsCount = 0;
-    unsigned int cbTmp;
-    bool bExtBit;
-    unsigned char byPreambleType = pDevice->byPreambleType;
-    bool bCCK = pDevice->bCCK;
-
-    cbBitCount = cbFrameLength * 8;
-    bExtBit = false;
-
-    switch (wRate) {
-    case RATE_1M :
-        cbUsCount = cbBitCount;
-        *pbyPhySgn = 0x00;
-        break;
-
-    case RATE_2M :
-        cbUsCount = cbBitCount / 2;
-        if (byPreambleType == 1)
-            *pbyPhySgn = 0x09;
-        else // long preamble
-            *pbyPhySgn = 0x01;
-        break;
-
-    case RATE_5M :
-        if (bCCK == false)
-            cbBitCount ++;
-        cbUsCount = (cbBitCount * 10) / 55;
-        cbTmp = (cbUsCount * 55) / 10;
-        if (cbTmp != cbBitCount)
-            cbUsCount ++;
-        if (byPreambleType == 1)
-            *pbyPhySgn = 0x0a;
-        else // long preamble
-            *pbyPhySgn = 0x02;
-        break;
-
-    case RATE_11M :
-
-        if (bCCK == false)
-            cbBitCount ++;
-        cbUsCount = cbBitCount / 11;
-        cbTmp = cbUsCount * 11;
-        if (cbTmp != cbBitCount) {
-            cbUsCount ++;
-            if ((cbBitCount - cbTmp) <= 3)
-                bExtBit = true;
-        }
-        if (byPreambleType == 1)
-            *pbyPhySgn = 0x0b;
-        else // long preamble
-            *pbyPhySgn = 0x03;
-        break;
-
-    case RATE_6M :
-        if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
-            *pbyPhySgn = 0x9B; //1001 1011
-        }
-        else {//11g, 2.4GHZ
-            *pbyPhySgn = 0x8B; //1000 1011
-        }
-        break;
-
-    case RATE_9M :
-        if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
-            *pbyPhySgn = 0x9F; //1001 1111
-        }
-        else {//11g, 2.4GHZ
-            *pbyPhySgn = 0x8F; //1000 1111
-        }
-        break;
-
-    case RATE_12M :
-        if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
-            *pbyPhySgn = 0x9A; //1001 1010
-        }
-        else {//11g, 2.4GHZ
-            *pbyPhySgn = 0x8A; //1000 1010
-        }
-        break;
-
-    case RATE_18M :
-        if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
-            *pbyPhySgn = 0x9E; //1001 1110
-        }
-        else {//11g, 2.4GHZ
-            *pbyPhySgn = 0x8E; //1000 1110
-        }
-        break;
-
-    case RATE_24M :
-        if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
-            *pbyPhySgn = 0x99; //1001 1001
-        }
-        else {//11g, 2.4GHZ
-            *pbyPhySgn = 0x89; //1000 1001
-        }
-        break;
-
-    case RATE_36M :
-        if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
-            *pbyPhySgn = 0x9D; //1001 1101
-        }
-        else {//11g, 2.4GHZ
-            *pbyPhySgn = 0x8D; //1000 1101
-        }
-        break;
-
-    case RATE_48M :
-        if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
-            *pbyPhySgn = 0x98; //1001 1000
-        }
-        else {//11g, 2.4GHZ
-            *pbyPhySgn = 0x88; //1000 1000
-        }
-        break;
-
-    case RATE_54M :
-        if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
-            *pbyPhySgn = 0x9C; //1001 1100
-        }
-        else {//11g, 2.4GHZ
-            *pbyPhySgn = 0x8C; //1000 1100
-        }
-        break;
-
-    default :
-        if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
-            *pbyPhySgn = 0x9C; //1001 1100
-        }
-        else {//11g, 2.4GHZ
-            *pbyPhySgn = 0x8C; //1000 1100
-        }
-        break;
-    }
-
-    if (byPacketType == PK_TYPE_11B) {
-        *pbyPhySrv = 0x00;
-        if (bExtBit)
-            *pbyPhySrv = *pbyPhySrv | 0x80;
-        *pwPhyLen = (unsigned short)cbUsCount;
-    }
-    else {
-        *pbyPhySrv = 0x00;
-        *pwPhyLen = (unsigned short)cbFrameLength;
-    }
+       unsigned int cbBitCount;
+       unsigned int cbUsCount = 0;
+       unsigned int cbTmp;
+       bool bExtBit;
+       unsigned char byPreambleType = pDevice->byPreambleType;
+       bool bCCK = pDevice->bCCK;
+
+       cbBitCount = cbFrameLength * 8;
+       bExtBit = false;
+
+       switch (wRate) {
+       case RATE_1M:
+               cbUsCount = cbBitCount;
+               *pbyPhySgn = 0x00;
+               break;
+
+       case RATE_2M:
+               cbUsCount = cbBitCount / 2;
+               if (byPreambleType == 1)
+                       *pbyPhySgn = 0x09;
+               else // long preamble
+                       *pbyPhySgn = 0x01;
+               break;
+
+       case RATE_5M:
+               if (bCCK == false)
+                       cbBitCount++;
+               cbUsCount = (cbBitCount * 10) / 55;
+               cbTmp = (cbUsCount * 55) / 10;
+               if (cbTmp != cbBitCount)
+                       cbUsCount++;
+               if (byPreambleType == 1)
+                       *pbyPhySgn = 0x0a;
+               else // long preamble
+                       *pbyPhySgn = 0x02;
+               break;
+
+       case RATE_11M:
+
+               if (bCCK == false)
+                       cbBitCount++;
+               cbUsCount = cbBitCount / 11;
+               cbTmp = cbUsCount * 11;
+               if (cbTmp != cbBitCount) {
+                       cbUsCount++;
+                       if ((cbBitCount - cbTmp) <= 3)
+                               bExtBit = true;
+               }
+               if (byPreambleType == 1)
+                       *pbyPhySgn = 0x0b;
+               else // long preamble
+                       *pbyPhySgn = 0x03;
+               break;
+
+       case RATE_6M:
+               if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
+                       *pbyPhySgn = 0x9B; //1001 1011
+               } else {//11g, 2.4GHZ
+                       *pbyPhySgn = 0x8B; //1000 1011
+               }
+               break;
+
+       case RATE_9M:
+               if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
+                       *pbyPhySgn = 0x9F; //1001 1111
+               } else {//11g, 2.4GHZ
+                       *pbyPhySgn = 0x8F; //1000 1111
+               }
+               break;
+
+       case RATE_12M:
+               if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
+                       *pbyPhySgn = 0x9A; //1001 1010
+               } else {//11g, 2.4GHZ
+                       *pbyPhySgn = 0x8A; //1000 1010
+               }
+               break;
+
+       case RATE_18M:
+               if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
+                       *pbyPhySgn = 0x9E; //1001 1110
+               } else {//11g, 2.4GHZ
+                       *pbyPhySgn = 0x8E; //1000 1110
+               }
+               break;
+
+       case RATE_24M:
+               if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
+                       *pbyPhySgn = 0x99; //1001 1001
+               } else {//11g, 2.4GHZ
+                       *pbyPhySgn = 0x89; //1000 1001
+               }
+               break;
+
+       case RATE_36M:
+               if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
+                       *pbyPhySgn = 0x9D; //1001 1101
+               } else {//11g, 2.4GHZ
+                       *pbyPhySgn = 0x8D; //1000 1101
+               }
+               break;
+
+       case RATE_48M:
+               if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
+                       *pbyPhySgn = 0x98; //1001 1000
+               } else {//11g, 2.4GHZ
+                       *pbyPhySgn = 0x88; //1000 1000
+               }
+               break;
+
+       case RATE_54M:
+               if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
+                       *pbyPhySgn = 0x9C; //1001 1100
+               } else {//11g, 2.4GHZ
+                       *pbyPhySgn = 0x8C; //1000 1100
+               }
+               break;
+
+       default:
+               if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
+                       *pbyPhySgn = 0x9C; //1001 1100
+               } else {//11g, 2.4GHZ
+                       *pbyPhySgn = 0x8C; //1000 1100
+               }
+               break;
+       }
+
+       if (byPacketType == PK_TYPE_11B) {
+               *pbyPhySrv = 0x00;
+               if (bExtBit)
+                       *pbyPhySrv = *pbyPhySrv | 0x80;
+               *pwPhyLen = (unsigned short)cbUsCount;
+       } else {
+               *pbyPhySrv = 0x00;
+               *pwPhyLen = (unsigned short)cbFrameLength;
+       }
 }
 
 /*
@@ -2013,35 +1991,34 @@ BBvCalculateParameter (
  * Return Value: true if succeeded; false if failed.
  *
  */
-bool BBbReadEmbedded (unsigned long dwIoBase, unsigned char byBBAddr, unsigned char *pbyData)
+bool BBbReadEmbedded(unsigned long dwIoBase, unsigned char byBBAddr, unsigned char *pbyData)
 {
-    unsigned short ww;
-    unsigned char byValue;
-
-    // BB reg offset
-    VNSvOutPortB(dwIoBase + MAC_REG_BBREGADR, byBBAddr);
-
-    // turn on REGR
-    MACvRegBitsOn(dwIoBase, MAC_REG_BBREGCTL, BBREGCTL_REGR);
-    // W_MAX_TIMEOUT is the timeout period
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_BBREGCTL, &byValue);
-        if (byValue & BBREGCTL_DONE)
-            break;
-    }
-
-    // get BB data
-    VNSvInPortB(dwIoBase + MAC_REG_BBREGDATA, pbyData);
-
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x30);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x30)\n");
-        return false;
-    }
-    return true;
+       unsigned short ww;
+       unsigned char byValue;
+
+       // BB reg offset
+       VNSvOutPortB(dwIoBase + MAC_REG_BBREGADR, byBBAddr);
+
+       // turn on REGR
+       MACvRegBitsOn(dwIoBase, MAC_REG_BBREGCTL, BBREGCTL_REGR);
+       // W_MAX_TIMEOUT is the timeout period
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_BBREGCTL, &byValue);
+               if (byValue & BBREGCTL_DONE)
+                       break;
+       }
+
+       // get BB data
+       VNSvInPortB(dwIoBase + MAC_REG_BBREGDATA, pbyData);
+
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x30);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x30)\n");
+               return false;
+       }
+       return true;
 }
 
-
 /*
  * Description: Write a Byte to BASEBAND, by embedded programming
  *
@@ -2056,34 +2033,33 @@ bool BBbReadEmbedded (unsigned long dwIoBase, unsigned char byBBAddr, unsigned c
  * Return Value: true if succeeded; false if failed.
  *
  */
-bool BBbWriteEmbedded (unsigned long dwIoBase, unsigned char byBBAddr, unsigned char byData)
+bool BBbWriteEmbedded(unsigned long dwIoBase, unsigned char byBBAddr, unsigned char byData)
 {
-    unsigned short ww;
-    unsigned char byValue;
-
-    // BB reg offset
-    VNSvOutPortB(dwIoBase + MAC_REG_BBREGADR, byBBAddr);
-    // set BB data
-    VNSvOutPortB(dwIoBase + MAC_REG_BBREGDATA, byData);
-
-    // turn on BBREGCTL_REGW
-    MACvRegBitsOn(dwIoBase, MAC_REG_BBREGCTL, BBREGCTL_REGW);
-    // W_MAX_TIMEOUT is the timeout period
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_BBREGCTL, &byValue);
-        if (byValue & BBREGCTL_DONE)
-            break;
-    }
-
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x31);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x31)\n");
-        return false;
-    }
-    return true;
+       unsigned short ww;
+       unsigned char byValue;
+
+       // BB reg offset
+       VNSvOutPortB(dwIoBase + MAC_REG_BBREGADR, byBBAddr);
+       // set BB data
+       VNSvOutPortB(dwIoBase + MAC_REG_BBREGDATA, byData);
+
+       // turn on BBREGCTL_REGW
+       MACvRegBitsOn(dwIoBase, MAC_REG_BBREGCTL, BBREGCTL_REGW);
+       // W_MAX_TIMEOUT is the timeout period
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_BBREGCTL, &byValue);
+               if (byValue & BBREGCTL_DONE)
+                       break;
+       }
+
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x31);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x31)\n");
+               return false;
+       }
+       return true;
 }
 
-
 /*
  * Description: Test if all bits are set for the Baseband register
  *
@@ -2098,15 +2074,14 @@ bool BBbWriteEmbedded (unsigned long dwIoBase, unsigned char byBBAddr, unsigned
  * Return Value: true if all TestBits are set; false otherwise.
  *
  */
-bool BBbIsRegBitsOn (unsigned long dwIoBase, unsigned char byBBAddr, unsigned char byTestBits)
+bool BBbIsRegBitsOn(unsigned long dwIoBase, unsigned char byBBAddr, unsigned char byTestBits)
 {
-    unsigned char byOrgData;
+       unsigned char byOrgData;
 
-    BBbReadEmbedded(dwIoBase, byBBAddr, &byOrgData);
-    return (byOrgData & byTestBits) == byTestBits;
+       BBbReadEmbedded(dwIoBase, byBBAddr, &byOrgData);
+       return (byOrgData & byTestBits) == byTestBits;
 }
 
-
 /*
  * Description: Test if all bits are clear for the Baseband register
  *
@@ -2121,12 +2096,12 @@ bool BBbIsRegBitsOn (unsigned long dwIoBase, unsigned char byBBAddr, unsigned ch
  * Return Value: true if all TestBits are clear; false otherwise.
  *
  */
-bool BBbIsRegBitsOff (unsigned long dwIoBase, unsigned char byBBAddr, unsigned char byTestBits)
+bool BBbIsRegBitsOff(unsigned long dwIoBase, unsigned char byBBAddr, unsigned char byTestBits)
 {
-    unsigned char byOrgData;
+       unsigned char byOrgData;
 
-    BBbReadEmbedded(dwIoBase, byBBAddr, &byOrgData);
-    return (byOrgData & byTestBits) == 0;
+       BBbReadEmbedded(dwIoBase, byBBAddr, &byOrgData);
+       return (byOrgData & byTestBits) == 0;
 }
 
 /*
@@ -2144,168 +2119,166 @@ bool BBbIsRegBitsOff (unsigned long dwIoBase, unsigned char byBBAddr, unsigned c
  *
  */
 
-bool BBbVT3253Init (PSDevice pDevice)
+bool BBbVT3253Init(PSDevice pDevice)
 {
-    bool bResult = true;
-    int        ii;
-    unsigned long dwIoBase = pDevice->PortOffset;
-    unsigned char byRFType = pDevice->byRFType;
-    unsigned char byLocalID = pDevice->byLocalID;
-
-    if (byRFType == RF_RFMD2959) {
-        if (byLocalID <= REV_ID_VT3253_A1) {
-            for (ii = 0; ii < CB_VT3253_INIT_FOR_RFMD; ii++) {
-                bResult &= BBbWriteEmbedded(dwIoBase,byVT3253InitTab_RFMD[ii][0],byVT3253InitTab_RFMD[ii][1]);
-            }
-        } else {
-            for (ii = 0; ii < CB_VT3253B0_INIT_FOR_RFMD; ii++) {
-                bResult &= BBbWriteEmbedded(dwIoBase,byVT3253B0_RFMD[ii][0],byVT3253B0_RFMD[ii][1]);
-            }
-            for (ii = 0; ii < CB_VT3253B0_AGC_FOR_RFMD2959; ii++) {
-                   bResult &= BBbWriteEmbedded(dwIoBase,byVT3253B0_AGC4_RFMD2959[ii][0],byVT3253B0_AGC4_RFMD2959[ii][1]);
-            }
-            VNSvOutPortD(dwIoBase + MAC_REG_ITRTMSET, 0x23);
-            MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT0);
-        }
-        pDevice->abyBBVGA[0] = 0x18;
-        pDevice->abyBBVGA[1] = 0x0A;
-        pDevice->abyBBVGA[2] = 0x0;
-        pDevice->abyBBVGA[3] = 0x0;
-        pDevice->ldBmThreshold[0] = -70;
-        pDevice->ldBmThreshold[1] = -50;
-        pDevice->ldBmThreshold[2] = 0;
-        pDevice->ldBmThreshold[3] = 0;
-    } else if ((byRFType == RF_AIROHA) || (byRFType == RF_AL2230S) ) {
-        for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) {
-           bResult &= BBbWriteEmbedded(dwIoBase,byVT3253B0_AIROHA2230[ii][0],byVT3253B0_AIROHA2230[ii][1]);
-       }
-        for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
-           bResult &= BBbWriteEmbedded(dwIoBase,byVT3253B0_AGC[ii][0],byVT3253B0_AGC[ii][1]);
-       }
-        pDevice->abyBBVGA[0] = 0x1C;
-        pDevice->abyBBVGA[1] = 0x10;
-        pDevice->abyBBVGA[2] = 0x0;
-        pDevice->abyBBVGA[3] = 0x0;
-        pDevice->ldBmThreshold[0] = -70;
-        pDevice->ldBmThreshold[1] = -48;
-        pDevice->ldBmThreshold[2] = 0;
-        pDevice->ldBmThreshold[3] = 0;
-    } else if (byRFType == RF_UW2451) {
-        for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++) {
-               bResult &= BBbWriteEmbedded(dwIoBase,byVT3253B0_UW2451[ii][0],byVT3253B0_UW2451[ii][1]);
-       }
-        for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
-           bResult &= BBbWriteEmbedded(dwIoBase,byVT3253B0_AGC[ii][0],byVT3253B0_AGC[ii][1]);
-       }
-        VNSvOutPortB(dwIoBase + MAC_REG_ITRTMSET, 0x23);
-        MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT0);
-
-        pDevice->abyBBVGA[0] = 0x14;
-        pDevice->abyBBVGA[1] = 0x0A;
-        pDevice->abyBBVGA[2] = 0x0;
-        pDevice->abyBBVGA[3] = 0x0;
-        pDevice->ldBmThreshold[0] = -60;
-        pDevice->ldBmThreshold[1] = -50;
-        pDevice->ldBmThreshold[2] = 0;
-        pDevice->ldBmThreshold[3] = 0;
-    } else if (byRFType == RF_UW2452) {
-        for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++) {
-            bResult &= BBbWriteEmbedded(dwIoBase,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)
-        //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)
-        //bResult &= BBbWriteEmbedded(dwIoBase,0x0a,0x28);
-        // Select VC1/VC2, CR215 = 0x02->0x06
-        bResult &= BBbWriteEmbedded(dwIoBase,0xd7,0x06);
-
-        //{{RobertYu:20050125, request by Jack
-        bResult &= BBbWriteEmbedded(dwIoBase,0x90,0x20);
-        bResult &= BBbWriteEmbedded(dwIoBase,0x97,0xeb);
-        //}}
-
-        //{{RobertYu:20050221, request by Jack
-        bResult &= BBbWriteEmbedded(dwIoBase,0xa6,0x00);
-        bResult &= BBbWriteEmbedded(dwIoBase,0xa8,0x30);
-        //}}
-        bResult &= BBbWriteEmbedded(dwIoBase,0xb0,0x58);
-
-        for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
-           bResult &= BBbWriteEmbedded(dwIoBase,byVT3253B0_AGC[ii][0],byVT3253B0_AGC[ii][1]);
-       }
-        //VNSvOutPortB(dwIoBase + MAC_REG_ITRTMSET, 0x23); // RobertYu: 20050104, 20050131 disable PA_Delay
-        //MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT0); // RobertYu: 20050104, 20050131 disable PA_Delay
-
-        pDevice->abyBBVGA[0] = 0x14;
-        pDevice->abyBBVGA[1] = 0x0A;
-        pDevice->abyBBVGA[2] = 0x0;
-        pDevice->abyBBVGA[3] = 0x0;
-        pDevice->ldBmThreshold[0] = -60;
-        pDevice->ldBmThreshold[1] = -50;
-        pDevice->ldBmThreshold[2] = 0;
-        pDevice->ldBmThreshold[3] = 0;
-    //}} RobertYu
-
-    } else if (byRFType == RF_VT3226) {
-        for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) {
-           bResult &= BBbWriteEmbedded(dwIoBase,byVT3253B0_AIROHA2230[ii][0],byVT3253B0_AIROHA2230[ii][1]);
-       }
-        for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
-           bResult &= BBbWriteEmbedded(dwIoBase,byVT3253B0_AGC[ii][0],byVT3253B0_AGC[ii][1]);
-       }
-        pDevice->abyBBVGA[0] = 0x1C;
-        pDevice->abyBBVGA[1] = 0x10;
-        pDevice->abyBBVGA[2] = 0x0;
-        pDevice->abyBBVGA[3] = 0x0;
-        pDevice->ldBmThreshold[0] = -70;
-        pDevice->ldBmThreshold[1] = -48;
-        pDevice->ldBmThreshold[2] = 0;
-        pDevice->ldBmThreshold[3] = 0;
-        // Fix VT3226 DFC system timing issue
-        MACvSetRFLE_LatchBase(dwIoBase);
-         //{{ RobertYu: 20050104
-    } else if (byRFType == RF_AIROHA7230) {
-        for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) {
-           bResult &= BBbWriteEmbedded(dwIoBase,byVT3253B0_AIROHA2230[ii][0],byVT3253B0_AIROHA2230[ii][1]);
-       }
-
-        //{{ RobertYu:20050223, request by JerryChung
-        // 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)
-        //bResult &= BBbWriteEmbedded(dwIoBase,0x0a,0x28);
-        // Select VC1/VC2, CR215 = 0x02->0x06
-        bResult &= BBbWriteEmbedded(dwIoBase,0xd7,0x06);
-        //}}
-
-        for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
-           bResult &= BBbWriteEmbedded(dwIoBase,byVT3253B0_AGC[ii][0],byVT3253B0_AGC[ii][1]);
-       }
-        pDevice->abyBBVGA[0] = 0x1C;
-        pDevice->abyBBVGA[1] = 0x10;
-        pDevice->abyBBVGA[2] = 0x0;
-        pDevice->abyBBVGA[3] = 0x0;
-        pDevice->ldBmThreshold[0] = -70;
-        pDevice->ldBmThreshold[1] = -48;
-        pDevice->ldBmThreshold[2] = 0;
-        pDevice->ldBmThreshold[3] = 0;
-    //}} RobertYu
-    } else {
-       // No VGA Table now
-       pDevice->bUpdateBBVGA = false;
-        pDevice->abyBBVGA[0] = 0x1C;
-    }
-
-    if (byLocalID > REV_ID_VT3253_A1) {
-        BBbWriteEmbedded(dwIoBase, 0x04, 0x7F);
-        BBbWriteEmbedded(dwIoBase, 0x0D, 0x01);
-    }
-
-    return bResult;
+       bool bResult = true;
+       int        ii;
+       unsigned long dwIoBase = pDevice->PortOffset;
+       unsigned char byRFType = pDevice->byRFType;
+       unsigned char byLocalID = pDevice->byLocalID;
+
+       if (byRFType == RF_RFMD2959) {
+               if (byLocalID <= REV_ID_VT3253_A1) {
+                       for (ii = 0; ii < CB_VT3253_INIT_FOR_RFMD; ii++) {
+                               bResult &= BBbWriteEmbedded(dwIoBase, byVT3253InitTab_RFMD[ii][0], byVT3253InitTab_RFMD[ii][1]);
+                       }
+               } else {
+                       for (ii = 0; ii < CB_VT3253B0_INIT_FOR_RFMD; ii++) {
+                               bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_RFMD[ii][0], byVT3253B0_RFMD[ii][1]);
+                       }
+                       for (ii = 0; ii < CB_VT3253B0_AGC_FOR_RFMD2959; ii++) {
+                               bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC4_RFMD2959[ii][0], byVT3253B0_AGC4_RFMD2959[ii][1]);
+                       }
+                       VNSvOutPortD(dwIoBase + MAC_REG_ITRTMSET, 0x23);
+                       MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT0);
+               }
+               pDevice->abyBBVGA[0] = 0x18;
+               pDevice->abyBBVGA[1] = 0x0A;
+               pDevice->abyBBVGA[2] = 0x0;
+               pDevice->abyBBVGA[3] = 0x0;
+               pDevice->ldBmThreshold[0] = -70;
+               pDevice->ldBmThreshold[1] = -50;
+               pDevice->ldBmThreshold[2] = 0;
+               pDevice->ldBmThreshold[3] = 0;
+       } else if ((byRFType == RF_AIROHA) || (byRFType == RF_AL2230S)) {
+               for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) {
+                       bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]);
+               }
+               for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
+                       bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]);
+               }
+               pDevice->abyBBVGA[0] = 0x1C;
+               pDevice->abyBBVGA[1] = 0x10;
+               pDevice->abyBBVGA[2] = 0x0;
+               pDevice->abyBBVGA[3] = 0x0;
+               pDevice->ldBmThreshold[0] = -70;
+               pDevice->ldBmThreshold[1] = -48;
+               pDevice->ldBmThreshold[2] = 0;
+               pDevice->ldBmThreshold[3] = 0;
+       } else if (byRFType == RF_UW2451) {
+               for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++) {
+                       bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_UW2451[ii][0], byVT3253B0_UW2451[ii][1]);
+               }
+               for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
+                       bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]);
+               }
+               VNSvOutPortB(dwIoBase + MAC_REG_ITRTMSET, 0x23);
+               MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT0);
+
+               pDevice->abyBBVGA[0] = 0x14;
+               pDevice->abyBBVGA[1] = 0x0A;
+               pDevice->abyBBVGA[2] = 0x0;
+               pDevice->abyBBVGA[3] = 0x0;
+               pDevice->ldBmThreshold[0] = -60;
+               pDevice->ldBmThreshold[1] = -50;
+               pDevice->ldBmThreshold[2] = 0;
+               pDevice->ldBmThreshold[3] = 0;
+       } else if (byRFType == RF_UW2452) {
+               for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++) {
+                       bResult &= BBbWriteEmbedded(dwIoBase, 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)
+               //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)
+               //bResult &= BBbWriteEmbedded(dwIoBase,0x0a,0x28);
+               // Select VC1/VC2, CR215 = 0x02->0x06
+               bResult &= BBbWriteEmbedded(dwIoBase, 0xd7, 0x06);
+
+               //{{RobertYu:20050125, request by Jack
+               bResult &= BBbWriteEmbedded(dwIoBase, 0x90, 0x20);
+               bResult &= BBbWriteEmbedded(dwIoBase, 0x97, 0xeb);
+               //}}
+
+               //{{RobertYu:20050221, request by Jack
+               bResult &= BBbWriteEmbedded(dwIoBase, 0xa6, 0x00);
+               bResult &= BBbWriteEmbedded(dwIoBase, 0xa8, 0x30);
+               //}}
+               bResult &= BBbWriteEmbedded(dwIoBase, 0xb0, 0x58);
+
+               for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
+                       bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]);
+               }
+               //VNSvOutPortB(dwIoBase + MAC_REG_ITRTMSET, 0x23); // RobertYu: 20050104, 20050131 disable PA_Delay
+               //MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT0); // RobertYu: 20050104, 20050131 disable PA_Delay
+
+               pDevice->abyBBVGA[0] = 0x14;
+               pDevice->abyBBVGA[1] = 0x0A;
+               pDevice->abyBBVGA[2] = 0x0;
+               pDevice->abyBBVGA[3] = 0x0;
+               pDevice->ldBmThreshold[0] = -60;
+               pDevice->ldBmThreshold[1] = -50;
+               pDevice->ldBmThreshold[2] = 0;
+               pDevice->ldBmThreshold[3] = 0;
+               //}} RobertYu
+
+       } else if (byRFType == RF_VT3226) {
+               for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) {
+                       bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]);
+               }
+               for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
+                       bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]);
+               }
+               pDevice->abyBBVGA[0] = 0x1C;
+               pDevice->abyBBVGA[1] = 0x10;
+               pDevice->abyBBVGA[2] = 0x0;
+               pDevice->abyBBVGA[3] = 0x0;
+               pDevice->ldBmThreshold[0] = -70;
+               pDevice->ldBmThreshold[1] = -48;
+               pDevice->ldBmThreshold[2] = 0;
+               pDevice->ldBmThreshold[3] = 0;
+               // Fix VT3226 DFC system timing issue
+               MACvSetRFLE_LatchBase(dwIoBase);
+               //{{ RobertYu: 20050104
+       } else if (byRFType == RF_AIROHA7230) {
+               for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) {
+                       bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]);
+               }
+
+               //{{ RobertYu:20050223, request by JerryChung
+               // 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)
+               //bResult &= BBbWriteEmbedded(dwIoBase,0x0a,0x28);
+               // Select VC1/VC2, CR215 = 0x02->0x06
+               bResult &= BBbWriteEmbedded(dwIoBase, 0xd7, 0x06);
+               //}}
+
+               for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
+                       bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]);
+               }
+               pDevice->abyBBVGA[0] = 0x1C;
+               pDevice->abyBBVGA[1] = 0x10;
+               pDevice->abyBBVGA[2] = 0x0;
+               pDevice->abyBBVGA[3] = 0x0;
+               pDevice->ldBmThreshold[0] = -70;
+               pDevice->ldBmThreshold[1] = -48;
+               pDevice->ldBmThreshold[2] = 0;
+               pDevice->ldBmThreshold[3] = 0;
+               //}} RobertYu
+       } else {
+               // No VGA Table now
+               pDevice->bUpdateBBVGA = false;
+               pDevice->abyBBVGA[0] = 0x1C;
+       }
+
+       if (byLocalID > REV_ID_VT3253_A1) {
+               BBbWriteEmbedded(dwIoBase, 0x04, 0x7F);
+               BBbWriteEmbedded(dwIoBase, 0x0D, 0x01);
+       }
+
+       return bResult;
 }
 
-
-
 /*
  * Description: Read All Baseband Registers
  *
@@ -2319,14 +2292,14 @@ bool BBbVT3253Init (PSDevice pDevice)
  * Return Value: none
  *
  */
-void BBvReadAllRegs (unsigned long dwIoBase, unsigned char *pbyBBRegs)
+void BBvReadAllRegs(unsigned long dwIoBase, unsigned char *pbyBBRegs)
 {
-    int  ii;
-    unsigned char byBase = 1;
-    for (ii = 0; ii < BB_MAX_CONTEXT_SIZE; ii++) {
-        BBbReadEmbedded(dwIoBase, (unsigned char)(ii*byBase), pbyBBRegs);
-        pbyBBRegs += byBase;
-    }
+       int  ii;
+       unsigned char byBase = 1;
+       for (ii = 0; ii < BB_MAX_CONTEXT_SIZE; ii++) {
+               BBbReadEmbedded(dwIoBase, (unsigned char)(ii*byBase), pbyBBRegs);
+               pbyBBRegs += byBase;
+       }
 }
 
 /*
@@ -2343,46 +2316,44 @@ void BBvReadAllRegs (unsigned long dwIoBase, unsigned char *pbyBBRegs)
  *
  */
 
-
-void BBvLoopbackOn (PSDevice pDevice)
+void BBvLoopbackOn(PSDevice pDevice)
 {
-    unsigned char byData;
-    unsigned long dwIoBase = pDevice->PortOffset;
-
-    //CR C9 = 0x00
-    BBbReadEmbedded(dwIoBase, 0xC9, &pDevice->byBBCRc9);//CR201
-    BBbWriteEmbedded(dwIoBase, 0xC9, 0);
-    BBbReadEmbedded(dwIoBase, 0x4D, &pDevice->byBBCR4d);//CR77
-    BBbWriteEmbedded(dwIoBase, 0x4D, 0x90);
-
-    //CR 88 = 0x02(CCK), 0x03(OFDM)
-    BBbReadEmbedded(dwIoBase, 0x88, &pDevice->byBBCR88);//CR136
-
-    if (pDevice->uConnectionRate <= RATE_11M) { //CCK
-        // Enable internal digital loopback: CR33 |= 0000 0001
-        BBbReadEmbedded(dwIoBase, 0x21, &byData);//CR33
-        BBbWriteEmbedded(dwIoBase, 0x21, (unsigned char)(byData | 0x01));//CR33
-        // CR154 = 0x00
-        BBbWriteEmbedded(dwIoBase, 0x9A, 0);   //CR154
-
-        BBbWriteEmbedded(dwIoBase, 0x88, 0x02);//CR239
-    }
-    else { //OFDM
-        // Enable internal digital loopback:CR154 |= 0000 0001
-        BBbReadEmbedded(dwIoBase, 0x9A, &byData);//CR154
-        BBbWriteEmbedded(dwIoBase, 0x9A, (unsigned char)(byData | 0x01));//CR154
-        // CR33 = 0x00
-        BBbWriteEmbedded(dwIoBase, 0x21, 0);   //CR33
-
-        BBbWriteEmbedded(dwIoBase, 0x88, 0x03);//CR239
-    }
-
-    //CR14 = 0x00
-    BBbWriteEmbedded(dwIoBase, 0x0E, 0);//CR14
-
-    // Disable TX_IQUN
-    BBbReadEmbedded(pDevice->PortOffset, 0x09, &pDevice->byBBCR09);
-    BBbWriteEmbedded(pDevice->PortOffset, 0x09, (unsigned char)(pDevice->byBBCR09 & 0xDE));
+       unsigned char byData;
+       unsigned long dwIoBase = pDevice->PortOffset;
+
+       //CR C9 = 0x00
+       BBbReadEmbedded(dwIoBase, 0xC9, &pDevice->byBBCRc9);//CR201
+       BBbWriteEmbedded(dwIoBase, 0xC9, 0);
+       BBbReadEmbedded(dwIoBase, 0x4D, &pDevice->byBBCR4d);//CR77
+       BBbWriteEmbedded(dwIoBase, 0x4D, 0x90);
+
+       //CR 88 = 0x02(CCK), 0x03(OFDM)
+       BBbReadEmbedded(dwIoBase, 0x88, &pDevice->byBBCR88);//CR136
+
+       if (pDevice->uConnectionRate <= RATE_11M) { //CCK
+               // Enable internal digital loopback: CR33 |= 0000 0001
+               BBbReadEmbedded(dwIoBase, 0x21, &byData);//CR33
+               BBbWriteEmbedded(dwIoBase, 0x21, (unsigned char)(byData | 0x01));//CR33
+               // CR154 = 0x00
+               BBbWriteEmbedded(dwIoBase, 0x9A, 0);   //CR154
+
+               BBbWriteEmbedded(dwIoBase, 0x88, 0x02);//CR239
+       } else { //OFDM
+               // Enable internal digital loopback:CR154 |= 0000 0001
+               BBbReadEmbedded(dwIoBase, 0x9A, &byData);//CR154
+               BBbWriteEmbedded(dwIoBase, 0x9A, (unsigned char)(byData | 0x01));//CR154
+               // CR33 = 0x00
+               BBbWriteEmbedded(dwIoBase, 0x21, 0);   //CR33
+
+               BBbWriteEmbedded(dwIoBase, 0x88, 0x03);//CR239
+       }
+
+       //CR14 = 0x00
+       BBbWriteEmbedded(dwIoBase, 0x0E, 0);//CR14
+
+       // Disable TX_IQUN
+       BBbReadEmbedded(pDevice->PortOffset, 0x09, &pDevice->byBBCR09);
+       BBbWriteEmbedded(pDevice->PortOffset, 0x09, (unsigned char)(pDevice->byBBCR09 & 0xDE));
 }
 
 /*
@@ -2398,32 +2369,28 @@ void BBvLoopbackOn (PSDevice pDevice)
  * Return Value: none
  *
  */
-void BBvLoopbackOff (PSDevice pDevice)
+void BBvLoopbackOff(PSDevice pDevice)
 {
-    unsigned char byData;
-    unsigned long dwIoBase = pDevice->PortOffset;
-
-    BBbWriteEmbedded(dwIoBase, 0xC9, pDevice->byBBCRc9);//CR201
-    BBbWriteEmbedded(dwIoBase, 0x88, pDevice->byBBCR88);//CR136
-    BBbWriteEmbedded(dwIoBase, 0x09, pDevice->byBBCR09);//CR136
-    BBbWriteEmbedded(dwIoBase, 0x4D, pDevice->byBBCR4d);//CR77
-
-    if (pDevice->uConnectionRate <= RATE_11M) { // CCK
-        // Set the CR33 Bit2 to disable internal Loopback.
-        BBbReadEmbedded(dwIoBase, 0x21, &byData);//CR33
-        BBbWriteEmbedded(dwIoBase, 0x21, (unsigned char)(byData & 0xFE));//CR33
-    }
-    else { // OFDM
-        BBbReadEmbedded(dwIoBase, 0x9A, &byData);//CR154
-        BBbWriteEmbedded(dwIoBase, 0x9A, (unsigned char)(byData & 0xFE));//CR154
-    }
-    BBbReadEmbedded(dwIoBase, 0x0E, &byData);//CR14
-    BBbWriteEmbedded(dwIoBase, 0x0E, (unsigned char)(byData | 0x80));//CR14
-
+       unsigned char byData;
+       unsigned long dwIoBase = pDevice->PortOffset;
+
+       BBbWriteEmbedded(dwIoBase, 0xC9, pDevice->byBBCRc9);//CR201
+       BBbWriteEmbedded(dwIoBase, 0x88, pDevice->byBBCR88);//CR136
+       BBbWriteEmbedded(dwIoBase, 0x09, pDevice->byBBCR09);//CR136
+       BBbWriteEmbedded(dwIoBase, 0x4D, pDevice->byBBCR4d);//CR77
+
+       if (pDevice->uConnectionRate <= RATE_11M) { // CCK
+               // Set the CR33 Bit2 to disable internal Loopback.
+               BBbReadEmbedded(dwIoBase, 0x21, &byData);//CR33
+               BBbWriteEmbedded(dwIoBase, 0x21, (unsigned char)(byData & 0xFE));//CR33
+       } else { // OFDM
+               BBbReadEmbedded(dwIoBase, 0x9A, &byData);//CR154
+               BBbWriteEmbedded(dwIoBase, 0x9A, (unsigned char)(byData & 0xFE));//CR154
+       }
+       BBbReadEmbedded(dwIoBase, 0x0E, &byData);//CR14
+       BBbWriteEmbedded(dwIoBase, 0x0E, (unsigned char)(byData | 0x80));//CR14
 }
 
-
-
 /*
  * Description: Set ShortSlotTime mode
  *
@@ -2437,49 +2404,47 @@ void BBvLoopbackOff (PSDevice pDevice)
  *
  */
 void
-BBvSetShortSlotTime (PSDevice pDevice)
+BBvSetShortSlotTime(PSDevice pDevice)
 {
-    unsigned char byBBRxConf=0;
-    unsigned char byBBVGA=0;
+       unsigned char byBBRxConf = 0;
+       unsigned char byBBVGA = 0;
 
-    BBbReadEmbedded(pDevice->PortOffset, 0x0A, &byBBRxConf);//CR10
+       BBbReadEmbedded(pDevice->PortOffset, 0x0A, &byBBRxConf);//CR10
 
-    if (pDevice->bShortSlotTime) {
-        byBBRxConf &= 0xDF;//1101 1111
-    } else {
-        byBBRxConf |= 0x20;//0010 0000
-    }
+       if (pDevice->bShortSlotTime) {
+               byBBRxConf &= 0xDF;//1101 1111
+       } else {
+               byBBRxConf |= 0x20;//0010 0000
+       }
 
-    // patch for 3253B0 Baseband with Cardbus module
-    BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byBBVGA);
-    if (byBBVGA == pDevice->abyBBVGA[0]) {
-        byBBRxConf |= 0x20;//0010 0000
-    }
-
-    BBbWriteEmbedded(pDevice->PortOffset, 0x0A, byBBRxConf);//CR10
+       // patch for 3253B0 Baseband with Cardbus module
+       BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byBBVGA);
+       if (byBBVGA == pDevice->abyBBVGA[0]) {
+               byBBRxConf |= 0x20;//0010 0000
+       }
 
+       BBbWriteEmbedded(pDevice->PortOffset, 0x0A, byBBRxConf);//CR10
 }
 
 void BBvSetVGAGainOffset(PSDevice pDevice, unsigned char byData)
 {
-    unsigned char byBBRxConf=0;
-
-    BBbWriteEmbedded(pDevice->PortOffset, 0xE7, byData);
-
-    BBbReadEmbedded(pDevice->PortOffset, 0x0A, &byBBRxConf);//CR10
-    // patch for 3253B0 Baseband with Cardbus module
-    if (byData == pDevice->abyBBVGA[0]) {
-        byBBRxConf |= 0x20;//0010 0000
-    } else if (pDevice->bShortSlotTime) {
-        byBBRxConf &= 0xDF;//1101 1111
-    } else {
-        byBBRxConf |= 0x20;//0010 0000
-    }
-    pDevice->byBBVGACurrent = byData;
-    BBbWriteEmbedded(pDevice->PortOffset, 0x0A, byBBRxConf);//CR10
+       unsigned char byBBRxConf = 0;
+
+       BBbWriteEmbedded(pDevice->PortOffset, 0xE7, byData);
+
+       BBbReadEmbedded(pDevice->PortOffset, 0x0A, &byBBRxConf);//CR10
+       // patch for 3253B0 Baseband with Cardbus module
+       if (byData == pDevice->abyBBVGA[0]) {
+               byBBRxConf |= 0x20;//0010 0000
+       } else if (pDevice->bShortSlotTime) {
+               byBBRxConf &= 0xDF;//1101 1111
+       } else {
+               byBBRxConf |= 0x20;//0010 0000
+       }
+       pDevice->byBBVGACurrent = byData;
+       BBbWriteEmbedded(pDevice->PortOffset, 0x0A, byBBRxConf);//CR10
 }
 
-
 /*
  * Description: Baseband SoftwareReset
  *
@@ -2493,12 +2458,12 @@ void BBvSetVGAGainOffset(PSDevice pDevice, unsigned char byData)
  *
  */
 void
-BBvSoftwareReset (unsigned long dwIoBase)
+BBvSoftwareReset(unsigned long dwIoBase)
 {
-    BBbWriteEmbedded(dwIoBase, 0x50, 0x40);
-    BBbWriteEmbedded(dwIoBase, 0x50, 0);
-    BBbWriteEmbedded(dwIoBase, 0x9C, 0x01);
-    BBbWriteEmbedded(dwIoBase, 0x9C, 0);
+       BBbWriteEmbedded(dwIoBase, 0x50, 0x40);
+       BBbWriteEmbedded(dwIoBase, 0x50, 0);
+       BBbWriteEmbedded(dwIoBase, 0x9C, 0x01);
+       BBbWriteEmbedded(dwIoBase, 0x9C, 0);
 }
 
 /*
@@ -2514,13 +2479,13 @@ BBvSoftwareReset (unsigned long dwIoBase)
  *
  */
 void
-BBvPowerSaveModeON (unsigned long dwIoBase)
+BBvPowerSaveModeON(unsigned long dwIoBase)
 {
-    unsigned char byOrgData;
+       unsigned char byOrgData;
 
-    BBbReadEmbedded(dwIoBase, 0x0D, &byOrgData);
-    byOrgData |= BIT0;
-    BBbWriteEmbedded(dwIoBase, 0x0D, byOrgData);
+       BBbReadEmbedded(dwIoBase, 0x0D, &byOrgData);
+       byOrgData |= BIT0;
+       BBbWriteEmbedded(dwIoBase, 0x0D, byOrgData);
 }
 
 /*
@@ -2536,13 +2501,13 @@ BBvPowerSaveModeON (unsigned long dwIoBase)
  *
  */
 void
-BBvPowerSaveModeOFF (unsigned long dwIoBase)
+BBvPowerSaveModeOFF(unsigned long dwIoBase)
 {
-    unsigned char byOrgData;
+       unsigned char byOrgData;
 
-    BBbReadEmbedded(dwIoBase, 0x0D, &byOrgData);
-    byOrgData &= ~(BIT0);
-    BBbWriteEmbedded(dwIoBase, 0x0D, byOrgData);
+       BBbReadEmbedded(dwIoBase, 0x0D, &byOrgData);
+       byOrgData &= ~(BIT0);
+       BBbWriteEmbedded(dwIoBase, 0x0D, byOrgData);
 }
 
 /*
@@ -2560,33 +2525,24 @@ BBvPowerSaveModeOFF (unsigned long dwIoBase)
  */
 
 void
-BBvSetTxAntennaMode (unsigned long dwIoBase, unsigned char byAntennaMode)
+BBvSetTxAntennaMode(unsigned long dwIoBase, unsigned char byAntennaMode)
 {
-    unsigned char byBBTxConf;
-
-#ifdef PLICE_DEBUG
-       //printk("Enter BBvSetTxAntennaMode\n");
-#endif
-    BBbReadEmbedded(dwIoBase, 0x09, &byBBTxConf);//CR09
-    if (byAntennaMode == ANT_DIVERSITY) {
-        // bit 1 is diversity
-        byBBTxConf |= 0x02;
-    } else if (byAntennaMode == ANT_A) {
-        // bit 2 is ANTSEL
-        byBBTxConf &= 0xF9; // 1111 1001
-    } else if (byAntennaMode == ANT_B) {
-#ifdef PLICE_DEBUG
-       //printk("BBvSetTxAntennaMode:ANT_B\n");
-#endif
-        byBBTxConf &= 0xFD; // 1111 1101
-        byBBTxConf |= 0x04;
-    }
-    BBbWriteEmbedded(dwIoBase, 0x09, byBBTxConf);//CR09
+       unsigned char byBBTxConf;
+
+       BBbReadEmbedded(dwIoBase, 0x09, &byBBTxConf);//CR09
+       if (byAntennaMode == ANT_DIVERSITY) {
+               // bit 1 is diversity
+               byBBTxConf |= 0x02;
+       } else if (byAntennaMode == ANT_A) {
+               // bit 2 is ANTSEL
+               byBBTxConf &= 0xF9; // 1111 1001
+       } else if (byAntennaMode == ANT_B) {
+               byBBTxConf &= 0xFD; // 1111 1101
+               byBBTxConf |= 0x04;
+       }
+       BBbWriteEmbedded(dwIoBase, 0x09, byBBTxConf);//CR09
 }
 
-
-
-
 /*
  * Description: Set Rx Antenna mode
  *
@@ -2602,24 +2558,23 @@ BBvSetTxAntennaMode (unsigned long dwIoBase, unsigned char byAntennaMode)
  */
 
 void
-BBvSetRxAntennaMode (unsigned long dwIoBase, unsigned char byAntennaMode)
+BBvSetRxAntennaMode(unsigned long dwIoBase, unsigned char byAntennaMode)
 {
-    unsigned char byBBRxConf;
-
-    BBbReadEmbedded(dwIoBase, 0x0A, &byBBRxConf);//CR10
-    if (byAntennaMode == ANT_DIVERSITY) {
-        byBBRxConf |= 0x01;
-
-    } else if (byAntennaMode == ANT_A) {
-        byBBRxConf &= 0xFC; // 1111 1100
-    } else if (byAntennaMode == ANT_B) {
-        byBBRxConf &= 0xFE; // 1111 1110
-        byBBRxConf |= 0x02;
-    }
-    BBbWriteEmbedded(dwIoBase, 0x0A, byBBRxConf);//CR10
+       unsigned char byBBRxConf;
+
+       BBbReadEmbedded(dwIoBase, 0x0A, &byBBRxConf);//CR10
+       if (byAntennaMode == ANT_DIVERSITY) {
+               byBBRxConf |= 0x01;
+
+       } else if (byAntennaMode == ANT_A) {
+               byBBRxConf &= 0xFC; // 1111 1100
+       } else if (byAntennaMode == ANT_B) {
+               byBBRxConf &= 0xFE; // 1111 1110
+               byBBRxConf |= 0x02;
+       }
+       BBbWriteEmbedded(dwIoBase, 0x0A, byBBRxConf);//CR10
 }
 
-
 /*
  * Description: BBvSetDeepSleep
  *
@@ -2633,142 +2588,138 @@ BBvSetRxAntennaMode (unsigned long dwIoBase, unsigned char byAntennaMode)
  *
  */
 void
-BBvSetDeepSleep (unsigned long dwIoBase, unsigned char byLocalID)
+BBvSetDeepSleep(unsigned long dwIoBase, unsigned char byLocalID)
 {
-    BBbWriteEmbedded(dwIoBase, 0x0C, 0x17);//CR12
-    BBbWriteEmbedded(dwIoBase, 0x0D, 0xB9);//CR13
+       BBbWriteEmbedded(dwIoBase, 0x0C, 0x17);//CR12
+       BBbWriteEmbedded(dwIoBase, 0x0D, 0xB9);//CR13
 }
 
 void
-BBvExitDeepSleep (unsigned long dwIoBase, unsigned char byLocalID)
+BBvExitDeepSleep(unsigned long dwIoBase, unsigned char byLocalID)
 {
-    BBbWriteEmbedded(dwIoBase, 0x0C, 0x00);//CR12
-    BBbWriteEmbedded(dwIoBase, 0x0D, 0x01);//CR13
+       BBbWriteEmbedded(dwIoBase, 0x0C, 0x00);//CR12
+       BBbWriteEmbedded(dwIoBase, 0x0D, 0x01);//CR13
 }
 
-
-
 static
 unsigned long
-s_ulGetRatio (PSDevice pDevice)
+s_ulGetRatio(PSDevice pDevice)
 {
-unsigned long ulRatio = 0;
-unsigned long ulMaxPacket;
-unsigned long ulPacketNum;
-
-    //This is a thousand-ratio
-    ulMaxPacket = pDevice->uNumSQ3[RATE_54M];
-    if ( pDevice->uNumSQ3[RATE_54M] != 0 ) {
-        ulPacketNum = pDevice->uNumSQ3[RATE_54M];
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_54M] * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_54M;
-    }
-    if ( pDevice->uNumSQ3[RATE_48M] > ulMaxPacket ) {
-        ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M];
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_48M] * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_48M;
-        ulMaxPacket = pDevice->uNumSQ3[RATE_48M];
-    }
-    if ( pDevice->uNumSQ3[RATE_36M] > ulMaxPacket ) {
-        ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
-                      pDevice->uNumSQ3[RATE_36M];
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_36M] * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_36M;
-        ulMaxPacket = pDevice->uNumSQ3[RATE_36M];
-    }
-    if ( pDevice->uNumSQ3[RATE_24M] > ulMaxPacket ) {
-        ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
-                      pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M];
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_24M] * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_24M;
-        ulMaxPacket = pDevice->uNumSQ3[RATE_24M];
-    }
-    if ( pDevice->uNumSQ3[RATE_18M] > ulMaxPacket ) {
-        ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
-                      pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M] +
-                      pDevice->uNumSQ3[RATE_18M];
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_18M] * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_18M;
-        ulMaxPacket = pDevice->uNumSQ3[RATE_18M];
-    }
-    if ( pDevice->uNumSQ3[RATE_12M] > ulMaxPacket ) {
-        ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
-                      pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M] +
-                      pDevice->uNumSQ3[RATE_18M] + pDevice->uNumSQ3[RATE_12M];
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_12M] * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_12M;
-        ulMaxPacket = pDevice->uNumSQ3[RATE_12M];
-    }
-    if ( pDevice->uNumSQ3[RATE_11M] > ulMaxPacket ) {
-        ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
-                      pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M] -
-                      pDevice->uNumSQ3[RATE_6M] - pDevice->uNumSQ3[RATE_9M];
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_11M] * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_11M;
-        ulMaxPacket = pDevice->uNumSQ3[RATE_11M];
-    }
-    if ( pDevice->uNumSQ3[RATE_9M] > ulMaxPacket ) {
-        ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
-                      pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M] -
-                      pDevice->uNumSQ3[RATE_6M];
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_9M] * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_9M;
-        ulMaxPacket = pDevice->uNumSQ3[RATE_9M];
-    }
-    if ( pDevice->uNumSQ3[RATE_6M] > ulMaxPacket ) {
-        ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
-                      pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M];
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_6M] * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_6M;
-        ulMaxPacket = pDevice->uNumSQ3[RATE_6M];
-    }
-    if ( pDevice->uNumSQ3[RATE_5M] > ulMaxPacket ) {
-        ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
-                      pDevice->uNumSQ3[RATE_2M];
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_5M] * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_55M;
-        ulMaxPacket = pDevice->uNumSQ3[RATE_5M];
-    }
-    if ( pDevice->uNumSQ3[RATE_2M] > ulMaxPacket ) {
-        ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M];
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_2M]  * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_2M;
-        ulMaxPacket = pDevice->uNumSQ3[RATE_2M];
-    }
-    if ( pDevice->uNumSQ3[RATE_1M] > ulMaxPacket ) {
-        ulPacketNum = pDevice->uDiversityCnt;
-        ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
-        //ulRatio = (pDevice->uNumSQ3[RATE_1M]  * 1000 / pDevice->uDiversityCnt);
-        ulRatio += TOP_RATE_1M;
-    }
-
-    return ulRatio;
+       unsigned long ulRatio = 0;
+       unsigned long ulMaxPacket;
+       unsigned long ulPacketNum;
+
+       //This is a thousand-ratio
+       ulMaxPacket = pDevice->uNumSQ3[RATE_54M];
+       if (pDevice->uNumSQ3[RATE_54M] != 0) {
+               ulPacketNum = pDevice->uNumSQ3[RATE_54M];
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_54M] * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_54M;
+       }
+       if (pDevice->uNumSQ3[RATE_48M] > ulMaxPacket) {
+               ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M];
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_48M] * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_48M;
+               ulMaxPacket = pDevice->uNumSQ3[RATE_48M];
+       }
+       if (pDevice->uNumSQ3[RATE_36M] > ulMaxPacket) {
+               ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
+                       pDevice->uNumSQ3[RATE_36M];
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_36M] * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_36M;
+               ulMaxPacket = pDevice->uNumSQ3[RATE_36M];
+       }
+       if (pDevice->uNumSQ3[RATE_24M] > ulMaxPacket) {
+               ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
+                       pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M];
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_24M] * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_24M;
+               ulMaxPacket = pDevice->uNumSQ3[RATE_24M];
+       }
+       if (pDevice->uNumSQ3[RATE_18M] > ulMaxPacket) {
+               ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
+                       pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M] +
+                       pDevice->uNumSQ3[RATE_18M];
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_18M] * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_18M;
+               ulMaxPacket = pDevice->uNumSQ3[RATE_18M];
+       }
+       if (pDevice->uNumSQ3[RATE_12M] > ulMaxPacket) {
+               ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
+                       pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M] +
+                       pDevice->uNumSQ3[RATE_18M] + pDevice->uNumSQ3[RATE_12M];
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_12M] * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_12M;
+               ulMaxPacket = pDevice->uNumSQ3[RATE_12M];
+       }
+       if (pDevice->uNumSQ3[RATE_11M] > ulMaxPacket) {
+               ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
+                       pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M] -
+                       pDevice->uNumSQ3[RATE_6M] - pDevice->uNumSQ3[RATE_9M];
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_11M] * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_11M;
+               ulMaxPacket = pDevice->uNumSQ3[RATE_11M];
+       }
+       if (pDevice->uNumSQ3[RATE_9M] > ulMaxPacket) {
+               ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
+                       pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M] -
+                       pDevice->uNumSQ3[RATE_6M];
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_9M] * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_9M;
+               ulMaxPacket = pDevice->uNumSQ3[RATE_9M];
+       }
+       if (pDevice->uNumSQ3[RATE_6M] > ulMaxPacket) {
+               ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
+                       pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M];
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_6M] * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_6M;
+               ulMaxPacket = pDevice->uNumSQ3[RATE_6M];
+       }
+       if (pDevice->uNumSQ3[RATE_5M] > ulMaxPacket) {
+               ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
+                       pDevice->uNumSQ3[RATE_2M];
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_5M] * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_55M;
+               ulMaxPacket = pDevice->uNumSQ3[RATE_5M];
+       }
+       if (pDevice->uNumSQ3[RATE_2M] > ulMaxPacket) {
+               ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M];
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_2M]  * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_2M;
+               ulMaxPacket = pDevice->uNumSQ3[RATE_2M];
+       }
+       if (pDevice->uNumSQ3[RATE_1M] > ulMaxPacket) {
+               ulPacketNum = pDevice->uDiversityCnt;
+               ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
+               //ulRatio = (pDevice->uNumSQ3[RATE_1M]  * 1000 / pDevice->uDiversityCnt);
+               ulRatio += TOP_RATE_1M;
+       }
+
+       return ulRatio;
 }
 
-
 void
-BBvClearAntDivSQ3Value (PSDevice pDevice)
+BBvClearAntDivSQ3Value(PSDevice pDevice)
 {
-    unsigned int ii;
+       unsigned int ii;
 
-    pDevice->uDiversityCnt = 0;
-    for (ii = 0; ii < MAX_RATE; ii++) {
-        pDevice->uNumSQ3[ii] = 0;
-    }
+       pDevice->uDiversityCnt = 0;
+       for (ii = 0; ii < MAX_RATE; ii++) {
+               pDevice->uNumSQ3[ii] = 0;
+       }
 }
 
-
 /*
  * Description: Antenna Diversity
  *
@@ -2785,79 +2736,70 @@ BBvClearAntDivSQ3Value (PSDevice pDevice)
  */
 
 void
-BBvAntennaDiversity (PSDevice pDevice, unsigned char byRxRate, unsigned char bySQ3)
+BBvAntennaDiversity(PSDevice pDevice, unsigned char byRxRate, unsigned char bySQ3)
 {
+       if ((byRxRate >= MAX_RATE) || (pDevice->wAntDiversityMaxRate >= MAX_RATE)) {
+               return;
+       }
+       pDevice->uDiversityCnt++;
+       // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->uDiversityCnt = %d\n", (int)pDevice->uDiversityCnt);
 
-    if ((byRxRate >= MAX_RATE) || (pDevice->wAntDiversityMaxRate >= MAX_RATE)) {
-        return;
-    }
-    pDevice->uDiversityCnt++;
-   // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->uDiversityCnt = %d\n", (int)pDevice->uDiversityCnt);
-
-    pDevice->uNumSQ3[byRxRate]++;
+       pDevice->uNumSQ3[byRxRate]++;
 
-    if (pDevice->byAntennaState == 0) {
+       if (pDevice->byAntennaState == 0) {
+               if (pDevice->uDiversityCnt > pDevice->ulDiversityNValue) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ulDiversityNValue=[%d],54M-[%d]\n",
+                               (int)pDevice->ulDiversityNValue, (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate]);
 
-        if (pDevice->uDiversityCnt > pDevice->ulDiversityNValue) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ulDiversityNValue=[%d],54M-[%d]\n",
-                          (int)pDevice->ulDiversityNValue, (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate]);
+                       if (pDevice->uNumSQ3[pDevice->wAntDiversityMaxRate] < pDevice->uDiversityCnt/2) {
+                               pDevice->ulRatio_State0 = s_ulGetRatio(pDevice);
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "SQ3_State0, rate = [%08x]\n", (int)pDevice->ulRatio_State0);
 
-            if (pDevice->uNumSQ3[pDevice->wAntDiversityMaxRate] < pDevice->uDiversityCnt/2) {
+                               if (pDevice->byTMax == 0)
+                                       return;
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "1.[%08x], uNumSQ3[%d]=%d, %d\n",
+                                       (int)pDevice->ulRatio_State0, (int)pDevice->wAntDiversityMaxRate,
+                                       (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], (int)pDevice->uDiversityCnt);
 
-                pDevice->ulRatio_State0 = s_ulGetRatio(pDevice);
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SQ3_State0, rate = [%08x]\n", (int)pDevice->ulRatio_State0);
+                               s_vChangeAntenna(pDevice);
+                               pDevice->byAntennaState = 1;
+                               del_timer(&pDevice->TimerSQ3Tmax3);
+                               del_timer(&pDevice->TimerSQ3Tmax2);
+                               pDevice->TimerSQ3Tmax1.expires =  RUN_AT(pDevice->byTMax * HZ);
+                               add_timer(&pDevice->TimerSQ3Tmax1);
+
+                       } else {
+                               pDevice->TimerSQ3Tmax3.expires =  RUN_AT(pDevice->byTMax3 * HZ);
+                               add_timer(&pDevice->TimerSQ3Tmax3);
+                       }
+                       BBvClearAntDivSQ3Value(pDevice);
+
+               }
+       } else { //byAntennaState == 1
+
+               if (pDevice->uDiversityCnt > pDevice->ulDiversityMValue) {
+                       del_timer(&pDevice->TimerSQ3Tmax1);
+
+                       pDevice->ulRatio_State1 = s_ulGetRatio(pDevice);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "RX:SQ3_State1, rate0 = %08x,rate1 = %08x\n",
+                               (int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1);
+
+                       if (pDevice->ulRatio_State1 < pDevice->ulRatio_State0) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "2.[%08x][%08x], uNumSQ3[%d]=%d, %d\n",
+                                       (int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1,
+                                       (int)pDevice->wAntDiversityMaxRate,
+                                       (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], (int)pDevice->uDiversityCnt);
 
-                if ( pDevice->byTMax == 0 )
-                    return;
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1.[%08x], uNumSQ3[%d]=%d, %d\n",
-                              (int)pDevice->ulRatio_State0, (int)pDevice->wAntDiversityMaxRate,
-                              (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], (int)pDevice->uDiversityCnt);
-#ifdef PLICE_DEBUG
-               //printk("BBvAntennaDiversity1:call s_vChangeAntenna\n");
-#endif
-               s_vChangeAntenna(pDevice);
-                pDevice->byAntennaState = 1;
-                del_timer(&pDevice->TimerSQ3Tmax3);
-                del_timer(&pDevice->TimerSQ3Tmax2);
-                pDevice->TimerSQ3Tmax1.expires =  RUN_AT(pDevice->byTMax * HZ);
-                add_timer(&pDevice->TimerSQ3Tmax1);
-
-            } else {
-
-                pDevice->TimerSQ3Tmax3.expires =  RUN_AT(pDevice->byTMax3 * HZ);
-                add_timer(&pDevice->TimerSQ3Tmax3);
-            }
-            BBvClearAntDivSQ3Value(pDevice);
-
-        }
-    } else { //byAntennaState == 1
-
-        if (pDevice->uDiversityCnt > pDevice->ulDiversityMValue) {
-
-            del_timer(&pDevice->TimerSQ3Tmax1);
-
-            pDevice->ulRatio_State1 = s_ulGetRatio(pDevice);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RX:SQ3_State1, rate0 = %08x,rate1 = %08x\n",
-                          (int)pDevice->ulRatio_State0,(int)pDevice->ulRatio_State1);
-
-            if (pDevice->ulRatio_State1 < pDevice->ulRatio_State0) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2.[%08x][%08x], uNumSQ3[%d]=%d, %d\n",
-                              (int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1,
-                              (int)pDevice->wAntDiversityMaxRate,
-                              (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], (int)pDevice->uDiversityCnt);
-#ifdef PLICE_DEBUG
-               //printk("BBvAntennaDiversity2:call s_vChangeAntenna\n");
-#endif
                                s_vChangeAntenna(pDevice);
-                pDevice->TimerSQ3Tmax3.expires =  RUN_AT(pDevice->byTMax3 * HZ);
-                pDevice->TimerSQ3Tmax2.expires =  RUN_AT(pDevice->byTMax2 * HZ);
-                add_timer(&pDevice->TimerSQ3Tmax3);
-                add_timer(&pDevice->TimerSQ3Tmax2);
-            }
-            pDevice->byAntennaState = 0;
-            BBvClearAntDivSQ3Value(pDevice);
-        }
-    } //byAntennaState
+                               pDevice->TimerSQ3Tmax3.expires =  RUN_AT(pDevice->byTMax3 * HZ);
+                               pDevice->TimerSQ3Tmax2.expires =  RUN_AT(pDevice->byTMax2 * HZ);
+                               add_timer(&pDevice->TimerSQ3Tmax3);
+                               add_timer(&pDevice->TimerSQ3Tmax2);
+                       }
+                       pDevice->byAntennaState = 0;
+                       BBvClearAntDivSQ3Value(pDevice);
+               }
+       } //byAntennaState
 }
 
 /*+
@@ -2872,38 +2814,33 @@ BBvAntennaDiversity (PSDevice pDevice, unsigned char byRxRate, unsigned char byS
  *
  * Return Value: none
  *
--*/
+ -*/
 
 void
-TimerSQ3CallBack (
-    void *hDeviceContext
-    )
+TimerSQ3CallBack(
+       void *hDeviceContext
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TimerSQ3CallBack...");
-    spin_lock_irq(&pDevice->lock);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "TimerSQ3CallBack...");
+       spin_lock_irq(&pDevice->lock);
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"3.[%08x][%08x], %d\n",(int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1, (int)pDevice->uDiversityCnt);
-#ifdef PLICE_DEBUG
-               //printk("TimerSQ3CallBack1:call s_vChangeAntenna\n");
-#endif
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "3.[%08x][%08x], %d\n", (int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1, (int)pDevice->uDiversityCnt);
 
-    s_vChangeAntenna(pDevice);
-    pDevice->byAntennaState = 0;
-    BBvClearAntDivSQ3Value(pDevice);
+       s_vChangeAntenna(pDevice);
+       pDevice->byAntennaState = 0;
+       BBvClearAntDivSQ3Value(pDevice);
 
-    pDevice->TimerSQ3Tmax3.expires =  RUN_AT(pDevice->byTMax3 * HZ);
-    pDevice->TimerSQ3Tmax2.expires =  RUN_AT(pDevice->byTMax2 * HZ);
-    add_timer(&pDevice->TimerSQ3Tmax3);
-    add_timer(&pDevice->TimerSQ3Tmax2);
+       pDevice->TimerSQ3Tmax3.expires =  RUN_AT(pDevice->byTMax3 * HZ);
+       pDevice->TimerSQ3Tmax2.expires =  RUN_AT(pDevice->byTMax2 * HZ);
+       add_timer(&pDevice->TimerSQ3Tmax3);
+       add_timer(&pDevice->TimerSQ3Tmax2);
 
-
-    spin_unlock_irq(&pDevice->lock);
-    return;
+       spin_unlock_irq(&pDevice->lock);
+       return;
 }
 
-
 /*+
  *
  * Description:
@@ -2920,54 +2857,46 @@ TimerSQ3CallBack (
  *
  * Return Value: none
  *
--*/
+ -*/
 
 void
-TimerState1CallBack (
-    void *hDeviceContext
-    )
+TimerState1CallBack(
+       void *hDeviceContext
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TimerState1CallBack...");
-
-    spin_lock_irq(&pDevice->lock);
-    if (pDevice->uDiversityCnt < pDevice->ulDiversityMValue/100) {
-#ifdef PLICE_DEBUG
-               //printk("TimerSQ3CallBack2:call s_vChangeAntenna\n");
-#endif
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "TimerState1CallBack...");
 
+       spin_lock_irq(&pDevice->lock);
+       if (pDevice->uDiversityCnt < pDevice->ulDiversityMValue/100) {
                s_vChangeAntenna(pDevice);
-        pDevice->TimerSQ3Tmax3.expires =  RUN_AT(pDevice->byTMax3 * HZ);
-        pDevice->TimerSQ3Tmax2.expires =  RUN_AT(pDevice->byTMax2 * HZ);
-        add_timer(&pDevice->TimerSQ3Tmax3);
-        add_timer(&pDevice->TimerSQ3Tmax2);
-    } else {
-        pDevice->ulRatio_State1 = s_ulGetRatio(pDevice);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SQ3_State1, rate0 = %08x,rate1 = %08x\n",
-                      (int)pDevice->ulRatio_State0,(int)pDevice->ulRatio_State1);
-
-        if ( pDevice->ulRatio_State1 < pDevice->ulRatio_State0 ) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2.[%08x][%08x], uNumSQ3[%d]=%d, %d\n",
-                          (int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1,
-                          (int)pDevice->wAntDiversityMaxRate,
-                          (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], (int)pDevice->uDiversityCnt);
-#ifdef PLICE_DEBUG
-               //printk("TimerSQ3CallBack3:call s_vChangeAntenna\n");
-#endif
+               pDevice->TimerSQ3Tmax3.expires =  RUN_AT(pDevice->byTMax3 * HZ);
+               pDevice->TimerSQ3Tmax2.expires =  RUN_AT(pDevice->byTMax2 * HZ);
+               add_timer(&pDevice->TimerSQ3Tmax3);
+               add_timer(&pDevice->TimerSQ3Tmax2);
+       } else {
+               pDevice->ulRatio_State1 = s_ulGetRatio(pDevice);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "SQ3_State1, rate0 = %08x,rate1 = %08x\n",
+                       (int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1);
+
+               if (pDevice->ulRatio_State1 < pDevice->ulRatio_State0) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "2.[%08x][%08x], uNumSQ3[%d]=%d, %d\n",
+                               (int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1,
+                               (int)pDevice->wAntDiversityMaxRate,
+                               (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], (int)pDevice->uDiversityCnt);
 
                        s_vChangeAntenna(pDevice);
 
-            pDevice->TimerSQ3Tmax3.expires =  RUN_AT(pDevice->byTMax3 * HZ);
-            pDevice->TimerSQ3Tmax2.expires =  RUN_AT(pDevice->byTMax2 * HZ);
-            add_timer(&pDevice->TimerSQ3Tmax3);
-            add_timer(&pDevice->TimerSQ3Tmax2);
-        }
-    }
-    pDevice->byAntennaState = 0;
-    BBvClearAntDivSQ3Value(pDevice);
-    spin_unlock_irq(&pDevice->lock);
-
-    return;
+                       pDevice->TimerSQ3Tmax3.expires =  RUN_AT(pDevice->byTMax3 * HZ);
+                       pDevice->TimerSQ3Tmax2.expires =  RUN_AT(pDevice->byTMax2 * HZ);
+                       add_timer(&pDevice->TimerSQ3Tmax3);
+                       add_timer(&pDevice->TimerSQ3Tmax2);
+               }
+       }
+       pDevice->byAntennaState = 0;
+       BBvClearAntDivSQ3Value(pDevice);
+       spin_unlock_irq(&pDevice->lock);
+
+       return;
 }
-
index 9b5bc9c58d9fa87c75ab8798697e2000efa06be1..e31bb7600673fb2a8b7e64b937da0247479c8549 100644 (file)
@@ -41,7 +41,6 @@
 //
 #define BB_MAX_CONTEXT_SIZE 256
 
-
 //
 // Baseband RF pair definition in eeprom (Bits 6..0)
 //
@@ -49,7 +48,6 @@
 #define PREAMBLE_LONG   0
 #define PREAMBLE_SHORT  1
 
-
 #define F5G             0
 #define F2_4G           1
 
 #define TOP_RATE_2M         0x00200000
 #define TOP_RATE_1M         0x00100000
 
-
 /*---------------------  Export Types  ------------------------------*/
 
 /*---------------------  Export Macros ------------------------------*/
 
-#define BBvClearFOE(dwIoBase)                               \
-{                                                           \
-    BBbWriteEmbedded(dwIoBase, 0xB1, 0);                     \
-}
-
-#define BBvSetFOE(dwIoBase)                                 \
-{                                                           \
-    BBbWriteEmbedded(dwIoBase, 0xB1, 0x0C);                  \
-}
+#define BBvClearFOE(dwIoBase)                          \
+       BBbWriteEmbedded(dwIoBase, 0xB1, 0)
 
+#define BBvSetFOE(dwIoBase)                            \
+       BBbWriteEmbedded(dwIoBase, 0xB1, 0x0C)
 
 /*---------------------  Export Classes  ----------------------------*/
 
 
 unsigned int
 BBuGetFrameTime(
-    unsigned char byPreambleType,
-    unsigned char byPktType,
-    unsigned int cbFrameLength,
-    unsigned short wRate
-    );
+       unsigned char byPreambleType,
+       unsigned char byPktType,
+       unsigned int cbFrameLength,
+       unsigned short wRate
+);
 
 void
-BBvCalculateParameter (
-    PSDevice pDevice,
-    unsigned int cbFrameLength,
-    unsigned short wRate,
-    unsigned char byPacketType,
-    unsigned short *pwPhyLen,
-    unsigned char *pbyPhySrv,
-    unsigned char *pbyPhySgn
-    );
+BBvCalculateParameter(
+       PSDevice pDevice,
+       unsigned int cbFrameLength,
+       unsigned short wRate,
+       unsigned char byPacketType,
+       unsigned short *pwPhyLen,
+       unsigned char *pbyPhySrv,
+       unsigned char *pbyPhySgn
+);
 
 bool BBbReadEmbedded(unsigned long dwIoBase, unsigned char byBBAddr, unsigned char *pbyData);
 bool BBbWriteEmbedded(unsigned long dwIoBase, unsigned char byBBAddr, unsigned char byData);
@@ -131,17 +123,17 @@ void BBvExitDeepSleep(unsigned long dwIoBase, unsigned char byLocalID);
 // timer for antenna diversity
 
 void
-TimerSQ3CallBack (
-    void *hDeviceContext
-    );
+TimerSQ3CallBack(
+       void *hDeviceContext
+);
 
 void
 TimerState1CallBack(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 void BBvAntennaDiversity(PSDevice pDevice, unsigned char byRxRate, unsigned char bySQ3);
 void
-BBvClearAntDivSQ3Value (PSDevice pDevice);
+BBvClearAntDivSQ3Value(PSDevice pDevice);
 
 #endif // __BASEBAND_H__
index fe57fb880a8f43431af813e27ca8f3cf8647c6b5..f983915168b7883c30a435c4561b8571abb77f75 100644 (file)
 
 /*---------------------  Static Definitions -------------------------*/
 
-
-
-
 /*---------------------  Static Classes  ----------------------------*/
 
 /*---------------------  Static Variables  --------------------------*/
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 
-
-
 const unsigned short awHWRetry0[5][5] = {
-                                            {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
-                                            {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
-                                            {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
-                                            {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
-                                            {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
-                                           };
+       {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
+       {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
+       {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
+       {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
+       {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
+};
 const unsigned short awHWRetry1[5][5] = {
-                                            {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
-                                            {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
-                                            {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
-                                            {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
-                                            {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
-                                           };
-
-
+       {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
+       {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
+       {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
+       {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
+       {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
+};
 
 /*---------------------  Static Functions  --------------------------*/
 
 void s_vCheckSensitivity(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 #ifdef Calcu_LinkQual
 void s_uCalculateLinkQual(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 #endif
 
-
 void s_vCheckPreEDThreshold(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
-
-
-
-
 /*+
  *
  * Routine Description:
@@ -121,153 +108,150 @@ void s_vCheckPreEDThreshold(
  * Return Value:
  *    PTR to KnownBSS or NULL
  *
--*/
+ -*/
 
 PKnownBSS
 BSSpSearchBSSList(
-    void *hDeviceContext,
-    unsigned char *pbyDesireBSSID,
-    unsigned char *pbyDesireSSID,
-    CARD_PHY_TYPE  ePhyType
-    )
+       void *hDeviceContext,
+       unsigned char *pbyDesireBSSID,
+       unsigned char *pbyDesireSSID,
+       CARD_PHY_TYPE  ePhyType
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned char *pbyBSSID = NULL;
-    PWLAN_IE_SSID   pSSID = NULL;
-    PKnownBSS       pCurrBSS = NULL;
-    PKnownBSS       pSelect = NULL;
-    unsigned char ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
-    unsigned int ii = 0;
-
-    if (pbyDesireBSSID != NULL) {
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned char *pbyBSSID = NULL;
+       PWLAN_IE_SSID   pSSID = NULL;
+       PKnownBSS       pCurrBSS = NULL;
+       PKnownBSS       pSelect = NULL;
+       unsigned char ZeroBSSID[WLAN_BSSID_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+       unsigned int ii = 0;
+
+       if (pbyDesireBSSID != NULL) {
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
                        "BSSpSearchBSSList BSSID[%pM]\n", pbyDesireBSSID);
-        if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
-            (memcmp(pbyDesireBSSID, ZeroBSSID, 6)!= 0)){
-            pbyBSSID = pbyDesireBSSID;
-        }
-    }
-    if (pbyDesireSSID != NULL) {
-        if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0) {
-            pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
-        }
-    }
-
-    if (pbyBSSID != NULL) {
-        // match BSSID first
-        for (ii = 0; ii <MAX_BSS_NUM; ii++) {
-            pCurrBSS = &(pMgmt->sBSSList[ii]);
-if(pDevice->bLinkPass==false) pCurrBSS->bSelected = false;
-            if ((pCurrBSS->bActive) &&
-                (pCurrBSS->bSelected == false)) {
-                if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) {
-                    if (pSSID != NULL) {
-                        // compare ssid
-                        if ( !memcmp(pSSID->abySSID,
-                            ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
-                            pSSID->len)) {
-                            if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
-                                ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
-                                ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
-                                ) {
-                                pCurrBSS->bSelected = true;
-                                return(pCurrBSS);
-                            }
-                        }
-                    } else {
-                        if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
-                            ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
-                            ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
-                            ) {
-                            pCurrBSS->bSelected = true;
-                            return(pCurrBSS);
-                        }
-                    }
-                }
-            }
-        }
-    } else {
-        // ignore BSSID
-        for (ii = 0; ii <MAX_BSS_NUM; ii++) {
-            pCurrBSS = &(pMgmt->sBSSList[ii]);
-       //2007-0721-01<Add>by MikeLiu
-         pCurrBSS->bSelected = false;
-          if (pCurrBSS->bActive) {
-
-                if (pSSID != NULL) {
-                    // matched SSID
-                    if (! !memcmp(pSSID->abySSID,
-                        ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
-                        pSSID->len) ||
-                        (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
-                        // SSID not match skip this BSS
-                        continue;
-                      }
-                }
-                if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
-                    ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
-                    ){
-                    // Type not match skip this BSS
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt->eConfigMode, pCurrBSS->wCapInfo);
-                    continue;
-                }
-
-                if (ePhyType != PHY_TYPE_AUTO) {
-                    if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
-                        ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
-                        // PhyType not match skip this BSS
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType, pCurrBSS->eNetworkTypeInUse);
-                        continue;
-                    }
-                }
+               if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
+                   (memcmp(pbyDesireBSSID, ZeroBSSID, 6) != 0)) {
+                       pbyBSSID = pbyDesireBSSID;
+               }
+       }
+       if (pbyDesireSSID != NULL) {
+               if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0) {
+                       pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
+               }
+       }
+
+       if (pbyBSSID != NULL) {
+               // match BSSID first
+               for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+                       pCurrBSS = &(pMgmt->sBSSList[ii]);
+                       if (pDevice->bLinkPass == false) pCurrBSS->bSelected = false;
+                       if ((pCurrBSS->bActive) &&
+                           (pCurrBSS->bSelected == false)) {
+                               if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) {
+                                       if (pSSID != NULL) {
+                                               // compare ssid
+                                               if (!memcmp(pSSID->abySSID,
+                                                           ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
+                                                           pSSID->len)) {
+                                                       if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
+                                                           ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
+                                                           ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
+) {
+                                                               pCurrBSS->bSelected = true;
+                                                               return pCurrBSS;
+                                                       }
+                                               }
+                                       } else {
+                                               if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
+                                                   ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
+                                                   ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
+) {
+                                                       pCurrBSS->bSelected = true;
+                                                       return pCurrBSS;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       } else {
+               // ignore BSSID
+               for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+                       pCurrBSS = &(pMgmt->sBSSList[ii]);
+                       //2007-0721-01<Add>by MikeLiu
+                       pCurrBSS->bSelected = false;
+                       if (pCurrBSS->bActive) {
+                               if (pSSID != NULL) {
+                                       // matched SSID
+                                       if (!!memcmp(pSSID->abySSID,
+                                                    ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
+                                                    pSSID->len) ||
+                                           (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
+                                               // SSID not match skip this BSS
+                                               continue;
+                                       }
+                               }
+                               if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
+                                   ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
+) {
+                                       // Type not match skip this BSS
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt->eConfigMode, pCurrBSS->wCapInfo);
+                                       continue;
+                               }
+
+                               if (ePhyType != PHY_TYPE_AUTO) {
+                                       if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
+                                           ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
+                                               // PhyType not match skip this BSS
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType, pCurrBSS->eNetworkTypeInUse);
+                                               continue;
+                                       }
+                               }
 /*
-                if (pMgmt->eAuthenMode < WMAC_AUTH_WPA) {
-                    if (pCurrBSS->bWPAValid == true) {
-                        // WPA AP will reject connection of station without WPA enable.
-                        continue;
-                    }
-                } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
-                           (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
-                    if (pCurrBSS->bWPAValid == false) {
-                        // station with WPA enable can't join NonWPA AP.
-                        continue;
-                    }
-                } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
-                           (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
-                    if (pCurrBSS->bWPA2Valid == false) {
-                        // station with WPA2 enable can't join NonWPA2 AP.
-                        continue;
-                    }
-                }
+  if (pMgmt->eAuthenMode < WMAC_AUTH_WPA) {
+  if (pCurrBSS->bWPAValid == true) {
+  // WPA AP will reject connection of station without WPA enable.
+  continue;
+  }
+  } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
+  (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
+  if (pCurrBSS->bWPAValid == false) {
+  // station with WPA enable can't join NonWPA AP.
+  continue;
+  }
+  } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
+  (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
+  if (pCurrBSS->bWPA2Valid == false) {
+  // station with WPA2 enable can't join NonWPA2 AP.
+  continue;
+  }
+  }
 */
-                if (pSelect == NULL) {
-                    pSelect = pCurrBSS;
-                } else {
-                    // compare RSSI, select signal strong one
-                    if (pCurrBSS->uRSSI < pSelect->uRSSI) {
-                        pSelect = pCurrBSS;
-                    }
-                }
-            }
-        }
-        if (pSelect != NULL) {
-            pSelect->bSelected = true;
+                               if (pSelect == NULL) {
+                                       pSelect = pCurrBSS;
+                               } else {
+                                       // compare RSSI, select signal strong one
+                                       if (pCurrBSS->uRSSI < pSelect->uRSSI) {
+                                               pSelect = pCurrBSS;
+                                       }
+                               }
+                       }
+               }
+               if (pSelect != NULL) {
+                       pSelect->bSelected = true;
 /*
-                        if (pDevice->bRoaming == false)  {
-       //       Einsn Add @20070907
-                       memset(pbyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-                       memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ;
-                                                }*/
-
-            return(pSelect);
-        }
-    }
-    return(NULL);
+  if (pDevice->bRoaming == false)  {
+  //       Einsn Add @20070907
+  memset(pbyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+  memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+  }*/
 
+                       return pSelect;
+               }
+       }
+       return NULL;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -276,42 +260,39 @@ if(pDevice->bLinkPass==false) pCurrBSS->bSelected = false;
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 void
 BSSvClearBSSList(
-    void *hDeviceContext,
-    bool bKeepCurrBSSID
-    )
+       void *hDeviceContext,
+       bool bKeepCurrBSSID
+)
 {
-    PSDevice     pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned int ii;
-
-    for (ii = 0; ii < MAX_BSS_NUM; ii++) {
-        if (bKeepCurrBSSID) {
-            if (pMgmt->sBSSList[ii].bActive &&
-                !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pMgmt->abyCurrBSSID)) {
-               // bKeepCurrBSSID = false;
-                continue;
-            }
-        }
-
-        if ((pMgmt->sBSSList[ii].bActive) && (pMgmt->sBSSList[ii].uClearCount < BSS_CLEAR_COUNT)) {
-             pMgmt->sBSSList[ii].uClearCount ++;
-             continue;
-        }
-
-        pMgmt->sBSSList[ii].bActive = false;
-        memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
-    }
-    BSSvClearAnyBSSJoinRecord(pDevice);
-
-    return;
-}
+       PSDevice     pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned int ii;
+
+       for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+               if (bKeepCurrBSSID) {
+                       if (pMgmt->sBSSList[ii].bActive &&
+                           !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pMgmt->abyCurrBSSID)) {
+                               // bKeepCurrBSSID = false;
+                               continue;
+                       }
+               }
 
+               if ((pMgmt->sBSSList[ii].bActive) && (pMgmt->sBSSList[ii].uClearCount < BSS_CLEAR_COUNT)) {
+                       pMgmt->sBSSList[ii].uClearCount++;
+                       continue;
+               }
 
+               pMgmt->sBSSList[ii].bActive = false;
+               memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
+       }
+       BSSvClearAnyBSSJoinRecord(pDevice);
+
+       return;
+}
 
 /*+
  *
@@ -321,39 +302,35 @@ BSSvClearBSSList(
  * Return Value:
  *    true if found.
  *
--*/
+ -*/
 PKnownBSS
 BSSpAddrIsInBSSList(
-    void *hDeviceContext,
-    unsigned char *abyBSSID,
-    PWLAN_IE_SSID pSSID
-    )
+       void *hDeviceContext,
+       unsigned char *abyBSSID,
+       PWLAN_IE_SSID pSSID
+)
 {
-    PSDevice     pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    PKnownBSS       pBSSList = NULL;
-    unsigned int ii;
-
-    for (ii = 0; ii < MAX_BSS_NUM; ii++) {
-        pBSSList = &(pMgmt->sBSSList[ii]);
-        if (pBSSList->bActive) {
-            if (!compare_ether_addr(pBSSList->abyBSSID, abyBSSID)) {
-//                if (pSSID == NULL)
-//                    return pBSSList;
-                if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len){
-                    if (memcmp(pSSID->abySSID,
-                            ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
-                            pSSID->len) == 0)
-                        return pBSSList;
-                }
-            }
-        }
-    }
-
-    return NULL;
-};
-
+       PSDevice     pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PKnownBSS       pBSSList = NULL;
+       unsigned int ii;
+
+       for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+               pBSSList = &(pMgmt->sBSSList[ii]);
+               if (pBSSList->bActive) {
+                       if (!compare_ether_addr(pBSSList->abyBSSID, abyBSSID)) {
+                               if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len) {
+                                       if (memcmp(pSSID->abySSID,
+                                                  ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
+                                                  pSSID->len) == 0)
+                                               return pBSSList;
+                               }
+                       }
+               }
+       }
 
+       return NULL;
+};
 
 /*+
  *
@@ -363,212 +340,206 @@ BSSpAddrIsInBSSList(
  * Return Value:
  *    true if success.
  *
--*/
+ -*/
 
 bool
-BSSbInsertToBSSList (
-    void *hDeviceContext,
-    unsigned char *abyBSSIDAddr,
-    QWORD qwTimestamp,
-    unsigned short wBeaconInterval,
-    unsigned short wCapInfo,
-    unsigned char byCurrChannel,
-    PWLAN_IE_SSID pSSID,
-    PWLAN_IE_SUPP_RATES pSuppRates,
-    PWLAN_IE_SUPP_RATES pExtSuppRates,
-    PERPObject psERP,
-    PWLAN_IE_RSN pRSN,
-    PWLAN_IE_RSN_EXT pRSNWPA,
-    PWLAN_IE_COUNTRY pIE_Country,
-    PWLAN_IE_QUIET pIE_Quiet,
-    unsigned int uIELength,
-    unsigned char *pbyIEs,
-    void *pRxPacketContext
-    )
+BSSbInsertToBSSList(
+       void *hDeviceContext,
+       unsigned char *abyBSSIDAddr,
+       QWORD qwTimestamp,
+       unsigned short wBeaconInterval,
+       unsigned short wCapInfo,
+       unsigned char byCurrChannel,
+       PWLAN_IE_SSID pSSID,
+       PWLAN_IE_SUPP_RATES pSuppRates,
+       PWLAN_IE_SUPP_RATES pExtSuppRates,
+       PERPObject psERP,
+       PWLAN_IE_RSN pRSN,
+       PWLAN_IE_RSN_EXT pRSNWPA,
+       PWLAN_IE_COUNTRY pIE_Country,
+       PWLAN_IE_QUIET pIE_Quiet,
+       unsigned int uIELength,
+       unsigned char *pbyIEs,
+       void *pRxPacketContext
+)
 {
+       PSDevice     pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSRxMgmtPacket  pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
+       PKnownBSS       pBSSList = NULL;
+       unsigned int ii;
+       bool bParsingQuiet = false;
+       PWLAN_IE_QUIET  pQuiet = NULL;
+
+       pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
+
+       for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+               pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
+               if (!pBSSList->bActive)
+                       break;
+       }
+
+       if (ii == MAX_BSS_NUM) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
+               return false;
+       }
+       // save the BSS info
+       pBSSList->bActive = true;
+       memcpy(pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
+       HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
+       LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
+       pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
+       pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
+       pBSSList->uClearCount = 0;
+
+       if (pSSID->len > WLAN_SSID_MAXLEN)
+               pSSID->len = WLAN_SSID_MAXLEN;
+       memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
+
+       pBSSList->uChannel = byCurrChannel;
+
+       if (pSuppRates->len > WLAN_RATES_MAXLEN)
+               pSuppRates->len = WLAN_RATES_MAXLEN;
+       memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
+
+       if (pExtSuppRates != NULL) {
+               if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
+                       pExtSuppRates->len = WLAN_RATES_MAXLEN;
+               memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
+
+       } else {
+               memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
+       }
+       pBSSList->sERP.byERP = psERP->byERP;
+       pBSSList->sERP.bERPExist = psERP->bERPExist;
+
+       // Check if BSS is 802.11a/b/g
+       if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
+               pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
+       } else {
+               if (pBSSList->sERP.bERPExist == true) {
+                       pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
+               } else {
+                       pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
+               }
+       }
+
+       pBSSList->byRxRate = pRxPacket->byRxRate;
+       pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
+       pBSSList->uRSSI = pRxPacket->uRSSI;
+       pBSSList->bySQ = pRxPacket->bySQ;
+
+       if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
+           (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
+               // assoc with BSS
+               if (pBSSList == pMgmt->pCurrBSS) {
+                       bParsingQuiet = true;
+               }
+       }
 
-    PSDevice     pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    PSRxMgmtPacket  pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
-    PKnownBSS       pBSSList = NULL;
-    unsigned int ii;
-    bool bParsingQuiet = false;
-    PWLAN_IE_QUIET  pQuiet = NULL;
-
-
-
-    pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
-
-    for (ii = 0; ii < MAX_BSS_NUM; ii++) {
-        pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
-        if (!pBSSList->bActive)
-                break;
-    }
-
-    if (ii == MAX_BSS_NUM){
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
-        return false;
-    }
-    // save the BSS info
-    pBSSList->bActive = true;
-    memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
-    HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
-    LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
-    pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
-    pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
-    pBSSList->uClearCount = 0;
-
-    if (pSSID->len > WLAN_SSID_MAXLEN)
-        pSSID->len = WLAN_SSID_MAXLEN;
-    memcpy( pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
-
-    pBSSList->uChannel = byCurrChannel;
-
-    if (pSuppRates->len > WLAN_RATES_MAXLEN)
-        pSuppRates->len = WLAN_RATES_MAXLEN;
-    memcpy( pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
-
-    if (pExtSuppRates != NULL) {
-        if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
-            pExtSuppRates->len = WLAN_RATES_MAXLEN;
-        memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
-
-    } else {
-        memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
-    }
-    pBSSList->sERP.byERP = psERP->byERP;
-    pBSSList->sERP.bERPExist = psERP->bERPExist;
-
-    // Check if BSS is 802.11a/b/g
-    if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
-        pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
-    } else {
-        if (pBSSList->sERP.bERPExist == true) {
-            pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
-        } else {
-            pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
-        }
-    }
-
-    pBSSList->byRxRate = pRxPacket->byRxRate;
-    pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
-    pBSSList->uRSSI = pRxPacket->uRSSI;
-    pBSSList->bySQ = pRxPacket->bySQ;
-
-   if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
-        (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
-        // assoc with BSS
-        if (pBSSList == pMgmt->pCurrBSS) {
-            bParsingQuiet = true;
-        }
-    }
-
-    WPA_ClearRSN(pBSSList);
-
-    if (pRSNWPA != NULL) {
-        unsigned int uLen = pRSNWPA->len + 2;
-
-        if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
-            pBSSList->wWPALen = uLen;
-            memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
-            WPA_ParseRSN(pBSSList, pRSNWPA);
-        }
-    }
-
-    WPA2_ClearRSN(pBSSList);
-
-    if (pRSN != NULL) {
-        unsigned int uLen = pRSN->len + 2;
-        if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
-            pBSSList->wRSNLen = uLen;
-            memcpy(pBSSList->byRSNIE, pRSN, uLen);
-            WPA2vParseRSN(pBSSList, pRSN);
-        }
-    }
-
-    if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == true)) {
-
-        PSKeyItem  pTransmitKey = NULL;
-        bool bIs802_1x = false;
-
-        for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) {
-            if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
-                bIs802_1x = true;
-                break;
-            }
-        }
-        if ((bIs802_1x == true) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
-            ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
-
-            bAdd_PMKID_Candidate((void *)pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj);
-
-            if ((pDevice->bLinkPass == true) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
-                if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) ||
-                    (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == true)) {
-                    pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
-                    pDevice->gsPMKIDCandidate.Version = 1;
-
-                }
-
-            }
-        }
-    }
-
-    if (pDevice->bUpdateBBVGA) {
-        // Moniter if RSSI is too strong.
-        pBSSList->byRSSIStatCnt = 0;
-        RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
-        pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
-        for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
-            pBSSList->ldBmAverage[ii] = 0;
-    }
-
-    if ((pIE_Country != NULL) &&
-        (pMgmt->b11hEnable == true)) {
-        set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
-                            pIE_Country);
-    }
-
-    if ((bParsingQuiet == true) && (pIE_Quiet != NULL)) {
-        if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
-            (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
-            // valid EID
-            if (pQuiet == NULL) {
-                pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
-                CARDbSetQuiet(  pMgmt->pAdapter,
-                                true,
-                                pQuiet->byQuietCount,
-                                pQuiet->byQuietPeriod,
-                                *((unsigned short *)pQuiet->abyQuietDuration),
-                                *((unsigned short *)pQuiet->abyQuietOffset)
-                                );
-            } else {
-                pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
-                CARDbSetQuiet(  pMgmt->pAdapter,
-                                false,
-                                pQuiet->byQuietCount,
-                                pQuiet->byQuietPeriod,
-                                *((unsigned short *)pQuiet->abyQuietDuration),
-                                *((unsigned short *)pQuiet->abyQuietOffset)
-                                );
-            }
-        }
-    }
-
-    if ((bParsingQuiet == true) &&
-        (pQuiet != NULL)) {
-        CARDbStartQuiet(pMgmt->pAdapter);
-    }
-
-    pBSSList->uIELength = uIELength;
-    if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
-        pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
-    memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
-
-    return true;
-}
+       WPA_ClearRSN(pBSSList);
 
+       if (pRSNWPA != NULL) {
+               unsigned int uLen = pRSNWPA->len + 2;
+
+               if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
+                       pBSSList->wWPALen = uLen;
+                       memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
+                       WPA_ParseRSN(pBSSList, pRSNWPA);
+               }
+       }
+
+       WPA2_ClearRSN(pBSSList);
+
+       if (pRSN != NULL) {
+               unsigned int uLen = pRSN->len + 2;
+               if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
+                       pBSSList->wRSNLen = uLen;
+                       memcpy(pBSSList->byRSNIE, pRSN, uLen);
+                       WPA2vParseRSN(pBSSList, pRSN);
+               }
+       }
+
+       if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == true)) {
+               PSKeyItem  pTransmitKey = NULL;
+               bool bIs802_1x = false;
+
+               for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii++) {
+                       if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
+                               bIs802_1x = true;
+                               break;
+                       }
+               }
+               if ((bIs802_1x == true) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
+                   (!memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
+                       bAdd_PMKID_Candidate((void *)pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj);
+
+                       if ((pDevice->bLinkPass == true) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
+                               if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) ||
+                                   (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == true)) {
+                                       pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
+                                       pDevice->gsPMKIDCandidate.Version = 1;
+
+                               }
+
+                       }
+               }
+       }
+
+       if (pDevice->bUpdateBBVGA) {
+               // Moniter if RSSI is too strong.
+               pBSSList->byRSSIStatCnt = 0;
+               RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
+               pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
+               for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
+                       pBSSList->ldBmAverage[ii] = 0;
+       }
+
+       if ((pIE_Country != NULL) &&
+           (pMgmt->b11hEnable == true)) {
+               set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
+                                pIE_Country);
+       }
+
+       if ((bParsingQuiet == true) && (pIE_Quiet != NULL)) {
+               if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
+                   (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
+                       // valid EID
+                       if (pQuiet == NULL) {
+                               pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
+                               CARDbSetQuiet(pMgmt->pAdapter,
+                                             true,
+                                             pQuiet->byQuietCount,
+                                             pQuiet->byQuietPeriod,
+                                             *((unsigned short *)pQuiet->abyQuietDuration),
+                                             *((unsigned short *)pQuiet->abyQuietOffset)
+);
+                       } else {
+                               pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
+                               CARDbSetQuiet(pMgmt->pAdapter,
+                                             false,
+                                             pQuiet->byQuietCount,
+                                             pQuiet->byQuietPeriod,
+                                             *((unsigned short *)pQuiet->abyQuietDuration),
+                                             *((unsigned short *)pQuiet->abyQuietOffset)
+                                       );
+                       }
+               }
+       }
+
+       if ((bParsingQuiet == true) &&
+           (pQuiet != NULL)) {
+               CARDbStartQuiet(pMgmt->pAdapter);
+       }
+
+       pBSSList->uIELength = uIELength;
+       if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
+               pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
+       memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
+
+       return true;
+}
 
 /*+
  *
@@ -578,176 +549,169 @@ BSSbInsertToBSSList (
  * Return Value:
  *    true if success.
  *
--*/
+ -*/
 // TODO: input structure modify
 
 bool
-BSSbUpdateToBSSList (
-    void *hDeviceContext,
-    QWORD qwTimestamp,
-    unsigned short wBeaconInterval,
-    unsigned short wCapInfo,
-    unsigned char byCurrChannel,
-    bool bChannelHit,
-    PWLAN_IE_SSID pSSID,
-    PWLAN_IE_SUPP_RATES pSuppRates,
-    PWLAN_IE_SUPP_RATES pExtSuppRates,
-    PERPObject psERP,
-    PWLAN_IE_RSN pRSN,
-    PWLAN_IE_RSN_EXT pRSNWPA,
-    PWLAN_IE_COUNTRY pIE_Country,
-    PWLAN_IE_QUIET pIE_Quiet,
-    PKnownBSS pBSSList,
-    unsigned int uIELength,
-    unsigned char *pbyIEs,
-    void *pRxPacketContext
-    )
+BSSbUpdateToBSSList(
+       void *hDeviceContext,
+       QWORD qwTimestamp,
+       unsigned short wBeaconInterval,
+       unsigned short wCapInfo,
+       unsigned char byCurrChannel,
+       bool bChannelHit,
+       PWLAN_IE_SSID pSSID,
+       PWLAN_IE_SUPP_RATES pSuppRates,
+       PWLAN_IE_SUPP_RATES pExtSuppRates,
+       PERPObject psERP,
+       PWLAN_IE_RSN pRSN,
+       PWLAN_IE_RSN_EXT pRSNWPA,
+       PWLAN_IE_COUNTRY pIE_Country,
+       PWLAN_IE_QUIET pIE_Quiet,
+       PKnownBSS pBSSList,
+       unsigned int uIELength,
+       unsigned char *pbyIEs,
+       void *pRxPacketContext
+)
 {
-    int             ii;
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    PSRxMgmtPacket  pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
-    long            ldBm;
-    bool bParsingQuiet = false;
-    PWLAN_IE_QUIET  pQuiet = NULL;
-
-
-
-    if (pBSSList == NULL)
-        return false;
-
-
-    HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
-    LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
-    pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
-    pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
-    pBSSList->uClearCount = 0;
-    pBSSList->uChannel = byCurrChannel;
-//    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbUpdateToBSSList: pBSSList->uChannel: %d\n", pBSSList->uChannel);
-
-    if (pSSID->len > WLAN_SSID_MAXLEN)
-        pSSID->len = WLAN_SSID_MAXLEN;
-
-    if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
-        memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
-    memcpy(pBSSList->abySuppRates, pSuppRates,pSuppRates->len + WLAN_IEHDR_LEN);
-
-    if (pExtSuppRates != NULL) {
-        memcpy(pBSSList->abyExtSuppRates, pExtSuppRates,pExtSuppRates->len + WLAN_IEHDR_LEN);
-    } else {
-        memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
-    }
-    pBSSList->sERP.byERP = psERP->byERP;
-    pBSSList->sERP.bERPExist = psERP->bERPExist;
-
-    // Check if BSS is 802.11a/b/g
-    if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
-        pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
-    } else {
-        if (pBSSList->sERP.bERPExist == true) {
-            pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
-        } else {
-            pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
-        }
-    }
-
-    pBSSList->byRxRate = pRxPacket->byRxRate;
-    pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
-    if(bChannelHit)
-        pBSSList->uRSSI = pRxPacket->uRSSI;
-    pBSSList->bySQ = pRxPacket->bySQ;
-
-   if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
-        (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
-        // assoc with BSS
-        if (pBSSList == pMgmt->pCurrBSS) {
-            bParsingQuiet = true;
-        }
-    }
-
-   WPA_ClearRSN(pBSSList);         //mike update
-
-    if (pRSNWPA != NULL) {
-        unsigned int uLen = pRSNWPA->len + 2;
-        if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
-            pBSSList->wWPALen = uLen;
-            memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
-            WPA_ParseRSN(pBSSList, pRSNWPA);
-        }
-    }
-
-   WPA2_ClearRSN(pBSSList);  //mike update
-
-    if (pRSN != NULL) {
-        unsigned int uLen = pRSN->len + 2;
-        if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
-            pBSSList->wRSNLen = uLen;
-            memcpy(pBSSList->byRSNIE, pRSN, uLen);
-            WPA2vParseRSN(pBSSList, pRSN);
-        }
-    }
-
-    if (pRxPacket->uRSSI != 0) {
-        RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &ldBm);
-        // Moniter if RSSI is too strong.
-        pBSSList->byRSSIStatCnt++;
-        pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
-        pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
-        for(ii=0;ii<RSSI_STAT_COUNT;ii++) {
-            if (pBSSList->ldBmAverage[ii] != 0) {
-                pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
-            }
-        }
-    }
-
-    if ((pIE_Country != NULL) &&
-        (pMgmt->b11hEnable == true)) {
-        set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
-                            pIE_Country);
-    }
-
-    if ((bParsingQuiet == true) && (pIE_Quiet != NULL)) {
-        if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
-            (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
-            // valid EID
-            if (pQuiet == NULL) {
-                pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
-                CARDbSetQuiet(  pMgmt->pAdapter,
-                                true,
-                                pQuiet->byQuietCount,
-                                pQuiet->byQuietPeriod,
-                                *((unsigned short *)pQuiet->abyQuietDuration),
-                                *((unsigned short *)pQuiet->abyQuietOffset)
-                                );
-            } else {
-                pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
-                CARDbSetQuiet(  pMgmt->pAdapter,
-                                false,
-                                pQuiet->byQuietCount,
-                                pQuiet->byQuietPeriod,
-                                *((unsigned short *)pQuiet->abyQuietDuration),
-                                *((unsigned short *)pQuiet->abyQuietOffset)
-                                );
-            }
-        }
-    }
-
-    if ((bParsingQuiet == true) &&
-        (pQuiet != NULL)) {
-        CARDbStartQuiet(pMgmt->pAdapter);
-    }
-
-    pBSSList->uIELength = uIELength;
-    if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
-        pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
-    memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
-
-    return true;
-}
+       int             ii;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSRxMgmtPacket  pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
+       long            ldBm;
+       bool bParsingQuiet = false;
+       PWLAN_IE_QUIET  pQuiet = NULL;
+
+       if (pBSSList == NULL)
+               return false;
+
+       HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
+       LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
+       pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
+       pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
+       pBSSList->uClearCount = 0;
+       pBSSList->uChannel = byCurrChannel;
+//    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSbUpdateToBSSList: pBSSList->uChannel: %d\n", pBSSList->uChannel);
+
+       if (pSSID->len > WLAN_SSID_MAXLEN)
+               pSSID->len = WLAN_SSID_MAXLEN;
+
+       if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
+               memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
+       memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
+
+       if (pExtSuppRates != NULL) {
+               memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
+       } else {
+               memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
+       }
+       pBSSList->sERP.byERP = psERP->byERP;
+       pBSSList->sERP.bERPExist = psERP->bERPExist;
+
+       // Check if BSS is 802.11a/b/g
+       if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
+               pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
+       } else {
+               if (pBSSList->sERP.bERPExist == true) {
+                       pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
+               } else {
+                       pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
+               }
+       }
+
+       pBSSList->byRxRate = pRxPacket->byRxRate;
+       pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
+       if (bChannelHit)
+               pBSSList->uRSSI = pRxPacket->uRSSI;
+       pBSSList->bySQ = pRxPacket->bySQ;
+
+       if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
+           (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
+               // assoc with BSS
+               if (pBSSList == pMgmt->pCurrBSS) {
+                       bParsingQuiet = true;
+               }
+       }
 
+       WPA_ClearRSN(pBSSList);         //mike update
 
+       if (pRSNWPA != NULL) {
+               unsigned int uLen = pRSNWPA->len + 2;
+               if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
+                       pBSSList->wWPALen = uLen;
+                       memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
+                       WPA_ParseRSN(pBSSList, pRSNWPA);
+               }
+       }
+
+       WPA2_ClearRSN(pBSSList);  //mike update
+
+       if (pRSN != NULL) {
+               unsigned int uLen = pRSN->len + 2;
+               if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
+                       pBSSList->wRSNLen = uLen;
+                       memcpy(pBSSList->byRSNIE, pRSN, uLen);
+                       WPA2vParseRSN(pBSSList, pRSN);
+               }
+       }
+
+       if (pRxPacket->uRSSI != 0) {
+               RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &ldBm);
+               // Moniter if RSSI is too strong.
+               pBSSList->byRSSIStatCnt++;
+               pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
+               pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
+               for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
+                       if (pBSSList->ldBmAverage[ii] != 0) {
+                               pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
+                       }
+               }
+       }
+
+       if ((pIE_Country != NULL) &&
+           (pMgmt->b11hEnable == true)) {
+               set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
+                                pIE_Country);
+       }
+
+       if ((bParsingQuiet == true) && (pIE_Quiet != NULL)) {
+               if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
+                   (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
+                       // valid EID
+                       if (pQuiet == NULL) {
+                               pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
+                               CARDbSetQuiet(pMgmt->pAdapter,
+                                             true,
+                                             pQuiet->byQuietCount,
+                                             pQuiet->byQuietPeriod,
+                                             *((unsigned short *)pQuiet->abyQuietDuration),
+                                             *((unsigned short *)pQuiet->abyQuietOffset)
+);
+                       } else {
+                               pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
+                               CARDbSetQuiet(pMgmt->pAdapter,
+                                             false,
+                                             pQuiet->byQuietCount,
+                                             pQuiet->byQuietPeriod,
+                                             *((unsigned short *)pQuiet->abyQuietDuration),
+                                             *((unsigned short *)pQuiet->abyQuietOffset)
+                                       );
+                       }
+               }
+       }
 
+       if ((bParsingQuiet == true) &&
+           (pQuiet != NULL)) {
+               CARDbStartQuiet(pMgmt->pAdapter);
+       }
 
+       pBSSList->uIELength = uIELength;
+       if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
+               pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
+       memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
+
+       return true;
+}
 
 /*+
  *
@@ -757,29 +721,27 @@ BSSbUpdateToBSSList (
  * Return Value:
  *    None
  *
--*/
+ -*/
 
 bool
 BSSDBbIsSTAInNodeDB(void *pMgmtObject, unsigned char *abyDstAddr,
-               unsigned int *puNodeIndex)
+                   unsigned int *puNodeIndex)
 {
-    PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
-    unsigned int ii;
-
-    // Index = 0 reserved for AP Node
-    for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
-        if (pMgmt->sNodeDBTable[ii].bActive) {
-            if (!compare_ether_addr(abyDstAddr, pMgmt->sNodeDBTable[ii].abyMACAddr)) {
-                *puNodeIndex = ii;
-                return true;
-            }
-        }
-    }
-
-   return false;
-};
-
+       PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
+       unsigned int ii;
+
+       // Index = 0 reserved for AP Node
+       for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
+               if (pMgmt->sNodeDBTable[ii].bActive) {
+                       if (!compare_ether_addr(abyDstAddr, pMgmt->sNodeDBTable[ii].abyMACAddr)) {
+                               *puNodeIndex = ii;
+                               return true;
+                       }
+               }
+       }
 
+       return false;
+};
 
 /*+
  *
@@ -790,59 +752,54 @@ BSSDBbIsSTAInNodeDB(void *pMgmtObject, unsigned char *abyDstAddr,
  * Return Value:
  *    None
  *
--*/
+ -*/
 void
 BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
 {
-
-    PSDevice     pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned int ii;
-    unsigned int BigestCount = 0;
-    unsigned int SelectIndex;
-    struct sk_buff  *skb;
-    // Index = 0 reserved for AP Node (In STA mode)
-    // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
-    SelectIndex = 1;
-    for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
-        if (pMgmt->sNodeDBTable[ii].bActive) {
-            if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
-                BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
-                SelectIndex = ii;
-            }
-        }
-        else {
-            break;
-        }
-    }
-
-    // if not found replace uInActiveCount is largest one.
-    if ( ii == (MAX_NODE_NUM + 1)) {
-        *puNodeIndex = SelectIndex;
-        DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
-        // clear ps buffer
-        if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
-           while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
-            dev_kfree_skb(skb);
-        }
-    }
-    else {
-        *puNodeIndex = ii;
-    }
-
-    memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
-    pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
-    pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
-    // for AP mode PS queue
-    skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
-    pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
-    pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
-    return;
+       PSDevice     pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned int ii;
+       unsigned int BigestCount = 0;
+       unsigned int SelectIndex;
+       struct sk_buff  *skb;
+       // Index = 0 reserved for AP Node (In STA mode)
+       // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
+       SelectIndex = 1;
+       for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
+               if (pMgmt->sNodeDBTable[ii].bActive) {
+                       if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
+                               BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
+                               SelectIndex = ii;
+                       }
+               } else {
+                       break;
+               }
+       }
+
+       // if not found replace uInActiveCount is largest one.
+       if (ii == (MAX_NODE_NUM + 1)) {
+               *puNodeIndex = SelectIndex;
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
+               // clear ps buffer
+               if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
+                       while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
+                               dev_kfree_skb(skb);
+               }
+       } else {
+               *puNodeIndex = ii;
+       }
+
+       memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
+       pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
+       pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
+       // for AP mode PS queue
+       skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
+       pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
+       pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
+       return;
 };
 
-
-
 /*+
  *
  * Routine Description:
@@ -852,28 +809,26 @@ BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
  * Return Value:
  *    None
  *
--*/
+ -*/
 void
 BSSvRemoveOneNode(
-    void *hDeviceContext,
-    unsigned int uNodeIndex
-    )
+       void *hDeviceContext,
+       unsigned int uNodeIndex
+)
 {
-
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
-    struct sk_buff  *skb;
-
-
-    while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
-            dev_kfree_skb(skb);
-    // clear context
-    memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
-    // clear tx bit map
-    pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &=  ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
-
-    return;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
+       struct sk_buff  *skb;
+
+       while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
+               dev_kfree_skb(skb);
+       // clear context
+       memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
+       // clear tx bit map
+       pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &=  ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
+
+       return;
 };
 /*+
  *
@@ -884,59 +839,54 @@ BSSvRemoveOneNode(
  * Return Value:
  *    None
  *
--*/
+ -*/
 
 void
 BSSvUpdateAPNode(
-    void *hDeviceContext,
-    unsigned short *pwCapInfo,
-    PWLAN_IE_SUPP_RATES pSuppRates,
-    PWLAN_IE_SUPP_RATES pExtSuppRates
-    )
+       void *hDeviceContext,
+       unsigned short *pwCapInfo,
+       PWLAN_IE_SUPP_RATES pSuppRates,
+       PWLAN_IE_SUPP_RATES pExtSuppRates
+)
 {
-    PSDevice     pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned int uRateLen = WLAN_RATES_MAXLEN;
-
-    memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
-
-    pMgmt->sNodeDBTable[0].bActive = true;
-    if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
-        uRateLen = WLAN_RATES_MAXLEN_11B;
-    }
-    pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
-                                            (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                                            uRateLen);
-    pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
-                                            (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
-                                            uRateLen);
-    RATEvParseMaxRate((void *)pDevice,
-                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
-                       true,
-                       &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
-                       &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
-                       &(pMgmt->sNodeDBTable[0].wSuppRate),
-                       &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
-                       &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
-                      );
-    memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
-    pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
-    pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
-    pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
+       PSDevice     pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned int uRateLen = WLAN_RATES_MAXLEN;
+
+       memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
+
+       pMgmt->sNodeDBTable[0].bActive = true;
+       if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
+               uRateLen = WLAN_RATES_MAXLEN_11B;
+       }
+       pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
+                                               (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                                               uRateLen);
+       pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
+                                                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
+                                                  uRateLen);
+       RATEvParseMaxRate((void *)pDevice,
+                         (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                         (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
+                         true,
+                         &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
+                         &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
+                         &(pMgmt->sNodeDBTable[0].wSuppRate),
+                         &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
+                         &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
+);
+       memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
+       pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
+       pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
+       pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
 #ifdef PLICE_DEBUG
-       printk("BSSvUpdateAPNode:MaxSuppRate is %d\n",pMgmt->sNodeDBTable[0].wMaxSuppRate);
+       printk("BSSvUpdateAPNode:MaxSuppRate is %d\n", pMgmt->sNodeDBTable[0].wMaxSuppRate);
 #endif
-    // Auto rate fallback function initiation.
-    // RATEbInit(pDevice);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->sNodeDBTable[0].wTxDataRate = %d \n", pMgmt->sNodeDBTable[0].wTxDataRate);
-
+       // Auto rate fallback function initiation.
+       // RATEbInit(pDevice);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->sNodeDBTable[0].wTxDataRate = %d \n", pMgmt->sNodeDBTable[0].wTxDataRate);
 };
 
-
-
-
-
 /*+
  *
  * Routine Description:
@@ -946,45 +896,39 @@ BSSvUpdateAPNode(
  * Return Value:
  *    None
  *
--*/
-
+ -*/
 
 void
 BSSvAddMulticastNode(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-    PSDevice     pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-
-    if (!pDevice->bEnableHostWEP)
-        memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
-    memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
-    pMgmt->sNodeDBTable[0].bActive = true;
-    pMgmt->sNodeDBTable[0].bPSEnable = false;
-    skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
-    RATEvParseMaxRate((void *)pDevice,
-                      (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                      (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
-                      true,
-                      &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
-                      &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
-                       &(pMgmt->sNodeDBTable[0].wSuppRate),
-                      &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
-                      &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
-                     );
-    pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
+       PSDevice     pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+
+       if (!pDevice->bEnableHostWEP)
+               memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
+       memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
+       pMgmt->sNodeDBTable[0].bActive = true;
+       pMgmt->sNodeDBTable[0].bPSEnable = false;
+       skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
+       RATEvParseMaxRate((void *)pDevice,
+                         (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                         (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
+                         true,
+                         &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
+                         &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
+                         &(pMgmt->sNodeDBTable[0].wSuppRate),
+                         &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
+                         &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
+);
+       pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
 #ifdef PLICE_DEBUG
-       printk("BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
+       printk("BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n", pMgmt->sNodeDBTable[0].wTxDataRate);
 #endif
-    pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
-
+       pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
 };
 
-
-
-
-
 /*+
  *
  * Routine Description:
@@ -996,373 +940,348 @@ BSSvAddMulticastNode(
  * Return Value:
  *    none.
  *
--*/
- //2008-4-14 <add> by chester for led issue
- #ifdef FOR_LED_ON_NOTEBOOK
-bool cc=false;
+ -*/
+//2008-4-14 <add> by chester for led issue
+#ifdef FOR_LED_ON_NOTEBOOK
+bool cc = false;
 unsigned int status;
 #endif
 void
 BSSvSecondCallBack(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned int ii;
-    PWLAN_IE_SSID   pItemSSID, pCurrSSID;
-    unsigned int uSleepySTACnt = 0;
-    unsigned int uNonShortSlotSTACnt = 0;
-    unsigned int uLongPreambleSTACnt = 0;
-    viawget_wpa_header* wpahdr;  //DavidWang
-
-    spin_lock_irq(&pDevice->lock);
-
-    pDevice->uAssocCount = 0;
-
-    pDevice->byERPFlag &=
-        ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
- //2008-4-14 <add> by chester for led issue
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned int ii;
+       PWLAN_IE_SSID   pItemSSID, pCurrSSID;
+       unsigned int uSleepySTACnt = 0;
+       unsigned int uNonShortSlotSTACnt = 0;
+       unsigned int uLongPreambleSTACnt = 0;
+       viawget_wpa_header *wpahdr;  //DavidWang
+
+       spin_lock_irq(&pDevice->lock);
+
+       pDevice->uAssocCount = 0;
+
+       pDevice->byERPFlag &=
+               ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
      //2008-4-14 <add> by chester for led issue
 #ifdef FOR_LED_ON_NOTEBOOK
-MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
-if ((( !(pDevice->byGPIO & GPIO0_DATA)&&(pDevice->bHWRadioOff == false))||((pDevice->byGPIO & GPIO0_DATA)&&(pDevice->bHWRadioOff == true)))&&(cc==false)){
-cc=true;
-}
-else if(cc==true){
-
-if(pDevice->bHWRadioOff == true){
-            if ( !(pDevice->byGPIO & GPIO0_DATA))
-//||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
-{if(status==1) goto start;
-status=1;
-CARDbRadioPowerOff(pDevice);
-                pMgmt->sNodeDBTable[0].bActive = false;
-                pMgmt->eCurrMode = WMAC_MODE_STANDBY;
-                pMgmt->eCurrState = WMAC_STATE_IDLE;
-                //netif_stop_queue(pDevice->dev);
-                pDevice->bLinkPass = false;
-
-}
-  if (pDevice->byGPIO &GPIO0_DATA)
-//||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
-{if(status==2) goto start;
-status=2;
-CARDbRadioPowerOn(pDevice);
-} }
-else{
-            if (pDevice->byGPIO & GPIO0_DATA)
-//||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
-{if(status==3) goto start;
-status=3;
-CARDbRadioPowerOff(pDevice);
-                pMgmt->sNodeDBTable[0].bActive = false;
-                pMgmt->eCurrMode = WMAC_MODE_STANDBY;
-                pMgmt->eCurrState = WMAC_STATE_IDLE;
-                //netif_stop_queue(pDevice->dev);
-                pDevice->bLinkPass = false;
-
-}
-  if ( !(pDevice->byGPIO & GPIO0_DATA))
-//||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
-{if(status==4) goto start;
-status=4;
-CARDbRadioPowerOn(pDevice);
-} }
-}
+       MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
+       if (((!(pDevice->byGPIO & GPIO0_DATA) && (pDevice->bHWRadioOff == false)) || ((pDevice->byGPIO & GPIO0_DATA) && (pDevice->bHWRadioOff == true))) && (cc == false)) {
+               cc = true;
+       } else if (cc == true) {
+               if (pDevice->bHWRadioOff == true) {
+                       if (!(pDevice->byGPIO & GPIO0_DATA))
+//||(!(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
+                       {
+                               if (status == 1) goto start;
+                               status = 1;
+                               CARDbRadioPowerOff(pDevice);
+                               pMgmt->sNodeDBTable[0].bActive = false;
+                               pMgmt->eCurrMode = WMAC_MODE_STANDBY;
+                               pMgmt->eCurrState = WMAC_STATE_IDLE;
+                               //netif_stop_queue(pDevice->dev);
+                               pDevice->bLinkPass = false;
+
+                       }
+                       if (pDevice->byGPIO & GPIO0_DATA)
+//||(!(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
+                       {
+                               if (status == 2) goto start;
+                               status = 2;
+                               CARDbRadioPowerOn(pDevice);
+                       }
+               } else {
+                       if (pDevice->byGPIO & GPIO0_DATA)
+//||(!(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
+                       {
+                               if (status == 3) goto start;
+                               status = 3;
+                               CARDbRadioPowerOff(pDevice);
+                               pMgmt->sNodeDBTable[0].bActive = false;
+                               pMgmt->eCurrMode = WMAC_MODE_STANDBY;
+                               pMgmt->eCurrState = WMAC_STATE_IDLE;
+                               //netif_stop_queue(pDevice->dev);
+                               pDevice->bLinkPass = false;
+
+                       }
+                       if (!(pDevice->byGPIO & GPIO0_DATA))
+//||(!(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
+                       {
+                               if (status == 4) goto start;
+                               status = 4;
+                               CARDbRadioPowerOn(pDevice);
+                       }
+               }
+       }
 start:
 #endif
 
-
-    if (pDevice->wUseProtectCntDown > 0) {
-        pDevice->wUseProtectCntDown --;
-    }
-    else {
-        // disable protect mode
-        pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
-    }
-
-{
-       pDevice->byReAssocCount++;
-   if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != true)) {  //10 sec timeout
-                     printk("Re-association timeout!!!\n");
-                  pDevice->byReAssocCount = 0;
-                     #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-                    // if(pDevice->bWPASuppWextEnabled == true)
-                        {
-                       union iwreq_data  wrqu;
-                       memset(&wrqu, 0, sizeof (wrqu));
-                          wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-                       PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
-                       wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
-                       }
-                    #endif
-     }
-   else if(pDevice->bLinkPass == true)
-       pDevice->byReAssocCount = 0;
-}
+       if (pDevice->wUseProtectCntDown > 0) {
+               pDevice->wUseProtectCntDown--;
+       } else {
+               // disable protect mode
+               pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
+       }
+
+       {
+               pDevice->byReAssocCount++;
+               if ((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != true)) {  //10 sec timeout
+                       printk("Re-association timeout!!!\n");
+                       pDevice->byReAssocCount = 0;
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+                       {
+                               union iwreq_data  wrqu;
+                               memset(&wrqu, 0, sizeof(wrqu));
+                               wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+                               PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
+                               wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
+                       }
+#endif
+               } else if (pDevice->bLinkPass == true)
+                       pDevice->byReAssocCount = 0;
+       }
 
 #ifdef Calcu_LinkQual
-   s_uCalculateLinkQual((void *)pDevice);
+       s_uCalculateLinkQual((void *)pDevice);
 #endif
 
-    for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
-
-        if (pMgmt->sNodeDBTable[ii].bActive) {
-            // Increase in-activity counter
-            pMgmt->sNodeDBTable[ii].uInActiveCount++;
-
-            if (ii > 0) {
-                if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
-                    BSSvRemoveOneNode(pDevice, ii);
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
-                        "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
-                    continue;
-                }
-
-                if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
-
-                    pDevice->uAssocCount++;
-
-                    // check if Non ERP exist
-                    if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
-                        if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
-                            pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
-                            uLongPreambleSTACnt ++;
-                        }
-                        if (!pMgmt->sNodeDBTable[ii].bERPExist) {
-                            pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
-                            pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
-                        }
-                        if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
-                            uNonShortSlotSTACnt++;
-                    }
-                }
+       for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
+               if (pMgmt->sNodeDBTable[ii].bActive) {
+                       // Increase in-activity counter
+                       pMgmt->sNodeDBTable[ii].uInActiveCount++;
+
+                       if (ii > 0) {
+                               if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
+                                       BSSvRemoveOneNode(pDevice, ii);
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
+                                               "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
+                                       continue;
+                               }
 
-                // check if any STA in PS mode
-                if (pMgmt->sNodeDBTable[ii].bPSEnable)
-                    uSleepySTACnt++;
+                               if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
+                                       pDevice->uAssocCount++;
+
+                                       // check if Non ERP exist
+                                       if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
+                                               if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
+                                                       pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
+                                                       uLongPreambleSTACnt++;
+                                               }
+                                               if (!pMgmt->sNodeDBTable[ii].bERPExist) {
+                                                       pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
+                                                       pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
+                                               }
+                                               if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
+                                                       uNonShortSlotSTACnt++;
+                                       }
+                               }
 
+                               // check if any STA in PS mode
+                               if (pMgmt->sNodeDBTable[ii].bPSEnable)
+                                       uSleepySTACnt++;
 
-            }
+                       }
 
-            // Rate fallback check
-            if (!pDevice->bFixRate) {
+                       // Rate fallback check
+                       if (!pDevice->bFixRate) {
 /*
-                if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (ii == 0))
-                    RATEvTxRateFallBack(pDevice, &(pMgmt->sNodeDBTable[ii]));
+  if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (ii == 0))
+  RATEvTxRateFallBack(pDevice, &(pMgmt->sNodeDBTable[ii]));
 */
-                if (ii > 0) {
-                    // ii = 0 for multicast node (AP & Adhoc)
-                    RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
-                }
-                else {
-                    // ii = 0 reserved for unicast AP node (Infra STA)
-                    if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
+                               if (ii > 0) {
+                                       // ii = 0 for multicast node (AP & Adhoc)
+                                       RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
+                               } else {
+                                       // ii = 0 reserved for unicast AP node (Infra STA)
+                                       if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
 #ifdef PLICE_DEBUG
-               printk("SecondCallback:Before:TxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
+                                               printk("SecondCallback:Before:TxDataRate is %d\n", pMgmt->sNodeDBTable[0].wTxDataRate);
 #endif
-                        RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
+                                       RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
 #ifdef PLICE_DEBUG
-               printk("SecondCallback:After:TxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
+                                       printk("SecondCallback:After:TxDataRate is %d\n", pMgmt->sNodeDBTable[0].wTxDataRate);
 #endif
 
+                               }
+
+                       }
+
+                       // check if pending PS queue
+                       if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending \n",
+                                       ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
+                               if ((ii > 0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
+                                       BSSvRemoveOneNode(pDevice, ii);
+                                       DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove \n", ii);
+                                       continue;
+                               }
+                       }
                }
 
-            }
-
-            // check if pending PS queue
-            if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending \n",
-                           ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
-                if ((ii >0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
-                    BSSvRemoveOneNode(pDevice, ii);
-                    DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove \n", ii);
-                    continue;
-                }
-            }
-        }
-
-    }
-
-
-    if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
-
-        // on/off protect mode
-        if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
-            if (!pDevice->bProtectMode) {
-                MACvEnableProtectMD(pDevice->PortOffset);
-                pDevice->bProtectMode = true;
-            }
-        }
-        else {
-            if (pDevice->bProtectMode) {
-                MACvDisableProtectMD(pDevice->PortOffset);
-                pDevice->bProtectMode = false;
-            }
-        }
-        // on/off short slot time
-
-        if (uNonShortSlotSTACnt > 0) {
-            if (pDevice->bShortSlotTime) {
-                pDevice->bShortSlotTime = false;
-                BBvSetShortSlotTime(pDevice);
-                vUpdateIFS((void *)pDevice);
-            }
-        }
-        else {
-            if (!pDevice->bShortSlotTime) {
-                pDevice->bShortSlotTime = true;
-                BBvSetShortSlotTime(pDevice);
-                vUpdateIFS((void *)pDevice);
-            }
-        }
-
-        // on/off barker long preamble mode
-
-        if (uLongPreambleSTACnt > 0) {
-            if (!pDevice->bBarkerPreambleMd) {
-                MACvEnableBarkerPreambleMd(pDevice->PortOffset);
-                pDevice->bBarkerPreambleMd = true;
-            }
-        }
-        else {
-            if (pDevice->bBarkerPreambleMd) {
-                MACvDisableBarkerPreambleMd(pDevice->PortOffset);
-                pDevice->bBarkerPreambleMd = false;
-            }
-        }
-
-    }
-
-
-    // Check if any STA in PS mode, enable DTIM multicast deliver
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-        if (uSleepySTACnt > 0)
-            pMgmt->sNodeDBTable[0].bPSEnable = true;
-        else
-            pMgmt->sNodeDBTable[0].bPSEnable = false;
-    }
-
-    pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
-    pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
-
-    if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
-        (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
-
-        if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
-           // DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Callback inactive Count = [%d]\n", pMgmt->sNodeDBTable[0].uInActiveCount);
-            //if (pDevice->bUpdateBBVGA) {
-            //  s_vCheckSensitivity((void *) pDevice);
-            //}
-
-            if (pDevice->bUpdateBBVGA) {
-               // s_vCheckSensitivity((void *) pDevice);
-               s_vCheckPreEDThreshold((void *)pDevice);
-            }
-
-           if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
-               (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0]) ) {
-               pDevice->byBBVGANew = pDevice->abyBBVGA[0];
-                bScheduleCommand((void *) pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
-           }
-
-               if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
-                pMgmt->sNodeDBTable[0].bActive = false;
-                pMgmt->eCurrMode = WMAC_MODE_STANDBY;
-                pMgmt->eCurrState = WMAC_STATE_IDLE;
-                netif_stop_queue(pDevice->dev);
-                pDevice->bLinkPass = false;
-                pDevice->bRoaming = true;
-                DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
-        if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
-             wpahdr = (viawget_wpa_header *)pDevice->skb->data;
-             wpahdr->type = VIAWGET_DISASSOC_MSG;
-             wpahdr->resp_ie_len = 0;
-             wpahdr->req_ie_len = 0;
-             skb_put(pDevice->skb, sizeof(viawget_wpa_header));
-             pDevice->skb->dev = pDevice->wpadev;
-            skb_reset_mac_header(pDevice->skb);
-             pDevice->skb->pkt_type = PACKET_HOST;
-             pDevice->skb->protocol = htons(ETH_P_802_2);
-             memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
-             netif_rx(pDevice->skb);
-             pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-         }
-   #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-  // if(pDevice->bWPASuppWextEnabled == true)
-      {
-       union iwreq_data  wrqu;
-       memset(&wrqu, 0, sizeof (wrqu));
-        wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-       PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
-       wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
-     }
-  #endif
-           }
-        }
-        else if (pItemSSID->len != 0) {
-            if (pDevice->uAutoReConnectTime < 10) {
-                pDevice->uAutoReConnectTime++;
-              #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-                //network manager support need not do Roaming scan???
-                if(pDevice->bWPASuppWextEnabled ==true)
-                pDevice->uAutoReConnectTime = 0;
-            #endif
-            }
-            else {
-          //mike use old encryption status for wpa reauthen
-             if(pDevice->bWPADEVUp)
-                 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
-
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
-                BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
-             pMgmt->eScanType = WMAC_SCAN_ACTIVE;
-                bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
-                bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
-                pDevice->uAutoReConnectTime = 0;
-            }
-        }
-    }
-
-    if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-        // if adhoc started which essid is NULL string, rescanning.
-        if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
-            if (pDevice->uAutoReConnectTime < 10) {
-                pDevice->uAutoReConnectTime++;
-            }
-            else {
-                DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scanning ...\n");
-             pMgmt->eScanType = WMAC_SCAN_ACTIVE;
-                bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
-                bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
-                pDevice->uAutoReConnectTime = 0;
-            };
-        }
-        if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
-
-            if (pDevice->bUpdateBBVGA) {
-               //s_vCheckSensitivity((void *) pDevice);
-               s_vCheckPreEDThreshold((void *)pDevice);
-            }
-               if (pMgmt->sNodeDBTable[0].uInActiveCount >=ADHOC_LOST_BEACON_COUNT) {
-                   DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
-                pMgmt->sNodeDBTable[0].uInActiveCount = 0;
-                pMgmt->eCurrState = WMAC_STATE_STARTED;
-                netif_stop_queue(pDevice->dev);
-                pDevice->bLinkPass = false;
-            }
-        }
-    }
-
-    spin_unlock_irq(&pDevice->lock);
-
-    pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
-    add_timer(&pMgmt->sTimerSecondCallback);
-    return;
-}
+       }
+
+       if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
+               // on/off protect mode
+               if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
+                       if (!pDevice->bProtectMode) {
+                               MACvEnableProtectMD(pDevice->PortOffset);
+                               pDevice->bProtectMode = true;
+                       }
+               } else {
+                       if (pDevice->bProtectMode) {
+                               MACvDisableProtectMD(pDevice->PortOffset);
+                               pDevice->bProtectMode = false;
+                       }
+               }
+               // on/off short slot time
+
+               if (uNonShortSlotSTACnt > 0) {
+                       if (pDevice->bShortSlotTime) {
+                               pDevice->bShortSlotTime = false;
+                               BBvSetShortSlotTime(pDevice);
+                               vUpdateIFS((void *)pDevice);
+                       }
+               } else {
+                       if (!pDevice->bShortSlotTime) {
+                               pDevice->bShortSlotTime = true;
+                               BBvSetShortSlotTime(pDevice);
+                               vUpdateIFS((void *)pDevice);
+                       }
+               }
+
+               // on/off barker long preamble mode
+
+               if (uLongPreambleSTACnt > 0) {
+                       if (!pDevice->bBarkerPreambleMd) {
+                               MACvEnableBarkerPreambleMd(pDevice->PortOffset);
+                               pDevice->bBarkerPreambleMd = true;
+                       }
+               } else {
+                       if (pDevice->bBarkerPreambleMd) {
+                               MACvDisableBarkerPreambleMd(pDevice->PortOffset);
+                               pDevice->bBarkerPreambleMd = false;
+                       }
+               }
 
+       }
+
+       // Check if any STA in PS mode, enable DTIM multicast deliver
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               if (uSleepySTACnt > 0)
+                       pMgmt->sNodeDBTable[0].bPSEnable = true;
+               else
+                       pMgmt->sNodeDBTable[0].bPSEnable = false;
+       }
+
+       pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
+       pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
+
+       if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
+           (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
+               if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
+                       if (pDevice->bUpdateBBVGA) {
+                               // s_vCheckSensitivity((void *) pDevice);
+                               s_vCheckPreEDThreshold((void *)pDevice);
+                       }
+
+                       if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
+                           (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0])) {
+                               pDevice->byBBVGANew = pDevice->abyBBVGA[0];
+                               bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
+                       }
+
+                       if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
+                               pMgmt->sNodeDBTable[0].bActive = false;
+                               pMgmt->eCurrMode = WMAC_MODE_STANDBY;
+                               pMgmt->eCurrState = WMAC_STATE_IDLE;
+                               netif_stop_queue(pDevice->dev);
+                               pDevice->bLinkPass = false;
+                               pDevice->bRoaming = true;
+                               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
+                               if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
+                                       wpahdr = (viawget_wpa_header *)pDevice->skb->data;
+                                       wpahdr->type = VIAWGET_DISASSOC_MSG;
+                                       wpahdr->resp_ie_len = 0;
+                                       wpahdr->req_ie_len = 0;
+                                       skb_put(pDevice->skb, sizeof(viawget_wpa_header));
+                                       pDevice->skb->dev = pDevice->wpadev;
+                                       skb_reset_mac_header(pDevice->skb);
+                                       pDevice->skb->pkt_type = PACKET_HOST;
+                                       pDevice->skb->protocol = htons(ETH_P_802_2);
+                                       memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
+                                       netif_rx(pDevice->skb);
+                                       pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
+                               }
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+                               {
+                                       union iwreq_data  wrqu;
+                                       memset(&wrqu, 0, sizeof(wrqu));
+                                       wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+                                       PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
+                                       wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
+                               }
+#endif
+                       }
+               } else if (pItemSSID->len != 0) {
+                       if (pDevice->uAutoReConnectTime < 10) {
+                               pDevice->uAutoReConnectTime++;
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+                               //network manager support need not do Roaming scan???
+                               if (pDevice->bWPASuppWextEnabled == true)
+                                       pDevice->uAutoReConnectTime = 0;
+#endif
+                       } else {
+                               //mike use old encryption status for wpa reauthen
+                               if (pDevice->bWPADEVUp)
+                                       pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
+
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
+                               BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
+                               pMgmt->eScanType = WMAC_SCAN_ACTIVE;
+                               bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
+                               bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
+                               pDevice->uAutoReConnectTime = 0;
+                       }
+               }
+       }
+
+       if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+               // if adhoc started which essid is NULL string, rescanning.
+               if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
+                       if (pDevice->uAutoReConnectTime < 10) {
+                               pDevice->uAutoReConnectTime++;
+                       } else {
+                               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scanning ...\n");
+                               pMgmt->eScanType = WMAC_SCAN_ACTIVE;
+                               bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
+                               bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
+                               pDevice->uAutoReConnectTime = 0;
+                       };
+               }
+               if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
+                       if (pDevice->bUpdateBBVGA) {
+                               //s_vCheckSensitivity((void *) pDevice);
+                               s_vCheckPreEDThreshold((void *)pDevice);
+                       }
+                       if (pMgmt->sNodeDBTable[0].uInActiveCount >= ADHOC_LOST_BEACON_COUNT) {
+                               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
+                               pMgmt->sNodeDBTable[0].uInActiveCount = 0;
+                               pMgmt->eCurrState = WMAC_STATE_STARTED;
+                               netif_stop_queue(pDevice->dev);
+                               pDevice->bLinkPass = false;
+                       }
+               }
+       }
 
+       spin_unlock_irq(&pDevice->lock);
 
+       pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
+       add_timer(&pMgmt->sTimerSecondCallback);
+       return;
+}
 
 /*+
  *
@@ -1375,184 +1294,162 @@ start:
  * Return Value:
  *    none.
  *
--*/
-
-
+ -*/
 
 void
 BSSvUpdateNodeTxCounter(
-    void *hDeviceContext,
-    unsigned char byTsr0,
-    unsigned char byTsr1,
-    unsigned char *pbyBuffer,
-    unsigned int uFIFOHeaderSize
-    )
+       void *hDeviceContext,
+       unsigned char byTsr0,
+       unsigned char byTsr1,
+       unsigned char *pbyBuffer,
+       unsigned int uFIFOHeaderSize
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned int uNodeIndex = 0;
-    unsigned char byTxRetry = (byTsr0 & TSR0_NCR);
-    PSTxBufHead     pTxBufHead;
-    PS802_11Header  pMACHeader;
-    unsigned short wRate;
-    unsigned short wFallBackRate = RATE_1M;
-    unsigned char byFallBack;
-    unsigned int ii;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned int uNodeIndex = 0;
+       unsigned char byTxRetry = (byTsr0 & TSR0_NCR);
+       PSTxBufHead     pTxBufHead;
+       PS802_11Header  pMACHeader;
+       unsigned short wRate;
+       unsigned short wFallBackRate = RATE_1M;
+       unsigned char byFallBack;
+       unsigned int ii;
 //     unsigned int txRetryTemp;
 //PLICE_DEBUG->
        //txRetryTemp = byTxRetry;
-       //if (txRetryTemp== 8)
-       //txRetryTemp -=3;
 //PLICE_DEBUG <-
-    pTxBufHead = (PSTxBufHead) pbyBuffer;
-    if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
-        byFallBack = AUTO_FB_0;
-    } else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
-        byFallBack = AUTO_FB_1;
-    } else {
-        byFallBack = AUTO_FB_NONE;
-    }
-    wRate = pTxBufHead->wReserved; //?wRate
-    //printk("BSSvUpdateNodeTxCounter:byTxRetry is %d\n",byTxRetry);
-
-//printk("BSSvUpdateNodeTx:wRate is %d,byFallback is %d\n",wRate,byFallBack);
-//#ifdef       PLICE_DEBUG
-       //printk("BSSvUpdateNodeTx: wRate is %d\n",wRate);
-////#endif
-    // Only Unicast using support rates
-    if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate, byTsr0, byTsr1);
-        if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
-            pMgmt->sNodeDBTable[0].uTxAttempts += 1;
-            if ((byTsr1 & TSR1_TERR) == 0) {
-                // transmit success, TxAttempts at least plus one
-                pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
-                if ( (byFallBack == AUTO_FB_NONE) ||
-                     (wRate < RATE_18M) ) {
-                    wFallBackRate = wRate;
-                } else if (byFallBack == AUTO_FB_0) {
+       pTxBufHead = (PSTxBufHead) pbyBuffer;
+       if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
+               byFallBack = AUTO_FB_0;
+       } else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
+               byFallBack = AUTO_FB_1;
+       } else {
+               byFallBack = AUTO_FB_NONE;
+       }
+       wRate = pTxBufHead->wReserved; //?wRate
+
+       // Only Unicast using support rates
+       if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate, byTsr0, byTsr1);
+               if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
+                       pMgmt->sNodeDBTable[0].uTxAttempts += 1;
+                       if ((byTsr1 & TSR1_TERR) == 0) {
+                               // transmit success, TxAttempts at least plus one
+                               pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
+                               if ((byFallBack == AUTO_FB_NONE) ||
+                                   (wRate < RATE_18M)) {
+                                       wFallBackRate = wRate;
+                               } else if (byFallBack == AUTO_FB_0) {
 //PLICE_DEBUG
-                                 if (byTxRetry < 5)
-                               //if (txRetryTemp < 5)
-                                       wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
-                       //wFallBackRate = awHWRetry0[wRate-RATE_12M][byTxRetry];
-                       //wFallBackRate = awHWRetry0[wRate-RATE_18M][txRetryTemp] +1;
-               else
-                        wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
-                       //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
-               } else if (byFallBack == AUTO_FB_1) {
-                    if (byTxRetry < 5)
-                        wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
-                    else
-                        wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
-                }
-                pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
-            } else {
-                pMgmt->sNodeDBTable[0].uTxFailures ++;
-            }
-            pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
-            if (byTxRetry != 0) {
-                pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE]+=byTxRetry;
-                if ( (byFallBack == AUTO_FB_NONE) ||
-                     (wRate < RATE_18M) ) {
-                    pMgmt->sNodeDBTable[0].uTxFail[wRate]+=byTxRetry;
-                } else if (byFallBack == AUTO_FB_0) {
+                                       if (byTxRetry < 5)
+                                               wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
+                                       //wFallBackRate = awHWRetry0[wRate-RATE_12M][byTxRetry];
+                                       //wFallBackRate = awHWRetry0[wRate-RATE_18M][txRetryTemp] +1;
+                                       else
+                                               wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
+                                       //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
+                               } else if (byFallBack == AUTO_FB_1) {
+                                       if (byTxRetry < 5)
+                                               wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
+                                       else
+                                               wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
+                               }
+                               pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
+                       } else {
+                               pMgmt->sNodeDBTable[0].uTxFailures++;
+                       }
+                       pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
+                       if (byTxRetry != 0) {
+                               pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE] += byTxRetry;
+                               if ((byFallBack == AUTO_FB_NONE) ||
+                                   (wRate < RATE_18M)) {
+                                       pMgmt->sNodeDBTable[0].uTxFail[wRate] += byTxRetry;
+                               } else if (byFallBack == AUTO_FB_0) {
 //PLICE_DEBUG
-                                  for(ii=0;ii<byTxRetry;ii++)
-               //for (ii=0;ii<txRetryTemp;ii++)
-               {
-                        if (ii < 5)
-                               {
-
+                                       for (ii = 0; ii < byTxRetry; ii++)
+                                               //for (ii=0;ii<txRetryTemp;ii++)
+                                       {
+                                               if (ii < 5) {
 //PLICE_DEBUG
-                                               wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
-                                       //printk(" II is %d:BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
-                               //wFallBackRate = awHWRetry0[wRate-RATE_12M][ii];
-                               }
-                       else
-                               {
-                       wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
-                       //printk("ii is %d BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
-                               //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
-                               }
+                                                       wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
+                                                       //wFallBackRate = awHWRetry0[wRate-RATE_12M][ii];
+                                               } else {
+                                                       wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
+                                                       //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
+                                               }
                                                pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
-                    }
-                } else if (byFallBack == AUTO_FB_1) {
-                    for(ii=0;ii<byTxRetry;ii++) {
-                        if (ii < 5)
-                            wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
-                        else
-                            wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
-                        pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
-                    }
-                }
-            }
-        }
-
-        if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
-            (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
-
-            pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
-
-            if (BSSDBbIsSTAInNodeDB((void *)pMgmt, &(pMACHeader->abyAddr1[0]), &uNodeIndex)){
-                pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
-                if ((byTsr1 & TSR1_TERR) == 0) {
-                    // transmit success, TxAttempts at least plus one
-                    pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
-                    if ( (byFallBack == AUTO_FB_NONE) ||
-                         (wRate < RATE_18M) ) {
-                        wFallBackRate = wRate;
-                    } else if (byFallBack == AUTO_FB_0) {
-                        if (byTxRetry < 5)
-                            wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
-                        else
-                            wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
-                    } else if (byFallBack == AUTO_FB_1) {
-                        if (byTxRetry < 5)
-                            wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
-                        else
-                            wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
-                    }
-                    pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
-                } else {
-                    pMgmt->sNodeDBTable[uNodeIndex].uTxFailures ++;
-                }
-                pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
-                if (byTxRetry != 0) {
-                    pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE]+=byTxRetry;
-                    if ( (byFallBack == AUTO_FB_NONE) ||
-                         (wRate < RATE_18M) ) {
-                        pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate]+=byTxRetry;
-                    } else if (byFallBack == AUTO_FB_0) {
-                        for(ii=0;ii<byTxRetry;ii++) {
-                            if (ii < 5)
-                                wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
-                            else
-                                wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
-                            pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
-                        }
-                    } else if (byFallBack == AUTO_FB_1) {
-                        for(ii=0;ii<byTxRetry;ii++) {
-                            if (ii < 5)
-                                wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
-                            else
-                                wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
-                            pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    return;
+                                       }
+                               } else if (byFallBack == AUTO_FB_1) {
+                                       for (ii = 0; ii < byTxRetry; ii++) {
+                                               if (ii < 5)
+                                                       wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
+                                               else
+                                                       wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
+                                               pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
+                                       }
+                               }
+                       }
+               }
 
+               if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
+                   (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
+                       pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
+
+                       if (BSSDBbIsSTAInNodeDB((void *)pMgmt,  &(pMACHeader->abyAddr1[0]), &uNodeIndex)) {
+                               pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
+                               if ((byTsr1 & TSR1_TERR) == 0) {
+                                       // transmit success, TxAttempts at least plus one
+                                       pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
+                                       if ((byFallBack == AUTO_FB_NONE) ||
+                                           (wRate < RATE_18M)) {
+                                               wFallBackRate = wRate;
+                                       } else if (byFallBack == AUTO_FB_0) {
+                                               if (byTxRetry < 5)
+                                                       wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
+                                               else
+                                                       wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
+                                       } else if (byFallBack == AUTO_FB_1) {
+                                               if (byTxRetry < 5)
+                                                       wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
+                                               else
+                                                       wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
+                                       }
+                                       pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
+                               } else {
+                                       pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
+                               }
+                               pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
+                               if (byTxRetry != 0) {
+                                       pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE] += byTxRetry;
+                                       if ((byFallBack == AUTO_FB_NONE) ||
+                                           (wRate < RATE_18M)) {
+                                               pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate] += byTxRetry;
+                                       } else if (byFallBack == AUTO_FB_0) {
+                                               for (ii = 0; ii < byTxRetry; ii++) {
+                                                       if (ii < 5)
+                                                               wFallBackRate = awHWRetry0[wRate - RATE_18M][ii];
+                                                       else
+                                                               wFallBackRate = awHWRetry0[wRate - RATE_18M][4];
+                                                       pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
+                                               }
+                                       } else if (byFallBack == AUTO_FB_1) {
+                                               for (ii = 0; ii < byTxRetry; ii++) {
+                                                       if (ii < 5)
+                                                               wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
+                                                       else
+                                                               wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
+                                                       pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
 
+       return;
 }
 
-
-
-
 /*+
  *
  * Routine Description:
@@ -1569,167 +1466,157 @@ BSSvUpdateNodeTxCounter(
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 void
 BSSvClearNodeDBTable(
-    void *hDeviceContext,
-    unsigned int uStartIndex
-    )
+       void *hDeviceContext,
+       unsigned int uStartIndex
+)
 
 {
-    PSDevice     pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    struct sk_buff  *skb;
-    unsigned int ii;
-
-    for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
-        if (pMgmt->sNodeDBTable[ii].bActive) {
-            // check if sTxPSQueue has been initial
-            if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
-                while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL){
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
-                        dev_kfree_skb(skb);
-                }
-            }
-            memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
-        }
-    }
-
-    return;
-};
+       PSDevice     pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       struct sk_buff  *skb;
+       unsigned int ii;
+
+       for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
+               if (pMgmt->sNodeDBTable[ii].bActive) {
+                       // check if sTxPSQueue has been initial
+                       if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
+                               while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
+                                       dev_kfree_skb(skb);
+                               }
+                       }
+                       memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
+               }
+       }
 
+       return;
+};
 
 void s_vCheckSensitivity(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    PKnownBSS       pBSSList = NULL;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    int             ii;
-
-    if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
-        (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
-        return;
-    }
-
-    if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
-        ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
-        pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
-        if (pBSSList != NULL) {
-            // Updata BB Reg if RSSI is too strong.
-            long    LocalldBmAverage = 0;
-            long    uNumofdBm = 0;
-            for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
-                if (pBSSList->ldBmAverage[ii] != 0) {
-                    uNumofdBm ++;
-                    LocalldBmAverage += pBSSList->ldBmAverage[ii];
-                }
-            }
-            if (uNumofdBm > 0) {
-                LocalldBmAverage = LocalldBmAverage/uNumofdBm;
-                for (ii=0;ii<BB_VGA_LEVEL;ii++) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
-                    if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
-                           pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
-                        break;
-                    }
-                }
-                if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
-                    pDevice->uBBVGADiffCount++;
-                    if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
-                        bScheduleCommand((void *) pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
-                } else {
-                    pDevice->uBBVGADiffCount = 0;
-                }
-            }
-        }
-    }
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PKnownBSS       pBSSList = NULL;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       int             ii;
+
+       if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
+           (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
+               return;
+       }
+
+       if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
+           ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
+               pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
+               if (pBSSList != NULL) {
+                       // Updata BB Reg if RSSI is too strong.
+                       long    LocalldBmAverage = 0;
+                       long    uNumofdBm = 0;
+                       for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
+                               if (pBSSList->ldBmAverage[ii] != 0) {
+                                       uNumofdBm++;
+                                       LocalldBmAverage += pBSSList->ldBmAverage[ii];
+                               }
+                       }
+                       if (uNumofdBm > 0) {
+                               LocalldBmAverage = LocalldBmAverage/uNumofdBm;
+                               for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
+                                       if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
+                                               pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
+                                               break;
+                                       }
+                               }
+                               if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
+                                       pDevice->uBBVGADiffCount++;
+                                       if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
+                                               bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
+                               } else {
+                                       pDevice->uBBVGADiffCount = 0;
+                               }
+                       }
+               }
+       }
 }
 
-
 void
-BSSvClearAnyBSSJoinRecord (
-    void *hDeviceContext
-    )
+BSSvClearAnyBSSJoinRecord(
+       void *hDeviceContext
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned int ii;
-
-    for (ii = 0; ii < MAX_BSS_NUM; ii++) {
-        pMgmt->sBSSList[ii].bSelected = false;
-    }
-    return;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned int ii;
+
+       for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+               pMgmt->sBSSList[ii].bSelected = false;
+       }
+       return;
 }
 
 #ifdef Calcu_LinkQual
 void s_uCalculateLinkQual(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-   PSDevice        pDevice = (PSDevice)hDeviceContext;
-   unsigned long TxOkRatio, TxCnt;
-   unsigned long RxOkRatio,RxCnt;
-   unsigned long RssiRatio;
-   long ldBm;
-
-TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
-             pDevice->scStatistic.TxRetryOkCount +
-             pDevice->scStatistic.TxFailCount;
-RxCnt = pDevice->scStatistic.RxFcsErrCnt +
-             pDevice->scStatistic.RxOkCnt;
-TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
-RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       unsigned long TxOkRatio, TxCnt;
+       unsigned long RxOkRatio, RxCnt;
+       unsigned long RssiRatio;
+       long ldBm;
+
+       TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
+               pDevice->scStatistic.TxRetryOkCount +
+               pDevice->scStatistic.TxFailCount;
+       RxCnt = pDevice->scStatistic.RxFcsErrCnt +
+               pDevice->scStatistic.RxOkCnt;
+       TxOkRatio = (TxCnt < 6) ? 4000 : ((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
+       RxOkRatio = (RxCnt < 6) ? 2000 : ((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
 //decide link quality
-if(pDevice->bLinkPass !=true)
-{
- //  printk("s_uCalculateLinkQual-->Link disconnect and Poor quality**\n");
-   pDevice->scStatistic.LinkQuality = 0;
-   pDevice->scStatistic.SignalStren = 0;
-}
-else
-{
-   RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
-   if(-ldBm < 50)  {
-       RssiRatio = 4000;
-     }
-   else if(-ldBm > 90) {
-       RssiRatio = 0;
-     }
-   else {
-       RssiRatio = (40-(-ldBm-50))*4000/40;
-     }
-   pDevice->scStatistic.SignalStren = RssiRatio/40;
-   pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
-}
-   pDevice->scStatistic.RxFcsErrCnt = 0;
-   pDevice->scStatistic.RxOkCnt = 0;
-   pDevice->scStatistic.TxFailCount = 0;
-   pDevice->scStatistic.TxNoRetryOkCount = 0;
-   pDevice->scStatistic.TxRetryOkCount = 0;
-   return;
+       if (pDevice->bLinkPass != true) {
+               pDevice->scStatistic.LinkQuality = 0;
+               pDevice->scStatistic.SignalStren = 0;
+       } else {
+               RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
+               if (-ldBm < 50)  {
+                       RssiRatio = 4000;
+               } else if (-ldBm > 90) {
+                       RssiRatio = 0;
+               } else {
+                       RssiRatio = (40-(-ldBm-50))*4000/40;
+               }
+               pDevice->scStatistic.SignalStren = RssiRatio/40;
+               pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
+       }
+       pDevice->scStatistic.RxFcsErrCnt = 0;
+       pDevice->scStatistic.RxOkCnt = 0;
+       pDevice->scStatistic.TxFailCount = 0;
+       pDevice->scStatistic.TxNoRetryOkCount = 0;
+       pDevice->scStatistic.TxRetryOkCount = 0;
+       return;
 }
 #endif
 
 void s_vCheckPreEDThreshold(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    PKnownBSS       pBSSList = NULL;
-    PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
-
-    if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
-        ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
-        pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
-        if (pBSSList != NULL) {
-            pDevice->byBBPreEDRSSI = (unsigned char) (~(pBSSList->ldBmAverRange) + 1);
-            //BBvUpdatePreEDThreshold(pDevice, false);
-        }
-    }
-    return;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PKnownBSS       pBSSList = NULL;
+       PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
+
+       if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
+           ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
+               pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
+               if (pBSSList != NULL) {
+                       pDevice->byBBPreEDRSSI = (unsigned char) (~(pBSSList->ldBmAverRange) + 1);
+                       //BBvUpdatePreEDThreshold(pDevice, false);
+               }
+       }
+       return;
 }
-
index 0af42118612218aabe7c7c1794da88e97a3bd32c..5c77677251ed8137b86ae9135068d72ba4baa5c9 100644 (file)
@@ -39,7 +39,7 @@
 
 #define MAX_NODE_NUM             64
 #define MAX_BSS_NUM              42
-#define LOST_BEACON_COUNT               10   // 10 sec, XP defined
+#define LOST_BEACON_COUNT        10   // 10 sec, XP defined
 #define MAX_PS_TX_BUF            32   // sta max power saving tx buf
 #define ADHOC_LOST_BEACON_COUNT  30   // 30 sec, beacon lost for adhoc only
 #define MAX_INACTIVE_COUNT       300  // 300 sec, inactive STA node refresh
 
 #define MAX_WPA_IE_LEN      64
 
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Types  ------------------------------*/
 
 //
 
 typedef enum _NDIS_802_11_NETWORK_TYPE
 {
-    Ndis802_11FH,
-    Ndis802_11DS,
-    Ndis802_11OFDM5,
-    Ndis802_11OFDM24,
-    Ndis802_11NetworkTypeMax    // not a real type, defined as an upper bound
+       Ndis802_11FH,
+       Ndis802_11DS,
+       Ndis802_11OFDM5,
+       Ndis802_11OFDM24,
+       Ndis802_11NetworkTypeMax    // not a real type, defined as an upper bound
 } NDIS_802_11_NETWORK_TYPE, *PNDIS_802_11_NETWORK_TYPE;
 
-
 typedef struct tagSERPObject {
-    bool bERPExist;
-    unsigned char byERP;
-}ERPObject, *PERPObject;
-
+       bool bERPExist;
+       unsigned char byERP;
+} ERPObject, *PERPObject;
 
 typedef struct tagSRSNCapObject {
-    bool bRSNCapExist;
-    unsigned short wRSNCap;
-}SRSNCapObject, *PSRSNCapObject;
+       bool bRSNCapExist;
+       unsigned short wRSNCap;
+} SRSNCapObject, *PSRSNCapObject;
 
 // BSS info(AP)
 #pragma pack(1)
 typedef struct tagKnownBSS {
-    // BSS info
-    bool bActive;
-    unsigned char abyBSSID[WLAN_BSSID_LEN];
-    unsigned int       uChannel;
-    unsigned char abySuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
-    unsigned char abyExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
-    unsigned int       uRSSI;
-    unsigned char bySQ;
-    unsigned short wBeaconInterval;
-    unsigned short wCapInfo;
-    unsigned char abySSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
-    unsigned char byRxRate;
+       // BSS info
+       bool bActive;
+       unsigned char abyBSSID[WLAN_BSSID_LEN];
+       unsigned int    uChannel;
+       unsigned char abySuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
+       unsigned char abyExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
+       unsigned int    uRSSI;
+       unsigned char bySQ;
+       unsigned short wBeaconInterval;
+       unsigned short wCapInfo;
+       unsigned char abySSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
+       unsigned char byRxRate;
 
 //    unsigned short wATIMWindow;
-    unsigned char byRSSIStatCnt;
-    long            ldBmMAX;
-    long            ldBmAverage[RSSI_STAT_COUNT];
-    long            ldBmAverRange;
-    //For any BSSID selection improvment
-    bool bSelected;
-
-    //++ WPA informations
-    bool bWPAValid;
-    unsigned char byGKType;
-    unsigned char abyPKType[4];
-    unsigned short wPKCount;
-    unsigned char abyAuthType[4];
-    unsigned short wAuthCount;
-    unsigned char byDefaultK_as_PK;
-    unsigned char byReplayIdx;
-    //--
-
-    //++ WPA2 informations
-    bool bWPA2Valid;
-    unsigned char byCSSGK;
-    unsigned short wCSSPKCount;
-    unsigned char abyCSSPK[4];
-    unsigned short wAKMSSAuthCount;
-    unsigned char abyAKMSSAuthType[4];
-
-    //++  wpactl
-    unsigned char byWPAIE[MAX_WPA_IE_LEN];
-    unsigned char byRSNIE[MAX_WPA_IE_LEN];
-    unsigned short wWPALen;
-    unsigned short wRSNLen;
-
-    // Clear count
-    unsigned int       uClearCount;
+       unsigned char byRSSIStatCnt;
+       long            ldBmMAX;
+       long            ldBmAverage[RSSI_STAT_COUNT];
+       long            ldBmAverRange;
+       //For any BSSID selection improvment
+       bool bSelected;
+
+       //++ WPA informations
+       bool bWPAValid;
+       unsigned char byGKType;
+       unsigned char abyPKType[4];
+       unsigned short wPKCount;
+       unsigned char abyAuthType[4];
+       unsigned short wAuthCount;
+       unsigned char byDefaultK_as_PK;
+       unsigned char byReplayIdx;
+       //--
+
+       //++ WPA2 informations
+       bool bWPA2Valid;
+       unsigned char byCSSGK;
+       unsigned short wCSSPKCount;
+       unsigned char abyCSSPK[4];
+       unsigned short wAKMSSAuthCount;
+       unsigned char abyAKMSSAuthType[4];
+
+       //++  wpactl
+       unsigned char byWPAIE[MAX_WPA_IE_LEN];
+       unsigned char byRSNIE[MAX_WPA_IE_LEN];
+       unsigned short wWPALen;
+       unsigned short wRSNLen;
+
+       // Clear count
+       unsigned int    uClearCount;
 //    unsigned char abyIEs[WLAN_BEACON_FR_MAXLEN];
-    unsigned int       uIELength;
-    QWORD           qwBSSTimestamp;
-    QWORD           qwLocalTSF;     // local TSF timer
+       unsigned int    uIELength;
+       QWORD           qwBSSTimestamp;
+       QWORD           qwLocalTSF;     // local TSF timer
 
 //    NDIS_802_11_NETWORK_TYPE    NetworkTypeInUse;
-    CARD_PHY_TYPE   eNetworkTypeInUse;
+       CARD_PHY_TYPE   eNetworkTypeInUse;
 
-    ERPObject       sERP;
-    SRSNCapObject   sRSNCapObj;
-    unsigned char abyIEs[1024];   // don't move this field !!
-
-}__attribute__ ((__packed__))
+       ERPObject       sERP;
+       SRSNCapObject   sRSNCapObj;
+       unsigned char abyIEs[1024];   // don't move this field !!
+} __attribute__ ((__packed__))
 KnownBSS , *PKnownBSS;
 
 //2006-1116-01,<Add> by NomadZhao
 #pragma pack()
 
 typedef enum tagNODE_STATE {
-    NODE_FREE,
-    NODE_AGED,
-    NODE_KNOWN,
-    NODE_AUTH,
-    NODE_ASSOC
+       NODE_FREE,
+       NODE_AGED,
+       NODE_KNOWN,
+       NODE_AUTH,
+       NODE_ASSOC
 } NODE_STATE, *PNODE_STATE;
 
-
 // STA node info
 typedef struct tagKnownNodeDB {
-    // STA info
-    bool bActive;
-    unsigned char abyMACAddr[WLAN_ADDR_LEN];
-    unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
-    unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
-    unsigned short wTxDataRate;
-    bool bShortPreamble;
-    bool bERPExist;
-    bool bShortSlotTime;
-    unsigned int       uInActiveCount;
-    unsigned short wMaxBasicRate;     //Get from byTopOFDMBasicRate or byTopCCKBasicRate which depends on packetTyp.
-    unsigned short wMaxSuppRate;      //Records the highest supported rate getting from SuppRates IE and ExtSuppRates IE in Beacon.
-    unsigned short wSuppRate;
-    unsigned char byTopOFDMBasicRate;//Records the highest basic rate in OFDM mode
-    unsigned char byTopCCKBasicRate; //Records the highest basic rate in CCK mode
-
-    // For AP mode
-    struct sk_buff_head sTxPSQueue;
-    unsigned short wCapInfo;
-    unsigned short wListenInterval;
-    unsigned short wAID;
-    NODE_STATE      eNodeState;
-    bool bPSEnable;
-    bool bRxPSPoll;
-    unsigned char byAuthSequence;
-    unsigned long ulLastRxJiffer;
-    unsigned char bySuppRate;
-    unsigned long dwFlags;
-    unsigned short wEnQueueCnt;
-
-    bool bOnFly;
-    unsigned long long       KeyRSC;
-    unsigned char byKeyIndex;
-    unsigned long dwKeyIndex;
-    unsigned char byCipherSuite;
-    unsigned long dwTSC47_16;
-    unsigned short wTSC15_0;
-    unsigned int       uWepKeyLength;
-    unsigned char abyWepKey[WLAN_WEPMAX_KEYLEN];
-    //
-    // Auto rate fallback vars
-    bool bIsInFallback;
-    unsigned int       uAverageRSSI;
-    unsigned int       uRateRecoveryTimeout;
-    unsigned int       uRatePollTimeout;
-    unsigned int       uTxFailures;
-    unsigned int       uTxAttempts;
-
-    unsigned int       uTxRetry;
-    unsigned int       uFailureRatio;
-    unsigned int       uRetryRatio;
-    unsigned int       uTxOk[MAX_RATE+1];
-    unsigned int       uTxFail[MAX_RATE+1];
-    unsigned int       uTimeCount;
-
+       // STA info
+       bool bActive;
+       unsigned char abyMACAddr[WLAN_ADDR_LEN];
+       unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
+       unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
+       unsigned short wTxDataRate;
+       bool bShortPreamble;
+       bool bERPExist;
+       bool bShortSlotTime;
+       unsigned int    uInActiveCount;
+       unsigned short wMaxBasicRate;     //Get from byTopOFDMBasicRate or byTopCCKBasicRate which depends on packetTyp.
+       unsigned short wMaxSuppRate;      //Records the highest supported rate getting from SuppRates IE and ExtSuppRates IE in Beacon.
+       unsigned short wSuppRate;
+       unsigned char byTopOFDMBasicRate;//Records the highest basic rate in OFDM mode
+       unsigned char byTopCCKBasicRate; //Records the highest basic rate in CCK mode
+
+       // For AP mode
+       struct sk_buff_head sTxPSQueue;
+       unsigned short wCapInfo;
+       unsigned short wListenInterval;
+       unsigned short wAID;
+       NODE_STATE      eNodeState;
+       bool bPSEnable;
+       bool bRxPSPoll;
+       unsigned char byAuthSequence;
+       unsigned long ulLastRxJiffer;
+       unsigned char bySuppRate;
+       unsigned long dwFlags;
+       unsigned short wEnQueueCnt;
+
+       bool bOnFly;
+       unsigned long long       KeyRSC;
+       unsigned char byKeyIndex;
+       unsigned long dwKeyIndex;
+       unsigned char byCipherSuite;
+       unsigned long dwTSC47_16;
+       unsigned short wTSC15_0;
+       unsigned int    uWepKeyLength;
+       unsigned char abyWepKey[WLAN_WEPMAX_KEYLEN];
+       //
+       // Auto rate fallback vars
+       bool bIsInFallback;
+       unsigned int    uAverageRSSI;
+       unsigned int    uRateRecoveryTimeout;
+       unsigned int    uRatePollTimeout;
+       unsigned int    uTxFailures;
+       unsigned int    uTxAttempts;
+
+       unsigned int    uTxRetry;
+       unsigned int    uFailureRatio;
+       unsigned int    uRetryRatio;
+       unsigned int    uTxOk[MAX_RATE+1];
+       unsigned int    uTxFail[MAX_RATE+1];
+       unsigned int    uTimeCount;
 } KnownNodeDB, *PKnownNodeDB;
 
-
 /*---------------------  Export Functions  --------------------------*/
 
-
-
 PKnownBSS
 BSSpSearchBSSList(
-    void *hDeviceContext,
-    unsigned char *pbyDesireBSSID,
-    unsigned char *pbyDesireSSID,
-    CARD_PHY_TYPE ePhyType
-    );
+       void *hDeviceContext,
+       unsigned char *pbyDesireBSSID,
+       unsigned char *pbyDesireSSID,
+       CARD_PHY_TYPE ePhyType
+);
 
 PKnownBSS
 BSSpAddrIsInBSSList(
-    void *hDeviceContext,
-    unsigned char *abyBSSID,
-    PWLAN_IE_SSID pSSID
-    );
+       void *hDeviceContext,
+       unsigned char *abyBSSID,
+       PWLAN_IE_SSID pSSID
+);
 
 void
 BSSvClearBSSList(
-    void *hDeviceContext,
-    bool bKeepCurrBSSID
-    );
+       void *hDeviceContext,
+       bool bKeepCurrBSSID
+);
 
 bool
 BSSbInsertToBSSList(
-    void *hDeviceContext,
-    unsigned char *abyBSSIDAddr,
-    QWORD qwTimestamp,
-    unsigned short wBeaconInterval,
-    unsigned short wCapInfo,
-    unsigned char byCurrChannel,
-    PWLAN_IE_SSID pSSID,
-    PWLAN_IE_SUPP_RATES pSuppRates,
-    PWLAN_IE_SUPP_RATES pExtSuppRates,
-    PERPObject psERP,
-    PWLAN_IE_RSN pRSN,
-    PWLAN_IE_RSN_EXT pRSNWPA,
-    PWLAN_IE_COUNTRY pIE_Country,
-    PWLAN_IE_QUIET pIE_Quiet,
-    unsigned int uIELength,
-    unsigned char *pbyIEs,
-    void *pRxPacketContext
-    );
-
+       void *hDeviceContext,
+       unsigned char *abyBSSIDAddr,
+       QWORD qwTimestamp,
+       unsigned short wBeaconInterval,
+       unsigned short wCapInfo,
+       unsigned char byCurrChannel,
+       PWLAN_IE_SSID pSSID,
+       PWLAN_IE_SUPP_RATES pSuppRates,
+       PWLAN_IE_SUPP_RATES pExtSuppRates,
+       PERPObject psERP,
+       PWLAN_IE_RSN pRSN,
+       PWLAN_IE_RSN_EXT pRSNWPA,
+       PWLAN_IE_COUNTRY pIE_Country,
+       PWLAN_IE_QUIET pIE_Quiet,
+       unsigned int uIELength,
+       unsigned char *pbyIEs,
+       void *pRxPacketContext
+);
 
 bool
 BSSbUpdateToBSSList(
-    void *hDeviceContext,
-    QWORD qwTimestamp,
-    unsigned short wBeaconInterval,
-    unsigned short wCapInfo,
-    unsigned char byCurrChannel,
-    bool bChannelHit,
-    PWLAN_IE_SSID pSSID,
-    PWLAN_IE_SUPP_RATES pSuppRates,
-    PWLAN_IE_SUPP_RATES pExtSuppRates,
-    PERPObject psERP,
-    PWLAN_IE_RSN pRSN,
-    PWLAN_IE_RSN_EXT pRSNWPA,
-    PWLAN_IE_COUNTRY pIE_Country,
-    PWLAN_IE_QUIET pIE_Quiet,
-    PKnownBSS pBSSList,
-    unsigned int uIELength,
-    unsigned char *pbyIEs,
-    void *pRxPacketContext
-    );
-
+       void *hDeviceContext,
+       QWORD qwTimestamp,
+       unsigned short wBeaconInterval,
+       unsigned short wCapInfo,
+       unsigned char byCurrChannel,
+       bool bChannelHit,
+       PWLAN_IE_SSID pSSID,
+       PWLAN_IE_SUPP_RATES pSuppRates,
+       PWLAN_IE_SUPP_RATES pExtSuppRates,
+       PERPObject psERP,
+       PWLAN_IE_RSN pRSN,
+       PWLAN_IE_RSN_EXT pRSNWPA,
+       PWLAN_IE_COUNTRY pIE_Country,
+       PWLAN_IE_QUIET pIE_Quiet,
+       PKnownBSS pBSSList,
+       unsigned int uIELength,
+       unsigned char *pbyIEs,
+       void *pRxPacketContext
+);
 
 bool
 BSSDBbIsSTAInNodeDB(void *hDeviceContext, unsigned char *abyDstAddr,
-               unsigned int *puNodeIndex);
+                   unsigned int *puNodeIndex);
 
 void
 BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex);
 
 void
 BSSvUpdateAPNode(
-    void *hDeviceContext,
-    unsigned short *pwCapInfo,
-    PWLAN_IE_SUPP_RATES pItemRates,
-    PWLAN_IE_SUPP_RATES pExtSuppRates
-    );
-
+       void *hDeviceContext,
+       unsigned short *pwCapInfo,
+       PWLAN_IE_SUPP_RATES pItemRates,
+       PWLAN_IE_SUPP_RATES pExtSuppRates
+);
 
 void
 BSSvSecondCallBack(
-    void *hDeviceContext
-    );
-
+       void *hDeviceContext
+);
 
 void
 BSSvUpdateNodeTxCounter(
-    void *hDeviceContext,
-    unsigned char byTsr0,
-    unsigned char byTsr1,
-    unsigned char *pbyBuffer,
-    unsigned int uFIFOHeaderSize
-    );
+       void *hDeviceContext,
+       unsigned char byTsr0,
+       unsigned char byTsr1,
+       unsigned char *pbyBuffer,
+       unsigned int uFIFOHeaderSize
+);
 
 void
 BSSvRemoveOneNode(
-    void *hDeviceContext,
-    unsigned int uNodeIndex
-    );
+       void *hDeviceContext,
+       unsigned int uNodeIndex
+);
 
 void
 BSSvAddMulticastNode(
-    void *hDeviceContext
-    );
-
+       void *hDeviceContext
+);
 
 void
 BSSvClearNodeDBTable(
-    void *hDeviceContext,
-    unsigned int uStartIndex
-    );
+       void *hDeviceContext,
+       unsigned int uStartIndex
+);
 
 void
 BSSvClearAnyBSSJoinRecord(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 #endif //__BSSDB_H__
index 319ca482f003f0b4642a210167e870f9187b6490..fbf18e23e78ecb3230cbf45787f3bf91bcc6610b 100644 (file)
 /*---------------------  Static Definitions -------------------------*/
 
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 
 #define C_SIFS_A        16      // micro sec.
 #define C_SIFS_BG       10
 
 #define C_EIFS          80      // micro sec.
 
-
 #define C_SLOT_SHORT    9       // micro sec.
 #define C_SLOT_LONG     20
 
@@ -79,34 +78,30 @@ static int          msglevel                =MSG_LEVEL_INFO;
 
 #define WAIT_BEACON_TX_DOWN_TMO         3    // Times
 
-                                                              //1M,   2M,   5M,  11M,  18M,  24M,  36M,  54M
+//1M,   2M,   5M,  11M,  18M,  24M,  36M,  54M
 static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
-                                                                    //6M,   9M,  12M,  48M
+//6M,   9M,  12M,  48M
 static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
-                                                              //6M,   9M,  12M,  18M,  24M,  36M,  48M,  54M
+//6M,   9M,  12M,  18M,  24M,  36M,  48M,  54M
 static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
-                                                              //1M,   2M,   5M,  11M,
+//1M,   2M,   5M,  11M,
 static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
 
-
 /*---------------------  Static Variables  --------------------------*/
 
-
 const unsigned short cwRXBCNTSFOff[MAX_RATE] =
 {17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
 
-
 /*---------------------  Static Functions  --------------------------*/
 
 static
 void
 s_vCalculateOFDMRParameter(
-    unsigned char byRate,
-    CARD_PHY_TYPE ePHYType,
-    unsigned char *pbyTxRate,
-    unsigned char *pbyRsvTime
-    );
-
+       unsigned char byRate,
+       CARD_PHY_TYPE ePHYType,
+       unsigned char *pbyTxRate,
+       unsigned char *pbyRsvTime
+);
 
 /*---------------------  Export Functions  --------------------------*/
 
@@ -126,107 +121,97 @@ s_vCalculateOFDMRParameter(
  */
 static
 void
-s_vCalculateOFDMRParameter (
-    unsigned char byRate,
-    CARD_PHY_TYPE ePHYType,
-    unsigned char *pbyTxRate,
-    unsigned char *pbyRsvTime
-    )
+s_vCalculateOFDMRParameter(
+       unsigned char byRate,
+       CARD_PHY_TYPE ePHYType,
+       unsigned char *pbyTxRate,
+       unsigned char *pbyRsvTime
+)
 {
-    switch (byRate) {
-    case RATE_6M :
-        if (ePHYType == PHY_TYPE_11A) {//5GHZ
-            *pbyTxRate = 0x9B;
-            *pbyRsvTime = 44;
-        }
-        else {
-            *pbyTxRate = 0x8B;
-            *pbyRsvTime = 50;
-        }
-        break;
-
-    case RATE_9M :
-        if (ePHYType == PHY_TYPE_11A) {//5GHZ
-            *pbyTxRate = 0x9F;
-            *pbyRsvTime = 36;
-        }
-        else {
-            *pbyTxRate = 0x8F;
-            *pbyRsvTime = 42;
-        }
-        break;
-
-   case RATE_12M :
-        if (ePHYType == PHY_TYPE_11A) {//5GHZ
-            *pbyTxRate = 0x9A;
-            *pbyRsvTime = 32;
-        }
-        else {
-            *pbyTxRate = 0x8A;
-            *pbyRsvTime = 38;
-        }
-        break;
-
-   case RATE_18M :
-        if (ePHYType == PHY_TYPE_11A) {//5GHZ
-            *pbyTxRate = 0x9E;
-            *pbyRsvTime = 28;
-        }
-        else {
-            *pbyTxRate = 0x8E;
-            *pbyRsvTime = 34;
-        }
-        break;
-
-    case RATE_36M :
-        if (ePHYType == PHY_TYPE_11A) {//5GHZ
-            *pbyTxRate = 0x9D;
-            *pbyRsvTime = 24;
-        }
-        else {
-            *pbyTxRate = 0x8D;
-            *pbyRsvTime = 30;
-        }
-        break;
-
-    case RATE_48M :
-        if (ePHYType == PHY_TYPE_11A) {//5GHZ
-            *pbyTxRate = 0x98;
-            *pbyRsvTime = 24;
-        }
-        else {
-            *pbyTxRate = 0x88;
-            *pbyRsvTime = 30;
-        }
-        break;
-
-    case RATE_54M :
-        if (ePHYType == PHY_TYPE_11A) {//5GHZ
-            *pbyTxRate = 0x9C;
-            *pbyRsvTime = 24;
-        }
-        else {
-            *pbyTxRate = 0x8C;
-            *pbyRsvTime = 30;
-        }
-        break;
-
-    case RATE_24M :
-    default :
-        if (ePHYType == PHY_TYPE_11A) {//5GHZ
-            *pbyTxRate = 0x99;
-            *pbyRsvTime = 28;
-        }
-        else {
-            *pbyTxRate = 0x89;
-            *pbyRsvTime = 34;
-        }
-        break;
-    }
+       switch (byRate) {
+       case RATE_6M:
+               if (ePHYType == PHY_TYPE_11A) {//5GHZ
+                       *pbyTxRate = 0x9B;
+                       *pbyRsvTime = 44;
+               } else {
+                       *pbyTxRate = 0x8B;
+                       *pbyRsvTime = 50;
+               }
+               break;
+
+       case RATE_9M:
+               if (ePHYType == PHY_TYPE_11A) {//5GHZ
+                       *pbyTxRate = 0x9F;
+                       *pbyRsvTime = 36;
+               } else {
+                       *pbyTxRate = 0x8F;
+                       *pbyRsvTime = 42;
+               }
+               break;
+
+       case RATE_12M:
+               if (ePHYType == PHY_TYPE_11A) {//5GHZ
+                       *pbyTxRate = 0x9A;
+                       *pbyRsvTime = 32;
+               } else {
+                       *pbyTxRate = 0x8A;
+                       *pbyRsvTime = 38;
+               }
+               break;
+
+       case RATE_18M:
+               if (ePHYType == PHY_TYPE_11A) {//5GHZ
+                       *pbyTxRate = 0x9E;
+                       *pbyRsvTime = 28;
+               } else {
+                       *pbyTxRate = 0x8E;
+                       *pbyRsvTime = 34;
+               }
+               break;
+
+       case RATE_36M:
+               if (ePHYType == PHY_TYPE_11A) {//5GHZ
+                       *pbyTxRate = 0x9D;
+                       *pbyRsvTime = 24;
+               } else {
+                       *pbyTxRate = 0x8D;
+                       *pbyRsvTime = 30;
+               }
+               break;
+
+       case RATE_48M:
+               if (ePHYType == PHY_TYPE_11A) {//5GHZ
+                       *pbyTxRate = 0x98;
+                       *pbyRsvTime = 24;
+               } else {
+                       *pbyTxRate = 0x88;
+                       *pbyRsvTime = 30;
+               }
+               break;
+
+       case RATE_54M:
+               if (ePHYType == PHY_TYPE_11A) {//5GHZ
+                       *pbyTxRate = 0x9C;
+                       *pbyRsvTime = 24;
+               } else {
+                       *pbyTxRate = 0x8C;
+                       *pbyRsvTime = 30;
+               }
+               break;
+
+       case RATE_24M:
+       default:
+               if (ePHYType == PHY_TYPE_11A) {//5GHZ
+                       *pbyTxRate = 0x99;
+                       *pbyRsvTime = 28;
+               } else {
+                       *pbyTxRate = 0x89;
+                       *pbyRsvTime = 34;
+               }
+               break;
+       }
 }
 
-
-
 /*
  * Description: Set RSPINF
  *
@@ -241,114 +226,114 @@ s_vCalculateOFDMRParameter (
  */
 static
 void
-s_vSetRSPINF (PSDevice pDevice, CARD_PHY_TYPE ePHYType, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
+s_vSetRSPINF(PSDevice pDevice, CARD_PHY_TYPE ePHYType, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
 {
-    unsigned char byServ = 0, bySignal = 0; // For CCK
-    unsigned short wLen = 0;
-    unsigned char byTxRate = 0, byRsvTime = 0;    // For OFDM
-
-    //Set to Page1
-    MACvSelectPage1(pDevice->PortOffset);
-
-    //RSPINF_b_1
-    BBvCalculateParameter(pDevice,
-                         14,
-                         VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
-                         PK_TYPE_11B,
-                         &wLen,
-                         &byServ,
-                         &bySignal
-    );
-
-    VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
-    ///RSPINF_b_2
-    BBvCalculateParameter(pDevice,
-                         14,
-                         VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
-                         PK_TYPE_11B,
-                         &wLen,
-                         &byServ,
-                         &bySignal
-    );
-
-    VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
-    //RSPINF_b_5
-    BBvCalculateParameter(pDevice,
-                         14,
-                         VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
-                         PK_TYPE_11B,
-                         &wLen,
-                         &byServ,
-                         &bySignal
-    );
-
-    VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
-    //RSPINF_b_11
-    BBvCalculateParameter(pDevice,
-                         14,
-                         VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
-                         PK_TYPE_11B,
-                         &wLen,
-                         &byServ,
-                         &bySignal
-    );
-
-    VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
-    //RSPINF_a_6
-    s_vCalculateOFDMRParameter(RATE_6M,
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_9
-    s_vCalculateOFDMRParameter(RATE_9M,
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_12
-    s_vCalculateOFDMRParameter(RATE_12M,
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_18
-    s_vCalculateOFDMRParameter(RATE_18M,
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_24
-    s_vCalculateOFDMRParameter(RATE_24M,
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_36
-    s_vCalculateOFDMRParameter(
-                              VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_48
-    s_vCalculateOFDMRParameter(
-                              VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_54
-    s_vCalculateOFDMRParameter(
-                              VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_72
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate,byRsvTime));
-    //Set to Page0
-    MACvSelectPage0(pDevice->PortOffset);
+       unsigned char byServ = 0, bySignal = 0; // For CCK
+       unsigned short wLen = 0;
+       unsigned char byTxRate = 0, byRsvTime = 0;    // For OFDM
+
+       //Set to Page1
+       MACvSelectPage1(pDevice->PortOffset);
+
+       //RSPINF_b_1
+       BBvCalculateParameter(pDevice,
+                             14,
+                             VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
+                             PK_TYPE_11B,
+                             &wLen,
+                             &byServ,
+                             &bySignal
+);
+
+       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
+       ///RSPINF_b_2
+       BBvCalculateParameter(pDevice,
+                             14,
+                             VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
+                             PK_TYPE_11B,
+                             &wLen,
+                             &byServ,
+                             &bySignal
+);
+
+       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
+       //RSPINF_b_5
+       BBvCalculateParameter(pDevice,
+                             14,
+                             VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
+                             PK_TYPE_11B,
+                             &wLen,
+                             &byServ,
+                             &bySignal
+);
+
+       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
+       //RSPINF_b_11
+       BBvCalculateParameter(pDevice,
+                             14,
+                             VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
+                             PK_TYPE_11B,
+                             &wLen,
+                             &byServ,
+                             &bySignal
+);
+
+       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
+       //RSPINF_a_6
+       s_vCalculateOFDMRParameter(RATE_6M,
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_9
+       s_vCalculateOFDMRParameter(RATE_9M,
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_12
+       s_vCalculateOFDMRParameter(RATE_12M,
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_18
+       s_vCalculateOFDMRParameter(RATE_18M,
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_24
+       s_vCalculateOFDMRParameter(RATE_24M,
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_36
+       s_vCalculateOFDMRParameter(
+               VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
+               ePHYType,
+               &byTxRate,
+               &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_48
+       s_vCalculateOFDMRParameter(
+               VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
+               ePHYType,
+               &byTxRate,
+               &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_54
+       s_vCalculateOFDMRParameter(
+               VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
+               ePHYType,
+               &byTxRate,
+               &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_72
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
+       //Set to Page0
+       MACvSelectPage0(pDevice->PortOffset);
 }
 
 /*---------------------  Export Functions  --------------------------*/
@@ -369,22 +354,20 @@ s_vSetRSPINF (PSDevice pDevice, CARD_PHY_TYPE ePHYType, void *pvSupportRateIEs,
  *
  */
 /*
-bool CARDbSendPacket (void *pDeviceHandler, void *pPacket, CARD_PKT_TYPE ePktType, unsigned int uLength)
-{
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    if (ePktType == PKT_TYPE_802_11_MNG) {
-        return TXbTD0Send(pDevice, pPacket, uLength);
-    } else if (ePktType == PKT_TYPE_802_11_BCN) {
-        return TXbBeaconSend(pDevice, pPacket, uLength);
-    } if (ePktType == PKT_TYPE_802_11_DATA) {
-        return TXbTD1Send(pDevice, pPacket, uLength);
-    }
-
-    return (true);
-}
+  bool CARDbSendPacket (void *pDeviceHandler, void *pPacket, CARD_PKT_TYPE ePktType, unsigned int uLength) {
+  PSDevice    pDevice = (PSDevice) pDeviceHandler;
+  if (ePktType == PKT_TYPE_802_11_MNG) {
+  return TXbTD0Send(pDevice, pPacket, uLength);
+  } else if (ePktType == PKT_TYPE_802_11_BCN) {
+  return TXbBeaconSend(pDevice, pPacket, uLength);
+  } if (ePktType == PKT_TYPE_802_11_DATA) {
+  return TXbTD1Send(pDevice, pPacket, uLength);
+  }
+
+  return true;
+  }
 */
 
-
 /*
  * Description: Get Card short preamble option value
  *
@@ -397,13 +380,13 @@ bool CARDbSendPacket (void *pDeviceHandler, void *pPacket, CARD_PKT_TYPE ePktTyp
  * Return Value: true if short preamble; otherwise false
  *
  */
-bool CARDbIsShortPreamble (void *pDeviceHandler)
+bool CARDbIsShortPreamble(void *pDeviceHandler)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    if (pDevice->byPreambleType == 0) {
-        return(false);
-    }
-    return(true);
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       if (pDevice->byPreambleType == 0) {
+               return false;
+       }
+       return true;
 }
 
 /*
@@ -418,13 +401,12 @@ bool CARDbIsShortPreamble (void *pDeviceHandler)
  * Return Value: true if short slot time; otherwise false
  *
  */
-bool CARDbIsShorSlotTime (void *pDeviceHandler)
+bool CARDbIsShorSlotTime(void *pDeviceHandler)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    return(pDevice->bShortSlotTime);
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       return pDevice->bShortSlotTime;
 }
 
-
 /*
  * Description: Update IFS
  *
@@ -437,175 +419,174 @@ bool CARDbIsShorSlotTime (void *pDeviceHandler)
  * Return Value: None.
  *
  */
-bool CARDbSetPhyParameter (void *pDeviceHandler, CARD_PHY_TYPE ePHYType, unsigned short wCapInfo, unsigned char byERPField, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
+bool CARDbSetPhyParameter(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, unsigned short wCapInfo, unsigned char byERPField, void *pvSupportRateIEs, void *pvExtSupportRateIEs)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    unsigned char byCWMaxMin = 0;
-    unsigned char bySlot = 0;
-    unsigned char bySIFS = 0;
-    unsigned char byDIFS = 0;
-    unsigned char byData;
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       unsigned char byCWMaxMin = 0;
+       unsigned char bySlot = 0;
+       unsigned char bySIFS = 0;
+       unsigned char byDIFS = 0;
+       unsigned char byData;
 //    PWLAN_IE_SUPP_RATES pRates = NULL;
-    PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
-    PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
-
-
-    //Set SIFS, DIFS, EIFS, SlotTime, CwMin
-    if (ePHYType == PHY_TYPE_11A) {
-        if (pSupportRates == NULL) {
-            pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
-        }
-        if (pDevice->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->PortOffset, 0xE7, &byData);
-            if (byData == 0x1C) {
-                BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
-            }
-        } else if (pDevice->byRFType == RF_UW2452) {
-            MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
-            pDevice->abyBBVGA[0] = 0x18;
-            BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
-            if (byData == 0x14) {
-                BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
-                BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57);
-            }
-        } else {
-            MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
-        }
-        BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03);
-        bySlot = C_SLOT_SHORT;
-        bySIFS = C_SIFS_A;
-        byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
-        byCWMaxMin = 0xA4;
-    } else if (ePHYType == PHY_TYPE_11B) {
-        if (pSupportRates == NULL) {
-            pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
-        }
-        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->PortOffset, 0xE7, &byData);
-            if (byData == 0x20) {
-                BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
-            }
-        } else if (pDevice->byRFType == RF_UW2452) {
-            pDevice->abyBBVGA[0] = 0x14;
-            BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
-            if (byData == 0x18) {
-                BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
-                BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
-            }
-        }
-        BBbWriteEmbedded(pDevice->PortOffset, 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
-        if (pSupportRates == NULL) {
-            pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
-            pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
-        }
-        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->PortOffset, 0xE7, &byData);
-            if (byData == 0x20) {
-                BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
-            }
-        } else if (pDevice->byRFType == RF_UW2452) {
-            pDevice->abyBBVGA[0] = 0x14;
-            BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
-            if (byData == 0x18) {
-                BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
-                BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
-            }
-        }
-        BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08);
-        bySIFS = C_SIFS_BG;
-        if(VNTWIFIbIsShortSlotTime(wCapInfo)) {
-            bySlot = C_SLOT_SHORT;
-            byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
-        } else {
-            bySlot = C_SLOT_LONG;
-            byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
-           }
-        if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M) {
-            byCWMaxMin = 0xA4;
-        } else {
-            byCWMaxMin = 0xA5;
-        }
-        if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
-            pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
-            if (pDevice->bProtectMode) {
-                MACvEnableProtectMD(pDevice->PortOffset);
-            } else {
-                MACvDisableProtectMD(pDevice->PortOffset);
-            }
-        }
-        if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
-            pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
-            if (pDevice->bBarkerPreambleMd) {
-                MACvEnableBarkerPreambleMd(pDevice->PortOffset);
-            } else {
-                MACvDisableBarkerPreambleMd(pDevice->PortOffset);
-            }
-        }
-    }
-
-    if (pDevice->byRFType == RF_RFMD2959) {
-        // bcs TX_PE will reserve 3 us
-        // hardware's processing time here is 2 us.
-        bySIFS -= 3;
-        byDIFS -= 3;
-    //{{ RobertYu: 20041202
-    //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
-    //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
-    }
-
-    if (pDevice->bySIFS != bySIFS) {
-        pDevice->bySIFS = bySIFS;
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
-    }
-    if (pDevice->byDIFS != byDIFS) {
-        pDevice->byDIFS = byDIFS;
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
-    }
-    if (pDevice->byEIFS != C_EIFS) {
-        pDevice->byEIFS = C_EIFS;
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
-    }
-    if (pDevice->bySlot != bySlot) {
-        pDevice->bySlot = bySlot;
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
-        if (pDevice->bySlot == C_SLOT_SHORT) {
-            pDevice->bShortSlotTime = true;
-        } else {
-            pDevice->bShortSlotTime = false;
-        }
-        BBvSetShortSlotTime(pDevice);
-    }
-    if (pDevice->byCWMaxMin != byCWMaxMin) {
-        pDevice->byCWMaxMin = byCWMaxMin;
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
-    }
-    if (VNTWIFIbIsShortPreamble(wCapInfo)) {
-        pDevice->byPreambleType = pDevice->byShortPreamble;
-    } else {
-        pDevice->byPreambleType = 0;
-    }
-    s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
-    pDevice->eCurrentPHYType = ePHYType;
-    // set for NDIS OID_802_11SUPPORTED_RATES
-    return (true);
+       PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
+       PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
+
+       //Set SIFS, DIFS, EIFS, SlotTime, CwMin
+       if (ePHYType == PHY_TYPE_11A) {
+               if (pSupportRates == NULL) {
+                       pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
+               }
+               if (pDevice->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->PortOffset, 0xE7, &byData);
+                       if (byData == 0x1C) {
+                               BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
+                       }
+               } else if (pDevice->byRFType == RF_UW2452) {
+                       MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
+                       pDevice->abyBBVGA[0] = 0x18;
+                       BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
+                       if (byData == 0x14) {
+                               BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
+                               BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57);
+                       }
+               } else {
+                       MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
+               }
+               BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03);
+               bySlot = C_SLOT_SHORT;
+               bySIFS = C_SIFS_A;
+               byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
+               byCWMaxMin = 0xA4;
+       } else if (ePHYType == PHY_TYPE_11B) {
+               if (pSupportRates == NULL) {
+                       pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
+               }
+               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->PortOffset, 0xE7, &byData);
+                       if (byData == 0x20) {
+                               BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
+                       }
+               } else if (pDevice->byRFType == RF_UW2452) {
+                       pDevice->abyBBVGA[0] = 0x14;
+                       BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
+                       if (byData == 0x18) {
+                               BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
+                               BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
+                       }
+               }
+               BBbWriteEmbedded(pDevice->PortOffset, 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
+               if (pSupportRates == NULL) {
+                       pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
+                       pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
+               }
+               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->PortOffset, 0xE7, &byData);
+                       if (byData == 0x20) {
+                               BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
+                       }
+               } else if (pDevice->byRFType == RF_UW2452) {
+                       pDevice->abyBBVGA[0] = 0x14;
+                       BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData);
+                       if (byData == 0x18) {
+                               BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
+                               BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3);
+                       }
+               }
+               BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08);
+               bySIFS = C_SIFS_BG;
+               if (VNTWIFIbIsShortSlotTime(wCapInfo)) {
+                       bySlot = C_SLOT_SHORT;
+                       byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
+               } else {
+                       bySlot = C_SLOT_LONG;
+                       byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
+               }
+               if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M) {
+                       byCWMaxMin = 0xA4;
+               } else {
+                       byCWMaxMin = 0xA5;
+               }
+               if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
+                       pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
+                       if (pDevice->bProtectMode) {
+                               MACvEnableProtectMD(pDevice->PortOffset);
+                       } else {
+                               MACvDisableProtectMD(pDevice->PortOffset);
+                       }
+               }
+               if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
+                       pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
+                       if (pDevice->bBarkerPreambleMd) {
+                               MACvEnableBarkerPreambleMd(pDevice->PortOffset);
+                       } else {
+                               MACvDisableBarkerPreambleMd(pDevice->PortOffset);
+                       }
+               }
+       }
+
+       if (pDevice->byRFType == RF_RFMD2959) {
+               // bcs TX_PE will reserve 3 us
+               // hardware's processing time here is 2 us.
+               bySIFS -= 3;
+               byDIFS -= 3;
+               //{{ RobertYu: 20041202
+               //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
+               //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
+       }
+
+       if (pDevice->bySIFS != bySIFS) {
+               pDevice->bySIFS = bySIFS;
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
+       }
+       if (pDevice->byDIFS != byDIFS) {
+               pDevice->byDIFS = byDIFS;
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
+       }
+       if (pDevice->byEIFS != C_EIFS) {
+               pDevice->byEIFS = C_EIFS;
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
+       }
+       if (pDevice->bySlot != bySlot) {
+               pDevice->bySlot = bySlot;
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
+               if (pDevice->bySlot == C_SLOT_SHORT) {
+                       pDevice->bShortSlotTime = true;
+               } else {
+                       pDevice->bShortSlotTime = false;
+               }
+               BBvSetShortSlotTime(pDevice);
+       }
+       if (pDevice->byCWMaxMin != byCWMaxMin) {
+               pDevice->byCWMaxMin = byCWMaxMin;
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
+       }
+       if (VNTWIFIbIsShortPreamble(wCapInfo)) {
+               pDevice->byPreambleType = pDevice->byShortPreamble;
+       } else {
+               pDevice->byPreambleType = 0;
+       }
+       s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
+       pDevice->eCurrentPHYType = ePHYType;
+       // set for NDIS OID_802_11SUPPORTED_RATES
+       return true;
 }
 
 /*
@@ -624,27 +605,26 @@ bool CARDbSetPhyParameter (void *pDeviceHandler, CARD_PHY_TYPE ePHYType, unsigne
  * Return Value: none
  *
  */
-bool CARDbUpdateTSF (void *pDeviceHandler, unsigned char byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF)
+bool CARDbUpdateTSF(void *pDeviceHandler, unsigned char byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    QWORD       qwTSFOffset;
-
-    HIDWORD(qwTSFOffset) = 0;
-    LODWORD(qwTSFOffset) = 0;
-
-    if ((HIDWORD(qwBSSTimestamp) != HIDWORD(qwLocalTSF)) ||
-        (LODWORD(qwBSSTimestamp) != LODWORD(qwLocalTSF))) {
-        qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
-        // adjust TSF
-        // HW's TSF add TSF Offset reg
-        VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, LODWORD(qwTSFOffset));
-        VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, HIDWORD(qwTSFOffset));
-        MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
-    }
-    return(true);
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       QWORD       qwTSFOffset;
+
+       HIDWORD(qwTSFOffset) = 0;
+       LODWORD(qwTSFOffset) = 0;
+
+       if ((HIDWORD(qwBSSTimestamp) != HIDWORD(qwLocalTSF)) ||
+           (LODWORD(qwBSSTimestamp) != LODWORD(qwLocalTSF))) {
+               qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
+               // adjust TSF
+               // HW's TSF add TSF Offset reg
+               VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, LODWORD(qwTSFOffset));
+               VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, HIDWORD(qwTSFOffset));
+               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
+       }
+       return true;
 }
 
-
 /*
  * Description: Set NIC TSF counter for first Beacon time
  *              Get NEXTTBTT from adjusted TSF and Beacon Interval
@@ -659,47 +639,45 @@ bool CARDbUpdateTSF (void *pDeviceHandler, unsigned char byRxRate, QWORD qwBSSTi
  * Return Value: true if succeed; otherwise false
  *
  */
-bool CARDbSetBeaconPeriod (void *pDeviceHandler, unsigned short wBeaconInterval)
+bool CARDbSetBeaconPeriod(void *pDeviceHandler, unsigned short wBeaconInterval)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    unsigned int uBeaconInterval = 0;
-    unsigned int uLowNextTBTT = 0;
-    unsigned int uHighRemain = 0;
-    unsigned int uLowRemain = 0;
-    QWORD       qwNextTBTT;
-
-    HIDWORD(qwNextTBTT) = 0;
-    LODWORD(qwNextTBTT) = 0;
-    CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
-    uBeaconInterval = wBeaconInterval * 1024;
-    // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
-    uLowNextTBTT = (LODWORD(qwNextTBTT) >> 10) << 10;
-    uLowRemain = (uLowNextTBTT) % uBeaconInterval;
-    // high dword (mod) bcn
-    uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwNextTBTT))
-                  % uBeaconInterval;
-    uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
-    uLowRemain = uBeaconInterval - uLowRemain;
-
-    // check if carry when add one beacon interval
-    if ((~uLowNextTBTT) < uLowRemain) {
-        HIDWORD(qwNextTBTT) ++ ;
-    }
-    LODWORD(qwNextTBTT) = uLowNextTBTT + uLowRemain;
-
-    // set HW beacon interval
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
-    pDevice->wBeaconInterval = wBeaconInterval;
-    // Set NextTBTT
-    VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
-    VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
-    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
-
-    return(true);
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       unsigned int uBeaconInterval = 0;
+       unsigned int uLowNextTBTT = 0;
+       unsigned int uHighRemain = 0;
+       unsigned int uLowRemain = 0;
+       QWORD       qwNextTBTT;
+
+       HIDWORD(qwNextTBTT) = 0;
+       LODWORD(qwNextTBTT) = 0;
+       CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
+       uBeaconInterval = wBeaconInterval * 1024;
+       // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
+       uLowNextTBTT = (LODWORD(qwNextTBTT) >> 10) << 10;
+       uLowRemain = (uLowNextTBTT) % uBeaconInterval;
+       // high dword (mod) bcn
+       uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwNextTBTT))
+               % uBeaconInterval;
+       uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
+       uLowRemain = uBeaconInterval - uLowRemain;
+
+       // check if carry when add one beacon interval
+       if ((~uLowNextTBTT) < uLowRemain) {
+               HIDWORD(qwNextTBTT)++;
+       }
+       LODWORD(qwNextTBTT) = uLowNextTBTT + uLowRemain;
+
+       // set HW beacon interval
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
+       pDevice->wBeaconInterval = wBeaconInterval;
+       // Set NextTBTT
+       VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
+       VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
+
+       return true;
 }
 
-
-
 /*
  * Description: Card Stop Hardware Tx
  *
@@ -713,51 +691,49 @@ bool CARDbSetBeaconPeriod (void *pDeviceHandler, unsigned short wBeaconInterval)
  * Return Value: true if all data packet complete; otherwise false.
  *
  */
-bool CARDbStopTxPacket (void *pDeviceHandler, CARD_PKT_TYPE ePktType)
+bool CARDbStopTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-
-
-    if (ePktType == PKT_TYPE_802_11_ALL) {
-        pDevice->bStopBeacon = true;
-        pDevice->bStopTx0Pkt = true;
-        pDevice->bStopDataPkt = true;
-    } else if (ePktType == PKT_TYPE_802_11_BCN) {
-        pDevice->bStopBeacon = true;
-    } else if (ePktType == PKT_TYPE_802_11_MNG) {
-        pDevice->bStopTx0Pkt = true;
-    } else if (ePktType == PKT_TYPE_802_11_DATA) {
-        pDevice->bStopDataPkt = true;
-    }
-
-    if (pDevice->bStopBeacon == true) {
-        if (pDevice->bIsBeaconBufReadySet == true) {
-            if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
-                pDevice->cbBeaconBufReadySetCnt ++;
-                return(false);
-            }
-        }
-        pDevice->bIsBeaconBufReadySet = false;
-        pDevice->cbBeaconBufReadySetCnt = 0;
-        MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
-    }
-    // wait all TD0 complete
-    if (pDevice->bStopTx0Pkt == true) {
-         if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
-            return(false);
-        }
-    }
-    // wait all Data TD complete
-    if (pDevice->bStopDataPkt == true) {
-        if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
-            return(false);
-        }
-    }
-
-    return(true);
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+
+       if (ePktType == PKT_TYPE_802_11_ALL) {
+               pDevice->bStopBeacon = true;
+               pDevice->bStopTx0Pkt = true;
+               pDevice->bStopDataPkt = true;
+       } else if (ePktType == PKT_TYPE_802_11_BCN) {
+               pDevice->bStopBeacon = true;
+       } else if (ePktType == PKT_TYPE_802_11_MNG) {
+               pDevice->bStopTx0Pkt = true;
+       } else if (ePktType == PKT_TYPE_802_11_DATA) {
+               pDevice->bStopDataPkt = true;
+       }
+
+       if (pDevice->bStopBeacon == true) {
+               if (pDevice->bIsBeaconBufReadySet == true) {
+                       if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
+                               pDevice->cbBeaconBufReadySetCnt++;
+                               return false;
+                       }
+               }
+               pDevice->bIsBeaconBufReadySet = false;
+               pDevice->cbBeaconBufReadySetCnt = 0;
+               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
+       }
+       // wait all TD0 complete
+       if (pDevice->bStopTx0Pkt == true) {
+               if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
+                       return false;
+               }
+       }
+       // wait all Data TD complete
+       if (pDevice->bStopDataPkt == true) {
+               if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
+                       return false;
+               }
+       }
+
+       return true;
 }
 
-
 /*
  * Description: Card Start Hardware Tx
  *
@@ -771,34 +747,31 @@ bool CARDbStopTxPacket (void *pDeviceHandler, CARD_PKT_TYPE ePktType)
  * Return Value: true if success; false if failed.
  *
  */
-bool CARDbStartTxPacket (void *pDeviceHandler, CARD_PKT_TYPE ePktType)
+bool CARDbStartTxPacket(void *pDeviceHandler, CARD_PKT_TYPE ePktType)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-
-
-    if (ePktType == PKT_TYPE_802_11_ALL) {
-        pDevice->bStopBeacon = false;
-        pDevice->bStopTx0Pkt = false;
-        pDevice->bStopDataPkt = false;
-    } else if (ePktType == PKT_TYPE_802_11_BCN) {
-        pDevice->bStopBeacon = false;
-    } else if (ePktType == PKT_TYPE_802_11_MNG) {
-        pDevice->bStopTx0Pkt = false;
-    } else if (ePktType == PKT_TYPE_802_11_DATA) {
-        pDevice->bStopDataPkt = false;
-    }
-
-    if ((pDevice->bStopBeacon == false) &&
-        (pDevice->bBeaconBufReady == true) &&
-        (pDevice->eOPMode == OP_MODE_ADHOC)) {
-        MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
-    }
-
-    return(true);
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+
+       if (ePktType == PKT_TYPE_802_11_ALL) {
+               pDevice->bStopBeacon = false;
+               pDevice->bStopTx0Pkt = false;
+               pDevice->bStopDataPkt = false;
+       } else if (ePktType == PKT_TYPE_802_11_BCN) {
+               pDevice->bStopBeacon = false;
+       } else if (ePktType == PKT_TYPE_802_11_MNG) {
+               pDevice->bStopTx0Pkt = false;
+       } else if (ePktType == PKT_TYPE_802_11_DATA) {
+               pDevice->bStopDataPkt = false;
+       }
+
+       if ((pDevice->bStopBeacon == false) &&
+           (pDevice->bBeaconBufReady == true) &&
+           (pDevice->eOPMode == OP_MODE_ADHOC)) {
+               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
+       }
+
+       return true;
 }
 
-
-
 /*
  * Description: Card Set BSSID value
  *
@@ -815,39 +788,38 @@ bool CARDbStartTxPacket (void *pDeviceHandler, CARD_PKT_TYPE ePktType)
  */
 bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE eOPMode)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-
-    MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
-    memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
-    if (eOPMode == OP_MODE_ADHOC) {
-        MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
-    } else {
-        MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
-    }
-    if (eOPMode == OP_MODE_AP) {
-        MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
-    } else {
-        MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
-    }
-    if (eOPMode == OP_MODE_UNKNOWN) {
-        MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
-        pDevice->bBSSIDFilter = false;
-        pDevice->byRxMode &= ~RCR_BSSID;
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
-    } else {
-        if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
-            MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
-            pDevice->bBSSIDFilter = true;
-            pDevice->byRxMode |= RCR_BSSID;
-           }
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode );
-    }
-    // Adopt BSS state in Adapter Device Object
-    pDevice->eOPMode = eOPMode;
-    return(true);
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+
+       MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
+       memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
+       if (eOPMode == OP_MODE_ADHOC) {
+               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
+       } else {
+               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
+       }
+       if (eOPMode == OP_MODE_AP) {
+               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
+       } else {
+               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
+       }
+       if (eOPMode == OP_MODE_UNKNOWN) {
+               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
+               pDevice->bBSSIDFilter = false;
+               pDevice->byRxMode &= ~RCR_BSSID;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode);
+       } else {
+               if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
+                       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
+                       pDevice->bBSSIDFilter = true;
+                       pDevice->byRxMode |= RCR_BSSID;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode);
+       }
+       // Adopt BSS state in Adapter Device Object
+       pDevice->eOPMode = eOPMode;
+       return true;
 }
 
-
 /*
  * Description: Card indicate status
  *
@@ -862,9 +834,6 @@ bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE e
  *
  */
 
-
-
-
 /*
  * Description: Save Assoc info. contain in assoc. response frame
  *
@@ -883,14 +852,14 @@ bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE e
  *
  */
 bool CARDbSetTxDataRate(
-    void *pDeviceHandler,
-    unsigned short wDataRate
-    )
+       void *pDeviceHandler,
+       unsigned short wDataRate
+)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
 
-    pDevice->wCurrentRate = wDataRate;
-    return(true);
+       pDevice->wCurrentRate = wDataRate;
+       return true;
 }
 
 /*+
@@ -906,32 +875,32 @@ bool CARDbSetTxDataRate(
  *
  * Return Value: true if power down success; otherwise false
  *
--*/
+ -*/
 bool
 CARDbPowerDown(
-    void *pDeviceHandler
-    )
+       void *pDeviceHandler
+)
 {
-    PSDevice        pDevice = (PSDevice)pDeviceHandler;
-    unsigned int uIdx;
+       PSDevice        pDevice = (PSDevice)pDeviceHandler;
+       unsigned int uIdx;
 
-    // check if already in Doze mode
-    if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
-        return true;
+       // check if already in Doze mode
+       if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
+               return true;
 
-    // Froce PSEN on
-    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
+       // Froce PSEN on
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
 
-    // check if all TD are empty,
+       // check if all TD are empty,
 
-    for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx ++) {
-        if (pDevice->iTDUsed[uIdx] != 0)
-            return false;
-    }
+       for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
+               if (pDevice->iTDUsed[uIdx] != 0)
+                       return false;
+       }
 
-    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Go to Doze ZZZZZZZZZZZZZZZ\n");
-    return true;
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
+       return true;
 }
 
 /*
@@ -946,43 +915,40 @@ CARDbPowerDown(
  * Return Value: true if success; otherwise false
  *
  */
-bool CARDbRadioPowerOff (void *pDeviceHandler)
+bool CARDbRadioPowerOff(void *pDeviceHandler)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    bool bResult = true;
-
-    if (pDevice->bRadioOff == true)
-        return true;
+       PSDevice    pDevice = (PSDevice)pDeviceHandler;
+       bool bResult = true;
 
+       if (pDevice->bRadioOff == true)
+               return true;
 
-    switch (pDevice->byRFType) {
+       switch (pDevice->byRFType) {
+       case RF_RFMD2959:
+               MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
+               MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
+               break;
 
-        case RF_RFMD2959:
-            MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
-            MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
-            break;
+       case RF_AIROHA:
+       case RF_AL2230S:
+       case RF_AIROHA7230: //RobertYu:20050104
+               MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
+               MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
+               break;
 
-        case RF_AIROHA:
-        case RF_AL2230S:
-        case RF_AIROHA7230: //RobertYu:20050104
-            MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
-            MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
-            break;
+       }
 
-    }
+       MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
 
-    MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
+       BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
 
-    BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
-
-    pDevice->bRadioOff = true;
-     //2007-0409-03,<Add> by chester
-printk("chester power off\n");
-MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET);  //LED issue
-    return bResult;
+       pDevice->bRadioOff = true;
+       //2007-0409-03,<Add> by chester
+       printk("chester power off\n");
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET);  //LED issue
+       return bResult;
 }
 
-
 /*
  * Description: Turn on Radio power
  *
@@ -995,59 +961,54 @@ MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET);  //LED issue
  * Return Value: true if success; otherwise false
  *
  */
-bool CARDbRadioPowerOn (void *pDeviceHandler)
+bool CARDbRadioPowerOn(void *pDeviceHandler)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    bool bResult = true;
-printk("chester power on\n");
-    if (pDevice->bRadioControlOff == true){
-if (pDevice->bHWRadioOff == true) printk("chester bHWRadioOff\n");
-if (pDevice->bRadioControlOff == true) printk("chester bRadioControlOff\n");
-        return false;}
-
-    if (pDevice->bRadioOff == false)
-       {
-printk("chester pbRadioOff\n");
-return true;}
-
-    BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
-
-    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
-
-    switch (pDevice->byRFType) {
-
-        case RF_RFMD2959:
-            MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
-            MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
-            break;
-
-        case RF_AIROHA:
-        case RF_AL2230S:
-        case RF_AIROHA7230: //RobertYu:20050104
-            MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
-                                                                        SOFTPWRCTL_SWPE3));
-            break;
-
-    }
-
-    pDevice->bRadioOff = false;
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       bool bResult = true;
+       printk("chester power on\n");
+       if (pDevice->bRadioControlOff == true) {
+               if (pDevice->bHWRadioOff == true) printk("chester bHWRadioOff\n");
+               if (pDevice->bRadioControlOff == true) printk("chester bRadioControlOff\n");
+               return false; }
+
+       if (pDevice->bRadioOff == false) {
+               printk("chester pbRadioOff\n");
+               return true; }
+
+       BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
+
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
+
+       switch (pDevice->byRFType) {
+       case RF_RFMD2959:
+               MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
+               MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
+               break;
+
+       case RF_AIROHA:
+       case RF_AL2230S:
+       case RF_AIROHA7230: //RobertYu:20050104
+               MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
+                                                                           SOFTPWRCTL_SWPE3));
+               break;
+
+       }
+
+       pDevice->bRadioOff = false;
 //  2007-0409-03,<Add> by chester
-printk("chester power on\n");
-MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
-    return bResult;
+       printk("chester power on\n");
+       MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
+       return bResult;
 }
 
-
-
-bool CARDbRemoveKey (void *pDeviceHandler, unsigned char *pbyBSSID)
+bool CARDbRemoveKey(void *pDeviceHandler, unsigned char *pbyBSSID)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
 
-    KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
-    return (true);
+       KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
+       return true;
 }
 
-
 /*
  *
  * Description:
@@ -1063,66 +1024,65 @@ bool CARDbRemoveKey (void *pDeviceHandler, unsigned char *pbyBSSID)
  *
  * Return Value: none.
  *
--*/
+ -*/
 bool
-CARDbAdd_PMKID_Candidate (
-    void *pDeviceHandler,
-    unsigned char *pbyBSSID,
-    bool bRSNCapExist,
-    unsigned short wRSNCap
-    )
+CARDbAdd_PMKID_Candidate(
+       void *pDeviceHandler,
+       unsigned char *pbyBSSID,
+       bool bRSNCapExist,
+       unsigned short wRSNCap
+)
 {
-    PSDevice            pDevice = (PSDevice) pDeviceHandler;
-    PPMKID_CANDIDATE    pCandidateList;
-    unsigned int ii = 0;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
-
-    if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFlush_PMKID_Candidate: 3\n");
-        memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
-    }
-
-    for (ii = 0; ii < 6; ii++) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02X ", *(pbyBSSID + ii));
-    }
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
-
-
-    // Update Old Candidate
-    for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
-        pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
-        if ( !memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
-            if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
-                pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
-            } else {
-                pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
-            }
-            return true;
-        }
-    }
-
-    // New Candidate
-    pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
-    if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
-        pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
-    } else {
-        pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
-    }
-    memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
-    pDevice->gsPMKIDCandidate.NumCandidates++;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
-    return true;
+       PSDevice            pDevice = (PSDevice) pDeviceHandler;
+       PPMKID_CANDIDATE    pCandidateList;
+       unsigned int ii = 0;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
+
+       if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vFlush_PMKID_Candidate: 3\n");
+               memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
+       }
+
+       for (ii = 0; ii < 6; ii++) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02X ", *(pbyBSSID + ii));
+       }
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
+
+       // Update Old Candidate
+       for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
+               pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
+               if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
+                       if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
+                               pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
+                       } else {
+                               pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
+                       }
+                       return true;
+               }
+       }
+
+       // New Candidate
+       pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
+       if ((bRSNCapExist == true) && (wRSNCap & BIT0)) {
+               pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
+       } else {
+               pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
+       }
+       memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
+       pDevice->gsPMKIDCandidate.NumCandidates++;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
+       return true;
 }
 
 void *
-CARDpGetCurrentAddress (
-    void *pDeviceHandler
-    )
+CARDpGetCurrentAddress(
+       void *pDeviceHandler
+)
 {
-    PSDevice            pDevice = (PSDevice) pDeviceHandler;
+       PSDevice            pDevice = (PSDevice) pDeviceHandler;
 
-    return (pDevice->abyCurrentNetAddr);
+       return pDevice->abyCurrentNetAddr;
 }
 
 /*
@@ -1138,120 +1098,119 @@ CARDpGetCurrentAddress (
  *
  * Return Value: none.
  *
--*/
+ -*/
 bool
-CARDbStartMeasure (
-    void *pDeviceHandler,
-    void *pvMeasureEIDs,
-    unsigned int uNumOfMeasureEIDs
-    )
+CARDbStartMeasure(
+       void *pDeviceHandler,
+       void *pvMeasureEIDs,
+       unsigned int uNumOfMeasureEIDs
+)
 {
-    PSDevice                pDevice = (PSDevice) pDeviceHandler;
-    PWLAN_IE_MEASURE_REQ    pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
-    QWORD                   qwCurrTSF;
-    QWORD                   qwStartTSF;
-    bool bExpired = true;
-    unsigned short wDuration = 0;
-
-    if ((pEID == NULL) ||
-        (uNumOfMeasureEIDs == 0)) {
-        return (true);
-    }
-    CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
-    if (pDevice->bMeasureInProgress == true) {
-        pDevice->bMeasureInProgress = false;
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
-        MACvSelectPage1(pDevice->PortOffset);
-        VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
-        VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
-        // clear measure control
-        MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
-        MACvSelectPage0(pDevice->PortOffset);
-        set_channel(pDevice, pDevice->byOrgChannel);
-        MACvSelectPage1(pDevice->PortOffset);
-        MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
-        MACvSelectPage0(pDevice->PortOffset);
-    }
-    pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
-
-    do {
-        pDevice->pCurrMeasureEID = pEID;
-        pEID++;
-        pDevice->uNumOfMeasureEIDs--;
-
-        if (pDevice->byLocalID > REV_ID_VT3253_B1) {
-            HIDWORD(qwStartTSF) = HIDWORD(*((PQWORD) (pDevice->pCurrMeasureEID->sReq.abyStartTime)));
-            LODWORD(qwStartTSF) = LODWORD(*((PQWORD) (pDevice->pCurrMeasureEID->sReq.abyStartTime)));
-            wDuration = *((unsigned short *) (pDevice->pCurrMeasureEID->sReq.abyDuration));
-            wDuration += 1; // 1 TU for channel switching
-
-            if ((LODWORD(qwStartTSF) == 0) && (HIDWORD(qwStartTSF) == 0)) {
-                // start immediately by setting start TSF == current TSF + 2 TU
-                LODWORD(qwStartTSF) = LODWORD(qwCurrTSF) + 2048;
-                HIDWORD(qwStartTSF) = HIDWORD(qwCurrTSF);
-                if (LODWORD(qwCurrTSF) > LODWORD(qwStartTSF)) {
-                    HIDWORD(qwStartTSF)++;
-                }
-                bExpired = false;
-                break;
-            } else {
-                // start at setting start TSF - 1TU(for channel switching)
-                if (LODWORD(qwStartTSF) < 1024) {
-                    HIDWORD(qwStartTSF)--;
-                }
-                LODWORD(qwStartTSF) -= 1024;
-            }
-
-            if ((HIDWORD(qwCurrTSF) < HIDWORD(qwStartTSF)) ||
-                ((HIDWORD(qwCurrTSF) == HIDWORD(qwStartTSF)) &&
-                (LODWORD(qwCurrTSF) < LODWORD(qwStartTSF)))
-                ) {
-                bExpired = false;
-                break;
-            }
-            VNTWIFIbMeasureReport(  pDevice->pMgmt,
-                                    false,
-                                    pDevice->pCurrMeasureEID,
-                                    MEASURE_MODE_LATE,
-                                    pDevice->byBasicMap,
-                                    pDevice->byCCAFraction,
-                                    pDevice->abyRPIs
-                                    );
-        } else {
-            // hardware do not support measure
-            VNTWIFIbMeasureReport(  pDevice->pMgmt,
-                                    false,
-                                    pDevice->pCurrMeasureEID,
-                                    MEASURE_MODE_INCAPABLE,
-                                    pDevice->byBasicMap,
-                                    pDevice->byCCAFraction,
-                                    pDevice->abyRPIs
-                                    );
-        }
-    } while (pDevice->uNumOfMeasureEIDs != 0);
-
-    if (bExpired == false) {
-        MACvSelectPage1(pDevice->PortOffset);
-        VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, LODWORD(qwStartTSF));
-        VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, HIDWORD(qwStartTSF));
-        VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
-        MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
-        MACvSelectPage0(pDevice->PortOffset);
-    } else {
-        // all measure start time expired we should complete action
-        VNTWIFIbMeasureReport(  pDevice->pMgmt,
-                                true,
-                                NULL,
-                                0,
-                                pDevice->byBasicMap,
-                                pDevice->byCCAFraction,
-                                pDevice->abyRPIs
-                                );
-    }
-    return (true);
+       PSDevice                pDevice = (PSDevice) pDeviceHandler;
+       PWLAN_IE_MEASURE_REQ    pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
+       QWORD                   qwCurrTSF;
+       QWORD                   qwStartTSF;
+       bool bExpired = true;
+       unsigned short wDuration = 0;
+
+       if ((pEID == NULL) ||
+           (uNumOfMeasureEIDs == 0)) {
+               return true;
+       }
+       CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
+       if (pDevice->bMeasureInProgress == true) {
+               pDevice->bMeasureInProgress = false;
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
+               MACvSelectPage1(pDevice->PortOffset);
+               VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
+               VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
+               // clear measure control
+               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
+               MACvSelectPage0(pDevice->PortOffset);
+               set_channel(pDevice, pDevice->byOrgChannel);
+               MACvSelectPage1(pDevice->PortOffset);
+               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
+               MACvSelectPage0(pDevice->PortOffset);
+       }
+       pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
+
+       do {
+               pDevice->pCurrMeasureEID = pEID;
+               pEID++;
+               pDevice->uNumOfMeasureEIDs--;
+
+               if (pDevice->byLocalID > REV_ID_VT3253_B1) {
+                       HIDWORD(qwStartTSF) = HIDWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime)));
+                       LODWORD(qwStartTSF) = LODWORD(*((PQWORD)(pDevice->pCurrMeasureEID->sReq.abyStartTime)));
+                       wDuration = *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
+                       wDuration += 1; // 1 TU for channel switching
+
+                       if ((LODWORD(qwStartTSF) == 0) && (HIDWORD(qwStartTSF) == 0)) {
+                               // start immediately by setting start TSF == current TSF + 2 TU
+                               LODWORD(qwStartTSF) = LODWORD(qwCurrTSF) + 2048;
+                               HIDWORD(qwStartTSF) = HIDWORD(qwCurrTSF);
+                               if (LODWORD(qwCurrTSF) > LODWORD(qwStartTSF)) {
+                                       HIDWORD(qwStartTSF)++;
+                               }
+                               bExpired = false;
+                               break;
+                       } else {
+                               // start at setting start TSF - 1TU(for channel switching)
+                               if (LODWORD(qwStartTSF) < 1024) {
+                                       HIDWORD(qwStartTSF)--;
+                               }
+                               LODWORD(qwStartTSF) -= 1024;
+                       }
+
+                       if ((HIDWORD(qwCurrTSF) < HIDWORD(qwStartTSF)) ||
+                           ((HIDWORD(qwCurrTSF) == HIDWORD(qwStartTSF)) &&
+                            (LODWORD(qwCurrTSF) < LODWORD(qwStartTSF)))
+) {
+                               bExpired = false;
+                               break;
+                       }
+                       VNTWIFIbMeasureReport(pDevice->pMgmt,
+                                             false,
+                                             pDevice->pCurrMeasureEID,
+                                             MEASURE_MODE_LATE,
+                                             pDevice->byBasicMap,
+                                             pDevice->byCCAFraction,
+                                             pDevice->abyRPIs
+                               );
+               } else {
+                       // hardware do not support measure
+                       VNTWIFIbMeasureReport(pDevice->pMgmt,
+                                             false,
+                                             pDevice->pCurrMeasureEID,
+                                             MEASURE_MODE_INCAPABLE,
+                                             pDevice->byBasicMap,
+                                             pDevice->byCCAFraction,
+                                             pDevice->abyRPIs
+                               );
+               }
+       } while (pDevice->uNumOfMeasureEIDs != 0);
+
+       if (bExpired == false) {
+               MACvSelectPage1(pDevice->PortOffset);
+               VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, LODWORD(qwStartTSF));
+               VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, HIDWORD(qwStartTSF));
+               VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
+               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
+               MACvSelectPage0(pDevice->PortOffset);
+       } else {
+               // all measure start time expired we should complete action
+               VNTWIFIbMeasureReport(pDevice->pMgmt,
+                                     true,
+                                     NULL,
+                                     0,
+                                     pDevice->byBasicMap,
+                                     pDevice->byCCAFraction,
+                                     pDevice->abyRPIs
+                       );
+       }
+       return true;
 }
 
-
 /*
  *
  * Description:
@@ -1265,36 +1224,35 @@ CARDbStartMeasure (
  *
  * Return Value: none.
  *
--*/
+ -*/
 bool
-CARDbChannelSwitch (
-    void *pDeviceHandler,
-    unsigned char byMode,
-    unsigned char byNewChannel,
-    unsigned char byCount
-    )
+CARDbChannelSwitch(
+       void *pDeviceHandler,
+       unsigned char byMode,
+       unsigned char byNewChannel,
+       unsigned char byCount
+)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    bool bResult = true;
-
-    if (byCount == 0) {
-        bResult = set_channel(pDevice, byNewChannel);
-        VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
-        MACvSelectPage1(pDevice->PortOffset);
-        MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
-        MACvSelectPage0(pDevice->PortOffset);
-        return(bResult);
-    }
-    pDevice->byChannelSwitchCount = byCount;
-    pDevice->byNewChannel = byNewChannel;
-    pDevice->bChannelSwitch = true;
-    if (byMode == 1) {
-        bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
-    }
-    return (bResult);
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       bool bResult = true;
+
+       if (byCount == 0) {
+               bResult = set_channel(pDevice, byNewChannel);
+               VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
+               MACvSelectPage1(pDevice->PortOffset);
+               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
+               MACvSelectPage0(pDevice->PortOffset);
+               return bResult;
+       }
+       pDevice->byChannelSwitchCount = byCount;
+       pDevice->byNewChannel = byNewChannel;
+       pDevice->bChannelSwitch = true;
+       if (byMode == 1) {
+               bResult = CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
+       }
+       return bResult;
 }
 
-
 /*
  *
  * Description:
@@ -1308,53 +1266,52 @@ CARDbChannelSwitch (
  *
  * Return Value: none.
  *
--*/
+ -*/
 bool
-CARDbSetQuiet (
-    void *pDeviceHandler,
-    bool bResetQuiet,
-    unsigned char byQuietCount,
-    unsigned char byQuietPeriod,
-    unsigned short wQuietDuration,
-    unsigned short wQuietOffset
-    )
+CARDbSetQuiet(
+       void *pDeviceHandler,
+       bool bResetQuiet,
+       unsigned char byQuietCount,
+       unsigned char byQuietPeriod,
+       unsigned short wQuietDuration,
+       unsigned short wQuietOffset
+)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    unsigned int ii = 0;
-
-    if (bResetQuiet == true) {
-        MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
-        for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
-            pDevice->sQuiet[ii].bEnable = false;
-        }
-        pDevice->uQuietEnqueue = 0;
-        pDevice->bEnableFirstQuiet = false;
-        pDevice->bQuietEnable = false;
-        pDevice->byQuietStartCount = byQuietCount;
-    }
-    if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
-        pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
-        pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
-        pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
-        pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
-        pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
-        pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
-        pDevice->uQuietEnqueue++;
-        pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
-        if (pDevice->byQuietStartCount < byQuietCount) {
-            pDevice->byQuietStartCount = byQuietCount;
-        }
-    } else {
-        // we can not handle Quiet EID more
-    }
-    return (true);
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       unsigned int ii = 0;
+
+       if (bResetQuiet == true) {
+               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
+               for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
+                       pDevice->sQuiet[ii].bEnable = false;
+               }
+               pDevice->uQuietEnqueue = 0;
+               pDevice->bEnableFirstQuiet = false;
+               pDevice->bQuietEnable = false;
+               pDevice->byQuietStartCount = byQuietCount;
+       }
+       if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
+               pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
+               pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
+               pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
+               pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
+               pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
+               pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
+               pDevice->uQuietEnqueue++;
+               pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
+               if (pDevice->byQuietStartCount < byQuietCount) {
+                       pDevice->byQuietStartCount = byQuietCount;
+               }
+       } else {
+               // we can not handle Quiet EID more
+       }
+       return true;
 }
 
-
 /*
  *
  * Description:
- *    Do Quiet, It will be called by either ISR(after start) 
+ *    Do Quiet, It will be called by either ISR(after start)
  *    or VNTWIFI(before start) so we do not need a SPINLOCK
  *
  * Parameters:
@@ -1365,91 +1322,91 @@ CARDbSetQuiet (
  *
  * Return Value: none.
  *
--*/
+ -*/
 bool
-CARDbStartQuiet (
-    void *pDeviceHandler
-    )
+CARDbStartQuiet(
+       void *pDeviceHandler
+)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    unsigned int ii = 0;
-    unsigned long dwStartTime = 0xFFFFFFFF;
-    unsigned int uCurrentQuietIndex = 0;
-    unsigned long dwNextTime = 0;
-    unsigned long dwGap = 0;
-    unsigned long dwDuration = 0;
-
-    for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
-        if ((pDevice->sQuiet[ii].bEnable == true) &&
-            (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
-            dwStartTime = pDevice->sQuiet[ii].dwStartTime;
-            uCurrentQuietIndex = ii;
-        }
-    }
-    if (dwStartTime == 0xFFFFFFFF) {
-        // no more quiet
-        pDevice->bQuietEnable = false;
-        MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
-    } else {
-        if (pDevice->bQuietEnable == false) {
-            // first quiet
-            pDevice->byQuietStartCount--;
-            dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
-            dwNextTime %= pDevice->wBeaconInterval;
-            MACvSelectPage1(pDevice->PortOffset);
-            VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
-            VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
-            if (pDevice->byQuietStartCount == 0) {
-                pDevice->bEnableFirstQuiet = false;
-                MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
-            } else {
-                pDevice->bEnableFirstQuiet = true;
-            }
-            MACvSelectPage0(pDevice->PortOffset);
-        } else {
-            if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
-                // overlap with previous Quiet
-                dwGap =  pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
-                if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
-                    // return false to indicate next quiet expired, should call this function again
-                    return (false);
-                }
-                dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
-                dwGap = 0;
-            } else {
-                dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
-                dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
-            }
-            // set GAP and Next duration
-            MACvSelectPage1(pDevice->PortOffset);
-            VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
-            VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
-            MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
-            MACvSelectPage0(pDevice->PortOffset);
-        }
-        pDevice->bQuietEnable = true;
-        pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
-        pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
-        if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
-            // not period disable current quiet element
-            pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
-        } else {
-            // set next period start time
-            dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
-            dwNextTime *= pDevice->wBeaconInterval;
-            pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
-        }
-        if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
-            // decreament all time to avoid wrap around
-            for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
-                if (pDevice->sQuiet[ii].bEnable == true) {
-                    pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
-                }
-            }
-            pDevice->dwCurrentQuietEndTime -= 0x80000000;
-        }
-    }
-    return (true);
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       unsigned int ii = 0;
+       unsigned long dwStartTime = 0xFFFFFFFF;
+       unsigned int uCurrentQuietIndex = 0;
+       unsigned long dwNextTime = 0;
+       unsigned long dwGap = 0;
+       unsigned long dwDuration = 0;
+
+       for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
+               if ((pDevice->sQuiet[ii].bEnable == true) &&
+                   (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
+                       dwStartTime = pDevice->sQuiet[ii].dwStartTime;
+                       uCurrentQuietIndex = ii;
+               }
+       }
+       if (dwStartTime == 0xFFFFFFFF) {
+               // no more quiet
+               pDevice->bQuietEnable = false;
+               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
+       } else {
+               if (pDevice->bQuietEnable == false) {
+                       // first quiet
+                       pDevice->byQuietStartCount--;
+                       dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
+                       dwNextTime %= pDevice->wBeaconInterval;
+                       MACvSelectPage1(pDevice->PortOffset);
+                       VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
+                       VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
+                       if (pDevice->byQuietStartCount == 0) {
+                               pDevice->bEnableFirstQuiet = false;
+                               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
+                       } else {
+                               pDevice->bEnableFirstQuiet = true;
+                       }
+                       MACvSelectPage0(pDevice->PortOffset);
+               } else {
+                       if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
+                               // overlap with previous Quiet
+                               dwGap =  pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
+                               if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
+                                       // return false to indicate next quiet expired, should call this function again
+                                       return false;
+                               }
+                               dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
+                               dwGap = 0;
+                       } else {
+                               dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
+                               dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
+                       }
+                       // set GAP and Next duration
+                       MACvSelectPage1(pDevice->PortOffset);
+                       VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
+                       VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
+                       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
+                       MACvSelectPage0(pDevice->PortOffset);
+               }
+               pDevice->bQuietEnable = true;
+               pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
+               pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
+               if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
+                       // not period disable current quiet element
+                       pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
+               } else {
+                       // set next period start time
+                       dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
+                       dwNextTime *= pDevice->wBeaconInterval;
+                       pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
+               }
+               if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
+                       // decreament all time to avoid wrap around
+                       for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
+                               if (pDevice->sQuiet[ii].bEnable == true) {
+                                       pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
+                               }
+                       }
+                       pDevice->dwCurrentQuietEndTime -= 0x80000000;
+               }
+       }
+       return true;
 }
 
 /*
@@ -1465,28 +1422,27 @@ CARDbStartQuiet (
  *
  * Return Value: none.
  *
--*/
+ -*/
 void
-CARDvSetPowerConstraint (
-    void *pDeviceHandler,
-    unsigned char byChannel,
-    char byPower
-    )
+CARDvSetPowerConstraint(
+       void *pDeviceHandler,
+       unsigned char byChannel,
+       char byPower
+)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-
-    if (byChannel > CB_MAX_CHANNEL_24G) {
-        if (pDevice->bCountryInfo5G == true) {
-            pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
-        }
-    } else {
-        if (pDevice->bCountryInfo24G == true) {
-            pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
-        }
-    }
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+
+       if (byChannel > CB_MAX_CHANNEL_24G) {
+               if (pDevice->bCountryInfo5G == true) {
+                       pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
+               }
+       } else {
+               if (pDevice->bCountryInfo24G == true) {
+                       pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
+               }
+       }
 }
 
-
 /*
  *
  * Description:
@@ -1500,26 +1456,26 @@ CARDvSetPowerConstraint (
  *
  * Return Value: none.
  *
--*/
+ -*/
 void
-CARDvGetPowerCapability (
-    void *pDeviceHandler,
-    unsigned char *pbyMinPower,
-    unsigned char *pbyMaxPower
-    )
+CARDvGetPowerCapability(
+       void *pDeviceHandler,
+       unsigned char *pbyMinPower,
+       unsigned char *pbyMaxPower
+)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    unsigned char byDec = 0;
-
-    *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
-    byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
-    if (pDevice->byRFType == RF_UW2452) {
-        byDec *= 3;
-        byDec >>= 1;
-    } else {
-        byDec <<= 1;
-    }
-    *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       unsigned char byDec = 0;
+
+       *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
+       byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
+       if (pDevice->byRFType == RF_UW2452) {
+               byDec *= 3;
+               byDec >>= 1;
+       } else {
+               byDec <<= 1;
+       }
+       *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
 }
 
 /*
@@ -1537,58 +1493,55 @@ CARDvGetPowerCapability (
  *
  */
 char
-CARDbyGetTransmitPower (
-    void *pDeviceHandler
-    )
+CARDbyGetTransmitPower(
+       void *pDeviceHandler
+)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
 
-    return (pDevice->byCurPwrdBm);
+       return pDevice->byCurPwrdBm;
 }
 
 //xxx
 void
-CARDvSafeResetTx (
-    void *pDeviceHandler
-    )
+CARDvSafeResetTx(
+       void *pDeviceHandler
+)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    unsigned int uu;
-    PSTxDesc    pCurrTD;
-
-    // initialize TD index
-    pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
-    pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
-
-    for (uu = 0; uu < TYPE_MAXTD; uu ++)
-        pDevice->iTDUsed[uu] = 0;
-
-    for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
-        pCurrTD = &(pDevice->apTD0Rings[uu]);
-        pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
-        // init all Tx Packet pointer to NULL
-    }
-    for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
-        pCurrTD = &(pDevice->apTD1Rings[uu]);
-        pCurrTD->m_td0TD0.f1Owner = 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_AC0DMA, pDevice->PortOffset,
-                        (pDevice->td1_pool_dma));
-
-    // set MAC Beacon TX pointer
-    MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
-                        (pDevice->tx_beacon_dma));
-
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       unsigned int uu;
+       PSTxDesc    pCurrTD;
+
+       // initialize TD index
+       pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
+       pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
+
+       for (uu = 0; uu < TYPE_MAXTD; uu++)
+               pDevice->iTDUsed[uu] = 0;
+
+       for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
+               pCurrTD = &(pDevice->apTD0Rings[uu]);
+               pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
+               // init all Tx Packet pointer to NULL
+       }
+       for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
+               pCurrTD = &(pDevice->apTD1Rings[uu]);
+               pCurrTD->m_td0TD0.f1Owner = 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_AC0DMA, pDevice->PortOffset,
+                             (pDevice->td1_pool_dma));
+
+       // set MAC Beacon TX pointer
+       MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
+                                (pDevice->tx_beacon_dma));
 }
 
-
-
 /*+
  *
  * Description:
@@ -1602,55 +1555,50 @@ CARDvSafeResetTx (
  *
  * Return Value: none
  *
--*/
+ -*/
 void
-CARDvSafeResetRx (
-    void *pDeviceHandler
-    )
+CARDvSafeResetRx(
+       void *pDeviceHandler
+)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    unsigned int uu;
-    PSRxDesc    pDesc;
-
-
-
-    // initialize RD index
-    pDevice->pCurrRD[0]=&(pDevice->aRD0Ring[0]);
-    pDevice->pCurrRD[1]=&(pDevice->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 = (unsigned short)(pDevice->rx_buf_sz);
-        pDesc->m_rd0RD0.f1Owner=OWNED_BY_NIC;
-        pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->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 = (unsigned short)(pDevice->rx_buf_sz);
-        pDesc->m_rd0RD0.f1Owner=OWNED_BY_NIC;
-        pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
-    }
-
-    pDevice->cbDFCB = CB_MAX_RX_FRAG;
-    pDevice->cbFreeDFCB = pDevice->cbDFCB;
-
-    // set perPkt mode
-    MACvRx0PerPktMode(pDevice->PortOffset);
-    MACvRx1PerPktMode(pDevice->PortOffset);
-    // set MAC RD pointer
-    MACvSetCurrRx0DescAddr(pDevice->PortOffset,
-                            pDevice->rd0_pool_dma);
-
-    MACvSetCurrRx1DescAddr(pDevice->PortOffset,
-                            pDevice->rd1_pool_dma);
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       unsigned int uu;
+       PSRxDesc    pDesc;
+
+       // initialize RD index
+       pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
+       pDevice->pCurrRD[1] = &(pDevice->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 = (unsigned short)(pDevice->rx_buf_sz);
+               pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
+               pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->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 = (unsigned short)(pDevice->rx_buf_sz);
+               pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
+               pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
+       }
+
+       pDevice->cbDFCB = CB_MAX_RX_FRAG;
+       pDevice->cbFreeDFCB = pDevice->cbDFCB;
+
+       // set perPkt mode
+       MACvRx0PerPktMode(pDevice->PortOffset);
+       MACvRx1PerPktMode(pDevice->PortOffset);
+       // set MAC RD pointer
+       MACvSetCurrRx0DescAddr(pDevice->PortOffset,
+                              pDevice->rd0_pool_dma);
+
+       MACvSetCurrRx1DescAddr(pDevice->PortOffset,
+                              pDevice->rd1_pool_dma);
 }
 
-
-
-
 /*
  * Description: Get response Control frame rate in CCK mode
  *
@@ -1666,16 +1614,16 @@ CARDvSafeResetRx (
  */
 unsigned short CARDwGetCCKControlRate(void *pDeviceHandler, unsigned short wRateIdx)
 {
-    PSDevice    pDevice = (PSDevice) pDeviceHandler;
-    unsigned int ui = (unsigned int) wRateIdx;
-
-    while (ui > RATE_1M) {
-        if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
-            return (unsigned short)ui;
-        }
-        ui --;
-    }
-    return (unsigned short)RATE_1M;
+       PSDevice    pDevice = (PSDevice) pDeviceHandler;
+       unsigned int ui = (unsigned int) wRateIdx;
+
+       while (ui > RATE_1M) {
+               if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
+                       return (unsigned short)ui;
+               }
+               ui--;
+       }
+       return (unsigned short)RATE_1M;
 }
 
 /*
@@ -1691,31 +1639,30 @@ unsigned short CARDwGetCCKControlRate(void *pDeviceHandler, unsigned short wRate
  * Return Value: response Control frame rate
  *
  */
-unsigned short CARDwGetOFDMControlRate (void *pDeviceHandler, unsigned short wRateIdx)
+unsigned short CARDwGetOFDMControlRate(void *pDeviceHandler, unsigned short wRateIdx)
 {
-    PSDevice pDevice = (PSDevice) pDeviceHandler;
-    unsigned int ui = (unsigned int) wRateIdx;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", pDevice->wBasicRate);
-
-    if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
-        if (wRateIdx > RATE_24M)
-            wRateIdx = RATE_24M;
-        return wRateIdx;
-    }
-    while (ui > RATE_11M) {
-        if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate : %d\n", ui);
-            return (unsigned short)ui;
-        }
-        ui --;
-    }
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate: 6M\n");
-    return (unsigned short)RATE_24M;
+       PSDevice pDevice = (PSDevice) pDeviceHandler;
+       unsigned int ui = (unsigned int) wRateIdx;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BASIC RATE: %X\n", pDevice->wBasicRate);
+
+       if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
+               if (wRateIdx > RATE_24M)
+                       wRateIdx = RATE_24M;
+               return wRateIdx;
+       }
+       while (ui > RATE_11M) {
+               if (pDevice->wBasicRate & ((unsigned short)1 << ui)) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate : %d\n", ui);
+                       return (unsigned short)ui;
+               }
+               ui--;
+       }
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDwGetOFDMControlRate: 6M\n");
+       return (unsigned short)RATE_24M;
 }
 
-
 /*
  * Description: Set RSPINF
  *
@@ -1728,117 +1675,117 @@ unsigned short CARDwGetOFDMControlRate (void *pDeviceHandler, unsigned short wRa
  * Return Value: None.
  *
  */
-void CARDvSetRSPINF (void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
+void CARDvSetRSPINF(void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
 {
-    PSDevice pDevice = (PSDevice) pDeviceHandler;
-    unsigned char byServ = 0x00, bySignal = 0x00; //For CCK
-    unsigned short wLen = 0x0000;
-    unsigned char byTxRate, byRsvTime;             //For OFDM
-
-    //Set to Page1
-    MACvSelectPage1(pDevice->PortOffset);
-
-    //RSPINF_b_1
-    BBvCalculateParameter(pDevice,
-                         14,
-                         CARDwGetCCKControlRate((void *)pDevice, RATE_1M),
-                         PK_TYPE_11B,
-                         &wLen,
-                         &byServ,
-                         &bySignal
-    );
-
-    VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
-    ///RSPINF_b_2
-    BBvCalculateParameter(pDevice,
-                         14,
-                         CARDwGetCCKControlRate((void *)pDevice, RATE_2M),
-                         PK_TYPE_11B,
-                         &wLen,
-                         &byServ,
-                         &bySignal
-    );
-
-    VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
-    //RSPINF_b_5
-    BBvCalculateParameter(pDevice,
-                         14,
-                         CARDwGetCCKControlRate((void *)pDevice, RATE_5M),
-                         PK_TYPE_11B,
-                         &wLen,
-                         &byServ,
-                         &bySignal
-    );
-
-    VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
-    //RSPINF_b_11
-    BBvCalculateParameter(pDevice,
-                         14,
-                         CARDwGetCCKControlRate((void *)pDevice, RATE_11M),
-                         PK_TYPE_11B,
-                         &wLen,
-                         &byServ,
-                         &bySignal
-    );
-
-    VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
-    //RSPINF_a_6
-    s_vCalculateOFDMRParameter(RATE_6M,
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_9
-    s_vCalculateOFDMRParameter(RATE_9M,
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_12
-    s_vCalculateOFDMRParameter(RATE_12M,
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_18
-    s_vCalculateOFDMRParameter(RATE_18M,
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-   VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_24
-    s_vCalculateOFDMRParameter(RATE_24M,
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_36
-    s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_48
-    s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate,byRsvTime));
-    //RSPINF_a_54
-    s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate,byRsvTime));
-
-    //RSPINF_a_72
-    s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
-                              ePHYType,
-                              &byTxRate,
-                              &byRsvTime);
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate,byRsvTime));
-    //Set to Page0
-    MACvSelectPage0(pDevice->PortOffset);
+       PSDevice pDevice = (PSDevice) pDeviceHandler;
+       unsigned char byServ = 0x00, bySignal = 0x00; //For CCK
+       unsigned short wLen = 0x0000;
+       unsigned char byTxRate, byRsvTime;             //For OFDM
+
+       //Set to Page1
+       MACvSelectPage1(pDevice->PortOffset);
+
+       //RSPINF_b_1
+       BBvCalculateParameter(pDevice,
+                             14,
+                             CARDwGetCCKControlRate((void *)pDevice, RATE_1M),
+                             PK_TYPE_11B,
+                             &wLen,
+                             &byServ,
+                             &bySignal
+);
+
+       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
+       ///RSPINF_b_2
+       BBvCalculateParameter(pDevice,
+                             14,
+                             CARDwGetCCKControlRate((void *)pDevice, RATE_2M),
+                             PK_TYPE_11B,
+                             &wLen,
+                             &byServ,
+                             &bySignal
+);
+
+       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
+       //RSPINF_b_5
+       BBvCalculateParameter(pDevice,
+                             14,
+                             CARDwGetCCKControlRate((void *)pDevice, RATE_5M),
+                             PK_TYPE_11B,
+                             &wLen,
+                             &byServ,
+                             &bySignal
+);
+
+       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
+       //RSPINF_b_11
+       BBvCalculateParameter(pDevice,
+                             14,
+                             CARDwGetCCKControlRate((void *)pDevice, RATE_11M),
+                             PK_TYPE_11B,
+                             &wLen,
+                             &byServ,
+                             &bySignal
+);
+
+       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen, MAKEWORD(bySignal, byServ)));
+       //RSPINF_a_6
+       s_vCalculateOFDMRParameter(RATE_6M,
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_9
+       s_vCalculateOFDMRParameter(RATE_9M,
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_12
+       s_vCalculateOFDMRParameter(RATE_12M,
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_18
+       s_vCalculateOFDMRParameter(RATE_18M,
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_24
+       s_vCalculateOFDMRParameter(RATE_24M,
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_36
+       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_48
+       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
+       //RSPINF_a_54
+       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
+
+       //RSPINF_a_72
+       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
+                                  ePHYType,
+                                  &byTxRate,
+                                  &byRsvTime);
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
+       //Set to Page0
+       MACvSelectPage0(pDevice->PortOffset);
 }
 
 /*
@@ -1853,87 +1800,83 @@ void CARDvSetRSPINF (void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
  * Return Value: None.
  *
  */
-void vUpdateIFS (void *pDeviceHandler)
+void vUpdateIFS(void *pDeviceHandler)
 {
-    //Set SIFS, DIFS, EIFS, SlotTime, CwMin
-    PSDevice pDevice = (PSDevice) pDeviceHandler;
-
-    unsigned char byMaxMin = 0;
-    if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a
-        pDevice->uSlot = C_SLOT_SHORT;
-        pDevice->uSIFS = C_SIFS_A;
-        pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
-        pDevice->uCwMin = C_CWMIN_A;
-        byMaxMin = 4;
-    }
-    else if (pDevice->byPacketType==PK_TYPE_11B) {//0000 0001 0000 0000,11b
-        pDevice->uSlot = C_SLOT_LONG;
-        pDevice->uSIFS = C_SIFS_BG;
-        pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
-           pDevice->uCwMin = C_CWMIN_B;
-        byMaxMin = 5;
-    }
-    else { // PK_TYPE_11GA & PK_TYPE_11GB
-        pDevice->uSIFS = C_SIFS_BG;
-        if (pDevice->bShortSlotTime) {
-            pDevice->uSlot = C_SLOT_SHORT;
-        } else {
-               pDevice->uSlot = C_SLOT_LONG;
-           }
-           pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
-        if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
-            pDevice->uCwMin = C_CWMIN_A;
-            byMaxMin = 4;
-        }
-        else {
-            pDevice->uCwMin = C_CWMIN_B;
-            byMaxMin = 5;
-        }
-    }
-
-    pDevice->uCwMax = C_CWMAX;
-    pDevice->uEIFS = C_EIFS;
-    if (pDevice->byRFType == RF_RFMD2959) {
-        // bcs TX_PE will reserve 3 us
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
-    } else {
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
-    }
-    VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
-    VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
-    byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
-    VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
+       //Set SIFS, DIFS, EIFS, SlotTime, CwMin
+       PSDevice pDevice = (PSDevice) pDeviceHandler;
+
+       unsigned char byMaxMin = 0;
+       if (pDevice->byPacketType == PK_TYPE_11A) {//0000 0000 0000 0000,11a
+               pDevice->uSlot = C_SLOT_SHORT;
+               pDevice->uSIFS = C_SIFS_A;
+               pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
+               pDevice->uCwMin = C_CWMIN_A;
+               byMaxMin = 4;
+       } else if (pDevice->byPacketType == PK_TYPE_11B) {//0000 0001 0000 0000,11b
+               pDevice->uSlot = C_SLOT_LONG;
+               pDevice->uSIFS = C_SIFS_BG;
+               pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
+               pDevice->uCwMin = C_CWMIN_B;
+               byMaxMin = 5;
+       } else { // PK_TYPE_11GA & PK_TYPE_11GB
+               pDevice->uSIFS = C_SIFS_BG;
+               if (pDevice->bShortSlotTime) {
+                       pDevice->uSlot = C_SLOT_SHORT;
+               } else {
+                       pDevice->uSlot = C_SLOT_LONG;
+               }
+               pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
+               if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
+                       pDevice->uCwMin = C_CWMIN_A;
+                       byMaxMin = 4;
+               } else {
+                       pDevice->uCwMin = C_CWMIN_B;
+                       byMaxMin = 5;
+               }
+       }
+
+       pDevice->uCwMax = C_CWMAX;
+       pDevice->uEIFS = C_EIFS;
+       if (pDevice->byRFType == RF_RFMD2959) {
+               // bcs TX_PE will reserve 3 us
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
+       } else {
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
+       }
+       VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
+       VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
+       byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
+       VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
 }
 
-void CARDvUpdateBasicTopRate (void *pDeviceHandler)
+void CARDvUpdateBasicTopRate(void *pDeviceHandler)
 {
-    PSDevice pDevice = (PSDevice) pDeviceHandler;
-    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->wBasicRate) & ((unsigned short)(1<<ii)) ) {
-             byTopOFDM = ii;
-             break;
-         }
-     }
-     pDevice->byTopOFDMBasicRate = byTopOFDM;
-
-     for (ii = RATE_11M;; ii --) {
-         if ( (pDevice->wBasicRate) & ((unsigned short)(1<<ii)) ) {
-             byTopCCK = ii;
-             break;
-         }
-         if (ii == RATE_1M)
-            break;
-     }
-     pDevice->byTopCCKBasicRate = byTopCCK;
+       PSDevice pDevice = (PSDevice) pDeviceHandler;
+       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->wBasicRate) & ((unsigned short)(1<<ii))) {
+                       byTopOFDM = ii;
+                       break;
+               }
+       }
+       pDevice->byTopOFDMBasicRate = byTopOFDM;
+
+       for (ii = RATE_11M;; ii--) {
+               if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) {
+                       byTopCCK = ii;
+                       break;
+               }
+               if (ii == RATE_1M)
+                       break;
+       }
+       pDevice->byTopCCKBasicRate = byTopCCK;
 }
 
-
 /*
  * Description: Set NIC Tx Basic Rate
  *
@@ -1947,44 +1890,42 @@ void CARDvUpdateBasicTopRate (void *pDeviceHandler)
  * Return Value: true if succeeded; false if failed.
  *
  */
-bool CARDbAddBasicRate (void *pDeviceHandler, unsigned short wRateIdx)
+bool CARDbAddBasicRate(void *pDeviceHandler, unsigned short wRateIdx)
 {
-    PSDevice pDevice = (PSDevice) pDeviceHandler;
-    unsigned short wRate = (unsigned short)(1<<wRateIdx);
+       PSDevice pDevice = (PSDevice) pDeviceHandler;
+       unsigned short wRate = (unsigned short)(1<<wRateIdx);
 
-    pDevice->wBasicRate |= wRate;
+       pDevice->wBasicRate |= wRate;
 
-    //Determines the highest basic rate.
-    CARDvUpdateBasicTopRate((void *)pDevice);
+       //Determines the highest basic rate.
+       CARDvUpdateBasicTopRate((void *)pDevice);
 
-    return(true);
+       return true;
 }
 
-bool CARDbIsOFDMinBasicRate (void *pDeviceHandler)
+bool CARDbIsOFDMinBasicRate(void *pDeviceHandler)
 {
-    PSDevice pDevice = (PSDevice) pDeviceHandler;
-    int ii;
-
-    for (ii = RATE_54M; ii >= RATE_6M; ii --) {
-        if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii)))
-            return true;
-    }
-    return false;
+       PSDevice pDevice = (PSDevice)pDeviceHandler;
+       int ii;
+
+       for (ii = RATE_54M; ii >= RATE_6M; ii--) {
+               if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii)))
+                       return true;
+       }
+       return false;
 }
 
-unsigned char CARDbyGetPktType (void *pDeviceHandler)
+unsigned char CARDbyGetPktType(void *pDeviceHandler)
 {
-    PSDevice pDevice = (PSDevice) pDeviceHandler;
-
-    if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
-        return (unsigned char)pDevice->byBBType;
-    }
-    else if (CARDbIsOFDMinBasicRate((void *)pDevice)) {
-        return PK_TYPE_11GA;
-    }
-    else {
-       return PK_TYPE_11GB;
-    }
+       PSDevice pDevice = (PSDevice) pDeviceHandler;
+
+       if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
+               return (unsigned char)pDevice->byBBType;
+       } else if (CARDbIsOFDMinBasicRate((void *)pDevice)) {
+               return PK_TYPE_11GA;
+       } else {
+               return PK_TYPE_11GB;
+       }
 }
 
 /*
@@ -2000,23 +1941,22 @@ unsigned char CARDbyGetPktType (void *pDeviceHandler)
  * Return Value: none
  *
  */
-void CARDvSetLoopbackMode (unsigned long dwIoBase, unsigned short wLoopbackMode)
+void CARDvSetLoopbackMode(unsigned long dwIoBase, unsigned short wLoopbackMode)
 {
-    switch(wLoopbackMode) {
-    case CARD_LB_NONE:
-    case CARD_LB_MAC:
-    case CARD_LB_PHY:
-        break;
-    default:
-        ASSERT(false);
-        break;
-    }
-    // set MAC loopback
-    MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
-    // set Baseband loopback
+       switch (wLoopbackMode) {
+       case CARD_LB_NONE:
+       case CARD_LB_MAC:
+       case CARD_LB_PHY:
+               break;
+       default:
+               ASSERT(false);
+               break;
+       }
+       // set MAC loopback
+       MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
+       // set Baseband loopback
 }
 
-
 /*
  * Description: Software Reset NIC
  *
@@ -2029,18 +1969,17 @@ void CARDvSetLoopbackMode (unsigned long dwIoBase, unsigned short wLoopbackMode)
  * Return Value: none
  *
  */
-bool CARDbSoftwareReset (void *pDeviceHandler)
+bool CARDbSoftwareReset(void *pDeviceHandler)
 {
-    PSDevice pDevice = (PSDevice) pDeviceHandler;
+       PSDevice pDevice = (PSDevice) pDeviceHandler;
 
-    // reset MAC
-    if (!MACbSafeSoftwareReset(pDevice->PortOffset))
-        return false;
+       // reset MAC
+       if (!MACbSafeSoftwareReset(pDevice->PortOffset))
+               return false;
 
-    return true;
+       return true;
 }
 
-
 /*
  * Description: Calculate TSF offset of two TSF input
  *              Get TSF Offset from RxBCN's TSF and local TSF
@@ -2056,30 +1995,28 @@ bool CARDbSoftwareReset (void *pDeviceHandler)
  * Return Value: TSF Offset value
  *
  */
-QWORD CARDqGetTSFOffset (unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2)
+QWORD CARDqGetTSFOffset(unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2)
 {
-    QWORD   qwTSFOffset;
-    unsigned short wRxBcnTSFOffst= 0;
-
-    HIDWORD(qwTSFOffset) = 0;
-    LODWORD(qwTSFOffset) = 0;
-    wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
-    (qwTSF2).u.dwLowDword += (unsigned long)(wRxBcnTSFOffst);
-    if ((qwTSF2).u.dwLowDword < (unsigned long)(wRxBcnTSFOffst)) {
-        (qwTSF2).u.dwHighDword++;
-    }
-    LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
-    if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
-        // if borrow needed
-        HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1 ;
-    }
-    else {
-        HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
-    };
-    return (qwTSFOffset);
+       QWORD   qwTSFOffset;
+       unsigned short wRxBcnTSFOffst = 0;
+
+       HIDWORD(qwTSFOffset) = 0;
+       LODWORD(qwTSFOffset) = 0;
+       wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
+       (qwTSF2).u.dwLowDword += (unsigned long)(wRxBcnTSFOffst);
+       if ((qwTSF2).u.dwLowDword < (unsigned long)(wRxBcnTSFOffst)) {
+               (qwTSF2).u.dwHighDword++;
+       }
+       LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
+       if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
+               // if borrow needed
+               HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1;
+       } else {
+               HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
+       };
+       return qwTSFOffset;
 }
 
-
 /*
  * Description: Read NIC TSF counter
  *              Get local TSF counter
@@ -2093,26 +2030,25 @@ QWORD CARDqGetTSFOffset (unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2)
  * Return Value: true if success; otherwise false
  *
  */
-bool CARDbGetCurrentTSF (unsigned long dwIoBase, PQWORD pqwCurrTSF)
+bool CARDbGetCurrentTSF(unsigned long dwIoBase, PQWORD pqwCurrTSF)
 {
-    unsigned short ww;
-    unsigned char byData;
-
-    MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
-        if ( !(byData & TFTCTL_TSFCNTRRD))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT)
-        return(false);
-    VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, &LODWORD(*pqwCurrTSF));
-    VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, &HIDWORD(*pqwCurrTSF));
-
-    return(true);
+       unsigned short ww;
+       unsigned char byData;
+
+       MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
+               if (!(byData & TFTCTL_TSFCNTRRD))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT)
+               return false;
+       VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, &LODWORD(*pqwCurrTSF));
+       VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, &HIDWORD(*pqwCurrTSF));
+
+       return true;
 }
 
-
 /*
  * Description: Read NIC TSF counter
  *              Get NEXTTBTT from adjusted TSF and Beacon Interval
@@ -2127,36 +2063,34 @@ bool CARDbGetCurrentTSF (unsigned long dwIoBase, PQWORD pqwCurrTSF)
  * Return Value: TSF value of next Beacon
  *
  */
-QWORD CARDqGetNextTBTT (QWORD qwTSF, unsigned short wBeaconInterval)
+QWORD CARDqGetNextTBTT(QWORD qwTSF, unsigned short wBeaconInterval)
 {
-
-    unsigned int uLowNextTBTT;
-    unsigned int uHighRemain, uLowRemain;
-    unsigned int uBeaconInterval;
-
-    uBeaconInterval = wBeaconInterval * 1024;
-    // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
-    uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
-    // low dword (mod) bcn
-    uLowRemain = (uLowNextTBTT) % uBeaconInterval;
+       unsigned int uLowNextTBTT;
+       unsigned int uHighRemain, uLowRemain;
+       unsigned int uBeaconInterval;
+
+       uBeaconInterval = wBeaconInterval * 1024;
+       // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
+       uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
+       // low dword (mod) bcn
+       uLowRemain = (uLowNextTBTT) % uBeaconInterval;
 //    uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
 //                  % uBeaconInterval;
-    // high dword (mod) bcn
-    uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwTSF))
-                  % uBeaconInterval;
-    uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
-    uLowRemain = uBeaconInterval - uLowRemain;
+       // high dword (mod) bcn
+       uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwTSF))
+               % uBeaconInterval;
+       uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
+       uLowRemain = uBeaconInterval - uLowRemain;
 
-    // check if carry when add one beacon interval
-    if ((~uLowNextTBTT) < uLowRemain)
-        HIDWORD(qwTSF) ++ ;
+       // check if carry when add one beacon interval
+       if ((~uLowNextTBTT) < uLowRemain)
+               HIDWORD(qwTSF)++;
 
-    LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
+       LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
 
-    return (qwTSF);
+       return qwTSF;
 }
 
-
 /*
  * Description: Set NIC TSF counter for first Beacon time
  *              Get NEXTTBTT from adjusted TSF and Beacon Interval
@@ -2171,24 +2105,22 @@ QWORD CARDqGetNextTBTT (QWORD qwTSF, unsigned short wBeaconInterval)
  * Return Value: none
  *
  */
-void CARDvSetFirstNextTBTT (unsigned long dwIoBase, unsigned short wBeaconInterval)
+void CARDvSetFirstNextTBTT(unsigned long dwIoBase, unsigned short wBeaconInterval)
 {
-
-    QWORD   qwNextTBTT;
-
-    HIDWORD(qwNextTBTT) = 0;
-    LODWORD(qwNextTBTT) = 0;
-    CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
-    qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
-    // Set NextTBTT
-    VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
-    VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
-    MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
-    //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:First Next TBTT[%8xh:%8xh] \n", HIDWORD(qwNextTBTT), LODWORD(qwNextTBTT));
-    return;
+       QWORD   qwNextTBTT;
+
+       HIDWORD(qwNextTBTT) = 0;
+       LODWORD(qwNextTBTT) = 0;
+       CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
+       qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
+       // Set NextTBTT
+       VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
+       VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
+       MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
+       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:First Next TBTT[%8xh:%8xh] \n", HIDWORD(qwNextTBTT), LODWORD(qwNextTBTT));
+       return;
 }
 
-
 /*
  * Description: Sync NIC TSF counter for Beacon time
  *              Get NEXTTBTT and write to HW
@@ -2204,23 +2136,15 @@ void CARDvSetFirstNextTBTT (unsigned long dwIoBase, unsigned short wBeaconInterv
  * Return Value: none
  *
  */
-void CARDvUpdateNextTBTT (unsigned long dwIoBase, QWORD qwTSF, unsigned short wBeaconInterval)
+void CARDvUpdateNextTBTT(unsigned long dwIoBase, QWORD qwTSF, unsigned short wBeaconInterval)
 {
-
-    qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
-    // Set NextTBTT
-    VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwTSF));
-    VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwTSF));
-    MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:Update Next TBTT[%8xh:%8xh] \n",
-                   (unsigned int) HIDWORD(qwTSF), (unsigned int) LODWORD(qwTSF));
-
-    return;
+       qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
+       // Set NextTBTT
+       VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwTSF));
+       VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwTSF));
+       MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Card:Update Next TBTT[%8xh:%8xh] \n",
+               (unsigned int) HIDWORD(qwTSF), (unsigned int) LODWORD(qwTSF));
+
+       return;
 }
-
-
-
-
-
-
-
index e0836e1d5116aec0e60c3449145a5eb56cc5b775..ac6e2b4d0fd033bdd02373761523267636c8b3cd 100644 (file)
@@ -41,7 +41,6 @@
 #define CARD_LB_MAC             MAKEWORD(MAC_LB_INTERNAL, 0)   // PHY must ISO, avoid MAC loopback packet go out
 #define CARD_LB_PHY             MAKEWORD(MAC_LB_EXT, 0)
 
-
 #define DEFAULT_MSDU_LIFETIME           512  // ms
 #define DEFAULT_MSDU_LIFETIME_RES_64us  8000 // 64us
 
 #define CB_MAX_CHANNEL          (CB_MAX_CHANNEL_24G+CB_MAX_CHANNEL_5G)
 
 typedef enum _CARD_PHY_TYPE {
-    PHY_TYPE_AUTO,
-    PHY_TYPE_11B,
-    PHY_TYPE_11G,
-    PHY_TYPE_11A
+       PHY_TYPE_AUTO,
+       PHY_TYPE_11B,
+       PHY_TYPE_11G,
+       PHY_TYPE_11A
 } CARD_PHY_TYPE, *PCARD_PHY_TYPE;
 
 typedef enum _CARD_PKT_TYPE {
-    PKT_TYPE_802_11_BCN,
-    PKT_TYPE_802_11_MNG,
-    PKT_TYPE_802_11_DATA,
-    PKT_TYPE_802_11_ALL
+       PKT_TYPE_802_11_BCN,
+       PKT_TYPE_802_11_MNG,
+       PKT_TYPE_802_11_DATA,
+       PKT_TYPE_802_11_ALL
 } CARD_PKT_TYPE, *PCARD_PKT_TYPE;
 
 typedef enum _CARD_STATUS_TYPE {
-    CARD_STATUS_MEDIA_CONNECT,
-    CARD_STATUS_MEDIA_DISCONNECT,
-    CARD_STATUS_PMKID
+       CARD_STATUS_MEDIA_CONNECT,
+       CARD_STATUS_MEDIA_DISCONNECT,
+       CARD_STATUS_PMKID
 } CARD_STATUS_TYPE, *PCARD_STATUS_TYPE;
 
 typedef enum _CARD_OP_MODE {
-    OP_MODE_INFRASTRUCTURE,
-    OP_MODE_ADHOC,
-    OP_MODE_AP,
-    OP_MODE_UNKNOWN
+       OP_MODE_INFRASTRUCTURE,
+       OP_MODE_ADHOC,
+       OP_MODE_AP,
+       OP_MODE_UNKNOWN
 } CARD_OP_MODE, *PCARD_OP_MODE;
 
-
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
@@ -119,80 +116,76 @@ bool CARDbSetBSSID(void *pDeviceHandler, unsigned char *pbyBSSID, CARD_OP_MODE e
 
 bool
 CARDbPowerDown(
-    void *pDeviceHandler
-    );
+       void *pDeviceHandler
+);
 
 bool CARDbSetTxDataRate(
-    void *pDeviceHandler,
-    unsigned short wDataRate
-    );
-
+       void *pDeviceHandler,
+       unsigned short wDataRate
+);
 
-bool CARDbRemoveKey (void *pDeviceHandler, unsigned char *pbyBSSID);
+bool CARDbRemoveKey(void *pDeviceHandler, unsigned char *pbyBSSID);
 
 bool
-CARDbAdd_PMKID_Candidate (
-    void *pDeviceHandler,
-    unsigned char *pbyBSSID,
-    bool bRSNCapExist,
-    unsigned short wRSNCap
-    );
+CARDbAdd_PMKID_Candidate(
+       void *pDeviceHandler,
+       unsigned char *pbyBSSID,
+       bool bRSNCapExist,
+       unsigned short wRSNCap
+);
 
 void *
-CARDpGetCurrentAddress (
-    void *pDeviceHandler
-    );
+CARDpGetCurrentAddress(
+       void *pDeviceHandler
+);
 
 bool
-CARDbStartMeasure (
-    void *pDeviceHandler,
-    void *pvMeasureEIDs,
-    unsigned int uNumOfMeasureEIDs
-    );
+CARDbStartMeasure(
+       void *pDeviceHandler,
+       void *pvMeasureEIDs,
+       unsigned int uNumOfMeasureEIDs
+);
 
 bool
-CARDbChannelSwitch (
-    void *pDeviceHandler,
-    unsigned char byMode,
-    unsigned char byNewChannel,
-    unsigned char byCount
-    );
+CARDbChannelSwitch(
+       void *pDeviceHandler,
+       unsigned char byMode,
+       unsigned char byNewChannel,
+       unsigned char byCount
+);
 
 bool
-CARDbSetQuiet (
-    void *pDeviceHandler,
-    bool bResetQuiet,
-    unsigned char byQuietCount,
-    unsigned char byQuietPeriod,
-    unsigned short wQuietDuration,
-    unsigned short wQuietOffset
-    );
+CARDbSetQuiet(
+       void *pDeviceHandler,
+       bool bResetQuiet,
+       unsigned char byQuietCount,
+       unsigned char byQuietPeriod,
+       unsigned short wQuietDuration,
+       unsigned short wQuietOffset
+);
 
 bool
-CARDbStartQuiet (
-    void *pDeviceHandler
-    );
+CARDbStartQuiet(
+       void *pDeviceHandler
+);
 
 void
-CARDvSetPowerConstraint (
-    void *pDeviceHandler,
-    unsigned char byChannel,
-    char byPower
-    );
+CARDvSetPowerConstraint(
+       void *pDeviceHandler,
+       unsigned char byChannel,
+       char byPower
+);
 
 void
-CARDvGetPowerCapability (
-    void *pDeviceHandler,
-    unsigned char *pbyMinPower,
-    unsigned char *pbyMaxPower
-    );
+CARDvGetPowerCapability(
+       void *pDeviceHandler,
+       unsigned char *pbyMinPower,
+       unsigned char *pbyMaxPower
+);
 
 char
-CARDbyGetTransmitPower (
-    void *pDeviceHandler
-    );
+CARDbyGetTransmitPower(
+       void *pDeviceHandler
+);
 
 #endif // __CARD_H__
-
-
-
index aa76e39a46f49e8aed182e8994b5fc8bf059b3d5..ba9481fa654f137e0b6dd54e746174ad6cc2ac70 100644 (file)
@@ -37,63 +37,63 @@ static int msglevel = MSG_LEVEL_INFO;
 
 static SChannelTblElement sChannelTbl[CARD_MAX_CHANNEL_TBL + 1] =
 {
-  {0,   0,    false,    0},
-  {1,   2412, true,     0},
-  {2,   2417, true,     0},
-  {3,   2422, true,     0},
-  {4,   2427, true,     0},
-  {5,   2432, true,     0},
-  {6,   2437, true,     0},
-  {7,   2442, true,     0},
-  {8,   2447, true,     0},
-  {9,   2452, true,     0},
-  {10,  2457, true,     0},
-  {11,  2462, true,     0},
-  {12,  2467, true,     0},
-  {13,  2472, true,     0},
-  {14,  2484, true,     0},
-  {183, 4915, true,     0},
-  {184, 4920, true,     0},
-  {185, 4925, true,     0},
-  {187, 4935, true,     0},
-  {188, 4940, true,     0},
-  {189, 4945, true,     0},
-  {192, 4960, true,     0},
-  {196, 4980, true,     0},
-  {7,   5035, true,     0},
-  {8,   5040, true,     0},
-  {9,   5045, true,     0},
-  {11,  5055, true,     0},
-  {12,  5060, true,     0},
-  {16,  5080, true,     0},
-  {34,  5170, true,     0},
-  {36,  5180, true,     0},
-  {38,  5190, true,     0},
-  {40,  5200, true,     0},
-  {42,  5210, true,     0},
-  {44,  5220, true,     0},
-  {46,  5230, true,     0},
-  {48,  5240, true,     0},
-  {52,  5260, true,     0},
-  {56,  5280, true,     0},
-  {60,  5300, true,     0},
-  {64,  5320, true,     0},
-  {100, 5500, true,     0},
-  {104, 5520, true,     0},
-  {108, 5540, true,     0},
-  {112, 5560, true,     0},
-  {116, 5580, true,     0},
-  {120, 5600, true,     0},
-  {124, 5620, true,     0},
-  {128, 5640, true,     0},
-  {132, 5660, true,     0},
-  {136, 5680, true,     0},
-  {140, 5700, true,     0},
-  {149, 5745, true,     0},
-  {153, 5765, true,     0},
-  {157, 5785, true,     0},
-  {161, 5805, true,     0},
-  {165, 5825, true,     0}
+       {0,   0,    false,    0},
+       {1,   2412, true,     0},
+       {2,   2417, true,     0},
+       {3,   2422, true,     0},
+       {4,   2427, true,     0},
+       {5,   2432, true,     0},
+       {6,   2437, true,     0},
+       {7,   2442, true,     0},
+       {8,   2447, true,     0},
+       {9,   2452, true,     0},
+       {10,  2457, true,     0},
+       {11,  2462, true,     0},
+       {12,  2467, true,     0},
+       {13,  2472, true,     0},
+       {14,  2484, true,     0},
+       {183, 4915, true,     0},
+       {184, 4920, true,     0},
+       {185, 4925, true,     0},
+       {187, 4935, true,     0},
+       {188, 4940, true,     0},
+       {189, 4945, true,     0},
+       {192, 4960, true,     0},
+       {196, 4980, true,     0},
+       {7,   5035, true,     0},
+       {8,   5040, true,     0},
+       {9,   5045, true,     0},
+       {11,  5055, true,     0},
+       {12,  5060, true,     0},
+       {16,  5080, true,     0},
+       {34,  5170, true,     0},
+       {36,  5180, true,     0},
+       {38,  5190, true,     0},
+       {40,  5200, true,     0},
+       {42,  5210, true,     0},
+       {44,  5220, true,     0},
+       {46,  5230, true,     0},
+       {48,  5240, true,     0},
+       {52,  5260, true,     0},
+       {56,  5280, true,     0},
+       {60,  5300, true,     0},
+       {64,  5320, true,     0},
+       {100, 5500, true,     0},
+       {104, 5520, true,     0},
+       {108, 5540, true,     0},
+       {112, 5560, true,     0},
+       {116, 5580, true,     0},
+       {120, 5600, true,     0},
+       {124, 5620, true,     0},
+       {128, 5640, true,     0},
+       {132, 5660, true,     0},
+       {136, 5680, true,     0},
+       {140, 5700, true,     0},
+       {149, 5745, true,     0},
+       {153, 5765, true,     0},
+       {157, 5785, true,     0},
+       {161, 5805, true,     0},
+       {165, 5825, true,     0}
 };
 
 /************************************************************************
@@ -112,244 +112,244 @@ static struct
  ************************************************************************/
 /* Country          Available channels, ended with 0                    */
 /*                                              1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  */
-{CCODE_FCC,                     {'U','S'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_TELEC,                   {'J','P'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  1,  0,  0,  1,  0,  1,  1,  0,  1,  0,  0,  1,  1,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0, 23,  0,  0, 23,  0, 23, 23,  0, 23,  0,  0, 23, 23, 23,  0, 23,  0, 23,  0, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_ETSI,                    {'E','U'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_RESV3,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RESV4,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RESV5,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RESV6,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RESV7,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RESV8,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RESV9,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RESVa,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RESVb,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RESVc,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RESVd,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RESVe,                   {' ',' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_ALLBAND,                 {' ',' '},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_ALBANIA,                 {'A','L'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_ALGERIA,                 {'D','Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_ARGENTINA,               {'A','R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17, 17, 17,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30,  0}  },
-{CCODE_ARMENIA,                 {'A','M'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18, 18, 18, 18, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_AUSTRALIA,               {'A','U'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_AUSTRIA,                 {'A','T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 15,  0, 15,  0, 15,  0, 15,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_AZERBAIJAN,              {'A','Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18, 18, 18, 18, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_BAHRAIN,                 {'B','H'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_BELARUS,                 {'B','Y'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_BELGIUM,                 {'B','E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_BELIZE,                  {'B','Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_BOLIVIA,                 {'B','O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_BRAZIL,                  {'B','R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_BRUNEI_DARUSSALAM,       {'B','N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_BULGARIA,                {'B','G'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23, 23, 23,  0,  0, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,  0,  0,  0,  0,  0}  },
-{CCODE_CANADA,                  {'C','A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_CHILE,                   {'C','L'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17, 17, 17, 17, 17}  },
-{CCODE_CHINA,                   {'C','N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_COLOMBIA,                {'C','O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_COSTA_RICA,              {'C','R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_CROATIA,                 {'H','R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_CYPRUS,                  {'C','Y'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_CZECH,                   {'C','Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_DENMARK,                 {'D','K'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_DOMINICAN_REPUBLIC,      {'D','O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_ECUADOR,                 {'E','C'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_EGYPT,                   {'E','G'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_EL_SALVADOR,             {'S','V'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_ESTONIA,                 {'E','E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_FINLAND,                 {'F','I'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_FRANCE,                  {'F','R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_GERMANY,                 {'D','E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_GREECE,                  {'G','R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_GEORGIA,                 {'G','E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18, 18, 18, 18, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_GUATEMALA,               {'G','T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_HONDURAS,                {'H','N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_HONG_KONG,               {'H','K'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_HUNGARY,                 {'H','U'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_ICELAND,                 {'I','S'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_INDIA,                   {'I','N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_INDONESIA,               {'I','D'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_IRAN,                    {'I','R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_IRELAND,                 {'I','E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_ITALY,                   {'I','T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_ISRAEL,                  {'I','L'},  {   0,  0,  0,  0,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_JAPAN,                   {'J','P'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_JORDAN,                  {'J','O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_KAZAKHSTAN,              {'K','Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_KUWAIT,                  {'K','W'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_LATVIA,                  {'L','V'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_LEBANON,                 {'L','B'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_LEICHTENSTEIN,           {'L','I'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_LITHUANIA,               {'L','T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_LUXEMBURG,               {'L','U'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_MACAU,                   {'M','O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_MACEDONIA,               {'M','K'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_MALTA,                   {'M','T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
-                                         ,  {  23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16,  0, 16,  0, 16,  0, 16, 16, 16, 16, 16,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16, 16, 16, 16,  0}  },
-{CCODE_MALAYSIA,                {'M','Y'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_MEXICO,                  {'M','X'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_MONACO,                  {'M','C'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18, 18, 18, 18, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_MOROCCO,                 {'M','A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_NETHERLANDS,             {'N','L'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_NEW_ZEALAND,             {'N','Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_NORTH_KOREA,             {'K','P'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23, 23, 23, 23,  0}  },
-{CCODE_NORWAY,                  {'N','O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_OMAN,                    {'O','M'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_PAKISTAN,                {'P','K'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_PANAMA,                  {'P','A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_PERU,                    {'P','E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_PHILIPPINES,             {'P','H'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_POLAND,                  {'P','L'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_PORTUGAL,                {'P','T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_PUERTO_RICO,             {'P','R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_QATAR,                   {'Q','A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_ROMANIA,                 {'R','O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_RUSSIA,                  {'R','U'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_SAUDI_ARABIA,            {'S','A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_SINGAPORE,               {'S','G'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20, 20, 20, 20, 20}  },
-{CCODE_SLOVAKIA,                {'S','K'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
-                                         ,  {  23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16,  0, 16,  0, 16,  0, 16, 16, 16, 16, 16,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16, 16, 16, 16,  0}  },
-{CCODE_SLOVENIA,                {'S','I'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_SOUTH_AFRICA,            {'Z','A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_SOUTH_KOREA,             {'K','R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23, 23, 23, 23,  0}  },
-{CCODE_SPAIN,                   {'E','S'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
-                                         ,  {  23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16,  0, 16,  0, 16,  0, 16, 16, 16, 16, 16,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16, 16, 16, 16,  0}  },
-{CCODE_SWEDEN,                  {'S','E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_SWITZERLAND,             {'C','H'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_SYRIA,                   {'S','Y'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_TAIWAN,                  {'T','W'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17, 17, 17,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30,  0}  },
-{CCODE_THAILAND,                {'T','H'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23, 23, 23, 23,  0}  },
-{CCODE_TRINIDAD_TOBAGO,         {'T','T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18, 18, 18, 18, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_TUNISIA,                 {'T','N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_TURKEY,                  {'T','R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_UK,                      {'G','B'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
-{CCODE_UKRAINE,                 {'U','A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_UNITED_ARAB_EMIRATES,    {'A','E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_UNITED_STATES,           {'U','S'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
-                                         ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
-{CCODE_URUGUAY,                 {'U','Y'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23, 23, 23, 23,  0}  },
-{CCODE_UZBEKISTAN,              {'U','Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_VENEZUELA,               {'V','E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
-                                         ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23, 23, 23, 23,  0}  },
-{CCODE_VIETNAM,                 {'V','N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_YEMEN,                   {'Y','E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_ZIMBABWE,                {'Z','W'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_JAPAN_W52_W53,           {'J','J'},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
-{CCODE_MAX,                     {'U','N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1}
-                                         ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  }
+       {CCODE_FCC,                     {'U' , 'S'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_TELEC,                   {'J' , 'P'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  1,  0,  0,  1,  0,  1,  1,  0,  1,  0,  0,  1,  1,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0, 23,  0,  0, 23,  0, 23, 23,  0, 23,  0,  0, 23, 23, 23,  0, 23,  0, 23,  0, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_ETSI,                    {'E' , 'U'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_RESV3,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RESV4,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RESV5,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RESV6,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RESV7,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RESV8,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RESV9,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RESVa,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RESVb,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RESVc,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RESVd,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RESVe,                   {' ' , ' '},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_ALLBAND,                 {' ' , ' '},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_ALBANIA,                 {'A' , 'L'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_ALGERIA,                 {'D' , 'Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_ARGENTINA,               {'A' , 'R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17, 17, 17,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30,  0}  },
+       {CCODE_ARMENIA,                 {'A' , 'M'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18, 18, 18, 18, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_AUSTRALIA,               {'A' , 'U'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_AUSTRIA,                 {'A' , 'T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 15,  0, 15,  0, 15,  0, 15,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_AZERBAIJAN,              {'A' , 'Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18, 18, 18, 18, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_BAHRAIN,                 {'B' , 'H'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_BELARUS,                 {'B' , 'Y'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_BELGIUM,                 {'B' , 'E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_BELIZE,                  {'B' , 'Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_BOLIVIA,                 {'B' , 'O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_BRAZIL,                  {'B' , 'R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_BRUNEI_DARUSSALAM,       {'B' , 'N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_BULGARIA,                {'B' , 'G'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23, 23, 23,  0,  0, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,  0,  0,  0,  0,  0}  },
+       {CCODE_CANADA,                  {'C' , 'A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_CHILE,                   {'C' , 'L'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17, 17, 17, 17, 17}  },
+       {CCODE_CHINA,                   {'C' , 'N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_COLOMBIA,                {'C' , 'O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_COSTA_RICA,              {'C' , 'R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_CROATIA,                 {'H' , 'R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_CYPRUS,                  {'C' , 'Y'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_CZECH,                   {'C' , 'Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_DENMARK,                 {'D' , 'K'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_DOMINICAN_REPUBLIC,      {'D' , 'O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_ECUADOR,                 {'E' , 'C'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_EGYPT,                   {'E' , 'G'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_EL_SALVADOR,             {'S' , 'V'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_ESTONIA,                 {'E' , 'E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_FINLAND,                 {'F' , 'I'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_FRANCE,                  {'F' , 'R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_GERMANY,                 {'D' , 'E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_GREECE,                  {'G' , 'R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_GEORGIA,                 {'G' , 'E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18, 18, 18, 18, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_GUATEMALA,               {'G' , 'T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_HONDURAS,                {'H' , 'N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_HONG_KONG,               {'H' , 'K'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_HUNGARY,                 {'H' , 'U'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_ICELAND,                 {'I' , 'S'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_INDIA,                   {'I' , 'N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_INDONESIA,               {'I' , 'D'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_IRAN,                    {'I' , 'R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_IRELAND,                 {'I' , 'E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_ITALY,                   {'I' , 'T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_ISRAEL,                  {'I' , 'L'},  {   0,  0,  0,  0,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_JAPAN,                   {'J' , 'P'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_JORDAN,                  {'J' , 'O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_KAZAKHSTAN,              {'K' , 'Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_KUWAIT,                  {'K' , 'W'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_LATVIA,                  {'L' , 'V'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_LEBANON,                 {'L' , 'B'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_LEICHTENSTEIN,           {'L' , 'I'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_LITHUANIA,               {'L' , 'T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_LUXEMBURG,               {'L' , 'U'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_MACAU,                   {'M' , 'O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_MACEDONIA,               {'M' , 'K'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_MALTA,                   {'M' , 'T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
+        ,  {  23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16,  0, 16,  0, 16,  0, 16, 16, 16, 16, 16,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16, 16, 16, 16,  0}  },
+       {CCODE_MALAYSIA,                {'M' , 'Y'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_MEXICO,                  {'M' , 'X'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_MONACO,                  {'M' , 'C'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18, 18, 18, 18, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_MOROCCO,                 {'M' , 'A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_NETHERLANDS,             {'N' , 'L'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_NEW_ZEALAND,             {'N' , 'Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23,  0, 23,  0, 23,  0, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_NORTH_KOREA,             {'K' , 'P'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23, 23, 23, 23,  0}  },
+       {CCODE_NORWAY,                  {'N' , 'O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_OMAN,                    {'O' , 'M'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_PAKISTAN,                {'P' , 'K'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_PANAMA,                  {'P' , 'A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_PERU,                    {'P' , 'E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_PHILIPPINES,             {'P' , 'H'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_POLAND,                  {'P' , 'L'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_PORTUGAL,                {'P' , 'T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_PUERTO_RICO,             {'P' , 'R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_QATAR,                   {'Q' , 'A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_ROMANIA,                 {'R' , 'O'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_RUSSIA,                  {'R' , 'U'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_SAUDI_ARABIA,            {'S' , 'A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_SINGAPORE,               {'S' , 'G'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20, 20, 20, 20, 20}  },
+       {CCODE_SLOVAKIA,                {'S' , 'K'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
+        ,  {  23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16,  0, 16,  0, 16,  0, 16, 16, 16, 16, 16,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16, 16, 16, 16,  0}  },
+       {CCODE_SLOVENIA,                {'S' , 'I'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_SOUTH_AFRICA,            {'Z' , 'A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_SOUTH_KOREA,             {'K' , 'R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23, 23, 23, 23,  0}  },
+       {CCODE_SPAIN,                   {'E' , 'S'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
+        ,  {  23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16,  0, 16,  0, 16,  0, 16, 16, 16, 16, 16,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 16, 16, 16, 16,  0}  },
+       {CCODE_SWEDEN,                  {'S' , 'E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_SWITZERLAND,             {'C' , 'H'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_SYRIA,                   {'S' , 'Y'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_TAIWAN,                  {'T' , 'W'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17, 17, 17,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30,  0}  },
+       {CCODE_THAILAND,                {'T' , 'H'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23, 23, 23, 23,  0}  },
+       {CCODE_TRINIDAD_TOBAGO,         {'T' , 'T'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 18,  0, 18,  0, 18,  0, 18, 18, 18, 18, 18,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_TUNISIA,                 {'T' , 'N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_TURKEY,                  {'T' , 'R'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_UK,                      {'G' , 'B'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 20,  0, 20,  0, 20,  0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0}  },
+       {CCODE_UKRAINE,                 {'U' , 'A'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_UNITED_ARAB_EMIRATES,    {'A' , 'E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_UNITED_STATES,           {'U' , 'S'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1}
+        ,  {  27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 17,  0, 17,  0, 17,  0, 17, 23, 23, 23, 23,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 30, 30, 30, 30, 30}  },
+       {CCODE_URUGUAY,                 {'U' , 'Y'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23, 23, 23, 23,  0}  },
+       {CCODE_UZBEKISTAN,              {'U' , 'Z'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_VENEZUELA,               {'V' , 'E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  0}
+        ,  {  20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 23, 23, 23, 23,  0}  },
+       {CCODE_VIETNAM,                 {'V' , 'N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_YEMEN,                   {'Y' , 'E'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_ZIMBABWE,                {'Z' , 'W'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_JAPAN_W52_W53,           {'J' , 'J'},  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  0,  1,  0,  1,  0,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  },
+       {CCODE_MAX,                     {'U' , 'N'},  {   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1}
+        ,  {   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0}  }
 /*                                              1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  */
 };
 
@@ -382,8 +382,7 @@ bool is_channel_valid(unsigned int ChannelIndex)
         * If Channel Index is invalid, return invalid
         */
        if ((ChannelIndex > CB_MAX_CHANNEL) ||
-               (ChannelIndex == 0))
-       {
+           (ChannelIndex == 0)) {
                bValid = false;
                goto exit;
        }
@@ -391,8 +390,7 @@ bool is_channel_valid(unsigned int ChannelIndex)
        bValid = sChannelTbl[ChannelIndex].bValid;
 
 exit:
-       return (bValid);
-
+       return bValid;
 }
 
 /**
@@ -410,11 +408,11 @@ exit:
 bool channel_get_list(unsigned int uCountryCodeIdx, unsigned char *pbyChannelTable)
 {
        if (uCountryCodeIdx >= CCODE_MAX)
-               return (false);
+               return false;
 
        memcpy(pbyChannelTable, ChannelRuleTab[uCountryCodeIdx].bChannelIdxList, CB_MAX_CHANNEL);
 
-       return (true);
+       return true;
 }
 
 void init_channel_table(void *pDeviceHandler)
@@ -423,75 +421,74 @@ void init_channel_table(void *pDeviceHandler)
        bool bMultiBand = false;
        unsigned int ii;
 
-       for(ii = 1 ; ii<=CARD_MAX_CHANNEL_TBL ; ii++) {
+       for (ii = 1; ii <= CARD_MAX_CHANNEL_TBL; ii++) {
                sChannelTbl[ii].bValid = false;
        }
 
        switch (pDevice->byRFType) {
-               case RF_RFMD2959 :
-               case RF_AIROHA :
-               case RF_AL2230S:
-               case RF_UW2451 :
-               case RF_VT3226 :
-                       //printk("chester-false\n");
-                       bMultiBand = false;
-                       break;
-               case RF_AIROHA7230 :
-               case RF_UW2452 :
-               case RF_NOTHING :
-               default :
-                       bMultiBand = true;
-                       break;
+       case RF_RFMD2959:
+       case RF_AIROHA:
+       case RF_AL2230S:
+       case RF_UW2451:
+       case RF_VT3226:
+               bMultiBand = false;
+               break;
+       case RF_AIROHA7230:
+       case RF_UW2452:
+       case RF_NOTHING:
+       default:
+               bMultiBand = true;
+               break;
        }
 
        if ((pDevice->dwDiagRefCount != 0) || (pDevice->b11hEnable == true)) {
                if (bMultiBand == true) {
-                       for(ii = 0 ; ii<CARD_MAX_CHANNEL_TBL ; ii++) {
-                               sChannelTbl[ii+1].bValid = true;
-                               pDevice->abyRegPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
-                               pDevice->abyLocalPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
+                       for (ii = 0; ii < CARD_MAX_CHANNEL_TBL; ii++) {
+                               sChannelTbl[ii + 1].bValid = true;
+                               pDevice->abyRegPwr[ii + 1] = pDevice->abyOFDMDefaultPwr[ii + 1];
+                               pDevice->abyLocalPwr[ii + 1] = pDevice->abyOFDMDefaultPwr[ii + 1];
                        }
-                       for(ii = 0 ; ii<CHANNEL_MAX_24G ; ii++) {
-                               pDevice->abyRegPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
-                               pDevice->abyLocalPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
+                       for (ii = 0; ii < CHANNEL_MAX_24G; ii++) {
+                               pDevice->abyRegPwr[ii + 1] = pDevice->abyCCKDefaultPwr[ii + 1];
+                               pDevice->abyLocalPwr[ii + 1] = pDevice->abyCCKDefaultPwr[ii + 1];
                        }
                } else {
-                       for(ii = 0 ; ii<CHANNEL_MAX_24G ; ii++) {
+                       for (ii = 0; ii < CHANNEL_MAX_24G; ii++) {
                                //2008-8-4 <add> by chester
                                if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
-                                       sChannelTbl[ii+1].bValid = true;
-                                       pDevice->abyRegPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
-                                       pDevice->abyLocalPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
+                                       sChannelTbl[ii + 1].bValid = true;
+                                       pDevice->abyRegPwr[ii + 1] = pDevice->abyCCKDefaultPwr[ii + 1];
+                                       pDevice->abyLocalPwr[ii + 1] = pDevice->abyCCKDefaultPwr[ii + 1];
                                }
                        }
                }
        } else if (pDevice->byZoneType <= CCODE_MAX) {
                if (bMultiBand == true) {
-                       for(ii = 0 ; ii<CARD_MAX_CHANNEL_TBL ; ii++) {
+                       for (ii = 0; ii < CARD_MAX_CHANNEL_TBL; ii++) {
                                if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
-                                       sChannelTbl[ii+1].bValid = true;
-                                       pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
-                                       pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
+                                       sChannelTbl[ii + 1].bValid = true;
+                                       pDevice->abyRegPwr[ii + 1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
+                                       pDevice->abyLocalPwr[ii + 1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
                                }
                        }
                } else {
-                       for(ii = 0 ; ii<CHANNEL_MAX_24G ; ii++) {
+                       for (ii = 0; ii < CHANNEL_MAX_24G; ii++) {
                                if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
-                                       sChannelTbl[ii+1].bValid = true;
-                                       pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
-                                       pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
+                                       sChannelTbl[ii + 1].bValid = true;
+                                       pDevice->abyRegPwr[ii + 1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
+                                       pDevice->abyLocalPwr[ii + 1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
                                }
                        }
                }
        }
 
-       DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO"Zone=[%d][%c][%c]!!\n",pDevice->byZoneType,ChannelRuleTab[pDevice->byZoneType].chCountryCode[0],ChannelRuleTab[pDevice->byZoneType].chCountryCode[1]);
+       DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Zone=[%d][%c][%c]!!\n", pDevice->byZoneType, ChannelRuleTab[pDevice->byZoneType].chCountryCode[0], ChannelRuleTab[pDevice->byZoneType].chCountryCode[1]);
 
-       for(ii = 0 ; ii<CARD_MAX_CHANNEL_TBL ; ii++) {
-               if (pDevice->abyRegPwr[ii+1] == 0)
-                       pDevice->abyRegPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
-               if (pDevice->abyLocalPwr[ii+1] == 0)
-                       pDevice->abyLocalPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
+       for (ii = 0; ii < CARD_MAX_CHANNEL_TBL; ii++) {
+               if (pDevice->abyRegPwr[ii + 1] == 0)
+                       pDevice->abyRegPwr[ii + 1] = pDevice->abyOFDMDefaultPwr[ii + 1];
+               if (pDevice->abyLocalPwr[ii + 1] == 0)
+                       pDevice->abyLocalPwr[ii + 1] = pDevice->abyOFDMDefaultPwr[ii + 1];
        }
 }
 
@@ -500,11 +497,11 @@ unsigned char get_channel_mapping(void *pDeviceHandler, unsigned char byChannelN
        unsigned int ii;
 
        if ((ePhyType == PHY_TYPE_11B) || (ePhyType == PHY_TYPE_11G))
-               return (byChannelNumber);
+               return byChannelNumber;
 
-       for(ii = (CB_MAX_CHANNEL_24G + 1); ii <= CB_MAX_CHANNEL; ) {
+       for (ii = (CB_MAX_CHANNEL_24G + 1); ii <= CB_MAX_CHANNEL;) {
                if (sChannelTbl[ii].byChannelNumber == byChannelNumber)
-                       return ((unsigned char) ii);
+                       return (unsigned char) ii;
                ii++;
        }
        return 0;
@@ -513,7 +510,7 @@ unsigned char get_channel_mapping(void *pDeviceHandler, unsigned char byChannelN
 unsigned char get_channel_number(void *pDeviceHandler, unsigned char byChannelIndex)
 {
        //PSDevice    pDevice = (PSDevice) pDeviceHandler;
-       return(sChannelTbl[byChannelIndex].byChannelNumber);
+       return sChannelTbl[byChannelIndex].byChannelNumber;
 }
 
 /**
@@ -525,25 +522,24 @@ unsigned char get_channel_number(void *pDeviceHandler, unsigned char byChannelIn
  * Return Value: true if succeeded; false if failed.
  *
  */
-bool set_channel (void *pDeviceHandler, unsigned int uConnectionChannel)
+bool set_channel(void *pDeviceHandler, unsigned int uConnectionChannel)
 {
        PSDevice pDevice = (PSDevice) pDeviceHandler;
        bool bResult = true;
 
-
        if (pDevice->byCurrentCh == uConnectionChannel) {
                return bResult;
        }
 
        if (sChannelTbl[uConnectionChannel].bValid == false) {
-               return (false);
+               return false;
        }
 
        if ((uConnectionChannel > CB_MAX_CHANNEL_24G) &&
-                       (pDevice->eCurrentPHYType != PHY_TYPE_11A)) {
+           (pDevice->eCurrentPHYType != PHY_TYPE_11A)) {
                CARDbSetPhyParameter(pDevice, PHY_TYPE_11A, 0, 0, NULL, NULL);
        } else if ((uConnectionChannel <= CB_MAX_CHANNEL_24G) &&
-                       (pDevice->eCurrentPHYType == PHY_TYPE_11A)) {
+                  (pDevice->eCurrentPHYType == PHY_TYPE_11A)) {
                CARDbSetPhyParameter(pDevice, PHY_TYPE_11G, 0, 0, NULL, NULL);
        }
        // clear NAV
@@ -552,13 +548,11 @@ bool set_channel (void *pDeviceHandler, unsigned int uConnectionChannel)
        //{{ RobertYu: 20041202
        //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
 
-       if ( pDevice->byRFType == RF_AIROHA7230 )
-       {
+       if (pDevice->byRFType == RF_AIROHA7230) {
                RFbAL7230SelectChannelPostProcess(pDevice->PortOffset, pDevice->byCurrentCh, (unsigned char)uConnectionChannel);
        }
        //}} RobertYu
 
-
        pDevice->byCurrentCh = (unsigned char)uConnectionChannel;
        bResult &= RFbSelectChannel(pDevice->PortOffset, pDevice->byRFType, (unsigned char)uConnectionChannel);
 
@@ -566,8 +560,7 @@ bool set_channel (void *pDeviceHandler, unsigned int uConnectionChannel)
        if (pDevice->bEnablePSMode == true)
                RFvWriteWakeProgSyn(pDevice->PortOffset, pDevice->byRFType, uConnectionChannel);
 
-
-       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDbSetMediaChannel: %d\n", (unsigned char)uConnectionChannel);
+       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CARDbSetMediaChannel: %d\n", (unsigned char)uConnectionChannel);
        BBvSoftwareReset(pDevice->PortOffset);
 
        if (pDevice->byLocalID > REV_ID_VT3253_B1) {
@@ -581,18 +574,12 @@ bool set_channel (void *pDeviceHandler, unsigned int uConnectionChannel)
        }
 
        if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
-#ifdef PLICE_DEBUG
-               //printk("Func:ChbSetChannel:call RFbSetPower:11B\n");
-#endif
                RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh);
        } else {
-#ifdef PLICE_DEBUG
-               //printk("Func:ChbSetChannel:call RFbSetPower\n");
-#endif
                RFbSetPower(pDevice, RATE_6M, pDevice->byCurrentCh);
        }
 
-       return(bResult);
+       return bResult;
 }
 
 /**
@@ -612,19 +599,18 @@ void set_country_info(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, void *pIE)
        unsigned char byCh = 0;
        PWLAN_IE_COUNTRY pIE_Country = (PWLAN_IE_COUNTRY) pIE;
 
-
        uNumOfCountryInfo = (pIE_Country->len - 3);
        uNumOfCountryInfo /= 3;
 
        if (ePHYType == PHY_TYPE_11A) {
                pDevice->bCountryInfo5G = true;
-               for(ii = CB_MAX_CHANNEL_24G + 1 ; ii <= CARD_MAX_CHANNEL_TBL ; ii++) {
+               for (ii = CB_MAX_CHANNEL_24G + 1; ii <= CARD_MAX_CHANNEL_TBL; ii++) {
                        sChannelTbl[ii].bValid = false;
                }
                step = 4;
        } else {
                pDevice->bCountryInfo24G = true;
-               for(ii = 1 ; ii <= CB_MAX_CHANNEL_24G ; ii++) {
+               for (ii = 1; ii <= CB_MAX_CHANNEL_24G; ii++) {
                        sChannelTbl[ii].bValid = false;
                }
                step = 1;
@@ -633,8 +619,8 @@ void set_country_info(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, void *pIE)
        pDevice->abyCountryCode[1] = pIE_Country->abyCountryString[1];
        pDevice->abyCountryCode[2] = pIE_Country->abyCountryString[2];
 
-       for(ii = 0 ; ii < uNumOfCountryInfo ; ii++) {
-               for(uu = 0 ; uu < pIE_Country->abyCountryInfo[ii*3+1] ; uu++) {
+       for (ii = 0; ii < uNumOfCountryInfo; ii++) {
+               for (uu = 0; uu < pIE_Country->abyCountryInfo[ii*3+1]; uu++) {
                        byCh = get_channel_mapping(pDevice, (unsigned char)(pIE_Country->abyCountryInfo[ii*3]+step*uu), ePHYType);
                        sChannelTbl[byCh].bValid = true;
                        pDevice->abyRegPwr[byCh] = pIE_Country->abyCountryInfo[ii*3+2];
@@ -661,7 +647,6 @@ unsigned char set_support_channels(void *pDeviceHandler, unsigned char *pbyIEs)
        unsigned char *pbyChTupple;
        unsigned char byLen = 0;
 
-
        pIE->byElementID = WLAN_EID_SUPP_CH;
        pIE->len = 0;
        pbyChTupple = pIE->abyChannelTuple;
@@ -669,7 +654,7 @@ unsigned char set_support_channels(void *pDeviceHandler, unsigned char *pbyIEs)
        // lower band
        byCount = 0;
        if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[28] == true) {
-               for (ii = 28 ; ii < 36 ; ii+= 2) {
+               for (ii = 28; ii < 36; ii += 2) {
                        if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == true) {
                                byCount++;
                        }
@@ -678,7 +663,7 @@ unsigned char set_support_channels(void *pDeviceHandler, unsigned char *pbyIEs)
                *pbyChTupple++ = byCount;
                byLen += 2;
        } else if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[29] == true) {
-               for (ii = 29 ; ii < 36 ; ii+= 2) {
+               for (ii = 29; ii < 36; ii += 2) {
                        if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == true) {
                                byCount++;
                        }
@@ -690,7 +675,7 @@ unsigned char set_support_channels(void *pDeviceHandler, unsigned char *pbyIEs)
        // middle band
        byCount = 0;
        if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[36] == true) {
-               for (ii = 36 ; ii < 40 ; ii++) {
+               for (ii = 36; ii < 40; ii++) {
                        if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == true) {
                                byCount++;
                        }
@@ -702,7 +687,7 @@ unsigned char set_support_channels(void *pDeviceHandler, unsigned char *pbyIEs)
        // higher band
        byCount = 0;
        if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[40] == true) {
-               for (ii = 40 ; ii < 51 ; ii++) {
+               for (ii = 40; ii < 51; ii++) {
                        if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == true) {
                                byCount++;
                        }
@@ -711,7 +696,7 @@ unsigned char set_support_channels(void *pDeviceHandler, unsigned char *pbyIEs)
                *pbyChTupple++ = byCount;
                byLen += 2;
        } else if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[51] == true) {
-               for (ii = 51 ; ii < 56 ; ii++) {
+               for (ii = 51; ii < 56; ii++) {
                        if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == true) {
                                byCount++;
                        }
@@ -721,7 +706,7 @@ unsigned char set_support_channels(void *pDeviceHandler, unsigned char *pbyIEs)
                byLen += 2;
        }
        pIE->len += (byLen - 2);
-       return (byLen);
+       return byLen;
 }
 
 void set_country_IE(void *pDeviceHandler, void *pIE)
@@ -735,9 +720,9 @@ void set_country_IE(void *pDeviceHandler, void *pIE)
        pIECountry->abyCountryString[0] = ChannelRuleTab[pDevice->byZoneType].chCountryCode[0];
        pIECountry->abyCountryString[1] = ChannelRuleTab[pDevice->byZoneType].chCountryCode[1];
        pIECountry->abyCountryString[2] = ' ';
-       for (ii = CB_MAX_CHANNEL_24G; ii < CB_MAX_CHANNEL; ii++ ) {
+       for (ii = CB_MAX_CHANNEL_24G; ii < CB_MAX_CHANNEL; ii++) {
                if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
-                       pIECountry->abyCountryInfo[pIECountry->len++] = sChannelTbl[ii+1].byChannelNumber;
+                       pIECountry->abyCountryInfo[pIECountry->len++] = sChannelTbl[ii + 1].byChannelNumber;
                        pIECountry->abyCountryInfo[pIECountry->len++] = 1;
                        pIECountry->abyCountryInfo[pIECountry->len++] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
                }
@@ -746,9 +731,8 @@ void set_country_IE(void *pDeviceHandler, void *pIE)
 }
 
 bool get_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
-               unsigned char *pbyChannelNumber, unsigned char *pbyMap)
+                         unsigned char *pbyChannelNumber, unsigned char *pbyMap)
 {
-
        if (uChannelIndex > CB_MAX_CHANNEL)
                return false;
 
@@ -758,9 +742,8 @@ bool get_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
 }
 
 void set_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
-               unsigned char byMap)
+                         unsigned char byMap)
 {
-
        if (uChannelIndex > CB_MAX_CHANNEL)
                return;
 
@@ -779,40 +762,40 @@ unsigned char auto_channel_select(void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
 {
        unsigned int ii = 0;
        unsigned char byOptionChannel = 0;
-       int aiWeight[CB_MAX_CHANNEL_24G+1] = {-1000,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+       int aiWeight[CB_MAX_CHANNEL_24G + 1] = {-1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
        if (ePHYType == PHY_TYPE_11A) {
-               for(ii = CB_MAX_CHANNEL_24G + 1 ; ii <= CB_MAX_CHANNEL ; ii++) {
+               for (ii = CB_MAX_CHANNEL_24G + 1; ii <= CB_MAX_CHANNEL; ii++) {
                        if (sChannelTbl[ii].bValid == true) {
                                if (byOptionChannel == 0) {
                                        byOptionChannel = (unsigned char) ii;
                                }
                                if (sChannelTbl[ii].byMAP == 0) {
-                                       return ((unsigned char) ii);
-                               } else if ( !(sChannelTbl[ii].byMAP & 0x08)) {
+                                       return (unsigned char) ii;
+                               } else if (!(sChannelTbl[ii].byMAP & 0x08)) {
                                        byOptionChannel = (unsigned char) ii;
                                }
                        }
                }
        } else {
                byOptionChannel = 0;
-               for(ii = 1 ; ii <= CB_MAX_CHANNEL_24G ; ii++) {
+               for (ii = 1; ii <= CB_MAX_CHANNEL_24G; ii++) {
                        if (sChannelTbl[ii].bValid == true) {
                                if (sChannelTbl[ii].byMAP == 0) {
                                        aiWeight[ii] += 100;
                                } else if (sChannelTbl[ii].byMAP & 0x01) {
                                        if (ii > 3) {
-                                               aiWeight[ii-3] -= 10;
+                                               aiWeight[ii - 3] -= 10;
                                        }
                                        if (ii > 2) {
-                                               aiWeight[ii-2] -= 20;
+                                               aiWeight[ii - 2] -= 20;
                                        }
                                        if (ii > 1) {
-                                               aiWeight[ii-1] -= 40;
+                                               aiWeight[ii - 1] -= 40;
                                        }
                                        aiWeight[ii] -= 80;
                                        if (ii < CB_MAX_CHANNEL_24G) {
-                                               aiWeight[ii+1] -= 40;
+                                               aiWeight[ii + 1] -= 40;
                                        }
                                        if (ii < (CB_MAX_CHANNEL_24G - 1)) {
                                                aiWeight[ii+2] -= 20;
@@ -823,12 +806,12 @@ unsigned char auto_channel_select(void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
                                }
                        }
                }
-               for(ii = 1 ; ii <= CB_MAX_CHANNEL_24G ; ii++) {
+               for (ii = 1; ii <= CB_MAX_CHANNEL_24G; ii++) {
                        if ((sChannelTbl[ii].bValid == true) &&
-                                       (aiWeight[ii] > aiWeight[byOptionChannel])) {
+                           (aiWeight[ii] > aiWeight[byOptionChannel])) {
                                byOptionChannel = (unsigned char) ii;
                        }
                }
        }
-       return (byOptionChannel);
+       return byOptionChannel;
 }
index 7038f0d3bde99ee4e114e40a77856d6b9badc056..c9931d7f66530b2aee7c997259e5ee14ccda3573 100644 (file)
 /*---------------------  Export Classes  ----------------------------*/
 
 typedef struct tagSChannelTblElement {
-    unsigned char byChannelNumber;
-    unsigned int uFrequency;
-    bool bValid;
-    unsigned char byMAP;
-}SChannelTblElement, *PSChannelTblElement;
-
+       unsigned char byChannelNumber;
+       unsigned int uFrequency;
+       bool bValid;
+       unsigned char byMAP;
+} SChannelTblElement, *PSChannelTblElement;
 
 /*---------------------  Export Functions  --------------------------*/
 
@@ -48,11 +47,10 @@ void set_country_info(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, void *pIE);
 unsigned char set_support_channels(void *pDeviceHandler, unsigned char *pbyIEs);
 void set_country_IE(void *pDeviceHandler, void *pIE);
 bool get_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
-               unsigned char *pbyChannelNumber, unsigned char *pbyMap);
+                         unsigned char *pbyChannelNumber, unsigned char *pbyMap);
 void set_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
-               unsigned char byMap);
+                         unsigned char byMap);
 void clear_channel_map_info(void *pDeviceHandler);
 unsigned char auto_channel_select(void *pDeviceHandler, CARD_PHY_TYPE ePHYType);
 
-
 #endif /* _CHANNEL_H_ */
index 05fda4104200b3b43cc63da351d77308e28538b8..415e7672aa3291a52b0c428bc3e7bf4a9adb0376 100644 (file)
  * Please check with VNWL.inf/VNWL64.inf/VNWL*.inf
  ************************************************************************/
 typedef enum _COUNTRY_CODE {
-    CCODE_FCC = 0,
-    CCODE_TELEC,
-    CCODE_ETSI,
-    CCODE_RESV3,
-    CCODE_RESV4,
-    CCODE_RESV5,
-    CCODE_RESV6,
-    CCODE_RESV7,
-    CCODE_RESV8,
-    CCODE_RESV9,
-    CCODE_RESVa,
-    CCODE_RESVb,
-    CCODE_RESVc,
-    CCODE_RESVd,
-    CCODE_RESVe,
-    CCODE_ALLBAND,
-    CCODE_ALBANIA,
-    CCODE_ALGERIA,
-    CCODE_ARGENTINA,
-    CCODE_ARMENIA,
-    CCODE_AUSTRALIA,
-    CCODE_AUSTRIA,
-    CCODE_AZERBAIJAN,
-    CCODE_BAHRAIN,
-    CCODE_BELARUS,
-    CCODE_BELGIUM,
-    CCODE_BELIZE,
-    CCODE_BOLIVIA,
-    CCODE_BRAZIL,
-    CCODE_BRUNEI_DARUSSALAM,
-    CCODE_BULGARIA,
-    CCODE_CANADA,
-    CCODE_CHILE,
-    CCODE_CHINA,
-    CCODE_COLOMBIA,
-    CCODE_COSTA_RICA,
-    CCODE_CROATIA,
-    CCODE_CYPRUS,
-    CCODE_CZECH,
-    CCODE_DENMARK,
-    CCODE_DOMINICAN_REPUBLIC,
-    CCODE_ECUADOR,
-    CCODE_EGYPT,
-    CCODE_EL_SALVADOR,
-    CCODE_ESTONIA,
-    CCODE_FINLAND,
-    CCODE_FRANCE,
-    CCODE_GERMANY,
-    CCODE_GREECE,
-    CCODE_GEORGIA,
-    CCODE_GUATEMALA,
-    CCODE_HONDURAS,
-    CCODE_HONG_KONG,
-    CCODE_HUNGARY,
-    CCODE_ICELAND,
-    CCODE_INDIA,
-    CCODE_INDONESIA,
-    CCODE_IRAN,
-    CCODE_IRELAND,
-    CCODE_ITALY,
-    CCODE_ISRAEL,
-    CCODE_JAPAN,
-    CCODE_JORDAN,
-    CCODE_KAZAKHSTAN,
-    CCODE_KUWAIT,
-    CCODE_LATVIA,
-    CCODE_LEBANON,
-    CCODE_LEICHTENSTEIN,
-    CCODE_LITHUANIA,
-    CCODE_LUXEMBURG,
-    CCODE_MACAU,
-    CCODE_MACEDONIA,
-    CCODE_MALTA,
-    CCODE_MALAYSIA,
-    CCODE_MEXICO,
-    CCODE_MONACO,
-    CCODE_MOROCCO,
-    CCODE_NETHERLANDS,
-    CCODE_NEW_ZEALAND,
-    CCODE_NORTH_KOREA,
-    CCODE_NORWAY,
-    CCODE_OMAN,
-    CCODE_PAKISTAN,
-    CCODE_PANAMA,
-    CCODE_PERU,
-    CCODE_PHILIPPINES,
-    CCODE_POLAND,
-    CCODE_PORTUGAL,
-    CCODE_PUERTO_RICO,
-    CCODE_QATAR,
-    CCODE_ROMANIA,
-    CCODE_RUSSIA,
-    CCODE_SAUDI_ARABIA,
-    CCODE_SINGAPORE,
-    CCODE_SLOVAKIA,
-    CCODE_SLOVENIA,
-    CCODE_SOUTH_AFRICA,
-    CCODE_SOUTH_KOREA,
-    CCODE_SPAIN,
-    CCODE_SWEDEN,
-    CCODE_SWITZERLAND,
-    CCODE_SYRIA,
-    CCODE_TAIWAN,
-    CCODE_THAILAND,
-    CCODE_TRINIDAD_TOBAGO,
-    CCODE_TUNISIA,
-    CCODE_TURKEY,
-    CCODE_UK,
-    CCODE_UKRAINE,
-    CCODE_UNITED_ARAB_EMIRATES,
-    CCODE_UNITED_STATES,
-    CCODE_URUGUAY,
-    CCODE_UZBEKISTAN,
-    CCODE_VENEZUELA,
-    CCODE_VIETNAM,
-    CCODE_YEMEN,
-    CCODE_ZIMBABWE,
-    CCODE_JAPAN_W52_W53,
-    CCODE_MAX
+       CCODE_FCC = 0,
+       CCODE_TELEC,
+       CCODE_ETSI,
+       CCODE_RESV3,
+       CCODE_RESV4,
+       CCODE_RESV5,
+       CCODE_RESV6,
+       CCODE_RESV7,
+       CCODE_RESV8,
+       CCODE_RESV9,
+       CCODE_RESVa,
+       CCODE_RESVb,
+       CCODE_RESVc,
+       CCODE_RESVd,
+       CCODE_RESVe,
+       CCODE_ALLBAND,
+       CCODE_ALBANIA,
+       CCODE_ALGERIA,
+       CCODE_ARGENTINA,
+       CCODE_ARMENIA,
+       CCODE_AUSTRALIA,
+       CCODE_AUSTRIA,
+       CCODE_AZERBAIJAN,
+       CCODE_BAHRAIN,
+       CCODE_BELARUS,
+       CCODE_BELGIUM,
+       CCODE_BELIZE,
+       CCODE_BOLIVIA,
+       CCODE_BRAZIL,
+       CCODE_BRUNEI_DARUSSALAM,
+       CCODE_BULGARIA,
+       CCODE_CANADA,
+       CCODE_CHILE,
+       CCODE_CHINA,
+       CCODE_COLOMBIA,
+       CCODE_COSTA_RICA,
+       CCODE_CROATIA,
+       CCODE_CYPRUS,
+       CCODE_CZECH,
+       CCODE_DENMARK,
+       CCODE_DOMINICAN_REPUBLIC,
+       CCODE_ECUADOR,
+       CCODE_EGYPT,
+       CCODE_EL_SALVADOR,
+       CCODE_ESTONIA,
+       CCODE_FINLAND,
+       CCODE_FRANCE,
+       CCODE_GERMANY,
+       CCODE_GREECE,
+       CCODE_GEORGIA,
+       CCODE_GUATEMALA,
+       CCODE_HONDURAS,
+       CCODE_HONG_KONG,
+       CCODE_HUNGARY,
+       CCODE_ICELAND,
+       CCODE_INDIA,
+       CCODE_INDONESIA,
+       CCODE_IRAN,
+       CCODE_IRELAND,
+       CCODE_ITALY,
+       CCODE_ISRAEL,
+       CCODE_JAPAN,
+       CCODE_JORDAN,
+       CCODE_KAZAKHSTAN,
+       CCODE_KUWAIT,
+       CCODE_LATVIA,
+       CCODE_LEBANON,
+       CCODE_LEICHTENSTEIN,
+       CCODE_LITHUANIA,
+       CCODE_LUXEMBURG,
+       CCODE_MACAU,
+       CCODE_MACEDONIA,
+       CCODE_MALTA,
+       CCODE_MALAYSIA,
+       CCODE_MEXICO,
+       CCODE_MONACO,
+       CCODE_MOROCCO,
+       CCODE_NETHERLANDS,
+       CCODE_NEW_ZEALAND,
+       CCODE_NORTH_KOREA,
+       CCODE_NORWAY,
+       CCODE_OMAN,
+       CCODE_PAKISTAN,
+       CCODE_PANAMA,
+       CCODE_PERU,
+       CCODE_PHILIPPINES,
+       CCODE_POLAND,
+       CCODE_PORTUGAL,
+       CCODE_PUERTO_RICO,
+       CCODE_QATAR,
+       CCODE_ROMANIA,
+       CCODE_RUSSIA,
+       CCODE_SAUDI_ARABIA,
+       CCODE_SINGAPORE,
+       CCODE_SLOVAKIA,
+       CCODE_SLOVENIA,
+       CCODE_SOUTH_AFRICA,
+       CCODE_SOUTH_KOREA,
+       CCODE_SPAIN,
+       CCODE_SWEDEN,
+       CCODE_SWITZERLAND,
+       CCODE_SYRIA,
+       CCODE_TAIWAN,
+       CCODE_THAILAND,
+       CCODE_TRINIDAD_TOBAGO,
+       CCODE_TUNISIA,
+       CCODE_TURKEY,
+       CCODE_UK,
+       CCODE_UKRAINE,
+       CCODE_UNITED_ARAB_EMIRATES,
+       CCODE_UNITED_STATES,
+       CCODE_URUGUAY,
+       CCODE_UZBEKISTAN,
+       CCODE_VENEZUELA,
+       CCODE_VIETNAM,
+       CCODE_YEMEN,
+       CCODE_ZIMBABWE,
+       CCODE_JAPAN_W52_W53,
+       CCODE_MAX
 } COUNTRY_CODE;
 
 #endif  /* __COUNTRY_H__ */
index b86ec1b6d1876e410c6da747ad5df9301c852e1c..e7b6bc7de4ac20ffa233293e7278c815356c27fc 100644 (file)
 
 /*---------------------  Static Definitions -------------------------*/
 
-
-
-
 /*---------------------  Static Classes  ----------------------------*/
 
-
- extern unsigned short TxRate_iwconfig; //2008-5-8 <add> by chester
+extern unsigned short TxRate_iwconfig; //2008-5-8 <add> by chester
 /*---------------------  Static Variables  --------------------------*/
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 const unsigned char acbyIERate[MAX_RATE] =
 {0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
 
@@ -64,32 +60,28 @@ const unsigned char acbyIERate[MAX_RATE] =
 
 /*---------------------  Static Functions  --------------------------*/
 
-void s_vResetCounter (
-    PKnownNodeDB psNodeDBTable
-    );
-
-
+void s_vResetCounter(
+       PKnownNodeDB psNodeDBTable
+);
 
 void
-s_vResetCounter (
-    PKnownNodeDB psNodeDBTable
-    )
+s_vResetCounter(
+       PKnownNodeDB psNodeDBTable
+)
 {
-    unsigned char ii;
+       unsigned char ii;
 
-    // clear statistic counter for auto_rate
-    for(ii=0;ii<=MAX_RATE;ii++) {
-        psNodeDBTable->uTxOk[ii] = 0;
-        psNodeDBTable->uTxFail[ii] = 0;
-    }
+       // clear statistic counter for auto_rate
+       for (ii = 0; ii <= MAX_RATE; ii++) {
+               psNodeDBTable->uTxOk[ii] = 0;
+               psNodeDBTable->uTxFail[ii] = 0;
+       }
 }
 
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
-
 /*+
  *
  * Description:
@@ -103,26 +95,24 @@ s_vResetCounter (
  *
  * Return Value: RateIdx
  *
--*/
+ -*/
 unsigned char
-DATARATEbyGetRateIdx (
-    unsigned char byRate
-    )
+DATARATEbyGetRateIdx(
+       unsigned char byRate
+)
 {
-    unsigned char ii;
+       unsigned char ii;
 
-    //Erase basicRate flag.
-    byRate = byRate & 0x7F;//0111 1111
+       //Erase basicRate flag.
+       byRate = byRate & 0x7F;//0111 1111
 
-    for (ii = 0; ii < MAX_RATE; ii ++) {
-        if (acbyIERate[ii] == byRate)
-            return ii;
-    }
-    return 0;
+       for (ii = 0; ii < MAX_RATE; ii++) {
+               if (acbyIERate[ii] == byRate)
+                       return ii;
+       }
+       return 0;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -137,13 +127,10 @@ DATARATEbyGetRateIdx (
  *
  * Return Value: none
  *
--*/
+ -*/
 #define AUTORATE_TXCNT_THRESHOLD        20
 #define AUTORATE_INC_THRESHOLD          30
 
-
-
-
 /*+
  *
  * Description:
@@ -157,22 +144,22 @@ DATARATEbyGetRateIdx (
  *
  * Return Value: RateIdx
  *
--*/
+ -*/
 unsigned short
 wGetRateIdx(
-    unsigned char byRate
-    )
+       unsigned char byRate
+)
 {
-    unsigned short ii;
+       unsigned short ii;
 
-    //Erase basicRate flag.
-    byRate = byRate & 0x7F;//0111 1111
+       //Erase basicRate flag.
+       byRate = byRate & 0x7F;//0111 1111
 
-    for (ii = 0; ii < MAX_RATE; ii ++) {
-        if (acbyIERate[ii] == byRate)
-            return ii;
-    }
-    return 0;
+       for (ii = 0; ii < MAX_RATE; ii++) {
+               if (acbyIERate[ii] == byRate)
+                       return ii;
+       }
+       return 0;
 }
 
 /*+
@@ -193,102 +180,99 @@ wGetRateIdx(
  *
  * Return Value: none
  *
--*/
+ -*/
 void
-RATEvParseMaxRate (
-    void *pDeviceHandler,
-    PWLAN_IE_SUPP_RATES pItemRates,
-    PWLAN_IE_SUPP_RATES pItemExtRates,
-    bool bUpdateBasicRate,
-    unsigned short *pwMaxBasicRate,
-    unsigned short *pwMaxSuppRate,
-    unsigned short *pwSuppRate,
-    unsigned char *pbyTopCCKRate,
-    unsigned char *pbyTopOFDMRate
-    )
+RATEvParseMaxRate(
+       void *pDeviceHandler,
+       PWLAN_IE_SUPP_RATES pItemRates,
+       PWLAN_IE_SUPP_RATES pItemExtRates,
+       bool bUpdateBasicRate,
+       unsigned short *pwMaxBasicRate,
+       unsigned short *pwMaxSuppRate,
+       unsigned short *pwSuppRate,
+       unsigned char *pbyTopCCKRate,
+       unsigned char *pbyTopOFDMRate
+)
 {
-PSDevice  pDevice = (PSDevice) pDeviceHandler;
-unsigned int ii;
-unsigned char byHighSuppRate = 0;
-unsigned char byRate = 0;
-unsigned short wOldBasicRate = pDevice->wBasicRate;
-unsigned int uRateLen;
-
-
-    if (pItemRates == NULL)
-        return;
-
-    *pwSuppRate = 0;
-    uRateLen = pItemRates->len;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate Len: %d\n", uRateLen);
-    if (pDevice->eCurrentPHYType != PHY_TYPE_11B) {
-        if (uRateLen > WLAN_RATES_MAXLEN)
-            uRateLen = WLAN_RATES_MAXLEN;
-    } else {
-        if (uRateLen > WLAN_RATES_MAXLEN_11B)
-            uRateLen = WLAN_RATES_MAXLEN_11B;
-    }
-
-    for (ii = 0; ii < uRateLen; ii++) {
-       byRate = (unsigned char)(pItemRates->abyRates[ii]);
-        if (WLAN_MGMT_IS_BASICRATE(byRate) &&
-            (bUpdateBasicRate == true))  {
-            // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
-            CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate));
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate));
-        }
-        byRate = (unsigned char)(pItemRates->abyRates[ii]&0x7F);
-        if (byHighSuppRate == 0)
-            byHighSuppRate = byRate;
-        if (byRate > byHighSuppRate)
-            byHighSuppRate = byRate;
-        *pwSuppRate |= (1<<wGetRateIdx(byRate));
-    }
-    if ((pItemExtRates != NULL) && (pItemExtRates->byElementID == WLAN_EID_EXTSUPP_RATES) &&
-        (pDevice->eCurrentPHYType != PHY_TYPE_11B)) {
-
-        unsigned int uExtRateLen = pItemExtRates->len;
-
-        if (uExtRateLen > WLAN_RATES_MAXLEN)
-            uExtRateLen = WLAN_RATES_MAXLEN;
-
-        for (ii = 0; ii < uExtRateLen ; ii++) {
-            byRate = (unsigned char)(pItemExtRates->abyRates[ii]);
-            // select highest basic rate
-            if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) {
-               // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
-                CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate));
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate));
-            }
-            byRate = (unsigned char)(pItemExtRates->abyRates[ii]&0x7F);
-            if (byHighSuppRate == 0)
-                byHighSuppRate = byRate;
-            if (byRate > byHighSuppRate)
-                byHighSuppRate = byRate;
-            *pwSuppRate |= (1<<wGetRateIdx(byRate));
-            //DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n", wGetRateIdx(byRate), byRate));
-        }
-    } //if(pItemExtRates != NULL)
-
-    if ((pDevice->byPacketType == PK_TYPE_11GB) && CARDbIsOFDMinBasicRate((void *)pDevice)) {
-        pDevice->byPacketType = PK_TYPE_11GA;
-    }
-
-    *pbyTopCCKRate = pDevice->byTopCCKBasicRate;
-    *pbyTopOFDMRate = pDevice->byTopOFDMBasicRate;
-    *pwMaxSuppRate = wGetRateIdx(byHighSuppRate);
-    if ((pDevice->byPacketType==PK_TYPE_11B) || (pDevice->byPacketType==PK_TYPE_11GB))
-       *pwMaxBasicRate = pDevice->byTopCCKBasicRate;
-    else
-       *pwMaxBasicRate = pDevice->byTopOFDMBasicRate;
-    if (wOldBasicRate != pDevice->wBasicRate)
-        CARDvSetRSPINF((void *)pDevice, pDevice->eCurrentPHYType);
-
-     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Exit ParseMaxRate\n");
+       PSDevice  pDevice = (PSDevice) pDeviceHandler;
+       unsigned int ii;
+       unsigned char byHighSuppRate = 0;
+       unsigned char byRate = 0;
+       unsigned short wOldBasicRate = pDevice->wBasicRate;
+       unsigned int uRateLen;
+
+       if (pItemRates == NULL)
+               return;
+
+       *pwSuppRate = 0;
+       uRateLen = pItemRates->len;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ParseMaxRate Len: %d\n", uRateLen);
+       if (pDevice->eCurrentPHYType != PHY_TYPE_11B) {
+               if (uRateLen > WLAN_RATES_MAXLEN)
+                       uRateLen = WLAN_RATES_MAXLEN;
+       } else {
+               if (uRateLen > WLAN_RATES_MAXLEN_11B)
+                       uRateLen = WLAN_RATES_MAXLEN_11B;
+       }
+
+       for (ii = 0; ii < uRateLen; ii++) {
+               byRate = (unsigned char)(pItemRates->abyRates[ii]);
+               if (WLAN_MGMT_IS_BASICRATE(byRate) &&
+                   (bUpdateBasicRate == true))  {
+                       // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
+                       CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate));
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate));
+               }
+               byRate = (unsigned char)(pItemRates->abyRates[ii]&0x7F);
+               if (byHighSuppRate == 0)
+                       byHighSuppRate = byRate;
+               if (byRate > byHighSuppRate)
+                       byHighSuppRate = byRate;
+               *pwSuppRate |= (1<<wGetRateIdx(byRate));
+       }
+       if ((pItemExtRates != NULL) && (pItemExtRates->byElementID == WLAN_EID_EXTSUPP_RATES) &&
+           (pDevice->eCurrentPHYType != PHY_TYPE_11B)) {
+               unsigned int uExtRateLen = pItemExtRates->len;
+
+               if (uExtRateLen > WLAN_RATES_MAXLEN)
+                       uExtRateLen = WLAN_RATES_MAXLEN;
+
+               for (ii = 0; ii < uExtRateLen; ii++) {
+                       byRate = (unsigned char)(pItemExtRates->abyRates[ii]);
+                       // select highest basic rate
+                       if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) {
+                               // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
+                               CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate));
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate));
+                       }
+                       byRate = (unsigned char)(pItemExtRates->abyRates[ii]&0x7F);
+                       if (byHighSuppRate == 0)
+                               byHighSuppRate = byRate;
+                       if (byRate > byHighSuppRate)
+                               byHighSuppRate = byRate;
+                       *pwSuppRate |= (1<<wGetRateIdx(byRate));
+                       //DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n", wGetRateIdx(byRate), byRate));
+               }
+       } //if (pItemExtRates != NULL)
+
+       if ((pDevice->byPacketType == PK_TYPE_11GB) && CARDbIsOFDMinBasicRate((void *)pDevice)) {
+               pDevice->byPacketType = PK_TYPE_11GA;
+       }
+
+       *pbyTopCCKRate = pDevice->byTopCCKBasicRate;
+       *pbyTopOFDMRate = pDevice->byTopOFDMBasicRate;
+       *pwMaxSuppRate = wGetRateIdx(byHighSuppRate);
+       if ((pDevice->byPacketType == PK_TYPE_11B) || (pDevice->byPacketType == PK_TYPE_11GB))
+               *pwMaxBasicRate = pDevice->byTopCCKBasicRate;
+       else
+               *pwMaxBasicRate = pDevice->byTopOFDMBasicRate;
+       if (wOldBasicRate != pDevice->wBasicRate)
+               CARDvSetRSPINF((void *)pDevice, pDevice->eCurrentPHYType);
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Exit ParseMaxRate\n");
 }
 
-
 /*+
  *
  * Routine Description:
@@ -303,97 +287,95 @@ unsigned int uRateLen;
  *
  * Return Value: none
  *
--*/
+ -*/
 #define AUTORATE_TXCNT_THRESHOLD        20
 #define AUTORATE_INC_THRESHOLD          30
 
 void
-RATEvTxRateFallBack (
-    void *pDeviceHandler,
-    PKnownNodeDB psNodeDBTable
-    )
+RATEvTxRateFallBack(
+       void *pDeviceHandler,
+       PKnownNodeDB psNodeDBTable
+)
 {
-PSDevice        pDevice = (PSDevice) pDeviceHandler;
-unsigned short wIdxDownRate = 0;
-unsigned int ii;
+       PSDevice        pDevice = (PSDevice) pDeviceHandler;
+       unsigned short wIdxDownRate = 0;
+       unsigned int ii;
 //unsigned long dwRateTable[MAX_RATE]  = {1,   2,   5,   11,  6,    9,    12,   18,  24,  36,  48,  54};
-bool bAutoRate[MAX_RATE]    = {true,true,true,true,false,false,true,true,true,true,true,true};
+       bool bAutoRate[MAX_RATE]    = {true, true, true, true, false, false, true, true, true, true, true, true};
        unsigned long dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540};
        unsigned long dwThroughput = 0;
        unsigned short wIdxUpRate = 0;
        unsigned long dwTxDiff = 0;
 
-    if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
-        // Don't do Fallback when scanning Channel
-        return;
-    }
-
-    psNodeDBTable->uTimeCount ++;
-
-    if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE])
-        dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE];
-
-    if ((psNodeDBTable->uTxOk[MAX_RATE] < AUTORATE_TXOK_CNT) &&
-        (dwTxDiff < AUTORATE_TXFAIL_CNT) &&
-        (psNodeDBTable->uTimeCount < AUTORATE_TIMEOUT)) {
-        return;
-    }
-
-    if (psNodeDBTable->uTimeCount >= AUTORATE_TIMEOUT) {
-        psNodeDBTable->uTimeCount = 0;
-    }
-
-
-    for(ii=0;ii<MAX_RATE;ii++) {
-        if (psNodeDBTable->wSuppRate & (0x0001<<ii)) {
-            if (bAutoRate[ii] == true) {
-                wIdxUpRate = (unsigned short) ii;
-            }
-        } else {
-            bAutoRate[ii] = false;
-        }
-    }
-
-    for(ii=0;ii<=psNodeDBTable->wTxDataRate;ii++) {
-        if ( (psNodeDBTable->uTxOk[ii] != 0) ||
-             (psNodeDBTable->uTxFail[ii] != 0) ) {
-            dwThroughputTbl[ii] *= psNodeDBTable->uTxOk[ii];
-            if (ii < RATE_11M) {
-                psNodeDBTable->uTxFail[ii] *= 4;
-            }
-            dwThroughputTbl[ii] /= (psNodeDBTable->uTxOk[ii] + psNodeDBTable->uTxFail[ii]);
-        }
-//        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate %d,Ok: %d, Fail:%d, Throughput:%d\n",
+       if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
+               // Don't do Fallback when scanning Channel
+               return;
+       }
+
+       psNodeDBTable->uTimeCount++;
+
+       if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE])
+               dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE];
+
+       if ((psNodeDBTable->uTxOk[MAX_RATE] < AUTORATE_TXOK_CNT) &&
+           (dwTxDiff < AUTORATE_TXFAIL_CNT) &&
+           (psNodeDBTable->uTimeCount < AUTORATE_TIMEOUT)) {
+               return;
+       }
+
+       if (psNodeDBTable->uTimeCount >= AUTORATE_TIMEOUT) {
+               psNodeDBTable->uTimeCount = 0;
+       }
+
+       for (ii = 0; ii < MAX_RATE; ii++) {
+               if (psNodeDBTable->wSuppRate & (0x0001<<ii)) {
+                       if (bAutoRate[ii] == true) {
+                               wIdxUpRate = (unsigned short) ii;
+                       }
+               } else {
+                       bAutoRate[ii] = false;
+               }
+       }
+
+       for (ii = 0; ii <= psNodeDBTable->wTxDataRate; ii++) {
+               if ((psNodeDBTable->uTxOk[ii] != 0) ||
+                   (psNodeDBTable->uTxFail[ii] != 0)) {
+                       dwThroughputTbl[ii] *= psNodeDBTable->uTxOk[ii];
+                       if (ii < RATE_11M) {
+                               psNodeDBTable->uTxFail[ii] *= 4;
+                       }
+                       dwThroughputTbl[ii] /= (psNodeDBTable->uTxOk[ii] + psNodeDBTable->uTxFail[ii]);
+               }
+//        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rate %d,Ok: %d, Fail:%d, Throughput:%d\n",
 //                       ii, psNodeDBTable->uTxOk[ii], psNodeDBTable->uTxFail[ii], dwThroughputTbl[ii]);
-    }
-    dwThroughput = dwThroughputTbl[psNodeDBTable->wTxDataRate];
-
-    wIdxDownRate = psNodeDBTable->wTxDataRate;
-    for(ii = psNodeDBTable->wTxDataRate; ii > 0;) {
-        ii--;
-        if ( (dwThroughputTbl[ii] > dwThroughput) &&
-             (bAutoRate[ii]==true) ) {
-            dwThroughput = dwThroughputTbl[ii];
-            wIdxDownRate = (unsigned short) ii;
-        }
-    }
-    psNodeDBTable->wTxDataRate = wIdxDownRate;
-    if (psNodeDBTable->uTxOk[MAX_RATE]) {
-        if (psNodeDBTable->uTxOk[MAX_RATE] >
-           (psNodeDBTable->uTxFail[MAX_RATE] * 4) ) {
-            psNodeDBTable->wTxDataRate = wIdxUpRate;
-        }
-    }else { // adhoc, if uTxOk =0 & uTxFail = 0
-        if (psNodeDBTable->uTxFail[MAX_RATE] == 0)
-            psNodeDBTable->wTxDataRate = wIdxUpRate;
-    }
+       }
+       dwThroughput = dwThroughputTbl[psNodeDBTable->wTxDataRate];
+
+       wIdxDownRate = psNodeDBTable->wTxDataRate;
+       for (ii = psNodeDBTable->wTxDataRate; ii > 0;) {
+               ii--;
+               if ((dwThroughputTbl[ii] > dwThroughput) &&
+                   (bAutoRate[ii] == true)) {
+                       dwThroughput = dwThroughputTbl[ii];
+                       wIdxDownRate = (unsigned short) ii;
+               }
+       }
+       psNodeDBTable->wTxDataRate = wIdxDownRate;
+       if (psNodeDBTable->uTxOk[MAX_RATE]) {
+               if (psNodeDBTable->uTxOk[MAX_RATE] >
+                   (psNodeDBTable->uTxFail[MAX_RATE] * 4)) {
+                       psNodeDBTable->wTxDataRate = wIdxUpRate;
+               }
+       } else { // adhoc, if uTxOk =0 & uTxFail = 0
+               if (psNodeDBTable->uTxFail[MAX_RATE] == 0)
+                       psNodeDBTable->wTxDataRate = wIdxUpRate;
+       }
 //2008-5-8 <add> by chester
-TxRate_iwconfig=psNodeDBTable->wTxDataRate;
-    s_vResetCounter(psNodeDBTable);
-//    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate: %d, U:%d, D:%d\n", psNodeDBTable->wTxDataRate, wIdxUpRate, wIdxDownRate);
-
-    return;
+       TxRate_iwconfig = psNodeDBTable->wTxDataRate;
+       s_vResetCounter(psNodeDBTable);
+//    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rate: %d, U:%d, D:%d\n", psNodeDBTable->wTxDataRate, wIdxUpRate, wIdxDownRate);
 
+       return;
 }
 
 /*+
@@ -408,30 +390,29 @@ TxRate_iwconfig=psNodeDBTable->wTxDataRate;
  *
  * Return Value: None
  *
--*/
+ -*/
 unsigned char
-RATEuSetIE (
-    PWLAN_IE_SUPP_RATES pSrcRates,
-    PWLAN_IE_SUPP_RATES pDstRates,
-    unsigned int uRateLen
-    )
+RATEuSetIE(
+       PWLAN_IE_SUPP_RATES pSrcRates,
+       PWLAN_IE_SUPP_RATES pDstRates,
+       unsigned int uRateLen
+)
 {
-    unsigned int ii, uu, uRateCnt = 0;
-
-    if ((pSrcRates == NULL) || (pDstRates == NULL))
-        return 0;
-
-    if (pSrcRates->len == 0)
-        return 0;
-
-    for (ii = 0; ii < uRateLen; ii++) {
-        for (uu = 0; uu < pSrcRates->len; uu++) {
-            if ((pSrcRates->abyRates[uu] & 0x7F) == acbyIERate[ii]) {
-                pDstRates->abyRates[uRateCnt ++] = pSrcRates->abyRates[uu];
-                break;
-            }
-        }
-    }
-    return (unsigned char)uRateCnt;
+       unsigned int ii, uu, uRateCnt = 0;
+
+       if ((pSrcRates == NULL) || (pDstRates == NULL))
+               return 0;
+
+       if (pSrcRates->len == 0)
+               return 0;
+
+       for (ii = 0; ii < uRateLen; ii++) {
+               for (uu = 0; uu < pSrcRates->len; uu++) {
+                       if ((pSrcRates->abyRates[uu] & 0x7F) == acbyIERate[ii]) {
+                               pDstRates->abyRates[uRateCnt++] = pSrcRates->abyRates[uu];
+                               break;
+                       }
+               }
+       }
+       return (unsigned char)uRateCnt;
 }
-
index 4f8ea0b0532d751f7b5866e46ba916da7da3502d..e4fad05ad8596bffa0c537c264f4e2ad320c3f1b 100644 (file)
 #define RETRY_TIMES_THRD_H         2    // times
 #define RETRY_TIMES_THRD_L         1    // times
 
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Types  ------------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
-
-
 void
 RATEvParseMaxRate(
-    void *pDeviceHandler,
-    PWLAN_IE_SUPP_RATES pItemRates,
-    PWLAN_IE_SUPP_RATES pItemExtRates,
-    bool bUpdateBasicRate,
-    unsigned short *pwMaxBasicRate,
-    unsigned short *pwMaxSuppRate,
-    unsigned short *pwSuppRate,
-    unsigned char *pbyTopCCKRate,
-    unsigned char *pbyTopOFDMRate
-    );
+       void *pDeviceHandler,
+       PWLAN_IE_SUPP_RATES pItemRates,
+       PWLAN_IE_SUPP_RATES pItemExtRates,
+       bool bUpdateBasicRate,
+       unsigned short *pwMaxBasicRate,
+       unsigned short *pwMaxSuppRate,
+       unsigned short *pwSuppRate,
+       unsigned char *pbyTopCCKRate,
+       unsigned char *pbyTopOFDMRate
+);
 
 void
 RATEvTxRateFallBack(
-    void *pDeviceHandler,
-    PKnownNodeDB psNodeDBTable
-    );
+       void *pDeviceHandler,
+       PKnownNodeDB psNodeDBTable
+);
 
 unsigned char
 RATEuSetIE(
-    PWLAN_IE_SUPP_RATES pSrcRates,
-    PWLAN_IE_SUPP_RATES pDstRates,
-    unsigned int uRateLen
-    );
+       PWLAN_IE_SUPP_RATES pSrcRates,
+       PWLAN_IE_SUPP_RATES pDstRates,
+       unsigned int uRateLen
+);
 
 unsigned short
 wGetRateIdx(
-    unsigned char byRate
-    );
-
+       unsigned char byRate
+);
 
 unsigned char
 DATARATEbyGetRateIdx(
-    unsigned char byRate
-    );
-
+       unsigned char byRate
+);
 
 #endif //__DATARATE_H__
index 084a1a5566adc57c4ba0a636e5fba3e8814806e1..32d808ec502a2aaff97156cac3d069e3674b6e95 100644 (file)
@@ -89,7 +89,7 @@
 
 // max transmit or receive buffer size
 #define CB_MAX_BUF_SIZE     2900U       // max buffer size
-                                        // NOTE: must be multiple of 4
+                                       // NOTE: must be multiple of 4
 #define CB_MAX_TX_BUF_SIZE          CB_MAX_BUF_SIZE // max Tx buffer size
 #define CB_MAX_RX_BUF_SIZE_NORMAL   CB_MAX_BUF_SIZE // max Rx buffer size when not use Multi-RD
 
 #define CB_MIN_TX_DESC      16          // min # of tx descriptor
 
 #define CB_MAX_RECEIVED_PACKETS     16  // max # of received packets at one time
-                                        // limit our receive routine to indicating
-                                        // this many at a time for 2 reasons:
-                                        // 1. driver flow control to protocol layer
-                                        // 2. limit the time used in ISR routine
+                                       // limit our receive routine to indicating
+                                       // this many at a time for 2 reasons:
+                                       // 1. driver flow control to protocol layer
+                                       // 2. limit the time used in ISR routine
 
 #define CB_EXTRA_RD_NUM     32          // default # of Extra RD
 #define CB_RD_NUM           32          // default # of RD
 #define CB_TD_NUM           32          // default # of TD
 
-
 // max number of physical segments
 // in a single NDIS packet. Above this threshold, the packet
 // is copied into a single physically contiguous buffer
 
 #define CB_PROTOCOL_RESERVED_SECTION    16
 
-
-
 // if retrys excess 15 times , tx will abort, and
 // if tx fifo underflow, tx will fail
 // we should try to resend it
 #define TYPE_RXDMA1     1
 #define TYPE_MAXRD      2
 
-
-
 // TD_INFO flags control bit
 #define TD_FLAGS_NETIF_SKB               0x01       // check if need release skb
 #define TD_FLAGS_PRIV_SKB                0x02       // check if called from private skb(hostap)
 // may link to older skb that leads error.
 
 typedef struct tagDEVICE_RD_INFO {
-    struct sk_buff* skb;
-    dma_addr_t  skb_dma;
-    dma_addr_t  curr_desc;
+       struct sk_buff *skb;
+       dma_addr_t  skb_dma;
+       dma_addr_t  curr_desc;
 } DEVICE_RD_INFO,   *PDEVICE_RD_INFO;
 
 /*
-static inline PDEVICE_RD_INFO alloc_rd_info(void) {
-    PDEVICE_RD_INFO  ptr;
-    ptr = kmalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC);
-    if (ptr == NULL)
-        return NULL;
-    else {
-        memset(ptr,0,sizeof(DEVICE_RD_INFO));
-        return ptr;
-    }
-}
+  static inline PDEVICE_RD_INFO alloc_rd_info(void) {
+  PDEVICE_RD_INFO  ptr;
+  ptr = kmalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC);
+  if (ptr == NULL)
+  return NULL;
+  else {
+  memset(ptr,0,sizeof(DEVICE_RD_INFO));
+  return ptr;
+  }
+  }
 */
 
 /*
-typedef struct tagRDES0 {
-    unsigned short wResCount;
-    unsigned short wf1Owner ;
+  typedef struct tagRDES0 {
+  unsigned short wResCount;
+  unsigned short wf1Owner;
 //    unsigned short f15Reserved : 15;
 //    unsigned short f1Owner : 1;
 } __attribute__ ((__packed__))
@@ -244,11 +239,11 @@ SRDES0;
 #ifdef __BIG_ENDIAN
 
 typedef struct tagRDES0 {
-   volatile unsigned short wResCount;
+       volatile unsigned short wResCount;
        union {
                volatile u16    f15Reserved;
                struct {
-            volatile u8 f8Reserved1;
+                       volatile u8 f8Reserved1;
                        volatile u8 f1Owner:1;
                        volatile u8 f7Reserved:7;
                } __attribute__ ((__packed__));
@@ -259,18 +254,17 @@ SRDES0, *PSRDES0;
 #else
 
 typedef struct tagRDES0 {
-    unsigned short wResCount;
-    unsigned short f15Reserved : 15;
-    unsigned short f1Owner : 1;
+       unsigned short wResCount;
+       unsigned short f15Reserved:15;
+       unsigned short f1Owner:1;
 } __attribute__ ((__packed__))
 SRDES0;
 
-
 #endif
 
 typedef struct tagRDES1 {
-    unsigned short wReqCount;
-    unsigned short wReserved;
+       unsigned short wReqCount;
+       unsigned short wReserved;
 } __attribute__ ((__packed__))
 SRDES1;
 
@@ -278,13 +272,13 @@ SRDES1;
 // Rx descriptor
 //
 typedef struct tagSRxDesc {
-    volatile SRDES0 m_rd0RD0;
-    volatile SRDES1 m_rd1RD1;
-    volatile u32    buff_addr;
-    volatile u32    next_desc;
-    struct tagSRxDesc   *next;//4 bytes
-    volatile PDEVICE_RD_INFO    pRDInfo;//4 bytes
-    volatile u32    Reserved[2];//8 bytes
+       volatile SRDES0 m_rd0RD0;
+       volatile SRDES1 m_rd1RD1;
+       volatile u32    buff_addr;
+       volatile u32    next_desc;
+       struct tagSRxDesc   *next;//4 bytes
+       volatile PDEVICE_RD_INFO    pRDInfo;//4 bytes
+       volatile u32    Reserved[2];//8 bytes
 } __attribute__ ((__packed__))
 SRxDesc, *PSRxDesc;
 typedef const SRxDesc *PCSRxDesc;
@@ -292,10 +286,10 @@ typedef const SRxDesc *PCSRxDesc;
 #ifdef __BIG_ENDIAN
 
 /*
-typedef struct tagTDES0 {
-    volatile    unsigned char byTSR0;
-    volatile    unsigned char byTSR1;
-    volatile    unsigned short wOwner_Txtime;
+  typedef struct tagTDES0 {
+  volatile    unsigned char byTSR0;
+  volatile    unsigned char byTSR1;
+  volatile    unsigned short wOwner_Txtime;
 //    volatile    unsigned short f15Txtime : 15;
 //    volatile    unsigned short f1Owner:1;
 } __attribute__ ((__packed__))
@@ -303,12 +297,12 @@ STDES0;
 */
 
 typedef struct tagTDES0 {
-    volatile    unsigned char byTSR0;
-    volatile    unsigned char byTSR1;
+       volatile    unsigned char byTSR0;
+       volatile    unsigned char byTSR1;
        union {
                volatile u16    f15Txtime;
                struct {
-            volatile u8 f8Reserved1;
+                       volatile u8 f8Reserved1;
                        volatile u8 f1Owner:1;
                        volatile u8 f7Reserved:7;
                } __attribute__ ((__packed__));
@@ -319,113 +313,109 @@ STDES0, PSTDES0;
 #else
 
 typedef struct tagTDES0 {
-    volatile    unsigned char byTSR0;
-    volatile    unsigned char byTSR1;
-    volatile    unsigned short f15Txtime : 15;
-    volatile    unsigned short f1Owner:1;
+       volatile    unsigned char byTSR0;
+       volatile    unsigned char byTSR1;
+       volatile    unsigned short f15Txtime:15;
+       volatile    unsigned short f1Owner:1;
 } __attribute__ ((__packed__))
 STDES0;
 
 #endif
 
-
 typedef struct tagTDES1 {
-    volatile    unsigned short wReqCount;
-    volatile    unsigned char byTCR;
-    volatile    unsigned char byReserved;
+       volatile    unsigned short wReqCount;
+       volatile    unsigned char byTCR;
+       volatile    unsigned char byReserved;
 } __attribute__ ((__packed__))
 STDES1;
 
-
-typedef struct tagDEVICE_TD_INFO{
-    struct sk_buff*     skb;
-    unsigned char *buf;
-    dma_addr_t          skb_dma;
-    dma_addr_t          buf_dma;
-    dma_addr_t          curr_desc;
-    unsigned long dwReqCount;
-    unsigned long dwHeaderLength;
-    unsigned char byFlags;
+typedef struct tagDEVICE_TD_INFO {
+       struct sk_buff *skb;
+       unsigned char *buf;
+       dma_addr_t          skb_dma;
+       dma_addr_t          buf_dma;
+       dma_addr_t          curr_desc;
+       unsigned long dwReqCount;
+       unsigned long dwHeaderLength;
+       unsigned char byFlags;
 } DEVICE_TD_INFO,    *PDEVICE_TD_INFO;
 
 /*
-static inline PDEVICE_TD_INFO alloc_td_info(void) {
-    PDEVICE_TD_INFO  ptr;
-    ptr = kmalloc(sizeof(DEVICE_TD_INFO),GFP_ATOMIC);
-    if (ptr == NULL)
-        return NULL;
-    else {
-        memset(ptr,0,sizeof(DEVICE_TD_INFO));
-        return ptr;
-    }
-}
+  static inline PDEVICE_TD_INFO alloc_td_info(void) {
+  PDEVICE_TD_INFO  ptr;
+  ptr = kmalloc(sizeof(DEVICE_TD_INFO),GFP_ATOMIC);
+  if (ptr == NULL)
+  return NULL;
+  else {
+  memset(ptr,0,sizeof(DEVICE_TD_INFO));
+  return ptr;
+  }
+  }
 */
 
 //
 // transmit descriptor
 //
 typedef struct tagSTxDesc {
-    volatile    STDES0  m_td0TD0;
-    volatile    STDES1  m_td1TD1;
-    volatile    u32    buff_addr;
-    volatile    u32    next_desc;
-    struct tagSTxDesc*  next; //4 bytes
-    volatile    PDEVICE_TD_INFO pTDInfo;//4 bytes
-    volatile    u32    Reserved[2];//8 bytes
+       volatile    STDES0  m_td0TD0;
+       volatile    STDES1  m_td1TD1;
+       volatile    u32    buff_addr;
+       volatile    u32    next_desc;
+       struct tagSTxDesc *next; //4 bytes
+       volatile    PDEVICE_TD_INFO pTDInfo;//4 bytes
+       volatile    u32    Reserved[2];//8 bytes
 } __attribute__ ((__packed__))
 STxDesc, *PSTxDesc;
 typedef const STxDesc *PCSTxDesc;
 
-
 typedef struct tagSTxSyncDesc {
-    volatile    STDES0  m_td0TD0;
-    volatile    STDES1  m_td1TD1;
-    volatile    u32 buff_addr; // pointer to logical buffer
-    volatile    u32 next_desc; // pointer to next logical descriptor
-    volatile    unsigned short m_wFIFOCtl;
-    volatile    unsigned short m_wTimeStamp;
-    struct tagSTxSyncDesc*  next; //4 bytes
-    volatile    PDEVICE_TD_INFO pTDInfo;//4 bytes
-    volatile    u32 m_dwReserved2;
+       volatile    STDES0  m_td0TD0;
+       volatile    STDES1  m_td1TD1;
+       volatile    u32 buff_addr; // pointer to logical buffer
+       volatile    u32 next_desc; // pointer to next logical descriptor
+       volatile    unsigned short m_wFIFOCtl;
+       volatile    unsigned short m_wTimeStamp;
+       struct tagSTxSyncDesc *next; //4 bytes
+       volatile    PDEVICE_TD_INFO pTDInfo;//4 bytes
+       volatile    u32 m_dwReserved2;
 } __attribute__ ((__packed__))
 STxSyncDesc, *PSTxSyncDesc;
 typedef const STxSyncDesc *PCSTxSyncDesc;
 
-
 //
 // RsvTime buffer header
 //
 typedef struct tagSRrvTime_gRTS {
-    unsigned short wRTSTxRrvTime_ba;
-    unsigned short wRTSTxRrvTime_aa;
-    unsigned short wRTSTxRrvTime_bb;
-    unsigned short wReserved;
-    unsigned short wTxRrvTime_b;
-    unsigned short wTxRrvTime_a;
-}__attribute__ ((__packed__))
+       unsigned short wRTSTxRrvTime_ba;
+       unsigned short wRTSTxRrvTime_aa;
+       unsigned short wRTSTxRrvTime_bb;
+       unsigned short wReserved;
+       unsigned short wTxRrvTime_b;
+       unsigned short wTxRrvTime_a;
+} __attribute__ ((__packed__))
 SRrvTime_gRTS, *PSRrvTime_gRTS;
 typedef const SRrvTime_gRTS *PCSRrvTime_gRTS;
 
 typedef struct tagSRrvTime_gCTS {
-    unsigned short wCTSTxRrvTime_ba;
-    unsigned short wReserved;
-    unsigned short wTxRrvTime_b;
-    unsigned short wTxRrvTime_a;
-}__attribute__ ((__packed__))
+       unsigned short wCTSTxRrvTime_ba;
+       unsigned short wReserved;
+       unsigned short wTxRrvTime_b;
+       unsigned short wTxRrvTime_a;
+} __attribute__ ((__packed__))
 SRrvTime_gCTS, *PSRrvTime_gCTS;
 typedef const SRrvTime_gCTS *PCSRrvTime_gCTS;
 
 typedef struct tagSRrvTime_ab {
-    unsigned short wRTSTxRrvTime;
-    unsigned short wTxRrvTime;
-}__attribute__ ((__packed__))
+       unsigned short wRTSTxRrvTime;
+       unsigned short wTxRrvTime;
+} __attribute__ ((__packed__))
 SRrvTime_ab, *PSRrvTime_ab;
 typedef const SRrvTime_ab *PCSRrvTime_ab;
 
 typedef struct tagSRrvTime_atim {
-    unsigned short wCTSTxRrvTime_ba;
-    unsigned short wTxRrvTime_a;
-}__attribute__ ((__packed__))
+       unsigned short wCTSTxRrvTime_ba;
+       unsigned short wTxRrvTime_a;
+} __attribute__ ((__packed__))
 SRrvTime_atim, *PSRrvTime_atim;
 typedef const SRrvTime_atim *PCSRrvTime_atim;
 
@@ -433,132 +423,127 @@ typedef const SRrvTime_atim *PCSRrvTime_atim;
 // RTS buffer header
 //
 typedef struct tagSRTSData {
-    unsigned short wFrameControl;
-    unsigned short wDurationID;
-    unsigned char abyRA[ETH_ALEN];
-    unsigned char abyTA[ETH_ALEN];
-}__attribute__ ((__packed__))
+       unsigned short wFrameControl;
+       unsigned short wDurationID;
+       unsigned char abyRA[ETH_ALEN];
+       unsigned char abyTA[ETH_ALEN];
+} __attribute__ ((__packed__))
 SRTSData, *PSRTSData;
 typedef const SRTSData *PCSRTSData;
 
 typedef struct tagSRTS_g {
-    unsigned char bySignalField_b;
-    unsigned char byServiceField_b;
-    unsigned short wTransmitLength_b;
-    unsigned char bySignalField_a;
-    unsigned char byServiceField_a;
-    unsigned short wTransmitLength_a;
-    unsigned short wDuration_ba;
-    unsigned short wDuration_aa;
-    unsigned short wDuration_bb;
-    unsigned short wReserved;
-    SRTSData    Data;
-}__attribute__ ((__packed__))
+       unsigned char bySignalField_b;
+       unsigned char byServiceField_b;
+       unsigned short wTransmitLength_b;
+       unsigned char bySignalField_a;
+       unsigned char byServiceField_a;
+       unsigned short wTransmitLength_a;
+       unsigned short wDuration_ba;
+       unsigned short wDuration_aa;
+       unsigned short wDuration_bb;
+       unsigned short wReserved;
+       SRTSData    Data;
+} __attribute__ ((__packed__))
 SRTS_g, *PSRTS_g;
 typedef const SRTS_g *PCSRTS_g;
 
-
 typedef struct tagSRTS_g_FB {
-    unsigned char bySignalField_b;
-    unsigned char byServiceField_b;
-    unsigned short wTransmitLength_b;
-    unsigned char bySignalField_a;
-    unsigned char byServiceField_a;
-    unsigned short wTransmitLength_a;
-    unsigned short wDuration_ba;
-    unsigned short wDuration_aa;
-    unsigned short wDuration_bb;
-    unsigned short wReserved;
-    unsigned short wRTSDuration_ba_f0;
-    unsigned short wRTSDuration_aa_f0;
-    unsigned short wRTSDuration_ba_f1;
-    unsigned short wRTSDuration_aa_f1;
-    SRTSData    Data;
-}__attribute__ ((__packed__))
+       unsigned char bySignalField_b;
+       unsigned char byServiceField_b;
+       unsigned short wTransmitLength_b;
+       unsigned char bySignalField_a;
+       unsigned char byServiceField_a;
+       unsigned short wTransmitLength_a;
+       unsigned short wDuration_ba;
+       unsigned short wDuration_aa;
+       unsigned short wDuration_bb;
+       unsigned short wReserved;
+       unsigned short wRTSDuration_ba_f0;
+       unsigned short wRTSDuration_aa_f0;
+       unsigned short wRTSDuration_ba_f1;
+       unsigned short wRTSDuration_aa_f1;
+       SRTSData    Data;
+} __attribute__ ((__packed__))
 SRTS_g_FB, *PSRTS_g_FB;
 typedef const SRTS_g_FB *PCSRTS_g_FB;
 
-
 typedef struct tagSRTS_ab {
-    unsigned char bySignalField;
-    unsigned char byServiceField;
-    unsigned short wTransmitLength;
-    unsigned short wDuration;
-    unsigned short wReserved;
-    SRTSData    Data;
-}__attribute__ ((__packed__))
+       unsigned char bySignalField;
+       unsigned char byServiceField;
+       unsigned short wTransmitLength;
+       unsigned short wDuration;
+       unsigned short wReserved;
+       SRTSData    Data;
+} __attribute__ ((__packed__))
 SRTS_ab, *PSRTS_ab;
 typedef const SRTS_ab *PCSRTS_ab;
 
-
 typedef struct tagSRTS_a_FB {
-    unsigned char bySignalField;
-    unsigned char byServiceField;
-    unsigned short wTransmitLength;
-    unsigned short wDuration;
-    unsigned short wReserved;
-    unsigned short wRTSDuration_f0;
-    unsigned short wRTSDuration_f1;
-    SRTSData    Data;
-}__attribute__ ((__packed__))
+       unsigned char bySignalField;
+       unsigned char byServiceField;
+       unsigned short wTransmitLength;
+       unsigned short wDuration;
+       unsigned short wReserved;
+       unsigned short wRTSDuration_f0;
+       unsigned short wRTSDuration_f1;
+       SRTSData    Data;
+} __attribute__ ((__packed__))
 SRTS_a_FB, *PSRTS_a_FB;
 typedef const SRTS_a_FB *PCSRTS_a_FB;
 
-
 //
 // CTS buffer header
 //
 typedef struct tagSCTSData {
-    unsigned short wFrameControl;
-    unsigned short wDurationID;
-    unsigned char abyRA[ETH_ALEN];
-    unsigned short wReserved;
-}__attribute__ ((__packed__))
+       unsigned short wFrameControl;
+       unsigned short wDurationID;
+       unsigned char abyRA[ETH_ALEN];
+       unsigned short wReserved;
+} __attribute__ ((__packed__))
 SCTSData, *PSCTSData;
 
 typedef struct tagSCTS {
-    unsigned char bySignalField_b;
-    unsigned char byServiceField_b;
-    unsigned short wTransmitLength_b;
-    unsigned short wDuration_ba;
-    unsigned short wReserved;
-    SCTSData    Data;
-}__attribute__ ((__packed__))
+       unsigned char bySignalField_b;
+       unsigned char byServiceField_b;
+       unsigned short wTransmitLength_b;
+       unsigned short wDuration_ba;
+       unsigned short wReserved;
+       SCTSData    Data;
+} __attribute__ ((__packed__))
 SCTS, *PSCTS;
 typedef const SCTS *PCSCTS;
 
 typedef struct tagSCTS_FB {
-    unsigned char bySignalField_b;
-    unsigned char byServiceField_b;
-    unsigned short wTransmitLength_b;
-    unsigned short wDuration_ba;
-    unsigned short wReserved;
-    unsigned short wCTSDuration_ba_f0;
-    unsigned short wCTSDuration_ba_f1;
-    SCTSData    Data;
-}__attribute__ ((__packed__))
+       unsigned char bySignalField_b;
+       unsigned char byServiceField_b;
+       unsigned short wTransmitLength_b;
+       unsigned short wDuration_ba;
+       unsigned short wReserved;
+       unsigned short wCTSDuration_ba_f0;
+       unsigned short wCTSDuration_ba_f1;
+       SCTSData    Data;
+} __attribute__ ((__packed__))
 SCTS_FB, *PSCTS_FB;
 typedef const SCTS_FB *PCSCTS_FB;
 
-
 //
 // Tx FIFO header
 //
 typedef struct tagSTxBufHead {
-    u32 adwTxKey[4];
-    unsigned short wFIFOCtl;
-    unsigned short wTimeStamp;
-    unsigned short wFragCtl;
-    unsigned char byTxPower;
-    unsigned char wReserved;
-}__attribute__ ((__packed__))
+       u32 adwTxKey[4];
+       unsigned short wFIFOCtl;
+       unsigned short wTimeStamp;
+       unsigned short wFragCtl;
+       unsigned char byTxPower;
+       unsigned char wReserved;
+} __attribute__ ((__packed__))
 STxBufHead, *PSTxBufHead;
 typedef const STxBufHead *PCSTxBufHead;
 
 typedef struct tagSTxShortBufHead {
-    unsigned short wFIFOCtl;
-    unsigned short wTimeStamp;
-}__attribute__ ((__packed__))
+       unsigned short wFIFOCtl;
+       unsigned short wTimeStamp;
+} __attribute__ ((__packed__))
 STxShortBufHead, *PSTxShortBufHead;
 typedef const STxShortBufHead *PCSTxShortBufHead;
 
@@ -566,58 +551,56 @@ typedef const STxShortBufHead *PCSTxShortBufHead;
 // Tx data header
 //
 typedef struct tagSTxDataHead_g {
-    unsigned char bySignalField_b;
-    unsigned char byServiceField_b;
-    unsigned short wTransmitLength_b;
-    unsigned char bySignalField_a;
-    unsigned char byServiceField_a;
-    unsigned short wTransmitLength_a;
-    unsigned short wDuration_b;
-    unsigned short wDuration_a;
-    unsigned short wTimeStampOff_b;
-    unsigned short wTimeStampOff_a;
-}__attribute__ ((__packed__))
+       unsigned char bySignalField_b;
+       unsigned char byServiceField_b;
+       unsigned short wTransmitLength_b;
+       unsigned char bySignalField_a;
+       unsigned char byServiceField_a;
+       unsigned short wTransmitLength_a;
+       unsigned short wDuration_b;
+       unsigned short wDuration_a;
+       unsigned short wTimeStampOff_b;
+       unsigned short wTimeStampOff_a;
+} __attribute__ ((__packed__))
 STxDataHead_g, *PSTxDataHead_g;
 typedef const STxDataHead_g *PCSTxDataHead_g;
 
 typedef struct tagSTxDataHead_g_FB {
-    unsigned char bySignalField_b;
-    unsigned char byServiceField_b;
-    unsigned short wTransmitLength_b;
-    unsigned char bySignalField_a;
-    unsigned char byServiceField_a;
-    unsigned short wTransmitLength_a;
-    unsigned short wDuration_b;
-    unsigned short wDuration_a;
-    unsigned short wDuration_a_f0;
-    unsigned short wDuration_a_f1;
-    unsigned short wTimeStampOff_b;
-    unsigned short wTimeStampOff_a;
-}__attribute__ ((__packed__))
+       unsigned char bySignalField_b;
+       unsigned char byServiceField_b;
+       unsigned short wTransmitLength_b;
+       unsigned char bySignalField_a;
+       unsigned char byServiceField_a;
+       unsigned short wTransmitLength_a;
+       unsigned short wDuration_b;
+       unsigned short wDuration_a;
+       unsigned short wDuration_a_f0;
+       unsigned short wDuration_a_f1;
+       unsigned short wTimeStampOff_b;
+       unsigned short wTimeStampOff_a;
+} __attribute__ ((__packed__))
 STxDataHead_g_FB, *PSTxDataHead_g_FB;
 typedef const STxDataHead_g_FB *PCSTxDataHead_g_FB;
 
-
 typedef struct tagSTxDataHead_ab {
-    unsigned char bySignalField;
-    unsigned char byServiceField;
-    unsigned short wTransmitLength;
-    unsigned short wDuration;
-    unsigned short wTimeStampOff;
-}__attribute__ ((__packed__))
+       unsigned char bySignalField;
+       unsigned char byServiceField;
+       unsigned short wTransmitLength;
+       unsigned short wDuration;
+       unsigned short wTimeStampOff;
+} __attribute__ ((__packed__))
 STxDataHead_ab, *PSTxDataHead_ab;
 typedef const STxDataHead_ab *PCSTxDataHead_ab;
 
-
 typedef struct tagSTxDataHead_a_FB {
-    unsigned char bySignalField;
-    unsigned char byServiceField;
-    unsigned short wTransmitLength;
-    unsigned short wDuration;
-    unsigned short wTimeStampOff;
-    unsigned short wDuration_f0;
-    unsigned short wDuration_f1;
-}__attribute__ ((__packed__))
+       unsigned char bySignalField;
+       unsigned char byServiceField;
+       unsigned short wTransmitLength;
+       unsigned short wDuration;
+       unsigned short wTimeStampOff;
+       unsigned short wDuration_f0;
+       unsigned short wDuration_f1;
+} __attribute__ ((__packed__))
 STxDataHead_a_FB, *PSTxDataHead_a_FB;
 typedef const STxDataHead_a_FB *PCSTxDataHead_a_FB;
 
@@ -625,38 +608,37 @@ typedef const STxDataHead_a_FB *PCSTxDataHead_a_FB;
 // MICHDR data header
 //
 typedef struct tagSMICHDRHead {
-    u32 adwHDR0[4];
-    u32 adwHDR1[4];
-    u32 adwHDR2[4];
-}__attribute__ ((__packed__))
+       u32 adwHDR0[4];
+       u32 adwHDR1[4];
+       u32 adwHDR2[4];
+} __attribute__ ((__packed__))
 SMICHDRHead, *PSMICHDRHead;
 typedef const SMICHDRHead *PCSMICHDRHead;
 
 typedef struct tagSBEACONCtl {
-    u32 BufReady : 1;
-    u32 TSF      : 15;
-    u32 BufLen   : 11;
-    u32 Reserved : 5;
-}__attribute__ ((__packed__))
+       u32 BufReady:1;
+       u32 TSF:15;
+       u32 BufLen:11;
+       u32 Reserved:5;
+} __attribute__ ((__packed__))
 SBEACONCtl;
 
-
 typedef struct tagSSecretKey {
-    u32 dwLowDword;
-    unsigned char byHighByte;
-}__attribute__ ((__packed__))
+       u32 dwLowDword;
+       unsigned char byHighByte;
+} __attribute__ ((__packed__))
 SSecretKey;
 
 typedef struct tagSKeyEntry {
-    unsigned char abyAddrHi[2];
-    unsigned short wKCTL;
-    unsigned char abyAddrLo[4];
-    u32 dwKey0[4];
-    u32 dwKey1[4];
-    u32 dwKey2[4];
-    u32 dwKey3[4];
-    u32 dwKey4[4];
-}__attribute__ ((__packed__))
+       unsigned char abyAddrHi[2];
+       unsigned short wKCTL;
+       unsigned char abyAddrLo[4];
+       u32 dwKey0[4];
+       u32 dwKey1[4];
+       u32 dwKey2[4];
+       u32 dwKey3[4];
+       u32 dwKey4[4];
+} __attribute__ ((__packed__))
 SKeyEntry;
 /*---------------------  Export Macros ------------------------------*/
 
@@ -666,8 +648,4 @@ SKeyEntry;
 
 /*---------------------  Export Functions  --------------------------*/
 
-
-
-
 #endif // __DESC_H__
-
index e27244ce383e4f92865122027a5753e110ae47f9..ca1b8578cf79f9f5d252b624c36a2b1081ad2aa7 100644 (file)
@@ -87,7 +87,6 @@
 #include "key.h"
 #include "mac.h"
 
-
 /*---------------------  Export Definitions -------------------------*/
 
 #define MAC_MAX_CONTEXT_REG     (256+128)
 #define KEYSEL_TKIP                     2
 #define KEYSEL_CCMP                     3
 
-
-
 #define AUTO_FB_NONE            0
 #define AUTO_FB_0               1
 #define AUTO_FB_1               2
 #define BB_VGA_LEVEL            4
 #define BB_VGA_CHANGE_THRESHOLD 16
 
-
-
 #ifndef RUN_AT
 #define RUN_AT(x)                       (jiffies+(x))
 #endif
 // DMA related
 #define RESERV_AC0DMA                   4
 
-
 // BUILD OBJ mode
 
-
-#define        AVAIL_TD(p,q)   ((p)->sOpts.nTxDescs[(q)]-((p)->iTDUsed[(q)]))
+#define        AVAIL_TD(p, q)  ((p)->sOpts.nTxDescs[(q)] - ((p)->iTDUsed[(q)]))
 
 //PLICE_DEBUG ->
 #define        NUM                             64
 //PLICE_DEUBG <-
 
-
-
 #define PRIVATE_Message                 0
 
 /*---------------------  Export Types  ------------------------------*/
 
-
-#define DBG_PRT(l, p, args...) {if (l<=msglevel) printk( p ,##args);}
-#define PRINT_K(p, args...) {if (PRIVATE_Message) printk( p ,##args);}
+#define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
+#define PRINT_K(p, args...) { if (PRIVATE_Message) printk(p, ##args); }
 
 //0:11A 1:11B 2:11G
 typedef enum _VIA_BB_TYPE
 {
-    BB_TYPE_11A=0,
-    BB_TYPE_11B,
-    BB_TYPE_11G
+       BB_TYPE_11A = 0,
+       BB_TYPE_11B,
+       BB_TYPE_11G
 } VIA_BB_TYPE, *PVIA_BB_TYPE;
 
 //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
 typedef enum _VIA_PKT_TYPE
 {
-    PK_TYPE_11A=0,
-    PK_TYPE_11B,
-    PK_TYPE_11GB,
-    PK_TYPE_11GA
+       PK_TYPE_11A = 0,
+       PK_TYPE_11B,
+       PK_TYPE_11GB,
+       PK_TYPE_11GA
 } VIA_PKT_TYPE, *PVIA_PKT_TYPE;
 
-
 typedef enum __device_msg_level {
-    MSG_LEVEL_ERR=0,            //Errors that will cause abnormal operation.
-    MSG_LEVEL_NOTICE=1,         //Some errors need users to be notified.
-    MSG_LEVEL_INFO=2,           //Normal message.
-    MSG_LEVEL_VERBOSE=3,        //Will report all trival errors.
-    MSG_LEVEL_DEBUG=4           //Only for debug purpose.
+       MSG_LEVEL_ERR = 0,            //Errors that will cause abnormal operation.
+       MSG_LEVEL_NOTICE = 1,         //Some errors need users to be notified.
+       MSG_LEVEL_INFO = 2,           //Normal message.
+       MSG_LEVEL_VERBOSE = 3,        //Will report all trival errors.
+       MSG_LEVEL_DEBUG = 4           //Only for debug purpose.
 } DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL;
 
 typedef enum __device_init_type {
-    DEVICE_INIT_COLD=0,         // cold init
-    DEVICE_INIT_RESET,          // reset init or Dx to D0 power remain init
-    DEVICE_INIT_DXPL            // Dx to D0 power lost init
+       DEVICE_INIT_COLD = 0,         // cold init
+       DEVICE_INIT_RESET,          // reset init or Dx to D0 power remain init
+       DEVICE_INIT_DXPL            // Dx to D0 power lost init
 } DEVICE_INIT_TYPE, *PDEVICE_INIT_TYPE;
 
-
 //++ NDIS related
 
 #define MAX_BSSIDINFO_4_PMKID   16
@@ -205,57 +193,54 @@ typedef enum __device_init_type {
 // PMKID Structures
 typedef unsigned char NDIS_802_11_PMKID_VALUE[16];
 
-
 typedef enum _NDIS_802_11_WEP_STATUS
 {
-    Ndis802_11WEPEnabled,
-    Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
-    Ndis802_11WEPDisabled,
-    Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
-    Ndis802_11WEPKeyAbsent,
-    Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
-    Ndis802_11WEPNotSupported,
-    Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
-    Ndis802_11Encryption2Enabled,
-    Ndis802_11Encryption2KeyAbsent,
-    Ndis802_11Encryption3Enabled,
-    Ndis802_11Encryption3KeyAbsent
+       Ndis802_11WEPEnabled,
+       Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
+       Ndis802_11WEPDisabled,
+       Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
+       Ndis802_11WEPKeyAbsent,
+       Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
+       Ndis802_11WEPNotSupported,
+       Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
+       Ndis802_11Encryption2Enabled,
+       Ndis802_11Encryption2KeyAbsent,
+       Ndis802_11Encryption3Enabled,
+       Ndis802_11Encryption3KeyAbsent
 } NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
-  NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
-
+       NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
 
 typedef enum _NDIS_802_11_STATUS_TYPE
 {
-    Ndis802_11StatusType_Authentication,
-    Ndis802_11StatusType_MediaStreamMode,
-    Ndis802_11StatusType_PMKID_CandidateList,
-    Ndis802_11StatusTypeMax    // not a real type, defined as an upper bound
+       Ndis802_11StatusType_Authentication,
+       Ndis802_11StatusType_MediaStreamMode,
+       Ndis802_11StatusType_PMKID_CandidateList,
+       Ndis802_11StatusTypeMax    // not a real type, defined as an upper bound
 } NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
 
 //Added new types for PMKID Candidate lists.
 typedef struct _PMKID_CANDIDATE {
-    NDIS_802_11_MAC_ADDRESS BSSID;
-    unsigned long Flags;
+       NDIS_802_11_MAC_ADDRESS BSSID;
+       unsigned long Flags;
 } PMKID_CANDIDATE, *PPMKID_CANDIDATE;
 
-
 typedef struct _BSSID_INFO
 {
-    NDIS_802_11_MAC_ADDRESS BSSID;
-    NDIS_802_11_PMKID_VALUE PMKID;
+       NDIS_802_11_MAC_ADDRESS BSSID;
+       NDIS_802_11_PMKID_VALUE PMKID;
 } BSSID_INFO, *PBSSID_INFO;
 
 typedef struct tagSPMKID {
-    unsigned long Length;
-    unsigned long BSSIDInfoCount;
-    BSSID_INFO BSSIDInfo[MAX_BSSIDINFO_4_PMKID];
+       unsigned long Length;
+       unsigned long BSSIDInfoCount;
+       BSSID_INFO BSSIDInfo[MAX_BSSIDINFO_4_PMKID];
 } SPMKID, *PSPMKID;
 
 typedef struct tagSPMKIDCandidateEvent {
-    NDIS_802_11_STATUS_TYPE     StatusType;
-    unsigned long Version;       // Version of the structure
-    unsigned long NumCandidates; // No. of pmkid candidates
-    PMKID_CANDIDATE CandidateList[MAX_PMKIDLIST];
+       NDIS_802_11_STATUS_TYPE     StatusType;
+       unsigned long Version;       // Version of the structure
+       unsigned long NumCandidates; // No. of pmkid candidates
+       PMKID_CANDIDATE CandidateList[MAX_PMKIDLIST];
 } SPMKIDCandidateEvent, *PSPMKIDCandidateEvent;
 
 //--
@@ -264,58 +249,54 @@ typedef struct tagSPMKIDCandidateEvent {
 #define MAX_QUIET_COUNT     8
 
 typedef struct tagSQuietControl {
-    bool bEnable;
-    unsigned long dwStartTime;
-    unsigned char byPeriod;
-    unsigned short wDuration;
+       bool bEnable;
+       unsigned long dwStartTime;
+       unsigned char byPeriod;
+       unsigned short wDuration;
 } SQuietControl, *PSQuietControl;
 
 //--
-typedef struct __chip_info_tbl{
-    CHIP_TYPE   chip_id;
-    char*       name;
-    int         io_size;
-    int         nTxQueue;
-    u32         flags;
+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
+       OWNED_BY_HOST = 0,
+       OWNED_BY_NIC = 1
 } DEVICE_OWNER_TYPE, *PDEVICE_OWNER_TYPE;
 
-
 // The receive duplicate detection cache entry
-typedef struct tagSCacheEntry{
-    unsigned short wFmSequence;
-    unsigned char abyAddr2[ETH_ALEN];
+typedef struct tagSCacheEntry {
+       unsigned short wFmSequence;
+       unsigned char abyAddr2[ETH_ALEN];
 } SCacheEntry, *PSCacheEntry;
 
-typedef struct tagSCache{
+typedef struct tagSCache {
 /* The receive cache is updated circularly.  The next entry to be written is
  * indexed by the "InPtr".
-*/
-    unsigned int uInPtr;         // Place to use next
-    SCacheEntry     asCacheEntry[DUPLICATE_RX_CACHE_LENGTH];
+ */
+       unsigned int uInPtr;         // Place to use next
+       SCacheEntry     asCacheEntry[DUPLICATE_RX_CACHE_LENGTH];
 } SCache, *PSCache;
 
 #define CB_MAX_RX_FRAG                 64
 // DeFragment Control Block, used for collecting fragments prior to reassembly
 typedef struct tagSDeFragControlBlock
 {
-    unsigned short wSequence;
-    unsigned short wFragNum;
-    unsigned char abyAddr2[ETH_ALEN];
-    unsigned int uLifetime;
-    struct sk_buff* skb;
-    unsigned char *pbyRxBuffer;
-    unsigned int cbFrameLength;
-    bool bInUse;
+       unsigned short wSequence;
+       unsigned short wFragNum;
+       unsigned char abyAddr2[ETH_ALEN];
+       unsigned int uLifetime;
+       struct sk_buff *skb;
+       unsigned char *pbyRxBuffer;
+       unsigned int cbFrameLength;
+       bool bInUse;
 } SDeFragControlBlock, *PSDeFragControlBlock;
 
-
-
 //flags for options
 #define     DEVICE_FLAGS_IP_ALIGN        0x00000001UL
 #define     DEVICE_FLAGS_PREAMBLE_TYPE   0x00000002UL
@@ -343,511 +324,474 @@ typedef struct tagSDeFragControlBlock
 //for device_set_media_duplex
 #define     DEVICE_LINK_CHANGE           0x00000001UL
 
-
 //PLICE_DEBUG->
 
-
 typedef        struct _RxManagementQueue
 {
        int     packet_num;
-       int     head,tail;
+       int     head, tail;
        PSRxMgmtPacket  Q[NUM];
-} RxManagementQueue,*PSRxManagementQueue;
-
-
+} RxManagementQueue, *PSRxManagementQueue;
 
 //PLICE_DEBUG<-
 
-
 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         rts_thresh;   //rts threshold
-    int         frag_thresh;
-    int         data_rate;
-    int         channel_num;
-    int         short_retry;
-    int         long_retry;
-    int         bbp_type;
-    u32         flags;
+       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         rts_thresh;   //rts threshold
+       int         frag_thresh;
+       int         data_rate;
+       int         channel_num;
+       int         short_retry;
+       int         long_retry;
+       int         bbp_type;
+       u32         flags;
 } OPTIONS, *POPTIONS;
 
-
 typedef struct __device_info {
-    struct __device_info*        next;
-    struct __device_info*        prev;
+       struct __device_info *next;
+       struct __device_info *prev;
 
-    struct pci_dev*             pcid;
+       struct pci_dev *pcid;
 
 #ifdef CONFIG_PM
-    u32                         pci_state[16];
+       u32                         pci_state[16];
 #endif
 
 // netdev
-    struct net_device*          dev;
-    struct net_device*          next_module;
-    struct net_device_stats     stats;
+       struct net_device *dev;
+       struct net_device *next_module;
+       struct net_device_stats     stats;
 
 //dma addr, rx/tx pool
-    dma_addr_t                  pool_dma;
-    dma_addr_t                  rd0_pool_dma;
-    dma_addr_t                  rd1_pool_dma;
+       dma_addr_t                  pool_dma;
+       dma_addr_t                  rd0_pool_dma;
+       dma_addr_t                  rd1_pool_dma;
 
-    dma_addr_t                  td0_pool_dma;
-    dma_addr_t                  td1_pool_dma;
+       dma_addr_t                  td0_pool_dma;
+       dma_addr_t                  td1_pool_dma;
 
-    dma_addr_t                  tx_bufs_dma0;
-    dma_addr_t                  tx_bufs_dma1;
-    dma_addr_t                  tx_beacon_dma;
+       dma_addr_t                  tx_bufs_dma0;
+       dma_addr_t                  tx_bufs_dma1;
+       dma_addr_t                  tx_beacon_dma;
 
-    unsigned char *tx0_bufs;
-    unsigned char *tx1_bufs;
-    unsigned char *tx_beacon_bufs;
+       unsigned char *tx0_bufs;
+       unsigned char *tx1_bufs;
+       unsigned char *tx_beacon_bufs;
 
-    CHIP_TYPE                   chip_id;
+       CHIP_TYPE                   chip_id;
 
-    unsigned long               PortOffset;
-    unsigned long dwIsr;
-    u32                         memaddr;
-    u32                         ioaddr;
-    u32                         io_size;
+       unsigned long               PortOffset;
+       unsigned long dwIsr;
+       u32                         memaddr;
+       u32                         ioaddr;
+       u32                         io_size;
 
-    unsigned char byRevId;
-    unsigned short SubSystemID;
-    unsigned short SubVendorID;
+       unsigned char byRevId;
+       unsigned short SubSystemID;
+       unsigned short SubVendorID;
 
-    int                         nTxQueues;
-    volatile int                iTDUsed[TYPE_MAXTD];
+       int                         nTxQueues;
+       volatile int                iTDUsed[TYPE_MAXTD];
 
-    volatile PSTxDesc           apCurrTD[TYPE_MAXTD];
-    volatile PSTxDesc           apTailTD[TYPE_MAXTD];
+       volatile PSTxDesc           apCurrTD[TYPE_MAXTD];
+       volatile PSTxDesc           apTailTD[TYPE_MAXTD];
 
-    volatile PSTxDesc           apTD0Rings;
-    volatile PSTxDesc           apTD1Rings;
+       volatile PSTxDesc           apTD0Rings;
+       volatile PSTxDesc           apTD1Rings;
 
-    volatile PSRxDesc           aRD0Ring;
-    volatile PSRxDesc           aRD1Ring;
-    volatile PSRxDesc           pCurrRD[TYPE_MAXRD];
-    SCache                      sDupRxCache;
+       volatile PSRxDesc           aRD0Ring;
+       volatile PSRxDesc           aRD1Ring;
+       volatile PSRxDesc           pCurrRD[TYPE_MAXRD];
+       SCache                      sDupRxCache;
 
-    SDeFragControlBlock         sRxDFCB[CB_MAX_RX_FRAG];
-    unsigned int       cbDFCB;
-    unsigned int       cbFreeDFCB;
-    unsigned int       uCurrentDFCBIdx;
+       SDeFragControlBlock         sRxDFCB[CB_MAX_RX_FRAG];
+       unsigned int    cbDFCB;
+       unsigned int    cbFreeDFCB;
+       unsigned int    uCurrentDFCBIdx;
 
-    OPTIONS                     sOpts;
+       OPTIONS                     sOpts;
 
-    u32                         flags;
+       u32                         flags;
 
-    u32                         rx_buf_sz;
-    int                         multicast_limit;
-    unsigned char byRxMode;
+       u32                         rx_buf_sz;
+       int                         multicast_limit;
+       unsigned char byRxMode;
 
-    spinlock_t                  lock;
+       spinlock_t                  lock;
 //PLICE_DEBUG->
-       struct  tasklet_struct          RxMngWorkItem;
+       struct  tasklet_struct  RxMngWorkItem;
        RxManagementQueue       rxManeQueue;
 //PLICE_DEBUG<-
 //PLICE_DEBUG ->
-       pid_t                           MLMEThr_pid;
-       struct  completion      notify;
-       struct  semaphore       mlme_semaphore;
+       pid_t                   MLMEThr_pid;
+       struct completion       notify;
+       struct semaphore        mlme_semaphore;
 //PLICE_DEBUG <-
 
-
-    u32                         rx_bytes;
-
-    // Version control
-    unsigned char byLocalID;
-    unsigned char byRFType;
-
-    unsigned char byMaxPwrLevel;
-    unsigned char byZoneType;
-    bool bZoneRegExist;
-   unsigned char byOriginalZonetype;
-    unsigned char abyMacContext[MAC_MAX_CONTEXT_REG];
-    bool bLinkPass;          // link status: OK or fail
-    unsigned char abyCurrentNetAddr[ETH_ALEN];
-
-    // Adapter statistics
-    SStatCounter                scStatistic;
-    // 802.11 counter
-    SDot11Counters              s802_11Counter;
-
-
-    // 802.11 management
-    PSMgmtObject                pMgmt;
-    SMgmtObject                 sMgmtObj;
-
-    // 802.11 MAC specific
-    unsigned int       uCurrRSSI;
-    unsigned char byCurrSQ;
-
-    unsigned long dwTxAntennaSel;
-    unsigned long dwRxAntennaSel;
-    unsigned char byAntennaCount;
-    unsigned char byRxAntennaMode;
-    unsigned char byTxAntennaMode;
-    bool bTxRxAntInv;
-
-    unsigned char *pbyTmpBuff;
-    unsigned int       uSIFS;    //Current SIFS
-    unsigned int       uDIFS;    //Current DIFS
-    unsigned int       uEIFS;    //Current EIFS
-    unsigned int       uSlot;    //Current SlotTime
-    unsigned int       uCwMin;   //Current CwMin
-    unsigned int       uCwMax;   //CwMax is fixed on 1023.
-    // PHY parameter
-    unsigned char bySIFS;
-    unsigned char byDIFS;
-    unsigned char byEIFS;
-    unsigned char bySlot;
-    unsigned char byCWMaxMin;
-    CARD_PHY_TYPE               eCurrentPHYType;
-
-
-    VIA_BB_TYPE                 byBBType; //0: 11A, 1:11B, 2:11G
-    VIA_PKT_TYPE                byPacketType; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
-    unsigned short wBasicRate;
-    unsigned char byACKRate;
-    unsigned char byTopOFDMBasicRate;
-    unsigned char byTopCCKBasicRate;
-
-    unsigned char byMinChannel;
-    unsigned char byMaxChannel;
-    unsigned int       uConnectionRate;
-
-    unsigned char byPreambleType;
-    unsigned char byShortPreamble;
-
-    unsigned short wCurrentRate;
-    unsigned short wRTSThreshold;
-    unsigned short wFragmentationThreshold;
-    unsigned char byShortRetryLimit;
-    unsigned char byLongRetryLimit;
-    CARD_OP_MODE                eOPMode;
-    unsigned char byOpMode;
-    bool bBSSIDFilter;
-    unsigned short wMaxTransmitMSDULifetime;
-    unsigned char abyBSSID[ETH_ALEN];
-    unsigned char abyDesireBSSID[ETH_ALEN];
-    unsigned short wCTSDuration;       // update while speed change
-    unsigned short wACKDuration;       // update while speed change
-    unsigned short wRTSTransmitLen;    // update while speed change
-    unsigned char byRTSServiceField;  // update while speed change
-    unsigned char byRTSSignalField;   // update while speed change
-
-    unsigned long dwMaxReceiveLifetime;       // dot11MaxReceiveLifetime
-
-    bool bCCK;
-    bool bEncryptionEnable;
-    bool bLongHeader;
-    bool bShortSlotTime;
-    bool bProtectMode;
-    bool bNonERPPresent;
-    bool bBarkerPreambleMd;
-
-    unsigned char byERPFlag;
-    unsigned short wUseProtectCntDown;
-
-    bool bRadioControlOff;
-    bool bRadioOff;
-    bool bEnablePSMode;
-    unsigned short wListenInterval;
-    bool bPWBitOn;
-    WMAC_POWER_MODE         ePSMode;
-
-
-    // GPIO Radio Control
-    unsigned char byRadioCtl;
-    unsigned char byGPIO;
-    bool bHWRadioOff;
-    bool bPrvActive4RadioOFF;
-    bool bGPIOBlockRead;
-
-    // Beacon related
-    unsigned short wSeqCounter;
-    unsigned short wBCNBufLen;
-    bool bBeaconBufReady;
-    bool bBeaconSent;
-    bool bIsBeaconBufReadySet;
-    unsigned int       cbBeaconBufReadySetCnt;
-    bool bFixRate;
-    unsigned char byCurrentCh;
-    unsigned int       uScanTime;
-
-    CMD_STATE               eCommandState;
-
-    CMD_CODE                eCommand;
-    bool bBeaconTx;
-
-    bool bStopBeacon;
-    bool bStopDataPkt;
-    bool bStopTx0Pkt;
-    unsigned int       uAutoReConnectTime;
-
-    // 802.11 counter
-
-    CMD_ITEM                eCmdQueue[CMD_Q_SIZE];
-    unsigned int       uCmdDequeueIdx;
-    unsigned int       uCmdEnqueueIdx;
-    unsigned int       cbFreeCmdQueue;
-    bool bCmdRunning;
-    bool bCmdClear;
-
-
-
-    bool bRoaming;
-    //WOW
-    unsigned char abyIPAddr[4];
-
-    unsigned long ulTxPower;
-    NDIS_802_11_WEP_STATUS  eEncryptionStatus;
-    bool bTransmitKey;
+       u32                         rx_bytes;
+
+       // Version control
+       unsigned char byLocalID;
+       unsigned char byRFType;
+
+       unsigned char byMaxPwrLevel;
+       unsigned char byZoneType;
+       bool bZoneRegExist;
+       unsigned char byOriginalZonetype;
+       unsigned char abyMacContext[MAC_MAX_CONTEXT_REG];
+       bool bLinkPass;          // link status: OK or fail
+       unsigned char abyCurrentNetAddr[ETH_ALEN];
+
+       // Adapter statistics
+       SStatCounter                scStatistic;
+       // 802.11 counter
+       SDot11Counters              s802_11Counter;
+
+       // 802.11 management
+       PSMgmtObject                pMgmt;
+       SMgmtObject                 sMgmtObj;
+
+       // 802.11 MAC specific
+       unsigned int    uCurrRSSI;
+       unsigned char byCurrSQ;
+
+       unsigned long dwTxAntennaSel;
+       unsigned long dwRxAntennaSel;
+       unsigned char byAntennaCount;
+       unsigned char byRxAntennaMode;
+       unsigned char byTxAntennaMode;
+       bool bTxRxAntInv;
+
+       unsigned char *pbyTmpBuff;
+       unsigned int    uSIFS;    //Current SIFS
+       unsigned int    uDIFS;    //Current DIFS
+       unsigned int    uEIFS;    //Current EIFS
+       unsigned int    uSlot;    //Current SlotTime
+       unsigned int    uCwMin;   //Current CwMin
+       unsigned int    uCwMax;   //CwMax is fixed on 1023.
+       // PHY parameter
+       unsigned char bySIFS;
+       unsigned char byDIFS;
+       unsigned char byEIFS;
+       unsigned char bySlot;
+       unsigned char byCWMaxMin;
+       CARD_PHY_TYPE               eCurrentPHYType;
+
+       VIA_BB_TYPE                 byBBType; //0: 11A, 1:11B, 2:11G
+       VIA_PKT_TYPE                byPacketType; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
+       unsigned short wBasicRate;
+       unsigned char byACKRate;
+       unsigned char byTopOFDMBasicRate;
+       unsigned char byTopCCKBasicRate;
+
+       unsigned char byMinChannel;
+       unsigned char byMaxChannel;
+       unsigned int    uConnectionRate;
+
+       unsigned char byPreambleType;
+       unsigned char byShortPreamble;
+
+       unsigned short wCurrentRate;
+       unsigned short wRTSThreshold;
+       unsigned short wFragmentationThreshold;
+       unsigned char byShortRetryLimit;
+       unsigned char byLongRetryLimit;
+       CARD_OP_MODE                eOPMode;
+       unsigned char byOpMode;
+       bool bBSSIDFilter;
+       unsigned short wMaxTransmitMSDULifetime;
+       unsigned char abyBSSID[ETH_ALEN];
+       unsigned char abyDesireBSSID[ETH_ALEN];
+       unsigned short wCTSDuration;       // update while speed change
+       unsigned short wACKDuration;       // update while speed change
+       unsigned short wRTSTransmitLen;    // update while speed change
+       unsigned char byRTSServiceField;  // update while speed change
+       unsigned char byRTSSignalField;   // update while speed change
+
+       unsigned long dwMaxReceiveLifetime;       // dot11MaxReceiveLifetime
+
+       bool bCCK;
+       bool bEncryptionEnable;
+       bool bLongHeader;
+       bool bShortSlotTime;
+       bool bProtectMode;
+       bool bNonERPPresent;
+       bool bBarkerPreambleMd;
+
+       unsigned char byERPFlag;
+       unsigned short wUseProtectCntDown;
+
+       bool bRadioControlOff;
+       bool bRadioOff;
+       bool bEnablePSMode;
+       unsigned short wListenInterval;
+       bool bPWBitOn;
+       WMAC_POWER_MODE         ePSMode;
+
+       // GPIO Radio Control
+       unsigned char byRadioCtl;
+       unsigned char byGPIO;
+       bool bHWRadioOff;
+       bool bPrvActive4RadioOFF;
+       bool bGPIOBlockRead;
+
+       // Beacon related
+       unsigned short wSeqCounter;
+       unsigned short wBCNBufLen;
+       bool bBeaconBufReady;
+       bool bBeaconSent;
+       bool bIsBeaconBufReadySet;
+       unsigned int    cbBeaconBufReadySetCnt;
+       bool bFixRate;
+       unsigned char byCurrentCh;
+       unsigned int    uScanTime;
+
+       CMD_STATE               eCommandState;
+
+       CMD_CODE                eCommand;
+       bool bBeaconTx;
+
+       bool bStopBeacon;
+       bool bStopDataPkt;
+       bool bStopTx0Pkt;
+       unsigned int    uAutoReConnectTime;
+
+       // 802.11 counter
+
+       CMD_ITEM                eCmdQueue[CMD_Q_SIZE];
+       unsigned int    uCmdDequeueIdx;
+       unsigned int    uCmdEnqueueIdx;
+       unsigned int    cbFreeCmdQueue;
+       bool bCmdRunning;
+       bool bCmdClear;
+
+       bool bRoaming;
+       //WOW
+       unsigned char abyIPAddr[4];
+
+       unsigned long ulTxPower;
+       NDIS_802_11_WEP_STATUS  eEncryptionStatus;
+       bool bTransmitKey;
 //2007-0925-01<Add>by MikeLiu
 //mike add :save old Encryption
-    NDIS_802_11_WEP_STATUS  eOldEncryptionStatus;
-
-    SKeyManagement          sKey;
-    unsigned long dwIVCounter;
-
-    QWORD                   qwPacketNumber; //For CCMP and TKIP as TSC(6 bytes)
-    unsigned int       uCurrentWEPMode;
-
-    RC4Ext                  SBox;
-    unsigned char abyPRNG[WLAN_WEPMAX_KEYLEN+3];
-    unsigned char byKeyIndex;
-    unsigned int       uKeyLength;
-    unsigned char abyKey[WLAN_WEP232_KEYLEN];
-
-    bool bAES;
-    unsigned char byCntMeasure;
-
-    // for AP mode
-    unsigned int       uAssocCount;
-    bool bMoreData;
-
-    // QoS
-    bool bGrpAckPolicy;
-
-    // for OID_802_11_ASSOCIATION_INFORMATION
-    bool bAssocInfoSet;
-
-
-    unsigned char byAutoFBCtrl;
-
-    bool bTxMICFail;
-    bool bRxMICFail;
-
-
-    unsigned int       uRATEIdx;
-
-
-    // For Update BaseBand VGA Gain Offset
-    bool bUpdateBBVGA;
-    unsigned int       uBBVGADiffCount;
-    unsigned char byBBVGANew;
-    unsigned char byBBVGACurrent;
-    unsigned char abyBBVGA[BB_VGA_LEVEL];
-    long                    ldBmThreshold[BB_VGA_LEVEL];
-
-    unsigned char byBBPreEDRSSI;
-    unsigned char byBBPreEDIndex;
-
-
-    bool bRadioCmd;
-    unsigned long dwDiagRefCount;
-
-    // For FOE Tuning
-    unsigned char byFOETuning;
-
-    // For Auto Power Tunning
-
-    unsigned char byAutoPwrTunning;
-    short                   sPSetPointCCK;
-    short                   sPSetPointOFDMG;
-    short                   sPSetPointOFDMA;
-    long                    lPFormulaOffset;
-    short                   sPThreshold;
-    char                    cAdjustStep;
-    char                    cMinTxAGC;
-
-    // For RF Power table
-    unsigned char byCCKPwr;
-    unsigned char byOFDMPwrG;
-    unsigned char byCurPwr;
-    char        byCurPwrdBm;
-    unsigned char abyCCKPwrTbl[CB_MAX_CHANNEL_24G+1];
-    unsigned char abyOFDMPwrTbl[CB_MAX_CHANNEL+1];
-    char       abyCCKDefaultPwr[CB_MAX_CHANNEL_24G+1];
-    char       abyOFDMDefaultPwr[CB_MAX_CHANNEL+1];
-    char       abyRegPwr[CB_MAX_CHANNEL+1];
-    char       abyLocalPwr[CB_MAX_CHANNEL+1];
-
-
-    // BaseBand Loopback Use
-    unsigned char byBBCR4d;
-    unsigned char byBBCRc9;
-    unsigned char byBBCR88;
-    unsigned char byBBCR09;
-
-    // command timer
-    struct timer_list       sTimerCommand;
+       NDIS_802_11_WEP_STATUS  eOldEncryptionStatus;
+
+       SKeyManagement          sKey;
+       unsigned long dwIVCounter;
+
+       QWORD                   qwPacketNumber; //For CCMP and TKIP as TSC(6 bytes)
+       unsigned int    uCurrentWEPMode;
+
+       RC4Ext                  SBox;
+       unsigned char abyPRNG[WLAN_WEPMAX_KEYLEN+3];
+       unsigned char byKeyIndex;
+       unsigned int    uKeyLength;
+       unsigned char abyKey[WLAN_WEP232_KEYLEN];
+
+       bool bAES;
+       unsigned char byCntMeasure;
+
+       // for AP mode
+       unsigned int    uAssocCount;
+       bool bMoreData;
+
+       // QoS
+       bool bGrpAckPolicy;
+
+       // for OID_802_11_ASSOCIATION_INFORMATION
+       bool bAssocInfoSet;
+
+       unsigned char byAutoFBCtrl;
+
+       bool bTxMICFail;
+       bool bRxMICFail;
+
+       unsigned int    uRATEIdx;
+
+       // For Update BaseBand VGA Gain Offset
+       bool bUpdateBBVGA;
+       unsigned int    uBBVGADiffCount;
+       unsigned char byBBVGANew;
+       unsigned char byBBVGACurrent;
+       unsigned char abyBBVGA[BB_VGA_LEVEL];
+       long                    ldBmThreshold[BB_VGA_LEVEL];
+
+       unsigned char byBBPreEDRSSI;
+       unsigned char byBBPreEDIndex;
+
+       bool bRadioCmd;
+       unsigned long dwDiagRefCount;
+
+       // For FOE Tuning
+       unsigned char byFOETuning;
+
+       // For Auto Power Tunning
+
+       unsigned char byAutoPwrTunning;
+       short                   sPSetPointCCK;
+       short                   sPSetPointOFDMG;
+       short                   sPSetPointOFDMA;
+       long                    lPFormulaOffset;
+       short                   sPThreshold;
+       char                    cAdjustStep;
+       char                    cMinTxAGC;
+
+       // For RF Power table
+       unsigned char byCCKPwr;
+       unsigned char byOFDMPwrG;
+       unsigned char byCurPwr;
+       char     byCurPwrdBm;
+       unsigned char abyCCKPwrTbl[CB_MAX_CHANNEL_24G+1];
+       unsigned char abyOFDMPwrTbl[CB_MAX_CHANNEL+1];
+       char    abyCCKDefaultPwr[CB_MAX_CHANNEL_24G+1];
+       char    abyOFDMDefaultPwr[CB_MAX_CHANNEL+1];
+       char    abyRegPwr[CB_MAX_CHANNEL+1];
+       char    abyLocalPwr[CB_MAX_CHANNEL+1];
+
+       // BaseBand Loopback Use
+       unsigned char byBBCR4d;
+       unsigned char byBBCRc9;
+       unsigned char byBBCR88;
+       unsigned char byBBCR09;
+
+       // command timer
+       struct timer_list       sTimerCommand;
 #ifdef TxInSleep
-     struct timer_list       sTimerTxData;
-     unsigned long nTxDataTimeCout;
-     bool fTxDataInSleep;
-     bool IsTxDataTrigger;
+       struct timer_list       sTimerTxData;
+       unsigned long nTxDataTimeCout;
+       bool fTxDataInSleep;
+       bool IsTxDataTrigger;
 #endif
 
 #ifdef WPA_SM_Transtatus
-    bool fWPA_Authened;           //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
+       bool fWPA_Authened;           //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
 #endif
-    unsigned char byReAssocCount;   //mike add:re-association retry times!
-    unsigned char byLinkWaitCount;
+       unsigned char byReAssocCount;   //mike add:re-association retry times!
+       unsigned char byLinkWaitCount;
 
+       unsigned char abyNodeName[17];
 
-    unsigned char abyNodeName[17];
-
-    bool bDiversityRegCtlON;
-    bool bDiversityEnable;
-    unsigned long ulDiversityNValue;
-    unsigned long ulDiversityMValue;
-    unsigned char byTMax;
-    unsigned char byTMax2;
-    unsigned char byTMax3;
-    unsigned long ulSQ3TH;
+       bool bDiversityRegCtlON;
+       bool bDiversityEnable;
+       unsigned long ulDiversityNValue;
+       unsigned long ulDiversityMValue;
+       unsigned char byTMax;
+       unsigned char byTMax2;
+       unsigned char byTMax3;
+       unsigned long ulSQ3TH;
 
 // ANT diversity
-    unsigned long uDiversityCnt;
-    unsigned char byAntennaState;
-    unsigned long ulRatio_State0;
-    unsigned long ulRatio_State1;
-
-    //SQ3 functions for antenna diversity
-    struct timer_list           TimerSQ3Tmax1;
-    struct timer_list           TimerSQ3Tmax2;
-    struct timer_list           TimerSQ3Tmax3;
-
-
-    unsigned long uNumSQ3[MAX_RATE];
-    unsigned short wAntDiversityMaxRate;
-
-
-    SEthernetHeader         sTxEthHeader;
-    SEthernetHeader         sRxEthHeader;
-    unsigned char abyBroadcastAddr[ETH_ALEN];
-    unsigned char abySNAP_RFC1042[ETH_ALEN];
-    unsigned char abySNAP_Bridgetunnel[ETH_ALEN];
-     unsigned char abyEEPROM[EEP_MAX_CONTEXT_SIZE];  //unsigned long alignment
-    // Pre-Authentication & PMK cache
-    SPMKID                  gsPMKID;
-    SPMKIDCandidateEvent    gsPMKIDCandidate;
-
-
-    // for 802.11h
-    bool b11hEnable;
-    unsigned char abyCountryCode[3];
-    // for 802.11h DFS
-    unsigned int       uNumOfMeasureEIDs;
-    PWLAN_IE_MEASURE_REQ    pCurrMeasureEID;
-    bool bMeasureInProgress;
-    unsigned char byOrgChannel;
-    unsigned char byOrgRCR;
-    unsigned long dwOrgMAR0;
-    unsigned long dwOrgMAR4;
-    unsigned char byBasicMap;
-    unsigned char byCCAFraction;
-    unsigned char abyRPIs[8];
-    unsigned long dwRPIs[8];
-    bool bChannelSwitch;
-    unsigned char byNewChannel;
-    unsigned char byChannelSwitchCount;
-    bool bQuietEnable;
-    bool bEnableFirstQuiet;
-    unsigned char byQuietStartCount;
-    unsigned int       uQuietEnqueue;
-    unsigned long dwCurrentQuietEndTime;
-    SQuietControl           sQuiet[MAX_QUIET_COUNT];
-    // for 802.11h TPC
-    bool bCountryInfo5G;
-    bool bCountryInfo24G;
-
-    unsigned short wBeaconInterval;
-
-    //WPA supplicant deamon
+       unsigned long uDiversityCnt;
+       unsigned char byAntennaState;
+       unsigned long ulRatio_State0;
+       unsigned long ulRatio_State1;
+
+       //SQ3 functions for antenna diversity
+       struct timer_list           TimerSQ3Tmax1;
+       struct timer_list           TimerSQ3Tmax2;
+       struct timer_list           TimerSQ3Tmax3;
+
+       unsigned long uNumSQ3[MAX_RATE];
+       unsigned short wAntDiversityMaxRate;
+
+       SEthernetHeader         sTxEthHeader;
+       SEthernetHeader         sRxEthHeader;
+       unsigned char abyBroadcastAddr[ETH_ALEN];
+       unsigned char abySNAP_RFC1042[ETH_ALEN];
+       unsigned char abySNAP_Bridgetunnel[ETH_ALEN];
+       unsigned char abyEEPROM[EEP_MAX_CONTEXT_SIZE];  //unsigned long alignment
+       // Pre-Authentication & PMK cache
+       SPMKID                  gsPMKID;
+       SPMKIDCandidateEvent    gsPMKIDCandidate;
+
+       // for 802.11h
+       bool b11hEnable;
+       unsigned char abyCountryCode[3];
+       // for 802.11h DFS
+       unsigned int    uNumOfMeasureEIDs;
+       PWLAN_IE_MEASURE_REQ    pCurrMeasureEID;
+       bool bMeasureInProgress;
+       unsigned char byOrgChannel;
+       unsigned char byOrgRCR;
+       unsigned long dwOrgMAR0;
+       unsigned long dwOrgMAR4;
+       unsigned char byBasicMap;
+       unsigned char byCCAFraction;
+       unsigned char abyRPIs[8];
+       unsigned long dwRPIs[8];
+       bool bChannelSwitch;
+       unsigned char byNewChannel;
+       unsigned char byChannelSwitchCount;
+       bool bQuietEnable;
+       bool bEnableFirstQuiet;
+       unsigned char byQuietStartCount;
+       unsigned int    uQuietEnqueue;
+       unsigned long dwCurrentQuietEndTime;
+       SQuietControl           sQuiet[MAX_QUIET_COUNT];
+       // for 802.11h TPC
+       bool bCountryInfo5G;
+       bool bCountryInfo24G;
+
+       unsigned short wBeaconInterval;
+
+       //WPA supplicant deamon
        struct net_device       *wpadev;
        bool bWPADEVUp;
-    struct sk_buff          *skb;
+       struct sk_buff          *skb;
 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
 /*
-        bool bwextstep0;
-        bool bwextstep1;
-        bool bwextstep2;
-        bool bwextstep3;
-        */
-        unsigned int   bwextcount;
-        bool bWPASuppWextEnabled;
+  bool bwextstep0;
+  bool bwextstep1;
+  bool bwextstep2;
+  bool bwextstep3;
+*/
+       unsigned int    bwextcount;
+       bool bWPASuppWextEnabled;
 #endif
 
-    //--
+       //--
 #ifdef HOSTAP
-    // user space daemon: hostapd, is used for HOSTAP
+       // user space daemon: hostapd, is used for HOSTAP
        bool bEnableHostapd;
        bool bEnable8021x;
        bool bEnableHostWEP;
        struct net_device       *apdev;
        int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
 #endif
-    unsigned int       uChannel;
-    bool bMACSuspend;
+       unsigned int    uChannel;
+       bool bMACSuspend;
 
        struct iw_statistics    wstats;         // wireless stats
-    bool bCommit;
-
+       bool bCommit;
 } DEVICE_INFO, *PSDevice;
 
-
 //PLICE_DEBUG->
 
-
- inline  static        void   EnQueue (PSDevice pDevice,PSRxMgmtPacket  pRxMgmtPacket)
+inline  static void   EnQueue(PSDevice pDevice, PSRxMgmtPacket  pRxMgmtPacket)
 {
-       //printk("Enter EnQueue:tail is %d\n",pDevice->rxManeQueue.tail);
-       if ((pDevice->rxManeQueue.tail+1) % NUM == pDevice->rxManeQueue.head)
-       {
-               //printk("Queue is Full,tail is %d\n",pDevice->rxManeQueue.tail);
-               return ;
-       }
-       else
-       {
-               pDevice->rxManeQueue.tail = (pDevice->rxManeQueue.tail+1)% NUM;
+       if ((pDevice->rxManeQueue.tail+1) % NUM == pDevice->rxManeQueue.head) {
+               return;
+       } else {
+               pDevice->rxManeQueue.tail = (pDevice->rxManeQueue.tail + 1) % NUM;
                pDevice->rxManeQueue.Q[pDevice->rxManeQueue.tail] = pRxMgmtPacket;
                pDevice->rxManeQueue.packet_num++;
-               //printk("packet num is %d\n",pDevice->rxManeQueue.packet_num);
        }
 }
 
-
-
-
-       inline  static  PSRxMgmtPacket DeQueue (PSDevice pDevice)
+inline  static  PSRxMgmtPacket DeQueue(PSDevice pDevice)
 {
        PSRxMgmtPacket  pRxMgmtPacket;
-       if (pDevice->rxManeQueue.tail == pDevice->rxManeQueue.head)
-       {
+       if (pDevice->rxManeQueue.tail == pDevice->rxManeQueue.head) {
                printk("Queue is Empty\n");
                return NULL;
-       }
-       else
-       {
+       } else {
                int     x;
                //x=pDevice->rxManeQueue.head = (pDevice->rxManeQueue.head+1)%NUM;
                pDevice->rxManeQueue.head = (pDevice->rxManeQueue.head+1)%NUM;
                x = pDevice->rxManeQueue.head;
-               //printk("Enter DeQueue:head is %d\n",x);
                pRxMgmtPacket = pDevice->rxManeQueue.Q[x];
                pDevice->rxManeQueue.packet_num--;
                return pRxMgmtPacket;
@@ -856,31 +800,22 @@ typedef struct __device_info {
 
 void   InitRxManagementQueue(PSDevice   pDevice);
 
-
-
 //PLICE_DEBUG<-
 
-
-
-
-
-
 inline static bool device_get_ip(PSDevice pInfo) {
-    struct in_device* in_dev=(struct in_device*) pInfo->dev->ip_ptr;
-    struct in_ifaddr* ifa;
-
-    if (in_dev!=NULL) {
-        ifa=(struct in_ifaddr*) in_dev->ifa_list;
-        if (ifa!=NULL) {
-            memcpy(pInfo->abyIPAddr,&ifa->ifa_address,4);
-            return true;
-        }
-    }
-    return false;
+       struct in_device *in_dev = (struct in_device *)pInfo->dev->ip_ptr;
+       struct in_ifaddr *ifa;
+
+       if (in_dev != NULL) {
+               ifa = (struct in_ifaddr *)in_dev->ifa_list;
+               if (ifa != NULL) {
+                       memcpy(pInfo->abyIPAddr, &ifa->ifa_address, 4);
+                       return true;
+               }
+       }
+       return false;
 }
 
-
-
 static inline PDEVICE_RD_INFO alloc_rd_info(void)
 {
        return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC);
@@ -897,5 +832,3 @@ bool device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, unsigned int uNodeI
 bool device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF);
 int Config_FileOperation(PSDevice pDevice, bool fwrite, unsigned char *Parameter);
 #endif
-
-
index 408edc27075fdf674643fb32cbf1276711553c37..1137adede9ee2da9fd16cadb14734e416df82122 100644 (file)
@@ -34,9 +34,9 @@
 
 typedef
 struct _version {
-    unsigned char   major;
-    unsigned char   minor;
-    unsigned char   build;
+       unsigned char   major;
+       unsigned char   minor;
+       unsigned char   build;
 } version_t, *pversion_t;
 
 #define VID_TABLE_SIZE      64
@@ -70,31 +70,26 @@ struct _version {
 //Max: 2378=2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
 #define PKT_BUF_SZ          2390
 
-
 #define MAX_UINTS           8
 #define OPTION_DEFAULT      { [0 ... MAX_UINTS-1] = -1}
 
-
-
-typedef enum  _chip_type{
-    VT3253=1
+typedef enum  _chip_type {
+       VT3253 = 1
 } CHIP_TYPE, *PCHIP_TYPE;
 
-
-
 #ifdef VIAWET_DEBUG
-#define ASSERT(x) { \
-    if (!(x)) { \
-        printk(KERN_ERR "assertion %s failed: file %s line %d\n", #x,\
-        __FUNCTION__, __LINE__);\
-        *(int*) 0=0;\
-    }\
-}
+#define ASSERT(x)                                                      \
+do {                                                                   \
+       if (!(x)) {                                                     \
+               printk(KERN_ERR "assertion %s failed: file %s line %d\n", \
+                      #x, __func__, __LINE__);                         \
+               *(int *)0 = 0;                                          \
+       }                                                               \
+} while (0)
 #define DBG_PORT80(value)                   outb(value, 0x80)
 #else
 #define ASSERT(x)
 #define DBG_PORT80(value)
 #endif
 
-
 #endif
index 453c83d7fe8ccbb82dbaa79d55ac96f6336772a0..be4f6c2ca3ff8c3df8ebcf222312f754b5c5ffb1 100644 (file)
@@ -98,52 +98,50 @@ MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
 
-       static int mlme_kill;
-       //static  struct task_struct * mlme_task;
+static int mlme_kill;
+//static  struct task_struct * mlme_task;
 
-#define DEVICE_PARAM(N,D)
+#define DEVICE_PARAM(N, D)
 /*
-        static const int N[MAX_UINTS]=OPTION_DEFAULT;\
-        MODULE_PARM(N, "1-" __MODULE_STRING(MAX_UINTS) "i");\
-        MODULE_PARM_DESC(N, D);
+  static const int N[MAX_UINTS]=OPTION_DEFAULT;\
+  MODULE_PARM(N, "1-" __MODULE_STRING(MAX_UINTS) "i");\
+  MODULE_PARM_DESC(N, D);
 */
 
 #define RX_DESC_MIN0     16
 #define RX_DESC_MAX0     128
 #define RX_DESC_DEF0     32
-DEVICE_PARAM(RxDescriptors0,"Number of receive descriptors0");
+DEVICE_PARAM(RxDescriptors0, "Number of receive descriptors0");
 
 #define RX_DESC_MIN1     16
 #define RX_DESC_MAX1     128
 #define RX_DESC_DEF1     32
-DEVICE_PARAM(RxDescriptors1,"Number of receive descriptors1");
+DEVICE_PARAM(RxDescriptors1, "Number of receive descriptors1");
 
 #define TX_DESC_MIN0     16
 #define TX_DESC_MAX0     128
 #define TX_DESC_DEF0     32
-DEVICE_PARAM(TxDescriptors0,"Number of transmit descriptors0");
+DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
 
 #define TX_DESC_MIN1     16
 #define TX_DESC_MAX1     128
 #define TX_DESC_DEF1     64
-DEVICE_PARAM(TxDescriptors1,"Number of transmit descriptors1");
-
+DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
 
 #define IP_ALIG_DEF     0
 /* IP_byte_align[] is used for IP header unsigned long byte aligned
    0: indicate the IP header won't be unsigned long byte aligned.(Default) .
    1: indicate the IP header will be unsigned long byte aligned.
-      In some environment, the IP header should be unsigned long byte aligned,
-      or the packet will be droped when we receive it. (eg: IPVS)
+   In some environment, the IP header should be unsigned long byte aligned,
+   or the packet will be droped when we receive it. (eg: IPVS)
 */
-DEVICE_PARAM(IP_byte_align,"Enable IP header dword aligned");
-
+DEVICE_PARAM(IP_byte_align, "Enable IP header dword aligned");
 
 #define INT_WORKS_DEF   20
 #define INT_WORKS_MIN   10
 #define INT_WORKS_MAX   64
 
-DEVICE_PARAM(int_works,"Number of packets per interrupt services");
+DEVICE_PARAM(int_works, "Number of packets per interrupt services");
 
 #define CHANNEL_MIN     1
 #define CHANNEL_MAX     14
@@ -151,7 +149,6 @@ DEVICE_PARAM(int_works,"Number of packets per interrupt services");
 
 DEVICE_PARAM(Channel, "Channel number");
 
-
 /* PreambleType[] is the preamble length used for transmit.
    0: indicate allows long preamble type
    1: indicate allows short preamble type
@@ -161,21 +158,18 @@ DEVICE_PARAM(Channel, "Channel number");
 
 DEVICE_PARAM(PreambleType, "Preamble Type");
 
-
 #define RTS_THRESH_MIN     512
 #define RTS_THRESH_MAX     2347
 #define RTS_THRESH_DEF     2347
 
 DEVICE_PARAM(RTSThreshold, "RTS threshold");
 
-
 #define FRAG_THRESH_MIN     256
 #define FRAG_THRESH_MAX     2346
 #define FRAG_THRESH_DEF     2346
 
 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
 
-
 #define DATA_RATE_MIN     0
 #define DATA_RATE_MAX     13
 #define DATA_RATE_DEF     13
@@ -190,10 +184,10 @@ DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
    7: indicate 18 Mbps  0x24
    8: indicate 24 Mbps  0x30
    9: indicate 36 Mbps  0x48
-  10: indicate 48 Mbps  0x60
-  11: indicate 54 Mbps  0x6c
-  12: indicate 72 Mbps  0x90
-  13: indicate auto rate
+   10: indicate 48 Mbps  0x60
+   11: indicate 54 Mbps  0x6c
+   12: indicate 72 Mbps  0x90
+   13: indicate auto rate
 */
 
 DEVICE_PARAM(ConnectionRate, "Connection data rate");
@@ -208,7 +202,6 @@ DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
    2: indicate AP mode used
 */
 
-
 /* PSMode[]
    0: indicate disable power saving mode
    1: indicate enable power saving mode
@@ -218,22 +211,18 @@ DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
 
 DEVICE_PARAM(PSMode, "Power saving mode");
 
-
 #define SHORT_RETRY_MIN     0
 #define SHORT_RETRY_MAX     31
 #define SHORT_RETRY_DEF     8
 
-
 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
 
 #define LONG_RETRY_MIN     0
 #define LONG_RETRY_MAX     15
 #define LONG_RETRY_DEF     4
 
-
 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
 
-
 /* BasebandType[] baseband type selected
    0: indicate 802.11a type
    1: indicate 802.11b type
@@ -245,8 +234,6 @@ DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
 
 DEVICE_PARAM(BasebandType, "baseband type");
 
-
-
 /* 80211hEnable[]
    0: indicate disable 802.11h
    1: indicate enable 802.11h
@@ -265,20 +252,18 @@ DEVICE_PARAM(b80211hEnable, "802.11h mode");
 
 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
 
-
 //
 // Static vars definitions
 //
 
-
-static int          device_nics             =0;
-static PSDevice     pDevice_Infos           =NULL;
+static int          device_nics             = 0;
+static PSDevice     pDevice_Infos           = NULL;
 static struct net_device *root_device_dev = NULL;
 
-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 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}
 };
 
 DEFINE_PCI_DEVICE_TABLE(vt6655_pci_id_table) = {
@@ -288,17 +273,16 @@ DEFINE_PCI_DEVICE_TABLE(vt6655_pci_id_table) = {
 
 /*---------------------  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, PSDevice* ppDevice, PCHIP_INFO);
+static void vt6655_init_info(struct pci_dev *pcid, PSDevice *ppDevice, PCHIP_INFO);
 static void device_free_info(PSDevice pDevice);
-static bool device_get_pci_info(PSDevice, struct pci_devpcid);
+static bool device_get_pci_info(PSDevice, struct pci_dev *pcid);
 static void device_print_info(PSDevice pDevice);
 static struct net_device_stats *device_get_stats(struct net_device *dev);
 static void device_init_diversity_timer(PSDevice pDevice);
 static int  device_open(struct net_device *dev);
 static int  device_xmit(struct sk_buff *skb, struct net_device *dev);
-static  irqreturn_t  device_intr(int irq,  void*dev_instance);
+static  irqreturn_t  device_intr(int irq,  void *dev_instance);
 static void device_set_multi(struct net_device *dev);
 static int  device_close(struct net_device *dev);
 static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
@@ -314,7 +298,6 @@ struct notifier_block device_notifier = {
 };
 #endif
 
-
 static void device_init_rd0_ring(PSDevice pDevice);
 static void device_init_rd1_ring(PSDevice pDevice);
 static void device_init_defrag_cb(PSDevice pDevice);
@@ -338,16 +321,13 @@ static void device_free_rd1_ring(PSDevice pDevice);
 static void device_free_rings(PSDevice pDevice);
 static void device_free_frag_buf(PSDevice pDevice);
 static int Config_FileGetParameter(unsigned char *string,
-               unsigned char *dest, unsigned char *source);
-
+                                  unsigned char *dest, unsigned char *source);
 
 /*---------------------  Export Variables  --------------------------*/
 
 /*---------------------  Export Functions  --------------------------*/
 
-
-
-static char* get_chip_name(int chip_id)
+static char *get_chip_name(int chip_id)
 {
        int i;
        for (i = 0; chip_info_table[i].name != NULL; i++)
@@ -363,42 +343,41 @@ static void vt6655_remove(struct pci_dev *pcid)
        if (pDevice == NULL)
                return;
        device_free_info(pDevice);
-
 }
 
 /*
-static void
-device_set_int_opt(int *opt, int val, int min, int max, int def,char* name,char* devname) {
-    if (val==-1)
-        *opt=def;
-    else if (val<min || val>max) {
-        DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n" ,
-            devname,name, min,max);
-        *opt=def;
-    } else {
-        DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n",
-            devname, name, val);
-        *opt=val;
-    }
-}
+  static void
+  device_set_int_opt(int *opt, int val, int min, int max, int def,char* name,char* devname) {
+  if (val==-1)
+  *opt=def;
+  else if (val<min || val>max) {
+  DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n" ,
+  devname,name, min,max);
+  *opt=def;
+  } else {
+  DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n",
+  devname, name, val);
+  *opt=val;
+  }
+  }
 
-static void
-device_set_bool_opt(unsigned int *opt, int val,bool def,u32 flag, char* name,char* devname) {
-    (*opt)&=(~flag);
-    if (val==-1)
-        *opt|=(def ? flag : 0);
-    else if (val<0 || val>1) {
-        DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE
-            "%s: the value of parameter %s is invalid, the valid range is (0-1)\n",devname,name);
-        *opt|=(def ? flag : 0);
-    } else {
-        DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: set parameter %s to %s\n",
-            devname,name , val ? "true" : "false");
-        *opt|=(val ? flag : 0);
-    }
-}
+  static void
+  device_set_bool_opt(unsigned int *opt, int val,bool def,u32 flag, char* name,char* devname) {
+  (*opt)&=(~flag);
+  if (val==-1)
+  *opt|=(def ? flag : 0);
+  else if (val<0 || val>1) {
+  DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE
+  "%s: the value of parameter %s is invalid, the valid range is (0-1)\n",devname,name);
+  *opt|=(def ? flag : 0);
+  } else {
+  DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: set parameter %s to %s\n",
+  devname,name , val ? "true" : "false");
+  *opt|=(val ? flag : 0);
+  }
+  }
 */
-static void device_get_options(PSDevice pDevice, int index, chardevname)
+static void device_get_options(PSDevice pDevice, int index, char *devname)
 {
        POPTIONS pOpts = &(pDevice->sOpts);
 
@@ -425,472 +404,436 @@ static void device_get_options(PSDevice pDevice, int index, char* devname)
 
 static void
 device_set_options(PSDevice pDevice) {
-
-    unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-    unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
-    unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
-
-
-    memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
-    memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
-    memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
-
-    pDevice->uChannel = pDevice->sOpts.channel_num;
-    pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
-    pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
-    pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
-    pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
-    pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
-    pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
-    pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
-    pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
-    pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
-    pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
-    pDevice->uConnectionRate = pDevice->sOpts.data_rate;
-    if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = true;
-    pDevice->byBBType = pDevice->sOpts.bbp_type;
-    pDevice->byPacketType = pDevice->byBBType;
+       unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+       unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
+       unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
+
+       memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
+       memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
+       memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
+
+       pDevice->uChannel = pDevice->sOpts.channel_num;
+       pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
+       pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
+       pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
+       pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
+       pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
+       pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
+       pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
+       pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
+       pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
+       pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
+       pDevice->uConnectionRate = pDevice->sOpts.data_rate;
+       if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = true;
+       pDevice->byBBType = pDevice->sOpts.bbp_type;
+       pDevice->byPacketType = pDevice->byBBType;
 
 //PLICE_DEBUG->
        pDevice->byAutoFBCtrl = AUTO_FB_0;
        //pDevice->byAutoFBCtrl = AUTO_FB_1;
 //PLICE_DEBUG<-
-pDevice->bUpdateBBVGA = true;
-    pDevice->byFOETuning = 0;
-    pDevice->wCTSDuration = 0;
-    pDevice->byPreambleType = 0;
-
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uChannel= %d\n",(int)pDevice->uChannel);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byOpMode= %d\n",(int)pDevice->byOpMode);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ePSMode= %d\n",(int)pDevice->ePSMode);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" wRTSThreshold= %d\n",(int)pDevice->wRTSThreshold);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortRetryLimit= %d\n",(int)pDevice->byShortRetryLimit);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byLongRetryLimit= %d\n",(int)pDevice->byLongRetryLimit);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byPreambleType= %d\n",(int)pDevice->byPreambleType);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortPreamble= %d\n",(int)pDevice->byShortPreamble);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uConnectionRate= %d\n",(int)pDevice->uConnectionRate);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byBBType= %d\n",(int)pDevice->byBBType);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->b11hEnable= %d\n",(int)pDevice->b11hEnable);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->bDiversityRegCtlON= %d\n",(int)pDevice->bDiversityRegCtlON);
+       pDevice->bUpdateBBVGA = true;
+       pDevice->byFOETuning = 0;
+       pDevice->wCTSDuration = 0;
+       pDevice->byPreambleType = 0;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " uChannel= %d\n", (int)pDevice->uChannel);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byOpMode= %d\n", (int)pDevice->byOpMode);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ePSMode= %d\n", (int)pDevice->ePSMode);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byPreambleType= %d\n", (int)pDevice->byPreambleType);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byBBType= %d\n", (int)pDevice->byBBType);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pDevice->bDiversityRegCtlON= %d\n", (int)pDevice->bDiversityRegCtlON);
 }
 
-static void s_vCompleteCurrentMeasure (PSDevice pDevice, unsigned char byResult)
+static void s_vCompleteCurrentMeasure(PSDevice pDevice, unsigned char byResult)
 {
-    unsigned int ii;
-    unsigned long dwDuration = 0;
-    unsigned char byRPI0 = 0;
-
-    for(ii=1;ii<8;ii++) {
-        pDevice->dwRPIs[ii] *= 255;
-        dwDuration |= *((unsigned short *) (pDevice->pCurrMeasureEID->sReq.abyDuration));
-        dwDuration <<= 10;
-        pDevice->dwRPIs[ii] /= dwDuration;
-        pDevice->abyRPIs[ii] = (unsigned char) pDevice->dwRPIs[ii];
-        byRPI0 += pDevice->abyRPIs[ii];
-    }
-    pDevice->abyRPIs[0] = (0xFF - byRPI0);
-
-     if (pDevice->uNumOfMeasureEIDs == 0) {
-        VNTWIFIbMeasureReport(  pDevice->pMgmt,
-                                true,
-                                pDevice->pCurrMeasureEID,
-                                byResult,
-                                pDevice->byBasicMap,
-                                pDevice->byCCAFraction,
-                                pDevice->abyRPIs
-                                );
-    } else {
-        VNTWIFIbMeasureReport(  pDevice->pMgmt,
-                                false,
-                                pDevice->pCurrMeasureEID,
-                                byResult,
-                                pDevice->byBasicMap,
-                                pDevice->byCCAFraction,
-                                pDevice->abyRPIs
-                                );
-        CARDbStartMeasure (pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
-    }
-
+       unsigned int ii;
+       unsigned long dwDuration = 0;
+       unsigned char byRPI0 = 0;
+
+       for (ii = 1; ii < 8; ii++) {
+               pDevice->dwRPIs[ii] *= 255;
+               dwDuration |= *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
+               dwDuration <<= 10;
+               pDevice->dwRPIs[ii] /= dwDuration;
+               pDevice->abyRPIs[ii] = (unsigned char)pDevice->dwRPIs[ii];
+               byRPI0 += pDevice->abyRPIs[ii];
+       }
+       pDevice->abyRPIs[0] = (0xFF - byRPI0);
+
+       if (pDevice->uNumOfMeasureEIDs == 0) {
+               VNTWIFIbMeasureReport(pDevice->pMgmt,
+                                     true,
+                                     pDevice->pCurrMeasureEID,
+                                     byResult,
+                                     pDevice->byBasicMap,
+                                     pDevice->byCCAFraction,
+                                     pDevice->abyRPIs
+                       );
+       } else {
+               VNTWIFIbMeasureReport(pDevice->pMgmt,
+                                     false,
+                                     pDevice->pCurrMeasureEID,
+                                     byResult,
+                                     pDevice->byBasicMap,
+                                     pDevice->byCCAFraction,
+                                     pDevice->abyRPIs
+                       );
+               CARDbStartMeasure(pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
+       }
 }
 
-
-
 //
 // Initialisation of MAC & BBP registers
 //
 
 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
 {
-    unsigned int ii;
-    unsigned char byValue;
-    unsigned char byValue1;
-    unsigned char byCCKPwrdBm = 0;
-    unsigned char byOFDMPwrdBm = 0;
-    int zonetype=0;
-     PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
-    MACbShutdown(pDevice->PortOffset);
-    BBvSoftwareReset(pDevice->PortOffset);
-
-    if ((InitType == DEVICE_INIT_COLD) ||
-        (InitType == DEVICE_INIT_DXPL)) {
-        // Do MACbSoftwareReset in MACvInitialize
-        MACbSoftwareReset(pDevice->PortOffset);
-        // force CCK
-        pDevice->bCCK = true;
-        pDevice->bAES = false;
-        pDevice->bProtectMode = false;      //Only used in 11g type, sync with ERP IE
-        pDevice->bNonERPPresent = false;
-        pDevice->bBarkerPreambleMd = false;
-        pDevice->wCurrentRate = RATE_1M;
-        pDevice->byTopOFDMBasicRate = RATE_24M;
-        pDevice->byTopCCKBasicRate = RATE_1M;
-
-        pDevice->byRevId = 0;                   //Target to IF pin while programming to RF chip.
-
-        // init MAC
-        MACvInitialize(pDevice->PortOffset);
-
-        // Get Local ID
-        VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
-
-           spin_lock_irq(&pDevice->lock);
-        SROMvReadAllContents(pDevice->PortOffset,pDevice->abyEEPROM);
-
-           spin_unlock_irq(&pDevice->lock);
-
-        // Get Channel range
-
-        pDevice->byMinChannel = 1;
-        pDevice->byMaxChannel = CB_MAX_CHANNEL;
-
-        // Get Antena
-        byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
-        if (byValue & EEP_ANTINV)
-            pDevice->bTxRxAntInv = true;
-        else
-            pDevice->bTxRxAntInv = false;
-#ifdef PLICE_DEBUG
-       //printk("init_register:TxRxAntInv is %d,byValue is %d\n",pDevice->bTxRxAntInv,byValue);
-#endif
-
-        byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
-        if (byValue == 0) // if not set default is All
-            byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
-#ifdef PLICE_DEBUG
-       //printk("init_register:byValue is %d\n",byValue);
-#endif
-        pDevice->ulDiversityNValue = 100*260;//100*SROMbyReadEmbedded(pDevice->PortOffset, 0x51);
-        pDevice->ulDiversityMValue = 100*16;//SROMbyReadEmbedded(pDevice->PortOffset, 0x52);
-        pDevice->byTMax = 1;//SROMbyReadEmbedded(pDevice->PortOffset, 0x53);
-        pDevice->byTMax2 = 4;//SROMbyReadEmbedded(pDevice->PortOffset, 0x54);
-        pDevice->ulSQ3TH = 0;//(unsigned long) SROMbyReadEmbedded(pDevice->PortOffset, 0x55);
-        pDevice->byTMax3 = 64;//SROMbyReadEmbedded(pDevice->PortOffset, 0x56);
-
-        if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
-            pDevice->byAntennaCount = 2;
-            pDevice->byTxAntennaMode = ANT_B;
-            pDevice->dwTxAntennaSel = 1;
-            pDevice->dwRxAntennaSel = 1;
-            if (pDevice->bTxRxAntInv == true)
-                pDevice->byRxAntennaMode = ANT_A;
-            else
-                pDevice->byRxAntennaMode = ANT_B;
-                // chester for antenna
-byValue1 = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
-          //  if (pDevice->bDiversityRegCtlON)
-          if((byValue1&0x08)==0)
-                pDevice->bDiversityEnable = false;//SROMbyReadEmbedded(pDevice->PortOffset, 0x50);
-            else
-                pDevice->bDiversityEnable = true;
-#ifdef PLICE_DEBUG
-               //printk("aux |main antenna: RxAntennaMode is %d\n",pDevice->byRxAntennaMode);
-#endif
-       } else  {
-            pDevice->bDiversityEnable = false;
-            pDevice->byAntennaCount = 1;
-            pDevice->dwTxAntennaSel = 0;
-            pDevice->dwRxAntennaSel = 0;
-            if (byValue & EEP_ANTENNA_AUX) {
-                pDevice->byTxAntennaMode = ANT_A;
-                if (pDevice->bTxRxAntInv == true)
-                    pDevice->byRxAntennaMode = ANT_B;
-                else
-                    pDevice->byRxAntennaMode = ANT_A;
-            } else {
-                pDevice->byTxAntennaMode = ANT_B;
-                if (pDevice->bTxRxAntInv == true)
-                    pDevice->byRxAntennaMode = ANT_A;
-                else
-                    pDevice->byRxAntennaMode = ANT_B;
-            }
-        }
-#ifdef PLICE_DEBUG
-       //printk("init registers: TxAntennaMode is %d\n",pDevice->byTxAntennaMode);
-#endif
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
-            pDevice->bDiversityEnable,(int)pDevice->ulDiversityNValue,(int)pDevice->ulDiversityMValue,pDevice->byTMax,pDevice->byTMax2);
-
-//#ifdef ZoneType_DefaultSetting
-//2008-8-4 <add> by chester
-//zonetype initial
- pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
- zonetype = Config_FileOperation(pDevice,false,NULL);
- if (zonetype >= 0) {         //read zonetype file ok!
-  if ((zonetype == 0)&&
-        (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] !=0x00)){          //for USA
-    pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
-    pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :USA\n");
-  }
- else if((zonetype == 1)&&
-            (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x01)){   //for Japan
-    pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
-    pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
-  }
- else if((zonetype == 2)&&
-            (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x02)){   //for Europe
-    pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
-    pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :Europe\n");
-  }
+       unsigned int ii;
+       unsigned char byValue;
+       unsigned char byValue1;
+       unsigned char byCCKPwrdBm = 0;
+       unsigned char byOFDMPwrdBm = 0;
+       int zonetype = 0;
+       PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
+       MACbShutdown(pDevice->PortOffset);
+       BBvSoftwareReset(pDevice->PortOffset);
+
+       if ((InitType == DEVICE_INIT_COLD) ||
+           (InitType == DEVICE_INIT_DXPL)) {
+               // Do MACbSoftwareReset in MACvInitialize
+               MACbSoftwareReset(pDevice->PortOffset);
+               // force CCK
+               pDevice->bCCK = true;
+               pDevice->bAES = false;
+               pDevice->bProtectMode = false;      //Only used in 11g type, sync with ERP IE
+               pDevice->bNonERPPresent = false;
+               pDevice->bBarkerPreambleMd = false;
+               pDevice->wCurrentRate = RATE_1M;
+               pDevice->byTopOFDMBasicRate = RATE_24M;
+               pDevice->byTopCCKBasicRate = RATE_1M;
+
+               pDevice->byRevId = 0;                   //Target to IF pin while programming to RF chip.
+
+               // init MAC
+               MACvInitialize(pDevice->PortOffset);
+
+               // Get Local ID
+               VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
 
-else
-{
-   if(zonetype!=pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
-      printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",zonetype,pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
-   else
-      printk("Read Zonetype file success,use default zonetype setting[%02x]\n",zonetype);
- }
-       }
-  else
-    printk("Read Zonetype file fail,use default zonetype setting[%02x]\n",SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
-
-        // Get RFType
-        pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
-
-        if ((pDevice->byRFType & RF_EMU) != 0) {
-            // force change RevID for VT3253 emu
-            pDevice->byRevId = 0x80;
-        }
-
-        pDevice->byRFType &= RF_MASK;
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
-
-        if (pDevice->bZoneRegExist == false) {
-            pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
-
-        //Init RF module
-        RFbInit(pDevice);
-
-        //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);
-        //byCCKPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_CCK_PWR_dBm);
-
-       //byOFDMPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_OFDM_PWR_dBm);
-//printk("CCKPwrdBm is 0x%x,byOFDMPwrdBm is 0x%x\n",byCCKPwrdBm,byOFDMPwrdBm);
-               // Load power Table
+               spin_lock_irq(&pDevice->lock);
+               SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
 
+               spin_unlock_irq(&pDevice->lock);
 
-        for (ii=0;ii<CB_MAX_CHANNEL_24G;ii++) {
-            pDevice->abyCCKPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
-            if (pDevice->abyCCKPwrTbl[ii+1] == 0) {
-                pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
-            }
-            pDevice->abyOFDMPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
-            if (pDevice->abyOFDMPwrTbl[ii+1] == 0) {
-                pDevice->abyOFDMPwrTbl[ii+1] = pDevice->byOFDMPwrG;
-            }
-            pDevice->abyCCKDefaultPwr[ii+1] = byCCKPwrdBm;
-            pDevice->abyOFDMDefaultPwr[ii+1] = byOFDMPwrdBm;
-        }
-               //2008-8-4 <add> by chester
-         //recover 12,13 ,14channel for EUROPE by 11 channel
-          if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
-               (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
-            (pDevice->byOriginalZonetype == ZoneType_USA)) {
-           for(ii=11;ii<14;ii++) {
-                pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
-              pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
+               // Get Channel range
 
-           }
-         }
+               pDevice->byMinChannel = 1;
+               pDevice->byMaxChannel = CB_MAX_CHANNEL;
 
+               // Get Antena
+               byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
+               if (byValue & EEP_ANTINV)
+                       pDevice->bTxRxAntInv = true;
+               else
+                       pDevice->bTxRxAntInv = false;
+
+               byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
+               if (byValue == 0) // if not set default is All
+                       byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
+
+               pDevice->ulDiversityNValue = 100*260;//100*SROMbyReadEmbedded(pDevice->PortOffset, 0x51);
+               pDevice->ulDiversityMValue = 100*16;//SROMbyReadEmbedded(pDevice->PortOffset, 0x52);
+               pDevice->byTMax = 1;//SROMbyReadEmbedded(pDevice->PortOffset, 0x53);
+               pDevice->byTMax2 = 4;//SROMbyReadEmbedded(pDevice->PortOffset, 0x54);
+               pDevice->ulSQ3TH = 0;//(unsigned long) SROMbyReadEmbedded(pDevice->PortOffset, 0x55);
+               pDevice->byTMax3 = 64;//SROMbyReadEmbedded(pDevice->PortOffset, 0x56);
+
+               if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
+                       pDevice->byAntennaCount = 2;
+                       pDevice->byTxAntennaMode = ANT_B;
+                       pDevice->dwTxAntennaSel = 1;
+                       pDevice->dwRxAntennaSel = 1;
+                       if (pDevice->bTxRxAntInv == true)
+                               pDevice->byRxAntennaMode = ANT_A;
+                       else
+                               pDevice->byRxAntennaMode = ANT_B;
+                       // chester for antenna
+                       byValue1 = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
+                       if ((byValue1 & 0x08) == 0)
+                               pDevice->bDiversityEnable = false;//SROMbyReadEmbedded(pDevice->PortOffset, 0x50);
+                       else
+                               pDevice->bDiversityEnable = true;
+               } else  {
+                       pDevice->bDiversityEnable = false;
+                       pDevice->byAntennaCount = 1;
+                       pDevice->dwTxAntennaSel = 0;
+                       pDevice->dwRxAntennaSel = 0;
+                       if (byValue & EEP_ANTENNA_AUX) {
+                               pDevice->byTxAntennaMode = ANT_A;
+                               if (pDevice->bTxRxAntInv == true)
+                                       pDevice->byRxAntennaMode = ANT_B;
+                               else
+                                       pDevice->byRxAntennaMode = ANT_A;
+                       } else {
+                               pDevice->byTxAntennaMode = ANT_B;
+                               if (pDevice->bTxRxAntInv == true)
+                                       pDevice->byRxAntennaMode = ANT_A;
+                               else
+                                       pDevice->byRxAntennaMode = ANT_B;
+                       }
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
+                       pDevice->bDiversityEnable, (int)pDevice->ulDiversityNValue, (int)pDevice->ulDiversityMValue, pDevice->byTMax, pDevice->byTMax2);
 
-        // Load OFDM A Power Table
-        for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
-            pDevice->abyOFDMPwrTbl[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
-            pDevice->abyOFDMDefaultPwr[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
-        }
-        init_channel_table((void *)pDevice);
+//#ifdef ZoneType_DefaultSetting
+//2008-8-4 <add> by chester
+//zonetype initial
+               pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
+               zonetype = Config_FileOperation(pDevice, false, NULL);
+               if (zonetype >= 0) {         //read zonetype file ok!
+                       if ((zonetype == 0) &&
+                           (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x00)) {          //for USA
+                               pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
+                               pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Init Zone Type :USA\n");
+                       } else if ((zonetype == 1) &&
+                                (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x01)) {   //for Japan
+                               pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
+                               pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
+                       } else if ((zonetype == 2) &&
+                                (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x02)) {   //for Europe
+                               pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
+                               pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Init Zone Type :Europe\n");
+                       }
 
+                       else {
+                               if (zonetype != pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
+                                       printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n", zonetype, pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
+                               else
+                                       printk("Read Zonetype file success,use default zonetype setting[%02x]\n", zonetype);
+                       }
+               } else
+                       printk("Read Zonetype file fail,use default zonetype setting[%02x]\n", SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
 
-        if (pDevice->byLocalID > REV_ID_VT3253_B1) {
-            MACvSelectPage1(pDevice->PortOffset);
-            VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
-            MACvSelectPage0(pDevice->PortOffset);
-        }
+               // Get RFType
+               pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
 
+               if ((pDevice->byRFType & RF_EMU) != 0) {
+                       // force change RevID for VT3253 emu
+                       pDevice->byRevId = 0x80;
+               }
 
-         // use relative tx timeout and 802.11i D4
-        MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
+               pDevice->byRFType &= RF_MASK;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
 
-        // set performance parameter by registry
-        MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
-        MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
+               if (pDevice->bZoneRegExist == false) {
+                       pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
 
-        // reset TSF counter
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
-        // enable TSF counter
-        VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
+               //Init RF module
+               RFbInit(pDevice);
 
-        // initialize BBP registers
-        BBbVT3253Init(pDevice);
+               //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);
+               //byCCKPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_CCK_PWR_dBm);
 
-        if (pDevice->bUpdateBBVGA) {
-            pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
-            pDevice->byBBVGANew = pDevice->byBBVGACurrent;
-            BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
-        }
-#ifdef PLICE_DEBUG
-       //printk("init registers:RxAntennaMode is %x,TxAntennaMode is %x\n",pDevice->byRxAntennaMode,pDevice->byTxAntennaMode);
-#endif
-        BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
-        BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
+               //byOFDMPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_OFDM_PWR_dBm);
 
-        pDevice->byCurrentCh = 0;
+               // Load power Table
 
-        //pDevice->NetworkType = Ndis802_11Automode;
-        // Set BB and packet type at the same time.
-        // Set Short Slot Time, xIFS, and RSPINF.
-        if (pDevice->uConnectionRate == RATE_AUTO) {
-            pDevice->wCurrentRate = RATE_54M;
-        } else {
-            pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
-        }
+               for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
+                       pDevice->abyCCKPwrTbl[ii + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
+                       if (pDevice->abyCCKPwrTbl[ii + 1] == 0) {
+                               pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
+                       }
+                       pDevice->abyOFDMPwrTbl[ii + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
+                       if (pDevice->abyOFDMPwrTbl[ii + 1] == 0) {
+                               pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
+                       }
+                       pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
+                       pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
+               }
+               //2008-8-4 <add> by chester
+               //recover 12,13 ,14channel for EUROPE by 11 channel
+               if (((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
+                    (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe)) &&
+                   (pDevice->byOriginalZonetype == ZoneType_USA)) {
+                       for (ii = 11; ii < 14; ii++) {
+                               pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
+                               pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
 
-        // default G Mode
-        VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
-        VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
+                       }
+               }
 
-        pDevice->bRadioOff = false;
+               // Load OFDM A Power Table
+               for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
+                       pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
+                       pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
+               }
+               init_channel_table((void *)pDevice);
 
-        pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
-        pDevice->bHWRadioOff = false;
+               if (pDevice->byLocalID > REV_ID_VT3253_B1) {
+                       MACvSelectPage1(pDevice->PortOffset);
+                       VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
+                       MACvSelectPage0(pDevice->PortOffset);
+               }
 
-        if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
-            // Get GPIO
-            MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
-//2008-4-14 <add> by chester for led issue
- #ifdef FOR_LED_ON_NOTEBOOK
-if (pDevice->byGPIO & GPIO0_DATA){pDevice->bHWRadioOff = true;}
-if ( !(pDevice->byGPIO & GPIO0_DATA)){pDevice->bHWRadioOff = false;}
-
-            }
-        if ( (pDevice->bRadioControlOff == true)) {
-            CARDbRadioPowerOff(pDevice);
-        }
-else  CARDbRadioPowerOn(pDevice);
-#else
-            if (((pDevice->byGPIO & GPIO0_DATA) && !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
-                ( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV))) {
-                pDevice->bHWRadioOff = true;
-            }
-        }
-        if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) {
-            CARDbRadioPowerOff(pDevice);
-        }
+               // use relative tx timeout and 802.11i D4
+               MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
 
-#endif
-    }
-            pMgmt->eScanType = WMAC_SCAN_PASSIVE;
-    // get Permanent network address
-    SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %pM\n",
-               pDevice->abyCurrentNetAddr);
+               // set performance parameter by registry
+               MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
+               MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
 
-    // reset Tx pointer
-    CARDvSafeResetRx(pDevice);
-    // reset Rx pointer
-    CARDvSafeResetTx(pDevice);
+               // reset TSF counter
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
+               // enable TSF counter
+               VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
 
-    if (pDevice->byLocalID <= REV_ID_VT3253_A1) {
-        MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
-    }
+               // initialize BBP registers
+               BBbVT3253Init(pDevice);
 
-    pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
+               if (pDevice->bUpdateBBVGA) {
+                       pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
+                       pDevice->byBBVGANew = pDevice->byBBVGACurrent;
+                       BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
+               }
+               BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
+               BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
 
-    // Turn On Rx DMA
-    MACvReceive0(pDevice->PortOffset);
-    MACvReceive1(pDevice->PortOffset);
+               pDevice->byCurrentCh = 0;
 
-    // start the adapter
-    MACvStart(pDevice->PortOffset);
+               //pDevice->NetworkType = Ndis802_11Automode;
+               // Set BB and packet type at the same time.
+               // Set Short Slot Time, xIFS, and RSPINF.
+               if (pDevice->uConnectionRate == RATE_AUTO) {
+                       pDevice->wCurrentRate = RATE_54M;
+               } else {
+                       pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
+               }
 
-    netif_stop_queue(pDevice->dev);
+               // default G Mode
+               VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
+               VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
 
+               pDevice->bRadioOff = false;
 
-}
+               pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
+               pDevice->bHWRadioOff = false;
 
+               if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
+                       // Get GPIO
+                       MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
+//2008-4-14 <add> by chester for led issue
+#ifdef FOR_LED_ON_NOTEBOOK
+                       if (pDevice->byGPIO & GPIO0_DATA) { pDevice->bHWRadioOff = true; }
+                       if (!(pDevice->byGPIO & GPIO0_DATA)) { pDevice->bHWRadioOff = false; }
 
+               }
+               if ((pDevice->bRadioControlOff == true)) {
+                       CARDbRadioPowerOff(pDevice);
+               } else  CARDbRadioPowerOn(pDevice);
+#else
+               if (((pDevice->byGPIO & GPIO0_DATA) && !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
+                   (!(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV))) {
+                       pDevice->bHWRadioOff = true;
+               }
+       }
+       if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) {
+               CARDbRadioPowerOff(pDevice);
+       }
 
-static void device_init_diversity_timer(PSDevice pDevice) {
+#endif
+}
+pMgmt->eScanType = WMAC_SCAN_PASSIVE;
+// get Permanent network address
+SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
+DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Network address = %pM\n",
+       pDevice->abyCurrentNetAddr);
+
+// reset Tx pointer
+CARDvSafeResetRx(pDevice);
+// reset Rx pointer
+CARDvSafeResetTx(pDevice);
+
+if (pDevice->byLocalID <= REV_ID_VT3253_A1) {
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
+}
 
-    init_timer(&pDevice->TimerSQ3Tmax1);
-    pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
-    pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
-    pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
+pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
 
-    init_timer(&pDevice->TimerSQ3Tmax2);
-    pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
-    pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
-    pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
+// Turn On Rx DMA
+MACvReceive0(pDevice->PortOffset);
+MACvReceive1(pDevice->PortOffset);
 
-    init_timer(&pDevice->TimerSQ3Tmax3);
-    pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
-    pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
-    pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
+// start the adapter
+MACvStart(pDevice->PortOffset);
 
-    return;
+netif_stop_queue(pDevice->dev);
 }
 
+static void device_init_diversity_timer(PSDevice pDevice) {
+       init_timer(&pDevice->TimerSQ3Tmax1);
+       pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
+       pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
+       pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
+
+       init_timer(&pDevice->TimerSQ3Tmax2);
+       pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
+       pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
+       pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
+
+       init_timer(&pDevice->TimerSQ3Tmax3);
+       pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
+       pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
+       pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
+
+       return;
+}
 
 static bool device_release_WPADEV(PSDevice pDevice)
 {
-  viawget_wpa_header *wpahdr;
-  int ii=0;
// wait_queue_head_t  Set_wait;
-  //send device close to wpa_supplicnat layer
-    if (pDevice->bWPADEVUp==true) {
-                 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
-                 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
-                 wpahdr->resp_ie_len = 0;
-                 wpahdr->req_ie_len = 0;
-                 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
-                 pDevice->skb->dev = pDevice->wpadev;
-                skb_reset_mac_header(pDevice->skb);
-                 pDevice->skb->pkt_type = PACKET_HOST;
-                 pDevice->skb->protocol = htons(ETH_P_802_2);
-                 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
-                 netif_rx(pDevice->skb);
-                 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-
- //wait release WPADEV
-              //    init_waitqueue_head(&Set_wait);
-              //    wait_event_timeout(Set_wait, ((pDevice->wpadev==NULL)&&(pDevice->skb == NULL)),5*HZ);    //1s wait
-              while((pDevice->bWPADEVUp==true)) {
-               set_current_state(TASK_UNINTERRUPTIBLE);
-                 schedule_timeout (HZ/20);          //wait 50ms
-                 ii++;
-               if(ii>20)
-                 break;
-              }
-           }
-    return true;
+       viawget_wpa_header *wpahdr;
+       int ii = 0;
      // wait_queue_head_t    Set_wait;
+       //send device close to wpa_supplicnat layer
+       if (pDevice->bWPADEVUp == true) {
+               wpahdr = (viawget_wpa_header *)pDevice->skb->data;
+               wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
+               wpahdr->resp_ie_len = 0;
+               wpahdr->req_ie_len = 0;
+               skb_put(pDevice->skb, sizeof(viawget_wpa_header));
+               pDevice->skb->dev = pDevice->wpadev;
+               skb_reset_mac_header(pDevice->skb);
+               pDevice->skb->pkt_type = PACKET_HOST;
+               pDevice->skb->protocol = htons(ETH_P_802_2);
+               memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
+               netif_rx(pDevice->skb);
+               pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
+
              //wait release WPADEV
+               //    init_waitqueue_head(&Set_wait);
+               //    wait_event_timeout(Set_wait, ((pDevice->wpadev==NULL)&&(pDevice->skb == NULL)),5*HZ);    //1s wait
+               while ((pDevice->bWPADEVUp == true)) {
+                       set_current_state(TASK_UNINTERRUPTIBLE);
+                       schedule_timeout(HZ / 20);          //wait 50ms
+                       ii++;
+                       if (ii > 20)
+                               break;
+               }
+       }
+       return true;
 }
 
 static const struct net_device_ops device_netdev_ops = {
@@ -905,93 +848,88 @@ static const struct net_device_ops device_netdev_ops = {
 static int
 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
 {
-    static bool bFirst = true;
-    struct net_device*  dev = NULL;
-    PCHIP_INFO  pChip_info = (PCHIP_INFO)ent->driver_data;
-    PSDevice    pDevice;
-    int         rc;
-    if (device_nics ++>= MAX_UINTS) {
-        printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
-        return -ENODEV;
-    }
-
-
-    dev = alloc_etherdev(sizeof(DEVICE_INFO));
-
-    pDevice = (PSDevice) netdev_priv(dev);
-
-    if (dev == NULL) {
-        printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
-        return -ENOMEM;
-    }
-
-    // Chain it all together
-   // SET_MODULE_OWNER(dev);
-    SET_NETDEV_DEV(dev, &pcid->dev);
-
-    if (bFirst) {
-        printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
-        printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
-        bFirst=false;
-    }
-
-    vt6655_init_info(pcid, &pDevice, pChip_info);
-    pDevice->dev = dev;
-    pDevice->next_module = root_device_dev;
-    root_device_dev = dev;
-
-    if (pci_enable_device(pcid)) {
-        device_free_info(pDevice);
-        return -ENODEV;
-    }
-    dev->irq = pcid->irq;
+       static bool bFirst = true;
+       struct net_device *dev = NULL;
+       PCHIP_INFO  pChip_info = (PCHIP_INFO)ent->driver_data;
+       PSDevice    pDevice;
+       int         rc;
+       if (device_nics++ >= MAX_UINTS) {
+               printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
+               return -ENODEV;
+       }
+
+       dev = alloc_etherdev(sizeof(DEVICE_INFO));
+
+       pDevice = (PSDevice) netdev_priv(dev);
+
+       if (dev == NULL) {
+               printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
+               return -ENOMEM;
+       }
+
+       // Chain it all together
+       // SET_MODULE_OWNER(dev);
+       SET_NETDEV_DEV(dev, &pcid->dev);
+
+       if (bFirst) {
+               printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
+               printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
+               bFirst = false;
+       }
+
+       vt6655_init_info(pcid, &pDevice, pChip_info);
+       pDevice->dev = dev;
+       pDevice->next_module = root_device_dev;
+       root_device_dev = dev;
+
+       if (pci_enable_device(pcid)) {
+               device_free_info(pDevice);
+               return -ENODEV;
+       }
+       dev->irq = pcid->irq;
 
 #ifdef DEBUG
-       printk("Before get pci_info memaddr is %x\n",pDevice->memaddr);
+       printk("Before get pci_info memaddr is %x\n", pDevice->memaddr);
 #endif
-    if (device_get_pci_info(pDevice,pcid) == false) {
-        printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
-        device_free_info(pDevice);
-        return -ENODEV;
-    }
+       if (device_get_pci_info(pDevice, pcid) == false) {
+               printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
+               device_free_info(pDevice);
+               return -ENODEV;
+       }
 
 #if 1
 
 #ifdef DEBUG
 
        //pci_read_config_byte(pcid, PCI_BASE_ADDRESS_0, &pDevice->byRevId);
-       printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",pDevice->memaddr,pDevice->ioaddr,pDevice->io_size);
+       printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n", pDevice->memaddr, pDevice->ioaddr, pDevice->io_size);
        {
                int i;
-               u32                     bar,len;
+               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_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_write_config_dword(pcid,address[i], 0xFFFFFFFF);
                        pci_read_config_dword(pcid, address[i], &bar);
-                       printk("bar %d is %x\n",i,bar);
-                       if (!bar)
-                       {
-                               printk("bar %d not implemented\n",i);
+                       printk("bar %d is %x\n", i, bar);
+                       if (!bar) {
+                               printk("bar %d not implemented\n", i);
                                continue;
                        }
                        if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
-                       /* This is IO */
+                               /* This is IO */
 
-                       len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
-                       len = len & ~(len - 1);
+                               len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
+                               len = len & ~(len - 1);
 
-                       printk("IO space:  len in IO %x, BAR %d\n", len, i);
-                       }
-                       else
-                       {
+                               printk("IO space:  len in IO %x, BAR %d\n", len, i);
+                       } else {
                                len = bar & 0xFFFFFFF0;
                                len = ~len + 1;
 
@@ -1001,813 +939,745 @@ vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
        }
 #endif
 
-
 #endif
 
 #ifdef DEBUG
-       //return  0  ;
+       //return  0;
 #endif
-    pDevice->PortOffset = (unsigned long)ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
+       pDevice->PortOffset = (unsigned long)ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
        //pDevice->PortOffset = (unsigned long)ioremap(pDevice->ioaddr & PCI_BASE_ADDRESS_IO_MASK, pDevice->io_size);
 
-       if(pDevice->PortOffset == 0) {
-       printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
-       device_free_info(pDevice);
-        return -ENODEV;
-    }
-
-
-
+       if (pDevice->PortOffset == 0) {
+               printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
+               device_free_info(pDevice);
+               return -ENODEV;
+       }
 
-    rc = pci_request_regions(pcid, DEVICE_NAME);
-    if (rc) {
-        printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
-        device_free_info(pDevice);
-        return -ENODEV;
-    }
+       rc = pci_request_regions(pcid, DEVICE_NAME);
+       if (rc) {
+               printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
+               device_free_info(pDevice);
+               return -ENODEV;
+       }
 
-    dev->base_addr = pDevice->ioaddr;
+       dev->base_addr = pDevice->ioaddr;
 #ifdef PLICE_DEBUG
-       unsigned char   value;
+       unsigned char value;
 
        VNSvInPortB(pDevice->PortOffset+0x4F, &value);
-       printk("Before write: value is %x\n",value);
+       printk("Before write: value is %x\n", value);
        //VNSvInPortB(pDevice->PortOffset+0x3F, 0x00);
-       VNSvOutPortB(pDevice->PortOffset,value);
+       VNSvOutPortB(pDevice->PortOffset, value);
        VNSvInPortB(pDevice->PortOffset+0x4F, &value);
-       printk("After write: value is %x\n",value);
+       printk("After write: value is %x\n", value);
 #endif
 
-
-
 #ifdef IO_MAP
-    pDevice->PortOffset = pDevice->ioaddr;
+       pDevice->PortOffset = pDevice->ioaddr;
 #endif
-    // do reset
-    if (!MACbSoftwareReset(pDevice->PortOffset)) {
-        printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
-        device_free_info(pDevice);
-        return -ENODEV;
-    }
-    // initial to reload eeprom
-    MACvInitialize(pDevice->PortOffset);
-    MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
-
-    device_get_options(pDevice, device_nics-1, dev->name);
-    device_set_options(pDevice);
-    //Mask out the options cannot be set to the chip
-    pDevice->sOpts.flags &= pChip_info->flags;
-
-    //Enable the chip specified capabilities
-    pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
-    pDevice->tx_80211 = device_dma0_tx_80211;
-    pDevice->sMgmtObj.pAdapter = (void *)pDevice;
-    pDevice->pMgmt = &(pDevice->sMgmtObj);
-
-    dev->irq                = pcid->irq;
-    dev->netdev_ops         = &device_netdev_ops;
+       // do reset
+       if (!MACbSoftwareReset(pDevice->PortOffset)) {
+               printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
+               device_free_info(pDevice);
+               return -ENODEV;
+       }
+       // initial to reload eeprom
+       MACvInitialize(pDevice->PortOffset);
+       MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
 
-       dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
+       device_get_options(pDevice, device_nics-1, dev->name);
+       device_set_options(pDevice);
+       //Mask out the options cannot be set to the chip
+       pDevice->sOpts.flags &= pChip_info->flags;
 
-    rc = register_netdev(dev);
-    if (rc)
-    {
-        printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
-        device_free_info(pDevice);
-        return -ENODEV;
-    }
-    device_print_info(pDevice);
-    pci_set_drvdata(pcid, pDevice);
-    return 0;
+       //Enable the chip specified capabilities
+       pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
+       pDevice->tx_80211 = device_dma0_tx_80211;
+       pDevice->sMgmtObj.pAdapter = (void *)pDevice;
+       pDevice->pMgmt = &(pDevice->sMgmtObj);
 
+       dev->irq                = pcid->irq;
+       dev->netdev_ops         = &device_netdev_ops;
+
+       dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
+
+       rc = register_netdev(dev);
+       if (rc) {
+               printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
+               device_free_info(pDevice);
+               return -ENODEV;
+       }
+       device_print_info(pDevice);
+       pci_set_drvdata(pcid, pDevice);
+       return 0;
 }
 
 static void device_print_info(PSDevice pDevice)
 {
-    struct net_device* dev=pDevice->dev;
+       struct net_device *dev = pDevice->dev;
 
-    DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n",dev->name, get_chip_name(pDevice->chip_id));
-    DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%pM", dev->name, dev->dev_addr);
+       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n", dev->name, get_chip_name(pDevice->chip_id));
+       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%pM", dev->name, dev->dev_addr);
 #ifdef IO_MAP
-    DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx  ",(unsigned long) pDevice->ioaddr);
-    DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
+       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IO=0x%lx  ", (unsigned long)pDevice->ioaddr);
+       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IRQ=%d \n", pDevice->dev->irq);
 #else
-    DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx Mem=0x%lx ",
-                   (unsigned long) pDevice->ioaddr,(unsigned long) pDevice->PortOffset);
-    DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
+       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IO=0x%lx Mem=0x%lx ",
+               (unsigned long)pDevice->ioaddr, (unsigned long)pDevice->PortOffset);
+       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IRQ=%d \n", pDevice->dev->irq);
 #endif
-
 }
 
-static void vt6655_init_info(struct pci_dev* pcid, PSDevice* ppDevice,
-    PCHIP_INFO pChip_info) {
+static void vt6655_init_info(struct pci_dev *pcid, PSDevice *ppDevice,
+                            PCHIP_INFO pChip_info) {
+       PSDevice p;
 
-    PSDevice p;
+       memset(*ppDevice, 0, sizeof(DEVICE_INFO));
 
-    memset(*ppDevice,0,sizeof(DEVICE_INFO));
-
-    if (pDevice_Infos == NULL) {
-        pDevice_Infos =*ppDevice;
-    }
-    else {
-        for (p=pDevice_Infos;p->next!=NULL;p=p->next)
-            do {} while (0);
-        p->next = *ppDevice;
-        (*ppDevice)->prev = p;
-    }
+       if (pDevice_Infos == NULL) {
+               pDevice_Infos = *ppDevice;
+       } else {
+               for (p = pDevice_Infos; p->next != NULL; p = p->next)
+                       do {} while (0);
+               p->next = *ppDevice;
+               (*ppDevice)->prev = p;
+       }
 
-    (*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;
+       (*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));
+       spin_lock_init(&((*ppDevice)->lock));
 }
 
-static bool device_get_pci_info(PSDevice pDevice, struct pci_dev* pcid) {
-
-    u16 pci_cmd;
-    u8  b;
-    unsigned int cis_addr;
+static bool device_get_pci_info(PSDevice pDevice, struct pci_dev *pcid) {
+       u16 pci_cmd;
+       u8  b;
+       unsigned int cis_addr;
 #ifdef PLICE_DEBUG
        unsigned char pci_config[256];
-       unsigned char   value =0x00;
-       int             ii,j;
-       u16     max_lat=0x0000;
-       memset(pci_config,0x00,256);
+       unsigned char value = 0x00;
+       int             ii, j;
+       u16     max_lat = 0x0000;
+       memset(pci_config, 0x00, 256);
 #endif
 
-    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_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);
+       pci_set_master(pcid);
 
-    pDevice->memaddr = pci_resource_start(pcid,0);
-    pDevice->ioaddr = pci_resource_start(pcid,1);
+       pDevice->memaddr = pci_resource_start(pcid, 0);
+       pDevice->ioaddr = pci_resource_start(pcid, 1);
 
 #ifdef DEBUG
 //     pDevice->ioaddr = pci_resource_start(pcid, 0);
 //     pDevice->memaddr = pci_resource_start(pcid,1);
 #endif
 
-    cis_addr = pci_resource_start(pcid,2);
+       cis_addr = pci_resource_start(pcid, 2);
 
-    pDevice->pcid = pcid;
+       pDevice->pcid = pcid;
 
-    pci_read_config_byte(pcid, PCI_COMMAND, &b);
-    pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
+       pci_read_config_byte(pcid, PCI_COMMAND, &b);
+       pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
 
 #ifdef PLICE_DEBUG
-       //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
-       //printk("max lat is %x,SubSystemID is %x\n",max_lat,pDevice->SubSystemID);
+       //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
        //for (ii=0;ii<0xFF;ii++)
        //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
        //max_lat  = 0x20;
        //pci_write_config_word(pcid,PCI_MAX_LAT,max_lat);
        //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
-       //printk("max lat is %x\n",max_lat);
 
-       for (ii=0;ii<0xFF;ii++)
-       {
-               pci_read_config_byte(pcid,ii,&value);
+       for (ii = 0; ii < 0xFF; ii++) {
+               pci_read_config_byte(pcid, ii, &value);
                pci_config[ii] = value;
        }
-       for (ii=0,j=1;ii<0x100;ii++,j++)
-       {
-               if (j %16 == 0)
-               {
-                       printk("%x:",pci_config[ii]);
+       for (ii = 0, j = 1; ii < 0x100; ii++, j++) {
+               if (j % 16 == 0) {
+                       printk("%x:", pci_config[ii]);
                        printk("\n");
-               }
-               else
-               {
-                       printk("%x:",pci_config[ii]);
+               } else {
+                       printk("%x:", pci_config[ii]);
                }
        }
 #endif
-    return true;
+       return true;
 }
 
 static void device_free_info(PSDevice pDevice) {
-    PSDevice         ptr;
-    struct net_device*  dev=pDevice->dev;
+       PSDevice         ptr;
+       struct net_device *dev = pDevice->dev;
 
-    ASSERT(pDevice);
+       ASSERT(pDevice);
 //2008-0714-01<Add>by chester
-device_release_WPADEV(pDevice);
+       device_release_WPADEV(pDevice);
 
 //2008-07-21-01<Add>by MikeLiu
 //unregister wpadev
-   if(wpa_set_wpadev(pDevice, 0)!=0)
-     printk("unregister wpadev fail?\n");
-
-    if (pDevice_Infos==NULL)
-        return;
-
-    for (ptr=pDevice_Infos;ptr && (ptr!=pDevice);ptr=ptr->next)
-            do {} while (0);
-
-    if (ptr==pDevice) {
-        if (ptr==pDevice_Infos)
-            pDevice_Infos=ptr->next;
-        else
-            ptr->prev->next=ptr->next;
-    }
-    else {
-        DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
-        return;
-    }
+       if (wpa_set_wpadev(pDevice, 0) != 0)
+               printk("unregister wpadev fail?\n");
+
+       if (pDevice_Infos == NULL)
+               return;
+
+       for (ptr = pDevice_Infos; ptr && (ptr != pDevice); ptr = ptr->next)
+               do {} while (0);
+
+       if (ptr == pDevice) {
+               if (ptr == pDevice_Infos)
+                       pDevice_Infos = ptr->next;
+               else
+                       ptr->prev->next = ptr->next;
+       } else {
+               DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
+               return;
+       }
 #ifdef HOSTAP
-    if (dev)
-        vt6655_hostap_set_hostapd(pDevice, 0, 0);
+       if (dev)
+               vt6655_hostap_set_hostapd(pDevice, 0, 0);
 #endif
-    if (dev)
-        unregister_netdev(dev);
+       if (dev)
+               unregister_netdev(dev);
 
-    if (pDevice->PortOffset)
-        iounmap((void *)pDevice->PortOffset);
+       if (pDevice->PortOffset)
+               iounmap((void *)pDevice->PortOffset);
 
-    if (pDevice->pcid)
-        pci_release_regions(pDevice->pcid);
-    if (dev)
-        free_netdev(dev);
+       if (pDevice->pcid)
+               pci_release_regions(pDevice->pcid);
+       if (dev)
+               free_netdev(dev);
 
-    if (pDevice->pcid) {
-        pci_set_drvdata(pDevice->pcid,NULL);
-    }
+       if (pDevice->pcid) {
+               pci_set_drvdata(pDevice->pcid, NULL);
+       }
 }
 
 static bool device_init_rings(PSDevice pDevice) {
-    void*   vir_pool;
-
-
-    /*allocate all RD/TD rings a single pool*/
-    vir_pool = pci_alloc_consistent(pDevice->pcid,
-                    pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
-                    pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
-                    pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
-                    pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
-                    &pDevice->pool_dma);
-
-    if (vir_pool == NULL) {
-        DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
-        return false;
-    }
-
-    memset(vir_pool, 0,
-            pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
-            pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
-            pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
-            pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
-          );
-
-    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 = pci_alloc_consistent(pDevice->pcid,
-                    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);
-
-    if (pDevice->tx0_bufs == NULL) {
-        DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
-        pci_free_consistent(pDevice->pcid,
-            pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
-            pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
-            pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
-            pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
-            vir_pool, pDevice->pool_dma
-            );
-        return false;
-    }
-
-    memset(pDevice->tx0_bufs, 0,
-           pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
-           pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
-           CB_BEACON_BUF_SIZE +
-           CB_MAX_BUF_SIZE
-          );
-
-    pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
-            pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
-
-    pDevice->td1_pool_dma = pDevice->td0_pool_dma +
-            pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
-
+       void *vir_pool;
+
+       /*allocate all RD/TD rings a single pool*/
+       vir_pool = pci_alloc_consistent(pDevice->pcid,
+                                       pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
+                                       pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
+                                       pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
+                                       pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
+                                       &pDevice->pool_dma);
+
+       if (vir_pool == NULL) {
+               DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
+               return false;
+       }
 
-    // vir_pool: pvoid type
-    pDevice->apTD0Rings = vir_pool
-                          + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
-                          + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
+       memset(vir_pool, 0,
+              pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
+              pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
+              pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
+              pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
+               );
+
+       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 = pci_alloc_consistent(pDevice->pcid,
+                                                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);
+
+       if (pDevice->tx0_bufs == NULL) {
+               DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
+               pci_free_consistent(pDevice->pcid,
+                                   pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
+                                   pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
+                                   pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
+                                   pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
+                                   vir_pool, pDevice->pool_dma
+                       );
+               return false;
+       }
 
-    pDevice->apTD1Rings = vir_pool
-            + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
-            + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
-            + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
+       memset(pDevice->tx0_bufs, 0,
+              pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
+              pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
+              CB_BEACON_BUF_SIZE +
+              CB_MAX_BUF_SIZE
+               );
 
+       pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
+               pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
 
-    pDevice->tx1_bufs = pDevice->tx0_bufs +
-            pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
+       pDevice->td1_pool_dma = pDevice->td0_pool_dma +
+               pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
 
+       // vir_pool: pvoid type
+       pDevice->apTD0Rings = vir_pool
+               + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
+               + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
 
-    pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
-            pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
+       pDevice->apTD1Rings = vir_pool
+               + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
+               + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
+               + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
 
-    pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
-            CB_BEACON_BUF_SIZE;
+       pDevice->tx1_bufs = pDevice->tx0_bufs +
+               pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
 
-    pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
-            pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
+       pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
+               pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
 
+       pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
+               CB_BEACON_BUF_SIZE;
 
-    pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
-            pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
+       pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
+               pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
 
+       pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
+               pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
 
-    return true;
+       return true;
 }
 
 static void device_free_rings(PSDevice pDevice) {
-
-    pci_free_consistent(pDevice->pcid,
-            pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
-            pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
-            pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
-            pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
-            ,
-            pDevice->aRD0Ring, pDevice->pool_dma
-        );
-
-    if (pDevice->tx0_bufs)
-        pci_free_consistent(pDevice->pcid,
-           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
-        );
+       pci_free_consistent(pDevice->pcid,
+                           pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
+                           pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
+                           pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
+                           pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
+                           ,
+                           pDevice->aRD0Ring, pDevice->pool_dma
+               );
+
+       if (pDevice->tx0_bufs)
+               pci_free_consistent(pDevice->pcid,
+                                   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
+                       );
 }
 
 static void device_init_rd0_ring(PSDevice pDevice) {
-    int i;
-    dma_addr_t      curr = pDevice->rd0_pool_dma;
-    PSRxDesc        pDesc;
-
-    /* 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();
-        ASSERT(pDesc->pRDInfo);
-        if (!device_alloc_rx_buf(pDevice, pDesc)) {
-            DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
-            pDevice->dev->name);
-        }
-        pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
-        pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
-        pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
-    }
-
-    if (i > 0)
-        pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
-    pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
-}
+       int i;
+       dma_addr_t      curr = pDevice->rd0_pool_dma;
+       PSRxDesc        pDesc;
+
+       /* 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();
+               ASSERT(pDesc->pRDInfo);
+               if (!device_alloc_rx_buf(pDevice, pDesc)) {
+                       DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc rx bufs\n",
+                               pDevice->dev->name);
+               }
+               pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
+               pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
+               pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
+       }
 
+       if (i > 0)
+               pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
+       pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
+}
 
 static void device_init_rd1_ring(PSDevice pDevice) {
-    int i;
-    dma_addr_t      curr = pDevice->rd1_pool_dma;
-    PSRxDesc        pDesc;
-
-    /* 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();
-        ASSERT(pDesc->pRDInfo);
-        if (!device_alloc_rx_buf(pDevice, pDesc)) {
-            DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
-            pDevice->dev->name);
-        }
-        pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
-        pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
-        pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
-    }
-
-    if (i > 0)
-        pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
-    pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
-}
+       int i;
+       dma_addr_t      curr = pDevice->rd1_pool_dma;
+       PSRxDesc        pDesc;
+
+       /* 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();
+               ASSERT(pDesc->pRDInfo);
+               if (!device_alloc_rx_buf(pDevice, pDesc)) {
+                       DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc rx bufs\n",
+                               pDevice->dev->name);
+               }
+               pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
+               pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
+               pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
+       }
 
+       if (i > 0)
+               pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
+       pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
+}
 
 static void device_init_defrag_cb(PSDevice pDevice) {
-    int i;
-    PSDeFragControlBlock pDeF;
-
-    /* Init the fragment ctl entries */
-    for (i = 0; i < CB_MAX_RX_FRAG; i++) {
-        pDeF = &(pDevice->sRxDFCB[i]);
-        if (!device_alloc_frag_buf(pDevice, pDeF)) {
-            DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
-                pDevice->dev->name);
-        }
-    }
-    pDevice->cbDFCB = CB_MAX_RX_FRAG;
-    pDevice->cbFreeDFCB = pDevice->cbDFCB;
+       int i;
+       PSDeFragControlBlock pDeF;
+
+       /* Init the fragment ctl entries */
+       for (i = 0; i < CB_MAX_RX_FRAG; i++) {
+               pDeF = &(pDevice->sRxDFCB[i]);
+               if (!device_alloc_frag_buf(pDevice, pDeF)) {
+                       DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc frag bufs\n",
+                               pDevice->dev->name);
+               }
+       }
+       pDevice->cbDFCB = CB_MAX_RX_FRAG;
+       pDevice->cbFreeDFCB = pDevice->cbDFCB;
 }
 
-
-
-
 static void device_free_rd0_ring(PSDevice pDevice) {
-    int i;
-
-    for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
-        PSRxDesc        pDesc =&(pDevice->aRD0Ring[i]);
-        PDEVICE_RD_INFO  pRDInfo =pDesc->pRDInfo;
+       int i;
 
-        pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
-           pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
+       for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
+               PSRxDesc        pDesc = &(pDevice->aRD0Ring[i]);
+               PDEVICE_RD_INFO  pRDInfo = pDesc->pRDInfo;
 
-        dev_kfree_skb(pRDInfo->skb);
+               pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
+                                pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
 
-        kfree((void *)pDesc->pRDInfo);
-    }
+               dev_kfree_skb(pRDInfo->skb);
 
+               kfree((void *)pDesc->pRDInfo);
+       }
 }
 
 static void device_free_rd1_ring(PSDevice pDevice) {
-    int i;
-
-
-    for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
-        PSRxDesc        pDesc=&(pDevice->aRD1Ring[i]);
-        PDEVICE_RD_INFO  pRDInfo=pDesc->pRDInfo;
+       int i;
 
-        pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
-           pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
+       for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
+               PSRxDesc        pDesc = &(pDevice->aRD1Ring[i]);
+               PDEVICE_RD_INFO  pRDInfo = pDesc->pRDInfo;
 
-        dev_kfree_skb(pRDInfo->skb);
+               pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
+                                pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
 
-        kfree((void *)pDesc->pRDInfo);
-    }
+               dev_kfree_skb(pRDInfo->skb);
 
+               kfree((void *)pDesc->pRDInfo);
+       }
 }
 
 static void device_free_frag_buf(PSDevice pDevice) {
-    PSDeFragControlBlock pDeF;
-    int i;
-
-    for (i = 0; i < CB_MAX_RX_FRAG; i++) {
-
-        pDeF = &(pDevice->sRxDFCB[i]);
+       PSDeFragControlBlock pDeF;
+       int i;
 
-        if (pDeF->skb)
-            dev_kfree_skb(pDeF->skb);
+       for (i = 0; i < CB_MAX_RX_FRAG; i++) {
+               pDeF = &(pDevice->sRxDFCB[i]);
 
-    }
+               if (pDeF->skb)
+                       dev_kfree_skb(pDeF->skb);
 
+       }
 }
 
 static void device_init_td0_ring(PSDevice pDevice) {
-    int i;
-    dma_addr_t  curr;
-    PSTxDesc        pDesc;
-
-    curr = pDevice->td0_pool_dma;
-    for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
-        pDesc = &(pDevice->apTD0Rings[i]);
-        pDesc->pTDInfo = alloc_td_info();
-        ASSERT(pDesc->pTDInfo);
-        if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
-            pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
-            pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
-        }
-        pDesc->next =&(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
-        pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
-        pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
-    }
-
-    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]);
+       int i;
+       dma_addr_t  curr;
+       PSTxDesc        pDesc;
+
+       curr = pDevice->td0_pool_dma;
+       for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
+               pDesc = &(pDevice->apTD0Rings[i]);
+               pDesc->pTDInfo = alloc_td_info();
+               ASSERT(pDesc->pTDInfo);
+               if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
+                       pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
+                       pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
+               }
+               pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
+               pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
+               pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
+       }
 
+       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]);
 }
 
 static void device_init_td1_ring(PSDevice pDevice) {
-    int i;
-    dma_addr_t  curr;
-    PSTxDesc    pDesc;
-
-    /* Init the TD ring entries */
-    curr=pDevice->td1_pool_dma;
-    for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr+=sizeof(STxDesc)) {
-        pDesc=&(pDevice->apTD1Rings[i]);
-        pDesc->pTDInfo = alloc_td_info();
-        ASSERT(pDesc->pTDInfo);
-        if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
-            pDesc->pTDInfo->buf=pDevice->tx1_bufs+(i)*PKT_BUF_SZ;
-            pDesc->pTDInfo->buf_dma=pDevice->tx_bufs_dma1+(i)*PKT_BUF_SZ;
-        }
-        pDesc->next=&(pDevice->apTD1Rings[(i+1) % pDevice->sOpts.nTxDescs[1]]);
-        pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
-        pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
-    }
-
-    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]);
-}
-
+       int i;
+       dma_addr_t  curr;
+       PSTxDesc    pDesc;
+
+       /* Init the TD ring entries */
+       curr = pDevice->td1_pool_dma;
+       for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
+               pDesc = &(pDevice->apTD1Rings[i]);
+               pDesc->pTDInfo = alloc_td_info();
+               ASSERT(pDesc->pTDInfo);
+               if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
+                       pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
+                       pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
+               }
+               pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
+               pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
+               pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
+       }
 
+       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]);
+}
 
 static void device_free_td0_ring(PSDevice pDevice) {
-    int i;
-    for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
-        PSTxDesc        pDesc=&(pDevice->apTD0Rings[i]);
-        PDEVICE_TD_INFO  pTDInfo=pDesc->pTDInfo;
+       int i;
+       for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
+               PSTxDesc        pDesc = &(pDevice->apTD0Rings[i]);
+               PDEVICE_TD_INFO  pTDInfo = pDesc->pTDInfo;
 
-        if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
-            pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,
-               pTDInfo->skb->len, PCI_DMA_TODEVICE);
+               if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
+                       pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
+                                        pTDInfo->skb->len, PCI_DMA_TODEVICE);
 
-        if (pTDInfo->skb)
-            dev_kfree_skb(pTDInfo->skb);
+               if (pTDInfo->skb)
+                       dev_kfree_skb(pTDInfo->skb);
 
-        kfree((void *)pDesc->pTDInfo);
-    }
+               kfree((void *)pDesc->pTDInfo);
+       }
 }
 
 static void device_free_td1_ring(PSDevice pDevice) {
-    int i;
-
-    for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
-        PSTxDesc        pDesc=&(pDevice->apTD1Rings[i]);
-        PDEVICE_TD_INFO  pTDInfo=pDesc->pTDInfo;
+       int i;
 
-        if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
-            pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
-               pTDInfo->skb->len, PCI_DMA_TODEVICE);
+       for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
+               PSTxDesc        pDesc = &(pDevice->apTD1Rings[i]);
+               PDEVICE_TD_INFO  pTDInfo = pDesc->pTDInfo;
 
-        if (pTDInfo->skb)
-            dev_kfree_skb(pTDInfo->skb);
+               if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
+                       pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
+                                        pTDInfo->skb->len, PCI_DMA_TODEVICE);
 
-        kfree((void *)pDesc->pTDInfo);
-    }
+               if (pTDInfo->skb)
+                       dev_kfree_skb(pTDInfo->skb);
 
+               kfree((void *)pDesc->pTDInfo);
+       }
 }
 
-
-
 /*-----------------------------------------------------------------*/
 
 static int device_rx_srv(PSDevice pDevice, unsigned int uIdx) {
-    PSRxDesc    pRD;
-    int works = 0;
+       PSRxDesc    pRD;
+       int works = 0;
 
-
-    for (pRD = pDevice->pCurrRD[uIdx];
-         pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
-         pRD = pRD->next) {
+       for (pRD = pDevice->pCurrRD[uIdx];
+            pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
+            pRD = pRD->next) {
 //        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->pCurrRD = %x, works = %d\n", pRD, works);
-        if (works++>15)
-            break;
-        if (device_receive_frame(pDevice, pRD)) {
-            if (!device_alloc_rx_buf(pDevice,pRD)) {
-                    DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
-                    "%s: can not allocate rx buf\n", pDevice->dev->name);
-                    break;
-            }
-        }
-        pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
-        pDevice->dev->last_rx = jiffies;
-    }
-
-    pDevice->pCurrRD[uIdx]=pRD;
-
-    return works;
-}
+               if (works++ > 15)
+                       break;
+               if (device_receive_frame(pDevice, pRD)) {
+                       if (!device_alloc_rx_buf(pDevice, pRD)) {
+                               DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
+                                       "%s: can not allocate rx buf\n", pDevice->dev->name);
+                               break;
+                       }
+               }
+               pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
+               pDevice->dev->last_rx = jiffies;
+       }
 
+       pDevice->pCurrRD[uIdx] = pRD;
 
-static bool device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD) {
+       return works;
+}
 
-    PDEVICE_RD_INFO pRDInfo=pRD->pRDInfo;
+static bool device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD) {
+       PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
+
+       pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
+       if (pRDInfo->skb == NULL)
+               return false;
+       ASSERT(pRDInfo->skb);
+       pRDInfo->skb->dev = pDevice->dev;
+       pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
+                                         pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
+       *((unsigned int *)&(pRD->m_rd0RD0)) = 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);
+
+       return true;
+}
 
+bool device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
+       pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
+       if (pDeF->skb == NULL)
+               return false;
+       ASSERT(pDeF->skb);
+       pDeF->skb->dev = pDevice->dev;
 
-    pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-#ifdef PLICE_DEBUG
-       //printk("device_alloc_rx_buf:skb is %x\n",pRDInfo->skb);
-#endif
-    if (pRDInfo->skb==NULL)
-        return false;
-    ASSERT(pRDInfo->skb);
-    pRDInfo->skb->dev = pDevice->dev;
-    pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
-                                     pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
-    *((unsigned int *) &(pRD->m_rd0RD0)) = 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);
-
-    return true;
+       return true;
 }
 
+static int device_tx_srv(PSDevice pDevice, unsigned int uIdx) {
+       PSTxDesc                 pTD;
+       bool bFull = false;
+       int                      works = 0;
+       unsigned char byTsr0;
+       unsigned char byTsr1;
+       unsigned int    uFrameSize, uFIFOHeaderSize;
+       PSTxBufHead              pTxBufHead;
+       struct net_device_stats *pStats = &pDevice->stats;
+       struct sk_buff *skb;
+       unsigned int    uNodeIndex;
+       PSMgmtObject             pMgmt = pDevice->pMgmt;
+
+       for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
+               if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
+                       break;
+               if (works++ > 15)
+                       break;
 
+               byTsr0 = pTD->m_td0TD0.byTSR0;
+               byTsr1 = pTD->m_td0TD0.byTSR1;
+
+               //Only the status of first TD in the chain is correct
+               if (pTD->m_td1TD1.byTCR & TCR_STP) {
+                       if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
+                               uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
+                               uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
+                               pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
+                               // Update the statistics based on the Transmit status
+                               // now, we DONT check TSR0_CDH
+
+                               STAvUpdateTDStatCounter(&pDevice->scStatistic,
+                                                       byTsr0, byTsr1,
+                                                       (unsigned char *)(pTD->pTDInfo->buf + uFIFOHeaderSize),
+                                                       uFrameSize, uIdx);
+
+                               BSSvUpdateNodeTxCounter(pDevice,
+                                                       byTsr0, byTsr1,
+                                                       (unsigned char *)(pTD->pTDInfo->buf),
+                                                       uFIFOHeaderSize
+                                       );
+
+                               if (!(byTsr1 & TSR1_TERR)) {
+                                       if (byTsr0 != 0) {
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
+                                                       (int)uIdx, byTsr1, byTsr0);
+                                       }
+                                       if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG) {
+                                               pDevice->s802_11Counter.TransmittedFragmentCount++;
+                                       }
+                                       pStats->tx_packets++;
+                                       pStats->tx_bytes += pTD->pTDInfo->skb->len;
+                               } else {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
+                                               (int)uIdx, byTsr1, byTsr0);
+                                       pStats->tx_errors++;
+                                       pStats->tx_dropped++;
+                               }
+                       }
 
-bool device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
+                       if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
+                               if (pDevice->bEnableHostapd) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif.. \n");
+                                       skb = pTD->pTDInfo->skb;
+                                       skb->dev = pDevice->apdev;
+                                       skb_reset_mac_header(skb);
+                                       skb->pkt_type = PACKET_OTHERHOST;
+                                       //skb->protocol = htons(ETH_P_802_2);
+                                       memset(skb->cb, 0, sizeof(skb->cb));
+                                       netif_rx(skb);
+                               }
+                       }
 
-    pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-    if (pDeF->skb == NULL)
-        return false;
-    ASSERT(pDeF->skb);
-    pDeF->skb->dev = pDevice->dev;
+                       if (byTsr1 & TSR1_TERR) {
+                               if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
+                                               (int)uIdx, byTsr1, byTsr0);
+                               }
 
-    return true;
-}
+//                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
+//                          (int)uIdx, byTsr1, byTsr0);
+
+                               if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
+                                   (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
+                                       unsigned short wAID;
+                                       unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
+
+                                       skb = pTD->pTDInfo->skb;
+                                       if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
+                                               if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
+                                                       skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
+                                                       pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
+                                                       // set tx map
+                                                       wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
+                                                       pMgmt->abyPSTxMap[wAID >> 3] |=  byMask[wAID & 7];
+                                                       pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
+                                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
+                                                               , (int)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
+                                                       pStats->tx_errors--;
+                                                       pStats->tx_dropped--;
+                                               }
+                                       }
+                               }
+                       }
+                       device_free_tx_buf(pDevice, pTD);
+                       pDevice->iTDUsed[uIdx]--;
+               }
+       }
 
+       if (uIdx == TYPE_AC0DMA) {
+               // RESERV_AC0DMA reserved for relay
 
+               if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
+                       bFull = true;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
+               }
+               if (netif_queue_stopped(pDevice->dev) && (bFull == false)) {
+                       netif_wake_queue(pDevice->dev);
+               }
+       }
 
-static int device_tx_srv(PSDevice pDevice, unsigned int uIdx) {
-    PSTxDesc                 pTD;
-    bool bFull=false;
-    int                      works = 0;
-    unsigned char byTsr0;
-    unsigned char byTsr1;
-    unsigned int       uFrameSize, uFIFOHeaderSize;
-    PSTxBufHead              pTxBufHead;
-    struct net_device_stats* pStats = &pDevice->stats;
-    struct sk_buff*          skb;
-    unsigned int       uNodeIndex;
-    PSMgmtObject             pMgmt = pDevice->pMgmt;
-
-
-    for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] >0; pTD = pTD->next) {
-
-        if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
-            break;
-        if (works++>15)
-            break;
-
-        byTsr0 = pTD->m_td0TD0.byTSR0;
-        byTsr1 = pTD->m_td0TD0.byTSR1;
-
-        //Only the status of first TD in the chain is correct
-        if (pTD->m_td1TD1.byTCR & TCR_STP) {
-
-            if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
-                uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
-                uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
-                pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
-                // Update the statistics based on the Transmit status
-                // now, we DONT check TSR0_CDH
-
-                STAvUpdateTDStatCounter(&pDevice->scStatistic,
-                        byTsr0, byTsr1,
-                        (unsigned char *)(pTD->pTDInfo->buf + uFIFOHeaderSize),
-                        uFrameSize, uIdx);
-
-
-                BSSvUpdateNodeTxCounter(pDevice,
-                         byTsr0, byTsr1,
-                         (unsigned char *)(pTD->pTDInfo->buf),
-                         uFIFOHeaderSize
-                         );
-
-                if ( !(byTsr1 & TSR1_TERR)) {
-                    if (byTsr0 != 0) {
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
-                           (int)uIdx, byTsr1, byTsr0);
-                    }
-                    if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG) {
-                        pDevice->s802_11Counter.TransmittedFragmentCount ++;
-                    }
-                    pStats->tx_packets++;
-                    pStats->tx_bytes += pTD->pTDInfo->skb->len;
-                }
-                else {
-                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
-                           (int)uIdx, byTsr1, byTsr0);
-                    pStats->tx_errors++;
-                    pStats->tx_dropped++;
-                }
-            }
-
-            if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
-                if (pDevice->bEnableHostapd) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif.. \n");
-                    skb = pTD->pTDInfo->skb;
-                       skb->dev = pDevice->apdev;
-                       skb_reset_mac_header(skb);
-                       skb->pkt_type = PACKET_OTHERHOST;
-                   //skb->protocol = htons(ETH_P_802_2);
-                       memset(skb->cb, 0, sizeof(skb->cb));
-                       netif_rx(skb);
-                   }
-            }
-
-            if (byTsr1 & TSR1_TERR) {
-            if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
-                          (int)uIdx, byTsr1, byTsr0);
-            }
-
-//                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
-//                          (int)uIdx, byTsr1, byTsr0);
+       pDevice->apTailTD[uIdx] = pTD;
 
-                if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
-                    (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
-                    unsigned short wAID;
-                    unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
-
-                    skb = pTD->pTDInfo->skb;
-                    if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
-                        if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
-                            skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
-                            pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
-                            // set tx map
-                            wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
-                            pMgmt->abyPSTxMap[wAID >> 3] |=  byMask[wAID & 7];
-                            pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
-                            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
-                                    ,(int)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
-                            pStats->tx_errors--;
-                            pStats->tx_dropped--;
-                        }
-                    }
-                }
-            }
-            device_free_tx_buf(pDevice,pTD);
-            pDevice->iTDUsed[uIdx]--;
-        }
-    }
-
-
-    if (uIdx == TYPE_AC0DMA) {
-        // RESERV_AC0DMA reserved for relay
-
-        if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
-            bFull = true;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
-        }
-        if (netif_queue_stopped(pDevice->dev) && (bFull==false)){
-            netif_wake_queue(pDevice->dev);
-        }
-    }
-
-
-    pDevice->apTailTD[uIdx] = pTD;
-
-    return works;
+       return works;
 }
 
-
 static void device_error(PSDevice pDevice, unsigned short status) {
-
-    if (status & ISR_FETALERR) {
-        DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
-            "%s: Hardware fatal error.\n",
-            pDevice->dev->name);
-        netif_stop_queue(pDevice->dev);
-        del_timer(&pDevice->sTimerCommand);
-        del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
-        pDevice->bCmdRunning = false;
-        MACbShutdown(pDevice->PortOffset);
-        return;
-    }
-
+       if (status & ISR_FETALERR) {
+               DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
+                       "%s: Hardware fatal error.\n",
+                       pDevice->dev->name);
+               netif_stop_queue(pDevice->dev);
+               del_timer(&pDevice->sTimerCommand);
+               del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
+               pDevice->bCmdRunning = false;
+               MACbShutdown(pDevice->PortOffset);
+               return;
+       }
 }
 
 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc) {
-    PDEVICE_TD_INFO  pTDInfo=pDesc->pTDInfo;
-    struct sk_buff* skb=pTDInfo->skb;
+       PDEVICE_TD_INFO  pTDInfo = pDesc->pTDInfo;
+       struct sk_buff *skb = pTDInfo->skb;
 
-    // pre-allocated buf_dma can't be unmapped.
-    if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
-        pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,skb->len,
-              PCI_DMA_TODEVICE);
-    }
+       // pre-allocated buf_dma can't be unmapped.
+       if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
+               pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
+                                PCI_DMA_TODEVICE);
+       }
 
-    if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
-        dev_kfree_skb_irq(skb);
+       if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
+               dev_kfree_skb_irq(skb);
 
-    pTDInfo->skb_dma = 0;
-    pTDInfo->skb = 0;
-    pTDInfo->byFlags = 0;
+       pTDInfo->skb_dma = 0;
+       pTDInfo->skb = 0;
+       pTDInfo->byFlags = 0;
 }
 
-
-
 //PLICE_DEBUG ->
 void   InitRxManagementQueue(PSDevice  pDevice)
 {
@@ -1816,107 +1686,88 @@ void   InitRxManagementQueue(PSDevice  pDevice)
 }
 //PLICE_DEBUG<-
 
-
-
-
-
 //PLICE_DEBUG ->
 int MlmeThread(
-     void * Context)
+       void *Context)
 {
        PSDevice        pDevice =  (PSDevice) Context;
        PSRxMgmtPacket                  pRxMgmtPacket;
-       // int i ;
+       // int i;
        //complete(&pDevice->notify);
-//printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
 
-       //printk("Enter MlmeThread,packet _num is %d\n",pDevice->rxManeQueue.packet_num);
        //i = 0;
 #if 1
-       while (1)
-       {
-
-       //printk("DDDD\n");
-       //down(&pDevice->mlme_semaphore);
-        // pRxMgmtPacket =  DeQueue(pDevice);
+       while (1) {
+               //down(&pDevice->mlme_semaphore);
+               // pRxMgmtPacket =  DeQueue(pDevice);
 #if 1
                spin_lock_irq(&pDevice->lock);
-                while(pDevice->rxManeQueue.packet_num != 0)
-               {
-                        pRxMgmtPacket =  DeQueue(pDevice);
-                               //pDevice;
-                               //DequeueManageObject(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
+               while (pDevice->rxManeQueue.packet_num != 0) {
+                       pRxMgmtPacket = DeQueue(pDevice);
+                       //pDevice;
+                       //DequeueManageObject(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
                        vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
-                       //printk("packet_num is %d\n",pDevice->rxManeQueue.packet_num);
-
-                }
+               }
                spin_unlock_irq(&pDevice->lock);
                if (mlme_kill == 0)
-               break;
+                       break;
                //udelay(200);
 #endif
-       //printk("Before schedule thread jiffies is %x\n",jiffies);
-       schedule();
-       //printk("after schedule thread jiffies is %x\n",jiffies);
-       if (mlme_kill == 0)
-               break;
-       //printk("i is %d\n",i);
+               schedule();
+               if (mlme_kill == 0)
+                       break;
        }
 
 #endif
        return 0;
-
 }
 
-
-
 static int  device_open(struct net_device *dev) {
-    PSDevice    pDevice=(PSDevice) netdev_priv(dev);
-    int i;
+       PSDevice pDevice = (PSDevice)netdev_priv(dev);
+       int i;
 #ifdef WPA_SM_Transtatus
-    extern SWPAResult wpa_Result;
+       extern SWPAResult wpa_Result;
 #endif
 
-    pDevice->rx_buf_sz = PKT_BUF_SZ;
-    if (!device_init_rings(pDevice)) {
-        return -ENOMEM;
-    }
+       pDevice->rx_buf_sz = PKT_BUF_SZ;
+       if (!device_init_rings(pDevice)) {
+               return -ENOMEM;
+       }
 //2008-5-13 <add> by chester
-    i=request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
-    if (i)
-        return i;
-       //printk("DEBUG1\n");
+       i = request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
+       if (i)
+               return i;
+
 #ifdef WPA_SM_Transtatus
-     memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
-     wpa_Result.proto = 0;
-     wpa_Result.key_mgmt = 0;
-     wpa_Result.eap_type = 0;
-     wpa_Result.authenticated = false;
-     pDevice->fWPA_Authened = false;
+       memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname));
+       wpa_Result.proto = 0;
+       wpa_Result.key_mgmt = 0;
+       wpa_Result.eap_type = 0;
+       wpa_Result.authenticated = false;
+       pDevice->fWPA_Authened = false;
 #endif
-DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
-device_init_rd0_ring(pDevice);
-    device_init_rd1_ring(pDevice);
-    device_init_defrag_cb(pDevice);
-    device_init_td0_ring(pDevice);
-    device_init_td1_ring(pDevice);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
+       device_init_rd0_ring(pDevice);
+       device_init_rd1_ring(pDevice);
+       device_init_defrag_cb(pDevice);
+       device_init_td0_ring(pDevice);
+       device_init_td1_ring(pDevice);
 //    VNTWIFIvSet11h(pDevice->pMgmt, pDevice->b11hEnable);
 
-
-    if (pDevice->bDiversityRegCtlON) {
-        device_init_diversity_timer(pDevice);
-    }
-    vMgrObjectInit(pDevice);
-    vMgrTimerInit(pDevice);
+       if (pDevice->bDiversityRegCtlON) {
+               device_init_diversity_timer(pDevice);
+       }
+       vMgrObjectInit(pDevice);
+       vMgrTimerInit(pDevice);
 
 //PLICE_DEBUG->
 #ifdef TASK_LET
-       tasklet_init (&pDevice->RxMngWorkItem,(void *)MngWorkItem,(unsigned long )pDevice);
+       tasklet_init(&pDevice->RxMngWorkItem, (void *)MngWorkItem, (unsigned long)pDevice);
 #endif
 #ifdef THREAD
        InitRxManagementQueue(pDevice);
        mlme_kill = 0;
-       mlme_task = kthread_run(MlmeThread,(void *) pDevice, "MLME");
+       mlme_task = kthread_run(MlmeThread, (void *)pDevice, "MLME");
        if (IS_ERR(mlme_task)) {
                printk("thread create fail\n");
                return -1;
@@ -1925,1184 +1776,1111 @@ device_init_rd0_ring(pDevice);
        mlme_kill = 1;
 #endif
 
-
-
-       //printk("thread id is %d\n",pDevice->MLMEThr_pid);
-       //printk("Create thread time is %x\n",jiffies);
        //wait_for_completion(&pDevice->notify);
 
-
-
-
-  // if (( SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL)&0x06)==0x04)
-    //    return -ENOMEM;
-DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
        device_init_registers(pDevice, DEVICE_INIT_COLD);
-    MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
-    memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN);
-    device_set_multi(pDevice->dev);
+       MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
+       memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN);
+       device_set_multi(pDevice->dev);
 
-    // Init for Key Management
-    KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
-    add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
+       // Init for Key Management
+       KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
+       add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
 
-       #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
        /*
-     pDevice->bwextstep0 = false;
-     pDevice->bwextstep1 = false;
-     pDevice->bwextstep2 = false;
-     pDevice->bwextstep3 = false;
-     */
-       pDevice->bwextcount=0;
-     pDevice->bWPASuppWextEnabled = false;
+         pDevice->bwextstep0 = false;
+         pDevice->bwextstep1 = false;
+         pDevice->bwextstep2 = false;
+         pDevice->bwextstep3 = false;
+       */
+       pDevice->bwextcount = 0;
+       pDevice->bWPASuppWextEnabled = false;
 #endif
-    pDevice->byReAssocCount = 0;
-   pDevice->bWPADEVUp = false;
-    // Patch: if WEP key already set by iwconfig but device not yet open
-    if ((pDevice->bEncryptionEnable == true) && (pDevice->bTransmitKey == true)) {
-        KeybSetDefaultKey(&(pDevice->sKey),
-                            (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
-                            pDevice->uKeyLength,
-                            NULL,
-                            pDevice->abyKey,
-                            KEY_CTL_WEP,
-                            pDevice->PortOffset,
-                            pDevice->byLocalID
-                          );
-         pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
-    }
-
-//printk("DEBUG2\n");
-
-
-DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
+       pDevice->byReAssocCount = 0;
+       pDevice->bWPADEVUp = false;
+       // Patch: if WEP key already set by iwconfig but device not yet open
+       if ((pDevice->bEncryptionEnable == true) && (pDevice->bTransmitKey == true)) {
+               KeybSetDefaultKey(&(pDevice->sKey),
+                                 (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
+                                 pDevice->uKeyLength,
+                                 NULL,
+                                 pDevice->abyKey,
+                                 KEY_CTL_WEP,
+                                 pDevice->PortOffset,
+                                 pDevice->byLocalID
+                       );
+               pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
+       }
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
        MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
 
-    if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
-        bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
+       if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
+               bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
+       } else {
+               bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
+               bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
        }
-       else {
-        bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
-        bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
-    }
-    pDevice->flags |=DEVICE_FLAGS_OPENED;
+       pDevice->flags |= DEVICE_FLAGS_OPENED;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
-    return 0;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
+       return 0;
 }
 
-
 static int  device_close(struct net_device *dev) {
-    PSDevice  pDevice=(PSDevice) netdev_priv(dev);
-    PSMgmtObject     pMgmt = pDevice->pMgmt;
- //PLICE_DEBUG->
+       PSDevice  pDevice = (PSDevice)netdev_priv(dev);
+       PSMgmtObject     pMgmt = pDevice->pMgmt;
      //PLICE_DEBUG->
 #ifdef THREAD
        mlme_kill = 0;
 #endif
 //PLICE_DEBUG<-
 //2007-1121-02<Add>by EinsnLiu
-    if (pDevice->bLinkPass) {
-       bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
-        mdelay(30);
-    }
+       if (pDevice->bLinkPass) {
+               bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
+               mdelay(30);
+       }
 #ifdef TxInSleep
-    del_timer(&pDevice->sTimerTxData);
+       del_timer(&pDevice->sTimerTxData);
 #endif
-    del_timer(&pDevice->sTimerCommand);
-    del_timer(&pMgmt->sTimerSecondCallback);
-    if (pDevice->bDiversityRegCtlON) {
-        del_timer(&pDevice->TimerSQ3Tmax1);
-        del_timer(&pDevice->TimerSQ3Tmax2);
-        del_timer(&pDevice->TimerSQ3Tmax3);
-    }
+       del_timer(&pDevice->sTimerCommand);
+       del_timer(&pMgmt->sTimerSecondCallback);
+       if (pDevice->bDiversityRegCtlON) {
+               del_timer(&pDevice->TimerSQ3Tmax1);
+               del_timer(&pDevice->TimerSQ3Tmax2);
+               del_timer(&pDevice->TimerSQ3Tmax3);
+       }
 
 #ifdef TASK_LET
        tasklet_kill(&pDevice->RxMngWorkItem);
 #endif
-     netif_stop_queue(dev);
-    pDevice->bCmdRunning = false;
-    MACbShutdown(pDevice->PortOffset);
-    MACbSoftwareReset(pDevice->PortOffset);
-    CARDbRadioPowerOff(pDevice);
-
-    pDevice->bLinkPass = false;
-    memset(pMgmt->abyCurrBSSID, 0, 6);
-    pMgmt->eCurrState = WMAC_STATE_IDLE;
-    device_free_td0_ring(pDevice);
-    device_free_td1_ring(pDevice);
-    device_free_rd0_ring(pDevice);
-    device_free_rd1_ring(pDevice);
-    device_free_frag_buf(pDevice);
-    device_free_rings(pDevice);
-    BSSvClearNodeDBTable(pDevice, 0);
-    free_irq(dev->irq, dev);
-    pDevice->flags &=(~DEVICE_FLAGS_OPENED);
+       netif_stop_queue(dev);
+       pDevice->bCmdRunning = false;
+       MACbShutdown(pDevice->PortOffset);
+       MACbSoftwareReset(pDevice->PortOffset);
+       CARDbRadioPowerOff(pDevice);
+
+       pDevice->bLinkPass = false;
+       memset(pMgmt->abyCurrBSSID, 0, 6);
+       pMgmt->eCurrState = WMAC_STATE_IDLE;
+       device_free_td0_ring(pDevice);
+       device_free_td1_ring(pDevice);
+       device_free_rd0_ring(pDevice);
+       device_free_rd1_ring(pDevice);
+       device_free_frag_buf(pDevice);
+       device_free_rings(pDevice);
+       BSSvClearNodeDBTable(pDevice, 0);
+       free_irq(dev->irq, dev);
+       pDevice->flags &= (~DEVICE_FLAGS_OPENED);
        //2008-0714-01<Add>by chester
-device_release_WPADEV(pDevice);
+       device_release_WPADEV(pDevice);
 //PLICE_DEBUG->
        //tasklet_kill(&pDevice->RxMngWorkItem);
 //PLICE_DEBUG<-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close.. \n");
-    return 0;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close.. \n");
+       return 0;
 }
 
+static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
+       PSDevice pDevice = netdev_priv(dev);
+       unsigned char *pbMPDU;
+       unsigned int cbMPDULen = 0;
 
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
+       spin_lock_irq(&pDevice->lock);
 
-static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
-    PSDevice        pDevice=netdev_priv(dev);
-    unsigned char *pbMPDU;
-    unsigned int cbMPDULen = 0;
+       if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
+               dev_kfree_skb_irq(skb);
+               spin_unlock_irq(&pDevice->lock);
+               return 0;
+       }
+
+       if (pDevice->bStopTx0Pkt == true) {
+               dev_kfree_skb_irq(skb);
+               spin_unlock_irq(&pDevice->lock);
+               return 0;
+       }
+
+       cbMPDULen = skb->len;
+       pbMPDU = skb->data;
+
+       vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
+
+       spin_unlock_irq(&pDevice->lock);
+
+       return 0;
+}
 
+bool device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, unsigned int uNodeIndex) {
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSTxDesc        pHeadTD, pLastTD;
+       unsigned int cbFrameBodySize;
+       unsigned int uMACfragNum;
+       unsigned char byPktType;
+       bool bNeedEncryption = false;
+       PSKeyItem       pTransmitKey = NULL;
+       unsigned int cbHeaderSize;
+       unsigned int ii;
+       SKeyItem        STempKey;
+//    unsigned char byKeyIndex = 0;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
-    spin_lock_irq(&pDevice->lock);
+       if (pDevice->bStopTx0Pkt == true) {
+               dev_kfree_skb_irq(skb);
+               return false;
+       }
 
-    if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
-        dev_kfree_skb_irq(skb);
-        spin_unlock_irq(&pDevice->lock);
-        return 0;
-    }
+       if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
+               dev_kfree_skb_irq(skb);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
+               return false;
+       }
 
-    if (pDevice->bStopTx0Pkt == true) {
-        dev_kfree_skb_irq(skb);
-        spin_unlock_irq(&pDevice->lock);
-        return 0;
-    }
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               if (pDevice->uAssocCount == 0) {
+                       dev_kfree_skb_irq(skb);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
+                       return false;
+               }
+       }
 
-    cbMPDULen = skb->len;
-    pbMPDU = skb->data;
+       pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
 
-    vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
+       pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
 
-    spin_unlock_irq(&pDevice->lock);
+       memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
+       cbFrameBodySize = skb->len - ETH_HLEN;
 
-    return 0;
+       // 802.1H
+       if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN) {
+               cbFrameBodySize += 8;
+       }
+       uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
 
-}
+       if (uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
+               dev_kfree_skb_irq(skb);
+               return false;
+       }
+       byPktType = (unsigned char)pDevice->byPacketType;
+
+       if (pDevice->bFixRate) {
+               if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
+                       if (pDevice->uConnectionRate >= RATE_11M) {
+                               pDevice->wCurrentRate = RATE_11M;
+                       } else {
+                               pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
+                       }
+               } else {
+                       if (pDevice->uConnectionRate >= RATE_54M)
+                               pDevice->wCurrentRate = RATE_54M;
+                       else
+                               pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
+               }
+       } else {
+               pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
+       }
 
+       //preamble type
+       if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
+               pDevice->byPreambleType = pDevice->byShortPreamble;
+       } else {
+               pDevice->byPreambleType = PREAMBLE_LONG;
+       }
 
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
 
-bool device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, unsigned int uNodeIndex) {
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    PSTxDesc        pHeadTD, pLastTD;
-    unsigned int cbFrameBodySize;
-    unsigned int uMACfragNum;
-    unsigned char byPktType;
-    bool bNeedEncryption = false;
-    PSKeyItem       pTransmitKey = NULL;
-    unsigned int cbHeaderSize;
-    unsigned int ii;
-    SKeyItem        STempKey;
-//    unsigned char byKeyIndex = 0;
+       if (pDevice->wCurrentRate <= RATE_11M) {
+               byPktType = PK_TYPE_11B;
+       } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
+               byPktType = PK_TYPE_11A;
+       } else {
+               if (pDevice->bProtectMode == true) {
+                       byPktType = PK_TYPE_11GB;
+               } else {
+                       byPktType = PK_TYPE_11GA;
+               }
+       }
+
+       if (pDevice->bEncryptionEnable == true)
+               bNeedEncryption = true;
+
+       if (pDevice->bEnableHostWEP) {
+               pTransmitKey = &STempKey;
+               pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
+               pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
+               pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
+               pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
+               pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
+               memcpy(pTransmitKey->abyKey,
+                      &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
+                      pTransmitKey->uKeyLength
+                       );
+       }
+       vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
+                           cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
+                           &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
+                           &uMACfragNum,
+                           &cbHeaderSize
+               );
+
+       if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
+               // Disable PS
+               MACbPSWakeup(pDevice->PortOffset);
+       }
+
+       pDevice->bPWBitOn = false;
+
+       pLastTD = pHeadTD;
+       for (ii = 0; ii < uMACfragNum; ii++) {
+               // Poll Transmit the adapter
+               wmb();
+               pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
+               wmb();
+               if (ii == (uMACfragNum - 1))
+                       pLastTD = pHeadTD;
+               pHeadTD = pHeadTD->next;
+       }
 
+       // Save the information needed by the tx interrupt handler
+       // to complete the Send request
+       pLastTD->pTDInfo->skb = skb;
+       pLastTD->pTDInfo->byFlags = 0;
+       pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
 
-    if (pDevice->bStopTx0Pkt == true) {
-        dev_kfree_skb_irq(skb);
-        return false;
-    }
-
-    if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
-        dev_kfree_skb_irq(skb);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
-        return false;
-    }
-
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-        if (pDevice->uAssocCount == 0) {
-            dev_kfree_skb_irq(skb);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
-            return false;
-        }
-    }
-
-    pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
-
-    pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
-
-    memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
-    cbFrameBodySize = skb->len - ETH_HLEN;
-
-    // 802.1H
-    if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN) {
-        cbFrameBodySize += 8;
-    }
-    uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
-
-    if ( uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
-        dev_kfree_skb_irq(skb);
-        return false;
-    }
-    byPktType = (unsigned char)pDevice->byPacketType;
-
-
-    if (pDevice->bFixRate) {
-        if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
-            if (pDevice->uConnectionRate >= RATE_11M) {
-                pDevice->wCurrentRate = RATE_11M;
-            } else {
-                pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
-            }
-        } else {
-            if (pDevice->uConnectionRate >= RATE_54M)
-                pDevice->wCurrentRate = RATE_54M;
-            else
-                pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
-        }
-    }
-    else {
-        pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
-    }
-
-    //preamble type
-    if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
-        pDevice->byPreambleType = pDevice->byShortPreamble;
-    }
-    else {
-        pDevice->byPreambleType = PREAMBLE_LONG;
-    }
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
-
-
-    if (pDevice->wCurrentRate <= RATE_11M) {
-        byPktType = PK_TYPE_11B;
-    } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
-        byPktType = PK_TYPE_11A;
-    } else {
-        if (pDevice->bProtectMode == true) {
-            byPktType = PK_TYPE_11GB;
-        } else {
-            byPktType = PK_TYPE_11GA;
-        }
-    }
-
-    if (pDevice->bEncryptionEnable == true)
-        bNeedEncryption = true;
-
-    if (pDevice->bEnableHostWEP) {
-        pTransmitKey = &STempKey;
-        pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
-        pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
-        pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
-        pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
-        pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
-        memcpy(pTransmitKey->abyKey,
-            &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
-            pTransmitKey->uKeyLength
-            );
-    }
-    vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
-                        cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
-                        &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
-                        &uMACfragNum,
-                        &cbHeaderSize
-                        );
-
-    if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
-        // Disable PS
-        MACbPSWakeup(pDevice->PortOffset);
-    }
-
-    pDevice->bPWBitOn = false;
-
-    pLastTD = pHeadTD;
-    for (ii = 0; ii < uMACfragNum; ii++) {
-        // Poll Transmit the adapter
-        wmb();
-        pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
-        wmb();
-        if (ii == (uMACfragNum - 1))
-            pLastTD = pHeadTD;
-        pHeadTD = pHeadTD->next;
-    }
-
-    // Save the information needed by the tx interrupt handler
-    // to complete the Send request
-    pLastTD->pTDInfo->skb = skb;
-    pLastTD->pTDInfo->byFlags = 0;
-    pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
-
-    pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
-
-    MACvTransmit0(pDevice->PortOffset);
-
-
-    return true;
+       pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
+
+       MACvTransmit0(pDevice->PortOffset);
+
+       return true;
 }
 
 //TYPE_AC0DMA data tx
 static int  device_xmit(struct sk_buff *skb, struct net_device *dev) {
-    PSDevice pDevice=netdev_priv(dev);
-
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    PSTxDesc        pHeadTD, pLastTD;
-    unsigned int uNodeIndex = 0;
-    unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
-    unsigned short wAID;
-    unsigned int uMACfragNum = 1;
-    unsigned int cbFrameBodySize;
-    unsigned char byPktType;
-    unsigned int cbHeaderSize;
-    bool bNeedEncryption = false;
-    PSKeyItem       pTransmitKey = NULL;
-    SKeyItem        STempKey;
-    unsigned int ii;
-    bool bTKIP_UseGTK = false;
-    bool bNeedDeAuth = false;
-    unsigned char *pbyBSSID;
-    bool bNodeExist = false;
-
-
-
-    spin_lock_irq(&pDevice->lock);
-    if (pDevice->bLinkPass == false) {
-        dev_kfree_skb_irq(skb);
-        spin_unlock_irq(&pDevice->lock);
-        return 0;
-    }
-
-    if (pDevice->bStopDataPkt) {
-        dev_kfree_skb_irq(skb);
-        spin_unlock_irq(&pDevice->lock);
-        return 0;
-    }
-
-
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-        if (pDevice->uAssocCount == 0) {
-            dev_kfree_skb_irq(skb);
-            spin_unlock_irq(&pDevice->lock);
-            return 0;
-        }
-        if (is_multicast_ether_addr((unsigned char *)(skb->data))) {
-            uNodeIndex = 0;
-            bNodeExist = true;
-            if (pMgmt->sNodeDBTable[0].bPSEnable) {
-                skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
-                pMgmt->sNodeDBTable[0].wEnQueueCnt++;
-                // set tx map
-                pMgmt->abyPSTxMap[0] |= byMask[0];
-                spin_unlock_irq(&pDevice->lock);
-                return 0;
-            }
-}else {
-            if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
-                if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
-                    skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
-                    pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
-                    // set tx map
-                    wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
-                    pMgmt->abyPSTxMap[wAID >> 3] |=  byMask[wAID & 7];
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
-                             (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
-                    spin_unlock_irq(&pDevice->lock);
-                    return 0;
-                }
-
-                if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
-                    pDevice->byPreambleType = pDevice->byShortPreamble;
-
-                }else {
-                    pDevice->byPreambleType = PREAMBLE_LONG;
-                }
-                bNodeExist = true;
-
-            }
-        }
-
-        if (bNodeExist == false) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
-            dev_kfree_skb_irq(skb);
-            spin_unlock_irq(&pDevice->lock);
-            return 0;
-        }
-    }
-
-    pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
-
-    pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
-
-
-    memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
-    cbFrameBodySize = skb->len - ETH_HLEN;
-    // 802.1H
-    if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN) {
-        cbFrameBodySize += 8;
-    }
-
-
-    if (pDevice->bEncryptionEnable == true) {
-        bNeedEncryption = true;
-        // get Transmit key
-        do {
-            if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
-                (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
-                pbyBSSID = pDevice->abyBSSID;
-                // get pairwise key
-                if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
-                    // get group key
-                    if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
-                        bTKIP_UseGTK = true;
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
-                        break;
-                    }
-                } else {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
-                    break;
-                }
-            }else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-
-                pbyBSSID = pDevice->sTxEthHeader.abyDstAddr;  //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
-                for (ii = 0; ii< 6; ii++)
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
-
-                // get pairwise key
-                if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
-                    break;
-            }
-            // get group key
-            pbyBSSID = pDevice->abyBroadcastAddr;
-            if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
-                pTransmitKey = NULL;
-                if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
-                }
-                else
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
-            } else {
-                bTKIP_UseGTK = true;
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
-            }
-        } while(false);
-    }
-
-    if (pDevice->bEnableHostWEP) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
-        if (pDevice->bEncryptionEnable == true) {
-            pTransmitKey = &STempKey;
-            pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
-            pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
-            pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
-            pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
-            pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
-            memcpy(pTransmitKey->abyKey,
-                &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
-                pTransmitKey->uKeyLength
-                );
-         }
-    }
-
-    uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
-
-    if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
-        DBG_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
-        dev_kfree_skb_irq(skb);
-        spin_unlock_irq(&pDevice->lock);
-        return 0;
-    }
-
-    if (pTransmitKey != NULL) {
-        if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
-            (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
-            uMACfragNum = 1; //WEP256 doesn't support fragment
-        }
-    }
-
-    byPktType = (unsigned char)pDevice->byPacketType;
-
-    if (pDevice->bFixRate) {
+       PSDevice pDevice = netdev_priv(dev);
+
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSTxDesc        pHeadTD, pLastTD;
+       unsigned int uNodeIndex = 0;
+       unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
+       unsigned short wAID;
+       unsigned int uMACfragNum = 1;
+       unsigned int cbFrameBodySize;
+       unsigned char byPktType;
+       unsigned int cbHeaderSize;
+       bool bNeedEncryption = false;
+       PSKeyItem       pTransmitKey = NULL;
+       SKeyItem        STempKey;
+       unsigned int ii;
+       bool bTKIP_UseGTK = false;
+       bool bNeedDeAuth = false;
+       unsigned char *pbyBSSID;
+       bool bNodeExist = false;
+
+       spin_lock_irq(&pDevice->lock);
+       if (pDevice->bLinkPass == false) {
+               dev_kfree_skb_irq(skb);
+               spin_unlock_irq(&pDevice->lock);
+               return 0;
+       }
+
+       if (pDevice->bStopDataPkt) {
+               dev_kfree_skb_irq(skb);
+               spin_unlock_irq(&pDevice->lock);
+               return 0;
+       }
+
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               if (pDevice->uAssocCount == 0) {
+                       dev_kfree_skb_irq(skb);
+                       spin_unlock_irq(&pDevice->lock);
+                       return 0;
+               }
+               if (is_multicast_ether_addr((unsigned char *)(skb->data))) {
+                       uNodeIndex = 0;
+                       bNodeExist = true;
+                       if (pMgmt->sNodeDBTable[0].bPSEnable) {
+                               skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
+                               pMgmt->sNodeDBTable[0].wEnQueueCnt++;
+                               // set tx map
+                               pMgmt->abyPSTxMap[0] |= byMask[0];
+                               spin_unlock_irq(&pDevice->lock);
+                               return 0;
+                       }
+               } else {
+                       if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
+                               if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
+                                       skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
+                                       pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
+                                       // set tx map
+                                       wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
+                                       pMgmt->abyPSTxMap[wAID >> 3] |=  byMask[wAID & 7];
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
+                                               (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
+                                       spin_unlock_irq(&pDevice->lock);
+                                       return 0;
+                               }
+
+                               if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
+                                       pDevice->byPreambleType = pDevice->byShortPreamble;
+
+                               } else {
+                                       pDevice->byPreambleType = PREAMBLE_LONG;
+                               }
+                               bNodeExist = true;
+
+                       }
+               }
+
+               if (bNodeExist == false) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Unknown STA not found in node DB \n");
+                       dev_kfree_skb_irq(skb);
+                       spin_unlock_irq(&pDevice->lock);
+                       return 0;
+               }
+       }
+
+       pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
+
+       pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
+
+       memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
+       cbFrameBodySize = skb->len - ETH_HLEN;
+       // 802.1H
+       if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN) {
+               cbFrameBodySize += 8;
+       }
+
+       if (pDevice->bEncryptionEnable == true) {
+               bNeedEncryption = true;
+               // get Transmit key
+               do {
+                       if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
+                           (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
+                               pbyBSSID = pDevice->abyBSSID;
+                               // get pairwise key
+                               if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
+                                       // get group key
+                                       if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
+                                               bTKIP_UseGTK = true;
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
+                                               break;
+                                       }
+                               } else {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get PTK.\n");
+                                       break;
+                               }
+                       } else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+                               pbyBSSID = pDevice->sTxEthHeader.abyDstAddr;  //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "IBSS Serach Key: \n");
+                               for (ii = 0; ii < 6; ii++)
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "%x \n", *(pbyBSSID+ii));
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "\n");
+
+                               // get pairwise key
+                               if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
+                                       break;
+                       }
+                       // get group key
+                       pbyBSSID = pDevice->abyBroadcastAddr;
+                       if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
+                               pTransmitKey = NULL;
+                               if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
+                               } else
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
+                       } else {
+                               bTKIP_UseGTK = true;
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
+                       }
+               } while (false);
+       }
+
+       if (pDevice->bEnableHostWEP) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "acdma0: STA index %d\n", uNodeIndex);
+               if (pDevice->bEncryptionEnable == true) {
+                       pTransmitKey = &STempKey;
+                       pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
+                       pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
+                       pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
+                       pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
+                       pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
+                       memcpy(pTransmitKey->abyKey,
+                              &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
+                              pTransmitKey->uKeyLength
+                               );
+               }
+       }
+
+       uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
+
+       if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
+               DBG_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
+               dev_kfree_skb_irq(skb);
+               spin_unlock_irq(&pDevice->lock);
+               return 0;
+       }
+
+       if (pTransmitKey != NULL) {
+               if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
+                   (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
+                       uMACfragNum = 1; //WEP256 doesn't support fragment
+               }
+       }
+
+       byPktType = (unsigned char)pDevice->byPacketType;
+
+       if (pDevice->bFixRate) {
 #ifdef PLICE_DEBUG
-       printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n",pDevice->eCurrentPHYType,pDevice->uConnectionRate);
+               printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n", pDevice->eCurrentPHYType, pDevice->uConnectionRate);
 #endif
 
-        if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
-            if (pDevice->uConnectionRate >= RATE_11M) {
-                pDevice->wCurrentRate = RATE_11M;
-            } else {
-                pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
-            }
-        } else {
-            if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
-                (pDevice->uConnectionRate <= RATE_6M)) {
-                pDevice->wCurrentRate = RATE_6M;
-            } else {
-                if (pDevice->uConnectionRate >= RATE_54M)
-                    pDevice->wCurrentRate = RATE_54M;
-                else
-                    pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
-
-            }
-        }
-        pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate;
-        pDevice->byTopCCKBasicRate = RATE_1M;
-        pDevice->byTopOFDMBasicRate = RATE_6M;
-    }
-    else {
-        //auto rate
-    if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
-            if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
-                pDevice->wCurrentRate = RATE_1M;
-                pDevice->byACKRate = RATE_1M;
-                pDevice->byTopCCKBasicRate = RATE_1M;
-                pDevice->byTopOFDMBasicRate = RATE_6M;
-            } else {
-                pDevice->wCurrentRate = RATE_6M;
-                pDevice->byACKRate = RATE_6M;
-                pDevice->byTopCCKBasicRate = RATE_1M;
-                pDevice->byTopOFDMBasicRate = RATE_6M;
-            }
-        }
-        else {
-               VNTWIFIvGetTxRate(  pDevice->pMgmt,
-                                pDevice->sTxEthHeader.abyDstAddr,
-                                &(pDevice->wCurrentRate),
-                                &(pDevice->byACKRate),
-                                &(pDevice->byTopCCKBasicRate),
-                                &(pDevice->byTopOFDMBasicRate));
+               if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
+                       if (pDevice->uConnectionRate >= RATE_11M) {
+                               pDevice->wCurrentRate = RATE_11M;
+                       } else {
+                               pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
+                       }
+               } else {
+                       if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
+                           (pDevice->uConnectionRate <= RATE_6M)) {
+                               pDevice->wCurrentRate = RATE_6M;
+                       } else {
+                               if (pDevice->uConnectionRate >= RATE_54M)
+                                       pDevice->wCurrentRate = RATE_54M;
+                               else
+                                       pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
 
+                       }
+               }
+               pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate;
+               pDevice->byTopCCKBasicRate = RATE_1M;
+               pDevice->byTopOFDMBasicRate = RATE_6M;
+       } else {
+               //auto rate
+               if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
+                       if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
+                               pDevice->wCurrentRate = RATE_1M;
+                               pDevice->byACKRate = RATE_1M;
+                               pDevice->byTopCCKBasicRate = RATE_1M;
+                               pDevice->byTopOFDMBasicRate = RATE_6M;
+                       } else {
+                               pDevice->wCurrentRate = RATE_6M;
+                               pDevice->byACKRate = RATE_6M;
+                               pDevice->byTopCCKBasicRate = RATE_1M;
+                               pDevice->byTopOFDMBasicRate = RATE_6M;
+                       }
+               } else {
+                       VNTWIFIvGetTxRate(pDevice->pMgmt,
+                                         pDevice->sTxEthHeader.abyDstAddr,
+                                         &(pDevice->wCurrentRate),
+                                         &(pDevice->byACKRate),
+                                         &(pDevice->byTopCCKBasicRate),
+                                         &(pDevice->byTopOFDMBasicRate));
 
                }
-    }
+       }
 
 //    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
 
-    if (pDevice->wCurrentRate <= RATE_11M) {
-        byPktType = PK_TYPE_11B;
-    } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
-        byPktType = PK_TYPE_11A;
-    } else {
-        if (pDevice->bProtectMode == true) {
-            byPktType = PK_TYPE_11GB;
-        } else {
-            byPktType = PK_TYPE_11GA;
-        }
-    }
+       if (pDevice->wCurrentRate <= RATE_11M) {
+               byPktType = PK_TYPE_11B;
+       } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
+               byPktType = PK_TYPE_11A;
+       } else {
+               if (pDevice->bProtectMode == true) {
+                       byPktType = PK_TYPE_11GB;
+               } else {
+                       byPktType = PK_TYPE_11GA;
+               }
+       }
 
 //#ifdef       PLICE_DEBUG
 //     printk("FIX RATE:CurrentRate is %d");
 //#endif
 
-    if (bNeedEncryption == true) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
-        if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
-            bNeedEncryption = false;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
-            if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
-                if (pTransmitKey == NULL) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
-                }
-                else {
-                    if (bTKIP_UseGTK == true) {
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
-                    }
-                    else {
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
-                        bNeedEncryption = true;
-                    }
-                }
-            }
-
-            if (pDevice->byCntMeasure == 2) {
-                bNeedDeAuth = true;
-                pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
-            }
-
-            if (pDevice->bEnableHostWEP) {
-                if ((uNodeIndex != 0) &&
-                    (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
-                    bNeedEncryption = true;
-                 }
-             }
-        }
-        else {
-            if (pTransmitKey == NULL) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
-                dev_kfree_skb_irq(skb);
-                spin_unlock_irq(&pDevice->lock);
-                return 0;
-            }
-        }
-    }
+       if (bNeedEncryption == true) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
+               if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
+                       bNeedEncryption = false;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
+                       if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
+                               if (pTransmitKey == NULL) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Don't Find TX KEY\n");
+                               } else {
+                                       if (bTKIP_UseGTK == true) {
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "error: KEY is GTK!!~~\n");
+                                       } else {
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
+                                               bNeedEncryption = true;
+                                       }
+                               }
+                       }
 
+                       if (pDevice->byCntMeasure == 2) {
+                               bNeedDeAuth = true;
+                               pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
+                       }
 
-#ifdef PLICE_DEBUG
-       //if (skb->len == 98)
-       //{
-       //      printk("ping:len is %d\n");
-       //}
-#endif
-    vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
-                        cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
-                        &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
-                        &uMACfragNum,
-                        &cbHeaderSize
-                        );
-
-    if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
-        // Disable PS
-        MACbPSWakeup(pDevice->PortOffset);
-    }
-    pDevice->bPWBitOn = false;
-
-    pLastTD = pHeadTD;
-    for (ii = 0; ii < uMACfragNum; ii++) {
-        // Poll Transmit the adapter
-        wmb();
-        pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
-        wmb();
-        if (ii == uMACfragNum - 1)
-            pLastTD = pHeadTD;
-        pHeadTD = pHeadTD->next;
-    }
-
-    // Save the information needed by the tx interrupt handler
-    // to complete the Send request
-    pLastTD->pTDInfo->skb = skb;
-    pLastTD->pTDInfo->byFlags = 0;
-    pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
+                       if (pDevice->bEnableHostWEP) {
+                               if ((uNodeIndex != 0) &&
+                                   (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
+                                       bNeedEncryption = true;
+                               }
+                       }
+               } else {
+                       if (pTransmitKey == NULL) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return no tx key\n");
+                               dev_kfree_skb_irq(skb);
+                               spin_unlock_irq(&pDevice->lock);
+                               return 0;
+                       }
+               }
+       }
+
+       vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
+                           cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
+                           &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
+                           &uMACfragNum,
+                           &cbHeaderSize
+               );
+
+       if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
+               // Disable PS
+               MACbPSWakeup(pDevice->PortOffset);
+       }
+       pDevice->bPWBitOn = false;
+
+       pLastTD = pHeadTD;
+       for (ii = 0; ii < uMACfragNum; ii++) {
+               // Poll Transmit the adapter
+               wmb();
+               pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
+               wmb();
+               if (ii == uMACfragNum - 1)
+                       pLastTD = pHeadTD;
+               pHeadTD = pHeadTD->next;
+       }
+
+       // Save the information needed by the tx interrupt handler
+       // to complete the Send request
+       pLastTD->pTDInfo->skb = skb;
+       pLastTD->pTDInfo->byFlags = 0;
+       pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
 #ifdef TxInSleep
-  pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
-  #endif
-    if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1) {
-        netif_stop_queue(dev);
-    }
+       pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
+#endif
+       if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1) {
+               netif_stop_queue(dev);
+       }
 
-    pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
+       pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
 //#ifdef       PLICE_DEBUG
-       if (pDevice->bFixRate)
-       {
-               printk("FixRate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
-       }
-       else
-       {
-               //printk("Auto Rate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
+       if (pDevice->bFixRate) {
+               printk("FixRate:Rate is %d,TxPower is %d\n", pDevice->wCurrentRate, pDevice->byCurPwr);
+       } else {
        }
 //#endif
 
-{
-    unsigned char Protocol_Version;    //802.1x Authentication
-    unsigned char Packet_Type;           //802.1x Authentication
-    unsigned char Descriptor_type;
-    unsigned short Key_info;
-bool bTxeapol_key = false;
-    Protocol_Version = skb->data[ETH_HLEN];
-    Packet_Type = skb->data[ETH_HLEN+1];
-    Descriptor_type = skb->data[ETH_HLEN+1+1+2];
-    Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
-   if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
-           if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
-               (Packet_Type==3)) {  //802.1x OR eapol-key challenge frame transfer
-                        bTxeapol_key = true;
-               if((Descriptor_type==254)||(Descriptor_type==2)) {       //WPA or RSN
-                       if(!(Key_info & BIT3) &&   //group-key challenge
-                          (Key_info & BIT8) && (Key_info & BIT9)) {    //send 2/2 key
-                         pDevice->fWPA_Authened = true;
-                         if(Descriptor_type==254)
-                             printk("WPA ");
-                         else
-                             printk("WPA2 ");
-                         printk("Authentication completed!!\n");
-                        }
-                }
-             }
-   }
-}
+       {
+               unsigned char Protocol_Version;    //802.1x Authentication
+               unsigned char Packet_Type;           //802.1x Authentication
+               unsigned char Descriptor_type;
+               unsigned short Key_info;
+               bool bTxeapol_key = false;
+               Protocol_Version = skb->data[ETH_HLEN];
+               Packet_Type = skb->data[ETH_HLEN+1];
+               Descriptor_type = skb->data[ETH_HLEN+1+1+2];
+               Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
+               if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
+                       if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
+                           (Packet_Type == 3)) {  //802.1x OR eapol-key challenge frame transfer
+                               bTxeapol_key = true;
+                               if ((Descriptor_type == 254) || (Descriptor_type == 2)) {       //WPA or RSN
+                                       if (!(Key_info & BIT3) &&   //group-key challenge
+                                           (Key_info & BIT8) && (Key_info & BIT9)) {    //send 2/2 key
+                                               pDevice->fWPA_Authened = true;
+                                               if (Descriptor_type == 254)
+                                                       printk("WPA ");
+                                               else
+                                                       printk("WPA2 ");
+                                               printk("Authentication completed!!\n");
+                                       }
+                               }
+                       }
+               }
+       }
 
-    MACvTransmitAC0(pDevice->PortOffset);
+       MACvTransmitAC0(pDevice->PortOffset);
 //    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0:pDevice->apCurrTD= %p\n", pHeadTD);
 
-    dev->trans_start = jiffies;
-
-    spin_unlock_irq(&pDevice->lock);
-    return 0;
+       dev->trans_start = jiffies;
 
+       spin_unlock_irq(&pDevice->lock);
+       return 0;
 }
 
 static  irqreturn_t  device_intr(int irq,  void *dev_instance) {
-    struct net_device* dev=dev_instance;
-    PSDevice     pDevice=(PSDevice) netdev_priv(dev);
-
-    int             max_count=0;
-    unsigned long dwMIBCounter=0;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned char byOrgPageSel=0;
-    int             handled = 0;
-    unsigned char byData = 0;
-    int             ii= 0;
+       struct net_device *dev = dev_instance;
+       PSDevice     pDevice = (PSDevice)netdev_priv(dev);
+
+       int             max_count = 0;
+       unsigned long dwMIBCounter = 0;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned char byOrgPageSel = 0;
+       int             handled = 0;
+       unsigned char byData = 0;
+       int             ii = 0;
 //    unsigned char byRSSI;
 
+       MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
 
-    MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
-
-    if (pDevice->dwIsr == 0)
-        return IRQ_RETVAL(handled);
-
-    if (pDevice->dwIsr == 0xffffffff) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
-        return IRQ_RETVAL(handled);
-    }
-    /*
-      // 2008-05-21 <mark> by Richardtai, we can't read RSSI here, because no packet bound with RSSI
-
-       if ((pDevice->dwIsr & ISR_RXDMA0) &&
-        (pDevice->byLocalID != REV_ID_VT3253_B0) &&
-        (pDevice->bBSSIDFilter == true)) {
-        // update RSSI
-        //BBbReadEmbedded(pDevice->PortOffset, 0x3E, &byRSSI);
-        //pDevice->uCurrRSSI = byRSSI;
-    }
-    */
-
-    handled = 1;
-    MACvIntDisable(pDevice->PortOffset);
-    spin_lock_irq(&pDevice->lock);
-
-    //Make sure current page is 0
-    VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
-    if (byOrgPageSel == 1) {
-        MACvSelectPage0(pDevice->PortOffset);
-    }
-    else
-        byOrgPageSel = 0;
-
-    MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
-    // TBD....
-    // Must do this after doing rx/tx, cause ISR bit is slow
-    // than RD/TD write back
-    // update ISR counter
-    STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
-    while (pDevice->dwIsr != 0) {
-
-        STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
-        MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
-
-        if (pDevice->dwIsr & ISR_FETALERR){
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR \n");
-            VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
-            VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
-            device_error(pDevice, pDevice->dwIsr);
-        }
-
-        if (pDevice->byLocalID > REV_ID_VT3253_B1) {
-
-            if (pDevice->dwIsr & ISR_MEASURESTART) {
-                // 802.11h measure start
-                pDevice->byOrgChannel = pDevice->byCurrentCh;
-                VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
-                VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
-                MACvSelectPage1(pDevice->PortOffset);
-                VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
-                VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
-                MACvSelectPage0(pDevice->PortOffset);
-               //xxxx
-               // WCMDbFlushCommandQueue(pDevice->pMgmt, true);
-                if (set_channel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel) == true) {
-                    pDevice->bMeasureInProgress = true;
-                    MACvSelectPage1(pDevice->PortOffset);
-                    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
-                    MACvSelectPage0(pDevice->PortOffset);
-                    pDevice->byBasicMap = 0;
-                    pDevice->byCCAFraction = 0;
-                    for(ii=0;ii<8;ii++) {
-                        pDevice->dwRPIs[ii] = 0;
-                    }
-                } else {
-                    // can not measure because set channel fail
-                   // WCMDbResetCommandQueue(pDevice->pMgmt);
-                    // clear measure control
-                    MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
-                    s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
-                    MACvSelectPage1(pDevice->PortOffset);
-                    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
-                    MACvSelectPage0(pDevice->PortOffset);
-                }
-            }
-            if (pDevice->dwIsr & ISR_MEASUREEND) {
-                // 802.11h measure end
-                pDevice->bMeasureInProgress = false;
-                VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
-                MACvSelectPage1(pDevice->PortOffset);
-                VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
-                VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
-                VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
-                pDevice->byBasicMap |= (byData >> 4);
-                VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
-                VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
-                // clear measure control
-                MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
-                MACvSelectPage0(pDevice->PortOffset);
-                set_channel(pDevice, pDevice->byOrgChannel);
-                // WCMDbResetCommandQueue(pDevice->pMgmt);
-                MACvSelectPage1(pDevice->PortOffset);
-                MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
-                MACvSelectPage0(pDevice->PortOffset);
-                if (byData & MSRCTL_FINISH) {
-                    // measure success
-                    s_vCompleteCurrentMeasure(pDevice, 0);
-                } else {
-                    // can not measure because not ready before end of measure time
-                    s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
-                }
-            }
-            if (pDevice->dwIsr & ISR_QUIETSTART) {
-                do {
-                    ;
-                } while (CARDbStartQuiet(pDevice) == false);
-            }
-        }
-
-        if (pDevice->dwIsr & ISR_TBTT) {
-            if (pDevice->bEnableFirstQuiet == true) {
-                pDevice->byQuietStartCount--;
-                if (pDevice->byQuietStartCount == 0) {
-                    pDevice->bEnableFirstQuiet = false;
-                    MACvSelectPage1(pDevice->PortOffset);
-                    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
-                    MACvSelectPage0(pDevice->PortOffset);
-                }
-            }
-            if ((pDevice->bChannelSwitch == true) &&
-                (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
-                pDevice->byChannelSwitchCount--;
-                if (pDevice->byChannelSwitchCount == 0) {
-                    pDevice->bChannelSwitch = false;
-                    set_channel(pDevice, pDevice->byNewChannel);
-                    VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
-                    MACvSelectPage1(pDevice->PortOffset);
-                    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
-                    MACvSelectPage0(pDevice->PortOffset);
-                    CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
-
-                }
-            }
-            if (pDevice->eOPMode == OP_MODE_ADHOC) {
-                //pDevice->bBeaconSent = false;
-            } else {
-                if ((pDevice->bUpdateBBVGA) && (pDevice->bLinkPass == true) && (pDevice->uCurrRSSI != 0)) {
-                    long            ldBm;
-
-                    RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
-                    for (ii=0;ii<BB_VGA_LEVEL;ii++) {
-                        if (ldBm < pDevice->ldBmThreshold[ii]) {
-                            pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
-                            break;
-                        }
-                    }
-                    if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
-                        pDevice->uBBVGADiffCount++;
-                        if (pDevice->uBBVGADiffCount == 1) {
-                            // first VGA diff gain
-                            BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
-                            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
-                                            (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
-                        }
-                        if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
-                            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
-                                            (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
-                            BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
-                        }
-                    } else {
-                        pDevice->uBBVGADiffCount = 1;
-                    }
-                }
-            }
-
-            pDevice->bBeaconSent = false;
-            if (pDevice->bEnablePSMode) {
-                PSbIsNextTBTTWakeUp((void *)pDevice);
-            }
-
-            if ((pDevice->eOPMode == OP_MODE_AP) ||
-                (pDevice->eOPMode == OP_MODE_ADHOC)) {
-
-                MACvOneShotTimer1MicroSec(pDevice->PortOffset,
-                        (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
-            }
-
-            if (pDevice->eOPMode == OP_MODE_ADHOC && pDevice->pMgmt->wCurrATIMWindow > 0) {
-                // todo adhoc PS mode
-            }
-
-        }
-
-        if (pDevice->dwIsr & ISR_BNTX) {
-
-            if (pDevice->eOPMode == OP_MODE_ADHOC) {
-                pDevice->bIsBeaconBufReadySet = false;
-                pDevice->cbBeaconBufReadySetCnt = 0;
-            }
-
-            if (pDevice->eOPMode == OP_MODE_AP) {
-                if(pMgmt->byDTIMCount > 0) {
-                   pMgmt->byDTIMCount --;
-                   pMgmt->sNodeDBTable[0].bRxPSPoll = false;
-                }
-                else {
-                    if(pMgmt->byDTIMCount == 0) {
-                        // check if mutltcast tx bufferring
-                        pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
-                        pMgmt->sNodeDBTable[0].bRxPSPoll = true;
-                        bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
-                    }
-                }
-            }
-            pDevice->bBeaconSent = true;
-
-            if (pDevice->bChannelSwitch == true) {
-                pDevice->byChannelSwitchCount--;
-                if (pDevice->byChannelSwitchCount == 0) {
-                    pDevice->bChannelSwitch = false;
-                    set_channel(pDevice, pDevice->byNewChannel);
-                    VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
-                    MACvSelectPage1(pDevice->PortOffset);
-                    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
-                    MACvSelectPage0(pDevice->PortOffset);
-                    //VNTWIFIbSendBeacon(pDevice->pMgmt);
-                    CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
-                }
-            }
-
-        }
-
-        if (pDevice->dwIsr & ISR_RXDMA0) {
-            max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
-        }
-        if (pDevice->dwIsr & ISR_RXDMA1) {
-            max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
-        }
-        if (pDevice->dwIsr & ISR_TXDMA0){
-            max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
-        }
-        if (pDevice->dwIsr & ISR_AC0DMA){
-            max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
-        }
-        if (pDevice->dwIsr & ISR_SOFTTIMER) {
-
-        }
-        if (pDevice->dwIsr & ISR_SOFTTIMER1) {
-            if (pDevice->eOPMode == OP_MODE_AP) {
-               if (pDevice->bShortSlotTime)
-                   pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
-               else
-                   pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
-            }
-            bMgrPrepareBeaconToSend(pDevice, pMgmt);
-            pDevice->byCntMeasure = 0;
-        }
-
-        MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
-
-        MACvReceive0(pDevice->PortOffset);
-        MACvReceive1(pDevice->PortOffset);
-
-        if (max_count>pDevice->sOpts.int_works)
-            break;
-    }
-
-    if (byOrgPageSel == 1) {
-        MACvSelectPage1(pDevice->PortOffset);
-    }
-
-    spin_unlock_irq(&pDevice->lock);
-    MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
-
-    return IRQ_RETVAL(handled);
-}
+       if (pDevice->dwIsr == 0)
+               return IRQ_RETVAL(handled);
+
+       if (pDevice->dwIsr == 0xffffffff) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
+               return IRQ_RETVAL(handled);
+       }
+       /*
+       // 2008-05-21 <mark> by Richardtai, we can't read RSSI here, because no packet bound with RSSI
+
+       if ((pDevice->dwIsr & ISR_RXDMA0) &&
+       (pDevice->byLocalID != REV_ID_VT3253_B0) &&
+       (pDevice->bBSSIDFilter == true)) {
+       // update RSSI
+       //BBbReadEmbedded(pDevice->PortOffset, 0x3E, &byRSSI);
+       //pDevice->uCurrRSSI = byRSSI;
+       }
+       */
+
+       handled = 1;
+       MACvIntDisable(pDevice->PortOffset);
+       spin_lock_irq(&pDevice->lock);
+
+       //Make sure current page is 0
+       VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
+       if (byOrgPageSel == 1) {
+               MACvSelectPage0(pDevice->PortOffset);
+       } else
+               byOrgPageSel = 0;
+
+       MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
+       // TBD....
+       // Must do this after doing rx/tx, cause ISR bit is slow
+       // than RD/TD write back
+       // update ISR counter
+       STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
+       while (pDevice->dwIsr != 0) {
+               STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
+               MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
+
+               if (pDevice->dwIsr & ISR_FETALERR) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR \n");
+                       VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
+                       VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
+                       device_error(pDevice, pDevice->dwIsr);
+               }
+
+               if (pDevice->byLocalID > REV_ID_VT3253_B1) {
+                       if (pDevice->dwIsr & ISR_MEASURESTART) {
+                               // 802.11h measure start
+                               pDevice->byOrgChannel = pDevice->byCurrentCh;
+                               VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
+                               VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
+                               MACvSelectPage1(pDevice->PortOffset);
+                               VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
+                               VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
+                               MACvSelectPage0(pDevice->PortOffset);
+                               //xxxx
+                               // WCMDbFlushCommandQueue(pDevice->pMgmt, true);
+                               if (set_channel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel) == true) {
+                                       pDevice->bMeasureInProgress = true;
+                                       MACvSelectPage1(pDevice->PortOffset);
+                                       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
+                                       MACvSelectPage0(pDevice->PortOffset);
+                                       pDevice->byBasicMap = 0;
+                                       pDevice->byCCAFraction = 0;
+                                       for (ii = 0; ii < 8; ii++) {
+                                               pDevice->dwRPIs[ii] = 0;
+                                       }
+                               } else {
+                                       // can not measure because set channel fail
+                                       // WCMDbResetCommandQueue(pDevice->pMgmt);
+                                       // clear measure control
+                                       MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
+                                       s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
+                                       MACvSelectPage1(pDevice->PortOffset);
+                                       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
+                                       MACvSelectPage0(pDevice->PortOffset);
+                               }
+                       }
+                       if (pDevice->dwIsr & ISR_MEASUREEND) {
+                               // 802.11h measure end
+                               pDevice->bMeasureInProgress = false;
+                               VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
+                               MACvSelectPage1(pDevice->PortOffset);
+                               VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
+                               VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
+                               VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
+                               pDevice->byBasicMap |= (byData >> 4);
+                               VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
+                               VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
+                               // clear measure control
+                               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
+                               MACvSelectPage0(pDevice->PortOffset);
+                               set_channel(pDevice, pDevice->byOrgChannel);
+                               // WCMDbResetCommandQueue(pDevice->pMgmt);
+                               MACvSelectPage1(pDevice->PortOffset);
+                               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
+                               MACvSelectPage0(pDevice->PortOffset);
+                               if (byData & MSRCTL_FINISH) {
+                                       // measure success
+                                       s_vCompleteCurrentMeasure(pDevice, 0);
+                               } else {
+                                       // can not measure because not ready before end of measure time
+                                       s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
+                               }
+                       }
+                       if (pDevice->dwIsr & ISR_QUIETSTART) {
+                               do {
+                                       ;
+                               } while (CARDbStartQuiet(pDevice) == false);
+                       }
+               }
+
+               if (pDevice->dwIsr & ISR_TBTT) {
+                       if (pDevice->bEnableFirstQuiet == true) {
+                               pDevice->byQuietStartCount--;
+                               if (pDevice->byQuietStartCount == 0) {
+                                       pDevice->bEnableFirstQuiet = false;
+                                       MACvSelectPage1(pDevice->PortOffset);
+                                       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
+                                       MACvSelectPage0(pDevice->PortOffset);
+                               }
+                       }
+                       if ((pDevice->bChannelSwitch == true) &&
+                           (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
+                               pDevice->byChannelSwitchCount--;
+                               if (pDevice->byChannelSwitchCount == 0) {
+                                       pDevice->bChannelSwitch = false;
+                                       set_channel(pDevice, pDevice->byNewChannel);
+                                       VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
+                                       MACvSelectPage1(pDevice->PortOffset);
+                                       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
+                                       MACvSelectPage0(pDevice->PortOffset);
+                                       CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
+
+                               }
+                       }
+                       if (pDevice->eOPMode == OP_MODE_ADHOC) {
+                               //pDevice->bBeaconSent = false;
+                       } else {
+                               if ((pDevice->bUpdateBBVGA) && (pDevice->bLinkPass == true) && (pDevice->uCurrRSSI != 0)) {
+                                       long            ldBm;
+
+                                       RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
+                                       for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
+                                               if (ldBm < pDevice->ldBmThreshold[ii]) {
+                                                       pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
+                                                       break;
+                                               }
+                                       }
+                                       if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
+                                               pDevice->uBBVGADiffCount++;
+                                               if (pDevice->uBBVGADiffCount == 1) {
+                                                       // first VGA diff gain
+                                                       BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
+                                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
+                                                               (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
+                                               }
+                                               if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
+                                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
+                                                               (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
+                                                       BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
+                                               }
+                                       } else {
+                                               pDevice->uBBVGADiffCount = 1;
+                                       }
+                               }
+                       }
+
+                       pDevice->bBeaconSent = false;
+                       if (pDevice->bEnablePSMode) {
+                               PSbIsNextTBTTWakeUp((void *)pDevice);
+                       }
+
+                       if ((pDevice->eOPMode == OP_MODE_AP) ||
+                           (pDevice->eOPMode == OP_MODE_ADHOC)) {
+                               MACvOneShotTimer1MicroSec(pDevice->PortOffset,
+                                                         (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
+                       }
+
+                       if (pDevice->eOPMode == OP_MODE_ADHOC && pDevice->pMgmt->wCurrATIMWindow > 0) {
+                               // todo adhoc PS mode
+                       }
+
+               }
+
+               if (pDevice->dwIsr & ISR_BNTX) {
+                       if (pDevice->eOPMode == OP_MODE_ADHOC) {
+                               pDevice->bIsBeaconBufReadySet = false;
+                               pDevice->cbBeaconBufReadySetCnt = 0;
+                       }
+
+                       if (pDevice->eOPMode == OP_MODE_AP) {
+                               if (pMgmt->byDTIMCount > 0) {
+                                       pMgmt->byDTIMCount--;
+                                       pMgmt->sNodeDBTable[0].bRxPSPoll = false;
+                               } else {
+                                       if (pMgmt->byDTIMCount == 0) {
+                                               // check if mutltcast tx bufferring
+                                               pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
+                                               pMgmt->sNodeDBTable[0].bRxPSPoll = true;
+                                               bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
+                                       }
+                               }
+                       }
+                       pDevice->bBeaconSent = true;
+
+                       if (pDevice->bChannelSwitch == true) {
+                               pDevice->byChannelSwitchCount--;
+                               if (pDevice->byChannelSwitchCount == 0) {
+                                       pDevice->bChannelSwitch = false;
+                                       set_channel(pDevice, pDevice->byNewChannel);
+                                       VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
+                                       MACvSelectPage1(pDevice->PortOffset);
+                                       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
+                                       MACvSelectPage0(pDevice->PortOffset);
+                                       //VNTWIFIbSendBeacon(pDevice->pMgmt);
+                                       CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
+                               }
+                       }
+
+               }
+
+               if (pDevice->dwIsr & ISR_RXDMA0) {
+                       max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
+               }
+               if (pDevice->dwIsr & ISR_RXDMA1) {
+                       max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
+               }
+               if (pDevice->dwIsr & ISR_TXDMA0) {
+                       max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
+               }
+               if (pDevice->dwIsr & ISR_AC0DMA) {
+                       max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
+               }
+               if (pDevice->dwIsr & ISR_SOFTTIMER) {
+               }
+               if (pDevice->dwIsr & ISR_SOFTTIMER1) {
+                       if (pDevice->eOPMode == OP_MODE_AP) {
+                               if (pDevice->bShortSlotTime)
+                                       pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
+                               else
+                                       pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
+                       }
+                       bMgrPrepareBeaconToSend(pDevice, pMgmt);
+                       pDevice->byCntMeasure = 0;
+               }
+
+               MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
 
+               MACvReceive0(pDevice->PortOffset);
+               MACvReceive1(pDevice->PortOffset);
+
+               if (max_count > pDevice->sOpts.int_works)
+                       break;
+       }
+
+       if (byOrgPageSel == 1) {
+               MACvSelectPage1(pDevice->PortOffset);
+       }
+
+       spin_unlock_irq(&pDevice->lock);
+       MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
+
+       return IRQ_RETVAL(handled);
+}
 
 static unsigned const ethernet_polynomial = 0x04c11db7U;
 static inline u32 ether_crc(int length, unsigned char *data)
 {
-    int crc = -1;
-
-    while(--length >= 0) {
-        unsigned char current_octet = *data++;
-        int bit;
-        for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
-            crc = (crc << 1) ^
-                ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
-        }
-    }
-    return crc;
+       int crc = -1;
+
+       while (--length >= 0) {
+               unsigned char current_octet = *data++;
+               int bit;
+               for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
+                       crc = (crc << 1) ^
+                               ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
+               }
+       }
+       return crc;
 }
 
 //2008-8-4 <add> by chester
 static int Config_FileGetParameter(unsigned char *string,
-               unsigned char *dest, unsigned char *source)
+                                  unsigned char *dest, unsigned char *source)
 {
-  unsigned char buf1[100];
-  int source_len = strlen(source);
+       unsigned char buf1[100];
+       int source_len = strlen(source);
 
-    memset(buf1,0,100);
-    strcat(buf1, string);
-    strcat(buf1, "=");
-    source+=strlen(buf1);
+       memset(buf1, 0, 100);
+       strcat(buf1, string);
+       strcat(buf1, "=");
+       source += strlen(buf1);
 
-   memcpy(dest,source,source_len-strlen(buf1));
- return true;
+       memcpy(dest, source, source_len - strlen(buf1));
      return true;
 }
 
-int Config_FileOperation(PSDevice pDevice,bool fwrite,unsigned char *Parameter) {
-    unsigned char *config_path = CONFIG_PATH;
-    unsigned char *buffer = NULL;
-    unsigned char tmpbuffer[20];
-    struct file   *filp=NULL;
-    mm_segment_t old_fs = get_fs();
-    //int oldfsuid=0,oldfsgid=0;
-    int result=0;
-
-    set_fs (KERNEL_DS);
-
-    /* Can't do this anymore, so we rely on correct filesystem permissions:
-    //Make sure a caller can read or write power as root
-    oldfsuid=current->cred->fsuid;
-    oldfsgid=current->cred->fsgid;
-    current->cred->fsuid = 0;
-    current->cred->fsgid = 0;
-    */
-
-    //open file
-      filp = filp_open(config_path, O_RDWR, 0);
-        if (IS_ERR(filp)) {
-            printk("Config_FileOperation:open file fail?\n");
-            result=-1;
-             goto error2;
-         }
-
-     if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
-           printk("file %s cann't readable or writable?\n",config_path);
-         result = -1;
-         goto error1;
-       }
-
-buffer = kmalloc(1024, GFP_KERNEL);
-if(buffer==NULL) {
-  printk("allocate mem for file fail?\n");
-  result = -1;
-  goto error1;
-}
+int Config_FileOperation(PSDevice pDevice, bool fwrite, unsigned char *Parameter) {
+       unsigned char *config_path = CONFIG_PATH;
+       unsigned char *buffer = NULL;
+       unsigned char tmpbuffer[20];
+       struct file   *filp = NULL;
+       mm_segment_t old_fs = get_fs();
+       //int oldfsuid=0,oldfsgid=0;
+       int result = 0;
+
+       set_fs(KERNEL_DS);
+
+       /* Can't do this anymore, so we rely on correct filesystem permissions:
+       //Make sure a caller can read or write power as root
+       oldfsuid=current->cred->fsuid;
+       oldfsgid=current->cred->fsgid;
+       current->cred->fsuid = 0;
+       current->cred->fsgid = 0;
+       */
+
+       //open file
+       filp = filp_open(config_path, O_RDWR, 0);
+       if (IS_ERR(filp)) {
+               printk("Config_FileOperation:open file fail?\n");
+               result = -1;
+               goto error2;
+       }
 
-if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
printk("read file error?\n");
- result = -1;
- goto error1;
-}
+       if (!(filp->f_op) || !(filp->f_op->read) || !(filp->f_op->write)) {
              printk("file %s cann't readable or writable?\n", config_path);
              result = -1;
              goto error1;
+       }
 
-if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=true) {
-  printk("get parameter error?\n");
-  result = -1;
-  goto error1;
-}
+       buffer = kmalloc(1024, GFP_KERNEL);
+       if (buffer == NULL) {
+               printk("allocate mem for file fail?\n");
+               result = -1;
+               goto error1;
+       }
 
-if(memcmp(tmpbuffer,"USA",3)==0) {
-  result=ZoneType_USA;
-}
-else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
-  result=ZoneType_Japan;
-}
-else if(memcmp(tmpbuffer,"EUROPE",5)==0) {
- result=ZoneType_Europe;
-}
-else {
-  result = -1;
-  printk("Unknown Zonetype[%s]?\n",tmpbuffer);
-}
+       if (filp->f_op->read(filp, buffer, 1024, &filp->f_pos) < 0) {
+               printk("read file error?\n");
+               result = -1;
+               goto error1;
+       }
+
+       if (Config_FileGetParameter("ZONETYPE", tmpbuffer, buffer) != true) {
+               printk("get parameter error?\n");
+               result = -1;
+               goto error1;
+       }
+
+       if (memcmp(tmpbuffer, "USA", 3) == 0) {
+               result = ZoneType_USA;
+       } else if (memcmp(tmpbuffer, "JAPAN", 5) == 0) {
+               result = ZoneType_Japan;
+       } else if (memcmp(tmpbuffer, "EUROPE", 5) == 0) {
+               result = ZoneType_Europe;
+       } else {
+               result = -1;
+               printk("Unknown Zonetype[%s]?\n", tmpbuffer);
+       }
 
 error1:
-  kfree(buffer);
+       kfree(buffer);
 
-  if(filp_close(filp,NULL))
-       printk("Config_FileOperation:close file fail\n");
+       if (filp_close(filp, NULL))
+               printk("Config_FileOperation:close file fail\n");
 
 error2:
-  set_fs (old_fs);
+       set_fs(old_fs);
 
-  /*
-  current->cred->fsuid=oldfsuid;
-  current->cred->fsgid=oldfsgid;
-  */
+       /*
+         current->cred->fsuid=oldfsuid;
+         current->cred->fsgid=oldfsgid;
+       */
 
-  return result;
+       return result;
 }
 
+static void device_set_multi(struct net_device *dev) {
+       PSDevice         pDevice = (PSDevice)netdev_priv(dev);
+
+       PSMgmtObject     pMgmt = pDevice->pMgmt;
+       u32              mc_filter[2];
+       struct netdev_hw_addr *ha;
+
+       VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
+
+       if (dev->flags & IFF_PROMISC) {         /* Set promiscuous. */
+               DBG_PRT(MSG_LEVEL_ERR, KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
+               /* Unconditionally log net taps. */
+               pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
+       } else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
+                ||  (dev->flags & IFF_ALLMULTI)) {
+               MACvSelectPage1(pDevice->PortOffset);
+               VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
+               VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
+               MACvSelectPage0(pDevice->PortOffset);
+               pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
+       } else {
+               memset(mc_filter, 0, sizeof(mc_filter));
+               netdev_for_each_mc_addr(ha, dev) {
+                       int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
+                       mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
+               }
+               MACvSelectPage1(pDevice->PortOffset);
+               VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
+               VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
+               MACvSelectPage0(pDevice->PortOffset);
+               pDevice->byRxMode &= ~(RCR_UNICAST);
+               pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
+       }
 
+       if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
+               // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
+               pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
+               pDevice->byRxMode &= ~(RCR_UNICAST);
+       }
 
-static void device_set_multi(struct net_device *dev) {
-    PSDevice         pDevice = (PSDevice) netdev_priv(dev);
-
-    PSMgmtObject     pMgmt = pDevice->pMgmt;
-    u32              mc_filter[2];
-    struct netdev_hw_addr *ha;
-
-
-    VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
-
-    if (dev->flags & IFF_PROMISC) {         /* Set promiscuous. */
-        DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
-        /* Unconditionally log net taps. */
-        pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
-    }
-    else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
-        ||  (dev->flags & IFF_ALLMULTI)) {
-        MACvSelectPage1(pDevice->PortOffset);
-        VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
-        VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
-        MACvSelectPage0(pDevice->PortOffset);
-        pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
-    }
-    else {
-        memset(mc_filter, 0, sizeof(mc_filter));
-       netdev_for_each_mc_addr(ha, dev) {
-            int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
-            mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
-        }
-        MACvSelectPage1(pDevice->PortOffset);
-        VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
-        VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
-        MACvSelectPage0(pDevice->PortOffset);
-        pDevice->byRxMode &= ~(RCR_UNICAST);
-        pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
-    }
-
-    if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
-        // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
-        pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
-        pDevice->byRxMode &= ~(RCR_UNICAST);
-    }
-
-    VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode );
+       VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode);
 }
 
-
 static struct net_device_stats *device_get_stats(struct net_device *dev) {
-    PSDevice pDevice=(PSDevice) netdev_priv(dev);
+       PSDevice pDevice = (PSDevice)netdev_priv(dev);
 
-    return &pDevice->stats;
+       return &pDevice->stats;
 }
 
-
-
 static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
 
-       struct iwreq *wrq = (struct iwreq *) rq;
-       int                 rc =0;
-    PSMgmtObject        pMgmt = pDevice->pMgmt;
-    PSCmdRequest        pReq;
+       struct iwreq *wrq = (struct iwreq *)rq;
+       int rc = 0;
+       PSMgmtObject pMgmt = pDevice->pMgmt;
+       PSCmdRequest pReq;
 
+       if (pMgmt == NULL) {
+               rc = -EFAULT;
+               return rc;
+       }
 
-    if (pMgmt == NULL) {
-        rc = -EFAULT;
-        return rc;
-    }
-
-    switch(cmd) {
-
+       switch (cmd) {
        case SIOCGIWNAME:
                rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
                break;
@@ -3113,7 +2891,7 @@ static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
 
                // Set frequency/channel
        case SIOCSIWFREQ:
-           rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
+               rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
                break;
 
                // Get frequency/channel
@@ -3124,60 +2902,57 @@ static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
                // Set desired network name (ESSID)
        case SIOCSIWESSID:
 
-               {
-                       char essid[IW_ESSID_MAX_SIZE+1];
-                       if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
-                               rc = -E2BIG;
-                               break;
-                       }
-                       if (copy_from_user(essid, wrq->u.essid.pointer,
-                                          wrq->u.essid.length)) {
-                               rc = -EFAULT;
-                               break;
-                       }
-                       rc = iwctl_siwessid(dev, NULL,
-                                           &(wrq->u.essid), essid);
+       {
+               char essid[IW_ESSID_MAX_SIZE+1];
+               if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
+                       rc = -E2BIG;
+                       break;
                }
-               break;
-
+               if (copy_from_user(essid, wrq->u.essid.pointer,
+                                  wrq->u.essid.length)) {
+                       rc = -EFAULT;
+                       break;
+               }
+               rc = iwctl_siwessid(dev, NULL,
+                                   &(wrq->u.essid), essid);
+       }
+       break;
 
-               // Get current network name (ESSID)
+       // Get current network name (ESSID)
        case SIOCGIWESSID:
 
-               {
-                       char essid[IW_ESSID_MAX_SIZE+1];
-                       if (wrq->u.essid.pointer)
-                               rc = iwctl_giwessid(dev, NULL,
-                                                   &(wrq->u.essid), essid);
-                               if (copy_to_user(wrq->u.essid.pointer,
-                                                        essid,
-                                                        wrq->u.essid.length) )
-                                       rc = -EFAULT;
-               }
-               break;
+       {
+               char essid[IW_ESSID_MAX_SIZE+1];
+               if (wrq->u.essid.pointer)
+                       rc = iwctl_giwessid(dev, NULL,
+                                           &(wrq->u.essid), essid);
+               if (copy_to_user(wrq->u.essid.pointer,
+                                essid,
+                                wrq->u.essid.length))
+                       rc = -EFAULT;
+       }
+       break;
 
        case SIOCSIWAP:
 
                rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
                break;
 
-
                // Get current Access Point (BSSID)
        case SIOCGIWAP:
                rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
                break;
 
-
                // Set desired station name
        case SIOCSIWNICKN:
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
-        rc = -EOPNOTSUPP;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
+               rc = -EOPNOTSUPP;
                break;
 
                // Get current station name
        case SIOCGIWNICKN:
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
-        rc = -EOPNOTSUPP;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
+               rc = -EOPNOTSUPP;
                break;
 
                // Set the desired bit-rate
@@ -3185,19 +2960,19 @@ static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
                rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
                break;
 
-       // Get the current bit-rate
+               // Get the current bit-rate
        case SIOCGIWRATE:
 
                rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
                break;
 
-       // Set the desired RTS threshold
+               // Set the desired RTS threshold
        case SIOCSIWRTS:
 
                rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
                break;
 
-       // Get the current RTS threshold
+               // Get the current RTS threshold
        case SIOCGIWRTS:
 
                rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
@@ -3207,9 +2982,9 @@ static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
        case SIOCSIWFRAG:
 
                rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
-           break;
+               break;
 
-       // Get the current fragmentation threshold
+               // Get the current fragmentation threshold
        case SIOCGIWFRAG:
 
                rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
@@ -3217,7 +2992,7 @@ static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
 
                // Set mode of operation
        case SIOCSIWMODE:
-       rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
+               rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
                break;
 
                // Get mode of operation
@@ -3226,33 +3001,30 @@ static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
                break;
 
                // Set WEP keys and mode
-       case SIOCSIWENCODE:
-               {
-            char abyKey[WLAN_WEP232_KEYLEN];
-
-                       if (wrq->u.encoding.pointer) {
-
+       case SIOCSIWENCODE: {
+               char abyKey[WLAN_WEP232_KEYLEN];
 
-                               if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
-                                       rc = -E2BIG;
-                                       break;
-                               }
-                               memset(abyKey, 0, WLAN_WEP232_KEYLEN);
-                               if (copy_from_user(abyKey,
-                                                 wrq->u.encoding.pointer,
-                                                 wrq->u.encoding.length)) {
-                                       rc = -EFAULT;
-                                       break;
-                               }
-                       } else if (wrq->u.encoding.length != 0) {
-                               rc = -EINVAL;
+               if (wrq->u.encoding.pointer) {
+                       if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
+                               rc = -E2BIG;
                                break;
                        }
-                       rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
+                       memset(abyKey, 0, WLAN_WEP232_KEYLEN);
+                       if (copy_from_user(abyKey,
+                                          wrq->u.encoding.pointer,
+                                          wrq->u.encoding.length)) {
+                               rc = -EFAULT;
+                               break;
+                       }
+               } else if (wrq->u.encoding.length != 0) {
+                       rc = -EINVAL;
+                       break;
                }
-               break;
+               rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
+       }
+       break;
 
-               // Get the WEP keys and mode
+       // Get the WEP keys and mode
        case SIOCGIWENCODE:
 
                if (!capable(CAP_NET_ADMIN)) {
@@ -3260,14 +3032,14 @@ static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
                        break;
                }
                {
-                   char abyKey[WLAN_WEP232_KEYLEN];
+                       char abyKey[WLAN_WEP232_KEYLEN];
 
-                   rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
-                   if (rc != 0) break;
+                       rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
+                       if (rc != 0) break;
                        if (wrq->u.encoding.pointer) {
                                if (copy_to_user(wrq->u.encoding.pointer,
-                                                       abyKey,
-                                                       wrq->u.encoding.length))
+                                                abyKey,
+                                                wrq->u.encoding.length))
                                        rc = -EFAULT;
                        }
                }
@@ -3275,13 +3047,13 @@ static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
 
                // Get the current Tx-Power
        case SIOCGIWTXPOW:
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
-        rc = -EOPNOTSUPP;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
+               rc = -EOPNOTSUPP;
                break;
 
        case SIOCSIWTXPOW:
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWTXPOW \n");
-        rc = -EOPNOTSUPP;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWTXPOW \n");
+               rc = -EOPNOTSUPP;
                break;
 
        case SIOCSIWRETRY:
@@ -3297,91 +3069,86 @@ static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
                // Get range of parameters
        case SIOCGIWRANGE:
 
-               {
-                       struct iw_range range;
+       {
+               struct iw_range range;
 
-                       rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *) &range);
-                       if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
-                               rc = -EFAULT;
-               }
+               rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *)&range);
+               if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
+                       rc = -EFAULT;
+       }
 
-               break;
+       break;
 
        case SIOCGIWPOWER:
 
                rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
                break;
 
-
        case SIOCSIWPOWER:
 
                rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
                break;
 
-
        case SIOCGIWSENS:
 
-           rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
+               rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
                break;
 
        case SIOCSIWSENS:
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
                rc = -EOPNOTSUPP;
                break;
 
-       case SIOCGIWAPLIST:
-           {
-            char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
-
-                   if (wrq->u.data.pointer) {
-                       rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
-                       if (rc == 0) {
-                    if (copy_to_user(wrq->u.data.pointer,
-                                                       buffer,
-                                                      (wrq->u.data.length * (sizeof(struct sockaddr) +  sizeof(struct iw_quality)))
-                                       ))
-                                   rc = -EFAULT;
-                       }
-            }
-        }
-               break;
+       case SIOCGIWAPLIST: {
+               char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
 
+               if (wrq->u.data.pointer) {
+                       rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
+                       if (rc == 0) {
+                               if (copy_to_user(wrq->u.data.pointer,
+                                                buffer,
+                                                (wrq->u.data.length * (sizeof(struct sockaddr) +  sizeof(struct iw_quality)))
+                                           ))
+                                       rc = -EFAULT;
+                       }
+               }
+       }
+       break;
 
 #ifdef WIRELESS_SPY
-               // Set the spy list
+       // Set the spy list
        case SIOCSIWSPY:
 
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
                rc = -EOPNOTSUPP;
                break;
 
                // Get the spy list
        case SIOCGIWSPY:
 
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSPY \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSPY \n");
                rc = -EOPNOTSUPP;
                break;
 
 #endif // WIRELESS_SPY
 
        case SIOCGIWPRIV:
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
                rc = -EOPNOTSUPP;
 /*
-               if(wrq->u.data.pointer) {
-                       wrq->u.data.length = sizeof(iwctl_private_args) / sizeof( iwctl_private_args[0]);
+  if (wrq->u.data.pointer) {
+  wrq->u.data.length = sizeof(iwctl_private_args) / sizeof(iwctl_private_args[0]);
 
-                       if(copy_to_user(wrq->u.data.pointer,
-                                       (u_char *) iwctl_private_args,
-                                       sizeof(iwctl_private_args)))
-                               rc = -EFAULT;
-               }
+  if (copy_to_user(wrq->u.data.pointer,
+  (u_char *) iwctl_private_args,
+  sizeof(iwctl_private_args)))
+  rc = -EFAULT;
+  }
 */
                break;
 
-
 //2008-0409-07, <Add> by Einsn Liu
-#ifdef  WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
        case SIOCSIWAUTH:
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
                rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
@@ -3402,27 +3169,26 @@ static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
                rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
                break;
 
-       case SIOCSIWENCODEEXT:
-               {
-                       char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
-                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
-                       if(wrq->u.encoding.pointer){
-                               memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1);
-                               if(wrq->u.encoding.length > (sizeof(struct iw_encode_ext)+ MAX_KEY_LEN)){
-                                       rc = -E2BIG;
-                                       break;
-                               }
-                               if(copy_from_user(extra, wrq->u.encoding.pointer,wrq->u.encoding.length)){
-                                       rc = -EFAULT;
-                                       break;
-                               }
-                       }else if(wrq->u.encoding.length != 0){
-                               rc = -EINVAL;
+       case SIOCSIWENCODEEXT: {
+               char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
+               if (wrq->u.encoding.pointer) {
+                       memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN + 1);
+                       if (wrq->u.encoding.length > (sizeof(struct iw_encode_ext) + MAX_KEY_LEN)) {
+                               rc = -E2BIG;
+                               break;
+                       }
+                       if (copy_from_user(extra, wrq->u.encoding.pointer, wrq->u.encoding.length)) {
+                               rc = -EFAULT;
                                break;
                        }
-                       rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
+               } else if (wrq->u.encoding.length != 0) {
+                       rc = -EINVAL;
+                       break;
                }
-               break;
+               rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
+       }
+       break;
 
        case SIOCGIWENCODEEXT:
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT \n");
@@ -3437,91 +3203,87 @@ static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
 //End Add -- //2008-0409-07, <Add> by Einsn Liu
 
-    case IOCTL_CMD_TEST:
+       case IOCTL_CMD_TEST:
 
                if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
-                   rc = -EFAULT;
-                   break;
-               } else {
-                   rc = 0;
-               }
-        pReq = (PSCmdRequest)rq;
-        pReq->wResult = MAGIC_CODE;
-        break;
-
-    case IOCTL_CMD_SET:
-
-               #ifdef SndEvt_ToAPI
-                  if((((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_EVT) &&
-                      !(pDevice->flags & DEVICE_FLAGS_OPENED))
-             #else
-               if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
-                      (((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_WPA))
-             #endif
-               {
-                   rc = -EFAULT;
-                   break;
+                       rc = -EFAULT;
+                       break;
                } else {
-                   rc = 0;
+                       rc = 0;
                }
+               pReq = (PSCmdRequest)rq;
+               pReq->wResult = MAGIC_CODE;
+               break;
 
-           if (test_and_set_bit( 0, (void*)&(pMgmt->uCmdBusy))) {
-                   return -EBUSY;
-           }
-        rc = private_ioctl(pDevice, rq);
-        clear_bit( 0, (void*)&(pMgmt->uCmdBusy));
-        break;
+       case IOCTL_CMD_SET:
 
-    case IOCTL_CMD_HOSTAPD:
+#ifdef SndEvt_ToAPI
+               if ((((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_EVT) &&
+                   !(pDevice->flags & DEVICE_FLAGS_OPENED))
+#else
+                       if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
+                           (((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_WPA))
+#endif
+                       {
+                               rc = -EFAULT;
+                               break;
+                       } else {
+                               rc = 0;
+                       }
 
+               if (test_and_set_bit(0, (void *)&(pMgmt->uCmdBusy))) {
+                       return -EBUSY;
+               }
+               rc = private_ioctl(pDevice, rq);
+               clear_bit(0, (void *)&(pMgmt->uCmdBusy));
+               break;
 
-       rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data);
-        break;
+       case IOCTL_CMD_HOSTAPD:
 
-    case IOCTL_CMD_WPA:
+               rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data);
+               break;
 
-       rc = wpa_ioctl(pDevice, &wrq->u.data);
-        break;
+       case IOCTL_CMD_WPA:
+
+               rc = wpa_ioctl(pDevice, &wrq->u.data);
+               break;
 
        case SIOCETHTOOL:
-        return ethtool_ioctl(dev, (void *) rq->ifr_data);
-       // All other calls are currently unsupported
+               return ethtool_ioctl(dev, (void *)rq->ifr_data);
+               // All other calls are currently unsupported
 
        default:
                rc = -EOPNOTSUPP;
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
-
-
-    }
-
-    if (pDevice->bCommit) {
-       if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
-           netif_stop_queue(pDevice->dev);
-           spin_lock_irq(&pDevice->lock);
-           bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
-           spin_unlock_irq(&pDevice->lock);
-       }
-       else {
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
-           spin_lock_irq(&pDevice->lock);
-           pDevice->bLinkPass = false;
-           memset(pMgmt->abyCurrBSSID, 0, 6);
-           pMgmt->eCurrState = WMAC_STATE_IDLE;
-           netif_stop_queue(pDevice->dev);
-       #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-             pMgmt->eScanType = WMAC_SCAN_ACTIVE;
-        if(pDevice->bWPASuppWextEnabled !=true)
-        #endif
-           bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
-           bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
-           spin_unlock_irq(&pDevice->lock);
-      }
-      pDevice->bCommit = false;
-    }
-
-    return rc;
-}
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
 
+       }
+
+       if (pDevice->bCommit) {
+               if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
+                       netif_stop_queue(pDevice->dev);
+                       spin_lock_irq(&pDevice->lock);
+                       bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
+                       spin_unlock_irq(&pDevice->lock);
+               } else {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
+                       spin_lock_irq(&pDevice->lock);
+                       pDevice->bLinkPass = false;
+                       memset(pMgmt->abyCurrBSSID, 0, 6);
+                       pMgmt->eCurrState = WMAC_STATE_IDLE;
+                       netif_stop_queue(pDevice->dev);
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+                       pMgmt->eScanType = WMAC_SCAN_ACTIVE;
+                       if (pDevice->bWPASuppWextEnabled != true)
+#endif
+                               bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
+                       bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
+                       spin_unlock_irq(&pDevice->lock);
+               }
+               pDevice->bCommit = false;
+       }
+
+       return rc;
+}
 
 static int ethtool_ioctl(struct net_device *dev, void *useraddr)
 {
@@ -3530,7 +3292,7 @@ static int ethtool_ioctl(struct net_device *dev, void *useraddr)
        if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
                return -EFAULT;
 
-        switch (ethcmd) {
+       switch (ethcmd) {
        case ETHTOOL_GDRVINFO: {
                struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
                strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
@@ -3540,7 +3302,7 @@ static int ethtool_ioctl(struct net_device *dev, void *useraddr)
                return 0;
        }
 
-        }
+       }
 
        return -EOPNOTSUPP;
 }
@@ -3562,122 +3324,111 @@ static struct pci_driver device_driver = {
 
 static int __init vt6655_init_module(void)
 {
-    int ret;
-
+       int ret;
 
 //    ret=pci_module_init(&device_driver);
        //ret = pcie_port_service_register(&device_driver);
        ret = pci_register_driver(&device_driver);
 #ifdef CONFIG_PM
-    if(ret >= 0)
-        register_reboot_notifier(&device_notifier);
+       if (ret >= 0)
+               register_reboot_notifier(&device_notifier);
 #endif
 
-    return ret;
+       return ret;
 }
 
 static void __exit vt6655_cleanup_module(void)
 {
-
-
 #ifdef CONFIG_PM
-    unregister_reboot_notifier(&device_notifier);
+       unregister_reboot_notifier(&device_notifier);
 #endif
-    pci_unregister_driver(&device_driver);
-
+       pci_unregister_driver(&device_driver);
 }
 
 module_init(vt6655_init_module);
 module_exit(vt6655_cleanup_module);
 
-
 #ifdef CONFIG_PM
 static int
 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
 {
-    struct pci_dev *pdev = NULL;
-    switch(event) {
-    case SYS_DOWN:
-    case SYS_HALT:
-    case SYS_POWER_OFF:
-       for_each_pci_dev(pdev) {
-            if(pci_dev_driver(pdev) == &device_driver) {
-                if (pci_get_drvdata(pdev))
-                    viawget_suspend(pdev, PMSG_HIBERNATE);
-            }
-        }
-    }
-    return NOTIFY_DONE;
+       struct pci_dev *pdev = NULL;
+       switch (event) {
+       case SYS_DOWN:
+       case SYS_HALT:
+       case SYS_POWER_OFF:
+               for_each_pci_dev(pdev) {
+                       if (pci_dev_driver(pdev) == &device_driver) {
+                               if (pci_get_drvdata(pdev))
+                                       viawget_suspend(pdev, PMSG_HIBERNATE);
+                       }
+               }
+       }
+       return NOTIFY_DONE;
 }
 
 static int
 viawget_suspend(struct pci_dev *pcid, pm_message_t state)
 {
-    int power_status;   // to silence the compiler
-
-    PSDevice pDevice=pci_get_drvdata(pcid);
-    PSMgmtObject  pMgmt = pDevice->pMgmt;
-
-    netif_stop_queue(pDevice->dev);
-    spin_lock_irq(&pDevice->lock);
-    pci_save_state(pcid);
-    del_timer(&pDevice->sTimerCommand);
-    del_timer(&pMgmt->sTimerSecondCallback);
-    pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
-    pDevice->uCmdDequeueIdx = 0;
-    pDevice->uCmdEnqueueIdx = 0;
-    pDevice->bCmdRunning = false;
-    MACbShutdown(pDevice->PortOffset);
-    MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
-    pDevice->bLinkPass = false;
-    memset(pMgmt->abyCurrBSSID, 0, 6);
-    pMgmt->eCurrState = WMAC_STATE_IDLE;
-    pci_disable_device(pcid);
-    power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
-    spin_unlock_irq(&pDevice->lock);
-    return 0;
+       int power_status;   // to silence the compiler
+
+       PSDevice pDevice = pci_get_drvdata(pcid);
+       PSMgmtObject  pMgmt = pDevice->pMgmt;
+
+       netif_stop_queue(pDevice->dev);
+       spin_lock_irq(&pDevice->lock);
+       pci_save_state(pcid);
+       del_timer(&pDevice->sTimerCommand);
+       del_timer(&pMgmt->sTimerSecondCallback);
+       pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
+       pDevice->uCmdDequeueIdx = 0;
+       pDevice->uCmdEnqueueIdx = 0;
+       pDevice->bCmdRunning = false;
+       MACbShutdown(pDevice->PortOffset);
+       MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
+       pDevice->bLinkPass = false;
+       memset(pMgmt->abyCurrBSSID, 0, 6);
+       pMgmt->eCurrState = WMAC_STATE_IDLE;
+       pci_disable_device(pcid);
+       power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
+       spin_unlock_irq(&pDevice->lock);
+       return 0;
 }
 
 static int
 viawget_resume(struct pci_dev *pcid)
 {
-    PSDevice  pDevice=pci_get_drvdata(pcid);
-    PSMgmtObject  pMgmt = pDevice->pMgmt;
-    int power_status;   // to silence the compiler
-
-
-    power_status = pci_set_power_state(pcid, 0);
-    power_status = pci_enable_wake(pcid, 0, 0);
-    pci_restore_state(pcid);
-    if (netif_running(pDevice->dev)) {
-        spin_lock_irq(&pDevice->lock);
-        MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
-        device_init_registers(pDevice, DEVICE_INIT_DXPL);
-        if (pMgmt->sNodeDBTable[0].bActive == true) { // Assoc with BSS
-            pMgmt->sNodeDBTable[0].bActive = false;
-            pDevice->bLinkPass = false;
-            if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-                // In Adhoc, BSS state set back to started.
-                pMgmt->eCurrState = WMAC_STATE_STARTED;
-           }
-            else {
-                pMgmt->eCurrMode = WMAC_MODE_STANDBY;
-                pMgmt->eCurrState = WMAC_STATE_IDLE;
-            }
-        }
-        init_timer(&pMgmt->sTimerSecondCallback);
-        init_timer(&pDevice->sTimerCommand);
-        MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
-        BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
-        bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
-        bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
-        spin_unlock_irq(&pDevice->lock);
-    }
-    return 0;
+       PSDevice  pDevice = pci_get_drvdata(pcid);
+       PSMgmtObject  pMgmt = pDevice->pMgmt;
+       int power_status;   // to silence the compiler
+
+       power_status = pci_set_power_state(pcid, 0);
+       power_status = pci_enable_wake(pcid, 0, 0);
+       pci_restore_state(pcid);
+       if (netif_running(pDevice->dev)) {
+               spin_lock_irq(&pDevice->lock);
+               MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
+               device_init_registers(pDevice, DEVICE_INIT_DXPL);
+               if (pMgmt->sNodeDBTable[0].bActive == true) { // Assoc with BSS
+                       pMgmt->sNodeDBTable[0].bActive = false;
+                       pDevice->bLinkPass = false;
+                       if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+                               // In Adhoc, BSS state set back to started.
+                               pMgmt->eCurrState = WMAC_STATE_STARTED;
+                       } else {
+                               pMgmt->eCurrMode = WMAC_MODE_STANDBY;
+                               pMgmt->eCurrState = WMAC_STATE_IDLE;
+                       }
+               }
+               init_timer(&pMgmt->sTimerSecondCallback);
+               init_timer(&pDevice->sTimerCommand);
+               MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
+               BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
+               bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
+               bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
+               spin_unlock_irq(&pDevice->lock);
+       }
+       return 0;
 }
 
 #endif
-
-
-
-
index 373e9e4fc87deee821e54e091b70a456ae16f9bc..a9533f3f25299cc77e9158712d218347dada3cb3 100644 (file)
 #include "iowpa.h"
 #include "aes_ccmp.h"
 
-
-
 /*---------------------  Static Definitions -------------------------*/
 
 /*---------------------  Static Classes  ----------------------------*/
 
 /*---------------------  Static Variables  --------------------------*/
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 
 const unsigned char acbyRxRate[MAX_RATE] =
 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
 
-
 /*---------------------  Static Functions  --------------------------*/
 
 /*---------------------  Static Definitions -------------------------*/
@@ -77,60 +74,56 @@ const unsigned char acbyRxRate[MAX_RATE] =
 
 static unsigned char s_byGetRateIdx(unsigned char byRate);
 
-
 static void
 s_vGetDASA(unsigned char *pbyRxBufferAddr, unsigned int *pcbHeaderSize,
-               PSEthernetHeader psEthHeader);
+          PSEthernetHeader psEthHeader);
 
 static void
 s_vProcessRxMACHeader(PSDevice pDevice, unsigned char *pbyRxBufferAddr,
-               unsigned int cbPacketSize, bool bIsWEP, bool bExtIV,
-               unsigned int *pcbHeadSize);
+                     unsigned int cbPacketSize, bool bIsWEP, bool bExtIV,
+                     unsigned int *pcbHeadSize);
 
 static bool s_bAPModeRxCtl(
-    PSDevice pDevice,
-    unsigned char *pbyFrame,
-    int      iSANodeIndex
-    );
-
-
-
-static bool s_bAPModeRxData (
-    PSDevice pDevice,
-    struct sk_buff* skb,
-    unsigned int FrameSize,
-    unsigned int cbHeaderOffset,
-    int      iSANodeIndex,
-    int      iDANodeIndex
-    );
-
+       PSDevice pDevice,
+       unsigned char *pbyFrame,
+       int      iSANodeIndex
+);
+
+static bool s_bAPModeRxData(
+       PSDevice pDevice,
+       struct sk_buff *skb,
+       unsigned int FrameSize,
+       unsigned int cbHeaderOffset,
+       int      iSANodeIndex,
+       int      iDANodeIndex
+);
 
 static bool s_bHandleRxEncryption(
-    PSDevice     pDevice,
-    unsigned char *pbyFrame,
-    unsigned int FrameSize,
-    unsigned char *pbyRsr,
-    unsigned char *pbyNewRsr,
-    PSKeyItem   *pKeyOut,
-    bool *pbExtIV,
-    unsigned short *pwRxTSC15_0,
-    unsigned long *pdwRxTSC47_16
-    );
+       PSDevice     pDevice,
+       unsigned char *pbyFrame,
+       unsigned int FrameSize,
+       unsigned char *pbyRsr,
+       unsigned char *pbyNewRsr,
+       PSKeyItem   *pKeyOut,
+       bool *pbExtIV,
+       unsigned short *pwRxTSC15_0,
+       unsigned long *pdwRxTSC47_16
+);
 
 static bool s_bHostWepRxEncryption(
 
-    PSDevice     pDevice,
-    unsigned char *pbyFrame,
-    unsigned int FrameSize,
-    unsigned char *pbyRsr,
-    bool bOnFly,
-    PSKeyItem    pKey,
-    unsigned char *pbyNewRsr,
-    bool *pbExtIV,
-    unsigned short *pwRxTSC15_0,
-    unsigned long *pdwRxTSC47_16
+       PSDevice     pDevice,
+       unsigned char *pbyFrame,
+       unsigned int FrameSize,
+       unsigned char *pbyRsr,
+       bool bOnFly,
+       PSKeyItem    pKey,
+       unsigned char *pbyNewRsr,
+       bool *pbExtIV,
+       unsigned short *pwRxTSC15_0,
+       unsigned long *pdwRxTSC47_16
 
-    );
+);
 
 /*---------------------  Export Variables  --------------------------*/
 
@@ -150,694 +143,647 @@ static bool s_bHostWepRxEncryption(
  *
  * Return Value: None
  *
--*/
+ -*/
 static void
 s_vProcessRxMACHeader(PSDevice pDevice, unsigned char *pbyRxBufferAddr,
-               unsigned int cbPacketSize, bool bIsWEP, bool bExtIV,
-               unsigned int *pcbHeadSize)
+                     unsigned int cbPacketSize, bool bIsWEP, bool bExtIV,
+                     unsigned int *pcbHeadSize)
 {
-    unsigned char *pbyRxBuffer;
-    unsigned int cbHeaderSize = 0;
-    unsigned short *pwType;
-    PS802_11Header  pMACHeader;
-    int             ii;
-
-
-    pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
-
-    s_vGetDASA((unsigned char *)pMACHeader, &cbHeaderSize, &pDevice->sRxEthHeader);
-
-    if (bIsWEP) {
-        if (bExtIV) {
-            // strip IV&ExtIV , add 8 byte
-            cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 8);
-        } else {
-            // strip IV , add 4 byte
-            cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 4);
-        }
-    }
-    else {
-        cbHeaderSize += WLAN_HDR_ADDR3_LEN;
-    };
-
-    pbyRxBuffer = (unsigned char *) (pbyRxBufferAddr + cbHeaderSize);
-    if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_Bridgetunnel[0])) {
-        cbHeaderSize += 6;
-    }
-    else if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_RFC1042[0])) {
-        cbHeaderSize += 6;
-        pwType = (unsigned short *) (pbyRxBufferAddr + cbHeaderSize);
-        if ((*pwType!= TYPE_PKT_IPX) && (*pwType != cpu_to_le16(0xF380))) {
-        }
-        else {
-            cbHeaderSize -= 8;
-            pwType = (unsigned short *) (pbyRxBufferAddr + cbHeaderSize);
-            if (bIsWEP) {
-                if (bExtIV) {
-                    *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8);    // 8 is IV&ExtIV
-                } else {
-                    *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4);    // 4 is IV
-                }
-            }
-            else {
-                *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
-            }
-        }
-    }
-    else {
-        cbHeaderSize -= 2;
-        pwType = (unsigned short *) (pbyRxBufferAddr + cbHeaderSize);
-        if (bIsWEP) {
-            if (bExtIV) {
-                *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8);    // 8 is IV&ExtIV
-            } else {
-                *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4);    // 4 is IV
-            }
-        }
-        else {
-            *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
-        }
-    }
-
-    cbHeaderSize -= (ETH_ALEN * 2);
-    pbyRxBuffer = (unsigned char *) (pbyRxBufferAddr + cbHeaderSize);
-    for(ii=0;ii<ETH_ALEN;ii++)
-        *pbyRxBuffer++ = pDevice->sRxEthHeader.abyDstAddr[ii];
-    for(ii=0;ii<ETH_ALEN;ii++)
-        *pbyRxBuffer++ = pDevice->sRxEthHeader.abySrcAddr[ii];
-
-    *pcbHeadSize = cbHeaderSize;
-}
-
+       unsigned char *pbyRxBuffer;
+       unsigned int cbHeaderSize = 0;
+       unsigned short *pwType;
+       PS802_11Header  pMACHeader;
+       int             ii;
+
+       pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
+
+       s_vGetDASA((unsigned char *)pMACHeader, &cbHeaderSize, &pDevice->sRxEthHeader);
+
+       if (bIsWEP) {
+               if (bExtIV) {
+                       // strip IV&ExtIV , add 8 byte
+                       cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 8);
+               } else {
+                       // strip IV , add 4 byte
+                       cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 4);
+               }
+       } else {
+               cbHeaderSize += WLAN_HDR_ADDR3_LEN;
+       };
+
+       pbyRxBuffer = (unsigned char *)(pbyRxBufferAddr + cbHeaderSize);
+       if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_Bridgetunnel[0])) {
+               cbHeaderSize += 6;
+       } else if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_RFC1042[0])) {
+               cbHeaderSize += 6;
+               pwType = (unsigned short *)(pbyRxBufferAddr + cbHeaderSize);
+               if ((*pwType != TYPE_PKT_IPX) && (*pwType != cpu_to_le16(0xF380))) {
+               } else {
+                       cbHeaderSize -= 8;
+                       pwType = (unsigned short *)(pbyRxBufferAddr + cbHeaderSize);
+                       if (bIsWEP) {
+                               if (bExtIV) {
+                                       *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8);    // 8 is IV&ExtIV
+                               } else {
+                                       *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4);    // 4 is IV
+                               }
+                       } else {
+                               *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
+                       }
+               }
+       } else {
+               cbHeaderSize -= 2;
+               pwType = (unsigned short *)(pbyRxBufferAddr + cbHeaderSize);
+               if (bIsWEP) {
+                       if (bExtIV) {
+                               *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8);    // 8 is IV&ExtIV
+                       } else {
+                               *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4);    // 4 is IV
+                       }
+               } else {
+                       *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
+               }
+       }
 
+       cbHeaderSize -= (ETH_ALEN * 2);
+       pbyRxBuffer = (unsigned char *)(pbyRxBufferAddr + cbHeaderSize);
+       for (ii = 0; ii < ETH_ALEN; ii++)
+               *pbyRxBuffer++ = pDevice->sRxEthHeader.abyDstAddr[ii];
+       for (ii = 0; ii < ETH_ALEN; ii++)
+               *pbyRxBuffer++ = pDevice->sRxEthHeader.abySrcAddr[ii];
 
+       *pcbHeadSize = cbHeaderSize;
+}
 
-static unsigned char s_byGetRateIdx (unsigned char byRate)
+static unsigned char s_byGetRateIdx(unsigned char byRate)
 {
-    unsigned char byRateIdx;
+       unsigned char byRateIdx;
 
-    for (byRateIdx = 0; byRateIdx <MAX_RATE ; byRateIdx++) {
-        if (acbyRxRate[byRateIdx%MAX_RATE] == byRate)
-            return byRateIdx;
-    }
-    return 0;
+       for (byRateIdx = 0; byRateIdx < MAX_RATE; byRateIdx++) {
+               if (acbyRxRate[byRateIdx % MAX_RATE] == byRate)
+                       return byRateIdx;
+       }
+       return 0;
 }
 
-
 static void
 s_vGetDASA(unsigned char *pbyRxBufferAddr, unsigned int *pcbHeaderSize,
-       PSEthernetHeader psEthHeader)
+          PSEthernetHeader psEthHeader)
 {
-    unsigned int cbHeaderSize = 0;
-    PS802_11Header  pMACHeader;
-    int             ii;
-
-    pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
-
-    if ((pMACHeader->wFrameCtl & FC_TODS) == 0) {
-        if (pMACHeader->wFrameCtl & FC_FROMDS) {
-            for(ii=0;ii<ETH_ALEN;ii++) {
-                psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr1[ii];
-                psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr3[ii];
-            }
-        }
-        else {
-            // IBSS mode
-            for(ii=0;ii<ETH_ALEN;ii++) {
-                psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr1[ii];
-                psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr2[ii];
-            }
-        }
-    }
-    else {
-        // Is AP mode..
-        if (pMACHeader->wFrameCtl & FC_FROMDS) {
-            for(ii=0;ii<ETH_ALEN;ii++) {
-                psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr3[ii];
-                psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr4[ii];
-                cbHeaderSize += 6;
-            }
-        }
-        else {
-            for(ii=0;ii<ETH_ALEN;ii++) {
-                psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr3[ii];
-                psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr2[ii];
-            }
-        }
-    };
-    *pcbHeaderSize = cbHeaderSize;
+       unsigned int cbHeaderSize = 0;
+       PS802_11Header  pMACHeader;
+       int             ii;
+
+       pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
+
+       if ((pMACHeader->wFrameCtl & FC_TODS) == 0) {
+               if (pMACHeader->wFrameCtl & FC_FROMDS) {
+                       for (ii = 0; ii < ETH_ALEN; ii++) {
+                               psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr1[ii];
+                               psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr3[ii];
+                       }
+               } else {
+                       // IBSS mode
+                       for (ii = 0; ii < ETH_ALEN; ii++) {
+                               psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr1[ii];
+                               psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr2[ii];
+                       }
+               }
+       } else {
+               // Is AP mode..
+               if (pMACHeader->wFrameCtl & FC_FROMDS) {
+                       for (ii = 0; ii < ETH_ALEN; ii++) {
+                               psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr3[ii];
+                               psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr4[ii];
+                               cbHeaderSize += 6;
+                       }
+               } else {
+                       for (ii = 0; ii < ETH_ALEN; ii++) {
+                               psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr3[ii];
+                               psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr2[ii];
+                       }
+               }
+       };
+       *pcbHeaderSize = cbHeaderSize;
 }
 
-
-
-
 //PLICE_DEBUG ->
 
 void   MngWorkItem(void *Context)
 {
        PSRxMgmtPacket                  pRxMgmtPacket;
        PSDevice        pDevice =  (PSDevice) Context;
-       //printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
+
        spin_lock_irq(&pDevice->lock);
-        while(pDevice->rxManeQueue.packet_num != 0)
-        {
-                pRxMgmtPacket =  DeQueue(pDevice);
-                       vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
+       while (pDevice->rxManeQueue.packet_num != 0) {
+               pRxMgmtPacket =  DeQueue(pDevice);
+               vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
        }
        spin_unlock_irq(&pDevice->lock);
 }
 
-
 //PLICE_DEBUG<-
 
-
-
 bool
-device_receive_frame (
-    PSDevice pDevice,
-    PSRxDesc pCurrRD
-    )
+device_receive_frame(
+       PSDevice pDevice,
+       PSRxDesc pCurrRD
+)
 {
-
-    PDEVICE_RD_INFO  pRDInfo = pCurrRD->pRDInfo;
-#ifdef PLICE_DEBUG
-       //printk("device_receive_frame:pCurrRD is %x,pRDInfo is %x\n",pCurrRD,pCurrRD->pRDInfo);
-#endif
-    struct net_device_stats* pStats=&pDevice->stats;
-    struct sk_buff* skb;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    PSRxMgmtPacket  pRxPacket = &(pDevice->pMgmt->sRxPacket);
-    PS802_11Header  p802_11Header;
-    unsigned char *pbyRsr;
-    unsigned char *pbyNewRsr;
-    unsigned char *pbyRSSI;
-    PQWORD          pqwTSFTime;
-    unsigned short *pwFrameSize;
-    unsigned char *pbyFrame;
-    bool bDeFragRx = false;
-    bool bIsWEP = false;
-    unsigned int cbHeaderOffset;
-    unsigned int FrameSize;
-    unsigned short wEtherType = 0;
-    int             iSANodeIndex = -1;
-    int             iDANodeIndex = -1;
-    unsigned int ii;
-    unsigned int cbIVOffset;
-    bool bExtIV = false;
-    unsigned char *pbyRxSts;
-    unsigned char *pbyRxRate;
-    unsigned char *pbySQ;
-    unsigned int cbHeaderSize;
-    PSKeyItem       pKey = NULL;
-    unsigned short wRxTSC15_0 = 0;
-    unsigned long dwRxTSC47_16 = 0;
-    SKeyItem        STempKey;
-    // 802.11h RPI
-    unsigned long dwDuration = 0;
-    long            ldBm = 0;
-    long            ldBmThreshold = 0;
-    PS802_11Header pMACHeader;
- bool bRxeapol_key = false;
-
-//    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- device_receive_frame---\n");
-
-    skb = pRDInfo->skb;
-
+       PDEVICE_RD_INFO  pRDInfo = pCurrRD->pRDInfo;
+       struct net_device_stats *pStats = &pDevice->stats;
+       struct sk_buff *skb;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSRxMgmtPacket  pRxPacket = &(pDevice->pMgmt->sRxPacket);
+       PS802_11Header  p802_11Header;
+       unsigned char *pbyRsr;
+       unsigned char *pbyNewRsr;
+       unsigned char *pbyRSSI;
+       PQWORD          pqwTSFTime;
+       unsigned short *pwFrameSize;
+       unsigned char *pbyFrame;
+       bool bDeFragRx = false;
+       bool bIsWEP = false;
+       unsigned int cbHeaderOffset;
+       unsigned int FrameSize;
+       unsigned short wEtherType = 0;
+       int             iSANodeIndex = -1;
+       int             iDANodeIndex = -1;
+       unsigned int ii;
+       unsigned int cbIVOffset;
+       bool bExtIV = false;
+       unsigned char *pbyRxSts;
+       unsigned char *pbyRxRate;
+       unsigned char *pbySQ;
+       unsigned int cbHeaderSize;
+       PSKeyItem       pKey = NULL;
+       unsigned short wRxTSC15_0 = 0;
+       unsigned long dwRxTSC47_16 = 0;
+       SKeyItem        STempKey;
+       // 802.11h RPI
+       unsigned long dwDuration = 0;
+       long            ldBm = 0;
+       long            ldBmThreshold = 0;
+       PS802_11Header pMACHeader;
+       bool bRxeapol_key = false;
+
+//    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- device_receive_frame---\n");
+
+       skb = pRDInfo->skb;
 
 //PLICE_DEBUG->
 #if 1
        pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
-                     pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
+                        pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
 #endif
 //PLICE_DEBUG<-
-    pwFrameSize = (unsigned short *)(skb->data + 2);
-    FrameSize = cpu_to_le16(pCurrRD->m_rd1RD1.wReqCount) - cpu_to_le16(pCurrRD->m_rd0RD0.wResCount);
-
-    // Max: 2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
-    // Min (ACK): 10HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
-    if ((FrameSize > 2364)||(FrameSize <= 32)) {
-        // Frame Size error drop this packet.
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- WRONG Length 1 \n");
-        return false;
-    }
-
-    pbyRxSts = (unsigned char *) (skb->data);
-    pbyRxRate = (unsigned char *) (skb->data + 1);
-    pbyRsr = (unsigned char *) (skb->data + FrameSize - 1);
-    pbyRSSI = (unsigned char *) (skb->data + FrameSize - 2);
-    pbyNewRsr = (unsigned char *) (skb->data + FrameSize - 3);
-    pbySQ = (unsigned char *) (skb->data + FrameSize - 4);
-    pqwTSFTime = (PQWORD) (skb->data + FrameSize - 12);
-    pbyFrame = (unsigned char *)(skb->data + 4);
-
-    // get packet size
-    FrameSize = cpu_to_le16(*pwFrameSize);
-
-    if ((FrameSize > 2346)|(FrameSize < 14)) { // Max: 2312Payload + 30HD +4CRC
-                                               // Min: 14 bytes ACK
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- WRONG Length 2 \n");
-        return false;
-    }
+       pwFrameSize = (unsigned short *)(skb->data + 2);
+       FrameSize = cpu_to_le16(pCurrRD->m_rd1RD1.wReqCount) - cpu_to_le16(pCurrRD->m_rd0RD0.wResCount);
+
+       // Max: 2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
+       // Min (ACK): 10HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
+       if ((FrameSize > 2364) || (FrameSize <= 32)) {
+               // Frame Size error drop this packet.
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 1 \n");
+               return false;
+       }
+
+       pbyRxSts = (unsigned char *)(skb->data);
+       pbyRxRate = (unsigned char *)(skb->data + 1);
+       pbyRsr = (unsigned char *)(skb->data + FrameSize - 1);
+       pbyRSSI = (unsigned char *)(skb->data + FrameSize - 2);
+       pbyNewRsr = (unsigned char *)(skb->data + FrameSize - 3);
+       pbySQ = (unsigned char *)(skb->data + FrameSize - 4);
+       pqwTSFTime = (PQWORD)(skb->data + FrameSize - 12);
+       pbyFrame = (unsigned char *)(skb->data + 4);
+
+       // get packet size
+       FrameSize = cpu_to_le16(*pwFrameSize);
+
+       if ((FrameSize > 2346)|(FrameSize < 14)) { // Max: 2312Payload + 30HD +4CRC
+               // Min: 14 bytes ACK
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 2 \n");
+               return false;
+       }
 //PLICE_DEBUG->
 #if 1
        // update receive statistic counter
-    STAvUpdateRDStatCounter(&pDevice->scStatistic,
-                            *pbyRsr,
-                            *pbyNewRsr,
-                            *pbyRxRate,
-                            pbyFrame,
-                            FrameSize);
+       STAvUpdateRDStatCounter(&pDevice->scStatistic,
+                               *pbyRsr,
+                               *pbyNewRsr,
+                               *pbyRxRate,
+                               pbyFrame,
+                               FrameSize);
 
 #endif
 
-  pMACHeader=(PS802_11Header)((unsigned char *) (skb->data)+8);
+       pMACHeader = (PS802_11Header)((unsigned char *)(skb->data) + 8);
 //PLICE_DEBUG<-
        if (pDevice->bMeasureInProgress == true) {
-        if ((*pbyRsr & RSR_CRCOK) != 0) {
-            pDevice->byBasicMap |= 0x01;
-        }
-        dwDuration = (FrameSize << 4);
-        dwDuration /= acbyRxRate[*pbyRxRate%MAX_RATE];
-        if (*pbyRxRate <= RATE_11M) {
-            if (*pbyRxSts & 0x01) {
-                // long preamble
-                dwDuration += 192;
-            } else {
-                // short preamble
-                dwDuration += 96;
-            }
-        } else {
-            dwDuration += 16;
-        }
-        RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
-        ldBmThreshold = -57;
-        for (ii = 7; ii > 0;) {
-            if (ldBm > ldBmThreshold) {
-                break;
-            }
-            ldBmThreshold -= 5;
-            ii--;
-        }
-        pDevice->dwRPIs[ii] += dwDuration;
-        return false;
-    }
-
-    if (!is_multicast_ether_addr(pbyFrame)) {
-        if (WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header) (skb->data + 4))) {
-            pDevice->s802_11Counter.FrameDuplicateCount++;
-            return false;
-        }
-    }
-
-
-    // Use for TKIP MIC
-    s_vGetDASA(skb->data+4, &cbHeaderSize, &pDevice->sRxEthHeader);
-
-    // filter packet send from myself
-    if (!compare_ether_addr((unsigned char *)&(pDevice->sRxEthHeader.abySrcAddr[0]), pDevice->abyCurrentNetAddr))
-        return false;
-
-    if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
-        if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
-            p802_11Header = (PS802_11Header) (pbyFrame);
-            // get SA NodeIndex
-            if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(p802_11Header->abyAddr2), &iSANodeIndex)) {
-                pMgmt->sNodeDBTable[iSANodeIndex].ulLastRxJiffer = jiffies;
-                pMgmt->sNodeDBTable[iSANodeIndex].uInActiveCount = 0;
-            }
-        }
-    }
-
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-        if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex) == true) {
-            return false;
-        }
-    }
-
-
-    if (IS_FC_WEP(pbyFrame)) {
-        bool bRxDecryOK = false;
-
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rx WEP pkt\n");
-        bIsWEP = true;
-        if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) {
-            pKey = &STempKey;
-            pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite;
-            pKey->dwKeyIndex = pMgmt->sNodeDBTable[iSANodeIndex].dwKeyIndex;
-            pKey->uKeyLength = pMgmt->sNodeDBTable[iSANodeIndex].uWepKeyLength;
-            pKey->dwTSC47_16 = pMgmt->sNodeDBTable[iSANodeIndex].dwTSC47_16;
-            pKey->wTSC15_0 = pMgmt->sNodeDBTable[iSANodeIndex].wTSC15_0;
-            memcpy(pKey->abyKey,
-                &pMgmt->sNodeDBTable[iSANodeIndex].abyWepKey[0],
-                pKey->uKeyLength
-                );
-
-            bRxDecryOK = s_bHostWepRxEncryption(pDevice,
-                                                pbyFrame,
-                                                FrameSize,
-                                                pbyRsr,
-                                                pMgmt->sNodeDBTable[iSANodeIndex].bOnFly,
-                                                pKey,
-                                                pbyNewRsr,
-                                                &bExtIV,
-                                                &wRxTSC15_0,
-                                                &dwRxTSC47_16);
-        } else {
-            bRxDecryOK = s_bHandleRxEncryption(pDevice,
-                                                pbyFrame,
-                                                FrameSize,
-                                                pbyRsr,
-                                                pbyNewRsr,
-                                                &pKey,
-                                                &bExtIV,
-                                                &wRxTSC15_0,
-                                                &dwRxTSC47_16);
-        }
-
-        if (bRxDecryOK) {
-            if ((*pbyNewRsr & NEWRSR_DECRYPTOK) == 0) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV Fail\n");
-                if ( (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
-                    (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
-                    (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
-                    (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
-                    (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
-
-                    if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
-                        pDevice->s802_11Counter.TKIPICVErrors++;
-                    } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP)) {
-                        pDevice->s802_11Counter.CCMPDecryptErrors++;
-                    } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_WEP)) {
+               if ((*pbyRsr & RSR_CRCOK) != 0) {
+                       pDevice->byBasicMap |= 0x01;
+               }
+               dwDuration = (FrameSize << 4);
+               dwDuration /= acbyRxRate[*pbyRxRate%MAX_RATE];
+               if (*pbyRxRate <= RATE_11M) {
+                       if (*pbyRxSts & 0x01) {
+                               // long preamble
+                               dwDuration += 192;
+                       } else {
+                               // short preamble
+                               dwDuration += 96;
+                       }
+               } else {
+                       dwDuration += 16;
+               }
+               RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
+               ldBmThreshold = -57;
+               for (ii = 7; ii > 0;) {
+                       if (ldBm > ldBmThreshold) {
+                               break;
+                       }
+                       ldBmThreshold -= 5;
+                       ii--;
+               }
+               pDevice->dwRPIs[ii] += dwDuration;
+               return false;
+       }
+
+       if (!is_multicast_ether_addr(pbyFrame)) {
+               if (WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header)(skb->data + 4))) {
+                       pDevice->s802_11Counter.FrameDuplicateCount++;
+                       return false;
+               }
+       }
+
+       // Use for TKIP MIC
+       s_vGetDASA(skb->data+4, &cbHeaderSize, &pDevice->sRxEthHeader);
+
+       // filter packet send from myself
+       if (!compare_ether_addr((unsigned char *)&(pDevice->sRxEthHeader.abySrcAddr[0]), pDevice->abyCurrentNetAddr))
+               return false;
+
+       if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
+               if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
+                       p802_11Header = (PS802_11Header)(pbyFrame);
+                       // get SA NodeIndex
+                       if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(p802_11Header->abyAddr2), &iSANodeIndex)) {
+                               pMgmt->sNodeDBTable[iSANodeIndex].ulLastRxJiffer = jiffies;
+                               pMgmt->sNodeDBTable[iSANodeIndex].uInActiveCount = 0;
+                       }
+               }
+       }
+
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex) == true) {
+                       return false;
+               }
+       }
+
+       if (IS_FC_WEP(pbyFrame)) {
+               bool bRxDecryOK = false;
+
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx WEP pkt\n");
+               bIsWEP = true;
+               if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) {
+                       pKey = &STempKey;
+                       pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite;
+                       pKey->dwKeyIndex = pMgmt->sNodeDBTable[iSANodeIndex].dwKeyIndex;
+                       pKey->uKeyLength = pMgmt->sNodeDBTable[iSANodeIndex].uWepKeyLength;
+                       pKey->dwTSC47_16 = pMgmt->sNodeDBTable[iSANodeIndex].dwTSC47_16;
+                       pKey->wTSC15_0 = pMgmt->sNodeDBTable[iSANodeIndex].wTSC15_0;
+                       memcpy(pKey->abyKey,
+                              &pMgmt->sNodeDBTable[iSANodeIndex].abyWepKey[0],
+                              pKey->uKeyLength
+);
+
+                       bRxDecryOK = s_bHostWepRxEncryption(pDevice,
+                                                           pbyFrame,
+                                                           FrameSize,
+                                                           pbyRsr,
+                                                           pMgmt->sNodeDBTable[iSANodeIndex].bOnFly,
+                                                           pKey,
+                                                           pbyNewRsr,
+                                                           &bExtIV,
+                                                           &wRxTSC15_0,
+                                                           &dwRxTSC47_16);
+               } else {
+                       bRxDecryOK = s_bHandleRxEncryption(pDevice,
+                                                          pbyFrame,
+                                                          FrameSize,
+                                                          pbyRsr,
+                                                          pbyNewRsr,
+                                                          &pKey,
+                                                          &bExtIV,
+                                                          &wRxTSC15_0,
+                                                          &dwRxTSC47_16);
+               }
+
+               if (bRxDecryOK) {
+                       if ((*pbyNewRsr & NEWRSR_DECRYPTOK) == 0) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ICV Fail\n");
+                               if ((pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
+                                   (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
+                                   (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
+                                   (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
+                                   (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
+                                       if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
+                                               pDevice->s802_11Counter.TKIPICVErrors++;
+                                       } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP)) {
+                                               pDevice->s802_11Counter.CCMPDecryptErrors++;
+                                       } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_WEP)) {
 //                      pDevice->s802_11Counter.WEPICVErrorCount.QuadPart++;
-                    }
-                }
-                return false;
-            }
-        } else {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WEP Func Fail\n");
-            return false;
-        }
-        if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
-            FrameSize -= 8;         // Message Integrity Code
-        else
-            FrameSize -= 4;         // 4 is ICV
-    }
-
-
-    //
-    // RX OK
-    //
-    //remove the CRC length
-    FrameSize -= ETH_FCS_LEN;
-
-    if (( !(*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI))) && // unicast address
-        (IS_FRAGMENT_PKT((skb->data+4)))
-        ) {
-        // defragment
-        bDeFragRx = WCTLbHandleFragment(pDevice, (PS802_11Header) (skb->data+4), FrameSize, bIsWEP, bExtIV);
-        pDevice->s802_11Counter.ReceivedFragmentCount++;
-        if (bDeFragRx) {
-            // defrag complete
-            skb = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb;
-            FrameSize = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength;
-
-        }
-        else {
-            return false;
-        }
-    }
+                                       }
+                               }
+                               return false;
+                       }
+               } else {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WEP Func Fail\n");
+                       return false;
+               }
+               if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
+                       FrameSize -= 8;         // Message Integrity Code
+               else
+                       FrameSize -= 4;         // 4 is ICV
+       }
 
+       //
+       // RX OK
+       //
+       //remove the CRC length
+       FrameSize -= ETH_FCS_LEN;
+
+       if ((!(*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI))) && // unicast address
+           (IS_FRAGMENT_PKT((skb->data+4)))
+) {
+               // defragment
+               bDeFragRx = WCTLbHandleFragment(pDevice, (PS802_11Header)(skb->data+4), FrameSize, bIsWEP, bExtIV);
+               pDevice->s802_11Counter.ReceivedFragmentCount++;
+               if (bDeFragRx) {
+                       // defrag complete
+                       skb = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb;
+                       FrameSize = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength;
+
+               } else {
+                       return false;
+               }
+       }
 
 // Management & Control frame Handle
-    if ((IS_TYPE_DATA((skb->data+4))) == false) {
-        // Handle Control & Manage Frame
-
-        if (IS_TYPE_MGMT((skb->data+4))) {
-            unsigned char *pbyData1;
-            unsigned char *pbyData2;
-
-            pRxPacket->p80211Header = (PUWLAN_80211HDR)(skb->data+4);
-            pRxPacket->cbMPDULen = FrameSize;
-            pRxPacket->uRSSI = *pbyRSSI;
-            pRxPacket->bySQ = *pbySQ;
-            HIDWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(HIDWORD(*pqwTSFTime));
-            LODWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(LODWORD(*pqwTSFTime));
-            if (bIsWEP) {
-                // strip IV
-                pbyData1 = WLAN_HDR_A3_DATA_PTR(skb->data+4);
-                pbyData2 = WLAN_HDR_A3_DATA_PTR(skb->data+4) + 4;
-                for (ii = 0; ii < (FrameSize - 4); ii++) {
-                    *pbyData1 = *pbyData2;
-                     pbyData1++;
-                     pbyData2++;
-                }
-            }
-            pRxPacket->byRxRate = s_byGetRateIdx(*pbyRxRate);
-            pRxPacket->byRxChannel = (*pbyRxSts) >> 2;
+       if ((IS_TYPE_DATA((skb->data+4))) == false) {
+               // Handle Control & Manage Frame
+
+               if (IS_TYPE_MGMT((skb->data+4))) {
+                       unsigned char *pbyData1;
+                       unsigned char *pbyData2;
+
+                       pRxPacket->p80211Header = (PUWLAN_80211HDR)(skb->data+4);
+                       pRxPacket->cbMPDULen = FrameSize;
+                       pRxPacket->uRSSI = *pbyRSSI;
+                       pRxPacket->bySQ = *pbySQ;
+                       HIDWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(HIDWORD(*pqwTSFTime));
+                       LODWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(LODWORD(*pqwTSFTime));
+                       if (bIsWEP) {
+                               // strip IV
+                               pbyData1 = WLAN_HDR_A3_DATA_PTR(skb->data+4);
+                               pbyData2 = WLAN_HDR_A3_DATA_PTR(skb->data+4) + 4;
+                               for (ii = 0; ii < (FrameSize - 4); ii++) {
+                                       *pbyData1 = *pbyData2;
+                                       pbyData1++;
+                                       pbyData2++;
+                               }
+                       }
+                       pRxPacket->byRxRate = s_byGetRateIdx(*pbyRxRate);
+                       pRxPacket->byRxChannel = (*pbyRxSts) >> 2;
 //PLICE_DEBUG->
 //EnQueue(pDevice,pRxPacket);
 
 #ifdef THREAD
-               EnQueue(pDevice,pRxPacket);
+                       EnQueue(pDevice, pRxPacket);
 
-               //printk("enque time is %x\n",jiffies);
-               //up(&pDevice->mlme_semaphore);
+                       //up(&pDevice->mlme_semaphore);
                        //Enque (pDevice->FirstRecvMngList,pDevice->LastRecvMngList,pMgmt);
 #else
 
 #ifdef TASK_LET
-               EnQueue(pDevice,pRxPacket);
-               tasklet_schedule(&pDevice->RxMngWorkItem);
+                       EnQueue(pDevice, pRxPacket);
+                       tasklet_schedule(&pDevice->RxMngWorkItem);
 #else
-//printk("RxMan\n");
-       vMgrRxManagePacket((void *)pDevice, pDevice->pMgmt, pRxPacket);
-           //tasklet_schedule(&pDevice->RxMngWorkItem);
+                       vMgrRxManagePacket((void *)pDevice, pDevice->pMgmt, pRxPacket);
+                       //tasklet_schedule(&pDevice->RxMngWorkItem);
 #endif
 
 #endif
 //PLICE_DEBUG<-
                        //vMgrRxManagePacket((void *)pDevice, pDevice->pMgmt, pRxPacket);
-            // hostap Deamon handle 802.11 management
-            if (pDevice->bEnableHostapd) {
-                   skb->dev = pDevice->apdev;
-                   skb->data += 4;
-                   skb->tail += 4;
-                     skb_put(skb, FrameSize);
-               skb_reset_mac_header(skb);
-                   skb->pkt_type = PACKET_OTHERHOST;
-               skb->protocol = htons(ETH_P_802_2);
-                   memset(skb->cb, 0, sizeof(skb->cb));
-                   netif_rx(skb);
-                return true;
-               }
-        }
-        else {
-            // Control Frame
-        };
-        return false;
-    }
-    else {
-        if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-            //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
-            if ( !(*pbyRsr & RSR_BSSIDOK)) {
-                if (bDeFragRx) {
-                    if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
-                        DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
-                        pDevice->dev->name);
-                    }
-                }
-                return false;
-            }
-        }
-        else {
-            // discard DATA packet while not associate || BSSID error
-            if ((pDevice->bLinkPass == false) ||
-                !(*pbyRsr & RSR_BSSIDOK)) {
-                if (bDeFragRx) {
-                    if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
-                        DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
-                        pDevice->dev->name);
-                    }
-                }
-                return false;
-            }
-   //mike add:station mode check eapol-key challenge--->
-         {
-           unsigned char Protocol_Version;    //802.1x Authentication
-           unsigned char Packet_Type;           //802.1x Authentication
-              if (bIsWEP)
-                  cbIVOffset = 8;
-              else
-                  cbIVOffset = 0;
-              wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
-                          skb->data[cbIVOffset + 8 + 24 + 6 + 1];
-             Protocol_Version = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1];
-             Packet_Type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1];
-            if (wEtherType == ETH_P_PAE) {         //Protocol Type in LLC-Header
-                  if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
-                    (Packet_Type==3)) {  //802.1x OR eapol-key challenge frame receive
-                        bRxeapol_key = true;
-                  }
-             }
-         }
-    //mike add:station mode check eapol-key challenge<---
-        }
-    }
-
+                       // hostap Deamon handle 802.11 management
+                       if (pDevice->bEnableHostapd) {
+                               skb->dev = pDevice->apdev;
+                               skb->data += 4;
+                               skb->tail += 4;
+                               skb_put(skb, FrameSize);
+                               skb_reset_mac_header(skb);
+                               skb->pkt_type = PACKET_OTHERHOST;
+                               skb->protocol = htons(ETH_P_802_2);
+                               memset(skb->cb, 0, sizeof(skb->cb));
+                               netif_rx(skb);
+                               return true;
+                       }
+               } else {
+                       // Control Frame
+               };
+               return false;
+       } else {
+               if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+                       //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
+                       if (!(*pbyRsr & RSR_BSSIDOK)) {
+                               if (bDeFragRx) {
+                                       if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
+                                               DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
+                                                       pDevice->dev->name);
+                                       }
+                               }
+                               return false;
+                       }
+               } else {
+                       // discard DATA packet while not associate || BSSID error
+                       if ((pDevice->bLinkPass == false) ||
+                           !(*pbyRsr & RSR_BSSIDOK)) {
+                               if (bDeFragRx) {
+                                       if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
+                                               DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
+                                                       pDevice->dev->name);
+                                       }
+                               }
+                               return false;
+                       }
+                       //mike add:station mode check eapol-key challenge--->
+                       {
+                               unsigned char Protocol_Version;    //802.1x Authentication
+                               unsigned char Packet_Type;           //802.1x Authentication
+                               if (bIsWEP)
+                                       cbIVOffset = 8;
+                               else
+                                       cbIVOffset = 0;
+                               wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
+                                       skb->data[cbIVOffset + 8 + 24 + 6 + 1];
+                               Protocol_Version = skb->data[cbIVOffset + 8 + 24 + 6 + 1 + 1];
+                               Packet_Type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 + 1 + 1];
+                               if (wEtherType == ETH_P_PAE) {         //Protocol Type in LLC-Header
+                                       if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
+                                           (Packet_Type == 3)) {  //802.1x OR eapol-key challenge frame receive
+                                               bRxeapol_key = true;
+                                       }
+                               }
+                       }
+                       //mike add:station mode check eapol-key challenge<---
+               }
+       }
 
 // Data frame Handle
 
+       if (pDevice->bEnablePSMode) {
+               if (IS_FC_MOREDATA((skb->data+4))) {
+                       if (*pbyRsr & RSR_ADDROK) {
+                               //PSbSendPSPOLL((PSDevice)pDevice);
+                       }
+               } else {
+                       if (pDevice->pMgmt->bInTIMWake == true) {
+                               pDevice->pMgmt->bInTIMWake = false;
+                       }
+               }
+       }
 
-    if (pDevice->bEnablePSMode) {
-        if (IS_FC_MOREDATA((skb->data+4))) {
-            if (*pbyRsr & RSR_ADDROK) {
-                //PSbSendPSPOLL((PSDevice)pDevice);
-            }
-        }
-        else {
-            if (pDevice->pMgmt->bInTIMWake == true) {
-                pDevice->pMgmt->bInTIMWake = false;
-            }
-        }
-    }
-
-    // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
-    if (pDevice->bDiversityEnable && (FrameSize>50) &&
-        (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
-        (pDevice->bLinkPass == true)) {
-       //printk("device_receive_frame: RxRate is %d\n",*pbyRxRate);
+       // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
+       if (pDevice->bDiversityEnable && (FrameSize > 50) &&
+           (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
+           (pDevice->bLinkPass == true)) {
                BBvAntennaDiversity(pDevice, s_byGetRateIdx(*pbyRxRate), 0);
-    }
-
-
-    if (pDevice->byLocalID != REV_ID_VT3253_B1) {
-        pDevice->uCurrRSSI = *pbyRSSI;
-    }
-    pDevice->byCurrSQ = *pbySQ;
-
-    if ((*pbyRSSI != 0) &&
-        (pMgmt->pCurrBSS!=NULL)) {
-        RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
-        // Monitor if RSSI is too strong.
-        pMgmt->pCurrBSS->byRSSIStatCnt++;
-        pMgmt->pCurrBSS->byRSSIStatCnt %= RSSI_STAT_COUNT;
-        pMgmt->pCurrBSS->ldBmAverage[pMgmt->pCurrBSS->byRSSIStatCnt] = ldBm;
-        for(ii=0;ii<RSSI_STAT_COUNT;ii++) {
-            if (pMgmt->pCurrBSS->ldBmAverage[ii] != 0) {
-            pMgmt->pCurrBSS->ldBmMAX = max(pMgmt->pCurrBSS->ldBmAverage[ii], ldBm);
-            }
-        }
-    }
-
-    // -----------------------------------------------
-
-    if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == true)){
-        unsigned char abyMacHdr[24];
-
-        // Only 802.1x packet incoming allowed
-        if (bIsWEP)
-            cbIVOffset = 8;
-        else
-            cbIVOffset = 0;
-        wEtherType = (skb->data[cbIVOffset + 4 + 24 + 6] << 8) |
-                    skb->data[cbIVOffset + 4 + 24 + 6 + 1];
-
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wEtherType = %04x \n", wEtherType);
-        if (wEtherType == ETH_P_PAE) {
-            skb->dev = pDevice->apdev;
-
-            if (bIsWEP == true) {
-                // strip IV header(8)
-                memcpy(&abyMacHdr[0], (skb->data + 4), 24);
-                memcpy((skb->data + 4 + cbIVOffset), &abyMacHdr[0], 24);
-            }
-            skb->data +=  (cbIVOffset + 4);
-            skb->tail +=  (cbIVOffset + 4);
-            skb_put(skb, FrameSize);
-           skb_reset_mac_header(skb);
-
-       skb->pkt_type = PACKET_OTHERHOST;
-            skb->protocol = htons(ETH_P_802_2);
-            memset(skb->cb, 0, sizeof(skb->cb));
-            netif_rx(skb);
-            return true;
+       }
 
-}
-        // check if 802.1x authorized
-        if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED))
-            return false;
-    }
-
-
-    if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
-        if (bIsWEP) {
-            FrameSize -= 8;  //MIC
-        }
-    }
-
-    //--------------------------------------------------------------------------------
-    // Soft MIC
-    if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
-        if (bIsWEP) {
-            unsigned long *pdwMIC_L;
-            unsigned long *pdwMIC_R;
-            unsigned long dwMIC_Priority;
-            unsigned long dwMICKey0 = 0, dwMICKey1 = 0;
-            unsigned long dwLocalMIC_L = 0;
-            unsigned long dwLocalMIC_R = 0;
-            viawget_wpa_header *wpahdr;
-
-
-            if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-                dwMICKey0 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[24]));
-                dwMICKey1 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[28]));
-            }
-            else {
-                if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
-                    dwMICKey0 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[16]));
-                    dwMICKey1 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[20]));
-                } else if ((pKey->dwKeyIndex & BIT28) == 0) {
-                    dwMICKey0 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[16]));
-                    dwMICKey1 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[20]));
-                } else {
-                    dwMICKey0 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[24]));
-                    dwMICKey1 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[28]));
-                }
-            }
-
-            MIC_vInit(dwMICKey0, dwMICKey1);
-            MIC_vAppend((unsigned char *)&(pDevice->sRxEthHeader.abyDstAddr[0]), 12);
-            dwMIC_Priority = 0;
-            MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
-            // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
-            MIC_vAppend((unsigned char *)(skb->data + 4 + WLAN_HDR_ADDR3_LEN + 8),
-                        FrameSize - WLAN_HDR_ADDR3_LEN - 8);
-            MIC_vGetMIC(&dwLocalMIC_L, &dwLocalMIC_R);
-            MIC_vUnInit();
-
-            pdwMIC_L = (unsigned long *)(skb->data + 4 + FrameSize);
-            pdwMIC_R = (unsigned long *)(skb->data + 4 + FrameSize + 4);
-            //DBG_PRN_GRP12(("RxL: %lx, RxR: %lx\n", *pdwMIC_L, *pdwMIC_R));
-            //DBG_PRN_GRP12(("LocalL: %lx, LocalR: %lx\n", dwLocalMIC_L, dwLocalMIC_R));
-            //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwMICKey0= %lx,dwMICKey1= %lx \n", dwMICKey0, dwMICKey1);
-
-
-            if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) ||
-                (pDevice->bRxMICFail == true)) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC comparison is fail!\n");
-                pDevice->bRxMICFail = false;
-                //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++;
-                pDevice->s802_11Counter.TKIPLocalMICFailures++;
-                if (bDeFragRx) {
-                    if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
-                        DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
-                            pDevice->dev->name);
-                    }
-                }
-               //2008-0409-07, <Add> by Einsn Liu
-       #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+       if (pDevice->byLocalID != REV_ID_VT3253_B1) {
+               pDevice->uCurrRSSI = *pbyRSSI;
+       }
+       pDevice->byCurrSQ = *pbySQ;
+
+       if ((*pbyRSSI != 0) &&
+           (pMgmt->pCurrBSS != NULL)) {
+               RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
+               // Monitor if RSSI is too strong.
+               pMgmt->pCurrBSS->byRSSIStatCnt++;
+               pMgmt->pCurrBSS->byRSSIStatCnt %= RSSI_STAT_COUNT;
+               pMgmt->pCurrBSS->ldBmAverage[pMgmt->pCurrBSS->byRSSIStatCnt] = ldBm;
+               for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
+                       if (pMgmt->pCurrBSS->ldBmAverage[ii] != 0) {
+                               pMgmt->pCurrBSS->ldBmMAX = max(pMgmt->pCurrBSS->ldBmAverage[ii], ldBm);
+                       }
+               }
+       }
+
+       // -----------------------------------------------
+
+       if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == true)) {
+               unsigned char abyMacHdr[24];
+
+               // Only 802.1x packet incoming allowed
+               if (bIsWEP)
+                       cbIVOffset = 8;
+               else
+                       cbIVOffset = 0;
+               wEtherType = (skb->data[cbIVOffset + 4 + 24 + 6] << 8) |
+                       skb->data[cbIVOffset + 4 + 24 + 6 + 1];
+
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wEtherType = %04x \n", wEtherType);
+               if (wEtherType == ETH_P_PAE) {
+                       skb->dev = pDevice->apdev;
+
+                       if (bIsWEP == true) {
+                               // strip IV header(8)
+                               memcpy(&abyMacHdr[0], (skb->data + 4), 24);
+                               memcpy((skb->data + 4 + cbIVOffset), &abyMacHdr[0], 24);
+                       }
+                       skb->data +=  (cbIVOffset + 4);
+                       skb->tail +=  (cbIVOffset + 4);
+                       skb_put(skb, FrameSize);
+                       skb_reset_mac_header(skb);
+
+                       skb->pkt_type = PACKET_OTHERHOST;
+                       skb->protocol = htons(ETH_P_802_2);
+                       memset(skb->cb, 0, sizeof(skb->cb));
+                       netif_rx(skb);
+                       return true;
+
+               }
+               // check if 802.1x authorized
+               if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED))
+                       return false;
+       }
+
+       if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
+               if (bIsWEP) {
+                       FrameSize -= 8;  //MIC
+               }
+       }
+
+       //--------------------------------------------------------------------------------
+       // Soft MIC
+       if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
+               if (bIsWEP) {
+                       unsigned long *pdwMIC_L;
+                       unsigned long *pdwMIC_R;
+                       unsigned long dwMIC_Priority;
+                       unsigned long dwMICKey0 = 0, dwMICKey1 = 0;
+                       unsigned long dwLocalMIC_L = 0;
+                       unsigned long dwLocalMIC_R = 0;
+                       viawget_wpa_header *wpahdr;
+
+                       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+                               dwMICKey0 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[24]));
+                               dwMICKey1 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[28]));
+                       } else {
+                               if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
+                                       dwMICKey0 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[16]));
+                                       dwMICKey1 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[20]));
+                               } else if ((pKey->dwKeyIndex & BIT28) == 0) {
+                                       dwMICKey0 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[16]));
+                                       dwMICKey1 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[20]));
+                               } else {
+                                       dwMICKey0 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[24]));
+                                       dwMICKey1 = cpu_to_le32(*(unsigned long *)(&pKey->abyKey[28]));
+                               }
+                       }
+
+                       MIC_vInit(dwMICKey0, dwMICKey1);
+                       MIC_vAppend((unsigned char *)&(pDevice->sRxEthHeader.abyDstAddr[0]), 12);
+                       dwMIC_Priority = 0;
+                       MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
+                       // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
+                       MIC_vAppend((unsigned char *)(skb->data + 4 + WLAN_HDR_ADDR3_LEN + 8),
+                                   FrameSize - WLAN_HDR_ADDR3_LEN - 8);
+                       MIC_vGetMIC(&dwLocalMIC_L, &dwLocalMIC_R);
+                       MIC_vUnInit();
+
+                       pdwMIC_L = (unsigned long *)(skb->data + 4 + FrameSize);
+                       pdwMIC_R = (unsigned long *)(skb->data + 4 + FrameSize + 4);
+                       //DBG_PRN_GRP12(("RxL: %lx, RxR: %lx\n", *pdwMIC_L, *pdwMIC_R));
+                       //DBG_PRN_GRP12(("LocalL: %lx, LocalR: %lx\n", dwLocalMIC_L, dwLocalMIC_R));
+                       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwMICKey0= %lx,dwMICKey1= %lx \n", dwMICKey0, dwMICKey1);
+
+                       if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) ||
+                           (pDevice->bRxMICFail == true)) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MIC comparison is fail!\n");
+                               pDevice->bRxMICFail = false;
+                               //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++;
+                               pDevice->s802_11Counter.TKIPLocalMICFailures++;
+                               if (bDeFragRx) {
+                                       if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
+                                               DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
+                                                       pDevice->dev->name);
+                                       }
+                               }
+                               //2008-0409-07, <Add> by Einsn Liu
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
                                //send event to wpa_supplicant
-                               //if(pDevice->bWPADevEnable == true)
                                {
                                        union iwreq_data wrqu;
                                        struct iw_michaelmicfailure ev;
@@ -845,8 +791,8 @@ device_receive_frame (
                                        memset(&ev, 0, sizeof(ev));
                                        ev.flags = keyidx & IW_MICFAILURE_KEY_ID;
                                        if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
-                                                       (pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
-                                                               (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
+                                           (pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
+                                           (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
                                                ev.flags |= IW_MICFAILURE_PAIRWISE;
                                        } else {
                                                ev.flags |= IW_MICFAILURE_GROUP;
@@ -859,633 +805,596 @@ device_receive_frame (
                                        wireless_send_event(pDevice->dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev);
 
                                }
-         #endif
-
-
-                if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
-                     wpahdr = (viawget_wpa_header *)pDevice->skb->data;
-                     if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
-                         (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
-                         (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
-                         //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR;
-                         wpahdr->type = VIAWGET_PTK_MIC_MSG;
-                     } else {
-                         //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_GROUP_ERROR;
-                         wpahdr->type = VIAWGET_GTK_MIC_MSG;
-                     }
-                     wpahdr->resp_ie_len = 0;
-                     wpahdr->req_ie_len = 0;
-                     skb_put(pDevice->skb, sizeof(viawget_wpa_header));
-                     pDevice->skb->dev = pDevice->wpadev;
-                    skb_reset_mac_header(pDevice->skb);
-                     pDevice->skb->pkt_type = PACKET_HOST;
-                     pDevice->skb->protocol = htons(ETH_P_802_2);
-                     memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
-                     netif_rx(pDevice->skb);
-                     pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-                 }
-
-                return false;
-
-            }
-        }
-    } //---end of SOFT MIC-----------------------------------------------------------------------
-
-    // ++++++++++ Reply Counter Check +++++++++++++
-
-    if ((pKey != NULL) && ((pKey->byCipherSuite == KEY_CTL_TKIP) ||
-                           (pKey->byCipherSuite == KEY_CTL_CCMP))) {
-        if (bIsWEP) {
-            unsigned short wLocalTSC15_0 = 0;
-            unsigned long dwLocalTSC47_16 = 0;
-            unsigned long long       RSC = 0;
-            // endian issues
-            RSC = *((unsigned long long *) &(pKey->KeyRSC));
-            wLocalTSC15_0 = (unsigned short) RSC;
-            dwLocalTSC47_16 = (unsigned long) (RSC>>16);
-
-            RSC = dwRxTSC47_16;
-            RSC <<= 16;
-            RSC += wRxTSC15_0;
-            memcpy(&(pKey->KeyRSC), &RSC,  sizeof(QWORD));
-
-            if ( (pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) &&
-                 (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) {
-                // check RSC
-                if ( (wRxTSC15_0 < wLocalTSC15_0) &&
-                     (dwRxTSC47_16 <= dwLocalTSC47_16) &&
-                     !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC is illegal~~!\n ");
-                    if (pKey->byCipherSuite == KEY_CTL_TKIP)
-                        //pDevice->s802_11Counter.TKIPReplays.QuadPart++;
-                        pDevice->s802_11Counter.TKIPReplays++;
-                    else
-                        //pDevice->s802_11Counter.CCMPReplays.QuadPart++;
-                        pDevice->s802_11Counter.CCMPReplays++;
-
-                    if (bDeFragRx) {
-                        if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
-                            DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
-                                pDevice->dev->name);
-                        }
-                    }
-                    return false;
-                }
-            }
-        }
-    } // ----- End of Reply Counter Check --------------------------
-
-
-
-    if ((pKey != NULL) && (bIsWEP)) {
+#endif
+
+                               if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
+                                       wpahdr = (viawget_wpa_header *)pDevice->skb->data;
+                                       if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
+                                           (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
+                                           (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
+                                               //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR;
+                                               wpahdr->type = VIAWGET_PTK_MIC_MSG;
+                                       } else {
+                                               //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_GROUP_ERROR;
+                                               wpahdr->type = VIAWGET_GTK_MIC_MSG;
+                                       }
+                                       wpahdr->resp_ie_len = 0;
+                                       wpahdr->req_ie_len = 0;
+                                       skb_put(pDevice->skb, sizeof(viawget_wpa_header));
+                                       pDevice->skb->dev = pDevice->wpadev;
+                                       skb_reset_mac_header(pDevice->skb);
+                                       pDevice->skb->pkt_type = PACKET_HOST;
+                                       pDevice->skb->protocol = htons(ETH_P_802_2);
+                                       memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
+                                       netif_rx(pDevice->skb);
+                                       pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
+                               }
+
+                               return false;
+
+                       }
+               }
+       } //---end of SOFT MIC-----------------------------------------------------------------------
+
+       // ++++++++++ Reply Counter Check +++++++++++++
+
+       if ((pKey != NULL) && ((pKey->byCipherSuite == KEY_CTL_TKIP) ||
+                              (pKey->byCipherSuite == KEY_CTL_CCMP))) {
+               if (bIsWEP) {
+                       unsigned short wLocalTSC15_0 = 0;
+                       unsigned long dwLocalTSC47_16 = 0;
+                       unsigned long long       RSC = 0;
+                       // endian issues
+                       RSC = *((unsigned long long *)&(pKey->KeyRSC));
+                       wLocalTSC15_0 = (unsigned short)RSC;
+                       dwLocalTSC47_16 = (unsigned long)(RSC>>16);
+
+                       RSC = dwRxTSC47_16;
+                       RSC <<= 16;
+                       RSC += wRxTSC15_0;
+                       memcpy(&(pKey->KeyRSC), &RSC,  sizeof(QWORD));
+
+                       if ((pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) &&
+                           (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) {
+                               // check RSC
+                               if ((wRxTSC15_0 < wLocalTSC15_0) &&
+                                   (dwRxTSC47_16 <= dwLocalTSC47_16) &&
+                                   !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "TSC is illegal~~!\n ");
+                                       if (pKey->byCipherSuite == KEY_CTL_TKIP)
+                                               //pDevice->s802_11Counter.TKIPReplays.QuadPart++;
+                                               pDevice->s802_11Counter.TKIPReplays++;
+                                       else
+                                               //pDevice->s802_11Counter.CCMPReplays.QuadPart++;
+                                               pDevice->s802_11Counter.CCMPReplays++;
+
+                                       if (bDeFragRx) {
+                                               if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
+                                                       DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
+                                                               pDevice->dev->name);
+                                               }
+                                       }
+                                       return false;
+                               }
+                       }
+               }
+       } // ----- End of Reply Counter Check --------------------------
+
+       if ((pKey != NULL) && (bIsWEP)) {
 //      pDevice->s802_11Counter.DecryptSuccessCount.QuadPart++;
-    }
-
-
-    s_vProcessRxMACHeader(pDevice, (unsigned char *)(skb->data+4), FrameSize, bIsWEP, bExtIV, &cbHeaderOffset);
-    FrameSize -= cbHeaderOffset;
-    cbHeaderOffset += 4;        // 4 is Rcv buffer header
-
-    // Null data, framesize = 14
-    if (FrameSize < 15)
-        return false;
-
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-        if (s_bAPModeRxData(pDevice,
-                            skb,
-                            FrameSize,
-                            cbHeaderOffset,
-                            iSANodeIndex,
-                            iDANodeIndex
-                            ) == false) {
-
-            if (bDeFragRx) {
-                if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
-                    DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
-                    pDevice->dev->name);
-                }
-            }
-            return false;
-        }
-
-//        if(pDevice->bRxMICFail == false) {
-//           for (ii =0; ii < 100; ii++)
-//                printk(" %02x", *(skb->data + ii));
-//           printk("\n");
-//         }
-
-    }
+       }
+
+       s_vProcessRxMACHeader(pDevice, (unsigned char *)(skb->data+4), FrameSize, bIsWEP, bExtIV, &cbHeaderOffset);
+       FrameSize -= cbHeaderOffset;
+       cbHeaderOffset += 4;        // 4 is Rcv buffer header
+
+       // Null data, framesize = 14
+       if (FrameSize < 15)
+               return false;
+
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               if (s_bAPModeRxData(pDevice,
+                                   skb,
+                                   FrameSize,
+                                   cbHeaderOffset,
+                                   iSANodeIndex,
+                                   iDANodeIndex
+) == false) {
+                       if (bDeFragRx) {
+                               if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
+                                       DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
+                                               pDevice->dev->name);
+                               }
+                       }
+                       return false;
+               }
+       }
 
        skb->data += cbHeaderOffset;
        skb->tail += cbHeaderOffset;
-    skb_put(skb, FrameSize);
-    skb->protocol=eth_type_trans(skb, skb->dev);
-
+       skb_put(skb, FrameSize);
+       skb->protocol = eth_type_trans(skb, skb->dev);
 
        //drop frame not met IEEE 802.3
 /*
-       if (pDevice->flags & DEVICE_FLAGS_VAL_PKT_LEN) {
-               if ((skb->protocol==htons(ETH_P_802_3)) &&
-                       (skb->len!=htons(skb->mac.ethernet->h_proto))) {
-                       pStats->rx_length_errors++;
-                       pStats->rx_dropped++;
-            if (bDeFragRx) {
-                if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
-                    DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
-                    pDevice->dev->name);
-                }
-            }
-                       return false;
-               }
-       }
+  if (pDevice->flags & DEVICE_FLAGS_VAL_PKT_LEN) {
+  if ((skb->protocol==htons(ETH_P_802_3)) &&
+  (skb->len!=htons(skb->mac.ethernet->h_proto))) {
+  pStats->rx_length_errors++;
+  pStats->rx_dropped++;
+  if (bDeFragRx) {
+  if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
+  DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
+  pDevice->dev->name);
+  }
+  }
+  return false;
+  }
+  }
 */
 
-    skb->ip_summed=CHECKSUM_NONE;
-    pStats->rx_bytes +=skb->len;
-    pStats->rx_packets++;
-    netif_rx(skb);
+       skb->ip_summed = CHECKSUM_NONE;
+       pStats->rx_bytes += skb->len;
+       pStats->rx_packets++;
+       netif_rx(skb);
 
-    if (bDeFragRx) {
-        if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
-            DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
-                pDevice->dev->name);
-        }
-        return false;
-    }
+       if (bDeFragRx) {
+               if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
+                       DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
+                               pDevice->dev->name);
+               }
+               return false;
+       }
 
-    return true;
+       return true;
 }
 
-
-static bool s_bAPModeRxCtl (
-    PSDevice pDevice,
-    unsigned char *pbyFrame,
-    int      iSANodeIndex
-    )
+static bool s_bAPModeRxCtl(
+       PSDevice pDevice,
+       unsigned char *pbyFrame,
+       int      iSANodeIndex
+)
 {
-    PS802_11Header      p802_11Header;
-    CMD_STATUS          Status;
-    PSMgmtObject        pMgmt = pDevice->pMgmt;
-
-
-    if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
-
-        p802_11Header = (PS802_11Header) (pbyFrame);
-        if (!IS_TYPE_MGMT(pbyFrame)) {
-
-            // Data & PS-Poll packet
-            // check frame class
-            if (iSANodeIndex > 0) {
-                // frame class 3 fliter & checking
-                if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_AUTH) {
-                    // send deauth notification
-                    // reason = (6) class 2 received from nonauth sta
-                    vMgrDeAuthenBeginSta(pDevice,
-                                         pMgmt,
-                                         (unsigned char *)(p802_11Header->abyAddr2),
-                                         (WLAN_MGMT_REASON_CLASS2_NONAUTH),
-                                         &Status
-                                         );
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 1\n");
-                    return true;
-                }
-                if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) {
-                    // send deassoc notification
-                    // reason = (7) class 3 received from nonassoc sta
-                    vMgrDisassocBeginSta(pDevice,
-                                         pMgmt,
-                                         (unsigned char *)(p802_11Header->abyAddr2),
-                                         (WLAN_MGMT_REASON_CLASS3_NONASSOC),
-                                         &Status
-                                         );
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDisassocBeginSta 2\n");
-                    return true;
-                }
-
-                if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) {
-                    // delcare received ps-poll event
-                    if (IS_CTL_PSPOLL(pbyFrame)) {
-                        pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
-                        bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 1\n");
-                    }
-                    else {
-                        // check Data PS state
-                        // if PW bit off, send out all PS bufferring packets.
-                        if (!IS_FC_POWERMGT(pbyFrame)) {
-                            pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false;
-                            pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
-                            bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
-                            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 2\n");
-                        }
-                    }
-                }
-                else {
-                   if (IS_FC_POWERMGT(pbyFrame)) {
-                       pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = true;
-                       // Once if STA in PS state, enable multicast bufferring
-                       pMgmt->sNodeDBTable[0].bPSEnable = true;
-                   }
-                   else {
-                      // clear all pending PS frame.
-                      if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) {
-                          pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false;
-                          pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
-                          bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
-                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 3\n");
-
-                      }
-                   }
-                }
-            }
-            else {
-                  vMgrDeAuthenBeginSta(pDevice,
-                                       pMgmt,
-                                       (unsigned char *)(p802_11Header->abyAddr2),
-                                       (WLAN_MGMT_REASON_CLASS2_NONAUTH),
-                                       &Status
-                                       );
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 3\n");
-                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSID:%pM\n",
-                               p802_11Header->abyAddr3);
-                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR2:%pM\n",
-                               p802_11Header->abyAddr2);
-                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%pM\n",
-                               p802_11Header->abyAddr1);
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl );
-                    VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc:pDevice->byRxMode = %x\n", pDevice->byRxMode );
-                    return true;
-            }
-        }
-    }
-    return false;
+       PS802_11Header      p802_11Header;
+       CMD_STATUS          Status;
+       PSMgmtObject        pMgmt = pDevice->pMgmt;
+
+       if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
+               p802_11Header = (PS802_11Header)(pbyFrame);
+               if (!IS_TYPE_MGMT(pbyFrame)) {
+                       // Data & PS-Poll packet
+                       // check frame class
+                       if (iSANodeIndex > 0) {
+                               // frame class 3 fliter & checking
+                               if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_AUTH) {
+                                       // send deauth notification
+                                       // reason = (6) class 2 received from nonauth sta
+                                       vMgrDeAuthenBeginSta(pDevice,
+                                                            pMgmt,
+                                                            (unsigned char *)(p802_11Header->abyAddr2),
+                                                            (WLAN_MGMT_REASON_CLASS2_NONAUTH),
+                                                            &Status
+);
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 1\n");
+                                       return true;
+                               }
+                               if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) {
+                                       // send deassoc notification
+                                       // reason = (7) class 3 received from nonassoc sta
+                                       vMgrDisassocBeginSta(pDevice,
+                                                            pMgmt,
+                                                            (unsigned char *)(p802_11Header->abyAddr2),
+                                                            (WLAN_MGMT_REASON_CLASS3_NONASSOC),
+                                                            &Status
+);
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDisassocBeginSta 2\n");
+                                       return true;
+                               }
 
+                               if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) {
+                                       // delcare received ps-poll event
+                                       if (IS_CTL_PSPOLL(pbyFrame)) {
+                                               pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
+                                               bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 1\n");
+                                       } else {
+                                               // check Data PS state
+                                               // if PW bit off, send out all PS bufferring packets.
+                                               if (!IS_FC_POWERMGT(pbyFrame)) {
+                                                       pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false;
+                                                       pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
+                                                       bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
+                                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 2\n");
+                                               }
+                                       }
+                               } else {
+                                       if (IS_FC_POWERMGT(pbyFrame)) {
+                                               pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = true;
+                                               // Once if STA in PS state, enable multicast bufferring
+                                               pMgmt->sNodeDBTable[0].bPSEnable = true;
+                                       } else {
+                                               // clear all pending PS frame.
+                                               if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) {
+                                                       pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false;
+                                                       pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
+                                                       bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
+                                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 3\n");
+
+                                               }
+                                       }
+                               }
+                       } else {
+                               vMgrDeAuthenBeginSta(pDevice,
+                                                    pMgmt,
+                                                    (unsigned char *)(p802_11Header->abyAddr2),
+                                                    (WLAN_MGMT_REASON_CLASS2_NONAUTH),
+                                                    &Status
+);
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 3\n");
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSID:%pM\n",
+                                       p802_11Header->abyAddr3);
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR2:%pM\n",
+                                       p802_11Header->abyAddr2);
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%pM\n",
+                                       p802_11Header->abyAddr1);
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl);
+                               VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc:pDevice->byRxMode = %x\n", pDevice->byRxMode);
+                               return true;
+                       }
+               }
+       }
+       return false;
 }
 
-static bool s_bHandleRxEncryption (
-    PSDevice     pDevice,
-    unsigned char *pbyFrame,
-    unsigned int FrameSize,
-    unsigned char *pbyRsr,
-    unsigned char *pbyNewRsr,
-    PSKeyItem   *pKeyOut,
-    bool *pbExtIV,
-    unsigned short *pwRxTSC15_0,
-    unsigned long *pdwRxTSC47_16
-    )
+static bool s_bHandleRxEncryption(
+       PSDevice     pDevice,
+       unsigned char *pbyFrame,
+       unsigned int FrameSize,
+       unsigned char *pbyRsr,
+       unsigned char *pbyNewRsr,
+       PSKeyItem   *pKeyOut,
+       bool *pbExtIV,
+       unsigned short *pwRxTSC15_0,
+       unsigned long *pdwRxTSC47_16
+)
 {
-    unsigned int PayloadLen = FrameSize;
-    unsigned char *pbyIV;
-    unsigned char byKeyIdx;
-    PSKeyItem       pKey = NULL;
-    unsigned char byDecMode = KEY_CTL_WEP;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-
-
-    *pwRxTSC15_0 = 0;
-    *pdwRxTSC47_16 = 0;
-
-    pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
-    if ( WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame) &&
-         WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame) ) {
-         pbyIV += 6;             // 6 is 802.11 address4
-         PayloadLen -= 6;
-    }
-    byKeyIdx = (*(pbyIV+3) & 0xc0);
-    byKeyIdx >>= 6;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
-
-    if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
-        (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
-        (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
-        (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
-        (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
-        if (((*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) &&
-            (pDevice->pMgmt->byCSSPK != KEY_CTL_NONE)) {
-            // unicast pkt use pairwise key
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt\n");
-            if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == true) {
-                if (pDevice->pMgmt->byCSSPK == KEY_CTL_TKIP)
-                    byDecMode = KEY_CTL_TKIP;
-                else if (pDevice->pMgmt->byCSSPK == KEY_CTL_CCMP)
-                    byDecMode = KEY_CTL_CCMP;
-            }
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt: %d, %p\n", byDecMode, pKey);
-        } else {
-            // use group key
-            KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, byKeyIdx, &pKey);
-            if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
-                byDecMode = KEY_CTL_TKIP;
-            else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
-                byDecMode = KEY_CTL_CCMP;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"group pkt: %d, %d, %p\n", byKeyIdx, byDecMode, pKey);
-        }
-    }
-    // our WEP only support Default Key
-    if (pKey == NULL) {
-        // use default group key
-        KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, byKeyIdx, &pKey);
-        if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
-            byDecMode = KEY_CTL_TKIP;
-        else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
-            byDecMode = KEY_CTL_CCMP;
-    }
-    *pKeyOut = pKey;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pDevice->pMgmt->byCSSPK, pDevice->pMgmt->byCSSGK, byDecMode);
-
-    if (pKey == NULL) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey == NULL\n");
-        if (byDecMode == KEY_CTL_WEP) {
+       unsigned int PayloadLen = FrameSize;
+       unsigned char *pbyIV;
+       unsigned char byKeyIdx;
+       PSKeyItem       pKey = NULL;
+       unsigned char byDecMode = KEY_CTL_WEP;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+
+       *pwRxTSC15_0 = 0;
+       *pdwRxTSC47_16 = 0;
+
+       pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
+       if (WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame) &&
+           WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame)) {
+               pbyIV += 6;             // 6 is 802.11 address4
+               PayloadLen -= 6;
+       }
+       byKeyIdx = (*(pbyIV+3) & 0xc0);
+       byKeyIdx >>= 6;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\nKeyIdx: %d\n", byKeyIdx);
+
+       if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
+           (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
+           (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
+           (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
+           (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
+               if (((*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) &&
+                   (pDevice->pMgmt->byCSSPK != KEY_CTL_NONE)) {
+                       // unicast pkt use pairwise key
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "unicast pkt\n");
+                       if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == true) {
+                               if (pDevice->pMgmt->byCSSPK == KEY_CTL_TKIP)
+                                       byDecMode = KEY_CTL_TKIP;
+                               else if (pDevice->pMgmt->byCSSPK == KEY_CTL_CCMP)
+                                       byDecMode = KEY_CTL_CCMP;
+                       }
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "unicast pkt: %d, %p\n", byDecMode, pKey);
+               } else {
+                       // use group key
+                       KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, byKeyIdx, &pKey);
+                       if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
+                               byDecMode = KEY_CTL_TKIP;
+                       else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
+                               byDecMode = KEY_CTL_CCMP;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group pkt: %d, %d, %p\n", byKeyIdx, byDecMode, pKey);
+               }
+       }
+       // our WEP only support Default Key
+       if (pKey == NULL) {
+               // use default group key
+               KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, byKeyIdx, &pKey);
+               if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
+                       byDecMode = KEY_CTL_TKIP;
+               else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
+                       byDecMode = KEY_CTL_CCMP;
+       }
+       *pKeyOut = pKey;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AES:%d %d %d\n", pDevice->pMgmt->byCSSPK, pDevice->pMgmt->byCSSGK, byDecMode);
+
+       if (pKey == NULL) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey == NULL\n");
+               if (byDecMode == KEY_CTL_WEP) {
 //            pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
-        } else if (pDevice->bLinkPass == true) {
+               } else if (pDevice->bLinkPass == true) {
 //            pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
-        }
-        return false;
-    }
-    if (byDecMode != pKey->byCipherSuite) {
-        if (byDecMode == KEY_CTL_WEP) {
+               }
+               return false;
+       }
+       if (byDecMode != pKey->byCipherSuite) {
+               if (byDecMode == KEY_CTL_WEP) {
 //            pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
-        } else if (pDevice->bLinkPass == true) {
+               } else if (pDevice->bLinkPass == true) {
 //            pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
-        }
-        *pKeyOut = NULL;
-        return false;
-    }
-    if (byDecMode == KEY_CTL_WEP) {
-        // handle WEP
-        if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
-            (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true)) {
-            // Software WEP
-            // 1. 3253A
-            // 2. WEP 256
-
-            PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
-            memcpy(pDevice->abyPRNG, pbyIV, 3);
-            memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
-            rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
-            rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
-
-            if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
-                *pbyNewRsr |= NEWRSR_DECRYPTOK;
-            }
-        }
-    } else if ((byDecMode == KEY_CTL_TKIP) ||
-               (byDecMode == KEY_CTL_CCMP)) {
-        // TKIP/AES
-
-        PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
-        *pdwRxTSC47_16 = cpu_to_le32(*(unsigned long *)(pbyIV + 4));
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %lx\n",*pdwRxTSC47_16);
-        if (byDecMode == KEY_CTL_TKIP) {
-            *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
-        } else {
-            *pwRxTSC15_0 = cpu_to_le16(*(unsigned short *)pbyIV);
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
-
-        if ((byDecMode == KEY_CTL_TKIP) &&
-            (pDevice->byLocalID <= REV_ID_VT3253_A1)) {
-            // Software TKIP
-            // 1. 3253 A
-            PS802_11Header  pMACHeader = (PS802_11Header) (pbyFrame);
-            TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
-            rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
-            rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
-            if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
-                *pbyNewRsr |= NEWRSR_DECRYPTOK;
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
-            } else {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
-            }
-        }
-    }// end of TKIP/AES
-
-    if ((*(pbyIV+3) & 0x20) != 0)
-        *pbExtIV = true;
-    return true;
-}
+               }
+               *pKeyOut = NULL;
+               return false;
+       }
+       if (byDecMode == KEY_CTL_WEP) {
+               // handle WEP
+               if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
+                   (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true)) {
+                       // Software WEP
+                       // 1. 3253A
+                       // 2. WEP 256
+
+                       PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
+                       memcpy(pDevice->abyPRNG, pbyIV, 3);
+                       memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
+                       rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
+                       rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
+
+                       if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
+                               *pbyNewRsr |= NEWRSR_DECRYPTOK;
+                       }
+               }
+       } else if ((byDecMode == KEY_CTL_TKIP) ||
+                  (byDecMode == KEY_CTL_CCMP)) {
+               // TKIP/AES
+
+               PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
+               *pdwRxTSC47_16 = cpu_to_le32(*(unsigned long *)(pbyIV + 4));
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ExtIV: %lx\n", *pdwRxTSC47_16);
+               if (byDecMode == KEY_CTL_TKIP) {
+                       *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV + 2), *pbyIV));
+               } else {
+                       *pwRxTSC15_0 = cpu_to_le16(*(unsigned short *)pbyIV);
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "TSC0_15: %x\n", *pwRxTSC15_0);
+
+               if ((byDecMode == KEY_CTL_TKIP) &&
+                   (pDevice->byLocalID <= REV_ID_VT3253_A1)) {
+                       // Software TKIP
+                       // 1. 3253 A
+                       PS802_11Header  pMACHeader = (PS802_11Header)(pbyFrame);
+                       TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
+                       rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
+                       rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
+                       if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
+                               *pbyNewRsr |= NEWRSR_DECRYPTOK;
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ICV OK!\n");
+                       } else {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ICV FAIL!!!\n");
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PayloadLen = %d\n", PayloadLen);
+                       }
+               }
+       }// end of TKIP/AES
 
+       if ((*(pbyIV+3) & 0x20) != 0)
+               *pbExtIV = true;
+       return true;
+}
 
-static bool s_bHostWepRxEncryption (
-    PSDevice     pDevice,
-    unsigned char *pbyFrame,
-    unsigned int FrameSize,
-    unsigned char *pbyRsr,
-    bool bOnFly,
-    PSKeyItem    pKey,
-    unsigned char *pbyNewRsr,
-    bool *pbExtIV,
-    unsigned short *pwRxTSC15_0,
-    unsigned long *pdwRxTSC47_16
-    )
+static bool s_bHostWepRxEncryption(
+       PSDevice     pDevice,
+       unsigned char *pbyFrame,
+       unsigned int FrameSize,
+       unsigned char *pbyRsr,
+       bool bOnFly,
+       PSKeyItem    pKey,
+       unsigned char *pbyNewRsr,
+       bool *pbExtIV,
+       unsigned short *pwRxTSC15_0,
+       unsigned long *pdwRxTSC47_16
+)
 {
-    unsigned int PayloadLen = FrameSize;
-    unsigned char *pbyIV;
-    unsigned char byKeyIdx;
-    unsigned char byDecMode = KEY_CTL_WEP;
-    PS802_11Header  pMACHeader;
-
+       unsigned int PayloadLen = FrameSize;
+       unsigned char *pbyIV;
+       unsigned char byKeyIdx;
+       unsigned char byDecMode = KEY_CTL_WEP;
+       PS802_11Header  pMACHeader;
+
+       *pwRxTSC15_0 = 0;
+       *pdwRxTSC47_16 = 0;
+
+       pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
+       if (WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame) &&
+           WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame)) {
+               pbyIV += 6;             // 6 is 802.11 address4
+               PayloadLen -= 6;
+       }
+       byKeyIdx = (*(pbyIV+3) & 0xc0);
+       byKeyIdx >>= 6;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\nKeyIdx: %d\n", byKeyIdx);
 
+       if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
+               byDecMode = KEY_CTL_TKIP;
+       else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
+               byDecMode = KEY_CTL_CCMP;
 
-    *pwRxTSC15_0 = 0;
-    *pdwRxTSC47_16 = 0;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AES:%d %d %d\n", pDevice->pMgmt->byCSSPK, pDevice->pMgmt->byCSSGK, byDecMode);
 
-    pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
-    if ( WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame) &&
-         WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame) ) {
-         pbyIV += 6;             // 6 is 802.11 address4
-         PayloadLen -= 6;
-    }
-    byKeyIdx = (*(pbyIV+3) & 0xc0);
-    byKeyIdx >>= 6;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
+       if (byDecMode != pKey->byCipherSuite) {
+               if (byDecMode == KEY_CTL_WEP) {
+//            pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
+               } else if (pDevice->bLinkPass == true) {
+//            pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
+               }
+               return false;
+       }
 
+       if (byDecMode == KEY_CTL_WEP) {
+               // handle WEP
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "byDecMode == KEY_CTL_WEP \n");
+               if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
+                   (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true) ||
+                   (bOnFly == false)) {
+                       // Software WEP
+                       // 1. 3253A
+                       // 2. WEP 256
+                       // 3. NotOnFly
+
+                       PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
+                       memcpy(pDevice->abyPRNG, pbyIV, 3);
+                       memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
+                       rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
+                       rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
+
+                       if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
+                               *pbyNewRsr |= NEWRSR_DECRYPTOK;
+                       }
+               }
+       } else if ((byDecMode == KEY_CTL_TKIP) ||
+                  (byDecMode == KEY_CTL_CCMP)) {
+               // TKIP/AES
+
+               PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
+               *pdwRxTSC47_16 = cpu_to_le32(*(unsigned long *)(pbyIV + 4));
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ExtIV: %lx\n", *pdwRxTSC47_16);
+
+               if (byDecMode == KEY_CTL_TKIP) {
+                       *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
+               } else {
+                       *pwRxTSC15_0 = cpu_to_le16(*(unsigned short *)pbyIV);
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "TSC0_15: %x\n", *pwRxTSC15_0);
+
+               if (byDecMode == KEY_CTL_TKIP) {
+                       if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (bOnFly == false)) {
+                               // Software TKIP
+                               // 1. 3253 A
+                               // 2. NotOnFly
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "soft KEY_CTL_TKIP \n");
+                               pMACHeader = (PS802_11Header)(pbyFrame);
+                               TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
+                               rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
+                               rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
+                               if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
+                                       *pbyNewRsr |= NEWRSR_DECRYPTOK;
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ICV OK!\n");
+                               } else {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ICV FAIL!!!\n");
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PayloadLen = %d\n", PayloadLen);
+                               }
+                       }
+               }
 
-    if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
-        byDecMode = KEY_CTL_TKIP;
-    else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
-        byDecMode = KEY_CTL_CCMP;
+               if (byDecMode == KEY_CTL_CCMP) {
+                       if (bOnFly == false) {
+                               // Software CCMP
+                               // NotOnFly
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "soft KEY_CTL_CCMP\n");
+                               if (AESbGenCCMP(pKey->abyKey, pbyFrame, FrameSize)) {
+                                       *pbyNewRsr |= NEWRSR_DECRYPTOK;
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CCMP MIC compare OK!\n");
+                               } else {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CCMP MIC fail!\n");
+                               }
+                       }
+               }
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pDevice->pMgmt->byCSSPK, pDevice->pMgmt->byCSSGK, byDecMode);
+       }// end of TKIP/AES
 
-    if (byDecMode != pKey->byCipherSuite) {
-        if (byDecMode == KEY_CTL_WEP) {
-//            pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
-        } else if (pDevice->bLinkPass == true) {
-//            pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
-        }
-        return false;
-    }
-
-    if (byDecMode == KEY_CTL_WEP) {
-        // handle WEP
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byDecMode == KEY_CTL_WEP \n");
-        if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
-            (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true) ||
-            (bOnFly == false)) {
-            // Software WEP
-            // 1. 3253A
-            // 2. WEP 256
-            // 3. NotOnFly
-
-            PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
-            memcpy(pDevice->abyPRNG, pbyIV, 3);
-            memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
-            rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
-            rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
-
-            if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
-                *pbyNewRsr |= NEWRSR_DECRYPTOK;
-            }
-        }
-    } else if ((byDecMode == KEY_CTL_TKIP) ||
-               (byDecMode == KEY_CTL_CCMP)) {
-        // TKIP/AES
-
-        PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
-        *pdwRxTSC47_16 = cpu_to_le32(*(unsigned long *)(pbyIV + 4));
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %lx\n",*pdwRxTSC47_16);
-
-        if (byDecMode == KEY_CTL_TKIP) {
-            *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
-        } else {
-            *pwRxTSC15_0 = cpu_to_le16(*(unsigned short *)pbyIV);
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
-
-        if (byDecMode == KEY_CTL_TKIP) {
-
-            if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (bOnFly == false)) {
-                // Software TKIP
-                // 1. 3253 A
-                // 2. NotOnFly
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_TKIP \n");
-                pMACHeader = (PS802_11Header) (pbyFrame);
-                TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
-                rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
-                rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
-                if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
-                    *pbyNewRsr |= NEWRSR_DECRYPTOK;
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
-                } else {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
-                }
-            }
-        }
-
-        if (byDecMode == KEY_CTL_CCMP) {
-            if (bOnFly == false) {
-                // Software CCMP
-                // NotOnFly
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_CCMP\n");
-                if (AESbGenCCMP(pKey->abyKey, pbyFrame, FrameSize)) {
-                    *pbyNewRsr |= NEWRSR_DECRYPTOK;
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC compare OK!\n");
-                } else {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC fail!\n");
-                }
-            }
-        }
-
-    }// end of TKIP/AES
-
-    if ((*(pbyIV+3) & 0x20) != 0)
-        *pbExtIV = true;
-    return true;
+       if ((*(pbyIV+3) & 0x20) != 0)
+               *pbExtIV = true;
+       return true;
 }
 
+static bool s_bAPModeRxData(
+       PSDevice pDevice,
+       struct sk_buff *skb,
+       unsigned int FrameSize,
+       unsigned int cbHeaderOffset,
+       int      iSANodeIndex,
+       int      iDANodeIndex
+)
+{
+       PSMgmtObject        pMgmt = pDevice->pMgmt;
+       bool bRelayAndForward = false;
+       bool bRelayOnly = false;
+       unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
+       unsigned short wAID;
+
+       struct sk_buff *skbcpy = NULL;
+
+       if (FrameSize > CB_MAX_BUF_SIZE)
+               return false;
+       // check DA
+       if (is_multicast_ether_addr((unsigned char *)(skb->data+cbHeaderOffset))) {
+               if (pMgmt->sNodeDBTable[0].bPSEnable) {
+                       skbcpy = dev_alloc_skb((int)pDevice->rx_buf_sz);
+
+                       // if any node in PS mode, buffer packet until DTIM.
+                       if (skbcpy == NULL) {
+                               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "relay multicast no skb available \n");
+                       } else {
+                               skbcpy->dev = pDevice->dev;
+                               skbcpy->len = FrameSize;
+                               memcpy(skbcpy->data, skb->data+cbHeaderOffset, FrameSize);
+                               skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skbcpy);
+
+                               pMgmt->sNodeDBTable[0].wEnQueueCnt++;
+                               // set tx map
+                               pMgmt->abyPSTxMap[0] |= byMask[0];
+                       }
+               } else {
+                       bRelayAndForward = true;
+               }
+       } else {
+               // check if relay
+               if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data+cbHeaderOffset), &iDANodeIndex)) {
+                       if (pMgmt->sNodeDBTable[iDANodeIndex].eNodeState >= NODE_ASSOC) {
+                               if (pMgmt->sNodeDBTable[iDANodeIndex].bPSEnable) {
+                                       // queue this skb until next PS tx, and then release.
+
+                                       skb->data += cbHeaderOffset;
+                                       skb->tail += cbHeaderOffset;
+                                       skb_put(skb, FrameSize);
+                                       skb_queue_tail(&pMgmt->sNodeDBTable[iDANodeIndex].sTxPSQueue, skb);
+                                       pMgmt->sNodeDBTable[iDANodeIndex].wEnQueueCnt++;
+                                       wAID = pMgmt->sNodeDBTable[iDANodeIndex].wAID;
+                                       pMgmt->abyPSTxMap[wAID >> 3] |=  byMask[wAID & 7];
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
+                                               iDANodeIndex, (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
+                                       return true;
+                               } else {
+                                       bRelayOnly = true;
+                               }
+                       }
+               }
+       }
+
+       if (bRelayOnly || bRelayAndForward) {
+               // relay this packet right now
+               if (bRelayAndForward)
+                       iDANodeIndex = 0;
+
+               if ((pDevice->uAssocCount > 1) && (iDANodeIndex >= 0)) {
+                       ROUTEbRelay(pDevice, (unsigned char *)(skb->data + cbHeaderOffset), FrameSize, (unsigned int)iDANodeIndex);
+               }
 
+               if (bRelayOnly)
+                       return false;
+       }
+       // none associate, don't forward
+       if (pDevice->uAssocCount == 0)
+               return false;
 
-static bool s_bAPModeRxData (
-    PSDevice pDevice,
-    struct sk_buff* skb,
-    unsigned int FrameSize,
-    unsigned int cbHeaderOffset,
-    int      iSANodeIndex,
-    int      iDANodeIndex
-    )
-{
-    PSMgmtObject        pMgmt = pDevice->pMgmt;
-    bool bRelayAndForward = false;
-    bool bRelayOnly = false;
-    unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
-    unsigned short wAID;
-
-
-    struct sk_buff* skbcpy = NULL;
-
-    if (FrameSize > CB_MAX_BUF_SIZE)
-        return false;
-    // check DA
-    if(is_multicast_ether_addr((unsigned char *)(skb->data+cbHeaderOffset))) {
-       if (pMgmt->sNodeDBTable[0].bPSEnable) {
-
-           skbcpy = dev_alloc_skb((int)pDevice->rx_buf_sz);
-
-        // if any node in PS mode, buffer packet until DTIM.
-           if (skbcpy == NULL) {
-               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "relay multicast no skb available \n");
-           }
-           else {
-               skbcpy->dev = pDevice->dev;
-               skbcpy->len = FrameSize;
-               memcpy(skbcpy->data, skb->data+cbHeaderOffset, FrameSize);
-               skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skbcpy);
-
-               pMgmt->sNodeDBTable[0].wEnQueueCnt++;
-               // set tx map
-               pMgmt->abyPSTxMap[0] |= byMask[0];
-           }
-       }
-       else {
-           bRelayAndForward = true;
-       }
-    }
-    else {
-        // check if relay
-        if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data+cbHeaderOffset), &iDANodeIndex)) {
-            if (pMgmt->sNodeDBTable[iDANodeIndex].eNodeState >= NODE_ASSOC) {
-                if (pMgmt->sNodeDBTable[iDANodeIndex].bPSEnable) {
-                    // queue this skb until next PS tx, and then release.
-
-                       skb->data += cbHeaderOffset;
-                       skb->tail += cbHeaderOffset;
-                    skb_put(skb, FrameSize);
-                    skb_queue_tail(&pMgmt->sNodeDBTable[iDANodeIndex].sTxPSQueue, skb);
-                    pMgmt->sNodeDBTable[iDANodeIndex].wEnQueueCnt++;
-                    wAID = pMgmt->sNodeDBTable[iDANodeIndex].wAID;
-                    pMgmt->abyPSTxMap[wAID >> 3] |=  byMask[wAID & 7];
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
-                               iDANodeIndex, (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
-                    return true;
-                }
-                else {
-                    bRelayOnly = true;
-                }
-            }
-        }
-    }
-
-    if (bRelayOnly || bRelayAndForward) {
-        // relay this packet right now
-        if (bRelayAndForward)
-            iDANodeIndex = 0;
-
-        if ((pDevice->uAssocCount > 1) && (iDANodeIndex >= 0)) {
-            ROUTEbRelay(pDevice, (unsigned char *)(skb->data + cbHeaderOffset), FrameSize, (unsigned int)iDANodeIndex);
-        }
-
-        if (bRelayOnly)
-            return false;
-    }
-    // none associate, don't forward
-    if (pDevice->uAssocCount == 0)
-        return false;
-
-    return true;
+       return true;
 }
-
index c1b6e76a421f16b8fe7050fb7e5f70f1ca05900c..0ce31557d5daed97f1029eaef8c0e0be2ad93d5c 100644 (file)
 /*---------------------  Export Functions  --------------------------*/
 
 bool
-device_receive_frame (
-    PSDevice pDevice,
-    PSRxDesc pCurrRD
-    );
+device_receive_frame(
+       PSDevice pDevice,
+       PSRxDesc pCurrRD
+);
 
 void   MngWorkItem(void *Context);
 
 #endif // __RXTX_H__
-
-
-
index 5f13890cf1241af033949988b437b284b23c8a4c..8417c2f2c6cfdbf2208a039b626b60ce56524134 100644 (file)
 
 /*---------------------  Static Variables  --------------------------*/
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 
 /*---------------------  Static Functions  --------------------------*/
 
-
-
-
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*
  * Description:
  *      register net_device (AP) for hostap deamon
@@ -75,21 +71,21 @@ static int          msglevel                =MSG_LEVEL_INFO;
 
 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
 {
-    PSDevice apdev_priv;
+       PSDevice apdev_priv;
        struct net_device *dev = pDevice->dev;
        int ret;
        const struct net_device_ops apdev_netdev_ops = {
                .ndo_start_xmit         = pDevice->tx_80211,
        };
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
 
        pDevice->apdev = kzalloc(sizeof(struct net_device), GFP_KERNEL);
        if (pDevice->apdev == NULL)
                return -ENOMEM;
 
-    apdev_priv = netdev_priv(pDevice->apdev);
-    *apdev_priv = *pDevice;
+       apdev_priv = netdev_priv(pDevice->apdev);
+       *apdev_priv = *pDevice;
        memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
 
        pDevice->apdev->netdev_ops = &apdev_netdev_ops;
@@ -107,14 +103,14 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
                ret = register_netdev(pDevice->apdev);
        if (ret) {
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n",
-                      dev->name);
+                       dev->name);
                return -1;
        }
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n",
-              dev->name, pDevice->apdev->name);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n",
+               dev->name, pDevice->apdev->name);
 
-    KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
+       KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
 
        return 0;
 }
@@ -135,33 +131,31 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
 
 static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked)
 {
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name);
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name);
-
-    if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) {
+       if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) {
                if (rtnl_locked)
                        unregister_netdevice(pDevice->apdev);
                else
                        unregister_netdev(pDevice->apdev);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
-                      pDevice->dev->name, pDevice->apdev->name);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
+                       pDevice->dev->name, pDevice->apdev->name);
        }
        kfree(pDevice->apdev);
        pDevice->apdev = NULL;
-    pDevice->bEnable8021x = false;
-    pDevice->bEnableHostWEP = false;
-    pDevice->bEncryptionEnable = false;
+       pDevice->bEnable8021x = false;
+       pDevice->bEnableHostWEP = false;
+       pDevice->bEncryptionEnable = false;
 
 //4.2007-0118-03,<Add> by EinsnLiu
 //execute some clear work
-pDevice->pMgmt->byCSSPK=KEY_CTL_NONE;
-pDevice->pMgmt->byCSSGK=KEY_CTL_NONE;
-KeyvInitTable(&pDevice->sKey,pDevice->PortOffset);
+       pDevice->pMgmt->byCSSPK = KEY_CTL_NONE;
+       pDevice->pMgmt->byCSSGK = KEY_CTL_NONE;
+       KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
 
        return 0;
 }
 
-
 /*
  * Description:
  *      Set enable/disable hostapd mode
@@ -192,7 +186,6 @@ int vt6655_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked)
                return hostap_disable_hostapd(pDevice, rtnl_locked);
 }
 
-
 /*
  * Description:
  *      remove station function supported for hostap deamon
@@ -207,17 +200,15 @@ int vt6655_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked)
  *
  */
 static int hostap_remove_sta(PSDevice pDevice,
-                                    struct viawget_hostapd_param *param)
+                            struct viawget_hostapd_param *param)
 {
        unsigned int uNodeIndex;
 
-
-    if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, param->sta_addr, &uNodeIndex)) {
-        BSSvRemoveOneNode(pDevice, uNodeIndex);
-    }
-    else {
-        return -ENOENT;
-    }
+       if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, param->sta_addr, &uNodeIndex)) {
+               BSSvRemoveOneNode(pDevice, uNodeIndex);
+       } else {
+               return -ENOENT;
+       }
        return 0;
 }
 
@@ -235,47 +226,46 @@ static int hostap_remove_sta(PSDevice pDevice,
  *
  */
 static int hostap_add_sta(PSDevice pDevice,
-                                 struct viawget_hostapd_param *param)
+                         struct viawget_hostapd_param *param)
 {
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
        unsigned int uNodeIndex;
 
-
-    if (!BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
-        BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
-    }
-    memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN);
-    pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
-    pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability;
+       if (!BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
+               BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
+       }
+       memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN);
+       pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
+       pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability;
 // TODO listenInterval
 //    pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1;
-    pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = false;
-    pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates;
-
-    // set max tx rate
-    pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
-           pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
-    // set max basic rate
-    pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate = RATE_2M;
-    // Todo: check sta preamble, if ap can't support, set status code
-    pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
-            WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo);
-
-    pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)param->u.add_sta.aid;
-
-    pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Add STA AID= %d \n", pMgmt->sNodeDBTable[uNodeIndex].wAID);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
-               param->sta_addr[0],
-               param->sta_addr[1],
-               param->sta_addr[2],
-               param->sta_addr[3],
-               param->sta_addr[4],
-               param->sta_addr[5]
-              ;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Max Support rate = %d \n",
-               pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
+       pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = false;
+       pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates;
+
+       // set max tx rate
+       pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
+               pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
+       // set max basic rate
+       pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate = RATE_2M;
+       // Todo: check sta preamble, if ap can't support, set status code
+       pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
+               WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo);
+
+       pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)param->u.add_sta.aid;
+
+       pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Add STA AID= %d \n", pMgmt->sNodeDBTable[uNodeIndex].wAID);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
+               param->sta_addr[0],
+               param->sta_addr[1],
+               param->sta_addr[2],
+               param->sta_addr[3],
+               param->sta_addr[4],
+               param->sta_addr[5]
+               );
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Max Support rate = %d \n",
+               pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
 
        return 0;
 }
@@ -295,19 +285,18 @@ static int hostap_add_sta(PSDevice pDevice,
  */
 
 static int hostap_get_info_sta(PSDevice pDevice,
-                                      struct viawget_hostapd_param *param)
+                              struct viawget_hostapd_param *param)
 {
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
        unsigned int uNodeIndex;
 
-    if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
-           param->u.get_info_sta.inactive_sec =
-               (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ;
+       if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
+               param->u.get_info_sta.inactive_sec =
+                       (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ;
 
-           //param->u.get_info_sta.txexc = pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts;
-       }
-       else {
-           return -ENOENT;
+               //param->u.get_info_sta.txexc = pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts;
+       } else {
+               return -ENOENT;
        }
 
        return 0;
@@ -328,21 +317,20 @@ static int hostap_get_info_sta(PSDevice pDevice,
  *
  */
 /*
-static int hostap_reset_txexc_sta(PSDevice pDevice,
-                                         struct viawget_hostapd_param *param)
-{
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-       unsigned int uNodeIndex;
-
-    if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
-        pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts = 0;
-       }
-       else {
-           return -ENOENT;
-       }
-
-       return 0;
-}
+  static int hostap_reset_txexc_sta(PSDevice pDevice,
+  struct viawget_hostapd_param *param)
+  {
+  PSMgmtObject    pMgmt = pDevice->pMgmt;
+  unsigned int uNodeIndex;
+
+  if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
+  pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts = 0;
+  } else {
+  return -ENOENT;
+  }
+
+  return 0;
+  }
 */
 
 /*
@@ -359,26 +347,23 @@ static int hostap_reset_txexc_sta(PSDevice pDevice,
  *
  */
 static int hostap_set_flags_sta(PSDevice pDevice,
-                                       struct viawget_hostapd_param *param)
+                               struct viawget_hostapd_param *param)
 {
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
        unsigned int uNodeIndex;
 
-    if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
+       if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
                pMgmt->sNodeDBTable[uNodeIndex].dwFlags |= param->u.set_flags_sta.flags_or;
                pMgmt->sNodeDBTable[uNodeIndex].dwFlags &= param->u.set_flags_sta.flags_and;
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " dwFlags = %x \n",
-                           (unsigned int)pMgmt->sNodeDBTable[uNodeIndex].dwFlags);
-       }
-       else {
-           return -ENOENT;
+                       (unsigned int)pMgmt->sNodeDBTable[uNodeIndex].dwFlags);
+       } else {
+               return -ENOENT;
        }
 
        return 0;
 }
 
-
-
 /*
  * Description:
  *      set generic element (wpa ie)
@@ -393,34 +378,32 @@ static int hostap_set_flags_sta(PSDevice pDevice,
  *
  */
 static int hostap_set_generic_element(PSDevice pDevice,
-                                       struct viawget_hostapd_param *param)
+                                     struct viawget_hostapd_param *param)
 {
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-
-
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
 
-    memcpy( pMgmt->abyWPAIE,
-            param->u.generic_elem.data,
-            param->u.generic_elem.len
-           );
+       memcpy(pMgmt->abyWPAIE,
+              param->u.generic_elem.data,
+              param->u.generic_elem.len
+               );
 
-    pMgmt->wWPAIELen =         param->u.generic_elem.len;
+       pMgmt->wWPAIELen = param->u.generic_elem.len;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->wWPAIELen = %d\n",  pMgmt->wWPAIELen);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->wWPAIELen = %d\n", pMgmt->wWPAIELen);
 
-    // disable wpa
-    if (pMgmt->wWPAIELen == 0) {
-        pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
+       // disable wpa
+       if (pMgmt->wWPAIELen == 0) {
+               pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " No WPAIE, Disable WPA \n");
-    } else  {
-        // enable wpa
-        if ((pMgmt->abyWPAIE[0] == WLAN_EID_RSN_WPA) ||
-             (pMgmt->abyWPAIE[0] == WLAN_EID_RSN)) {
-              pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
-               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set WPAIE enable WPA\n");
-        } else
-            return -EINVAL;
-    }
+       } else  {
+               // enable wpa
+               if ((pMgmt->abyWPAIE[0] == WLAN_EID_RSN_WPA) ||
+                   (pMgmt->abyWPAIE[0] == WLAN_EID_RSN)) {
+                       pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set WPAIE enable WPA\n");
+               } else
+                       return -EINVAL;
+       }
 
        return 0;
 }
@@ -440,11 +423,11 @@ static int hostap_set_generic_element(PSDevice pDevice,
 
 static void hostap_flush_sta(PSDevice pDevice)
 {
-    // reserved node index =0 for multicast node.
-    BSSvClearNodeDBTable(pDevice, 1);
-    pDevice->uAssocCount = 0;
+       // reserved node index =0 for multicast node.
+       BSSvClearNodeDBTable(pDevice, 1);
+       pDevice->uAssocCount = 0;
 
-    return;
+       return;
 }
 
 /*
@@ -461,34 +444,32 @@ static void hostap_flush_sta(PSDevice pDevice)
  *
  */
 static int hostap_set_encryption(PSDevice pDevice,
-                                      struct viawget_hostapd_param *param,
-                                      int param_len)
+                                struct viawget_hostapd_param *param,
+                                int param_len)
 {
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned long dwKeyIndex = 0;
-    unsigned char abyKey[MAX_KEY_LEN];
-    unsigned char abySeq[MAX_KEY_LEN];
-    NDIS_802_11_KEY_RSC   KeyRSC;
-    unsigned char byKeyDecMode = KEY_CTL_WEP;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned long dwKeyIndex = 0;
+       unsigned char abyKey[MAX_KEY_LEN];
+       unsigned char abySeq[MAX_KEY_LEN];
+       NDIS_802_11_KEY_RSC   KeyRSC;
+       unsigned char byKeyDecMode = KEY_CTL_WEP;
        int     ret = 0;
        int     iNodeIndex = -1;
        int     ii;
        bool bKeyTableFull = false;
        unsigned short wKeyCtl = 0;
 
-
        param->u.crypt.err = 0;
 /*
-       if (param_len !=
-           (int) ((char *) param->u.crypt.key - (char *) param) +
-           param->u.crypt.key_len)
-               return -EINVAL;
+  if (param_len !=
+  (int) ((char *) param->u.crypt.key - (char *) param) +
+  param->u.crypt.key_len)
+  return -EINVAL;
 */
 
        if (param->u.crypt.alg > WPA_ALG_CCMP)
                return -EINVAL;
 
-
        if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) {
                param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n");
@@ -498,105 +479,102 @@ static int hostap_set_encryption(PSDevice pDevice,
        if (is_broadcast_ether_addr(param->sta_addr)) {
                if (param->u.crypt.idx >= MAX_GROUP_KEY)
                        return -EINVAL;
-        iNodeIndex = 0;
+               iNodeIndex = 0;
 
        } else {
-           if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == false) {
-               param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
-               return -EINVAL;
-           }
+               if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == false) {
+                       param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
+                       return -EINVAL;
+               }
        }
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: sta_index %d \n", iNodeIndex);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: alg %d \n", param->u.crypt.alg);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: sta_index %d \n", iNodeIndex);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: alg %d \n", param->u.crypt.alg);
 
        if (param->u.crypt.alg == WPA_ALG_NONE) {
-
-        if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == true) {
-            if (KeybRemoveKey(&(pDevice->sKey),
-                                param->sta_addr,
-                                pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex,
-                                pDevice->PortOffset) == false) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n");
-            }
-            pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
-        }
-        pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0;
-        pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0;
-        pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0;
-        pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0;
-        pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
-        pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
-        pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0;
-        memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
-                0,
-                MAX_KEY_LEN
-               );
-
-        return ret;
+               if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == true) {
+                       if (KeybRemoveKey(&(pDevice->sKey),
+                                         param->sta_addr,
+                                         pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex,
+                                         pDevice->PortOffset) == false) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n");
+                       }
+                       pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
+               }
+               pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0;
+               pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0;
+               pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0;
+               pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0;
+               pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
+               pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
+               pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0;
+               memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
+                      0,
+                      MAX_KEY_LEN
+);
+
+               return ret;
        }
 
-    memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len);
-    // copy to node key tbl
-    pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx;
-    pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len;
-    memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
-            param->u.crypt.key,
-            param->u.crypt.key_len
-           );
-
-    dwKeyIndex = (unsigned long)(param->u.crypt.idx);
-    if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
-        pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
-        pDevice->bTransmitKey = true;
-        dwKeyIndex |= (1 << 31);
-    }
+       memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len);
+       // copy to node key tbl
+       pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx;
+       pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len;
+       memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
+              param->u.crypt.key,
+              param->u.crypt.key_len
+);
+
+       dwKeyIndex = (unsigned long)(param->u.crypt.idx);
+       if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
+               pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
+               pDevice->bTransmitKey = true;
+               dwKeyIndex |= (1 << 31);
+       }
 
        if (param->u.crypt.alg == WPA_ALG_WEP) {
-
-        if ((pDevice->bEnable8021x == false) || (iNodeIndex == 0)) {
-            KeybSetDefaultKey(&(pDevice->sKey),
-                                dwKeyIndex & ~(BIT30 | USE_KEYRSC),
-                                param->u.crypt.key_len,
-                                NULL,
-                                abyKey,
-                                KEY_CTL_WEP,
-                                pDevice->PortOffset,
-                                pDevice->byLocalID);
-
-        } else {
-            // 8021x enable, individual key
-            dwKeyIndex |= (1 << 30); // set pairwise key
-            if (KeybSetKey(&(pDevice->sKey),
-                           &param->sta_addr[0],
-                           dwKeyIndex & ~(USE_KEYRSC),
-                           param->u.crypt.key_len,
-                           (PQWORD) &(KeyRSC),
-                           (unsigned char *)abyKey,
-                            KEY_CTL_WEP,
-                            pDevice->PortOffset,
-                            pDevice->byLocalID) == true) {
-
-                pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
-
-            } else {
-                // Key Table Full
-                pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
-                bKeyTableFull = true;
-            }
-        }
-        pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
-        pDevice->bEncryptionEnable = true;
-        pMgmt->byCSSPK = KEY_CTL_WEP;
-        pMgmt->byCSSGK = KEY_CTL_WEP;
-        pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP;
-        pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
-        return ret;
+               if ((pDevice->bEnable8021x == false) || (iNodeIndex == 0)) {
+                       KeybSetDefaultKey(&(pDevice->sKey),
+                                         dwKeyIndex & ~(BIT30 | USE_KEYRSC),
+                                         param->u.crypt.key_len,
+                                         NULL,
+                                         abyKey,
+                                         KEY_CTL_WEP,
+                                         pDevice->PortOffset,
+                                         pDevice->byLocalID);
+
+               } else {
+                       // 8021x enable, individual key
+                       dwKeyIndex |= (1 << 30); // set pairwise key
+                       if (KeybSetKey(&(pDevice->sKey),
+                                      &param->sta_addr[0],
+                                      dwKeyIndex & ~(USE_KEYRSC),
+                                      param->u.crypt.key_len,
+                                      (PQWORD) &(KeyRSC),
+                                      (unsigned char *)abyKey,
+                                      KEY_CTL_WEP,
+                                      pDevice->PortOffset,
+                                      pDevice->byLocalID) == true) {
+                               pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
+
+                       } else {
+                               // Key Table Full
+                               pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
+                               bKeyTableFull = true;
+                       }
+               }
+               pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
+               pDevice->bEncryptionEnable = true;
+               pMgmt->byCSSPK = KEY_CTL_WEP;
+               pMgmt->byCSSGK = KEY_CTL_WEP;
+               pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP;
+               pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
+               return ret;
        }
 
        if (param->u.crypt.seq) {
-           memcpy(&abySeq, param->u.crypt.seq, 8);
-               for (ii = 0 ; ii < 8 ; ii++)
+               memcpy(&abySeq, param->u.crypt.seq, 8);
+               for (ii = 0; ii < 8; ii++)
                        KeyRSC |= (unsigned long)abySeq[ii] << (ii * 8);
 
                dwKeyIndex |= 1 << 29;
@@ -604,91 +582,87 @@ static int hostap_set_encryption(PSDevice pDevice,
        }
 
        if (param->u.crypt.alg == WPA_ALG_TKIP) {
-           if (param->u.crypt.key_len != MAX_KEY_LEN)
-               return -EINVAL;
-           pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
-        byKeyDecMode = KEY_CTL_TKIP;
-        pMgmt->byCSSPK = KEY_CTL_TKIP;
-        pMgmt->byCSSGK = KEY_CTL_TKIP;
+               if (param->u.crypt.key_len != MAX_KEY_LEN)
+                       return -EINVAL;
+               pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
+               byKeyDecMode = KEY_CTL_TKIP;
+               pMgmt->byCSSPK = KEY_CTL_TKIP;
+               pMgmt->byCSSGK = KEY_CTL_TKIP;
        }
 
        if (param->u.crypt.alg == WPA_ALG_CCMP) {
-           if ((param->u.crypt.key_len != AES_KEY_LEN) ||
-               (pDevice->byLocalID <= REV_ID_VT3253_A1))
-               return -EINVAL;
-        pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
-        byKeyDecMode = KEY_CTL_CCMP;
-        pMgmt->byCSSPK = KEY_CTL_CCMP;
-        pMgmt->byCSSGK = KEY_CTL_CCMP;
-    }
-
-
-    if (iNodeIndex == 0) {
-       KeybSetDefaultKey(&(pDevice->sKey),
-                           dwKeyIndex,
-                           param->u.crypt.key_len,
-                           (PQWORD) &(KeyRSC),
-                           abyKey,
-                           byKeyDecMode,
-                           pDevice->PortOffset,
-                           pDevice->byLocalID);
-       pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
-
-    } else {
-        dwKeyIndex |= (1 << 30); // set pairwise key
-        if (KeybSetKey(&(pDevice->sKey),
-                       &param->sta_addr[0],
-                       dwKeyIndex,
-                       param->u.crypt.key_len,
-                       (PQWORD) &(KeyRSC),
-                       (unsigned char *)abyKey,
-                        byKeyDecMode,
-                        pDevice->PortOffset,
-                        pDevice->byLocalID) == true) {
-
-            pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
-
-        } else {
-            // Key Table Full
-            pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
-            bKeyTableFull = true;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n");
-        }
-
-    }
-
-    if (bKeyTableFull == true) {
-        wKeyCtl &= 0x7F00;              // clear all key control filed
-        wKeyCtl |= (byKeyDecMode << 4);
-        wKeyCtl |= (byKeyDecMode);
-        wKeyCtl |= 0x0044;              // use group key for all address
-        wKeyCtl |= 0x4000;              // disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int
-        MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID);
-    }
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set key sta_index= %d \n", iNodeIndex);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " tx_index=%d len=%d \n", param->u.crypt.idx,
-               param->u.crypt.key_len );
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
-               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
-               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1],
-               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2],
-               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3],
-               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4]
-              );
+               if ((param->u.crypt.key_len != AES_KEY_LEN) ||
+                   (pDevice->byLocalID <= REV_ID_VT3253_A1))
+                       return -EINVAL;
+               pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
+               byKeyDecMode = KEY_CTL_CCMP;
+               pMgmt->byCSSPK = KEY_CTL_CCMP;
+               pMgmt->byCSSGK = KEY_CTL_CCMP;
+       }
+
+       if (iNodeIndex == 0) {
+               KeybSetDefaultKey(&(pDevice->sKey),
+                                 dwKeyIndex,
+                                 param->u.crypt.key_len,
+                                 (PQWORD) &(KeyRSC),
+                                 abyKey,
+                                 byKeyDecMode,
+                                 pDevice->PortOffset,
+                                 pDevice->byLocalID);
+               pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
+
+       } else {
+               dwKeyIndex |= (1 << 30); // set pairwise key
+               if (KeybSetKey(&(pDevice->sKey),
+                              &param->sta_addr[0],
+                              dwKeyIndex,
+                              param->u.crypt.key_len,
+                              (PQWORD) &(KeyRSC),
+                              (unsigned char *)abyKey,
+                              byKeyDecMode,
+                              pDevice->PortOffset,
+                              pDevice->byLocalID) == true) {
+                       pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
+
+               } else {
+                       // Key Table Full
+                       pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
+                       bKeyTableFull = true;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n");
+               }
+
+       }
+
+       if (bKeyTableFull == true) {
+               wKeyCtl &= 0x7F00;              // clear all key control filed
+               wKeyCtl |= (byKeyDecMode << 4);
+               wKeyCtl |= (byKeyDecMode);
+               wKeyCtl |= 0x0044;              // use group key for all address
+               wKeyCtl |= 0x4000;              // disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int
+               MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID);
+       }
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set key sta_index= %d \n", iNodeIndex);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " tx_index=%d len=%d \n", param->u.crypt.idx,
+               param->u.crypt.key_len);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
+               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
+               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1],
+               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2],
+               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3],
+               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4]
+);
 
        // set wep key
-    pDevice->bEncryptionEnable = true;
-    pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode;
-    pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
-    pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
-    pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
+       pDevice->bEncryptionEnable = true;
+       pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode;
+       pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
+       pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
+       pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
 
        return ret;
 }
 
-
-
 /*
  * Description:
  *      get each stations encryption key
@@ -703,36 +677,34 @@ static int hostap_set_encryption(PSDevice pDevice,
  *
  */
 static int hostap_get_encryption(PSDevice pDevice,
-                                      struct viawget_hostapd_param *param,
-                                      int param_len)
+                                struct viawget_hostapd_param *param,
+                                int param_len)
 {
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
        int     ret = 0;
        int     ii;
-       int     iNodeIndex =0;
-
+       int     iNodeIndex = 0;
 
        param->u.crypt.err = 0;
 
        if (is_broadcast_ether_addr(param->sta_addr)) {
-        iNodeIndex = 0;
+               iNodeIndex = 0;
        } else {
-           if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == false) {
-               param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
-               return -EINVAL;
-           }
+               if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == false) {
+                       param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
+                       return -EINVAL;
+               }
        }
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: %d\n", iNodeIndex);
-    memset(param->u.crypt.seq, 0, 8);
-    for (ii = 0 ; ii < 8 ; ii++) {
-        param->u.crypt.seq[ii] = (unsigned char)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
-    }
+       memset(param->u.crypt.seq, 0, 8);
+       for (ii = 0; ii < 8; ii++) {
+               param->u.crypt.seq[ii] = (unsigned char)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
+       }
 
        return ret;
 }
 
-
 /*
  * Description:
  *      vt6655_hostap_ioctl main function supported for hostap deamon.
@@ -768,80 +740,79 @@ int vt6655_hostap_ioctl(PSDevice pDevice, struct iw_point *p)
 
        switch (param->cmd) {
        case VIAWGET_HOSTAPD_SET_ENCRYPTION:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ENCRYPTION \n");
-        spin_lock_irq(&pDevice->lock);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ENCRYPTION \n");
+               spin_lock_irq(&pDevice->lock);
                ret = hostap_set_encryption(pDevice, param, p->length);
-        spin_unlock_irq(&pDevice->lock);
+               spin_unlock_irq(&pDevice->lock);
                break;
        case VIAWGET_HOSTAPD_GET_ENCRYPTION:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_ENCRYPTION \n");
-        spin_lock_irq(&pDevice->lock);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_ENCRYPTION \n");
+               spin_lock_irq(&pDevice->lock);
                ret = hostap_get_encryption(pDevice, param, p->length);
-        spin_unlock_irq(&pDevice->lock);
+               spin_unlock_irq(&pDevice->lock);
                break;
        case VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR \n");
                return -EOPNOTSUPP;
                break;
        case VIAWGET_HOSTAPD_FLUSH:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_FLUSH \n");
-        spin_lock_irq(&pDevice->lock);
-       hostap_flush_sta(pDevice);
-        spin_unlock_irq(&pDevice->lock);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_FLUSH \n");
+               spin_lock_irq(&pDevice->lock);
+               hostap_flush_sta(pDevice);
+               spin_unlock_irq(&pDevice->lock);
                break;
        case VIAWGET_HOSTAPD_ADD_STA:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_ADD_STA \n");
-         spin_lock_irq(&pDevice->lock);
-                ret = hostap_add_sta(pDevice, param);
-         spin_unlock_irq(&pDevice->lock);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_ADD_STA \n");
+               spin_lock_irq(&pDevice->lock);
+               ret = hostap_add_sta(pDevice, param);
+               spin_unlock_irq(&pDevice->lock);
                break;
        case VIAWGET_HOSTAPD_REMOVE_STA:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_REMOVE_STA \n");
-         spin_lock_irq(&pDevice->lock);
-                ret = hostap_remove_sta(pDevice, param);
-         spin_unlock_irq(&pDevice->lock);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_REMOVE_STA \n");
+               spin_lock_irq(&pDevice->lock);
+               ret = hostap_remove_sta(pDevice, param);
+               spin_unlock_irq(&pDevice->lock);
                break;
        case VIAWGET_HOSTAPD_GET_INFO_STA:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_INFO_STA \n");
-                ret = hostap_get_info_sta(pDevice, param);
-                ap_ioctl = 1;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_INFO_STA \n");
+               ret = hostap_get_info_sta(pDevice, param);
+               ap_ioctl = 1;
                break;
 /*
        case VIAWGET_HOSTAPD_RESET_TXEXC_STA:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_RESET_TXEXC_STA \n");
-                ret = hostap_reset_txexc_sta(pDevice, param);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_RESET_TXEXC_STA \n");
+               ret = hostap_reset_txexc_sta(pDevice, param);
                break;
 */
        case VIAWGET_HOSTAPD_SET_FLAGS_STA:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_FLAGS_STA \n");
-                ret = hostap_set_flags_sta(pDevice, param);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_FLAGS_STA \n");
+               ret = hostap_set_flags_sta(pDevice, param);
                break;
 
        case VIAWGET_HOSTAPD_MLME:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n");
-           return -EOPNOTSUPP;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n");
+               return -EOPNOTSUPP;
 
        case VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT \n");
                ret = hostap_set_generic_element(pDevice, param);
                break;
 
        case VIAWGET_HOSTAPD_SCAN_REQ:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n");
-           return -EOPNOTSUPP;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n");
+               return -EOPNOTSUPP;
 
        case VIAWGET_HOSTAPD_STA_CLEAR_STATS:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n");
-           return -EOPNOTSUPP;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n");
+               return -EOPNOTSUPP;
 
        default:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vt6655_hostap_ioctl: unknown cmd=%d\n",
-                      (int)param->cmd);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vt6655_hostap_ioctl: unknown cmd=%d\n",
+                       (int)param->cmd);
                return -EOPNOTSUPP;
                break;
        }
 
-
        if ((ret == 0) && ap_ioctl) {
                if (copy_to_user(p->pointer, param, p->length)) {
                        ret = -EFAULT;
@@ -849,9 +820,8 @@ int vt6655_hostap_ioctl(PSDevice pDevice, struct iw_point *p)
                }
        }
 
- out:
+out:
        kfree(param);
 
        return ret;
 }
-
index 55db55524d962f8c46edd65d5fdecd845cf9ddcf..f1a4f2eff058d737225ed449caadf13b4ad5d3ed 100644 (file)
@@ -46,7 +46,6 @@
 #define WLAN_RATE_48M   BIT10
 #define WLAN_RATE_54M   BIT11
 
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
@@ -65,6 +64,3 @@ int vt6655_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked);
 int vt6655_hostap_ioctl(PSDevice pDevice, struct iw_point *p);
 
 #endif // __HOSTAP_H__
-
-
-
index 166351bb71a6bb857a974136f5d5547ef604d544..e499f1b6f5317c054ff564c4e3c0ca966773d8e9 100644 (file)
@@ -37,7 +37,6 @@
 //typedef uint16_t u16;
 //typedef uint8_t u8;
 
-
 // ioctl Command code
 #define MAGIC_CODE                      0x3142
 #define IOCTL_CMD_TEST             (SIOCDEVPRIVATE + 0)
 #define IOCTL_CMD_HOSTAPD           (SIOCDEVPRIVATE + 2)
 #define IOCTL_CMD_WPA               (SIOCDEVPRIVATE + 3)
 
-
 typedef enum tagWMAC_CMD {
-
-    WLAN_CMD_BSS_SCAN,
-    WLAN_CMD_BSS_JOIN,
-    WLAN_CMD_DISASSOC,
-    WLAN_CMD_SET_WEP,
-    WLAN_CMD_GET_LINK,
-    WLAN_CMD_GET_LISTLEN,
-    WLAN_CMD_GET_LIST,
-    WLAN_CMD_GET_MIB,
-    WLAN_CMD_GET_STAT,
-    WLAN_CMD_STOP_MAC,
-    WLAN_CMD_START_MAC,
-    WLAN_CMD_AP_START,
-    WLAN_CMD_SET_HOSTAPD,
-    WLAN_CMD_SET_HOSTAPD_STA,
-    WLAN_CMD_SET_802_1X,
-    WLAN_CMD_SET_HOST_WEP,
-    WLAN_CMD_SET_WPA,
-    WLAN_CMD_GET_NODE_CNT,
-    WLAN_CMD_ZONETYPE_SET,
-    WLAN_CMD_GET_NODE_LIST
-
+       WLAN_CMD_BSS_SCAN,
+       WLAN_CMD_BSS_JOIN,
+       WLAN_CMD_DISASSOC,
+       WLAN_CMD_SET_WEP,
+       WLAN_CMD_GET_LINK,
+       WLAN_CMD_GET_LISTLEN,
+       WLAN_CMD_GET_LIST,
+       WLAN_CMD_GET_MIB,
+       WLAN_CMD_GET_STAT,
+       WLAN_CMD_STOP_MAC,
+       WLAN_CMD_START_MAC,
+       WLAN_CMD_AP_START,
+       WLAN_CMD_SET_HOSTAPD,
+       WLAN_CMD_SET_HOSTAPD_STA,
+       WLAN_CMD_SET_802_1X,
+       WLAN_CMD_SET_HOST_WEP,
+       WLAN_CMD_SET_WPA,
+       WLAN_CMD_GET_NODE_CNT,
+       WLAN_CMD_ZONETYPE_SET,
+       WLAN_CMD_GET_NODE_LIST
 } WMAC_CMD, *PWMAC_CMD;
 
 typedef enum tagWZONETYPE {
-  ZoneType_USA=0,
-  ZoneType_Japan=1,
-  ZoneType_Europe=2
-}WZONETYPE;
+       ZoneType_USA = 0,
+       ZoneType_Japan = 1,
+       ZoneType_Europe = 2
+} WZONETYPE;
 
 #define ADHOC  0
 #define INFRA  1
@@ -85,8 +81,7 @@ typedef enum tagWZONETYPE {
 #define ADHOC_STARTED     1
 #define ADHOC_JOINTED     2
 
-
-#define PHY80211a          0
+#define PHY80211a       0
 #define PHY80211b       1
 #define PHY80211g       2
 
@@ -115,25 +110,20 @@ typedef struct tagSCmdRequest {
 //
 
 typedef struct tagSCmdScan {
-
        u8 ssid[SSID_MAXLEN + 2];
-
 } SCmdScan, *PSCmdScan;
 
-
 //
 // BSS Join
 //
 
 typedef struct tagSCmdBSSJoin {
-
-    u16            wBSSType;
-    u16     wBBPType;
-    u8     ssid[SSID_MAXLEN + 2];
-    u32            uChannel;
-    bool bPSEnable;
-    bool bShareKeyAuth;
-
+       u16         wBSSType;
+       u16     wBBPType;
+       u8          ssid[SSID_MAXLEN + 2];
+       u32         uChannel;
+       bool bPSEnable;
+       bool bShareKeyAuth;
 } SCmdBSSJoin, *PSCmdBSSJoin;
 
 //
@@ -141,83 +131,67 @@ typedef struct tagSCmdBSSJoin {
 //
 
 typedef struct tagSCmdZoneTypeSet {
-
- bool bWrite;
- WZONETYPE  ZoneType;
-
+       bool bWrite;
+       WZONETYPE  ZoneType;
 } SCmdZoneTypeSet, *PSCmdZoneTypeSet;
 
 #ifdef WPA_SM_Transtatus
 typedef struct tagSWPAResult {
-         char  ifname[100];
-         u8 proto;
-         u8 key_mgmt;
-         u8 eap_type;
-         bool authenticated;
+       char    ifname[100];
+       u8 proto;
+       u8 key_mgmt;
+       u8 eap_type;
+       bool authenticated;
 } SWPAResult, *PSWPAResult;
 #endif
 
 typedef struct tagSCmdStartAP {
-
-    u16            wBSSType;
-    u16     wBBPType;
-    u8     ssid[SSID_MAXLEN + 2];
-    u32            uChannel;
-    u32     uBeaconInt;
-    bool bShareKeyAuth;
-    u8      byBasicRate;
-
+       u16         wBSSType;
+       u16     wBBPType;
+       u8          ssid[SSID_MAXLEN + 2];
+       u32         uChannel;
+       u32     uBeaconInt;
+       bool bShareKeyAuth;
+       u8      byBasicRate;
 } SCmdStartAP, *PSCmdStartAP;
 
-
 typedef struct tagSCmdSetWEP {
-
-    bool bEnableWep;
-    u8      byKeyIndex;
-    u8      abyWepKey[WEP_NKEYS][WEP_KEYMAXLEN];
-    bool bWepKeyAvailable[WEP_NKEYS];
-    u32     auWepKeyLength[WEP_NKEYS];
-
+       bool bEnableWep;
+       u8      byKeyIndex;
+       u8      abyWepKey[WEP_NKEYS][WEP_KEYMAXLEN];
+       bool bWepKeyAvailable[WEP_NKEYS];
+       u32     auWepKeyLength[WEP_NKEYS];
 } SCmdSetWEP, *PSCmdSetWEP;
 
-
-
 typedef struct tagSBSSIDItem {
-
        u32         uChannel;
-    u8      abyBSSID[BSSID_LEN];
-    u8      abySSID[SSID_MAXLEN + 1];
-    //2006-1116-01,<Modify> by NomadZhao
-    //u16          wBeaconInterval;
-    //u16          wCapInfo;
-    //u8      byNetType;
-    u8      byNetType;
-    u16            wBeaconInterval;
-    u16            wCapInfo;        // for address of byNetType at align 4
-
-    bool bWEPOn;
-    u32     uRSSI;
-
+       u8      abyBSSID[BSSID_LEN];
+       u8      abySSID[SSID_MAXLEN + 1];
+       //2006-1116-01,<Modify> by NomadZhao
+       //u16       wBeaconInterval;
+       //u16       wCapInfo;
+       //u8      byNetType;
+       u8      byNetType;
+       u16         wBeaconInterval;
+       u16         wCapInfo;        // for address of byNetType at align 4
+
+       bool bWEPOn;
+       u32     uRSSI;
 } SBSSIDItem;
 
-
 typedef struct tagSBSSIDList {
-
        u32                 uItem;
        SBSSIDItem      sBSSIDList[0];
 } SBSSIDList, *PSBSSIDList;
 
-
 typedef struct tagSCmdLinkStatus {
-
-    bool bLink;
+       bool bLink;
        u16   wBSSType;
        u8      byState;
-    u8      abyBSSID[BSSID_LEN];
-    u8      abySSID[SSID_MAXLEN + 2];
-    u32     uChannel;
-    u32     uLinkRate;
-
+       u8      abyBSSID[BSSID_LEN];
+       u8      abySSID[SSID_MAXLEN + 2];
+       u32     uChannel;
+       u32     uLinkRate;
 } SCmdLinkStatus, *PSCmdLinkStatus;
 
 //
@@ -238,15 +212,13 @@ typedef struct tagSDot11MIBCount {
        u32 FCSErrorCount;
 } SDot11MIBCount, *PSDot11MIBCount;
 
-
-
 //
 // statistic counter
 //
 typedef struct tagSStatMIBCount {
-    //
-    // ISR status count
-    //
+       //
+       // ISR status count
+       //
        u32   dwIsrTx0OK;
        u32   dwIsrTx1OK;
        u32   dwIsrBeaconTxOK;
@@ -256,12 +228,12 @@ typedef struct tagSStatMIBCount {
        u32   dwIsrUnrecoverableError;
        u32   dwIsrSoftInterrupt;
        u32   dwIsrRxNoBuf;
-    /////////////////////////////////////
+       /////////////////////////////////////
 
        u32   dwIsrUnknown;               // unknown interrupt count
 
-    // RSR status count
-    //
+       // RSR status count
+       //
        u32   dwRsrFrmAlgnErr;
        u32   dwRsrErr;
        u32   dwRsrCRCErr;
@@ -282,10 +254,10 @@ typedef struct tagSStatMIBCount {
        u32   dwRsrBroadcast;
        u32   dwRsrMulticast;
        u32   dwRsrDirected;
-    // 64-bit OID
+       // 64-bit OID
        u32   ullRsrOK;
 
-    // for some optional OIDs (64 bits) and DMI support
+       // for some optional OIDs (64 bits) and DMI support
        u32   ullRxBroadcastBytes;
        u32   ullRxMulticastBytes;
        u32   ullRxDirectedBytes;
@@ -301,13 +273,13 @@ typedef struct tagSStatMIBCount {
        u32   dwRsrRxFrmLen512_1023;
        u32   dwRsrRxFrmLen1024_1518;
 
-    // TSR0,1 status count
-    //
+       // TSR0,1 status count
+       //
        u32   dwTsrTotalRetry[2];        // total collision retry count
        u32   dwTsrOnceRetry[2];         // this packet only occur one collision
        u32   dwTsrMoreThanOnceRetry[2]; // this packet occur more than one collision
        u32   dwTsrRetry[2];             // this packet has ever occur collision,
-                                       // that is (dwTsrOnceCollision0 + dwTsrMoreThanOnceCollision0)
+       // that is (dwTsrOnceCollision0 + dwTsrMoreThanOnceCollision0)
        u32   dwTsrACKData[2];
        u32   dwTsrErr[2];
        u32   dwAllTsrOK[2];
@@ -320,23 +292,23 @@ typedef struct tagSStatMIBCount {
        u32   dwTsrMulticast[2];
        u32   dwTsrDirected[2];
 
-    // RD/TD count
+       // RD/TD count
        u32   dwCntRxFrmLength;
        u32   dwCntTxBufLength;
 
        u8    abyCntRxPattern[16];
        u8    abyCntTxPattern[16];
 
-    // Software check....
+       // Software check....
        u32   dwCntRxDataErr;             // rx buffer data software compare CRC err count
        u32   dwCntDecryptErr;            // rx buffer data software compare CRC err count
        u32   dwCntRxICVErr;              // rx buffer data software compare CRC err count
        u32    idxRxErrorDesc;             // index for rx data error RD
 
-    // 64-bit OID
+       // 64-bit OID
        u32   ullTsrOK[2];
 
-    // for some optional OIDs (64 bits) and DMI support
+       // for some optional OIDs (64 bits) and DMI support
        u32   ullTxBroadcastFrames[2];
        u32   ullTxMulticastFrames[2];
        u32   ullTxDirectedFrames[2];
@@ -345,49 +317,38 @@ typedef struct tagSStatMIBCount {
        u32   ullTxDirectedBytes[2];
 } SStatMIBCount, *PSStatMIBCount;
 
-
 typedef struct tagSNodeItem {
-    // STA info
-    u16            wAID;
-    u8             abyMACAddr[6];
-    u16            wTxDataRate;
-    u16            wInActiveCount;
-    u16            wEnQueueCnt;
-    u16            wFlags;
-    bool bPWBitOn;
-    u8             byKeyIndex;
-    u16            wWepKeyLength;
-    u8            abyWepKey[WEP_KEYMAXLEN];
-    // Auto rate fallback vars
-    bool bIsInFallback;
-    u32            uTxFailures;
-    u32            uTxAttempts;
-    u16            wFailureRatio;
-
+       // STA info
+       u16            wAID;
+       u8             abyMACAddr[6];
+       u16            wTxDataRate;
+       u16            wInActiveCount;
+       u16            wEnQueueCnt;
+       u16            wFlags;
+       bool bPWBitOn;
+       u8             byKeyIndex;
+       u16            wWepKeyLength;
+       u8            abyWepKey[WEP_KEYMAXLEN];
+       // Auto rate fallback vars
+       bool bIsInFallback;
+       u32            uTxFailures;
+       u32            uTxAttempts;
+       u16            wFailureRatio;
 } SNodeItem;
 
-
 typedef struct tagSNodeList {
-
        u32                 uItem;
        SNodeItem       sNodeList[0];
-
 } SNodeList, *PSNodeList;
 
-
-
 typedef struct tagSCmdValue {
-
        u32 dwValue;
-
 } SCmdValue,  *PSCmdValue;
 
-
 //
 // hostapd & viawget ioctl related
 //
 
-
 // VIAGWET_IOCTL_HOSTAPD ioctl() cmd:
 enum {
        VIAWGET_HOSTAPD_FLUSH = 1,
@@ -404,14 +365,11 @@ enum {
        VIAWGET_HOSTAPD_STA_CLEAR_STATS = 12,
 };
 
-
-#define VIAWGET_HOSTAPD_GENERIC_ELEMENT_HDR_LEN \
-((int) (&((struct viawget_hostapd_param *) 0)->u.generic_elem.data))
+#define VIAWGET_HOSTAPD_GENERIC_ELEMENT_HDR_LEN                                \
+       ((int)(&((struct viawget_hostapd_param *)0)->u.generic_elem.data))
 
 // Maximum length for algorithm names (-1 for nul termination) used in ioctl()
 
-
-
 struct viawget_hostapd_param {
        u32 cmd;
        u8 sta_addr[6];
@@ -464,12 +422,8 @@ struct viawget_hostapd_param {
 
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Types  ------------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
-
-
 #endif //__IOCMD_H__
index afed6e33dfc78ed7e8bf8cdb1756616fecb00034..2ae8116869eb1754411cd53633ce5f2186f8acf5 100644 (file)
@@ -41,7 +41,7 @@
 static int msglevel = MSG_LEVEL_INFO;
 
 #ifdef WPA_SM_Transtatus
-       SWPAResult wpa_Result;
+SWPAResult wpa_Result;
 #endif
 
 int private_ioctl(PSDevice pDevice, struct ifreq *rq)
@@ -104,9 +104,9 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
                        BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
 
                if (pItemSSID->len != 0)
-                       bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
+                       bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
                else
-                       bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
+                       bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
                spin_unlock_irq(&pDevice->lock);
                break;
 
@@ -202,8 +202,8 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
                netif_stop_queue(pDevice->dev);
                spin_lock_irq(&pDevice->lock);
                pMgmt->eCurrState = WMAC_STATE_IDLE;
-               bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
-               bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
+               bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
+               bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
                spin_unlock_irq(&pDevice->lock);
                break;
 
@@ -267,7 +267,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
                        memcpy(sLinkStatus.abySSID, pItemSSID->abySSID, pItemSSID->len);
                        memcpy(sLinkStatus.abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
                        sLinkStatus.uLinkRate = pMgmt->sNodeDBTable[0].wTxDataRate;
-                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Link Success!\n");
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Link Success!\n");
                } else {
                        sLinkStatus.bLink = false;
                        sLinkStatus.uLinkRate = 0;
@@ -311,7 +311,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
                }
                pList->uItem = sList.uItem;
                pBSS = &(pMgmt->sBSSList[0]);
-               for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
+               for (ii = 0, jj = 0; jj < MAX_BSS_NUM; jj++) {
                        pBSS = &(pMgmt->sBSSList[jj]);
                        if (pBSS->bActive) {
                                pList->sBSSIDList[ii].uChannel = pBSS->uChannel;
@@ -540,7 +540,7 @@ int private_ioctl(PSDevice pDevice, struct ifreq *rq)
                }
 
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Support Rate= %*ph\n",
-                               4, pMgmt->abyIBSSSuppRates + 2);
+                       4, pMgmt->abyIBSSSuppRates + 2);
 
                netif_stop_queue(pDevice->dev);
                spin_lock_irq(&pDevice->lock);
index ba85015c11b639abe5fb99e9bb6608d2b946fa45..ae240fd71a158143a66385c46a7b01caf2695d5b 100644 (file)
@@ -33,7 +33,6 @@
 
 /*---------------------  Export Definitions -------------------------*/
 
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 int private_ioctl(PSDevice pDevice, struct ifreq *rq);
 
 /*
-void vConfigWEPKey (
-    PSDevice pDevice,
-    unsigned long dwKeyIndex,
-    unsigned char *pbyKey,
-    unsigned long uKeyLength
-    );
+  void vConfigWEPKey(
+  PSDevice pDevice,
+  unsigned long dwKeyIndex,
+  unsigned char *pbyKey,
+  unsigned long uKeyLength
+);
 */
 
 #endif // __IOCTL_H__
-
-
-
index 33ae054478dc568fecfb39e4fc98e0e6950522bd..bfea01f5e00aabfd00eb83598209f1e6ec292de3 100644 (file)
 
 /*---------------------  Export Definitions -------------------------*/
 
-
 #define WPA_IE_LEN 64
 
-
 //WPA related
 /*
-typedef enum { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP } wpa_alg;
-typedef enum { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP,
-              CIPHER_WEP104 } wpa_cipher;
-typedef enum { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE,
-              KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE } wpa_key_mgmt;
+  typedef enum { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP } wpa_alg;
+  typedef enum { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP,
+  CIPHER_WEP104 } wpa_cipher;
+  typedef enum { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE,
+  KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE } wpa_key_mgmt;
 */
 
 enum {
@@ -54,10 +52,9 @@ enum {
        VIAWGET_SET_DROP_UNENCRYPT = 7,
        VIAWGET_SET_DEAUTHENTICATE = 8,
        VIAWGET_SET_ASSOCIATE = 9,
-       VIAWGET_SET_DISASSOCIATE= 10
+       VIAWGET_SET_DISASSOCIATE = 10
 };
 
-
 enum {
        VIAWGET_ASSOC_MSG = 1,
        VIAWGET_DISASSOC_MSG = 2,
@@ -67,8 +64,6 @@ enum {
        VIAWGET_DEVICECLOSE_MSG = 6
 };
 
-
-
 #pragma pack(1)
 typedef struct viawget_wpa_header {
        u8 type;
@@ -76,8 +71,6 @@ typedef struct viawget_wpa_header {
        u16 resp_ie_len;
 } viawget_wpa_header;
 
-
-
 struct viawget_wpa_param {
        u32 cmd;
        u8 addr[6];
@@ -88,27 +81,27 @@ struct viawget_wpa_param {
                } generic_elem;
 
                struct {
-               u8 bssid[6];
+                       u8 bssid[6];
                        u8 ssid[32];
                        u8 ssid_len;
-               u8 *wpa_ie;
-               u16 wpa_ie_len;
-               int pairwise_suite;
-               int group_suite;
-               int key_mgmt_suite;
-               int auth_alg;
-               int mode;
+                       u8 *wpa_ie;
+                       u16 wpa_ie_len;
+                       int pairwise_suite;
+                       int group_suite;
+                       int key_mgmt_suite;
+                       int auth_alg;
+                       int mode;
 
                } wpa_associate;
 
                struct {
-               int alg_name;
-               u16 key_index;
-               u16 set_tx;
-               u8 *seq;
-               u16 seq_len;
-               u8 *key;
-               u16 key_len;
+                       int alg_name;
+                       u16 key_index;
+                       u16 set_tx;
+                       u8 *seq;
+                       u16 seq_len;
+                       u8 *key;
+                       u16 key_len;
                } wpa_key;
 
                struct {
@@ -122,7 +115,6 @@ struct viawget_wpa_param {
                } scan_results;
 
        } u;
-
 };
 
 #pragma pack(1)
@@ -148,12 +140,8 @@ struct viawget_scan_result {
 
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Types  ------------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
-
-
 #endif //__IOWPA_H__
index 5cdda8dab854565cf11f535ba3d686418f8a8101..9de698ef25f5de0511b2f3ebc98c197c4f6566f8 100644 (file)
@@ -57,20 +57,17 @@ extern unsigned short TxRate_iwconfig;//2008-5-8 <add> by chester
 #endif
 
 static const long frequency_list[] = {
-    2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
-    4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
-    5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
-    5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
-    5700, 5745, 5765, 5785, 5805, 5825
-       };
-
+       2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
+       4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
+       5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
+       5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
+       5700, 5745, 5765, 5785, 5805, 5825
+};
 
 /*---------------------  Static Classes  ----------------------------*/
 
-
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-static int          msglevel                =MSG_LEVEL_INFO;
-
+static int msglevel = MSG_LEVEL_INFO;
 
 /*---------------------  Static Variables  --------------------------*/
 /*---------------------  Static Functions  --------------------------*/
@@ -83,13 +80,13 @@ struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
        long ldBm;
 
        pDevice->wstats.status = pDevice->eOPMode;
-       #ifdef Calcu_LinkQual
-          if(pDevice->scStatistic.LinkQuality > 100)
-              pDevice->scStatistic.LinkQuality = 100;
-               pDevice->wstats.qual.qual =(unsigned char) pDevice->scStatistic.LinkQuality;
-       #else
+#ifdef Calcu_LinkQual
+       if (pDevice->scStatistic.LinkQuality > 100)
+               pDevice->scStatistic.LinkQuality = 100;
+       pDevice->wstats.qual.qual = (unsigned char)pDevice->scStatistic.LinkQuality;
+#else
        pDevice->wstats.qual.qual = pDevice->byCurrSQ;
-       #endif
+#endif
        RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
        pDevice->wstats.qual.level = ldBm;
        //pDevice->wstats.qual.level = 0x100 - pDevice->uCurrRSSI;
@@ -105,29 +102,25 @@ struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
        return &pDevice->wstats;
 }
 
-
-
 /*------------------------------------------------------------------*/
 
-
 static int iwctl_commit(struct net_device *dev,
-                             struct iw_request_info *info,
-                             void *wrq,
-                             char *extra)
+                       struct iw_request_info *info,
+                       void *wrq,
+                       char *extra)
 {
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWCOMMIT \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWCOMMIT \n");
 
        return 0;
-
 }
 /*
  * Wireless Handler : get protocol name
  */
 
 int iwctl_giwname(struct net_device *dev,
-                        struct iw_request_info *info,
-                        char *wrq,
-                        char *extra)
+                 struct iw_request_info *info,
+                 char *wrq,
+                 char *extra)
 {
        strcpy(wrq, "802.11-a/b/g");
        return 0;
@@ -138,83 +131,77 @@ int iwctl_giwname(struct net_device *dev,
  */
 
 int iwctl_siwscan(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_point *wrq,
-             char *extra)
+                 struct iw_request_info *info,
+                 struct iw_point *wrq,
+                 char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
-        PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
        struct iw_scan_req  *req = (struct iw_scan_req *)extra;
        unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
-       PWLAN_IE_SSID       pItemSSID=NULL;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSCAN \n");
+       PWLAN_IE_SSID pItemSSID = NULL;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSCAN \n");
 
-
-if(pDevice->byReAssocCount > 0) {   //reject scan when re-associating!
+       if (pDevice->byReAssocCount > 0) {   //reject scan when re-associating!
 //send scan event to wpa_Supplicant
-  union iwreq_data wrqu;
- PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
- memset(&wrqu, 0, sizeof(wrqu));
- wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
-  return 0;
-}
+               union iwreq_data wrqu;
              PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
              memset(&wrqu, 0, sizeof(wrqu));
              wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
+               return 0;
+       }
 
        spin_lock_irq(&pDevice->lock);
-        BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
+       BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
 
 //mike add: active scan OR passive scan OR desire_ssid scan
- if(wrq->length == sizeof(struct iw_scan_req)) {
-   if (wrq->flags & IW_SCAN_THIS_ESSID)  {                               //desire_ssid scan
-       memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-       pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
-       pItemSSID->byElementID = WLAN_EID_SSID;
-       memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
-         if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
-           if(req->essid_len>0)
-               pItemSSID->len = req->essid_len - 1;
-         }
-       else
-         pItemSSID->len = req->essid_len;
-         pMgmt->eScanType = WMAC_SCAN_PASSIVE;
-         PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID)abyScanSSID)->abySSID,
-                                                                                                       ((PWLAN_IE_SSID)abyScanSSID)->len);
-       bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
-       spin_unlock_irq(&pDevice->lock);
+       if (wrq->length == sizeof(struct iw_scan_req)) {
+               if (wrq->flags & IW_SCAN_THIS_ESSID)  {                               //desire_ssid scan
+                       memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+                       pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
+                       pItemSSID->byElementID = WLAN_EID_SSID;
+                       memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
+                       if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
+                               if (req->essid_len > 0)
+                                       pItemSSID->len = req->essid_len - 1;
+                       } else
+                               pItemSSID->len = req->essid_len;
+                       pMgmt->eScanType = WMAC_SCAN_PASSIVE;
+                       PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n", ((PWLAN_IE_SSID)abyScanSSID)->abySSID,
+                               ((PWLAN_IE_SSID)abyScanSSID)->len);
+                       bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
+                       spin_unlock_irq(&pDevice->lock);
+
+                       return 0;
+               } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {          //passive scan
+                       pMgmt->eScanType = WMAC_SCAN_PASSIVE;
+               }
+       } else {           //active scan
+               pMgmt->eScanType = WMAC_SCAN_ACTIVE;
+       }
 
-       return 0;
-   }
-   else if(req->scan_type == IW_SCAN_TYPE_PASSIVE) {          //passive scan
-       pMgmt->eScanType = WMAC_SCAN_PASSIVE;
-   }
- }
- else {           //active scan
-     pMgmt->eScanType = WMAC_SCAN_ACTIVE;
- }
-
-        pMgmt->eScanType = WMAC_SCAN_PASSIVE;
-          //printk("SIOCSIWSCAN:WLAN_CMD_BSSID_SCAN\n");
-       bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
+       pMgmt->eScanType = WMAC_SCAN_PASSIVE;
+       bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
        spin_unlock_irq(&pDevice->lock);
 
        return 0;
 }
 
-
 /*
  * Wireless Handler : get scan results
  */
 
 int iwctl_giwscan(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_point *wrq,
-             char *extra)
+                 struct iw_request_info *info,
+                 struct iw_point *wrq,
+                 char *extra)
 {
-    int ii, jj, kk;
+       int ii, jj, kk;
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
-    PKnownBSS           pBSS;
-    PWLAN_IE_SSID       pItemSSID;
-    PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+       PKnownBSS           pBSS;
+       PWLAN_IE_SSID       pItemSSID;
+       PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
        char *current_ev = extra;
        char *end_buf = extra + IW_SCAN_MAX_DATA;
        char *current_val = NULL;
@@ -222,181 +209,177 @@ int iwctl_giwscan(struct net_device *dev,
        long ldBm;
        char buf[MAX_WPA_IE_LEN * 2 + 30];
 
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN \n");
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN \n");
-
-    if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
-        // In scanning..
+       if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
+               // In scanning..
                return -EAGAIN;
        }
        pBSS = &(pMgmt->sBSSList[0]);
-    for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
+       for (ii = 0, jj = 0; jj < MAX_BSS_NUM; jj++) {
                if (current_ev >= end_buf)
                        break;
-        pBSS = &(pMgmt->sBSSList[jj]);
-        if (pBSS->bActive) {
-               //ADD mac address
-                   memset(&iwe, 0, sizeof(iwe));
-                   iwe.cmd = SIOCGIWAP;
-                   iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
+               pBSS = &(pMgmt->sBSSList[jj]);
+               if (pBSS->bActive) {
+                       //ADD mac address
+                       memset(&iwe, 0, sizeof(iwe));
+                       iwe.cmd = SIOCGIWAP;
+                       iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
                        memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
-                            current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
-                 //ADD ssid
-                    memset(&iwe, 0, sizeof(iwe));
-                      iwe.cmd = SIOCGIWESSID;
-                      pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
-                       iwe.u.data.length = pItemSSID->len;
-                       iwe.u.data.flags = 1;
-                      current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
-               //ADD mode
-                   memset(&iwe, 0, sizeof(iwe));
-                   iwe.cmd = SIOCGIWMODE;
-            if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
-                       iwe.u.mode = IW_MODE_INFRA;
-            }
-            else {
-                iwe.u.mode = IW_MODE_ADHOC;
-                   }
-               iwe.len = IW_EV_UINT_LEN;
-                      current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe,  IW_EV_UINT_LEN);
-           //ADD frequency
-            pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
-            pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
-            memset(&iwe, 0, sizeof(iwe));
-               iwe.cmd = SIOCGIWFREQ;
-               iwe.u.freq.m = pBSS->uChannel;
-               iwe.u.freq.e = 0;
-               iwe.u.freq.i = 0;
-                   current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
-            //2008-0409-04, <Add> by Einsn Liu
+                       current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
+                       //ADD ssid
+                       memset(&iwe, 0, sizeof(iwe));
+                       iwe.cmd = SIOCGIWESSID;
+                       pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
+                       iwe.u.data.length = pItemSSID->len;
+                       iwe.u.data.flags = 1;
+                       current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
+                       //ADD mode
+                       memset(&iwe, 0, sizeof(iwe));
+                       iwe.cmd = SIOCGIWMODE;
+                       if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
+                               iwe.u.mode = IW_MODE_INFRA;
+                       } else {
+                               iwe.u.mode = IW_MODE_ADHOC;
+                       }
+                       iwe.len = IW_EV_UINT_LEN;
+                       current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
+                       //ADD frequency
+                       pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
+                       pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
+                       memset(&iwe, 0, sizeof(iwe));
+                       iwe.cmd = SIOCGIWFREQ;
+                       iwe.u.freq.m = pBSS->uChannel;
+                       iwe.u.freq.e = 0;
+                       iwe.u.freq.i = 0;
+                       current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
+                       //2008-0409-04, <Add> by Einsn Liu
                        {
-                       int f = (int)pBSS->uChannel - 1;
-                       if(f < 0)f = 0;
-                       iwe.u.freq.m = frequency_list[f] * 100000;
-                       iwe.u.freq.e = 1;
+                               int f = (int)pBSS->uChannel - 1;
+                               if (f < 0)f = 0;
+                               iwe.u.freq.m = frequency_list[f] * 100000;
+                               iwe.u.freq.e = 1;
                        }
-                   current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
-                       //ADD quality
-            memset(&iwe, 0, sizeof(iwe));
-               iwe.cmd = IWEVQUAL;
-               RFvRSSITodBm(pDevice, (unsigned char)(pBSS->uRSSI), &ldBm);
-                   iwe.u.qual.level = ldBm;
-               iwe.u.qual.noise = 0;
+                       current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
+                       //ADD quality
+                       memset(&iwe, 0, sizeof(iwe));
+                       iwe.cmd = IWEVQUAL;
+                       RFvRSSITodBm(pDevice, (unsigned char)(pBSS->uRSSI), &ldBm);
+                       iwe.u.qual.level = ldBm;
+                       iwe.u.qual.noise = 0;
 //2008-0409-01, <Add> by Einsn Liu
-                       if(-ldBm<50){
+                       if (-ldBm < 50) {
                                iwe.u.qual.qual = 100;
-                       }else  if(-ldBm > 90) {
-                                iwe.u.qual.qual = 0;
-                       }else {
-                               iwe.u.qual.qual=(40-(-ldBm-50))*100/40;
+                       } else if (-ldBm > 90) {
+                               iwe.u.qual.qual = 0;
+                       } else {
+                               iwe.u.qual.qual = (40 - (-ldBm - 50)) * 100 / 40;
+                       }
+                       iwe.u.qual.updated = 7;
+
+                       //  iwe.u.qual.qual = 0;
+                       current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
+
+                       memset(&iwe, 0, sizeof(iwe));
+                       iwe.cmd = SIOCGIWENCODE;
+                       iwe.u.data.length = 0;
+                       if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
+                               iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
+                       } else {
+                               iwe.u.data.flags = IW_ENCODE_DISABLED;
+                       }
+                       current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
+
+                       memset(&iwe, 0, sizeof(iwe));
+                       iwe.cmd = SIOCGIWRATE;
+                       iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
+                       current_val = current_ev + IW_EV_LCP_LEN;
+
+                       for (kk = 0; kk < 12; kk++) {
+                               if (pSuppRates->abyRates[kk] == 0)
+                                       break;
+                               // Bit rate given in 500 kb/s units (+ 0x80)
+                               iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
+                               current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
                        }
-                       iwe.u.qual.updated=7;
-
-             //  iwe.u.qual.qual = 0;
-            current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
-
-            memset(&iwe, 0, sizeof(iwe));
-            iwe.cmd = SIOCGIWENCODE;
-            iwe.u.data.length = 0;
-            if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
-                iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
-            }else {
-                iwe.u.data.flags = IW_ENCODE_DISABLED;
-            }
-            current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
-
-            memset(&iwe, 0, sizeof(iwe));
-            iwe.cmd = SIOCGIWRATE;
-               iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
-               current_val = current_ev + IW_EV_LCP_LEN;
-
-                       for (kk = 0 ; kk < 12 ; kk++) {
-                       if (pSuppRates->abyRates[kk] == 0)
-                               break;
-                       // Bit rate given in 500 kb/s units (+ 0x80)
-                       iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
-                           current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
+                       for (kk = 0; kk < 8; kk++) {
+                               if (pExtSuppRates->abyRates[kk] == 0)
+                                       break;
+                               // Bit rate given in 500 kb/s units (+ 0x80)
+                               iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
+                               current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
+                       }
+
+                       if ((current_val - current_ev) > IW_EV_LCP_LEN)
+                               current_ev = current_val;
+
+                       memset(&iwe, 0, sizeof(iwe));
+                       iwe.cmd = IWEVCUSTOM;
+                       sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
+                       iwe.u.data.length = strlen(buf);
+                       current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, buf);
+
+                       if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
+                               memset(&iwe, 0, sizeof(iwe));
+                               iwe.cmd = IWEVGENIE;
+                               iwe.u.data.length = pBSS->wWPALen;
+                               current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byWPAIE);
+                       }
+
+                       if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
+                               memset(&iwe, 0, sizeof(iwe));
+                               iwe.cmd = IWEVGENIE;
+                               iwe.u.data.length = pBSS->wRSNLen;
+                               current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byRSNIE);
+                       }
+
                }
-                       for (kk = 0 ; kk < 8 ; kk++) {
-                       if (pExtSuppRates->abyRates[kk] == 0)
-                               break;
-                       // Bit rate given in 500 kb/s units (+ 0x80)
-                       iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
-                          current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
-               }
-
-               if((current_val - current_ev) > IW_EV_LCP_LEN)
-                       current_ev = current_val;
-
-            memset(&iwe, 0, sizeof(iwe));
-            iwe.cmd = IWEVCUSTOM;
-            sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
-            iwe.u.data.length = strlen(buf);
-             current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, buf);
-
-            if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
-                memset(&iwe, 0, sizeof(iwe));
-                iwe.cmd = IWEVGENIE;
-                iwe.u.data.length = pBSS->wWPALen;
-                current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byWPAIE);
-            }
-
-            if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
-                memset(&iwe, 0, sizeof(iwe));
-                iwe.cmd = IWEVGENIE;
-                iwe.u.data.length = pBSS->wRSNLen;
-                current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byRSNIE);
-            }
-
-        }
-    }// for
+       }// for
 
        wrq->length = current_ev - extra;
        return 0;
-
 }
 
-
 /*
  * Wireless Handler : set frequency or channel
  */
 
 int iwctl_siwfreq(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_freq *wrq,
-             char *extra)
+                 struct iw_request_info *info,
+                 struct iw_freq *wrq,
+                 char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
        int rc = 0;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ \n");
 
        // If setting by frequency, convert to a channel
-       if((wrq->e == 1) &&
-          (wrq->m >= (int) 2.412e8) &&
-          (wrq->m <= (int) 2.487e8)) {
+       if ((wrq->e == 1) &&
+           (wrq->m >= (int) 2.412e8) &&
+           (wrq->m <= (int) 2.487e8)) {
                int f = wrq->m / 100000;
                int c = 0;
-               while((c < 14) && (f != frequency_list[c]))
+               while ((c < 14) && (f != frequency_list[c]))
                        c++;
                wrq->e = 0;
                wrq->m = c + 1;
        }
        // Setting by channel number
-       if((wrq->m > 14) || (wrq->e > 0))
+       if ((wrq->m > 14) || (wrq->e > 0))
                rc = -EOPNOTSUPP;
        else {
                int channel = wrq->m;
-               if((channel < 1) || (channel > 14)) {
+               if ((channel < 1) || (channel > 14)) {
                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m);
                        rc = -EINVAL;
                } else {
-                         // Yes ! We can set it !!!
-              DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
-                         pDevice->uChannel = channel;
-                        //2007-0207-04,<Add> by EinsnLiu
-                        //Make change effect at once
-                         pDevice->bCommit = true;
+                       // Yes ! We can set it !!!
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
+                       pDevice->uChannel = channel;
+                       //2007-0207-04,<Add> by EinsnLiu
+                       //Make change effect at once
+                       pDevice->bCommit = true;
                }
        }
 
@@ -408,14 +391,14 @@ int iwctl_siwfreq(struct net_device *dev,
  */
 
 int iwctl_giwfreq(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_freq *wrq,
-             char *extra)
+                 struct iw_request_info *info,
+                 struct iw_freq *wrq,
+                 char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ \n");
 
 #ifdef WEXT_USECHANNELS
        wrq->m = (int)pMgmt->uCurrChannel;
@@ -423,8 +406,8 @@ int iwctl_giwfreq(struct net_device *dev,
 #else
        {
                int f = (int)pMgmt->uCurrChannel - 1;
-               if(f < 0)
-                  f = 0;
+               if (f < 0)
+                       f = 0;
                wrq->m = frequency_list[f] * 100000;
                wrq->e = 1;
        }
@@ -438,59 +421,58 @@ int iwctl_giwfreq(struct net_device *dev,
  */
 
 int iwctl_siwmode(struct net_device *dev,
-             struct iw_request_info *info,
-             __u32 *wmode,
-             char *extra)
+                 struct iw_request_info *info,
+                 __u32 *wmode,
+                 char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
-    int rc = 0;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE \n");
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+       int rc = 0;
 
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Can't set operation mode, hostapd is running \n");
-        return rc;
-    }
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE \n");
 
-       switch(*wmode) {
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Can't set operation mode, hostapd is running \n");
+               return rc;
+       }
 
+       switch (*wmode) {
        case IW_MODE_ADHOC:
-           if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
-            pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
-            if (pDevice->flags & DEVICE_FLAGS_OPENED) {
-                       pDevice->bCommit = true;
-                   }
+               if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
+                       pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
+                       if (pDevice->flags & DEVICE_FLAGS_OPENED) {
+                               pDevice->bCommit = true;
+                       }
                }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
                break;
        case IW_MODE_AUTO:
        case IW_MODE_INFRA:
-           if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
-            pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
-            if (pDevice->flags & DEVICE_FLAGS_OPENED) {
-                       pDevice->bCommit = true;
-                   }
+               if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
+                       pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
+                       if (pDevice->flags & DEVICE_FLAGS_OPENED) {
+                               pDevice->bCommit = true;
+                       }
                }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
                break;
        case IW_MODE_MASTER:
 
-        pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
+               pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
                rc = -EOPNOTSUPP;
                break;
 
-           if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
-            pMgmt->eConfigMode = WMAC_CONFIG_AP;
-            if (pDevice->flags & DEVICE_FLAGS_OPENED) {
-                       pDevice->bCommit = true;
-                   }
+               if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
+                       pMgmt->eConfigMode = WMAC_CONFIG_AP;
+                       if (pDevice->flags & DEVICE_FLAGS_OPENED) {
+                               pDevice->bCommit = true;
+                       }
                }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
                break;
 
        case IW_MODE_REPEAT:
-        pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
+               pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
                rc = -EOPNOTSUPP;
                break;
        default:
@@ -505,22 +487,21 @@ int iwctl_siwmode(struct net_device *dev,
  */
 
 int iwctl_giwmode(struct net_device *dev,
-             struct iw_request_info *info,
-             __u32 *wmode,
-             char *extra)
+                 struct iw_request_info *info,
+                 __u32 *wmode,
+                 char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
-
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE \n");
        // If not managed, assume it's ad-hoc
        switch (pMgmt->eConfigMode) {
        case WMAC_CONFIG_ESS_STA:
                *wmode = IW_MODE_INFRA;
                break;
        case WMAC_CONFIG_IBSS_STA:
-        *wmode = IW_MODE_ADHOC;
+               *wmode = IW_MODE_ADHOC;
                break;
        case WMAC_CONFIG_AUTO:
                *wmode = IW_MODE_INFRA;
@@ -535,22 +516,20 @@ int iwctl_giwmode(struct net_device *dev,
        return 0;
 }
 
-
 /*
  * Wireless Handler : get capability range
  */
 
 int iwctl_giwrange(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra)
+                  struct iw_request_info *info,
+                  struct iw_point *wrq,
+                  char *extra)
 {
-       struct iw_range *range = (struct iw_range *) extra;
-       int             i,k;
-    unsigned char abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
-
+       struct iw_range *range = (struct iw_range *)extra;
+       int i, k;
+       unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE \n");
        if (wrq->pointer) {
                wrq->length = sizeof(struct iw_range);
                memset(range, 0, sizeof(struct iw_range));
@@ -560,25 +539,25 @@ int iwctl_giwrange(struct net_device *dev,
                // Should be based on cap_rid.country to give only
                //  what the current card support
                k = 0;
-               for(i = 0; i < 14; i++) {
+               for (i = 0; i < 14; i++) {
                        range->freq[k].i = i + 1; // List index
                        range->freq[k].m = frequency_list[i] * 100000;
                        range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
                }
                range->num_frequency = k;
                // Hum... Should put the right values there
-            #ifdef Calcu_LinkQual
-                 range->max_qual.qual = 100;
-            #else
+#ifdef Calcu_LinkQual
+               range->max_qual.qual = 100;
+#else
                range->max_qual.qual = 255;
-            #endif
+#endif
                range->max_qual.level = 0;
                range->max_qual.noise = 0;
                range->sensitivity = 255;
 
-               for(i = 0 ; i < 13 ; i++) {
+               for (i = 0; i < 13; i++) {
                        range->bitrate[i] = abySupportedRates[i] * 500000;
-                       if(range->bitrate[i] == 0)
+                       if (range->bitrate[i] == 0)
                                break;
                }
                range->num_bitrates = i;
@@ -586,7 +565,7 @@ int iwctl_giwrange(struct net_device *dev,
                // Set an indication of the max TCP throughput
                // in bit/s that we can expect using this interface.
                //  May be use for QoS stuff... Jean II
-               if(i > 2)
+               if (i > 2)
                        range->throughput = 5 * 1000 * 1000;
                else
                        range->throughput = 1.5 * 1000 * 1000;
@@ -596,20 +575,19 @@ int iwctl_giwrange(struct net_device *dev,
                range->min_frag = 256;
                range->max_frag = 2312;
 
+               // the encoding capabilities
+               range->num_encoding_sizes = 3;
+               // 64(40) bits WEP
+               range->encoding_size[0] = 5;
+               // 128(104) bits WEP
+               range->encoding_size[1] = 13;
+               // 256 bits for WPA-PSK
+               range->encoding_size[2] = 32;
+               // 4 keys are allowed
+               range->max_encoding_tokens = 4;
 
-           // the encoding capabilities
-           range->num_encoding_sizes = 3;
-           // 64(40) bits WEP
-           range->encoding_size[0] = 5;
-           // 128(104) bits WEP
-           range->encoding_size[1] = 13;
-           // 256 bits for WPA-PSK
-           range->encoding_size[2] = 32;
-           // 4 keys are allowed
-           range->max_encoding_tokens = 4;
-
-           range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
-                   IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
+               range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
+                       IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
 
                range->min_pmp = 0;
                range->max_pmp = 1000000;// 1 secs
@@ -621,7 +599,7 @@ int iwctl_giwrange(struct net_device *dev,
 
                // Transmit Power - values are in mW
 
-        range->txpower[0] = 100;
+               range->txpower[0] = 100;
                range->num_txpower = 1;
                range->txpower_capa = IW_TXPOW_MWATT;
                range->we_version_source = SUPPORTED_WIRELESS_EXT;
@@ -641,65 +619,63 @@ int iwctl_giwrange(struct net_device *dev,
                range->avg_qual.noise = 0;
        }
 
-
        return 0;
 }
 
-
 /*
  * Wireless Handler : set ap mac address
  */
 
 int iwctl_siwap(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct sockaddr *wrq,
-             char *extra)
+               struct iw_request_info *info,
+               struct sockaddr *wrq,
+               char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
-    int rc = 0;
-    unsigned char ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAP \n");
-if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
-        // In scanning..
-     printk("SIOCSIWAP(??)-->In scanning...\n");
-   //  return -EAGAIN;
-  }
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+       int rc = 0;
+       unsigned char ZeroBSSID[WLAN_BSSID_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAP \n");
+       if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
+               // In scanning..
+               printk("SIOCSIWAP(??)-->In scanning...\n");
+               //  return -EAGAIN;
+       }
        if (wrq->sa_family != ARPHRD_ETHER)
                rc = -EINVAL;
        else {
                memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
-                               //2008-0409-05, <Add> by Einsn Liu
-               if((pDevice->bLinkPass == true) &&
-                     (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6)== 0)){
+               //2008-0409-05, <Add> by Einsn Liu
+               if ((pDevice->bLinkPass == true) &&
+                   (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6) == 0)) {
                        return rc;
+               }
+               //mike :add
+               if ((is_broadcast_ether_addr(pMgmt->abyDesireBSSID)) ||
+                   (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)) {
+                       PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
+                       return rc;
+               }
+               //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
+               //                  then ignore,because you don't known which one to be connect with??
+               {
+                       unsigned int ii, uSameBssidNum = 0;
+                       for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+                               if (pMgmt->sBSSList[ii].bActive &&
+                                   !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pMgmt->abyDesireBSSID)) {
+                                       uSameBssidNum++;
+                               }
+                       }
+                       if (uSameBssidNum >= 2) {  //hit: desired AP is in hidden ssid mode!!!
+                               PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
+                               return rc;
                        }
-       //mike :add
-        if ((is_broadcast_ether_addr(pMgmt->abyDesireBSSID)) ||
-            (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)){
-             PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
-               return rc;
-         }
-       //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
-       //                  then ignore,because you don't known which one to be connect with??
-               {
-           unsigned int ii , uSameBssidNum=0;
-                  for (ii = 0; ii < MAX_BSS_NUM; ii++) {
-                     if (pMgmt->sBSSList[ii].bActive &&
-                        !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pMgmt->abyDesireBSSID)) {
-                        uSameBssidNum++;
-                     }
-                  }
-            if(uSameBssidNum >= 2) {  //hit: desired AP is in hidden ssid mode!!!
-                 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
-               return rc;
-            }
-               }
-
-        if (pDevice->flags & DEVICE_FLAGS_OPENED) {
-                   pDevice->bCommit = true;
-               }
+               }
+
+               if (pDevice->flags & DEVICE_FLAGS_OPENED) {
+                       pDevice->bCommit = true;
+               }
        }
        return rc;
 }
@@ -709,49 +685,45 @@ if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
  */
 
 int iwctl_giwap(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct sockaddr *wrq,
-             char *extra)
+               struct iw_request_info *info,
+               struct sockaddr *wrq,
+               char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
 
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n");
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n");
+       memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
+       //2008-0410,<Modify> by Einsn Liu
+       if ((pDevice->bLinkPass == false) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
+               memset(wrq->sa_data, 0, 6);
 
-    memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
-   //2008-0410,<Modify> by Einsn Liu
-    if ((pDevice->bLinkPass == false) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
-        memset(wrq->sa_data, 0, 6);
-
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-        memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
-    }
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
+       }
 
        wrq->sa_family = ARPHRD_ETHER;
 
        return 0;
-
 }
 
-
 /*
  * Wireless Handler : get ap list
  */
 
 int iwctl_giwaplist(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra)
+                   struct iw_request_info *info,
+                   struct iw_point *wrq,
+                   char *extra)
 {
-       int ii,jj, rc = 0;
+       int ii, jj, rc = 0;
        struct sockaddr sock[IW_MAX_AP];
        struct iw_quality qual[IW_MAX_AP];
-       PSDevice                pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
-
+       PSDevice pDevice = (PSDevice)netdev_priv(dev);
+       PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");
        // Only super-user can see AP list
 
        if (!capable(CAP_NET_ADMIN)) {
@@ -760,15 +732,14 @@ int iwctl_giwaplist(struct net_device *dev,
        }
 
        if (wrq->pointer) {
-
                PKnownBSS pBSS = &(pMgmt->sBSSList[0]);
 
-               for (ii = 0, jj= 0; ii < MAX_BSS_NUM; ii++) {
-                   pBSS = &(pMgmt->sBSSList[ii]);
-            if (!pBSS->bActive)
-                continue;
-            if ( jj >= IW_MAX_AP)
-                break;
+               for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
+                       pBSS = &(pMgmt->sBSSList[ii]);
+                       if (!pBSS->bActive)
+                               continue;
+                       if (jj >= IW_MAX_AP)
+                               break;
                        memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6);
                        sock[jj].sa_family = ARPHRD_ETHER;
                        qual[jj].level = pBSS->uRSSI;
@@ -786,155 +757,144 @@ int iwctl_giwaplist(struct net_device *dev,
        return rc;
 }
 
-
 /*
  * Wireless Handler : set essid
  */
 
 int iwctl_siwessid(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra)
+                  struct iw_request_info *info,
+                  struct iw_point *wrq,
+                  char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
-    PWLAN_IE_SSID       pItemSSID;
-  //2008-0409-05, <Add> by Einsn Liu
-    unsigned char len;
-
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID \n");
- pDevice->fWPA_Authened = false;
-if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
-        // In scanning..
-     printk("SIOCSIWESSID(??)-->In scanning...\n");
-   //  return -EAGAIN;
-  }
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+       PWLAN_IE_SSID       pItemSSID;
+       //2008-0409-05, <Add> by Einsn Liu
+       unsigned char len;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID \n");
+       pDevice->fWPA_Authened = false;
+       if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
+               // In scanning..
+               printk("SIOCSIWESSID(??)-->In scanning...\n");
+               //  return -EAGAIN;
+       }
        // Check if we asked for `any'
-       if(wrq->flags == 0) {
+       if (wrq->flags == 0) {
                // Just send an empty SSID list
                memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-                  memset(pMgmt->abyDesireBSSID, 0xFF,6);
-           PRINT_K("set essid to 'any' \n");
-           #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-             //Unknown desired AP,so here need not associate??
-            //if(pDevice->bWPASuppWextEnabled == true)  {
-                  return 0;
-            // }
-            #endif
+               memset(pMgmt->abyDesireBSSID, 0xFF, 6);
+               PRINT_K("set essid to 'any' \n");
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+               return 0;
+#endif
        } else {
                // Set the SSID
                memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-        pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
-        pItemSSID->byElementID = WLAN_EID_SSID;
+               pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
+               pItemSSID->byElementID = WLAN_EID_SSID;
 
                memcpy(pItemSSID->abySSID, extra, wrq->length);
-        if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
-           if(wrq->length>0)
-               pItemSSID->len = wrq->length - 1;
-         }
-       else
-         pItemSSID->len = wrq->length;
-       printk("set essid to %s \n",pItemSSID->abySSID);
+               if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
+                       if (wrq->length > 0)
+                               pItemSSID->len = wrq->length - 1;
+               } else
+                       pItemSSID->len = wrq->length;
+               printk("set essid to %s \n", pItemSSID->abySSID);
                //2008-0409-05, <Add> by Einsn Liu
-       len=(pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)?pItemSSID->len:((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len;
-   if((pDevice->bLinkPass == true) &&
-       (memcmp(pItemSSID->abySSID,((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,len)==0))
-         return 0;
-
-     //mike:need clear desiredBSSID
-     if(pItemSSID->len==0) {
-        memset(pMgmt->abyDesireBSSID, 0xFF,6);
-        return 0;
-     }
+               len = (pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) ? pItemSSID->len : ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len;
+               if ((pDevice->bLinkPass == true) &&
+                   (memcmp(pItemSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, len) == 0))
+                       return 0;
+
+               //mike:need clear desiredBSSID
+               if (pItemSSID->len == 0) {
+                       memset(pMgmt->abyDesireBSSID, 0xFF, 6);
+                       return 0;
+               }
 
 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
- //Wext wil order another command of siwap to link with desired AP,
- //so here need not associate??
-  if(pDevice->bWPASuppWextEnabled == true)  {
-        /*******search if  in hidden ssid mode ****/
-        {
-           PKnownBSS       pCurr = NULL;
-           unsigned char abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
-         unsigned int ii , uSameBssidNum=0;
-
-         memcpy(abyTmpDesireSSID,pMgmt->abyDesireSSID,sizeof(abyTmpDesireSSID));
-            pCurr = BSSpSearchBSSList(pDevice,
-                                      NULL,
-                                      abyTmpDesireSSID,
-                                      pMgmt->eConfigPHYMode
-                                      );
-
-            if (pCurr == NULL){
-               PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
-             vResetCommandTimer((void *) pDevice);
-             pMgmt->eScanType = WMAC_SCAN_ACTIVE;
-               bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
-             bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
-          }
-        else {  //mike:to find out if that desired SSID is a hidden-ssid AP ,
-                     //         by means of judging if there are two same BSSID exist in list ?
-                  for (ii = 0; ii < MAX_BSS_NUM; ii++) {
-                     if (pMgmt->sBSSList[ii].bActive &&
-                        !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
-                        uSameBssidNum++;
-                     }
-                  }
-            if(uSameBssidNum >= 2) {  //hit: desired AP is in hidden ssid mode!!!
-                 printk("SIOCSIWESSID:hidden ssid directly associate.......\n");
-               vResetCommandTimer((void *) pDevice);
-               pMgmt->eScanType = WMAC_SCAN_PASSIVE;          //this scan type,you'll submit scan result!
-               bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
-               bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
-            }
-        }
-        }
-     return 0;
-  }
-            #endif
+               //Wext wil order another command of siwap to link with desired AP,
+               //so here need not associate??
+               if (pDevice->bWPASuppWextEnabled == true)  {
+                       /*******search if  in hidden ssid mode ****/
+                       {
+                               PKnownBSS       pCurr = NULL;
+                               unsigned char abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
+                               unsigned int ii, uSameBssidNum = 0;
+
+                               memcpy(abyTmpDesireSSID, pMgmt->abyDesireSSID, sizeof(abyTmpDesireSSID));
+                               pCurr = BSSpSearchBSSList(pDevice,
+                                                         NULL,
+                                                         abyTmpDesireSSID,
+                                                         pMgmt->eConfigPHYMode
+);
+
+                               if (pCurr == NULL) {
+                                       PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
+                                       vResetCommandTimer((void *)pDevice);
+                                       pMgmt->eScanType = WMAC_SCAN_ACTIVE;
+                                       bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
+                                       bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
+                               } else {  //mike:to find out if that desired SSID is a hidden-ssid AP ,
+                                       //         by means of judging if there are two same BSSID exist in list ?
+                                       for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+                                               if (pMgmt->sBSSList[ii].bActive &&
+                                                   !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
+                                                       uSameBssidNum++;
+                                               }
+                                       }
+                                       if (uSameBssidNum >= 2) {  //hit: desired AP is in hidden ssid mode!!!
+                                               printk("SIOCSIWESSID:hidden ssid directly associate.......\n");
+                                               vResetCommandTimer((void *)pDevice);
+                                               pMgmt->eScanType = WMAC_SCAN_PASSIVE;          //this scan type,you'll submit scan result!
+                                               bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
+                                               bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
+                                       }
+                               }
+                       }
+                       return 0;
+               }
+#endif
 
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
        }
 
-    if (pDevice->flags & DEVICE_FLAGS_OPENED) {
-           pDevice->bCommit = true;
+       if (pDevice->flags & DEVICE_FLAGS_OPENED) {
+               pDevice->bCommit = true;
        }
 
-
        return 0;
 }
 
-
 /*
  * Wireless Handler : get essid
  */
 
 int iwctl_giwessid(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra)
+                  struct iw_request_info *info,
+                  struct iw_point *wrq,
+                  char *extra)
 {
-
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
        PWLAN_IE_SSID       pItemSSID;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
 
        // Note : if wrq->u.data.flags != 0, we should
        // get the relevant SSID from the SSID list...
 
        // Get the current SSID
-    pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
+       pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
        //pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
        memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
        extra[pItemSSID->len] = '\0';
        wrq->length = pItemSSID->len + 1;
-               //2008-0409-03, <Add> by Einsn Liu
-        wrq->length = pItemSSID->len;
+       //2008-0409-03, <Add> by Einsn Liu
+       wrq->length = pItemSSID->len;
        wrq->flags = 1; // active
 
-
        return 0;
 }
 
@@ -943,28 +903,27 @@ int iwctl_giwessid(struct net_device *dev,
  */
 
 int iwctl_siwrate(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra)
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
-    int rc = 0;
+       int rc = 0;
        u8      brate = 0;
        int     i;
-       unsigned char abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
-
+       unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
-    if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
-        rc = -EINVAL;
-        return rc;
-    }
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
+       if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
+               rc = -EINVAL;
+               return rc;
+       }
 
        // First : get a valid bit rate value
 
        // Which type of value
-       if((wrq->value < 13) &&
-          (wrq->value >= 0)) {
+       if ((wrq->value < 13) &&
+           (wrq->value >= 0)) {
                // Setting by rate index
                // Find value in the magic rate table
                brate = wrq->value;
@@ -973,51 +932,49 @@ int iwctl_siwrate(struct net_device *dev,
                u8      normvalue = (u8) (wrq->value/500000);
 
                // Check if rate is valid
-               for(i = 0 ; i < 13 ; i++) {
-                       if(normvalue == abySupportedRates[i]) {
+               for (i = 0; i < 13; i++) {
+                       if (normvalue == abySupportedRates[i]) {
                                brate = i;
                                break;
                        }
                }
        }
        // -1 designed the max rate (mostly auto mode)
-       if(wrq->value == -1) {
+       if (wrq->value == -1) {
                // Get the highest available rate
-               for(i = 0 ; i < 13 ; i++) {
-                       if(abySupportedRates[i] == 0)
+               for (i = 0; i < 13; i++) {
+                       if (abySupportedRates[i] == 0)
                                break;
                }
-               if(i != 0)
+               if (i != 0)
                        brate = i - 1;
 
        }
        // Check that it is valid
        // brate is index of abySupportedRates[]
-       if(brate > 13 ) {
+       if (brate > 13) {
                rc = -EINVAL;
                return rc;
        }
 
        // Now, check if we want a fixed or auto value
-       if(wrq->fixed != 0) {
+       if (wrq->fixed != 0) {
                // Fixed mode
                // One rate, fixed
-       printk("Rate Fix\n");
+               printk("Rate Fix\n");
                pDevice->bFixRate = true;
-        if ((pDevice->byBBType == BB_TYPE_11B)&& (brate > 3)) {
-           pDevice->uConnectionRate = 3;
-        }
-        else {
-            pDevice->uConnectionRate = brate;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
-        }
+               if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) {
+                       pDevice->uConnectionRate = 3;
+               } else {
+                       pDevice->uConnectionRate = brate;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
+               }
 
+       } else {
+               pDevice->bFixRate = false;
+               pDevice->uConnectionRate = 13;
+               printk("auto rate:connection_rate is 13\n");
        }
-       else {
-        pDevice->bFixRate = false;
-        pDevice->uConnectionRate = 13;
-       printk("auto rate:connection_rate is 13\n");
-     }
 
        return rc;
 }
@@ -1027,91 +984,84 @@ int iwctl_siwrate(struct net_device *dev,
  */
 
 int iwctl_giwrate(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_param *wrq,
-             char *extra)
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
 //2007-0118-05,<Mark> by EinsnLiu
 //Mark the unnecessary sentences.
 //    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
-    {
-        unsigned char abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
-           int brate = 0;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
+       {
+               unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
+               int brate = 0;
 //2008-5-8 <modify> by chester
-if(pDevice->bLinkPass){
-if(pDevice->bFixRate == true){
-               if (pDevice->uConnectionRate < 13) {
-               brate = abySupportedRates[pDevice->uConnectionRate];
-           }else {
-            if (pDevice->byBBType == BB_TYPE_11B)
-                   brate = 0x16;
-            if (pDevice->byBBType == BB_TYPE_11G)
-                   brate = 0x6C;
-            if (pDevice->byBBType == BB_TYPE_11A)
-                   brate = 0x6C;
-           }
-}
-else
-{
-
- brate = abySupportedRates[TxRate_iwconfig];
-}
-}
-else brate =0;
+               if (pDevice->bLinkPass) {
+                       if (pDevice->bFixRate == true) {
+                               if (pDevice->uConnectionRate < 13) {
+                                       brate = abySupportedRates[pDevice->uConnectionRate];
+                               } else {
+                                       if (pDevice->byBBType == BB_TYPE_11B)
+                                               brate = 0x16;
+                                       if (pDevice->byBBType == BB_TYPE_11G)
+                                               brate = 0x6C;
+                                       if (pDevice->byBBType == BB_TYPE_11A)
+                                               brate = 0x6C;
+                               }
+                       } else {
+                               brate = abySupportedRates[TxRate_iwconfig];
+                       }
+               } else brate = 0;
 //2007-0118-05,<Mark> by EinsnLiu
 //Mark the unnecessary sentences.
 /*
-           if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-            if (pDevice->byBBType == BB_TYPE_11B)
-                   brate = 0x16;
-            if (pDevice->byBBType == BB_TYPE_11G)
-                   brate = 0x6C;
-            if (pDevice->byBBType == BB_TYPE_11A)
-                   brate = 0x6C;
-           }
+  if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+  if (pDevice->byBBType == BB_TYPE_11B)
+  brate = 0x16;
+  if (pDevice->byBBType == BB_TYPE_11G)
+  brate = 0x6C;
+  if (pDevice->byBBType == BB_TYPE_11A)
+  brate = 0x6C;
+  }
 */
 
-//             if (pDevice->uConnectionRate == 13)
+//             if (pDevice->uConnectionRate == 13)
 //                brate = abySupportedRates[pDevice->wCurrentRate];
-           wrq->value = brate * 500000;
-           // If more than one rate, set auto
-           if (pDevice->bFixRate == true)
-               wrq->fixed = true;
-    }
-
+               wrq->value = brate * 500000;
+               // If more than one rate, set auto
+               if (pDevice->bFixRate == true)
+                       wrq->fixed = true;
+       }
 
        return 0;
 }
 
-
-
 /*
  * Wireless Handler : set rts threshold
  */
 
 int iwctl_siwrts(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra)
+                struct iw_request_info *info,
+                struct iw_param *wrq,
+                char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
        int rc = 0;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS \n");
 
        {
-           int rthr = wrq->value;
-           if(wrq->disabled)
+               int rthr = wrq->value;
+               if (wrq->disabled)
                        rthr = 2312;
-           if((rthr < 0) || (rthr > 2312)) {
+               if ((rthr < 0) || (rthr > 2312)) {
                        rc = -EINVAL;
-       }else {
-                   pDevice->wRTSThreshold = rthr;
-           }
-    }
+               } else {
+                       pDevice->wRTSThreshold = rthr;
+               }
+       }
 
        return 0;
 }
@@ -1121,13 +1071,13 @@ int iwctl_siwrts(struct net_device *dev,
  */
 
 int iwctl_giwrts(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra)
+                struct iw_request_info *info,
+                struct iw_param *wrq,
+                char *extra)
 {
        PSDevice                pDevice = (PSDevice)netdev_priv(dev);
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
        wrq->value = pDevice->wRTSThreshold;
        wrq->disabled = (wrq->value >= 2312);
        wrq->fixed = 1;
@@ -1140,26 +1090,24 @@ int iwctl_giwrts(struct net_device *dev,
  */
 
 int iwctl_siwfrag(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra)
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra)
 {
-    PSDevice           pDevice = (PSDevice)netdev_priv(dev);
-    int rc = 0;
-    int fthr = wrq->value;
-
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
+       PSDevice                pDevice = (PSDevice)netdev_priv(dev);
+       int rc = 0;
+       int fthr = wrq->value;
 
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
 
-    if (wrq->disabled)
+       if (wrq->disabled)
                fthr = 2312;
-    if((fthr < 256) || (fthr > 2312)) {
+       if ((fthr < 256) || (fthr > 2312)) {
                rc = -EINVAL;
-    }else {
-                fthr &= ~0x1;  // Get an even value
-            pDevice->wFragmentationThreshold = (u16)fthr;
-    }
+       } else {
+               fthr &= ~0x1;   // Get an even value
+               pDevice->wFragmentationThreshold = (u16)fthr;
+       }
 
        return rc;
 }
@@ -1169,13 +1117,13 @@ int iwctl_siwfrag(struct net_device *dev,
  */
 
 int iwctl_giwfrag(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra)
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra)
 {
-    PSDevice           pDevice = (PSDevice)netdev_priv(dev);
+       PSDevice                pDevice = (PSDevice)netdev_priv(dev);
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
        wrq->value = pDevice->wFragmentationThreshold;
        wrq->disabled = (wrq->value >= 2312);
        wrq->fixed = 1;
@@ -1183,21 +1131,18 @@ int iwctl_giwfrag(struct net_device *dev,
        return 0;
 }
 
-
-
 /*
  * Wireless Handler : set retry threshold
  */
 int iwctl_siwretry(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra)
+                  struct iw_request_info *info,
+                  struct iw_param *wrq,
+                  char *extra)
 {
-    PSDevice           pDevice = (PSDevice)netdev_priv(dev);
-    int rc = 0;
-
+       PSDevice                pDevice = (PSDevice)netdev_priv(dev);
+       int rc = 0;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
 
        if (wrq->disabled) {
                rc = -EINVAL;
@@ -1205,7 +1150,7 @@ int iwctl_siwretry(struct net_device *dev,
        }
 
        if (wrq->flags & IW_RETRY_LIMIT) {
-               if(wrq->flags & IW_RETRY_MAX)
+               if (wrq->flags & IW_RETRY_MAX)
                        pDevice->byLongRetryLimit = wrq->value;
                else if (wrq->flags & IW_RETRY_MIN)
                        pDevice->byShortRetryLimit = wrq->value;
@@ -1219,7 +1164,6 @@ int iwctl_siwretry(struct net_device *dev,
                pDevice->wMaxTransmitMSDULifetime = wrq->value;
        }
 
-
        return rc;
 }
 
@@ -1227,45 +1171,43 @@ int iwctl_siwretry(struct net_device *dev,
  * Wireless Handler : get retry threshold
  */
 int iwctl_giwretry(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra)
+                  struct iw_request_info *info,
+                  struct iw_param *wrq,
+                  char *extra)
 {
-    PSDevice           pDevice = (PSDevice)netdev_priv(dev);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
+       PSDevice                pDevice = (PSDevice)netdev_priv(dev);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
        wrq->disabled = 0;      // Can't be disabled
 
        // Note : by default, display the min retry number
-       if((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
+       if ((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
                wrq->flags = IW_RETRY_LIFETIME;
                wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms
-       } else if((wrq->flags & IW_RETRY_MAX)) {
+       } else if ((wrq->flags & IW_RETRY_MAX)) {
                wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
                wrq->value = (int)pDevice->byLongRetryLimit;
        } else {
                wrq->flags = IW_RETRY_LIMIT;
                wrq->value = (int)pDevice->byShortRetryLimit;
-               if((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
+               if ((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
                        wrq->flags |= IW_RETRY_MIN;
        }
 
-
        return 0;
 }
 
-
 /*
  * Wireless Handler : set encode mode
  */
 int iwctl_siwencode(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra)
+                   struct iw_request_info *info,
+                   struct iw_point *wrq,
+                   char *extra)
 {
-    PSDevice           pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+       PSDevice                pDevice = (PSDevice)netdev_priv(dev);
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
        unsigned long dwKeyIndex = (unsigned long)(wrq->flags & IW_ENCODE_INDEX);
-       int ii,uu, rc = 0;
+       int ii, uu, rc = 0;
        int index = (wrq->flags & IW_ENCODE_INDEX);
 
 //2007-0207-07,<Modify> by EinsnLiu
@@ -1281,192 +1223,182 @@ int iwctl_siwencode(struct net_device *dev,
 
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
 
-if((wrq->flags & IW_ENCODE_DISABLED)==0){
-       //Not disable encryption
+       if ((wrq->flags & IW_ENCODE_DISABLED) == 0) {
+               //Not disable encryption
 
-       if (dwKeyIndex > WLAN_WEP_NKEYS) {
-               rc = -EINVAL;
-        return rc;
-       }
+               if (dwKeyIndex > WLAN_WEP_NKEYS) {
+                       rc = -EINVAL;
+                       return rc;
+               }
 
-       if(dwKeyIndex<1&&((wrq->flags&IW_ENCODE_NOKEY)==0)){//set default key
-               if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
-                       dwKeyIndex=pDevice->byKeyIndex;
+               if (dwKeyIndex < 1 && ((wrq->flags & IW_ENCODE_NOKEY) == 0)) {//set default key
+                       if (pDevice->byKeyIndex < WLAN_WEP_NKEYS) {
+                               dwKeyIndex = pDevice->byKeyIndex;
+                       } else dwKeyIndex = 0;
+               } else dwKeyIndex--;
+
+               // Check the size of the key
+               if (wrq->length > WLAN_WEP232_KEYLEN) {
+                       rc = -EINVAL;
+                       return rc;
+               }
+
+               if (wrq->length > 0) {//have key
+
+                       if (wrq->length ==  WLAN_WEP232_KEYLEN) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
+                       } else if (wrq->length ==  WLAN_WEP104_KEYLEN) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
+                       } else if (wrq->length == WLAN_WEP40_KEYLEN) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
+                       } else {//no support length
+                               rc = -EINVAL;
+                               return rc;
                        }
-               else dwKeyIndex=0;
-               }else dwKeyIndex--;
+                       memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
+                       memcpy(pDevice->abyKey, extra, wrq->length);
 
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "abyKey: ");
+                       for (ii = 0; ii < wrq->length; ii++) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
+                       }
 
-       // Check the size of the key
-       if (wrq->length > WLAN_WEP232_KEYLEN) {
-               rc = -EINVAL;
-        return rc;
-       }
+                       if (pDevice->flags & DEVICE_FLAGS_OPENED) {
+                               spin_lock_irq(&pDevice->lock);
+                               KeybSetDefaultKey(&(pDevice->sKey),
+                                                 (unsigned long)(dwKeyIndex | (1 << 31)),
+                                                 wrq->length,
+                                                 NULL,
+                                                 pDevice->abyKey,
+                                                 KEY_CTL_WEP,
+                                                 pDevice->PortOffset,
+                                                 pDevice->byLocalID
+);
+                               spin_unlock_irq(&pDevice->lock);
+                       }
+                       pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
+                       pDevice->uKeyLength = wrq->length;
+                       pDevice->bTransmitKey = true;
+                       pDevice->bEncryptionEnable = true;
+                       pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
 
-       if(wrq->length>0){//have key
-
-        if (wrq->length ==  WLAN_WEP232_KEYLEN) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
-        }
-        else if (wrq->length ==  WLAN_WEP104_KEYLEN) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
-        }
-        else if (wrq->length == WLAN_WEP40_KEYLEN) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
-        }else {//no support length
-               rc = -EINVAL;
-        return rc;
+               } else if (index > 0) {
+                       //when the length is 0 the request only changes the default transmit key index
+                       //check the new key if it has a non zero length
+                       if (pDevice->bEncryptionEnable == false) {
+                               rc = -EINVAL;
+                               return rc;
+                       }
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Just set Default key Index:\n");
+                       pkeytab = &(pDevice->sKey.KeyTable[MAX_KEY_TABLE - 1]);
+                       if (pkeytab->GroupKey[(unsigned char)dwKeyIndex].uKeyLength == 0) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Default key len is 0\n");
+                               rc = -EINVAL;
+                               return rc;
+                       }
+                       pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
+                       pkeytab->dwGTKeyIndex = dwKeyIndex | (1 << 31);
+                       pkeytab->GroupKey[(unsigned char)dwKeyIndex].dwKeyIndex = dwKeyIndex | (1 << 31);
                }
-        memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
-        memcpy(pDevice->abyKey, extra, wrq->length);
-
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
-        for (ii = 0; ii < wrq->length; ii++) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
-        }
-
-        if (pDevice->flags & DEVICE_FLAGS_OPENED) {
-            spin_lock_irq(&pDevice->lock);
-            KeybSetDefaultKey(&(pDevice->sKey),
-                            (unsigned long)(dwKeyIndex | (1 << 31)),
-                               wrq->length,
-                            NULL,
-                            pDevice->abyKey,
-                            KEY_CTL_WEP,
-                            pDevice->PortOffset,
-                            pDevice->byLocalID
-                          );
-            spin_unlock_irq(&pDevice->lock);
-        }
-        pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
-        pDevice->uKeyLength = wrq->length;
-        pDevice->bTransmitKey = true;
-        pDevice->bEncryptionEnable = true;
-        pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
-
-               }else if(index>0){
-       //when the length is 0 the request only changes the default transmit key index
-       //check the new key if it has a non zero length
-       if(pDevice->bEncryptionEnable==false)
-       {
-               rc = -EINVAL;
-               return rc;
-       }
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Just set Default key Index:\n");
-       pkeytab=&(pDevice->sKey.KeyTable[MAX_KEY_TABLE-1]);
-       if(pkeytab->GroupKey[(unsigned char)dwKeyIndex].uKeyLength==0){
-               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Default key len is 0\n");
-               rc = -EINVAL;
-               return rc;
+
+       } else {//disable the key
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
+               if (pDevice->bEncryptionEnable == false)
+                       return 0;
+               pMgmt->bShareKeyAlgorithm = false;
+               pDevice->bEncryptionEnable = false;
+               pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
+               if (pDevice->flags & DEVICE_FLAGS_OPENED) {
+                       spin_lock_irq(&pDevice->lock);
+                       for (uu = 0; uu < MAX_KEY_TABLE; uu++)
+                               MACvDisableKeyEntry(pDevice->PortOffset, uu);
+                       spin_unlock_irq(&pDevice->lock);
                }
-        pDevice->byKeyIndex =(unsigned char)dwKeyIndex;
-        pkeytab->dwGTKeyIndex =dwKeyIndex | (1 << 31);
-        pkeytab->GroupKey[(unsigned char)dwKeyIndex].dwKeyIndex=dwKeyIndex | (1 << 31);
        }
-
-}else {//disable the key
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
-       if(pDevice->bEncryptionEnable==false)
-               return 0;
-       pMgmt->bShareKeyAlgorithm = false;
-        pDevice->bEncryptionEnable = false;
-        pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
-        if (pDevice->flags & DEVICE_FLAGS_OPENED) {
-            spin_lock_irq(&pDevice->lock);
-            for(uu=0;uu<MAX_KEY_TABLE;uu++)
-                MACvDisableKeyEntry(pDevice->PortOffset, uu);
-            spin_unlock_irq(&pDevice->lock);
-        }
-}
 //End Modify,Einsn
 
 /*
-     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
 
-       // Check the size of the key
-       if (wrq->length > WLAN_WEP232_KEYLEN) {
-               rc = -EINVAL;
-        return rc;
-       }
+  // Check the size of the key
+  if (wrq->length > WLAN_WEP232_KEYLEN) {
+  rc = -EINVAL;
+  return rc;
+  }
 
-       if (dwKeyIndex > WLAN_WEP_NKEYS) {
-               rc = -EINVAL;
-        return rc;
-    }
-
-    if (dwKeyIndex > 0)
-               dwKeyIndex--;
-
-       // Send the key to the card
-       if (wrq->length > 0) {
-
-        if (wrq->length ==  WLAN_WEP232_KEYLEN) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
-        }
-        else if (wrq->length ==  WLAN_WEP104_KEYLEN) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
-        }
-        else if (wrq->length == WLAN_WEP40_KEYLEN) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
-        }
-        memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
-        memcpy(pDevice->abyKey, extra, wrq->length);
-
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
-        for (ii = 0; ii < wrq->length; ii++) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
-        }
-
-        if (pDevice->flags & DEVICE_FLAGS_OPENED) {
-            spin_lock_irq(&pDevice->lock);
-            KeybSetDefaultKey(&(pDevice->sKey),
-                            (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
-                            pDevice->uKeyLength,
-                            NULL,
-                            pDevice->abyKey,
-                            KEY_CTL_WEP,
-                            pDevice->PortOffset,
-                            pDevice->byLocalID
-                          );
-            spin_unlock_irq(&pDevice->lock);
-        }
-        pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
-        pDevice->uKeyLength = wrq->length;
-        pDevice->bTransmitKey = true;
-        pDevice->bEncryptionEnable = true;
-        pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
-
-               // Do we want to just set the transmit key index ?
-               if ( index < 4 ) {
-                   pDevice->byKeyIndex = index;
-               }
-               else if(!(wrq->flags & IW_ENCODE_MODE)) {
-                               rc = -EINVAL;
-                               return rc;
-           }
-       }
-       // Read the flags
-       if(wrq->flags & IW_ENCODE_DISABLED){
+  if (dwKeyIndex > WLAN_WEP_NKEYS) {
+  rc = -EINVAL;
+  return rc;
+  }
 
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
-               pMgmt->bShareKeyAlgorithm = false;
-        pDevice->bEncryptionEnable = false;
-        pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
-        if (pDevice->flags & DEVICE_FLAGS_OPENED) {
-            spin_lock_irq(&pDevice->lock);
-            for(uu=0;uu<MAX_KEY_TABLE;uu++)
-                MACvDisableKeyEntry(pDevice->PortOffset, uu);
-            spin_unlock_irq(&pDevice->lock);
-        }
-       }
+  if (dwKeyIndex > 0)
+  dwKeyIndex--;
+
+  // Send the key to the card
+  if (wrq->length > 0) {
+  if (wrq->length ==  WLAN_WEP232_KEYLEN) {
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
+  } else if (wrq->length ==  WLAN_WEP104_KEYLEN) {
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
+  } else if (wrq->length == WLAN_WEP40_KEYLEN) {
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
+  }
+  memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
+  memcpy(pDevice->abyKey, extra, wrq->length);
+
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "abyKey: ");
+  for (ii = 0; ii < wrq->length; ii++) {
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
+  }
+
+  if (pDevice->flags & DEVICE_FLAGS_OPENED) {
+  spin_lock_irq(&pDevice->lock);
+  KeybSetDefaultKey(&(pDevice->sKey),
+  (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
+  pDevice->uKeyLength,
+  NULL,
+  pDevice->abyKey,
+  KEY_CTL_WEP,
+  pDevice->PortOffset,
+  pDevice->byLocalID
+);
+  spin_unlock_irq(&pDevice->lock);
+  }
+  pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
+  pDevice->uKeyLength = wrq->length;
+  pDevice->bTransmitKey = true;
+  pDevice->bEncryptionEnable = true;
+  pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
+
+  // Do we want to just set the transmit key index ?
+  if (index < 4) {
+  pDevice->byKeyIndex = index;
+  } else if (!(wrq->flags & IW_ENCODE_MODE)) {
+  rc = -EINVAL;
+  return rc;
+  }
+  }
+  // Read the flags
+  if (wrq->flags & IW_ENCODE_DISABLED) {
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
+  pMgmt->bShareKeyAlgorithm = false;
+  pDevice->bEncryptionEnable = false;
+  pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
+  if (pDevice->flags & DEVICE_FLAGS_OPENED) {
+  spin_lock_irq(&pDevice->lock);
+  for (uu=0; uu<MAX_KEY_TABLE; uu++)
+  MACvDisableKeyEntry(pDevice->PortOffset, uu);
+  spin_unlock_irq(&pDevice->lock);
+  }
+  }
 */
 
-       if(wrq->flags & IW_ENCODE_RESTRICTED) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
+       if (wrq->flags & IW_ENCODE_RESTRICTED) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
                pMgmt->bShareKeyAlgorithm = true;
        }
-       if(wrq->flags & IW_ENCODE_OPEN) {
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
+       if (wrq->flags & IW_ENCODE_OPEN) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
                pMgmt->bShareKeyAlgorithm = false;
        }
        return rc;
@@ -1475,80 +1407,78 @@ if((wrq->flags & IW_ENCODE_DISABLED)==0){
 /*
  * Wireless Handler : get encode mode
  */
- /*
-int iwctl_giwencode(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra)
-{
-    PSDevice           pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
-    int rc = 0;
-    char abyKey[WLAN_WEP232_KEYLEN];
-       unsigned int index = (unsigned int)(wrq->flags & IW_ENCODE_INDEX);
-       PSKeyItem   pKey = NULL;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
+/*
+  int iwctl_giwencode(struct net_device *dev,
+  struct iw_request_info *info,
+  struct iw_point *wrq,
+  char *extra) {
+  PSDevice             pDevice = (PSDevice)netdev_priv(dev);
+  PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+  int rc = 0;
+  char abyKey[WLAN_WEP232_KEYLEN];
+  unsigned int index = (unsigned int)(wrq->flags & IW_ENCODE_INDEX);
+  PSKeyItem   pKey = NULL;
+
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
 //2007-0207-06,<Add> by EinsnLiu
 //the key index in iwconfig is 1-4 when our driver is 0-3
 //so it can't be used directly.
 //if the index is 0,we should used the index set by driver.
-       if (index > WLAN_WEP_NKEYS) {
-               rc = -EINVAL;
-        return rc;
-       }
-       if(index<1){//set default key
-               if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
-                       index=pDevice->byKeyIndex;
-                       }
-               else index=0;
-               }else index--;
+if (index > WLAN_WEP_NKEYS) {
+rc = -EINVAL;
+return rc;
+}
+if (index<1) {//set default key
+if (pDevice->byKeyIndex<WLAN_WEP_NKEYS) {
+index=pDevice->byKeyIndex;
+}
+else index=0;
+else index--;
 //End Add,Einsn
 
-       memset(abyKey, 0, sizeof(abyKey));
-       // Check encryption mode
-       wrq->flags = IW_ENCODE_NOKEY;
-       // Is WEP enabled ???
-       if (pDevice->bEncryptionEnable)
-               wrq->flags |=  IW_ENCODE_ENABLED;
-    else
-               wrq->flags |=  IW_ENCODE_DISABLED;
+memset(abyKey, 0, sizeof(abyKey));
+// Check encryption mode
+wrq->flags = IW_ENCODE_NOKEY;
+// Is WEP enabled ???
+if (pDevice->bEncryptionEnable)
+wrq->flags |=  IW_ENCODE_ENABLED;
+else
+wrq->flags |=  IW_ENCODE_DISABLED;
 
-    if (pMgmt->bShareKeyAlgorithm)
-               wrq->flags |=  IW_ENCODE_RESTRICTED;
-       else
-               wrq->flags |=  IW_ENCODE_OPEN;
+if (pMgmt->bShareKeyAlgorithm)
+wrq->flags |=  IW_ENCODE_RESTRICTED;
+else
+wrq->flags |=  IW_ENCODE_OPEN;
 
-       if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (unsigned char)index , &pKey)){
-        wrq->length = pKey->uKeyLength;
-        memcpy(abyKey, pKey->abyKey,  pKey->uKeyLength);
+if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (unsigned char)index , &pKey)) {
+wrq->length = pKey->uKeyLength;
+memcpy(abyKey, pKey->abyKey,  pKey->uKeyLength);
 //2007-0207-06,<Modify> by EinsnLiu
 //only get key success need to  copy data
 //index should +1.
 //there is not necessary to return -EINVAL when get key failed
 //if return -EINVAL,the encryption item can't be display by the command "iwconfig".
-       wrq->flags |= index+1;
-       memcpy(extra,  abyKey, WLAN_WEP232_KEYLEN);
-    }
-
-    //else {
-    //    rc = -EINVAL;
-   //     return rc;
-  //  }
+wrq->flags |= index+1;
+memcpy(extra,  abyKey, WLAN_WEP232_KEYLEN);
+}
 
+//else {
+//    rc = -EINVAL;
+//     return rc;
+//  }
 
 //End Modify,Einsn
 
-       return 0;
+return 0;
 }
 */
 
 //2008-0409-06, <Add> by Einsn Liu
 
 int iwctl_giwencode(struct net_device *dev,
-                       struct iw_request_info *info,
-                       struct iw_point *wrq,
-                       char *extra)
+                   struct iw_request_info *info,
+                   struct iw_point *wrq,
+                   char *extra)
 {
        PSDevice                        pDevice = (PSDevice)netdev_priv(dev);
        PSMgmtObject            pMgmt = &(pDevice->sMgmtObj);
@@ -1562,13 +1492,13 @@ int iwctl_giwencode(struct net_device *dev,
        if (index > WLAN_WEP_NKEYS) {
                return  -EINVAL;
        }
-       if(index<1){//get default key
-               if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
-                       index=pDevice->byKeyIndex;
-               } else
-                      index=0;
-       }else
-             index--;
+       if (index < 1) {//get default key
+               if (pDevice->byKeyIndex < WLAN_WEP_NKEYS) {
+                       index = pDevice->byKeyIndex;
+               } else
+                       index = 0;
+       } else
+               index--;
 
        memset(abyKey, 0, WLAN_WEP232_KEYLEN);
        // Check encryption mode
@@ -1583,18 +1513,18 @@ int iwctl_giwencode(struct net_device *dev,
                wrq->flags |=  IW_ENCODE_RESTRICTED;
        else
                wrq->flags |=  IW_ENCODE_OPEN;
-               wrq->length=0;
-
-       if((index==0)&&(pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled||
-               pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)){//get wpa pairwise  key
-                       if (KeybGetKey(&(pDevice->sKey),pMgmt->abyCurrBSSID, 0xffffffff, &pKey)){
-                          wrq->length = pKey->uKeyLength;
-                                 memcpy(abyKey, pKey->abyKey,  pKey->uKeyLength);
-                                 memcpy(extra,  abyKey, WLAN_WEP232_KEYLEN);
-                          }
-       }else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (unsigned char)index , &pKey)){
+       wrq->length = 0;
+
+       if ((index == 0) && (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled ||
+                            pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)) {//get wpa pairwise  key
+               if (KeybGetKey(&(pDevice->sKey), pMgmt->abyCurrBSSID, 0xffffffff, &pKey)) {
                        wrq->length = pKey->uKeyLength;
-                       memcpy(abyKey, pKey->abyKey,  pKey->uKeyLength);
+                       memcpy(abyKey, pKey->abyKey,    pKey->uKeyLength);
+                       memcpy(extra,  abyKey, WLAN_WEP232_KEYLEN);
+               }
+       } else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (unsigned char)index , &pKey)) {
+               wrq->length = pKey->uKeyLength;
+               memcpy(abyKey, pKey->abyKey,  pKey->uKeyLength);
                memcpy(extra,  abyKey, WLAN_WEP232_KEYLEN);
        }
 
@@ -1603,24 +1533,23 @@ int iwctl_giwencode(struct net_device *dev,
        return 0;
 }
 
-
 /*
  * Wireless Handler : set power mode
  */
 int iwctl_siwpower(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra)
+                  struct iw_request_info *info,
+                  struct iw_param *wrq,
+                  char *extra)
 {
-    PSDevice            pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
-    int rc = 0;
+       PSDevice            pDevice = (PSDevice)netdev_priv(dev);
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+       int rc = 0;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
 
-    if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
-                rc = -EINVAL;
-                return rc;
+       if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
+               rc = -EINVAL;
+               return rc;
        }
 
        if (wrq->disabled) {
@@ -1629,23 +1558,23 @@ int iwctl_siwpower(struct net_device *dev,
                return rc;
        }
        if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
-         pDevice->ePSMode = WMAC_POWER_FAST;
-         PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
+               pDevice->ePSMode = WMAC_POWER_FAST;
+               PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
 
        } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
-            pDevice->ePSMode = WMAC_POWER_FAST;
-         PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
+               pDevice->ePSMode = WMAC_POWER_FAST;
+               PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
        }
        switch (wrq->flags & IW_POWER_MODE) {
        case IW_POWER_UNICAST_R:
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
                rc = -EINVAL;
                break;
        case IW_POWER_ALL_R:
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
                rc = -EINVAL;
        case IW_POWER_ON:
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
                break;
        default:
                rc = -EINVAL;
@@ -1658,21 +1587,19 @@ int iwctl_siwpower(struct net_device *dev,
  * Wireless Handler : get power mode
  */
 int iwctl_giwpower(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra)
+                  struct iw_request_info *info,
+                  struct iw_param *wrq,
+                  char *extra)
 {
-    PSDevice            pDevice = (PSDevice)netdev_priv(dev);
-    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
-    int mode = pDevice->ePSMode;
-
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
+       PSDevice            pDevice = (PSDevice)netdev_priv(dev);
+       PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
+       int mode = pDevice->ePSMode;
 
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
 
        wrq->disabled = (mode == WMAC_POWER_CAM);
        if (wrq->disabled)
-           return 0;
+               return 0;
 
        if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
                wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
@@ -1686,30 +1613,27 @@ int iwctl_giwpower(struct net_device *dev,
        return 0;
 }
 
-
 /*
  * Wireless Handler : get Sensitivity
  */
 int iwctl_giwsens(struct net_device *dev,
-                        struct iw_request_info *info,
-                        struct iw_param *wrq,
-                        char *extra)
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra)
 {
-    PSDevice           pDevice = (PSDevice)netdev_priv(dev);
-    long ldBm;
+       PSDevice                pDevice = (PSDevice)netdev_priv(dev);
+       long ldBm;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
-    if (pDevice->bLinkPass == true) {
-        RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
-           wrq->value = ldBm;
-       }
-       else {
-           wrq->value = 0;
-    };
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
+       if (pDevice->bLinkPass == true) {
+               RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
+               wrq->value = ldBm;
+       } else {
+               wrq->value = 0;
+       };
        wrq->disabled = (wrq->value == 0);
        wrq->fixed = 1;
 
-
        return 0;
 }
 
@@ -1717,66 +1641,64 @@ int iwctl_giwsens(struct net_device *dev,
 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
 
 int iwctl_siwauth(struct net_device *dev,
-                         struct iw_request_info *info,
-                         struct iw_param *wrq,
-                         char *extra)
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra)
 {
        PSDevice                        pDevice = (PSDevice)netdev_priv(dev);
        PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
-       int ret=0;
-       static int wpa_version=0;  //must be static to save the last value,einsn liu
-       static int pairwise=0;
+       int ret = 0;
+       static int wpa_version = 0;  //must be static to save the last value,einsn liu
+       static int pairwise = 0;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
        switch (wrq->flags & IW_AUTH_INDEX) {
        case IW_AUTH_WPA_VERSION:
                wpa_version = wrq->value;
-               if(wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
-                      PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
+               if (wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
+                       PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
                        //pDevice->bWPADevEnable = false;
-               }
-               else if(wrq->value == IW_AUTH_WPA_VERSION_WPA) {
-                          PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
-               }
-               else {
-                          PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
+               } else if (wrq->value == IW_AUTH_WPA_VERSION_WPA) {
+                       PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
+               } else {
+                       PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
                }
                //pDevice->bWPASuppWextEnabled =true;
                break;
        case IW_AUTH_CIPHER_PAIRWISE:
                pairwise = wrq->value;
-               if(pairwise == IW_AUTH_CIPHER_CCMP){
+               if (pairwise == IW_AUTH_CIPHER_CCMP) {
                        pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
-               }else if(pairwise == IW_AUTH_CIPHER_TKIP){
+               } else if (pairwise == IW_AUTH_CIPHER_TKIP) {
                        pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
-               }else if(pairwise == IW_AUTH_CIPHER_WEP40||pairwise == IW_AUTH_CIPHER_WEP104){
+               } else if (pairwise == IW_AUTH_CIPHER_WEP40 || pairwise == IW_AUTH_CIPHER_WEP104) {
                        pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
-               }else if(pairwise == IW_AUTH_CIPHER_NONE){
+               } else if (pairwise == IW_AUTH_CIPHER_NONE) {
                        //do nothing,einsn liu
-               }else pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
+               } else pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
 
                break;
        case IW_AUTH_CIPHER_GROUP:
-               if(wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
+               if (wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
                        break;
-               if(pairwise == IW_AUTH_CIPHER_NONE){
-                       if(wrq->value == IW_AUTH_CIPHER_CCMP){
+               if (pairwise == IW_AUTH_CIPHER_NONE) {
+                       if (wrq->value == IW_AUTH_CIPHER_CCMP) {
                                pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
-                       }else {
+                       } else {
                                pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
                        }
                }
                break;
        case IW_AUTH_KEY_MGMT:
 
-               if(wpa_version == IW_AUTH_WPA_VERSION_WPA2){
-                       if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
+               if (wpa_version == IW_AUTH_WPA_VERSION_WPA2) {
+                       if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
                                pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
                        else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
-               }else if(wpa_version == IW_AUTH_WPA_VERSION_WPA){
-                       if(wrq->value == 0){
+               } else if (wpa_version == IW_AUTH_WPA_VERSION_WPA) {
+                       if (wrq->value == 0) {
                                pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
-                       }else if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
+                       } else if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
                                pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
                        else pMgmt->eAuthenMode = WMAC_AUTH_WPA;
                }
@@ -1787,10 +1709,10 @@ int iwctl_siwauth(struct net_device *dev,
        case IW_AUTH_DROP_UNENCRYPTED:
                break;
        case IW_AUTH_80211_AUTH_ALG:
-               if(wrq->value==IW_AUTH_ALG_OPEN_SYSTEM){
-                       pMgmt->bShareKeyAlgorithm=false;
-               }else if(wrq->value==IW_AUTH_ALG_SHARED_KEY){
-                       pMgmt->bShareKeyAlgorithm=true;
+               if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM) {
+                       pMgmt->bShareKeyAlgorithm = false;
+               } else if (wrq->value == IW_AUTH_ALG_SHARED_KEY) {
+                       pMgmt->bShareKeyAlgorithm = true;
                }
                break;
        case IW_AUTH_WPA_ENABLED:
@@ -1803,7 +1725,7 @@ int iwctl_siwauth(struct net_device *dev,
                break;
        case IW_AUTH_PRIVACY_INVOKED:
                pDevice->bEncryptionEnable = !!wrq->value;
-               if(pDevice->bEncryptionEnable == false){
+               if (pDevice->bEncryptionEnable == false) {
                        wpa_version = 0;
                        pairwise = 0;
                        pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
@@ -1818,220 +1740,214 @@ int iwctl_siwauth(struct net_device *dev,
                break;
        }
 /*
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_version = %d\n",wpa_version);
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise = %d\n",pairwise);
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->eEncryptionStatus = %d\n",pDevice->eEncryptionStatus);
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->eAuthenMode  = %d\n",pMgmt->eAuthenMode);
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->bShareKeyAlgorithm = %s\n",pMgmt->bShareKeyAlgorithm?"true":"false");
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bEncryptionEnable = %s\n",pDevice->bEncryptionEnable?"true":"false");
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bWPADevEnable = %s\n",pDevice->bWPADevEnable?"true":"false");
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_version = %d\n",wpa_version);
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise = %d\n",pairwise);
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->eEncryptionStatus = %d\n",pDevice->eEncryptionStatus);
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->eAuthenMode  = %d\n",pMgmt->eAuthenMode);
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->bShareKeyAlgorithm = %s\n",pMgmt->bShareKeyAlgorithm?"true":"false");
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bEncryptionEnable = %s\n",pDevice->bEncryptionEnable?"true":"false");
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bWPADevEnable = %s\n",pDevice->bWPADevEnable?"true":"false");
 */
-   return ret;
+       return ret;
 }
 
-
 int iwctl_giwauth(struct net_device *dev,
-                         struct iw_request_info *info,
-                         struct iw_param *wrq,
-                         char *extra)
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra)
 {
        return -EOPNOTSUPP;
 }
 
-
-
 int iwctl_siwgenie(struct net_device *dev,
-                         struct iw_request_info *info,
-                         struct iw_point *wrq,
-                         char *extra)
+                  struct iw_request_info *info,
+                  struct iw_point *wrq,
+                  char *extra)
 {
        PSDevice                        pDevice = (PSDevice)netdev_priv(dev);
        PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
-       int ret=0;
+       int ret = 0;
 
-       if(wrq->length){
+       if (wrq->length) {
                if ((wrq->length < 2) || (extra[1]+2 != wrq->length)) {
                        ret = -EINVAL;
                        goto out;
                }
-               if(wrq->length > MAX_WPA_IE_LEN){
+               if (wrq->length > MAX_WPA_IE_LEN) {
                        ret = -ENOMEM;
                        goto out;
                }
                memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
-               if(copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
+               if (copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)) {
                        ret = -EFAULT;
                        goto out;
                }
                pMgmt->wWPAIELen = wrq->length;
-       }else {
+       } else {
                memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
                pMgmt->wWPAIELen = 0;
        }
 
-       out://not completely ...not necessary in wpa_supplicant 0.5.8
+out://not completely ...not necessary in wpa_supplicant 0.5.8
        return ret;
 }
 
 int iwctl_giwgenie(struct net_device *dev,
-                         struct iw_request_info *info,
-                         struct iw_point *wrq,
-                         char *extra)
+                  struct iw_request_info *info,
+                  struct iw_point *wrq,
+                  char *extra)
 {
        PSDevice                        pDevice = (PSDevice)netdev_priv(dev);
        PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
-       int ret=0;
+       int ret = 0;
        int space = wrq->length;
 
        wrq->length = 0;
-       if(pMgmt->wWPAIELen > 0){
+       if (pMgmt->wWPAIELen > 0) {
                wrq->length = pMgmt->wWPAIELen;
-               if(pMgmt->wWPAIELen <= space){
-                       if(copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)){
+               if (pMgmt->wWPAIELen <= space) {
+                       if (copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)) {
                                ret = -EFAULT;
                        }
-               }else
+               } else
                        ret = -E2BIG;
        }
 
        return ret;
 }
 
-
 int iwctl_siwencodeext(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra)
+                      struct iw_request_info *info,
+                      struct iw_point *wrq,
+                      char *extra)
 {
-    PSDevice           pDevice = (PSDevice)netdev_priv(dev);
-       struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
-    struct viawget_wpa_param *param=NULL;
+       PSDevice                pDevice = (PSDevice)netdev_priv(dev);
+       struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
+       struct viawget_wpa_param *param = NULL;
 //original member
-    wpa_alg alg_name;
-    u8  addr[6];
-    int key_idx, set_tx=0;
-    u8  seq[IW_ENCODE_SEQ_MAX_SIZE];
-    u8 key[64];
-    size_t seq_len=0,key_len=0;
+       wpa_alg alg_name;
+       u8  addr[6];
+       int key_idx, set_tx = 0;
+       u8  seq[IW_ENCODE_SEQ_MAX_SIZE];
+       u8 key[64];
+       size_t seq_len = 0, key_len = 0;
 //
-   // int ii;
-    u8 *buf;
-    size_t blen;
-    u8 key_array[64];
-    int ret=0;
+       // int ii;
+       u8 *buf;
+       size_t blen;
+       u8 key_array[64];
+       int ret = 0;
 
-PRINT_K("SIOCSIWENCODEEXT...... \n");
+       PRINT_K("SIOCSIWENCODEEXT...... \n");
 
-blen = sizeof(*param);
-buf = kmalloc((int)blen, (int)GFP_KERNEL);
-if (buf == NULL)
-    return -ENOMEM;
-memset(buf, 0, blen);
-param = (struct viawget_wpa_param *) buf;
+       blen = sizeof(*param);
+       buf = kmalloc((int)blen, (int)GFP_KERNEL);
+       if (buf == NULL)
+               return -ENOMEM;
+       memset(buf, 0, blen);
+       param = (struct viawget_wpa_param *)buf;
 
 //recover alg_name
-switch (ext->alg) {
-    case IW_ENCODE_ALG_NONE:
-                  alg_name = WPA_ALG_NONE;
+       switch (ext->alg) {
+       case IW_ENCODE_ALG_NONE:
+               alg_name = WPA_ALG_NONE;
                break;
-    case IW_ENCODE_ALG_WEP:
-                  alg_name = WPA_ALG_WEP;
+       case IW_ENCODE_ALG_WEP:
+               alg_name = WPA_ALG_WEP;
                break;
-    case IW_ENCODE_ALG_TKIP:
-                  alg_name = WPA_ALG_TKIP;
+       case IW_ENCODE_ALG_TKIP:
+               alg_name = WPA_ALG_TKIP;
                break;
-    case IW_ENCODE_ALG_CCMP:
-                  alg_name = WPA_ALG_CCMP;
+       case IW_ENCODE_ALG_CCMP:
+               alg_name = WPA_ALG_CCMP;
                break;
-    default:
-               PRINT_K("Unknown alg = %d\n",ext->alg);
-               ret= -ENOMEM;
+       default:
+               PRINT_K("Unknown alg = %d\n", ext->alg);
+               ret = -ENOMEM;
                goto error;
-               }
+       }
 //recover addr
- memcpy(addr, ext->addr.sa_data, ETH_ALEN);
      memcpy(addr, ext->addr.sa_data, ETH_ALEN);
 //recover key_idx
-  key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
+       key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
 //recover set_tx
-if(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
-   set_tx = 1;
+       if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
+               set_tx = 1;
 //recover seq,seq_len
-       if(ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
-   seq_len=IW_ENCODE_SEQ_MAX_SIZE;
-   memcpy(seq, ext->rx_seq, seq_len);
-               }
+       if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
+               seq_len = IW_ENCODE_SEQ_MAX_SIZE;
+               memcpy(seq, ext->rx_seq, seq_len);
+       }
 //recover key,key_len
-if(ext->key_len) {
-  key_len=ext->key_len;
-  memcpy(key, &ext->key[0], key_len);
+       if (ext->key_len) {
+               key_len = ext->key_len;
+               memcpy(key, &ext->key[0], key_len);
        }
 
-memset(key_array, 0, 64);
-if ( key_len > 0) {
-     memcpy(key_array, key, key_len);
-    if (key_len == 32) {
-          // notice ! the oder
-         memcpy(&key_array[16], &key[24], 8);
-         memcpy(&key_array[24], &key[16], 8);
-       }
+       memset(key_array, 0, 64);
+       if (key_len > 0) {
+               memcpy(key_array, key, key_len);
+               if (key_len == 32) {
+                       // notice ! the oder
+                       memcpy(&key_array[16], &key[24], 8);
+                       memcpy(&key_array[24], &key[16], 8);
+               }
        }
 
 /**************Translate iw_encode_ext to viawget_wpa_param****************/
-memcpy(param->addr, addr, ETH_ALEN);
-param->u.wpa_key.alg_name = (int)alg_name;
-param->u.wpa_key.set_tx = set_tx;
-param->u.wpa_key.key_index = key_idx;
-param->u.wpa_key.key_len = key_len;
-param->u.wpa_key.key = (u8 *)key_array;
-param->u.wpa_key.seq = (u8 *)seq;
-param->u.wpa_key.seq_len = seq_len;
+       memcpy(param->addr, addr, ETH_ALEN);
+       param->u.wpa_key.alg_name = (int)alg_name;
+       param->u.wpa_key.set_tx = set_tx;
+       param->u.wpa_key.key_index = key_idx;
+       param->u.wpa_key.key_len = key_len;
+       param->u.wpa_key.key = (u8 *)key_array;
+       param->u.wpa_key.seq = (u8 *)seq;
+       param->u.wpa_key.seq_len = seq_len;
 
 //****set if current action is Network Manager count??
 //****this method is so foolish,but there is no other way???
-if(param->u.wpa_key.alg_name == WPA_ALG_NONE) {
-   if(param->u.wpa_key.key_index ==0) {
-     pDevice->bwextcount++;
-    }
-   if((pDevice->bwextcount == 1)&&(param->u.wpa_key.key_index ==1)) {
- pDevice->bwextcount++;
-    }
-   if((pDevice->bwextcount ==2)&&(param->u.wpa_key.key_index ==2)) {
- pDevice->bwextcount++;
+       if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
+               if (param->u.wpa_key.key_index == 0) {
+                       pDevice->bwextcount++;
+               }
+               if ((pDevice->bwextcount == 1) && (param->u.wpa_key.key_index == 1)) {
+                       pDevice->bwextcount++;
+               }
+               if ((pDevice->bwextcount == 2) && (param->u.wpa_key.key_index == 2)) {
+                       pDevice->bwextcount++;
+               }
+               if ((pDevice->bwextcount == 3) && (param->u.wpa_key.key_index == 3)) {
+                       pDevice->bwextcount++;
+               }
+       }
+       if (pDevice->bwextcount == 4) {
+               printk("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
+               pDevice->bwextcount = 0;
+               pDevice->bWPASuppWextEnabled = true;
        }
-   if((pDevice->bwextcount ==3)&&(param->u.wpa_key.key_index ==3)) {
- pDevice->bwextcount++;
-        }
-                }
-if( pDevice->bwextcount == 4) {
-    printk("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
- pDevice->bwextcount=0;
-   pDevice->bWPASuppWextEnabled = true;
-                }
 //******
 
-               spin_lock_irq(&pDevice->lock);
- ret = wpa_set_keys(pDevice, param, true);
-               spin_unlock_irq(&pDevice->lock);
+       spin_lock_irq(&pDevice->lock);
      ret = wpa_set_keys(pDevice, param, true);
+       spin_unlock_irq(&pDevice->lock);
 
 error:
-kfree(param);
+       kfree(param);
        return ret;
 }
 
-
-
 int iwctl_giwencodeext(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra)
+                      struct iw_request_info *info,
+                      struct iw_point *wrq,
+                      char *extra)
 {
-               return -EOPNOTSUPP;
+       return -EOPNOTSUPP;
 }
 
 int iwctl_siwmlme(struct net_device *dev,
-                               struct iw_request_info * info,
-                               struct iw_point *wrq,
-                               char *extra)
+                 struct iw_request_info *info,
+                 struct iw_point *wrq,
+                 char *extra)
 {
        PSDevice                        pDevice = (PSDevice)netdev_priv(dev);
        PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
@@ -2039,21 +1955,21 @@ int iwctl_siwmlme(struct net_device *dev,
        //u16 reason = cpu_to_le16(mlme->reason_code);
        int ret = 0;
 
-       if(memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)){
+       if (memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)) {
                ret = -EINVAL;
                return ret;
        }
-       switch(mlme->cmd){
+       switch (mlme->cmd) {
        case IW_MLME_DEAUTH:
                //this command seems to be not complete,please test it --einsnliu
                //bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (unsigned char *)&reason);
                break;
        case IW_MLME_DISASSOC:
-               if(pDevice->bLinkPass == true){
-                                         printk("iwctl_siwmlme--->send DISASSOCIATE\n");
-                 //clear related flags
-                  memset(pMgmt->abyDesireBSSID, 0xFF,6);
-               KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
+               if (pDevice->bLinkPass == true) {
+                       printk("iwctl_siwmlme--->send DISASSOCIATE\n");
+                       //clear related flags
+                       memset(pMgmt->abyDesireBSSID, 0xFF, 6);
+                       KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
                        bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
                }
                break;
@@ -2062,109 +1978,106 @@ int iwctl_siwmlme(struct net_device *dev,
        }
 
        return ret;
-
 }
 
 #endif
 
-
 /*------------------------------------------------------------------*/
 /*
  * Structures to export the Wireless Handlers
  */
 
-
 /*
-static const iw_handler                iwctl_handler[] =
-{
-       (iw_handler) iwctl_commit,      // SIOCSIWCOMMIT
-       (iw_handler) iwctl_giwname,     // SIOCGIWNAME
-       (iw_handler) NULL,                              // SIOCSIWNWID
-       (iw_handler) NULL,                              // SIOCGIWNWID
-       (iw_handler) iwctl_siwfreq,             // SIOCSIWFREQ
-       (iw_handler) iwctl_giwfreq,             // SIOCGIWFREQ
-       (iw_handler) iwctl_siwmode,             // SIOCSIWMODE
-       (iw_handler) iwctl_giwmode,             // SIOCGIWMODE
-       (iw_handler) NULL,                      // SIOCSIWSENS
-       (iw_handler) iwctl_giwsens,                     // SIOCGIWSENS
-       (iw_handler) NULL,                      // SIOCSIWRANGE
-       (iw_handler) iwctl_giwrange,            // SIOCGIWRANGE
-       (iw_handler) NULL,                          // SIOCSIWPRIV
-       (iw_handler) NULL,                      // SIOCGIWPRIV
-       (iw_handler) NULL,                      // SIOCSIWSTATS
-       (iw_handler) NULL,                  // SIOCGIWSTATS
-    (iw_handler) NULL,                  // SIOCSIWSPY
-       (iw_handler) NULL,                          // SIOCGIWSPY
-       (iw_handler) NULL,                                  // -- hole --
-       (iw_handler) NULL,                                  // -- hole --
-       (iw_handler) iwctl_siwap,                   // SIOCSIWAP
-       (iw_handler) iwctl_giwap,                   // SIOCGIWAP
-       (iw_handler) NULL,                                  // -- hole -- 0x16
-       (iw_handler) iwctl_giwaplist,       // SIOCGIWAPLIST
-       (iw_handler) iwctl_siwscan,         // SIOCSIWSCAN
-       (iw_handler) iwctl_giwscan,         // SIOCGIWSCAN
-       (iw_handler) iwctl_siwessid,            // SIOCSIWESSID
-       (iw_handler) iwctl_giwessid,            // SIOCGIWESSID
-       (iw_handler) NULL,              // SIOCSIWNICKN
-       (iw_handler) NULL,              // SIOCGIWNICKN
-       (iw_handler) NULL,                                  // -- hole --
-       (iw_handler) NULL,                                  // -- hole --
-       (iw_handler) iwctl_siwrate,             // SIOCSIWRATE 0x20
-       (iw_handler) iwctl_giwrate,             // SIOCGIWRATE
-       (iw_handler) iwctl_siwrts,              // SIOCSIWRTS
-       (iw_handler) iwctl_giwrts,              // SIOCGIWRTS
-       (iw_handler) iwctl_siwfrag,             // SIOCSIWFRAG
-       (iw_handler) iwctl_giwfrag,             // SIOCGIWFRAG
-       (iw_handler) NULL,              // SIOCSIWTXPOW
-       (iw_handler) NULL,              // SIOCGIWTXPOW
-       (iw_handler) iwctl_siwretry,            // SIOCSIWRETRY
-       (iw_handler) iwctl_giwretry,            // SIOCGIWRETRY
-       (iw_handler) iwctl_siwencode,           // SIOCSIWENCODE
-       (iw_handler) iwctl_giwencode,           // SIOCGIWENCODE
-       (iw_handler) iwctl_siwpower,            // SIOCSIWPOWER
-       (iw_handler) iwctl_giwpower,            // SIOCGIWPOWER
-       (iw_handler) NULL,                      // -- hole --
-       (iw_handler) NULL,                      // -- hole --
-       (iw_handler) iwctl_siwgenie,    // SIOCSIWGENIE
-       (iw_handler) iwctl_giwgenie,    // SIOCGIWGENIE
-       (iw_handler) iwctl_siwauth,             // SIOCSIWAUTH
-       (iw_handler) iwctl_giwauth,             // SIOCGIWAUTH
-       (iw_handler) iwctl_siwencodeext,                // SIOCSIWENCODEEXT
-       (iw_handler) iwctl_giwencodeext,                // SIOCGIWENCODEEXT
-       (iw_handler) NULL,                              // SIOCSIWPMKSA
-       (iw_handler) NULL,                              // -- hole --
-
-};
+  static const iw_handler              iwctl_handler[] =
+  {
+  (iw_handler) iwctl_commit,      // SIOCSIWCOMMIT
+  (iw_handler) iwctl_giwname,     // SIOCGIWNAME
+  (iw_handler) NULL,                           // SIOCSIWNWID
+  (iw_handler) NULL,                           // SIOCGIWNWID
+  (iw_handler) iwctl_siwfreq,          // SIOCSIWFREQ
+  (iw_handler) iwctl_giwfreq,          // SIOCGIWFREQ
+  (iw_handler) iwctl_siwmode,          // SIOCSIWMODE
+  (iw_handler) iwctl_giwmode,          // SIOCGIWMODE
+  (iw_handler) NULL,                   // SIOCSIWSENS
+  (iw_handler) iwctl_giwsens,                  // SIOCGIWSENS
+  (iw_handler) NULL,                   // SIOCSIWRANGE
+  (iw_handler) iwctl_giwrange,         // SIOCGIWRANGE
+  (iw_handler) NULL,                   // SIOCSIWPRIV
+  (iw_handler) NULL,                   // SIOCGIWPRIV
+  (iw_handler) NULL,                   // SIOCSIWSTATS
+  (iw_handler) NULL,                  // SIOCGIWSTATS
+  (iw_handler) NULL,                  // SIOCSIWSPY
+  (iw_handler) NULL,                       // SIOCGIWSPY
+  (iw_handler) NULL,                               // -- hole --
+  (iw_handler) NULL,                               // -- hole --
+  (iw_handler) iwctl_siwap,                // SIOCSIWAP
+  (iw_handler) iwctl_giwap,                // SIOCGIWAP
+  (iw_handler) NULL,                               // -- hole -- 0x16
+  (iw_handler) iwctl_giwaplist,       // SIOCGIWAPLIST
+  (iw_handler) iwctl_siwscan,         // SIOCSIWSCAN
+  (iw_handler) iwctl_giwscan,         // SIOCGIWSCAN
+  (iw_handler) iwctl_siwessid,         // SIOCSIWESSID
+  (iw_handler) iwctl_giwessid,         // SIOCGIWESSID
+  (iw_handler) NULL,           // SIOCSIWNICKN
+  (iw_handler) NULL,           // SIOCGIWNICKN
+  (iw_handler) NULL,                               // -- hole --
+  (iw_handler) NULL,                               // -- hole --
+  (iw_handler) iwctl_siwrate,          // SIOCSIWRATE 0x20
+  (iw_handler) iwctl_giwrate,          // SIOCGIWRATE
+  (iw_handler) iwctl_siwrts,           // SIOCSIWRTS
+  (iw_handler) iwctl_giwrts,           // SIOCGIWRTS
+  (iw_handler) iwctl_siwfrag,          // SIOCSIWFRAG
+  (iw_handler) iwctl_giwfrag,          // SIOCGIWFRAG
+  (iw_handler) NULL,           // SIOCSIWTXPOW
+  (iw_handler) NULL,           // SIOCGIWTXPOW
+  (iw_handler) iwctl_siwretry,         // SIOCSIWRETRY
+  (iw_handler) iwctl_giwretry,         // SIOCGIWRETRY
+  (iw_handler) iwctl_siwencode,                // SIOCSIWENCODE
+  (iw_handler) iwctl_giwencode,                // SIOCGIWENCODE
+  (iw_handler) iwctl_siwpower,         // SIOCSIWPOWER
+  (iw_handler) iwctl_giwpower,         // SIOCGIWPOWER
+  (iw_handler) NULL,                   // -- hole --
+  (iw_handler) NULL,                   // -- hole --
+  (iw_handler) iwctl_siwgenie,    // SIOCSIWGENIE
+  (iw_handler) iwctl_giwgenie,    // SIOCGIWGENIE
+  (iw_handler) iwctl_siwauth,          // SIOCSIWAUTH
+  (iw_handler) iwctl_giwauth,          // SIOCGIWAUTH
+  (iw_handler) iwctl_siwencodeext,             // SIOCSIWENCODEEXT
+  (iw_handler) iwctl_giwencodeext,             // SIOCGIWENCODEEXT
+  (iw_handler) NULL,                           // SIOCSIWPMKSA
+  (iw_handler) NULL,                           // -- hole --
+
+  };
 */
 
 static const iw_handler                iwctl_handler[] =
 {
        (iw_handler) iwctl_commit,      // SIOCSIWCOMMIT
-       (iw_handler) NULL,      // SIOCGIWNAME
-       (iw_handler) NULL,                              // SIOCSIWNWID
-       (iw_handler) NULL,                              // SIOCGIWNWID
+       (iw_handler) NULL,              // SIOCGIWNAME
+       (iw_handler) NULL,              // SIOCSIWNWID
+       (iw_handler) NULL,              // SIOCGIWNWID
        (iw_handler) NULL,              // SIOCSIWFREQ
        (iw_handler) NULL,              // SIOCGIWFREQ
        (iw_handler) NULL,              // SIOCSIWMODE
        (iw_handler) NULL,              // SIOCGIWMODE
-       (iw_handler) NULL,                      // SIOCSIWSENS
-       (iw_handler) NULL,                      // SIOCGIWSENS
-       (iw_handler) NULL,                      // SIOCSIWRANGE
-       (iw_handler) iwctl_giwrange,            // SIOCGIWRANGE
-       (iw_handler) NULL,                          // SIOCSIWPRIV
-       (iw_handler) NULL,                      // SIOCGIWPRIV
-       (iw_handler) NULL,                      // SIOCSIWSTATS
-       (iw_handler) NULL,                  // SIOCGIWSTATS
-    (iw_handler) NULL,                  // SIOCSIWSPY
-       (iw_handler) NULL,                          // SIOCGIWSPY
-       (iw_handler) NULL,                                  // -- hole --
-       (iw_handler) NULL,                                  // -- hole --
-       (iw_handler) NULL,                  // SIOCSIWAP
-       (iw_handler) NULL,                  // SIOCGIWAP
-       (iw_handler) NULL,                                  // -- hole -- 0x16
-       (iw_handler) NULL,       // SIOCGIWAPLIST
-       (iw_handler) iwctl_siwscan,         // SIOCSIWSCAN
-       (iw_handler) iwctl_giwscan,         // SIOCGIWSCAN
+       (iw_handler) NULL,              // SIOCSIWSENS
+       (iw_handler) NULL,              // SIOCGIWSENS
+       (iw_handler) NULL,              // SIOCSIWRANGE
+       (iw_handler) iwctl_giwrange,    // SIOCGIWRANGE
+       (iw_handler) NULL,              // SIOCSIWPRIV
+       (iw_handler) NULL,              // SIOCGIWPRIV
+       (iw_handler) NULL,              // SIOCSIWSTATS
+       (iw_handler) NULL,              // SIOCGIWSTATS
+       (iw_handler) NULL,              // SIOCSIWSPY
+       (iw_handler) NULL,              // SIOCGIWSPY
+       (iw_handler) NULL,              // -- hole --
+       (iw_handler) NULL,              // -- hole --
+       (iw_handler) NULL,              // SIOCSIWAP
+       (iw_handler) NULL,              // SIOCGIWAP
+       (iw_handler) NULL,              // -- hole -- 0x16
+       (iw_handler) NULL,              // SIOCGIWAPLIST
+       (iw_handler) iwctl_siwscan,     // SIOCSIWSCAN
+       (iw_handler) iwctl_giwscan,     // SIOCGIWSCAN
        (iw_handler) NULL,              // SIOCSIWESSID
        (iw_handler) NULL,              // SIOCGIWESSID
        (iw_handler) NULL,              // SIOCSIWNICKN
@@ -2187,33 +2100,29 @@ static const iw_handler         iwctl_handler[] =
        (iw_handler) NULL,              // SIOCGIWPOWER
 
 //2008-0409-07, <Add> by Einsn Liu
-       (iw_handler) NULL,                      // -- hole --
-       (iw_handler) NULL,                      // -- hole --
-       (iw_handler) NULL,    // SIOCSIWGENIE
-       (iw_handler) NULL,    // SIOCGIWGENIE
+       (iw_handler) NULL,              // -- hole --
+       (iw_handler) NULL,              // -- hole --
+       (iw_handler) NULL,              // SIOCSIWGENIE
+       (iw_handler) NULL,              // SIOCGIWGENIE
        (iw_handler) NULL,              // SIOCSIWAUTH
        (iw_handler) NULL,              // SIOCGIWAUTH
        (iw_handler) NULL,              // SIOCSIWENCODEEXT
        (iw_handler) NULL,              // SIOCGIWENCODEEXT
-       (iw_handler) NULL,                              // SIOCSIWPMKSA
-       (iw_handler) NULL,                              // -- hole --
+       (iw_handler) NULL,              // SIOCSIWPMKSA
+       (iw_handler) NULL,              // -- hole --
 };
 
-
 static const iw_handler                iwctl_private_handler[] =
 {
        NULL,                           // SIOCIWFIRSTPRIV
 };
 
-
 struct iw_priv_args iwctl_private_args[] = {
-{ IOCTL_CMD_SET,
-  IW_PRIV_TYPE_CHAR | 1024, 0,
-  "set"},
+       { IOCTL_CMD_SET,
+         IW_PRIV_TYPE_CHAR | 1024, 0,
+         "set"},
 };
 
-
-
 const struct iw_handler_def    iwctl_handler_def =
 {
        .get_wireless_stats = &iwctl_get_wireless_stats,
@@ -2222,7 +2131,7 @@ const struct iw_handler_def       iwctl_handler_def =
 //     .num_private_args = sizeof(iwctl_private_args)/sizeof(struct iw_priv_args),
        .num_private    = 0,
        .num_private_args = 0,
-       .standard       = (iw_handler *) iwctl_handler,
+       .standard       = (iw_handler *)iwctl_handler,
 //     .private        = (iw_handler *) iwctl_private_handler,
 //     .private_args   = (struct iw_priv_args *)iwctl_private_args,
        .private        = NULL,
index d224f913a624046e88f00618918461a01e84178e..871bd7c4e716e853993670ac58fda95a283808e6 100644 (file)
 
 /*---------------------  Export Definitions -------------------------*/
 
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 
 /*---------------------  Export Functions  --------------------------*/
 
-struct iw_statistics *iwctl_get_wireless_stats (struct net_device *dev);
-
+struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev);
 
 int iwctl_siwap(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct sockaddr *wrq,
-             char *extra);
+               struct iw_request_info *info,
+               struct sockaddr *wrq,
+               char *extra);
 
 int iwctl_giwrange(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra);
-
+                  struct iw_request_info *info,
+                  struct iw_point *wrq,
+                  char *extra);
 
 int iwctl_giwmode(struct net_device *dev,
-             struct iw_request_info *info,
-             __u32 *wmode,
-             char *extra);
+                 struct iw_request_info *info,
+                 __u32 *wmode,
+                 char *extra);
 
 int iwctl_siwmode(struct net_device *dev,
-             struct iw_request_info *info,
-             __u32 *wmode,
-             char *extra);
+                 struct iw_request_info *info,
+                 __u32 *wmode,
+                 char *extra);
 
 int iwctl_giwfreq(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_freq *wrq,
-             char *extra);
+                 struct iw_request_info *info,
+                 struct iw_freq *wrq,
+                 char *extra);
 
 int iwctl_siwfreq(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_freq *wrq,
-             char *extra);
+                 struct iw_request_info *info,
+                 struct iw_freq *wrq,
+                 char *extra);
 
 int iwctl_giwname(struct net_device *dev,
-                        struct iw_request_info *info,
-                        char *wrq,
-                        char *extra);
+                 struct iw_request_info *info,
+                 char *wrq,
+                 char *extra);
 
 int iwctl_giwsens(struct net_device *dev,
-                        struct iw_request_info *info,
-                        struct iw_param *wrq,
-                        char *extra);
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra);
 
 int iwctl_giwap(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct sockaddr *wrq,
-             char *extra);
+               struct iw_request_info *info,
+               struct sockaddr *wrq,
+               char *extra);
 
 int iwctl_giwaplist(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra);
+                   struct iw_request_info *info,
+                   struct iw_point *wrq,
+                   char *extra);
 
 int iwctl_siwessid(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra);
+                  struct iw_request_info *info,
+                  struct iw_point *wrq,
+                  char *extra);
 
 int iwctl_giwessid(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra);
+                  struct iw_request_info *info,
+                  struct iw_point *wrq,
+                  char *extra);
 
 int iwctl_siwrate(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra);
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra);
 
 int iwctl_giwrate(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_param *wrq,
-             char *extra);
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra);
 
 int iwctl_siwrts(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra);
-
+                struct iw_request_info *info,
+                struct iw_param *wrq,
+                char *extra);
 
 int iwctl_giwrts(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra);
+                struct iw_request_info *info,
+                struct iw_param *wrq,
+                char *extra);
 
 int iwctl_siwfrag(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra);
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra);
 
 int iwctl_giwfrag(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra);
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra);
 
 int iwctl_siwretry(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra);
+                  struct iw_request_info *info,
+                  struct iw_param *wrq,
+                  char *extra);
 
 int iwctl_giwretry(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra);
+                  struct iw_request_info *info,
+                  struct iw_param *wrq,
+                  char *extra);
 
 int iwctl_siwencode(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra);
+                   struct iw_request_info *info,
+                   struct iw_point *wrq,
+                   char *extra);
 
 int iwctl_giwencode(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra);
+                   struct iw_request_info *info,
+                   struct iw_point *wrq,
+                   char *extra);
 
 int iwctl_siwpower(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra);
+                  struct iw_request_info *info,
+                  struct iw_param *wrq,
+                  char *extra);
 
 int iwctl_giwpower(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra);
+                  struct iw_request_info *info,
+                  struct iw_param *wrq,
+                  char *extra);
 
 int iwctl_giwscan(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_point *wrq,
-             char *extra);
+                 struct iw_request_info *info,
+                 struct iw_point *wrq,
+                 char *extra);
 
 int iwctl_siwscan(struct net_device *dev,
-             struct iw_request_info *info,
-                        struct iw_param *wrq,
-             char *extra);
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra);
 
 //2008-0409-07, <Add> by Einsn Liu
 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
 int iwctl_siwauth(struct net_device *dev,
-                         struct iw_request_info *info,
-                         struct iw_param *wrq,
-                         char *extra);
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra);
 
 int iwctl_giwauth(struct net_device *dev,
-                         struct iw_request_info *info,
-                         struct iw_param *wrq,
-                         char *extra);
+                 struct iw_request_info *info,
+                 struct iw_param *wrq,
+                 char *extra);
 
 int iwctl_siwgenie(struct net_device *dev,
-                         struct iw_request_info *info,
-                         struct iw_point *wrq,
-                         char *extra);
+                  struct iw_request_info *info,
+                  struct iw_point *wrq,
+                  char *extra);
 
 int iwctl_giwgenie(struct net_device *dev,
-                         struct iw_request_info *info,
-                         struct iw_point *wrq,
-                         char *extra);
+                  struct iw_request_info *info,
+                  struct iw_point *wrq,
+                  char *extra);
 
 int iwctl_siwencodeext(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra);
+                      struct iw_request_info *info,
+                      struct iw_point *wrq,
+                      char *extra);
 
 int iwctl_giwencodeext(struct net_device *dev,
-             struct iw_request_info *info,
-             struct iw_point *wrq,
-             char *extra);
+                      struct iw_request_info *info,
+                      struct iw_point *wrq,
+                      char *extra);
 
 int iwctl_siwmlme(struct net_device *dev,
-                       struct iw_request_info * info,
-                       struct iw_point *wrq,
-                       char *extra);
+                 struct iw_request_info *info,
+                 struct iw_point *wrq,
+                 char *extra);
 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
 //End Add -- //2008-0409-07, <Add> by Einsn Liu
 
-
 extern const struct iw_handler_def     iwctl_handler_def;
 extern const struct iw_priv_args       iwctl_private_args;
 
 #endif // __IWCTL_H__
-
-
-
index 194fedc715fa5767a4ac8bbad8dd1c45fbc63070..92b84b5ea115cd0ee465e097078bbd4bd9866500 100644 (file)
@@ -45,7 +45,7 @@
 /*---------------------  Static Classes  ----------------------------*/
 
 /*---------------------  Static Variables  --------------------------*/
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 /*---------------------  Static Functions  --------------------------*/
 
@@ -59,31 +59,28 @@ static int          msglevel                =MSG_LEVEL_INFO;
 
 /*---------------------  Static Functions  --------------------------*/
 static void
-s_vCheckKeyTableValid (PSKeyManagement pTable, unsigned long dwIoBase)
+s_vCheckKeyTableValid(PSKeyManagement pTable, unsigned long dwIoBase)
 {
-    int i;
-
-    for (i=0;i<MAX_KEY_TABLE;i++) {
-        if ((pTable->KeyTable[i].bInUse == true) &&
-            (pTable->KeyTable[i].PairwiseKey.bKeyValid == false) &&
-            (pTable->KeyTable[i].GroupKey[0].bKeyValid == false) &&
-            (pTable->KeyTable[i].GroupKey[1].bKeyValid == false) &&
-            (pTable->KeyTable[i].GroupKey[2].bKeyValid == false) &&
-            (pTable->KeyTable[i].GroupKey[3].bKeyValid == false)
-            ) {
-
-            pTable->KeyTable[i].bInUse = false;
-            pTable->KeyTable[i].wKeyCtl = 0;
-            pTable->KeyTable[i].bSoftWEP = false;
-            MACvDisableKeyEntry(dwIoBase, i);
-        }
-    }
+       int i;
+
+       for (i = 0; i < MAX_KEY_TABLE; i++) {
+               if ((pTable->KeyTable[i].bInUse == true) &&
+                   (pTable->KeyTable[i].PairwiseKey.bKeyValid == false) &&
+                   (pTable->KeyTable[i].GroupKey[0].bKeyValid == false) &&
+                   (pTable->KeyTable[i].GroupKey[1].bKeyValid == false) &&
+                   (pTable->KeyTable[i].GroupKey[2].bKeyValid == false) &&
+                   (pTable->KeyTable[i].GroupKey[3].bKeyValid == false)
+) {
+                       pTable->KeyTable[i].bInUse = false;
+                       pTable->KeyTable[i].wKeyCtl = 0;
+                       pTable->KeyTable[i].bSoftWEP = false;
+                       MACvDisableKeyEntry(dwIoBase, i);
+               }
+       }
 }
 
-
 /*---------------------  Export Functions  --------------------------*/
 
-
 /*
  * Description: Init Key management table
  *
@@ -96,27 +93,26 @@ s_vCheckKeyTableValid (PSKeyManagement pTable, unsigned long dwIoBase)
  * Return Value: none
  *
  */
-void KeyvInitTable (PSKeyManagement pTable, unsigned long dwIoBase)
+void KeyvInitTable(PSKeyManagement pTable, unsigned long dwIoBase)
 {
-    int i;
-    int jj;
-
-    for (i=0;i<MAX_KEY_TABLE;i++) {
-        pTable->KeyTable[i].bInUse = false;
-        pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
-        pTable->KeyTable[i].PairwiseKey.pvKeyTable = (void *)&pTable->KeyTable[i];
-        for (jj=0; jj < MAX_GROUP_KEY; jj++) {
-            pTable->KeyTable[i].GroupKey[jj].bKeyValid = false;
-            pTable->KeyTable[i].GroupKey[jj].pvKeyTable = (void *)&pTable->KeyTable[i];
-        }
-        pTable->KeyTable[i].wKeyCtl = 0;
-        pTable->KeyTable[i].dwGTKeyIndex = 0;
-        pTable->KeyTable[i].bSoftWEP = false;
-        MACvDisableKeyEntry(dwIoBase, i);
-    }
+       int i;
+       int jj;
+
+       for (i = 0; i < MAX_KEY_TABLE; i++) {
+               pTable->KeyTable[i].bInUse = false;
+               pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
+               pTable->KeyTable[i].PairwiseKey.pvKeyTable = (void *)&pTable->KeyTable[i];
+               for (jj = 0; jj < MAX_GROUP_KEY; jj++) {
+                       pTable->KeyTable[i].GroupKey[jj].bKeyValid = false;
+                       pTable->KeyTable[i].GroupKey[jj].pvKeyTable = (void *)&pTable->KeyTable[i];
+               }
+               pTable->KeyTable[i].wKeyCtl = 0;
+               pTable->KeyTable[i].dwGTKeyIndex = 0;
+               pTable->KeyTable[i].bSoftWEP = false;
+               MACvDisableKeyEntry(dwIoBase, i);
+       }
 }
 
-
 /*
  * Description: Get Key from table
  *
@@ -131,47 +127,43 @@ void KeyvInitTable (PSKeyManagement pTable, unsigned long dwIoBase)
  * Return Value: true if found otherwise false
  *
  */
-bool KeybGetKey (
-    PSKeyManagement pTable,
-    unsigned char *pbyBSSID,
-    unsigned long dwKeyIndex,
-    PSKeyItem       *pKey
-    )
+bool KeybGetKey(
+       PSKeyManagement pTable,
+       unsigned char *pbyBSSID,
+       unsigned long dwKeyIndex,
+       PSKeyItem       *pKey
+)
 {
-    int i;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetKey() \n");
-
-    *pKey = NULL;
-    for (i=0;i<MAX_KEY_TABLE;i++) {
-        if ((pTable->KeyTable[i].bInUse == true) &&
-            !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
-            if (dwKeyIndex == 0xFFFFFFFF) {
-                if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) {
-                    *pKey = &(pTable->KeyTable[i].PairwiseKey);
-                    return (true);
-                }
-                else {
-                    return (false);
-                }
-            } else if (dwKeyIndex < MAX_GROUP_KEY) {
-                if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == true) {
-                    *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
-                    return (true);
-                }
-                else {
-                    return (false);
-                }
-            }
-            else {
-                return (false);
-            }
-        }
-    }
-    return (false);
+       int i;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybGetKey() \n");
+
+       *pKey = NULL;
+       for (i = 0; i < MAX_KEY_TABLE; i++) {
+               if ((pTable->KeyTable[i].bInUse == true) &&
+                   !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
+                       if (dwKeyIndex == 0xFFFFFFFF) {
+                               if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) {
+                                       *pKey = &(pTable->KeyTable[i].PairwiseKey);
+                                       return true;
+                               } else {
+                                       return false;
+                               }
+                       } else if (dwKeyIndex < MAX_GROUP_KEY) {
+                               if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == true) {
+                                       *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
+                                       return true;
+                               } else {
+                                       return false;
+                               }
+                       } else {
+                               return false;
+                       }
+               }
+       }
+       return false;
 }
 
-
 /*
  * Description: Set Key to table
  *
@@ -189,165 +181,162 @@ bool KeybGetKey (
  * Return Value: true if success otherwise false
  *
  */
-bool KeybSetKey (
-    PSKeyManagement pTable,
-    unsigned char *pbyBSSID,
-    unsigned long dwKeyIndex,
-    unsigned long uKeyLength,
-    PQWORD          pKeyRSC,
-    unsigned char *pbyKey,
-    unsigned char byKeyDecMode,
-    unsigned long dwIoBase,
-    unsigned char byLocalID
-    )
+bool KeybSetKey(
+       PSKeyManagement pTable,
+       unsigned char *pbyBSSID,
+       unsigned long dwKeyIndex,
+       unsigned long uKeyLength,
+       PQWORD          pKeyRSC,
+       unsigned char *pbyKey,
+       unsigned char byKeyDecMode,
+       unsigned long dwIoBase,
+       unsigned char byLocalID
+)
 {
-    int         i,j;
-    unsigned int ii;
-    PSKeyItem   pKey;
-    unsigned int uKeyIdx;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetKey: %lX\n", dwKeyIndex);
-
-    j = (MAX_KEY_TABLE-1);
-    for (i=0;i<(MAX_KEY_TABLE-1);i++) {
-        if ((pTable->KeyTable[i].bInUse == false) &&
-            (j == (MAX_KEY_TABLE-1))) {
-            // found empty table
-            j = i;
-        }
-        if ((pTable->KeyTable[i].bInUse == true) &&
-            !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
-            // found table already exist
-            if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
-                // Pairwise key
-                pKey = &(pTable->KeyTable[i].PairwiseKey);
-                pTable->KeyTable[i].wKeyCtl &= 0xFFF0;          // clear pairwise key control filed
-                pTable->KeyTable[i].wKeyCtl |= byKeyDecMode;
-                uKeyIdx = 4;                                    // use HW key entry 4 for pairwise key
-            } else {
-                // Group key
-                if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
-                    return (false);
-                pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
-                if ((dwKeyIndex & TRANSMIT_KEY) != 0)  {
-                    // Group transmit key
-                    pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
-                }
-                pTable->KeyTable[i].wKeyCtl &= 0xFF0F;          // clear group key control filed
-                pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
-                pTable->KeyTable[i].wKeyCtl |= 0x0040;          // use group key for group address
-                uKeyIdx = (dwKeyIndex & 0x000000FF);
-            }
-            pTable->KeyTable[i].wKeyCtl |= 0x8000;              // enable on-fly
-
-            pKey->bKeyValid = true;
-            pKey->uKeyLength = uKeyLength;
-            pKey->dwKeyIndex = dwKeyIndex;
-            pKey->byCipherSuite = byKeyDecMode;
-            memcpy(pKey->abyKey, pbyKey, uKeyLength);
-            if (byKeyDecMode == KEY_CTL_WEP) {
-                if (uKeyLength == WLAN_WEP40_KEYLEN)
-                    pKey->abyKey[15] &= 0x7F;
-                if (uKeyLength == WLAN_WEP104_KEYLEN)
-                    pKey->abyKey[15] |= 0x80;
-            }
-            MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
-
-            if ((dwKeyIndex & USE_KEYRSC) == 0) {
-                // RSC set by NIC
-                   memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
-            }
-            else {
-                memcpy(&(pKey->KeyRSC), pKeyRSC,  sizeof(QWORD));
-            }
-            pKey->dwTSC47_16 = 0;
-            pKey->wTSC15_0 = 0;
-
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
-            //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", pKey->uKeyLength);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
-            for (ii = 0; ii < pKey->uKeyLength; ii++) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
-            }
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
-
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
-
-            return (true);
-        }
-    }
-    if (j < (MAX_KEY_TABLE-1)) {
-        memcpy(pTable->KeyTable[j].abyBSSID,pbyBSSID,ETH_ALEN);
-        pTable->KeyTable[j].bInUse = true;
-        if ((dwKeyIndex & PAIRWISE_KEY) != 0)  {
-            // Pairwise key
-            pKey = &(pTable->KeyTable[j].PairwiseKey);
-            pTable->KeyTable[j].wKeyCtl &= 0xFFF0;          // clear pairwise key control filed
-            pTable->KeyTable[j].wKeyCtl |= byKeyDecMode;
-            uKeyIdx = 4;                                    // use HW key entry 4 for pairwise key
-        } else {
-            // Group key
-            if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
-                return (false);
-            pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]);
-            if ((dwKeyIndex & TRANSMIT_KEY) != 0)  {
-                // Group transmit key
-                pTable->KeyTable[j].dwGTKeyIndex = dwKeyIndex;
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(N)[%lX]: %d\n", pTable->KeyTable[j].dwGTKeyIndex, j);
-            }
-            pTable->KeyTable[j].wKeyCtl &= 0xFF0F;          // clear group key control filed
-            pTable->KeyTable[j].wKeyCtl |= (byKeyDecMode << 4);
-            pTable->KeyTable[j].wKeyCtl |= 0x0040;          // use group key for group address
-            uKeyIdx = (dwKeyIndex & 0x000000FF);
-        }
-        pTable->KeyTable[j].wKeyCtl |= 0x8000;              // enable on-fly
-
-        pKey->bKeyValid = true;
-        pKey->uKeyLength = uKeyLength;
-        pKey->dwKeyIndex = dwKeyIndex;
-        pKey->byCipherSuite = byKeyDecMode;
-        memcpy(pKey->abyKey, pbyKey, uKeyLength);
-        if (byKeyDecMode == KEY_CTL_WEP) {
-            if (uKeyLength == WLAN_WEP40_KEYLEN)
-                pKey->abyKey[15] &= 0x7F;
-            if (uKeyLength == WLAN_WEP104_KEYLEN)
-                pKey->abyKey[15] |= 0x80;
-        }
-        MACvSetKeyEntry(dwIoBase, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
-
-        if ((dwKeyIndex & USE_KEYRSC) == 0) {
-            // RSC set by NIC
-               memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
-        }
-        else {
-            memcpy(&(pKey->KeyRSC), pKeyRSC,  sizeof(QWORD));
-        }
-        pKey->dwTSC47_16 = 0;
-        pKey->wTSC15_0 = 0;
-
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(N): \n");
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
-        for (ii = 0; ii < pKey->uKeyLength; ii++) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
-
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
-
-        return (true);
-    }
-    return (false);
+       int i, j;
+       unsigned int ii;
+       PSKeyItem   pKey;
+       unsigned int uKeyIdx;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enter KeybSetKey: %lX\n", dwKeyIndex);
+
+       j = (MAX_KEY_TABLE-1);
+       for (i = 0; i < (MAX_KEY_TABLE - 1); i++) {
+               if ((pTable->KeyTable[i].bInUse == false) &&
+                   (j == (MAX_KEY_TABLE-1))) {
+                       // found empty table
+                       j = i;
+               }
+               if ((pTable->KeyTable[i].bInUse == true) &&
+                   !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
+                       // found table already exist
+                       if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
+                               // Pairwise key
+                               pKey = &(pTable->KeyTable[i].PairwiseKey);
+                               pTable->KeyTable[i].wKeyCtl &= 0xFFF0;          // clear pairwise key control filed
+                               pTable->KeyTable[i].wKeyCtl |= byKeyDecMode;
+                               uKeyIdx = 4;                                    // use HW key entry 4 for pairwise key
+                       } else {
+                               // Group key
+                               if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
+                                       return false;
+                               pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
+                               if ((dwKeyIndex & TRANSMIT_KEY) != 0)  {
+                                       // Group transmit key
+                                       pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
+                               }
+                               pTable->KeyTable[i].wKeyCtl &= 0xFF0F;          // clear group key control filed
+                               pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
+                               pTable->KeyTable[i].wKeyCtl |= 0x0040;          // use group key for group address
+                               uKeyIdx = (dwKeyIndex & 0x000000FF);
+                       }
+                       pTable->KeyTable[i].wKeyCtl |= 0x8000;              // enable on-fly
+
+                       pKey->bKeyValid = true;
+                       pKey->uKeyLength = uKeyLength;
+                       pKey->dwKeyIndex = dwKeyIndex;
+                       pKey->byCipherSuite = byKeyDecMode;
+                       memcpy(pKey->abyKey, pbyKey, uKeyLength);
+                       if (byKeyDecMode == KEY_CTL_WEP) {
+                               if (uKeyLength == WLAN_WEP40_KEYLEN)
+                                       pKey->abyKey[15] &= 0x7F;
+                               if (uKeyLength == WLAN_WEP104_KEYLEN)
+                                       pKey->abyKey[15] |= 0x80;
+                       }
+                       MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
+
+                       if ((dwKeyIndex & USE_KEYRSC) == 0) {
+                               // RSC set by NIC
+                               memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
+                       } else {
+                               memcpy(&(pKey->KeyRSC), pKeyRSC,  sizeof(QWORD));
+                       }
+                       pKey->dwTSC47_16 = 0;
+                       pKey->wTSC15_0 = 0;
+
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybSetKey(R): \n");
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->bKeyValid: %d\n ", pKey->bKeyValid);
+                       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->uKeyLength: %d\n ", pKey->uKeyLength);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->abyKey: ");
+                       for (ii = 0; ii < pKey->uKeyLength; ii++) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
+                       }
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
+
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
+
+                       return true;
+               }
+       }
+       if (j < (MAX_KEY_TABLE-1)) {
+               memcpy(pTable->KeyTable[j].abyBSSID, pbyBSSID, ETH_ALEN);
+               pTable->KeyTable[j].bInUse = true;
+               if ((dwKeyIndex & PAIRWISE_KEY) != 0)  {
+                       // Pairwise key
+                       pKey = &(pTable->KeyTable[j].PairwiseKey);
+                       pTable->KeyTable[j].wKeyCtl &= 0xFFF0;          // clear pairwise key control filed
+                       pTable->KeyTable[j].wKeyCtl |= byKeyDecMode;
+                       uKeyIdx = 4;                                    // use HW key entry 4 for pairwise key
+               } else {
+                       // Group key
+                       if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
+                               return false;
+                       pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]);
+                       if ((dwKeyIndex & TRANSMIT_KEY) != 0)  {
+                               // Group transmit key
+                               pTable->KeyTable[j].dwGTKeyIndex = dwKeyIndex;
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Group transmit key(N)[%lX]: %d\n", pTable->KeyTable[j].dwGTKeyIndex, j);
+                       }
+                       pTable->KeyTable[j].wKeyCtl &= 0xFF0F;          // clear group key control filed
+                       pTable->KeyTable[j].wKeyCtl |= (byKeyDecMode << 4);
+                       pTable->KeyTable[j].wKeyCtl |= 0x0040;          // use group key for group address
+                       uKeyIdx = (dwKeyIndex & 0x000000FF);
+               }
+               pTable->KeyTable[j].wKeyCtl |= 0x8000;              // enable on-fly
+
+               pKey->bKeyValid = true;
+               pKey->uKeyLength = uKeyLength;
+               pKey->dwKeyIndex = dwKeyIndex;
+               pKey->byCipherSuite = byKeyDecMode;
+               memcpy(pKey->abyKey, pbyKey, uKeyLength);
+               if (byKeyDecMode == KEY_CTL_WEP) {
+                       if (uKeyLength == WLAN_WEP40_KEYLEN)
+                               pKey->abyKey[15] &= 0x7F;
+                       if (uKeyLength == WLAN_WEP104_KEYLEN)
+                               pKey->abyKey[15] |= 0x80;
+               }
+               MACvSetKeyEntry(dwIoBase, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
+
+               if ((dwKeyIndex & USE_KEYRSC) == 0) {
+                       // RSC set by NIC
+                       memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
+               } else {
+                       memcpy(&(pKey->KeyRSC), pKeyRSC,  sizeof(QWORD));
+               }
+               pKey->dwTSC47_16 = 0;
+               pKey->wTSC15_0 = 0;
+
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybSetKey(N): \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->bKeyValid: %d\n ", pKey->bKeyValid);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->abyKey: ");
+               for (ii = 0; ii < pKey->uKeyLength; ii++) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
+
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
+
+               return true;
+       }
+       return false;
 }
 
-
 /*
  * Description: Remove Key from table
  *
@@ -362,66 +351,61 @@ bool KeybSetKey (
  * Return Value: true if success otherwise false
  *
  */
-bool KeybRemoveKey (
-    PSKeyManagement pTable,
-    unsigned char *pbyBSSID,
-    unsigned long dwKeyIndex,
-    unsigned long dwIoBase
-    )
+bool KeybRemoveKey(
+       PSKeyManagement pTable,
+       unsigned char *pbyBSSID,
+       unsigned long dwKeyIndex,
+       unsigned long dwIoBase
+)
 {
-    int  i;
-
-    if (is_broadcast_ether_addr(pbyBSSID)) {
-        // delete all keys
-        if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
-            for (i=0;i<MAX_KEY_TABLE;i++) {
-                pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
-            }
-            s_vCheckKeyTableValid(pTable, dwIoBase);
-            return true;
-        }
-        else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
-            for (i=0;i<MAX_KEY_TABLE;i++) {
-                pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
-                if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
-                    // remove Group transmit key
-                    pTable->KeyTable[i].dwGTKeyIndex = 0;
-                }
-            }
-            s_vCheckKeyTableValid(pTable, dwIoBase);
-            return true;
-        }
-        else {
-            return false;
-        }
-    }
-
-    for (i=0;i<MAX_KEY_TABLE;i++) {
-        if ((pTable->KeyTable[i].bInUse == true) &&
-            !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
-            if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
-                pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
-                s_vCheckKeyTableValid(pTable, dwIoBase);
-                return (true);
-            }
-            else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
-                pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
-                if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
-                    // remove Group transmit key
-                    pTable->KeyTable[i].dwGTKeyIndex = 0;
-                }
-                s_vCheckKeyTableValid(pTable, dwIoBase);
-                return (true);
-            }
-            else {
-                return (false);
-            }
-        }
-    }
-    return (false);
+       int  i;
+
+       if (is_broadcast_ether_addr(pbyBSSID)) {
+               // delete all keys
+               if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
+                       for (i = 0; i < MAX_KEY_TABLE; i++) {
+                               pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
+                       }
+                       s_vCheckKeyTableValid(pTable, dwIoBase);
+                       return true;
+               } else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
+                       for (i = 0; i < MAX_KEY_TABLE; i++) {
+                               pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
+                               if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
+                                       // remove Group transmit key
+                                       pTable->KeyTable[i].dwGTKeyIndex = 0;
+                               }
+                       }
+                       s_vCheckKeyTableValid(pTable, dwIoBase);
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
+       for (i = 0; i < MAX_KEY_TABLE; i++) {
+               if ((pTable->KeyTable[i].bInUse == true) &&
+                   !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
+                       if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
+                               pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
+                               s_vCheckKeyTableValid(pTable, dwIoBase);
+                               return true;
+                       } else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
+                               pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
+                               if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
+                                       // remove Group transmit key
+                                       pTable->KeyTable[i].dwGTKeyIndex = 0;
+                               }
+                               s_vCheckKeyTableValid(pTable, dwIoBase);
+                               return true;
+                       } else {
+                               return false;
+                       }
+               }
+       }
+       return false;
 }
 
-
 /*
  * Description: Remove Key from table
  *
@@ -435,27 +419,27 @@ bool KeybRemoveKey (
  * Return Value: true if success otherwise false
  *
  */
-bool KeybRemoveAllKey (
-    PSKeyManagement pTable,
-    unsigned char *pbyBSSID,
-    unsigned long dwIoBase
-    )
+bool KeybRemoveAllKey(
+       PSKeyManagement pTable,
+       unsigned char *pbyBSSID,
+       unsigned long dwIoBase
+)
 {
-    int  i,u;
-
-    for (i=0;i<MAX_KEY_TABLE;i++) {
-        if ((pTable->KeyTable[i].bInUse == true) &&
-            !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
-            pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
-            for(u=0;u<MAX_GROUP_KEY;u++) {
-                pTable->KeyTable[i].GroupKey[u].bKeyValid = false;
-            }
-            pTable->KeyTable[i].dwGTKeyIndex = 0;
-            s_vCheckKeyTableValid(pTable, dwIoBase);
-            return (true);
-        }
-    }
-    return (false);
+       int i, u;
+
+       for (i = 0; i < MAX_KEY_TABLE; i++) {
+               if ((pTable->KeyTable[i].bInUse == true) &&
+                   !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
+                       pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
+                       for (u = 0; u < MAX_GROUP_KEY; u++) {
+                               pTable->KeyTable[i].GroupKey[u].bKeyValid = false;
+                       }
+                       pTable->KeyTable[i].dwGTKeyIndex = 0;
+                       s_vCheckKeyTableValid(pTable, dwIoBase);
+                       return true;
+               }
+       }
+       return false;
 }
 
 /*
@@ -470,38 +454,37 @@ bool KeybRemoveAllKey (
  * Return Value: true if success otherwise false
  *
  */
-void KeyvRemoveWEPKey (
-    PSKeyManagement pTable,
-    unsigned long dwKeyIndex,
-    unsigned long dwIoBase
-    )
+void KeyvRemoveWEPKey(
+       PSKeyManagement pTable,
+       unsigned long dwKeyIndex,
+       unsigned long dwIoBase
+)
 {
-
-   if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
-        if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == true) {
-            if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) {
-                pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
-                if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) {
-                    // remove Group transmit key
-                    pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0;
-                }
-            }
-        }
-        s_vCheckKeyTableValid(pTable, dwIoBase);
-    }
-    return;
+       if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
+               if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == true) {
+                       if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) {
+                               pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
+                               if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) {
+                                       // remove Group transmit key
+                                       pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0;
+                               }
+                       }
+               }
+               s_vCheckKeyTableValid(pTable, dwIoBase);
+       }
+       return;
 }
 
-void KeyvRemoveAllWEPKey (
-    PSKeyManagement pTable,
-    unsigned long dwIoBase
-    )
+void KeyvRemoveAllWEPKey(
+       PSKeyManagement pTable,
+       unsigned long dwIoBase
+)
 {
-    int i;
+       int i;
 
-    for(i=0;i<MAX_GROUP_KEY;i++) {
-        KeyvRemoveWEPKey(pTable, i, dwIoBase);
-    }
+       for (i = 0; i < MAX_GROUP_KEY; i++) {
+               KeyvRemoveWEPKey(pTable, i, dwIoBase);
+       }
 }
 
 /*
@@ -517,74 +500,68 @@ void KeyvRemoveAllWEPKey (
  * Return Value: true if found otherwise false
  *
  */
-bool KeybGetTransmitKey (
-    PSKeyManagement pTable,
-    unsigned char *pbyBSSID,
-    unsigned long dwKeyType,
-    PSKeyItem       *pKey
-    )
+bool KeybGetTransmitKey(
+       PSKeyManagement pTable,
+       unsigned char *pbyBSSID,
+       unsigned long dwKeyType,
+       PSKeyItem       *pKey
+)
 {
-    int i, ii;
-
-    *pKey = NULL;
-    for (i=0;i<MAX_KEY_TABLE;i++) {
-        if ((pTable->KeyTable[i].bInUse == true) &&
-            !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
-
-            if (dwKeyType == PAIRWISE_KEY) {
-
-                if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) {
-                    *pKey = &(pTable->KeyTable[i].PairwiseKey);
-
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PAIRWISE_KEY: KeyTable.abyBSSID: ");
-                    for (ii = 0; ii < 6; ii++) {
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
-                    }
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
-
-
-                    return (true);
-                }
-                else {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == false\n");
-                    return (false);
-                }
-            } // End of Type == PAIRWISE
-            else {
-                if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n");
-                    return false;
-                }
-                if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == true) {
-                    *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]);
-
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GROUP_KEY: KeyTable.abyBSSID\n");
-                        for (ii = 0; ii < 6; ii++) {
-                            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
-                        }
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwGTKeyIndex: %lX\n", pTable->KeyTable[i].dwGTKeyIndex);
-
-                    return (true);
-                }
-                else {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == false\n");
-                    return (false);
-                }
-            } // End of Type = GROUP
-        } // BSSID match
-    }
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: NO Match BSSID !!! ");
-    for (ii = 0; ii < 6; ii++) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(pbyBSSID+ii));
-    }
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
-    return (false);
+       int i, ii;
+
+       *pKey = NULL;
+       for (i = 0; i < MAX_KEY_TABLE; i++) {
+               if ((pTable->KeyTable[i].bInUse == true) &&
+                   !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
+                       if (dwKeyType == PAIRWISE_KEY) {
+                               if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) {
+                                       *pKey = &(pTable->KeyTable[i].PairwiseKey);
+
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybGetTransmitKey:");
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PAIRWISE_KEY: KeyTable.abyBSSID: ");
+                                       for (ii = 0; ii < 6; ii++) {
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%x ", pTable->KeyTable[i].abyBSSID[ii]);
+                                       }
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
+
+                                       return true;
+                               } else {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PairwiseKey.bKeyValid == false\n");
+                                       return false;
+                               }
+                       } // End of Type == PAIRWISE
+                       else {
+                               if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ERROR: dwGTKeyIndex == 0 !!!\n");
+                                       return false;
+                               }
+                               if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == true) {
+                                       *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]);
+
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybGetTransmitKey:");
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP_KEY: KeyTable.abyBSSID\n");
+                                       for (ii = 0; ii < 6; ii++) {
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%x ", pTable->KeyTable[i].abyBSSID[ii]);
+                                       }
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwGTKeyIndex: %lX\n", pTable->KeyTable[i].dwGTKeyIndex);
+
+                                       return true;
+                               } else {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GroupKey.bKeyValid == false\n");
+                                       return false;
+                               }
+                       } // End of Type = GROUP
+               } // BSSID match
+       }
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ERROR: NO Match BSSID !!! ");
+       for (ii = 0; ii < 6; ii++) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", *(pbyBSSID+ii));
+       }
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
+       return false;
 }
 
-
 /*
  * Description: Check Pairewise Key
  *
@@ -597,22 +574,22 @@ bool KeybGetTransmitKey (
  * Return Value: true if found otherwise false
  *
  */
-bool KeybCheckPairewiseKey (
-    PSKeyManagement pTable,
-    PSKeyItem       *pKey
-    )
+bool KeybCheckPairewiseKey(
+       PSKeyManagement pTable,
+       PSKeyItem       *pKey
+)
 {
-    int i;
-
-    *pKey = NULL;
-    for (i=0;i<MAX_KEY_TABLE;i++) {
-        if ((pTable->KeyTable[i].bInUse == true) &&
-            (pTable->KeyTable[i].PairwiseKey.bKeyValid == true)) {
-            *pKey = &(pTable->KeyTable[i].PairwiseKey);
-            return (true);
-        }
-    }
-    return (false);
+       int i;
+
+       *pKey = NULL;
+       for (i = 0; i < MAX_KEY_TABLE; i++) {
+               if ((pTable->KeyTable[i].bInUse == true) &&
+                   (pTable->KeyTable[i].PairwiseKey.bKeyValid == true)) {
+                       *pKey = &(pTable->KeyTable[i].PairwiseKey);
+                       return true;
+               }
+       }
+       return false;
 }
 
 /*
@@ -631,100 +608,97 @@ bool KeybCheckPairewiseKey (
  * Return Value: true if success otherwise false
  *
  */
-bool KeybSetDefaultKey (
-    PSKeyManagement pTable,
-    unsigned long dwKeyIndex,
-    unsigned long uKeyLength,
-    PQWORD          pKeyRSC,
-    unsigned char *pbyKey,
-    unsigned char byKeyDecMode,
-    unsigned long dwIoBase,
-    unsigned char byLocalID
-    )
+bool KeybSetDefaultKey(
+       PSKeyManagement pTable,
+       unsigned long dwKeyIndex,
+       unsigned long uKeyLength,
+       PQWORD          pKeyRSC,
+       unsigned char *pbyKey,
+       unsigned char byKeyDecMode,
+       unsigned long dwIoBase,
+       unsigned char byLocalID
+)
 {
-    unsigned int ii;
-    PSKeyItem   pKey;
-    unsigned int uKeyIdx;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex, (int)uKeyLength);
-
-
-    if ((dwKeyIndex & PAIRWISE_KEY) != 0) {                  // Pairwise key
-        return (false);
-    } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
-        return (false);
-    }
-
-    if (uKeyLength > MAX_KEY_LEN)
-           return false;
-
-    pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = true;
-    for(ii=0;ii<ETH_ALEN;ii++)
-        pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF;
-
-    // Group key
-    pKey = &(pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF]);
-    if ((dwKeyIndex & TRANSMIT_KEY) != 0)  {
-        // Group transmit key
-        pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = dwKeyIndex;
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex, MAX_KEY_TABLE-1);
-
-    }
-    pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl &= 0x7F00;          // clear all key control filed
-    pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode << 4);
-    pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode);
-    pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x0044;          // use group key for all address
-    uKeyIdx = (dwKeyIndex & 0x000000FF);
-
-    if ((uKeyLength == WLAN_WEP232_KEYLEN) &&
-        (byKeyDecMode == KEY_CTL_WEP)) {
-        pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000;              // disable on-fly disable address match
-        pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = true;
-    } else {
-        if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == false)
-            pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000;          // enable on-fly disable address match
-    }
-
-    pKey->bKeyValid = true;
-    pKey->uKeyLength = uKeyLength;
-    pKey->dwKeyIndex = dwKeyIndex;
-    pKey->byCipherSuite = byKeyDecMode;
-    memcpy(pKey->abyKey, pbyKey, uKeyLength);
-    if (byKeyDecMode == KEY_CTL_WEP) {
-        if (uKeyLength == WLAN_WEP40_KEYLEN)
-            pKey->abyKey[15] &= 0x7F;
-        if (uKeyLength == WLAN_WEP104_KEYLEN)
-            pKey->abyKey[15] |= 0x80;
-    }
-    MACvSetKeyEntry(dwIoBase, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
-
-    if ((dwKeyIndex & USE_KEYRSC) == 0) {
-        // RSC set by NIC
-           memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
-    } else {
-        memcpy(&(pKey->KeyRSC), pKeyRSC,  sizeof(QWORD));
-    }
-    pKey->dwTSC47_16 = 0;
-    pKey->wTSC15_0 = 0;
-
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n", pKey->bKeyValid);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n", (int)pKey->uKeyLength);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: \n");
-    for (ii = 0; ii < pKey->uKeyLength; ii++) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x", pKey->abyKey[ii]);
-    }
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n", pKey->dwTSC47_16);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n", pKey->wTSC15_0);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n", pKey->dwKeyIndex);
-
-    return (true);
+       unsigned int ii;
+       PSKeyItem   pKey;
+       unsigned int uKeyIdx;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex, (int)uKeyLength);
+
+       if ((dwKeyIndex & PAIRWISE_KEY) != 0) {                  // Pairwise key
+               return false;
+       } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
+               return false;
+       }
+
+       if (uKeyLength > MAX_KEY_LEN)
+               return false;
+
+       pTable->KeyTable[MAX_KEY_TABLE - 1].bInUse = true;
+       for (ii = 0; ii < ETH_ALEN; ii++)
+               pTable->KeyTable[MAX_KEY_TABLE - 1].abyBSSID[ii] = 0xFF;
+
+       // Group key
+       pKey = &(pTable->KeyTable[MAX_KEY_TABLE - 1].GroupKey[dwKeyIndex & 0x000000FF]);
+       if ((dwKeyIndex & TRANSMIT_KEY) != 0)  {
+               // Group transmit key
+               pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = dwKeyIndex;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex, MAX_KEY_TABLE-1);
+
+       }
+       pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl &= 0x7F00;          // clear all key control filed
+       pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode << 4);
+       pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode);
+       pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x0044;          // use group key for all address
+       uKeyIdx = (dwKeyIndex & 0x000000FF);
+
+       if ((uKeyLength == WLAN_WEP232_KEYLEN) &&
+           (byKeyDecMode == KEY_CTL_WEP)) {
+               pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000;              // disable on-fly disable address match
+               pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = true;
+       } else {
+               if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == false)
+                       pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000;          // enable on-fly disable address match
+       }
+
+       pKey->bKeyValid = true;
+       pKey->uKeyLength = uKeyLength;
+       pKey->dwKeyIndex = dwKeyIndex;
+       pKey->byCipherSuite = byKeyDecMode;
+       memcpy(pKey->abyKey, pbyKey, uKeyLength);
+       if (byKeyDecMode == KEY_CTL_WEP) {
+               if (uKeyLength == WLAN_WEP40_KEYLEN)
+                       pKey->abyKey[15] &= 0x7F;
+               if (uKeyLength == WLAN_WEP104_KEYLEN)
+                       pKey->abyKey[15] |= 0x80;
+       }
+       MACvSetKeyEntry(dwIoBase, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
+
+       if ((dwKeyIndex & USE_KEYRSC) == 0) {
+               // RSC set by NIC
+               memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
+       } else {
+               memcpy(&(pKey->KeyRSC), pKeyRSC,  sizeof(QWORD));
+       }
+       pKey->dwTSC47_16 = 0;
+       pKey->wTSC15_0 = 0;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybSetKey(R): \n");
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->bKeyValid: %d\n", pKey->bKeyValid);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->uKeyLength: %d\n", (int)pKey->uKeyLength);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->abyKey: \n");
+       for (ii = 0; ii < pKey->uKeyLength; ii++) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%x", pKey->abyKey[ii]);
+       }
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwTSC47_16: %lx\n", pKey->dwTSC47_16);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->wTSC15_0: %x\n", pKey->wTSC15_0);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->dwKeyIndex: %lx\n", pKey->dwKeyIndex);
+
+       return true;
 }
 
-
 /*
  * Description: Set Key to table
  *
@@ -741,86 +715,84 @@ bool KeybSetDefaultKey (
  * Return Value: true if success otherwise false
  *
  */
-bool KeybSetAllGroupKey (
-    PSKeyManagement pTable,
-    unsigned long dwKeyIndex,
-    unsigned long uKeyLength,
-    PQWORD          pKeyRSC,
-    unsigned char *pbyKey,
-    unsigned char byKeyDecMode,
-    unsigned long dwIoBase,
-    unsigned char byLocalID
-    )
+bool KeybSetAllGroupKey(
+       PSKeyManagement pTable,
+       unsigned long dwKeyIndex,
+       unsigned long uKeyLength,
+       PQWORD          pKeyRSC,
+       unsigned char *pbyKey,
+       unsigned char byKeyDecMode,
+       unsigned long dwIoBase,
+       unsigned char byLocalID
+)
 {
-    int         i;
-    unsigned int ii;
-    PSKeyItem   pKey;
-    unsigned int uKeyIdx;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex);
-
-
-    if ((dwKeyIndex & PAIRWISE_KEY) != 0) {                  // Pairwise key
-        return (false);
-    } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
-        return (false);
-    }
-
-    for (i=0; i < MAX_KEY_TABLE-1; i++) {
-        if (pTable->KeyTable[i].bInUse == true) {
-            // found table already exist
-            // Group key
-            pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
-            if ((dwKeyIndex & TRANSMIT_KEY) != 0)  {
-                // Group transmit key
-                pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
-
-            }
-            pTable->KeyTable[i].wKeyCtl &= 0xFF0F;          // clear group key control filed
-            pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
-            pTable->KeyTable[i].wKeyCtl |= 0x0040;          // use group key for group address
-            uKeyIdx = (dwKeyIndex & 0x000000FF);
-
-            pTable->KeyTable[i].wKeyCtl |= 0x8000;              // enable on-fly
-
-            pKey->bKeyValid = true;
-            pKey->uKeyLength = uKeyLength;
-            pKey->dwKeyIndex = dwKeyIndex;
-            pKey->byCipherSuite = byKeyDecMode;
-            memcpy(pKey->abyKey, pbyKey, uKeyLength);
-            if (byKeyDecMode == KEY_CTL_WEP) {
-                if (uKeyLength == WLAN_WEP40_KEYLEN)
-                    pKey->abyKey[15] &= 0x7F;
-                if (uKeyLength == WLAN_WEP104_KEYLEN)
-                    pKey->abyKey[15] |= 0x80;
-            }
-            MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
-
-            if ((dwKeyIndex & USE_KEYRSC) == 0) {
-                // RSC set by NIC
-                   memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
-            }
-            else {
-                memcpy(&(pKey->KeyRSC), pKeyRSC,  sizeof(QWORD));
-            }
-            pKey->dwTSC47_16 = 0;
-            pKey->wTSC15_0 = 0;
-
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
-            for (ii = 0; ii < pKey->uKeyLength; ii++) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", pKey->abyKey[ii]);
-            }
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
-
-            //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16));
-            //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
-            //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
-
-        } // (pTable->KeyTable[i].bInUse == true)
-    }
-    return (true);
+       int         i;
+       unsigned int ii;
+       PSKeyItem   pKey;
+       unsigned int uKeyIdx;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex);
+
+       if ((dwKeyIndex & PAIRWISE_KEY) != 0) {                  // Pairwise key
+               return false;
+       } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
+               return false;
+       }
+
+       for (i = 0; i < MAX_KEY_TABLE - 1; i++) {
+               if (pTable->KeyTable[i].bInUse == true) {
+                       // found table already exist
+                       // Group key
+                       pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
+                       if ((dwKeyIndex & TRANSMIT_KEY) != 0)  {
+                               // Group transmit key
+                               pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
+
+                       }
+                       pTable->KeyTable[i].wKeyCtl &= 0xFF0F;          // clear group key control filed
+                       pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
+                       pTable->KeyTable[i].wKeyCtl |= 0x0040;          // use group key for group address
+                       uKeyIdx = (dwKeyIndex & 0x000000FF);
+
+                       pTable->KeyTable[i].wKeyCtl |= 0x8000;              // enable on-fly
+
+                       pKey->bKeyValid = true;
+                       pKey->uKeyLength = uKeyLength;
+                       pKey->dwKeyIndex = dwKeyIndex;
+                       pKey->byCipherSuite = byKeyDecMode;
+                       memcpy(pKey->abyKey, pbyKey, uKeyLength);
+                       if (byKeyDecMode == KEY_CTL_WEP) {
+                               if (uKeyLength == WLAN_WEP40_KEYLEN)
+                                       pKey->abyKey[15] &= 0x7F;
+                               if (uKeyLength == WLAN_WEP104_KEYLEN)
+                                       pKey->abyKey[15] |= 0x80;
+                       }
+                       MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (unsigned long *)pKey->abyKey, byLocalID);
+
+                       if ((dwKeyIndex & USE_KEYRSC) == 0) {
+                               // RSC set by NIC
+                               memset(&(pKey->KeyRSC), 0, sizeof(QWORD));
+                       } else {
+                               memcpy(&(pKey->KeyRSC), pKeyRSC,  sizeof(QWORD));
+                       }
+                       pKey->dwTSC47_16 = 0;
+                       pKey->wTSC15_0 = 0;
+
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybSetKey(R): \n");
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->bKeyValid: %d\n ", pKey->bKeyValid);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey->abyKey: ");
+                       for (ii = 0; ii < pKey->uKeyLength; ii++) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
+                       }
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
+
+                       //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16));
+                       //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
+                       //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
+
+               } // (pTable->KeyTable[i].bInUse == true)
+       }
+       return true;
 }
index 6b2dad331a5bc7a3f1e5ad7f0371c383a8e23a3a..356e6de8f87f0e59658e1611bf81d4ebd8278cfd 100644 (file)
@@ -40,7 +40,6 @@
 #define MAX_KEY_LEN         32
 #define AES_KEY_LEN         16
 
-
 #define AUTHENTICATOR_KEY   0x10000000
 #define USE_KEYRSC          0x20000000
 #define PAIRWISE_KEY        0x40000000
 #define KEY_CTL_CCMP        0x03
 #define KEY_CTL_INVALID     0xFF
 
-
 typedef struct tagSKeyItem
 {
-    bool bKeyValid;
-    unsigned long uKeyLength;
-    unsigned char abyKey[MAX_KEY_LEN];
-    QWORD       KeyRSC;
-    unsigned long dwTSC47_16;
-    unsigned short wTSC15_0;
-    unsigned char byCipherSuite;
-    unsigned char byReserved0;
-    unsigned long dwKeyIndex;
-    void *pvKeyTable;
+       bool bKeyValid;
+       unsigned long uKeyLength;
+       unsigned char abyKey[MAX_KEY_LEN];
+       QWORD       KeyRSC;
+       unsigned long dwTSC47_16;
+       unsigned short wTSC15_0;
+       unsigned char byCipherSuite;
+       unsigned char byReserved0;
+       unsigned long dwKeyIndex;
+       void *pvKeyTable;
 } SKeyItem, *PSKeyItem; //64
 
 typedef struct tagSKeyTable
 {
-    unsigned char abyBSSID[ETH_ALEN];  //6
-    unsigned char byReserved0[2];              //8
-    SKeyItem    PairwiseKey;
-    SKeyItem    GroupKey[MAX_GROUP_KEY]; //64*5 = 320, 320+8=328
-    unsigned long dwGTKeyIndex;            // GroupTransmitKey Index
-    bool bInUse;
-    //2006-1116-01,<Modify> by NomadZhao
-    //unsigned short wKeyCtl;
-    //bool bSoftWEP;
-    bool bSoftWEP;
-    unsigned short wKeyCtl;      // for address of wKeyCtl at align 4
-
-    unsigned char byReserved1[6];
+       unsigned char abyBSSID[ETH_ALEN];  //6
+       unsigned char byReserved0[2];              //8
+       SKeyItem    PairwiseKey;
+       SKeyItem    GroupKey[MAX_GROUP_KEY]; //64*5 = 320, 320+8=328
+       unsigned long dwGTKeyIndex;            // GroupTransmitKey Index
+       bool bInUse;
+       //2006-1116-01,<Modify> by NomadZhao
+       //unsigned short wKeyCtl;
+       //bool bSoftWEP;
+       bool bSoftWEP;
+       unsigned short wKeyCtl;      // for address of wKeyCtl at align 4
+
+       unsigned char byReserved1[6];
 } SKeyTable, *PSKeyTable; //348
 
 typedef struct tagSKeyManagement
 {
-    SKeyTable   KeyTable[MAX_KEY_TABLE];
-} SKeyManagement, * PSKeyManagement;
+       SKeyTable   KeyTable[MAX_KEY_TABLE];
+} SKeyManagement, *PSKeyManagement;
 
 /*---------------------  Export Types  ------------------------------*/
 
@@ -104,81 +102,80 @@ typedef struct tagSKeyManagement
 void KeyvInitTable(PSKeyManagement pTable, unsigned long dwIoBase);
 
 bool KeybGetKey(
-    PSKeyManagement pTable,
-    unsigned char *pbyBSSID,
-    unsigned long dwKeyIndex,
-    PSKeyItem       *pKey
-    );
+       PSKeyManagement pTable,
+       unsigned char *pbyBSSID,
+       unsigned long dwKeyIndex,
+       PSKeyItem       *pKey
+);
 
 bool KeybSetKey(
-    PSKeyManagement pTable,
-    unsigned char *pbyBSSID,
-    unsigned long dwKeyIndex,
-    unsigned long uKeyLength,
-    PQWORD          pKeyRSC,
-    unsigned char *pbyKey,
-    unsigned char byKeyDecMode,
-    unsigned long dwIoBase,
-    unsigned char byLocalID
-    );
+       PSKeyManagement pTable,
+       unsigned char *pbyBSSID,
+       unsigned long dwKeyIndex,
+       unsigned long uKeyLength,
+       PQWORD          pKeyRSC,
+       unsigned char *pbyKey,
+       unsigned char byKeyDecMode,
+       unsigned long dwIoBase,
+       unsigned char byLocalID
+);
 
 bool KeybSetDefaultKey(
-    PSKeyManagement pTable,
-    unsigned long dwKeyIndex,
-    unsigned long uKeyLength,
-    PQWORD          pKeyRSC,
-    unsigned char *pbyKey,
-    unsigned char byKeyDecMode,
-    unsigned long dwIoBase,
-    unsigned char byLocalID
-    );
+       PSKeyManagement pTable,
+       unsigned long dwKeyIndex,
+       unsigned long uKeyLength,
+       PQWORD          pKeyRSC,
+       unsigned char *pbyKey,
+       unsigned char byKeyDecMode,
+       unsigned long dwIoBase,
+       unsigned char byLocalID
+);
 
 bool KeybRemoveKey(
-    PSKeyManagement pTable,
-    unsigned char *pbyBSSID,
-    unsigned long dwKeyIndex,
-    unsigned long dwIoBase
-    );
+       PSKeyManagement pTable,
+       unsigned char *pbyBSSID,
+       unsigned long dwKeyIndex,
+       unsigned long dwIoBase
+);
 
 bool KeybGetTransmitKey(
-    PSKeyManagement pTable,
-    unsigned char *pbyBSSID,
-    unsigned long dwKeyType,
-    PSKeyItem       *pKey
-    );
+       PSKeyManagement pTable,
+       unsigned char *pbyBSSID,
+       unsigned long dwKeyType,
+       PSKeyItem       *pKey
+);
 
 bool KeybCheckPairewiseKey(
-    PSKeyManagement pTable,
-    PSKeyItem       *pKey
-    );
+       PSKeyManagement pTable,
+       PSKeyItem       *pKey
+);
 
 bool KeybRemoveAllKey(
-    PSKeyManagement pTable,
-    unsigned char *pbyBSSID,
-    unsigned long dwIoBase
-    );
+       PSKeyManagement pTable,
+       unsigned char *pbyBSSID,
+       unsigned long dwIoBase
+);
 
 void KeyvRemoveWEPKey(
-    PSKeyManagement pTable,
-    unsigned long dwKeyIndex,
-    unsigned long dwIoBase
-    );
+       PSKeyManagement pTable,
+       unsigned long dwKeyIndex,
+       unsigned long dwIoBase
+);
 
 void KeyvRemoveAllWEPKey(
-    PSKeyManagement pTable,
-    unsigned long dwIoBase
-    );
-
-bool KeybSetAllGroupKey (
-    PSKeyManagement pTable,
-    unsigned long dwKeyIndex,
-    unsigned long uKeyLength,
-    PQWORD          pKeyRSC,
-    unsigned char *pbyKey,
-    unsigned char byKeyDecMode,
-    unsigned long dwIoBase,
-    unsigned char byLocalID
-    );
+       PSKeyManagement pTable,
+       unsigned long dwIoBase
+);
+
+bool KeybSetAllGroupKey(
+       PSKeyManagement pTable,
+       unsigned long dwKeyIndex,
+       unsigned long uKeyLength,
+       PQWORD          pKeyRSC,
+       unsigned char *pbyKey,
+       unsigned char byKeyDecMode,
+       unsigned long dwIoBase,
+       unsigned char byLocalID
+);
 
 #endif // __KEY_H__
-
index 30c261579412260af66fc99fc5400bb9315a77b1..001d15c0fa40721c7188e953a970fc1ebbd8dd39 100644 (file)
@@ -75,7 +75,7 @@
 unsigned short TxRate_iwconfig;//2008-5-8 <add> by chester
 /*---------------------  Static Definitions -------------------------*/
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 /*---------------------  Static Classes  ----------------------------*/
 
 /*---------------------  Static Variables  --------------------------*/
@@ -86,10 +86,6 @@ static int          msglevel                =MSG_LEVEL_INFO;
 
 /*---------------------  Export Functions  --------------------------*/
 
-
-
-
-
 /*
  * Description:
  *      Read All MAC Registers to buffer
@@ -103,26 +99,25 @@ static int          msglevel                =MSG_LEVEL_INFO;
  * Return Value: none
  *
  */
-void MACvReadAllRegs (unsigned long dwIoBase, unsigned char *pbyMacRegs)
+void MACvReadAllRegs(unsigned long dwIoBase, unsigned char *pbyMacRegs)
 {
-    int ii;
-
-    // read page0 register
-    for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
-        VNSvInPortB(dwIoBase + ii, pbyMacRegs);
-        pbyMacRegs++;
-    }
+       int ii;
 
-    MACvSelectPage1(dwIoBase);
+       // read page0 register
+       for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
+               VNSvInPortB(dwIoBase + ii, pbyMacRegs);
+               pbyMacRegs++;
+       }
 
-    // read page1 register
-    for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
-        VNSvInPortB(dwIoBase + ii, pbyMacRegs);
-        pbyMacRegs++;
-    }
+       MACvSelectPage1(dwIoBase);
 
-    MACvSelectPage0(dwIoBase);
+       // read page1 register
+       for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
+               VNSvInPortB(dwIoBase + ii, pbyMacRegs);
+               pbyMacRegs++;
+       }
 
+       MACvSelectPage0(dwIoBase);
 }
 
 /*
@@ -140,12 +135,12 @@ void MACvReadAllRegs (unsigned long dwIoBase, unsigned char *pbyMacRegs)
  * Return Value: true if all test bits On; otherwise false
  *
  */
-bool MACbIsRegBitsOn (unsigned long dwIoBase, unsigned char byRegOfs, unsigned char byTestBits)
+bool MACbIsRegBitsOn(unsigned long dwIoBase, unsigned char byRegOfs, unsigned char byTestBits)
 {
-    unsigned char byData;
+       unsigned char byData;
 
-    VNSvInPortB(dwIoBase + byRegOfs, &byData);
-    return (byData & byTestBits) == byTestBits;
+       VNSvInPortB(dwIoBase + byRegOfs, &byData);
+       return (byData & byTestBits) == byTestBits;
 }
 
 /*
@@ -163,12 +158,12 @@ bool MACbIsRegBitsOn (unsigned long dwIoBase, unsigned char byRegOfs, unsigned c
  * Return Value: true if all test bits Off; otherwise false
  *
  */
-bool MACbIsRegBitsOff (unsigned long dwIoBase, unsigned char byRegOfs, unsigned char byTestBits)
+bool MACbIsRegBitsOff(unsigned long dwIoBase, unsigned char byRegOfs, unsigned char byTestBits)
 {
-    unsigned char byData;
+       unsigned char byData;
 
-    VNSvInPortB(dwIoBase + byRegOfs, &byData);
-    return !(byData & byTestBits);
+       VNSvInPortB(dwIoBase + byRegOfs, &byData);
+       return !(byData & byTestBits);
 }
 
 /*
@@ -184,15 +179,15 @@ bool MACbIsRegBitsOff (unsigned long dwIoBase, unsigned char byRegOfs, unsigned
  * Return Value: true if interrupt is disable; otherwise false
  *
  */
-bool MACbIsIntDisable (unsigned long dwIoBase)
+bool MACbIsIntDisable(unsigned long dwIoBase)
 {
-    unsigned long dwData;
+       unsigned long dwData;
 
-    VNSvInPortD(dwIoBase + MAC_REG_IMR, &dwData);
-    if (dwData != 0)
-        return false;
+       VNSvInPortD(dwIoBase + MAC_REG_IMR, &dwData);
+       if (dwData != 0)
+               return false;
 
-    return true;
+       return true;
 }
 
 /*
@@ -209,14 +204,14 @@ bool MACbIsIntDisable (unsigned long dwIoBase)
  * Return Value: Mask Value read
  *
  */
-unsigned char MACbyReadMultiAddr (unsigned long dwIoBase, unsigned int uByteIdx)
+unsigned char MACbyReadMultiAddr(unsigned long dwIoBase, unsigned int uByteIdx)
 {
-    unsigned char byData;
+       unsigned char byData;
 
-    MACvSelectPage1(dwIoBase);
-    VNSvInPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, &byData);
-    MACvSelectPage0(dwIoBase);
-    return byData;
+       MACvSelectPage1(dwIoBase);
+       VNSvInPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, &byData);
+       MACvSelectPage0(dwIoBase);
+       return byData;
 }
 
 /*
@@ -234,11 +229,11 @@ unsigned char MACbyReadMultiAddr (unsigned long dwIoBase, unsigned int uByteIdx)
  * Return Value: none
  *
  */
-void MACvWriteMultiAddr (unsigned long dwIoBase, unsigned int uByteIdx, unsigned char byData)
+void MACvWriteMultiAddr(unsigned long dwIoBase, unsigned int uByteIdx, unsigned char byData)
 {
-    MACvSelectPage1(dwIoBase);
-    VNSvOutPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, byData);
-    MACvSelectPage0(dwIoBase);
+       MACvSelectPage1(dwIoBase);
+       VNSvOutPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, byData);
+       MACvSelectPage0(dwIoBase);
 }
 
 /*
@@ -255,21 +250,21 @@ void MACvWriteMultiAddr (unsigned long dwIoBase, unsigned int uByteIdx, unsigned
  * Return Value: none
  *
  */
-void MACvSetMultiAddrByHash (unsigned long dwIoBase, unsigned char byHashIdx)
+void MACvSetMultiAddrByHash(unsigned long dwIoBase, unsigned char byHashIdx)
 {
-    unsigned int uByteIdx;
-    unsigned char byBitMask;
-    unsigned char byOrgValue;
-
-    // calculate byte position
-    uByteIdx = byHashIdx / 8;
-    ASSERT(uByteIdx < 8);
-    // calculate bit position
-    byBitMask = 1;
-    byBitMask <<= (byHashIdx % 8);
-    // turn on the bit
-    byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
-    MACvWriteMultiAddr(dwIoBase, uByteIdx, (unsigned char)(byOrgValue | byBitMask));
+       unsigned int uByteIdx;
+       unsigned char byBitMask;
+       unsigned char byOrgValue;
+
+       // calculate byte position
+       uByteIdx = byHashIdx / 8;
+       ASSERT(uByteIdx < 8);
+       // calculate bit position
+       byBitMask = 1;
+       byBitMask <<= (byHashIdx % 8);
+       // turn on the bit
+       byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
+       MACvWriteMultiAddr(dwIoBase, uByteIdx, (unsigned char)(byOrgValue | byBitMask));
 }
 
 /*
@@ -286,21 +281,21 @@ void MACvSetMultiAddrByHash (unsigned long dwIoBase, unsigned char byHashIdx)
  * Return Value: none
  *
  */
-void MACvResetMultiAddrByHash (unsigned long dwIoBase, unsigned char byHashIdx)
+void MACvResetMultiAddrByHash(unsigned long dwIoBase, unsigned char byHashIdx)
 {
-    unsigned int uByteIdx;
-    unsigned char byBitMask;
-    unsigned char byOrgValue;
-
-    // calculate byte position
-    uByteIdx = byHashIdx / 8;
-    ASSERT(uByteIdx < 8);
-    // calculate bit position
-    byBitMask = 1;
-    byBitMask <<= (byHashIdx % 8);
-    // turn off the bit
-    byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
-    MACvWriteMultiAddr(dwIoBase, uByteIdx, (unsigned char)(byOrgValue & (~byBitMask)));
+       unsigned int uByteIdx;
+       unsigned char byBitMask;
+       unsigned char byOrgValue;
+
+       // calculate byte position
+       uByteIdx = byHashIdx / 8;
+       ASSERT(uByteIdx < 8);
+       // calculate bit position
+       byBitMask = 1;
+       byBitMask <<= (byHashIdx % 8);
+       // turn off the bit
+       byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
+       MACvWriteMultiAddr(dwIoBase, uByteIdx, (unsigned char)(byOrgValue & (~byBitMask)));
 }
 
 /*
@@ -317,16 +312,16 @@ void MACvResetMultiAddrByHash (unsigned long dwIoBase, unsigned char byHashIdx)
  * Return Value: none
  *
  */
-void MACvSetRxThreshold (unsigned long dwIoBase, unsigned char byThreshold)
+void MACvSetRxThreshold(unsigned long dwIoBase, unsigned char byThreshold)
 {
-    unsigned char byOrgValue;
+       unsigned char byOrgValue;
 
-    ASSERT(byThreshold < 4);
+       ASSERT(byThreshold < 4);
 
-    // set FCR0
-    VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
-    byOrgValue = (byOrgValue & 0xCF) | (byThreshold << 4);
-    VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
+       // set FCR0
+       VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
+       byOrgValue = (byOrgValue & 0xCF) | (byThreshold << 4);
+       VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
 }
 
 /*
@@ -342,11 +337,11 @@ void MACvSetRxThreshold (unsigned long dwIoBase, unsigned char byThreshold)
  * Return Value: none
  *
  */
-void MACvGetRxThreshold (unsigned long dwIoBase, unsigned char *pbyThreshold)
+void MACvGetRxThreshold(unsigned long dwIoBase, unsigned char *pbyThreshold)
 {
-    // get FCR0
-    VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
-    *pbyThreshold = (*pbyThreshold >> 4) & 0x03;
+       // get FCR0
+       VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
+       *pbyThreshold = (*pbyThreshold >> 4) & 0x03;
 }
 
 /*
@@ -363,16 +358,16 @@ void MACvGetRxThreshold (unsigned long dwIoBase, unsigned char *pbyThreshold)
  * Return Value: none
  *
  */
-void MACvSetTxThreshold (unsigned long dwIoBase, unsigned char byThreshold)
+void MACvSetTxThreshold(unsigned long dwIoBase, unsigned char byThreshold)
 {
-    unsigned char byOrgValue;
+       unsigned char byOrgValue;
 
-    ASSERT(byThreshold < 4);
+       ASSERT(byThreshold < 4);
 
-    // set FCR0
-    VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
-    byOrgValue = (byOrgValue & 0xF3) | (byThreshold << 2);
-    VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
+       // set FCR0
+       VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
+       byOrgValue = (byOrgValue & 0xF3) | (byThreshold << 2);
+       VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
 }
 
 /*
@@ -388,11 +383,11 @@ void MACvSetTxThreshold (unsigned long dwIoBase, unsigned char byThreshold)
  * Return Value: none
  *
  */
-void MACvGetTxThreshold (unsigned long dwIoBase, unsigned char *pbyThreshold)
+void MACvGetTxThreshold(unsigned long dwIoBase, unsigned char *pbyThreshold)
 {
-    // get FCR0
-    VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
-    *pbyThreshold = (*pbyThreshold >> 2) & 0x03;
+       // get FCR0
+       VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
+       *pbyThreshold = (*pbyThreshold >> 2) & 0x03;
 }
 
 /*
@@ -409,16 +404,16 @@ void MACvGetTxThreshold (unsigned long dwIoBase, unsigned char *pbyThreshold)
  * Return Value: none
  *
  */
-void MACvSetDmaLength (unsigned long dwIoBase, unsigned char byDmaLength)
+void MACvSetDmaLength(unsigned long dwIoBase, unsigned char byDmaLength)
 {
-    unsigned char byOrgValue;
+       unsigned char byOrgValue;
 
-    ASSERT(byDmaLength < 4);
+       ASSERT(byDmaLength < 4);
 
-    // set FCR0
-    VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
-    byOrgValue = (byOrgValue & 0xFC) | byDmaLength;
-    VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
+       // set FCR0
+       VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
+       byOrgValue = (byOrgValue & 0xFC) | byDmaLength;
+       VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
 }
 
 /*
@@ -434,11 +429,11 @@ void MACvSetDmaLength (unsigned long dwIoBase, unsigned char byDmaLength)
  * Return Value: none
  *
  */
-void MACvGetDmaLength (unsigned long dwIoBase, unsigned char *pbyDmaLength)
+void MACvGetDmaLength(unsigned long dwIoBase, unsigned char *pbyDmaLength)
 {
-    // get FCR0
-    VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyDmaLength);
-    *pbyDmaLength &= 0x03;
+       // get FCR0
+       VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyDmaLength);
+       *pbyDmaLength &= 0x03;
 }
 
 /*
@@ -455,10 +450,10 @@ void MACvGetDmaLength (unsigned long dwIoBase, unsigned char *pbyDmaLength)
  * Return Value: none
  *
  */
-void MACvSetShortRetryLimit (unsigned long dwIoBase, unsigned char byRetryLimit)
+void MACvSetShortRetryLimit(unsigned long dwIoBase, unsigned char byRetryLimit)
 {
-    // set SRT
-    VNSvOutPortB(dwIoBase + MAC_REG_SRT, byRetryLimit);
+       // set SRT
+       VNSvOutPortB(dwIoBase + MAC_REG_SRT, byRetryLimit);
 }
 
 /*
@@ -474,10 +469,10 @@ void MACvSetShortRetryLimit (unsigned long dwIoBase, unsigned char byRetryLimit)
  * Return Value: none
  *
  */
-void MACvGetShortRetryLimit (unsigned long dwIoBase, unsigned char *pbyRetryLimit)
+void MACvGetShortRetryLimit(unsigned long dwIoBase, unsigned char *pbyRetryLimit)
 {
-    // get SRT
-    VNSvInPortB(dwIoBase + MAC_REG_SRT, pbyRetryLimit);
+       // get SRT
+       VNSvInPortB(dwIoBase + MAC_REG_SRT, pbyRetryLimit);
 }
 
 /*
@@ -494,10 +489,10 @@ void MACvGetShortRetryLimit (unsigned long dwIoBase, unsigned char *pbyRetryLimi
  * Return Value: none
  *
  */
-void MACvSetLongRetryLimit (unsigned long dwIoBase, unsigned char byRetryLimit)
+void MACvSetLongRetryLimit(unsigned long dwIoBase, unsigned char byRetryLimit)
 {
-    // set LRT
-    VNSvOutPortB(dwIoBase + MAC_REG_LRT, byRetryLimit);
+       // set LRT
+       VNSvOutPortB(dwIoBase + MAC_REG_LRT, byRetryLimit);
 }
 
 /*
@@ -513,10 +508,10 @@ void MACvSetLongRetryLimit (unsigned long dwIoBase, unsigned char byRetryLimit)
  * Return Value: none
  *
  */
-void MACvGetLongRetryLimit (unsigned long dwIoBase, unsigned char *pbyRetryLimit)
+void MACvGetLongRetryLimit(unsigned long dwIoBase, unsigned char *pbyRetryLimit)
 {
-    // get LRT
-    VNSvInPortB(dwIoBase + MAC_REG_LRT, pbyRetryLimit);
+       // get LRT
+       VNSvInPortB(dwIoBase + MAC_REG_LRT, pbyRetryLimit);
 }
 
 /*
@@ -533,17 +528,17 @@ void MACvGetLongRetryLimit (unsigned long dwIoBase, unsigned char *pbyRetryLimit
  * Return Value: none
  *
  */
-void MACvSetLoopbackMode (unsigned long dwIoBase, unsigned char byLoopbackMode)
+void MACvSetLoopbackMode(unsigned long dwIoBase, unsigned char byLoopbackMode)
 {
-    unsigned char byOrgValue;
-
-    ASSERT(byLoopbackMode < 3);
-    byLoopbackMode <<= 6;
-    // set TCR
-    VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
-    byOrgValue = byOrgValue & 0x3F;
-    byOrgValue = byOrgValue | byLoopbackMode;
-    VNSvOutPortB(dwIoBase + MAC_REG_TEST, byOrgValue);
+       unsigned char byOrgValue;
+
+       ASSERT(byLoopbackMode < 3);
+       byLoopbackMode <<= 6;
+       // set TCR
+       VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
+       byOrgValue = byOrgValue & 0x3F;
+       byOrgValue = byOrgValue | byLoopbackMode;
+       VNSvOutPortB(dwIoBase + MAC_REG_TEST, byOrgValue);
 }
 
 /*
@@ -559,14 +554,14 @@ void MACvSetLoopbackMode (unsigned long dwIoBase, unsigned char byLoopbackMode)
  * Return Value: true if in Loopback mode; otherwise false
  *
  */
-bool MACbIsInLoopbackMode (unsigned long dwIoBase)
+bool MACbIsInLoopbackMode(unsigned long dwIoBase)
 {
-    unsigned char byOrgValue;
+       unsigned char byOrgValue;
 
-    VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
-    if (byOrgValue & (TEST_LBINT | TEST_LBEXT))
-        return true;
-    return false;
+       VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
+       if (byOrgValue & (TEST_LBINT | TEST_LBEXT))
+               return true;
+       return false;
 }
 
 /*
@@ -583,51 +578,50 @@ bool MACbIsInLoopbackMode (unsigned long dwIoBase)
  * Return Value: none
  *
  */
-void MACvSetPacketFilter (unsigned long dwIoBase, unsigned short wFilterType)
+void MACvSetPacketFilter(unsigned long dwIoBase, unsigned short wFilterType)
 {
-    unsigned char byOldRCR;
-    unsigned char byNewRCR = 0;
-
-    // if only in DIRECTED mode, multicast-address will set to zero,
-    // but if other mode exist (e.g. PROMISCUOUS), multicast-address
-    // will be open
-    if (wFilterType & PKT_TYPE_DIRECTED) {
-        // set multicast address to accept none
-        MACvSelectPage1(dwIoBase);
-        VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0L);
-        VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(unsigned long), 0L);
-        MACvSelectPage0(dwIoBase);
-    }
-
-    if (wFilterType & (PKT_TYPE_PROMISCUOUS | PKT_TYPE_ALL_MULTICAST)) {
-        // set multicast address to accept all
-        MACvSelectPage1(dwIoBase);
-        VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0xFFFFFFFFL);
-        VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(unsigned long), 0xFFFFFFFFL);
-        MACvSelectPage0(dwIoBase);
-    }
-
-    if (wFilterType & PKT_TYPE_PROMISCUOUS) {
-
-        byNewRCR |= (RCR_RXALLTYPE | RCR_UNICAST | RCR_MULTICAST | RCR_BROADCAST);
-
-        byNewRCR &= ~RCR_BSSID;
-    }
-
-    if (wFilterType & (PKT_TYPE_ALL_MULTICAST | PKT_TYPE_MULTICAST))
-        byNewRCR |= RCR_MULTICAST;
-
-    if (wFilterType & PKT_TYPE_BROADCAST)
-        byNewRCR |= RCR_BROADCAST;
-
-    if (wFilterType & PKT_TYPE_ERROR_CRC)
-        byNewRCR |= RCR_ERRCRC;
-
-    VNSvInPortB(dwIoBase + MAC_REG_RCR,  &byOldRCR);
-    if (byNewRCR != byOldRCR) {
-        // Modify the Receive Command Register
-        VNSvOutPortB(dwIoBase + MAC_REG_RCR, byNewRCR);
-    }
+       unsigned char byOldRCR;
+       unsigned char byNewRCR = 0;
+
+       // if only in DIRECTED mode, multicast-address will set to zero,
+       // but if other mode exist (e.g. PROMISCUOUS), multicast-address
+       // will be open
+       if (wFilterType & PKT_TYPE_DIRECTED) {
+               // set multicast address to accept none
+               MACvSelectPage1(dwIoBase);
+               VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0L);
+               VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(unsigned long), 0L);
+               MACvSelectPage0(dwIoBase);
+       }
+
+       if (wFilterType & (PKT_TYPE_PROMISCUOUS | PKT_TYPE_ALL_MULTICAST)) {
+               // set multicast address to accept all
+               MACvSelectPage1(dwIoBase);
+               VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0xFFFFFFFFL);
+               VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(unsigned long), 0xFFFFFFFFL);
+               MACvSelectPage0(dwIoBase);
+       }
+
+       if (wFilterType & PKT_TYPE_PROMISCUOUS) {
+               byNewRCR |= (RCR_RXALLTYPE | RCR_UNICAST | RCR_MULTICAST | RCR_BROADCAST);
+
+               byNewRCR &= ~RCR_BSSID;
+       }
+
+       if (wFilterType & (PKT_TYPE_ALL_MULTICAST | PKT_TYPE_MULTICAST))
+               byNewRCR |= RCR_MULTICAST;
+
+       if (wFilterType & PKT_TYPE_BROADCAST)
+               byNewRCR |= RCR_BROADCAST;
+
+       if (wFilterType & PKT_TYPE_ERROR_CRC)
+               byNewRCR |= RCR_ERRCRC;
+
+       VNSvInPortB(dwIoBase + MAC_REG_RCR,  &byOldRCR);
+       if (byNewRCR != byOldRCR) {
+               // Modify the Receive Command Register
+               VNSvOutPortB(dwIoBase + MAC_REG_RCR, byNewRCR);
+       }
 }
 
 /*
@@ -643,23 +637,23 @@ void MACvSetPacketFilter (unsigned long dwIoBase, unsigned short wFilterType)
  * Return Value: none
  *
  */
-void MACvSaveContext (unsigned long dwIoBase, unsigned char *pbyCxtBuf)
+void MACvSaveContext(unsigned long dwIoBase, unsigned char *pbyCxtBuf)
 {
-    int         ii;
+       int         ii;
 
-    // read page0 register
-    for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
-        VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + ii));
-    }
+       // read page0 register
+       for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
+               VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + ii));
+       }
 
-    MACvSelectPage1(dwIoBase);
+       MACvSelectPage1(dwIoBase);
 
-    // read page1 register
-    for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
-        VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
-    }
+       // read page1 register
+       for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
+               VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
+       }
 
-    MACvSelectPage0(dwIoBase);
+       MACvSelectPage0(dwIoBase);
 }
 
 /*
@@ -676,42 +670,40 @@ void MACvSaveContext (unsigned long dwIoBase, unsigned char *pbyCxtBuf)
  * Return Value: none
  *
  */
-void MACvRestoreContext (unsigned long dwIoBase, unsigned char *pbyCxtBuf)
+void MACvRestoreContext(unsigned long dwIoBase, unsigned char *pbyCxtBuf)
 {
-    int         ii;
-
-    MACvSelectPage1(dwIoBase);
-    // restore page1
-    for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
-        VNSvOutPortB((dwIoBase + ii), *(pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
-    }
-    MACvSelectPage0(dwIoBase);
-
-    // restore RCR,TCR,IMR...
-    for (ii = MAC_REG_RCR; ii < MAC_REG_ISR; ii++) {
-        VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
-    }
-    // restore MAC Config.
-    for (ii = MAC_REG_LRT; ii < MAC_REG_PAGE1SEL; ii++) {
-        VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
-    }
-    VNSvOutPortB(dwIoBase + MAC_REG_CFG, *(pbyCxtBuf + MAC_REG_CFG));
-
-    // restore PS Config.
-    for (ii = MAC_REG_PSCFG; ii < MAC_REG_BBREGCTL; ii++) {
-        VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
-    }
-
-    // restore CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
-    VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, *(unsigned long *)(pbyCxtBuf + MAC_REG_TXDMAPTR0));
-    VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, *(unsigned long *)(pbyCxtBuf + MAC_REG_AC0DMAPTR));
-    VNSvOutPortD(dwIoBase + MAC_REG_BCNDMAPTR, *(unsigned long *)(pbyCxtBuf + MAC_REG_BCNDMAPTR));
-
-
-    VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR0));
-
-    VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR1));
-
+       int         ii;
+
+       MACvSelectPage1(dwIoBase);
+       // restore page1
+       for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
+               VNSvOutPortB((dwIoBase + ii), *(pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
+       }
+       MACvSelectPage0(dwIoBase);
+
+       // restore RCR,TCR,IMR...
+       for (ii = MAC_REG_RCR; ii < MAC_REG_ISR; ii++) {
+               VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
+       }
+       // restore MAC Config.
+       for (ii = MAC_REG_LRT; ii < MAC_REG_PAGE1SEL; ii++) {
+               VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
+       }
+       VNSvOutPortB(dwIoBase + MAC_REG_CFG, *(pbyCxtBuf + MAC_REG_CFG));
+
+       // restore PS Config.
+       for (ii = MAC_REG_PSCFG; ii < MAC_REG_BBREGCTL; ii++) {
+               VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
+       }
+
+       // restore CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
+       VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, *(unsigned long *)(pbyCxtBuf + MAC_REG_TXDMAPTR0));
+       VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, *(unsigned long *)(pbyCxtBuf + MAC_REG_AC0DMAPTR));
+       VNSvOutPortD(dwIoBase + MAC_REG_BCNDMAPTR, *(unsigned long *)(pbyCxtBuf + MAC_REG_BCNDMAPTR));
+
+       VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR0));
+
+       VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR1));
 }
 
 /*
@@ -728,36 +720,35 @@ void MACvRestoreContext (unsigned long dwIoBase, unsigned char *pbyCxtBuf)
  * Return Value: true if all values are the same; otherwise false
  *
  */
-bool MACbCompareContext (unsigned long dwIoBase, unsigned char *pbyCxtBuf)
+bool MACbCompareContext(unsigned long dwIoBase, unsigned char *pbyCxtBuf)
 {
-    unsigned long dwData;
-
-    // compare MAC context to determine if this is a power lost init,
-    // return true for power remaining init, return false for power lost init
+       unsigned long dwData;
 
-    // compare CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
-    VNSvInPortD(dwIoBase + MAC_REG_TXDMAPTR0, &dwData);
-    if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_TXDMAPTR0)) {
-        return false;
-    }
+       // compare MAC context to determine if this is a power lost init,
+       // return true for power remaining init, return false for power lost init
 
-    VNSvInPortD(dwIoBase + MAC_REG_AC0DMAPTR, &dwData);
-    if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_AC0DMAPTR)) {
-        return false;
-    }
+       // compare CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
+       VNSvInPortD(dwIoBase + MAC_REG_TXDMAPTR0, &dwData);
+       if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_TXDMAPTR0)) {
+               return false;
+       }
 
-    VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR0, &dwData);
-    if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR0)) {
-        return false;
-    }
+       VNSvInPortD(dwIoBase + MAC_REG_AC0DMAPTR, &dwData);
+       if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_AC0DMAPTR)) {
+               return false;
+       }
 
-    VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR1, &dwData);
-    if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR1)) {
-        return false;
-    }
+       VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR0, &dwData);
+       if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR0)) {
+               return false;
+       }
 
+       VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR1, &dwData);
+       if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR1)) {
+               return false;
+       }
 
-    return true;
+       return true;
 }
 
 /*
@@ -773,24 +764,23 @@ bool MACbCompareContext (unsigned long dwIoBase, unsigned char *pbyCxtBuf)
  * Return Value: true if Reset Success; otherwise false
  *
  */
-bool MACbSoftwareReset (unsigned long dwIoBase)
+bool MACbSoftwareReset(unsigned long dwIoBase)
 {
-    unsigned char byData;
-    unsigned short ww;
-
-    // turn on HOSTCR_SOFTRST, just write 0x01 to reset
-    //MACvRegBitsOn(dwIoBase, MAC_REG_HOSTCR, HOSTCR_SOFTRST);
-    VNSvOutPortB(dwIoBase+ MAC_REG_HOSTCR, 0x01);
-
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
-        if ( !(byData & HOSTCR_SOFTRST))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT)
-        return false;
-    return true;
-
+       unsigned char byData;
+       unsigned short ww;
+
+       // turn on HOSTCR_SOFTRST, just write 0x01 to reset
+       //MACvRegBitsOn(dwIoBase, MAC_REG_HOSTCR, HOSTCR_SOFTRST);
+       VNSvOutPortB(dwIoBase + MAC_REG_HOSTCR, 0x01);
+
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
+               if (!(byData & HOSTCR_SOFTRST))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT)
+               return false;
+       return true;
 }
 
 /*
@@ -806,24 +796,24 @@ bool MACbSoftwareReset (unsigned long dwIoBase)
  * Return Value: true if success; otherwise false
  *
  */
-bool MACbSafeSoftwareReset (unsigned long dwIoBase)
+bool MACbSafeSoftwareReset(unsigned long dwIoBase)
 {
-    unsigned char abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0+MAC_MAX_CONTEXT_SIZE_PAGE1];
-    bool bRetVal;
-
-    // PATCH....
-    // save some important register's value, then do
-    // reset, then restore register's value
-
-    // save MAC context
-    MACvSaveContext(dwIoBase, abyTmpRegData);
-    // do reset
-    bRetVal = MACbSoftwareReset(dwIoBase);
-    //BBvSoftwareReset(pDevice->PortOffset);
-    // restore MAC context, except CR0
-    MACvRestoreContext(dwIoBase, abyTmpRegData);
-
-    return bRetVal;
+       unsigned char abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0+MAC_MAX_CONTEXT_SIZE_PAGE1];
+       bool bRetVal;
+
+       // PATCH....
+       // save some important register's value, then do
+       // reset, then restore register's value
+
+       // save MAC context
+       MACvSaveContext(dwIoBase, abyTmpRegData);
+       // do reset
+       bRetVal = MACbSoftwareReset(dwIoBase);
+       //BBvSoftwareReset(pDevice->PortOffset);
+       // restore MAC context, except CR0
+       MACvRestoreContext(dwIoBase, abyTmpRegData);
+
+       return bRetVal;
 }
 
 /*
@@ -839,52 +829,52 @@ bool MACbSafeSoftwareReset (unsigned long dwIoBase)
  * Return Value: true if success; otherwise false
  *
  */
-bool MACbSafeRxOff (unsigned long dwIoBase)
+bool MACbSafeRxOff(unsigned long dwIoBase)
 {
-    unsigned short ww;
-    unsigned long dwData;
-    unsigned char byData;
-
-    // turn off wow temp for turn off Rx safely
-
-    // Clear RX DMA0,1
-    VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_CLRRUN);
-    VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_CLRRUN);
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL0, &dwData);
-        if (!(dwData & DMACTL_RUN))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x10);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x10)\n");
-        return(false);
-    }
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL1, &dwData);
-        if ( !(dwData & DMACTL_RUN))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x11);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x11)\n");
-        return(false);
-    }
-
-    // try to safe shutdown RX
-    MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_RXON);
-    // W_MAX_TIMEOUT is the timeout period
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
-        if ( !(byData & HOSTCR_RXONST))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x12);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x12)\n");
-        return(false);
-    }
-    return true;
+       unsigned short ww;
+       unsigned long dwData;
+       unsigned char byData;
+
+       // turn off wow temp for turn off Rx safely
+
+       // Clear RX DMA0,1
+       VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_CLRRUN);
+       VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_CLRRUN);
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL0, &dwData);
+               if (!(dwData & DMACTL_RUN))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x10);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x10)\n");
+               return false;
+       }
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL1, &dwData);
+               if (!(dwData & DMACTL_RUN))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x11);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x11)\n");
+               return false;
+       }
+
+       // try to safe shutdown RX
+       MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_RXON);
+       // W_MAX_TIMEOUT is the timeout period
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
+               if (!(byData & HOSTCR_RXONST))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x12);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x12)\n");
+               return false;
+       }
+       return true;
 }
 
 /*
@@ -900,55 +890,54 @@ bool MACbSafeRxOff (unsigned long dwIoBase)
  * Return Value: true if success; otherwise false
  *
  */
-bool MACbSafeTxOff (unsigned long dwIoBase)
+bool MACbSafeTxOff(unsigned long dwIoBase)
 {
-    unsigned short ww;
-    unsigned long dwData;
-    unsigned char byData;
-
-    // Clear TX DMA
-    //Tx0
-    VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_CLRRUN);
-    //AC0
-    VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_CLRRUN);
-
-
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortD(dwIoBase + MAC_REG_TXDMACTL0, &dwData);
-        if ( !(dwData & DMACTL_RUN))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x20);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x20)\n");
-        return(false);
-    }
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortD(dwIoBase + MAC_REG_AC0DMACTL, &dwData);
-        if ( !(dwData & DMACTL_RUN))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x21);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x21)\n");
-        return(false);
-    }
-
-    // try to safe shutdown TX
-    MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_TXON);
-
-    // W_MAX_TIMEOUT is the timeout period
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
-        if ( !(byData & HOSTCR_TXONST))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x24);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x24)\n");
-        return(false);
-    }
-    return true;
+       unsigned short ww;
+       unsigned long dwData;
+       unsigned char byData;
+
+       // Clear TX DMA
+       //Tx0
+       VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_CLRRUN);
+       //AC0
+       VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_CLRRUN);
+
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortD(dwIoBase + MAC_REG_TXDMACTL0, &dwData);
+               if (!(dwData & DMACTL_RUN))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x20);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x20)\n");
+               return false;
+       }
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortD(dwIoBase + MAC_REG_AC0DMACTL, &dwData);
+               if (!(dwData & DMACTL_RUN))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x21);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x21)\n");
+               return false;
+       }
+
+       // try to safe shutdown TX
+       MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_TXON);
+
+       // W_MAX_TIMEOUT is the timeout period
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
+               if (!(byData & HOSTCR_TXONST))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x24);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x24)\n");
+               return false;
+       }
+       return true;
 }
 
 /*
@@ -964,26 +953,26 @@ bool MACbSafeTxOff (unsigned long dwIoBase)
  * Return Value: true if success; otherwise false
  *
  */
-bool MACbSafeStop (unsigned long dwIoBase)
+bool MACbSafeStop(unsigned long dwIoBase)
 {
-    MACvRegBitsOff(dwIoBase, MAC_REG_TCR, TCR_AUTOBCNTX);
-
-    if (MACbSafeRxOff(dwIoBase) == false) {
-        DBG_PORT80(0xA1);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" MACbSafeRxOff == false)\n");
-        MACbSafeSoftwareReset(dwIoBase);
-        return false;
-    }
-    if (MACbSafeTxOff(dwIoBase) == false) {
-        DBG_PORT80(0xA2);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" MACbSafeTxOff == false)\n");
-        MACbSafeSoftwareReset(dwIoBase);
-        return false;
-    }
-
-    MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_MACEN);
-
-    return true;
+       MACvRegBitsOff(dwIoBase, MAC_REG_TCR, TCR_AUTOBCNTX);
+
+       if (MACbSafeRxOff(dwIoBase) == false) {
+               DBG_PORT80(0xA1);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " MACbSafeRxOff == false)\n");
+               MACbSafeSoftwareReset(dwIoBase);
+               return false;
+       }
+       if (MACbSafeTxOff(dwIoBase) == false) {
+               DBG_PORT80(0xA2);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " MACbSafeTxOff == false)\n");
+               MACbSafeSoftwareReset(dwIoBase);
+               return false;
+       }
+
+       MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_MACEN);
+
+       return true;
 }
 
 /*
@@ -999,18 +988,18 @@ bool MACbSafeStop (unsigned long dwIoBase)
  * Return Value: true if success; otherwise false
  *
  */
-bool MACbShutdown (unsigned long dwIoBase)
+bool MACbShutdown(unsigned long dwIoBase)
 {
-    // disable MAC IMR
-    MACvIntDisable(dwIoBase);
-    MACvSetLoopbackMode(dwIoBase, MAC_LB_INTERNAL);
-    // stop the adapter
-    if (!MACbSafeStop(dwIoBase)) {
-        MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
-        return false;
-    }
-    MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
-    return true;
+       // disable MAC IMR
+       MACvIntDisable(dwIoBase);
+       MACvSetLoopbackMode(dwIoBase, MAC_LB_INTERNAL);
+       // stop the adapter
+       if (!MACbSafeStop(dwIoBase)) {
+               MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
+               return false;
+       }
+       MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
+       return true;
 }
 
 /*
@@ -1026,43 +1015,31 @@ bool MACbShutdown (unsigned long dwIoBase)
  * Return Value: none
  *
  */
-void MACvInitialize (unsigned long dwIoBase)
+void MACvInitialize(unsigned long dwIoBase)
 {
-    // clear sticky bits
-    MACvClearStckDS(dwIoBase);
-    // disable force PME-enable
-    VNSvOutPortB(dwIoBase + MAC_REG_PMC1, PME_OVR);
-    // only 3253 A
-    /*
-    MACvPwrEvntDisable(dwIoBase);
-    // clear power status
-    VNSvOutPortW(dwIoBase + MAC_REG_WAKEUPSR0, 0x0F0F);
-    */
-
-    // do reset
-    MACbSoftwareReset(dwIoBase);
-
-    // issue AUTOLD in EECSR to reload eeprom
-    //MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD);
-    // wait until EEPROM loading complete
-    //while (true) {
-    //    u8 u8Data;
-    //    VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &u8Data);
-    //    if ( !(u8Data & I2MCSR_AUTOLD))
-    //        break;
-    //}
-
-    // reset TSF counter
-    VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
-    // enable TSF counter
-    VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
-
-
-    // set packet filter
-    // receive directed and broadcast address
-
-    MACvSetPacketFilter(dwIoBase, PKT_TYPE_DIRECTED | PKT_TYPE_BROADCAST);
-
+       // clear sticky bits
+       MACvClearStckDS(dwIoBase);
+       // disable force PME-enable
+       VNSvOutPortB(dwIoBase + MAC_REG_PMC1, PME_OVR);
+       // only 3253 A
+       /*
+         MACvPwrEvntDisable(dwIoBase);
+         // clear power status
+         VNSvOutPortW(dwIoBase + MAC_REG_WAKEUPSR0, 0x0F0F);
+       */
+
+       // do reset
+       MACbSoftwareReset(dwIoBase);
+
+       // reset TSF counter
+       VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
+       // enable TSF counter
+       VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
+
+       // set packet filter
+       // receive directed and broadcast address
+
+       MACvSetPacketFilter(dwIoBase, PKT_TYPE_DIRECTED | PKT_TYPE_BROADCAST);
 }
 
 /*
@@ -1079,28 +1056,28 @@ void MACvInitialize (unsigned long dwIoBase)
  * Return Value: none
  *
  */
-void MACvSetCurrRx0DescAddr (unsigned long dwIoBase, unsigned long dwCurrDescAddr)
+void MACvSetCurrRx0DescAddr(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
 {
-unsigned short ww;
-unsigned char byData;
-unsigned char byOrgDMACtl;
-
-    VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byOrgDMACtl);
-    if (byOrgDMACtl & DMACTL_RUN) {
-        VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0+2, DMACTL_RUN);
-    }
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byData);
-        if ( !(byData & DMACTL_RUN))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x13);
-    }
-    VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, dwCurrDescAddr);
-    if (byOrgDMACtl & DMACTL_RUN) {
-        VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN);
-    }
+       unsigned short ww;
+       unsigned char byData;
+       unsigned char byOrgDMACtl;
+
+       VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byOrgDMACtl);
+       if (byOrgDMACtl & DMACTL_RUN) {
+               VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0+2, DMACTL_RUN);
+       }
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byData);
+               if (!(byData & DMACTL_RUN))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x13);
+       }
+       VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, dwCurrDescAddr);
+       if (byOrgDMACtl & DMACTL_RUN) {
+               VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN);
+       }
 }
 
 /*
@@ -1117,28 +1094,28 @@ unsigned char byOrgDMACtl;
  * Return Value: none
  *
  */
-void MACvSetCurrRx1DescAddr (unsigned long dwIoBase, unsigned long dwCurrDescAddr)
+void MACvSetCurrRx1DescAddr(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
 {
-unsigned short ww;
-unsigned char byData;
-unsigned char byOrgDMACtl;
-
-    VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byOrgDMACtl);
-    if (byOrgDMACtl & DMACTL_RUN) {
-        VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1+2, DMACTL_RUN);
-    }
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byData);
-        if ( !(byData & DMACTL_RUN))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x14);
-    }
-    VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, dwCurrDescAddr);
-    if (byOrgDMACtl & DMACTL_RUN) {
-        VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_RUN);
-    }
+       unsigned short ww;
+       unsigned char byData;
+       unsigned char byOrgDMACtl;
+
+       VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byOrgDMACtl);
+       if (byOrgDMACtl & DMACTL_RUN) {
+               VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1+2, DMACTL_RUN);
+       }
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byData);
+               if (!(byData & DMACTL_RUN))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x14);
+       }
+       VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, dwCurrDescAddr);
+       if (byOrgDMACtl & DMACTL_RUN) {
+               VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_RUN);
+       }
 }
 
 /*
@@ -1155,28 +1132,28 @@ unsigned char byOrgDMACtl;
  * Return Value: none
  *
  */
-void MACvSetCurrTx0DescAddrEx (unsigned long dwIoBase, unsigned long dwCurrDescAddr)
+void MACvSetCurrTx0DescAddrEx(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
 {
-unsigned short ww;
-unsigned char byData;
-unsigned char byOrgDMACtl;
-
-    VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byOrgDMACtl);
-    if (byOrgDMACtl & DMACTL_RUN) {
-        VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
-    }
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
-        if ( !(byData & DMACTL_RUN))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x25);
-    }
-    VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, dwCurrDescAddr);
-    if (byOrgDMACtl & DMACTL_RUN) {
-        VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_RUN);
-    }
+       unsigned short ww;
+       unsigned char byData;
+       unsigned char byOrgDMACtl;
+
+       VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byOrgDMACtl);
+       if (byOrgDMACtl & DMACTL_RUN) {
+               VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
+       }
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
+               if (!(byData & DMACTL_RUN))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x25);
+       }
+       VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, dwCurrDescAddr);
+       if (byOrgDMACtl & DMACTL_RUN) {
+               VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_RUN);
+       }
 }
 
 /*
@@ -1193,41 +1170,39 @@ unsigned char byOrgDMACtl;
  * Return Value: none
  *
  */
- //TxDMA1 = AC0DMA
-void MACvSetCurrAC0DescAddrEx (unsigned long dwIoBase, unsigned long dwCurrDescAddr)
+//TxDMA1 = AC0DMA
+void MACvSetCurrAC0DescAddrEx(unsigned long dwIoBase, unsigned long dwCurrDescAddr)
 {
-unsigned short ww;
-unsigned char byData;
-unsigned char byOrgDMACtl;
-
-    VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byOrgDMACtl);
-    if (byOrgDMACtl & DMACTL_RUN) {
-        VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
-    }
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
-        if (!(byData & DMACTL_RUN))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x26);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x26)\n");
-    }
-    VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, dwCurrDescAddr);
-    if (byOrgDMACtl & DMACTL_RUN) {
-        VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_RUN);
-    }
+       unsigned short ww;
+       unsigned char byData;
+       unsigned char byOrgDMACtl;
+
+       VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byOrgDMACtl);
+       if (byOrgDMACtl & DMACTL_RUN) {
+               VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
+       }
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
+               if (!(byData & DMACTL_RUN))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x26);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x26)\n");
+       }
+       VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, dwCurrDescAddr);
+       if (byOrgDMACtl & DMACTL_RUN) {
+               VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_RUN);
+       }
 }
 
-
-
-void MACvSetCurrTXDescAddr (int iTxType, unsigned long dwIoBase, unsigned long dwCurrDescAddr)
+void MACvSetCurrTXDescAddr(int iTxType, unsigned long dwIoBase, unsigned long dwCurrDescAddr)
 {
-    if(iTxType == TYPE_AC0DMA){
-        MACvSetCurrAC0DescAddrEx(dwIoBase, dwCurrDescAddr);
-    }else if(iTxType == TYPE_TXDMA0){
-        MACvSetCurrTx0DescAddrEx(dwIoBase, dwCurrDescAddr);
-    }
+       if (iTxType == TYPE_AC0DMA) {
+               MACvSetCurrAC0DescAddrEx(dwIoBase, dwCurrDescAddr);
+       } else if (iTxType == TYPE_TXDMA0) {
+               MACvSetCurrTx0DescAddrEx(dwIoBase, dwCurrDescAddr);
+       }
 }
 
 /*
@@ -1244,26 +1219,25 @@ void MACvSetCurrTXDescAddr (int iTxType, unsigned long dwIoBase, unsigned long d
  * Return Value: none
  *
  */
-void MACvTimer0MicroSDelay (unsigned long dwIoBase, unsigned int uDelay)
+void MACvTimer0MicroSDelay(unsigned long dwIoBase, unsigned int uDelay)
 {
-unsigned char byValue;
-unsigned int uu,ii;
-
-    VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
-    VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelay);
-    VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
-    for(ii=0;ii<66;ii++) {  // assume max PCI clock is 66Mhz
-        for (uu = 0; uu < uDelay; uu++) {
-            VNSvInPortB(dwIoBase + MAC_REG_TMCTL0, &byValue);
-            if ((byValue == 0) ||
-                (byValue & TMCTL_TSUSP)) {
-                VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
-                return;
-            }
-        }
-    }
-    VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
-
+       unsigned char byValue;
+       unsigned int uu, ii;
+
+       VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
+       VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelay);
+       VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
+       for (ii = 0; ii < 66; ii++) {  // assume max PCI clock is 66Mhz
+               for (uu = 0; uu < uDelay; uu++) {
+                       VNSvInPortB(dwIoBase + MAC_REG_TMCTL0, &byValue);
+                       if ((byValue == 0) ||
+                           (byValue & TMCTL_TSUSP)) {
+                               VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
+                               return;
+                       }
+               }
+       }
+       VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
 }
 
 /*
@@ -1280,11 +1254,11 @@ unsigned int uu,ii;
  * Return Value: none
  *
  */
-void MACvOneShotTimer0MicroSec (unsigned long dwIoBase, unsigned int uDelayTime)
+void MACvOneShotTimer0MicroSec(unsigned long dwIoBase, unsigned int uDelayTime)
 {
-    VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
-    VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelayTime);
-    VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
+       VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
+       VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelayTime);
+       VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
 }
 
 /*
@@ -1301,143 +1275,141 @@ void MACvOneShotTimer0MicroSec (unsigned long dwIoBase, unsigned int uDelayTime)
  * Return Value: none
  *
  */
-void MACvOneShotTimer1MicroSec (unsigned long dwIoBase, unsigned int uDelayTime)
+void MACvOneShotTimer1MicroSec(unsigned long dwIoBase, unsigned int uDelayTime)
 {
-    VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, 0);
-    VNSvOutPortD(dwIoBase + MAC_REG_TMDATA1, uDelayTime);
-    VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, (TMCTL_TMD | TMCTL_TE));
+       VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, 0);
+       VNSvOutPortD(dwIoBase + MAC_REG_TMDATA1, uDelayTime);
+       VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, (TMCTL_TMD | TMCTL_TE));
 }
 
-
-void MACvSetMISCFifo (unsigned long dwIoBase, unsigned short wOffset, unsigned long dwData)
+void MACvSetMISCFifo(unsigned long dwIoBase, unsigned short wOffset, unsigned long dwData)
 {
-    if (wOffset > 273)
-        return;
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
-    VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       if (wOffset > 273)
+               return;
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
+       VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
 }
 
-
-bool MACbTxDMAOff (unsigned long dwIoBase, unsigned int idx)
+bool MACbTxDMAOff(unsigned long dwIoBase, unsigned int idx)
 {
-unsigned char byData;
-unsigned int ww = 0;
-
-    if (idx == TYPE_TXDMA0) {
-        VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
-        for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-            VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
-            if ( !(byData & DMACTL_RUN))
-                break;
-        }
-    } else if (idx == TYPE_AC0DMA) {
-        VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
-        for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-            VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
-            if ( !(byData & DMACTL_RUN))
-                break;
-        }
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x29);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x29)\n");
-        return false;
-    }
-    return true;
+       unsigned char byData;
+       unsigned int ww = 0;
+
+       if (idx == TYPE_TXDMA0) {
+               VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
+               for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+                       VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
+                       if (!(byData & DMACTL_RUN))
+                               break;
+               }
+       } else if (idx == TYPE_AC0DMA) {
+               VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
+               for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+                       VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
+                       if (!(byData & DMACTL_RUN))
+                               break;
+               }
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x29);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x29)\n");
+               return false;
+       }
+       return true;
 }
 
-void MACvClearBusSusInd (unsigned long dwIoBase)
+void MACvClearBusSusInd(unsigned long dwIoBase)
 {
-    unsigned long dwOrgValue;
-    unsigned int ww;
-    // check if BcnSusInd enabled
-    VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
-    if( !(dwOrgValue & EnCFG_BcnSusInd))
-        return;
-    //Set BcnSusClr
-    dwOrgValue = dwOrgValue | EnCFG_BcnSusClr;
-    VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
-        if( !(dwOrgValue & EnCFG_BcnSusInd))
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x33);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x33)\n");
-    }
+       unsigned long dwOrgValue;
+       unsigned int ww;
+       // check if BcnSusInd enabled
+       VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
+       if (!(dwOrgValue & EnCFG_BcnSusInd))
+               return;
+       //Set BcnSusClr
+       dwOrgValue = dwOrgValue | EnCFG_BcnSusClr;
+       VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
+               if (!(dwOrgValue & EnCFG_BcnSusInd))
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x33);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x33)\n");
+       }
 }
 
-void MACvEnableBusSusEn (unsigned long dwIoBase)
+void MACvEnableBusSusEn(unsigned long dwIoBase)
 {
-    unsigned char byOrgValue;
-    unsigned long dwOrgValue;
-    unsigned int ww;
-    // check if BcnSusInd enabled
-    VNSvInPortB(dwIoBase + MAC_REG_CFG , &byOrgValue);
-
-    //Set BcnSusEn
-    byOrgValue = byOrgValue | CFG_BCNSUSEN;
-    VNSvOutPortB(dwIoBase + MAC_REG_ENCFG, byOrgValue);
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
-        if(dwOrgValue & EnCFG_BcnSusInd)
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x34);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x34)\n");
-    }
+       unsigned char byOrgValue;
+       unsigned long dwOrgValue;
+       unsigned int ww;
+       // check if BcnSusInd enabled
+       VNSvInPortB(dwIoBase + MAC_REG_CFG , &byOrgValue);
+
+       //Set BcnSusEn
+       byOrgValue = byOrgValue | CFG_BCNSUSEN;
+       VNSvOutPortB(dwIoBase + MAC_REG_ENCFG, byOrgValue);
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
+               if (dwOrgValue & EnCFG_BcnSusInd)
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x34);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x34)\n");
+       }
 }
 
-bool MACbFlushSYNCFifo (unsigned long dwIoBase)
+bool MACbFlushSYNCFifo(unsigned long dwIoBase)
 {
-    unsigned char byOrgValue;
-    unsigned int ww;
-    // Read MACCR
-    VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
-
-    // Set SYNCFLUSH
-    byOrgValue = byOrgValue | MACCR_SYNCFLUSH;
-    VNSvOutPortB(dwIoBase + MAC_REG_MACCR, byOrgValue);
-
-    // Check if SyncFlushOK
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
-        if(byOrgValue & MACCR_SYNCFLUSHOK)
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x35);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x33)\n");
-    }
-    return true;
+       unsigned char byOrgValue;
+       unsigned int ww;
+       // Read MACCR
+       VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
+
+       // Set SYNCFLUSH
+       byOrgValue = byOrgValue | MACCR_SYNCFLUSH;
+       VNSvOutPortB(dwIoBase + MAC_REG_MACCR, byOrgValue);
+
+       // Check if SyncFlushOK
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
+               if (byOrgValue & MACCR_SYNCFLUSHOK)
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x35);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x33)\n");
+       }
+       return true;
 }
 
-bool MACbPSWakeup (unsigned long dwIoBase)
+bool MACbPSWakeup(unsigned long dwIoBase)
 {
-    unsigned char byOrgValue;
-    unsigned int ww;
-    // Read PSCTL
-    if (MACbIsRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PS)) {
-        return true;
-    }
-    // Disable PS
-    MACvRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PSEN);
-
-    // Check if SyncFlushOK
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortB(dwIoBase + MAC_REG_PSCTL , &byOrgValue);
-        if(byOrgValue & PSCTL_WAKEDONE)
-            break;
-    }
-    if (ww == W_MAX_TIMEOUT) {
-        DBG_PORT80(0x36);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x33)\n");
-        return false;
-    }
-    return true;
+       unsigned char byOrgValue;
+       unsigned int ww;
+       // Read PSCTL
+       if (MACbIsRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PS)) {
+               return true;
+       }
+       // Disable PS
+       MACvRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PSEN);
+
+       // Check if SyncFlushOK
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortB(dwIoBase + MAC_REG_PSCTL , &byOrgValue);
+               if (byOrgValue & PSCTL_WAKEDONE)
+                       break;
+       }
+       if (ww == W_MAX_TIMEOUT) {
+               DBG_PORT80(0x36);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " DBG_PORT80(0x33)\n");
+               return false;
+       }
+       return true;
 }
 
 /*
@@ -1455,59 +1427,56 @@ bool MACbPSWakeup (unsigned long dwIoBase)
  *
  */
 
-void MACvSetKeyEntry (unsigned long dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx,
-               unsigned int uKeyIdx, unsigned char *pbyAddr, unsigned long *pdwKey, unsigned char byLocalID)
+void MACvSetKeyEntry(unsigned long dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx,
+                    unsigned int uKeyIdx, unsigned char *pbyAddr, unsigned long *pdwKey, unsigned char byLocalID)
 {
-unsigned short wOffset;
-unsigned long dwData;
-int     ii;
-
-    if (byLocalID <= 1)
-        return;
-
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetKeyEntry\n");
-    wOffset = MISCFIFO_KEYETRY0;
-    wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
-
-    dwData = 0;
-    dwData |= wKeyCtl;
-    dwData <<= 16;
-    dwData |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5));
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
-
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
-    VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
-    wOffset++;
-
-    dwData = 0;
-    dwData |= *(pbyAddr+3);
-    dwData <<= 8;
-    dwData |= *(pbyAddr+2);
-    dwData <<= 8;
-    dwData |= *(pbyAddr+1);
-    dwData <<= 8;
-    dwData |= *(pbyAddr+0);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2. wOffset: %d, Data: %lX\n", wOffset, dwData);
-
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
-    VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
-    wOffset++;
-
-    wOffset += (uKeyIdx * 4);
-    for (ii=0;ii<4;ii++) {
-        // always push 128 bits
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"3.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
-        VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
-        VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
-        VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
-    }
+       unsigned short wOffset;
+       unsigned long dwData;
+       int     ii;
+
+       if (byLocalID <= 1)
+               return;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetKeyEntry\n");
+       wOffset = MISCFIFO_KEYETRY0;
+       wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
+
+       dwData = 0;
+       dwData |= wKeyCtl;
+       dwData <<= 16;
+       dwData |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5));
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
+
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
+       VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       wOffset++;
+
+       dwData = 0;
+       dwData |= *(pbyAddr+3);
+       dwData <<= 8;
+       dwData |= *(pbyAddr+2);
+       dwData <<= 8;
+       dwData |= *(pbyAddr+1);
+       dwData <<= 8;
+       dwData |= *(pbyAddr+0);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "2. wOffset: %d, Data: %lX\n", wOffset, dwData);
+
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
+       VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       wOffset++;
+
+       wOffset += (uKeyIdx * 4);
+       for (ii = 0; ii < 4; ii++) {
+               // always push 128 bits
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "3.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
+               VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
+               VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
+               VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       }
 }
 
-
-
 /*
  * Description:
  *      Disable the Key Entry by MISCFIFO
@@ -1522,19 +1491,18 @@ int     ii;
  * Return Value: none
  *
  */
-void MACvDisableKeyEntry (unsigned long dwIoBase, unsigned int uEntryIdx)
+void MACvDisableKeyEntry(unsigned long dwIoBase, unsigned int uEntryIdx)
 {
-unsigned short wOffset;
+       unsigned short wOffset;
 
-    wOffset = MISCFIFO_KEYETRY0;
-    wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
+       wOffset = MISCFIFO_KEYETRY0;
+       wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
 
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
-    VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0);
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
+       VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0);
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
 }
 
-
 /*
  * Description:
  *      Set the default Key (KeyEntry[10]) by MISCFIFO
@@ -1550,42 +1518,40 @@ unsigned short wOffset;
  *
  */
 
-void MACvSetDefaultKeyEntry (unsigned long dwIoBase, unsigned int uKeyLen,
-               unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID)
+void MACvSetDefaultKeyEntry(unsigned long dwIoBase, unsigned int uKeyLen,
+                           unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID)
 {
-unsigned short wOffset;
-unsigned long dwData;
-int     ii;
-
-    if (byLocalID <= 1)
-        return;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetDefaultKeyEntry\n");
-    wOffset = MISCFIFO_KEYETRY0;
-    wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
-
-    wOffset++;
-    wOffset++;
-    wOffset += (uKeyIdx * 4);
-    // always push 128 bits
-    for (ii=0; ii<3; ii++) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
-        VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
-        VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
-        VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
-    }
-    dwData = *pdwKey;
-    if (uKeyLen == WLAN_WEP104_KEYLEN) {
-        dwData |= 0x80000000;
-    }
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+3);
-    VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"End. wOffset: %d, Data: %lX\n", wOffset+3, dwData);
-
+       unsigned short wOffset;
+       unsigned long dwData;
+       int     ii;
+
+       if (byLocalID <= 1)
+               return;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetDefaultKeyEntry\n");
+       wOffset = MISCFIFO_KEYETRY0;
+       wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
+
+       wOffset++;
+       wOffset++;
+       wOffset += (uKeyIdx * 4);
+       // always push 128 bits
+       for (ii = 0; ii < 3; ii++) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
+               VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
+               VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
+               VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       }
+       dwData = *pdwKey;
+       if (uKeyLen == WLAN_WEP104_KEYLEN) {
+               dwData |= 0x80000000;
+       }
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+3);
+       VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "End. wOffset: %d, Data: %lX\n", wOffset+3, dwData);
 }
 
-
 /*
  * Description:
  *      Enable default Key (KeyEntry[10]) by MISCFIFO
@@ -1601,25 +1567,24 @@ int     ii;
  *
  */
 /*
-void MACvEnableDefaultKey (unsigned long dwIoBase, unsigned char byLocalID)
-{
-unsigned short wOffset;
-unsigned long dwData;
+  void MACvEnableDefaultKey(unsigned long dwIoBase, unsigned char byLocalID)
+  {
+  unsigned short wOffset;
+  unsigned long dwData;
 
+  if (byLocalID <= 1)
+  return;
 
-    if (byLocalID <= 1)
-        return;
+  wOffset = MISCFIFO_KEYETRY0;
+  wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
 
-    wOffset = MISCFIFO_KEYETRY0;
-    wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
+  dwData = 0xC0440000;
+  VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
+  VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
+  VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvEnableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
 
-    dwData = 0xC0440000;
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
-    VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvEnableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
-
-}
+  }
 */
 
 /*
@@ -1636,20 +1601,19 @@ unsigned long dwData;
  * Return Value: none
  *
  */
-void MACvDisableDefaultKey (unsigned long dwIoBase)
+void MACvDisableDefaultKey(unsigned long dwIoBase)
 {
-unsigned short wOffset;
-unsigned long dwData;
-
+       unsigned short wOffset;
+       unsigned long dwData;
 
-    wOffset = MISCFIFO_KEYETRY0;
-    wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
+       wOffset = MISCFIFO_KEYETRY0;
+       wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
 
-    dwData = 0x0;
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
-    VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvDisableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
+       dwData = 0x0;
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
+       VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvDisableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
 }
 
 /*
@@ -1666,48 +1630,44 @@ unsigned long dwData;
  * Return Value: none
  *
  */
-void MACvSetDefaultTKIPKeyEntry (unsigned long dwIoBase, unsigned int uKeyLen,
-               unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID)
+void MACvSetDefaultTKIPKeyEntry(unsigned long dwIoBase, unsigned int uKeyLen,
+                               unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID)
 {
-unsigned short wOffset;
-unsigned long dwData;
-int     ii;
-
-    if (byLocalID <= 1)
-        return;
-
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetDefaultTKIPKeyEntry\n");
-    wOffset = MISCFIFO_KEYETRY0;
-    // Kyle test : change offset from 10 -> 0
-    wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
-
-    dwData = 0xC0660000;
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
-    VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
-    wOffset++;
-
-    dwData = 0;
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
-    VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
-    wOffset++;
-
-    wOffset += (uKeyIdx * 4);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %lX, idx:%d\n", wOffset, *pdwKey, uKeyIdx);
-    // always push 128 bits
-    for (ii=0; ii<4; ii++) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
-        VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
-        VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
-        VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
-    }
-
+       unsigned short wOffset;
+       unsigned long dwData;
+       int     ii;
+
+       if (byLocalID <= 1)
+               return;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetDefaultTKIPKeyEntry\n");
+       wOffset = MISCFIFO_KEYETRY0;
+       // Kyle test : change offset from 10 -> 0
+       wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
+
+       dwData = 0xC0660000;
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
+       VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       wOffset++;
+
+       dwData = 0;
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
+       VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       wOffset++;
+
+       wOffset += (uKeyIdx * 4);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "1. wOffset: %d, Data: %lX, idx:%d\n", wOffset, *pdwKey, uKeyIdx);
+       // always push 128 bits
+       for (ii = 0; ii < 4; ii++) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "2.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
+               VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
+               VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
+               VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       }
 }
 
-
-
 /*
  * Description:
  *      Set the Key Control by MISCFIFO
@@ -1723,28 +1683,25 @@ int     ii;
  *
  */
 
-void MACvSetDefaultKeyCtl (unsigned long dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx, unsigned char byLocalID)
+void MACvSetDefaultKeyCtl(unsigned long dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx, unsigned char byLocalID)
 {
-unsigned short wOffset;
-unsigned long dwData;
-
-    if (byLocalID <= 1)
-        return;
+       unsigned short wOffset;
+       unsigned long dwData;
 
+       if (byLocalID <= 1)
+               return;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetKeyEntry\n");
-    wOffset = MISCFIFO_KEYETRY0;
-    wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MACvSetKeyEntry\n");
+       wOffset = MISCFIFO_KEYETRY0;
+       wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
 
-    dwData = 0;
-    dwData |= wKeyCtl;
-    dwData <<= 16;
-    dwData |= 0xffff;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
-
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
-    VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
+       dwData = 0;
+       dwData |= wKeyCtl;
+       dwData <<= 16;
+       dwData |= 0xffff;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
 
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
+       VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
 }
-
index adfb366f4901668793bb78bd4b3ff92be69355f2..3f177f7c581c1c8a88ac182f7a3db49f0ff27a91 100644 (file)
 #define MAC_REG_PWRCCK      0x73
 #define MAC_REG_PWROFDM     0x7C
 
-
 //
 // Bits in the BCFG0 register
 //
 #define IMR_AC0DMA          0x00000002      //
 #define IMR_TXDMA0          0x00000001      //
 
-
 //
 // Bits in the ISR register
 //
 #define ISR_AC0DMA          0x00000002      //
 #define ISR_TXDMA0          0x00000001      //
 
-
 //
 // Bits in the PSCFG register
 //
 //
 #define MISCFFCTL_WRITE     0x0001      //
 
-
 //
 // Bits in WAKEUPEN0
 //
 #define GPIO1_MD            0x10        //
 #define GPIO1_DATA          0x20        //
 
-
 //
 // Bits in the MSRCTL register
 //
 #define MSRCTL1_CSAPAREN    0x04
 #define MSRCTL1_TXPAUSE     0x01
 
-
 // Loopback mode
 #define MAC_LB_EXT          0x02        //
 #define MAC_LB_INTERNAL     0x01        //
 
 #define Default_BI              0x200
 
-
 // MiscFIFO Offset
 #define MISCFIFO_KEYETRY0       32
 #define MISCFIFO_KEYENTRYSIZE   22
 #define MISCFIFO_SYNDATASIZE    21
 
 // enabled mask value of irq
-#define IMR_MASK_VALUE     (IMR_SOFTTIMER1 | \
-                            IMR_RXDMA1 | \
-                            IMR_RXNOBUF | \
-                            IMR_MIBNEARFULL | \
-                            IMR_SOFTINT | \
-                            IMR_FETALERR | \
-                            IMR_WATCHDOG | \
-                            IMR_SOFTTIMER | \
-                            IMR_GPIO | \
-                            IMR_TBTT | \
-                            IMR_RXDMA0 | \
-                            IMR_BNTX | \
-                            IMR_AC0DMA | \
-                            IMR_TXDMA0)
+#define IMR_MASK_VALUE     (IMR_SOFTTIMER1 |   \
+                           IMR_RXDMA1 |        \
+                           IMR_RXNOBUF |       \
+                           IMR_MIBNEARFULL |   \
+                           IMR_SOFTINT |       \
+                           IMR_FETALERR |      \
+                           IMR_WATCHDOG |      \
+                           IMR_SOFTTIMER |     \
+                           IMR_GPIO |          \
+                           IMR_TBTT |          \
+                           IMR_RXDMA0 |        \
+                           IMR_BNTX |          \
+                           IMR_AC0DMA |        \
+                           IMR_TXDMA0)
 
 // max time out delay time
 #define W_MAX_TIMEOUT       0xFFF0U     //
 
 /*---------------------  Export Macros ------------------------------*/
 
-#define MACvRegBitsOn(dwIoBase, byRegOfs, byBits)           \
-{                                                           \
-    unsigned char byData;                                   \
-    VNSvInPortB(dwIoBase + byRegOfs, &byData);              \
-    VNSvOutPortB(dwIoBase + byRegOfs, byData | (byBits));   \
-}
-
-#define MACvWordRegBitsOn(dwIoBase, byRegOfs, wBits)        \
-{                                                           \
-    unsigned short wData;                                   \
-    VNSvInPortW(dwIoBase + byRegOfs, &wData);               \
-    VNSvOutPortW(dwIoBase + byRegOfs, wData | (wBits));     \
-}
-
-#define MACvDWordRegBitsOn(dwIoBase, byRegOfs, dwBits)      \
-{                                                           \
-    unsigned long dwData;                                   \
-    VNSvInPortD(dwIoBase + byRegOfs, &dwData);              \
-    VNSvOutPortD(dwIoBase + byRegOfs, dwData | (dwBits));   \
-}
-
-#define MACvRegBitsOnEx(dwIoBase, byRegOfs, byMask, byBits) \
-{                                                           \
-    unsigned char byData;                                   \
-    VNSvInPortB(dwIoBase + byRegOfs, &byData);              \
-    byData &= byMask;                                       \
-    VNSvOutPortB(dwIoBase + byRegOfs, byData | (byBits));   \
-}
-
-#define MACvRegBitsOff(dwIoBase, byRegOfs, byBits)          \
-{                                                           \
-    unsigned char byData;                                   \
-    VNSvInPortB(dwIoBase + byRegOfs, &byData);              \
-    VNSvOutPortB(dwIoBase + byRegOfs, byData & ~(byBits));  \
-}
-
-#define MACvWordRegBitsOff(dwIoBase, byRegOfs, wBits)       \
-{                                                           \
-    unsigned short wData;                                   \
-    VNSvInPortW(dwIoBase + byRegOfs, &wData);               \
-    VNSvOutPortW(dwIoBase + byRegOfs, wData & ~(wBits));    \
-}
-
-#define MACvDWordRegBitsOff(dwIoBase, byRegOfs, dwBits)     \
-{                                                           \
-    unsigned long dwData;                                   \
-    VNSvInPortD(dwIoBase + byRegOfs, &dwData);              \
-    VNSvOutPortD(dwIoBase + byRegOfs, dwData & ~(dwBits));  \
-}
-
-#define MACvGetCurrRx0DescAddr(dwIoBase, pdwCurrDescAddr)    \
-{                                                           \
-    VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR0,               \
-                (unsigned long *)pdwCurrDescAddr);          \
-}
-
-#define MACvGetCurrRx1DescAddr(dwIoBase, pdwCurrDescAddr)   \
-{                                                           \
-    VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR1,               \
-                (unsigned long *)pdwCurrDescAddr);          \
-}
-
-#define MACvGetCurrTx0DescAddr(dwIoBase, pdwCurrDescAddr)   \
-{                                                           \
-    VNSvInPortD(dwIoBase + MAC_REG_TXDMAPTR0,               \
-                (unsigned long *)pdwCurrDescAddr);          \
-}
-
-#define MACvGetCurrAC0DescAddr(dwIoBase, pdwCurrDescAddr)   \
-{                                                           \
-    VNSvInPortD(dwIoBase + MAC_REG_AC0DMAPTR,               \
-                (unsigned long *)pdwCurrDescAddr);          \
-}
-
-#define MACvGetCurrSyncDescAddr(dwIoBase, pdwCurrDescAddr)  \
-{                                                           \
-    VNSvInPortD(dwIoBase + MAC_REG_SYNCDMAPTR,              \
-                (unsigned long *)pdwCurrDescAddr);          \
-}
-
-#define MACvGetCurrATIMDescAddr(dwIoBase, pdwCurrDescAddr)  \
-{                                                           \
-    VNSvInPortD(dwIoBase + MAC_REG_ATIMDMAPTR,              \
-                (unsigned long *)pdwCurrDescAddr);          \
-}                                                           \
+#define MACvRegBitsOn(dwIoBase, byRegOfs, byBits)                      \
+do {                                                                   \
+       unsigned char byData;                                           \
+       VNSvInPortB(dwIoBase + byRegOfs, &byData);                      \
+       VNSvOutPortB(dwIoBase + byRegOfs, byData | (byBits));           \
+} while (0)
+
+#define MACvWordRegBitsOn(dwIoBase, byRegOfs, wBits)                   \
+do {                                                                   \
+       unsigned short wData;                                           \
+       VNSvInPortW(dwIoBase + byRegOfs, &wData);                       \
+       VNSvOutPortW(dwIoBase + byRegOfs, wData | (wBits));             \
+} while (0)
+
+#define MACvDWordRegBitsOn(dwIoBase, byRegOfs, dwBits)                 \
+do {                                                                   \
+       unsigned long dwData;                                           \
+       VNSvInPortD(dwIoBase + byRegOfs, &dwData);                      \
+       VNSvOutPortD(dwIoBase + byRegOfs, dwData | (dwBits));           \
+} while (0)
+
+#define MACvRegBitsOnEx(dwIoBase, byRegOfs, byMask, byBits)            \
+do {                                                                   \
+       unsigned char byData;                                           \
+       VNSvInPortB(dwIoBase + byRegOfs, &byData);                      \
+       byData &= byMask;                                               \
+       VNSvOutPortB(dwIoBase + byRegOfs, byData | (byBits));           \
+} while (0)
+
+#define MACvRegBitsOff(dwIoBase, byRegOfs, byBits)                     \
+do {                                                                   \
+       unsigned char byData;                                           \
+       VNSvInPortB(dwIoBase + byRegOfs, &byData);                      \
+       VNSvOutPortB(dwIoBase + byRegOfs, byData & ~(byBits));          \
+} while (0)
+
+#define MACvWordRegBitsOff(dwIoBase, byRegOfs, wBits)                  \
+do {                                                                   \
+       unsigned short wData;                                           \
+       VNSvInPortW(dwIoBase + byRegOfs, &wData);                       \
+       VNSvOutPortW(dwIoBase + byRegOfs, wData & ~(wBits));            \
+} while (0)
+
+#define MACvDWordRegBitsOff(dwIoBase, byRegOfs, dwBits)                        \
+do {                                                                   \
+       unsigned long dwData;                                           \
+       VNSvInPortD(dwIoBase + byRegOfs, &dwData);                      \
+       VNSvOutPortD(dwIoBase + byRegOfs, dwData & ~(dwBits));          \
+} while (0)
+
+#define MACvGetCurrRx0DescAddr(dwIoBase, pdwCurrDescAddr)      \
+       VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR0,               \
+                   (unsigned long *)pdwCurrDescAddr)
+
+#define MACvGetCurrRx1DescAddr(dwIoBase, pdwCurrDescAddr)      \
+       VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR1,               \
+                   (unsigned long *)pdwCurrDescAddr)
+
+#define MACvGetCurrTx0DescAddr(dwIoBase, pdwCurrDescAddr)      \
+       VNSvInPortD(dwIoBase + MAC_REG_TXDMAPTR0,               \
+                   (unsigned long *)pdwCurrDescAddr)
+
+#define MACvGetCurrAC0DescAddr(dwIoBase, pdwCurrDescAddr)      \
+       VNSvInPortD(dwIoBase + MAC_REG_AC0DMAPTR,               \
+                   (unsigned long *)pdwCurrDescAddr)
+
+#define MACvGetCurrSyncDescAddr(dwIoBase, pdwCurrDescAddr)     \
+       VNSvInPortD(dwIoBase + MAC_REG_SYNCDMAPTR,              \
+                   (unsigned long *)pdwCurrDescAddr)
+
+#define MACvGetCurrATIMDescAddr(dwIoBase, pdwCurrDescAddr)     \
+       VNSvInPortD(dwIoBase + MAC_REG_ATIMDMAPTR,              \
+                   (unsigned long *)pdwCurrDescAddr)
 
 // set the chip with current BCN tx descriptor address
-#define MACvSetCurrBCNTxDescAddr(dwIoBase, dwCurrDescAddr)  \
-{                                                           \
-    VNSvOutPortD(dwIoBase + MAC_REG_BCNDMAPTR,              \
-                 dwCurrDescAddr);                           \
-}
+#define MACvSetCurrBCNTxDescAddr(dwIoBase, dwCurrDescAddr)     \
+       VNSvOutPortD(dwIoBase + MAC_REG_BCNDMAPTR,              \
+                    dwCurrDescAddr)
 
 // set the chip with current BCN length
-#define MACvSetCurrBCNLength(dwIoBase, wCurrBCNLength)     \
-{                                                          \
-    VNSvOutPortW(dwIoBase + MAC_REG_BCNDMACTL+2,           \
-                 wCurrBCNLength);                          \
-}
-
-#define MACvReadBSSIDAddress(dwIoBase, pbyEtherAddr)        \
-{                                                           \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1);           \
-    VNSvInPortB(dwIoBase + MAC_REG_BSSID0,                  \
-                (unsigned char *)pbyEtherAddr);             \
-    VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 1,              \
-                pbyEtherAddr + 1);                          \
-    VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 2,              \
-                pbyEtherAddr + 2);                          \
-    VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 3,              \
-                pbyEtherAddr + 3);                          \
-    VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 4,              \
-                pbyEtherAddr + 4);                          \
-    VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 5,              \
-                pbyEtherAddr + 5);                          \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0);           \
-}
-
-#define MACvWriteBSSIDAddress(dwIoBase, pbyEtherAddr)       \
-{                                                           \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1);           \
-    VNSvOutPortB(dwIoBase + MAC_REG_BSSID0,                 \
-                *(pbyEtherAddr));                           \
-    VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 1,             \
-                *(pbyEtherAddr + 1));                       \
-    VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 2,             \
-                *(pbyEtherAddr + 2));                       \
-    VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 3,             \
-                *(pbyEtherAddr + 3));                       \
-    VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 4,             \
-                *(pbyEtherAddr + 4));                       \
-    VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 5,             \
-                *(pbyEtherAddr + 5));                       \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0);           \
-}
-
-#define MACvReadEtherAddress(dwIoBase, pbyEtherAddr)        \
-{                                                           \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1);           \
-    VNSvInPortB(dwIoBase + MAC_REG_PAR0,                    \
-                (unsigned char *)pbyEtherAddr);             \
-    VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 1,                \
-                pbyEtherAddr + 1);                          \
-    VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 2,                \
-                pbyEtherAddr + 2);                          \
-    VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 3,                \
-                pbyEtherAddr + 3);                          \
-    VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 4,                \
-                pbyEtherAddr + 4);                          \
-    VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 5,                \
-                pbyEtherAddr + 5);                          \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0);           \
-}
-
-
-#define MACvWriteEtherAddress(dwIoBase, pbyEtherAddr)       \
-{                                                           \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1);           \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAR0,                   \
-                *pbyEtherAddr);                             \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 1,               \
-                *(pbyEtherAddr + 1));                       \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 2,               \
-                *(pbyEtherAddr + 2));                       \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 3,               \
-                *(pbyEtherAddr + 3));                       \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 4,               \
-                *(pbyEtherAddr + 4));                       \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 5,               \
-                *(pbyEtherAddr + 5));                       \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0);           \
-}
-
-
-#define MACvClearISR(dwIoBase)                              \
-{                                                           \
-    VNSvOutPortD(dwIoBase + MAC_REG_ISR, IMR_MASK_VALUE);   \
-}
-
-#define MACvStart(dwIoBase)                                      \
-{                                                                \
-    VNSvOutPortB(dwIoBase + MAC_REG_HOSTCR,                      \
-                    (HOSTCR_MACEN | HOSTCR_RXON | HOSTCR_TXON)); \
-}
-
-#define MACvRx0PerPktMode(dwIoBase)                         \
-{                                                           \
-    VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, RX_PERPKT);  \
-}
-
-#define MACvRx0BufferFillMode(dwIoBase)                         \
-{                                                               \
-    VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, RX_PERPKTCLR);   \
-}
-
-#define MACvRx1PerPktMode(dwIoBase)                         \
-{                                                           \
-    VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, RX_PERPKT);  \
-}
-
-#define MACvRx1BufferFillMode(dwIoBase)                         \
-{                                                               \
-    VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, RX_PERPKTCLR);   \
-}
-
-#define MACvRxOn(dwIoBase)                                      \
-{                                                               \
-    MACvRegBitsOn(dwIoBase, MAC_REG_HOSTCR, HOSTCR_RXON);       \
-}
-
-#define MACvReceive0(dwIoBase)                                  \
-{                                                               \
-    unsigned long dwData;                                       \
-    VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL0, &dwData);         \
-    if (dwData & DMACTL_RUN) {                                  \
-        VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_WAKE);\
-    }                                                           \
-    else {                                                      \
-        VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN); \
-    }                                                           \
-}
-
-#define MACvReceive1(dwIoBase)                                  \
-{                                                               \
-    unsigned long dwData;                                       \
-    VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL1, &dwData);         \
-    if (dwData & DMACTL_RUN) {                                  \
-        VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_WAKE);\
-    }                                                           \
-    else {                                                      \
-        VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_RUN); \
-    }                                                           \
-}
-
-#define MACvTxOn(dwIoBase)                                      \
-{                                                               \
-    MACvRegBitsOn(dwIoBase, MAC_REG_HOSTCR, HOSTCR_TXON);       \
-}
-
-#define MACvTransmit0(dwIoBase)                                 \
-{                                                               \
-    unsigned long dwData;                                       \
-    VNSvInPortD(dwIoBase + MAC_REG_TXDMACTL0, &dwData);         \
-    if (dwData & DMACTL_RUN) {                                  \
-        VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_WAKE);\
-    }                                                           \
-    else {                                                      \
-        VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_RUN); \
-    }                                                           \
-}
-
-#define MACvTransmitAC0(dwIoBase)                               \
-{                                                               \
-    unsigned long dwData;                                       \
-    VNSvInPortD(dwIoBase + MAC_REG_AC0DMACTL, &dwData);         \
-    if (dwData & DMACTL_RUN) {                                  \
-        VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_WAKE);\
-    }                                                           \
-    else {                                                      \
-        VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_RUN); \
-    }                                                           \
-}
-
-#define MACvTransmitSYNC(dwIoBase)                               \
-{                                                                \
-    unsigned long dwData;                                        \
-    VNSvInPortD(dwIoBase + MAC_REG_SYNCDMACTL, &dwData);         \
-    if (dwData & DMACTL_RUN) {                                   \
-        VNSvOutPortD(dwIoBase + MAC_REG_SYNCDMACTL, DMACTL_WAKE);\
-    }                                                            \
-    else {                                                       \
-        VNSvOutPortD(dwIoBase + MAC_REG_SYNCDMACTL, DMACTL_RUN); \
-    }                                                            \
-}
-
-#define MACvTransmitATIM(dwIoBase)                               \
-{                                                                \
-    unsigned long dwData;                                        \
-    VNSvInPortD(dwIoBase + MAC_REG_ATIMDMACTL, &dwData);         \
-    if (dwData & DMACTL_RUN) {                                   \
-        VNSvOutPortD(dwIoBase + MAC_REG_ATIMDMACTL, DMACTL_WAKE);\
-    }                                                            \
-    else {                                                       \
-        VNSvOutPortD(dwIoBase + MAC_REG_ATIMDMACTL, DMACTL_RUN); \
-    }                                                            \
-}
-
-#define MACvTransmitBCN(dwIoBase)                               \
-{                                                               \
-    VNSvOutPortB(dwIoBase + MAC_REG_BCNDMACTL, BEACON_READY);   \
-}
-
-#define MACvClearStckDS(dwIoBase)                           \
-{                                                           \
-    unsigned char byOrgValue;                               \
-    VNSvInPortB(dwIoBase + MAC_REG_STICKHW, &byOrgValue);   \
-    byOrgValue = byOrgValue & 0xFC;                         \
-    VNSvOutPortB(dwIoBase + MAC_REG_STICKHW, byOrgValue);   \
-}
-
-#define MACvReadISR(dwIoBase, pdwValue)             \
-{                                                   \
-    VNSvInPortD(dwIoBase + MAC_REG_ISR, pdwValue);  \
-}
-
-#define MACvWriteISR(dwIoBase, dwValue)             \
-{                                                   \
-    VNSvOutPortD(dwIoBase + MAC_REG_ISR, dwValue);  \
-}
-
-#define MACvIntEnable(dwIoBase, dwMask)             \
-{                                                   \
-    VNSvOutPortD(dwIoBase + MAC_REG_IMR, dwMask);   \
-}
-
-#define MACvIntDisable(dwIoBase)                    \
-{                                                   \
-    VNSvOutPortD(dwIoBase + MAC_REG_IMR, 0);        \
-}
-
-#define MACvSelectPage0(dwIoBase)                   \
-{                                                   \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0);   \
-}
-#define MACvSelectPage1(dwIoBase)                   \
-{                                                   \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1);   \
-}
-
-#define MACvReadMIBCounter(dwIoBase, pdwCounter)            \
-{                                                           \
-    VNSvInPortD(dwIoBase + MAC_REG_MIBCNTR , pdwCounter);   \
-}
-
-#define MACvPwrEvntDisable(dwIoBase)                    \
-{                                                       \
-    VNSvOutPortW(dwIoBase + MAC_REG_WAKEUPEN0, 0x0000); \
-}
-
-#define MACvEnableProtectMD(dwIoBase)                    \
-{                                                        \
-    unsigned long dwOrgValue;                            \
-    VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue); \
-    dwOrgValue = dwOrgValue | EnCFG_ProtectMd;           \
-    VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);  \
-}
-
-#define MACvDisableProtectMD(dwIoBase)                   \
-{                                                        \
-    unsigned long dwOrgValue;                            \
-    VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue); \
-    dwOrgValue = dwOrgValue & ~EnCFG_ProtectMd;          \
-    VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);  \
-}
-
-#define MACvEnableBarkerPreambleMd(dwIoBase)             \
-{                                                        \
-    unsigned long dwOrgValue;                            \
-    VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue); \
-    dwOrgValue = dwOrgValue | EnCFG_BarkerPream;         \
-    VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);  \
-}
-
-#define MACvDisableBarkerPreambleMd(dwIoBase)            \
-{                                                        \
-    unsigned long dwOrgValue;                            \
-    VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue); \
-    dwOrgValue = dwOrgValue & ~EnCFG_BarkerPream;        \
-    VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);  \
-}
-
-#define MACvSetBBType(dwIoBase, byTyp)                   \
-{                                                        \
-    unsigned long dwOrgValue;                            \
-    VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue); \
-    dwOrgValue = dwOrgValue & ~EnCFG_BBType_MASK;        \
-    dwOrgValue = dwOrgValue | (unsigned long) byTyp;     \
-    VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);  \
-}
-
-#define MACvReadATIMW(dwIoBase, pwCounter)                 \
-{                                                          \
-    VNSvInPortW(dwIoBase + MAC_REG_AIDATIM , pwCounter);   \
-}
-
-#define MACvWriteATIMW(dwIoBase, wCounter)                 \
-{                                                          \
-    VNSvOutPortW(dwIoBase + MAC_REG_AIDATIM , wCounter);   \
-}
-
-#define MACvWriteCRC16_128(dwIoBase, byRegOfs, wCRC)       \
-{                                                          \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1);          \
-    VNSvOutPortW(dwIoBase + byRegOfs, wCRC);               \
-    VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0);          \
-}
-
-#define MACvGPIOIn(dwIoBase, pbyValue)                      \
-{                                                           \
-    VNSvInPortB(dwIoBase + MAC_REG_GPIOCTL1, pbyValue);     \
-}
+#define MACvSetCurrBCNLength(dwIoBase, wCurrBCNLength)         \
+       VNSvOutPortW(dwIoBase + MAC_REG_BCNDMACTL+2,            \
+                    wCurrBCNLength)
+
+#define MACvReadBSSIDAddress(dwIoBase, pbyEtherAddr)           \
+do {                                                           \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1);           \
+       VNSvInPortB(dwIoBase + MAC_REG_BSSID0,                  \
+                   (unsigned char *)pbyEtherAddr);             \
+       VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 1,              \
+                   pbyEtherAddr + 1);                          \
+       VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 2,              \
+                   pbyEtherAddr + 2);                          \
+       VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 3,              \
+                   pbyEtherAddr + 3);                          \
+       VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 4,              \
+                   pbyEtherAddr + 4);                          \
+       VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 5,              \
+                   pbyEtherAddr + 5);                          \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0);           \
+} while (0)
+
+#define MACvWriteBSSIDAddress(dwIoBase, pbyEtherAddr)          \
+do {                                                           \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1);           \
+       VNSvOutPortB(dwIoBase + MAC_REG_BSSID0,                 \
+                    *(pbyEtherAddr));                          \
+       VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 1,             \
+                    *(pbyEtherAddr + 1));                      \
+       VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 2,             \
+                    *(pbyEtherAddr + 2));                      \
+       VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 3,             \
+                    *(pbyEtherAddr + 3));                      \
+       VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 4,             \
+                    *(pbyEtherAddr + 4));                      \
+       VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 5,             \
+                    *(pbyEtherAddr + 5));                      \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0);           \
+} while (0)
+
+#define MACvReadEtherAddress(dwIoBase, pbyEtherAddr)           \
+do {                                                           \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1);           \
+       VNSvInPortB(dwIoBase + MAC_REG_PAR0,                    \
+                   (unsigned char *)pbyEtherAddr);             \
+       VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 1,                \
+                   pbyEtherAddr + 1);                          \
+       VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 2,                \
+                   pbyEtherAddr + 2);                          \
+       VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 3,                \
+                   pbyEtherAddr + 3);                          \
+       VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 4,                \
+                   pbyEtherAddr + 4);                          \
+       VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 5,                \
+                   pbyEtherAddr + 5);                          \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0);           \
+} while (0)
+
+#define MACvWriteEtherAddress(dwIoBase, pbyEtherAddr)          \
+do {                                                           \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1);           \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAR0,                   \
+                    *pbyEtherAddr);                            \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 1,               \
+                    *(pbyEtherAddr + 1));                      \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 2,               \
+                    *(pbyEtherAddr + 2));                      \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 3,               \
+                    *(pbyEtherAddr + 3));                      \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 4,               \
+                    *(pbyEtherAddr + 4));                      \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 5,               \
+                    *(pbyEtherAddr + 5));                      \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0);           \
+} while (0)
+
+#define MACvClearISR(dwIoBase)                                         \
+       VNSvOutPortD(dwIoBase + MAC_REG_ISR, IMR_MASK_VALUE)
+
+#define MACvStart(dwIoBase)                                            \
+       VNSvOutPortB(dwIoBase + MAC_REG_HOSTCR,                         \
+                    (HOSTCR_MACEN | HOSTCR_RXON | HOSTCR_TXON))
+
+#define MACvRx0PerPktMode(dwIoBase)                                    \
+       VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, RX_PERPKT)
+
+#define MACvRx0BufferFillMode(dwIoBase)                                        \
+       VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, RX_PERPKTCLR)
+
+#define MACvRx1PerPktMode(dwIoBase)                                    \
+       VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, RX_PERPKT)
+
+#define MACvRx1BufferFillMode(dwIoBase)                                        \
+       VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, RX_PERPKTCLR)
+
+#define MACvRxOn(dwIoBase)                                             \
+       MACvRegBitsOn(dwIoBase, MAC_REG_HOSTCR, HOSTCR_RXON)
+
+#define MACvReceive0(dwIoBase)                                         \
+do {                                                                   \
+       unsigned long dwData;                                           \
+       VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL0, &dwData);             \
+       if (dwData & DMACTL_RUN)                                        \
+               VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_WAKE); \
+       else                                                            \
+               VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN); \
+} while (0)
+
+#define MACvReceive1(dwIoBase)                                         \
+do {                                                                   \
+       unsigned long dwData;                                           \
+       VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL1, &dwData);             \
+       if (dwData & DMACTL_RUN)                                        \
+               VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_WAKE); \
+       else                                                            \
+               VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_RUN); \
+} while (0)
+
+#define MACvTxOn(dwIoBase)                                             \
+       MACvRegBitsOn(dwIoBase, MAC_REG_HOSTCR, HOSTCR_TXON)
+
+#define MACvTransmit0(dwIoBase)                                                \
+do {                                                                   \
+       unsigned long dwData;                                           \
+       VNSvInPortD(dwIoBase + MAC_REG_TXDMACTL0, &dwData);             \
+       if (dwData & DMACTL_RUN)                                        \
+               VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_WAKE); \
+       else                                                            \
+               VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_RUN); \
+} while (0)
+
+#define MACvTransmitAC0(dwIoBase)                                      \
+do {                                                                   \
+       unsigned long dwData;                                           \
+       VNSvInPortD(dwIoBase + MAC_REG_AC0DMACTL, &dwData);             \
+       if (dwData & DMACTL_RUN)                                        \
+               VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_WAKE); \
+       else                                                            \
+               VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_RUN); \
+} while (0)
+
+#define MACvTransmitSYNC(dwIoBase)                                     \
+do {                                                                   \
+       unsigned long dwData;                                           \
+       VNSvInPortD(dwIoBase + MAC_REG_SYNCDMACTL, &dwData);            \
+       if (dwData & DMACTL_RUN)                                        \
+               VNSvOutPortD(dwIoBase + MAC_REG_SYNCDMACTL, DMACTL_WAKE); \
+       else                                                            \
+               VNSvOutPortD(dwIoBase + MAC_REG_SYNCDMACTL, DMACTL_RUN); \
+} while (0)
+
+#define MACvTransmitATIM(dwIoBase)                                     \
+do {                                                                   \
+       unsigned long dwData;                                           \
+       VNSvInPortD(dwIoBase + MAC_REG_ATIMDMACTL, &dwData);            \
+       if (dwData & DMACTL_RUN)                                        \
+               VNSvOutPortD(dwIoBase + MAC_REG_ATIMDMACTL, DMACTL_WAKE); \
+       else                                                            \
+               VNSvOutPortD(dwIoBase + MAC_REG_ATIMDMACTL, DMACTL_RUN); \
+} while (0)
+
+#define MACvTransmitBCN(dwIoBase)                                      \
+       VNSvOutPortB(dwIoBase + MAC_REG_BCNDMACTL, BEACON_READY)
+
+#define MACvClearStckDS(dwIoBase)                                      \
+do {                                                                   \
+       unsigned char byOrgValue;                                       \
+       VNSvInPortB(dwIoBase + MAC_REG_STICKHW, &byOrgValue);           \
+       byOrgValue = byOrgValue & 0xFC;                                 \
+       VNSvOutPortB(dwIoBase + MAC_REG_STICKHW, byOrgValue);           \
+} while (0)
+
+#define MACvReadISR(dwIoBase, pdwValue)                                \
+       VNSvInPortD(dwIoBase + MAC_REG_ISR, pdwValue)
+
+#define MACvWriteISR(dwIoBase, dwValue)                                \
+       VNSvOutPortD(dwIoBase + MAC_REG_ISR, dwValue)
+
+#define MACvIntEnable(dwIoBase, dwMask)                                \
+       VNSvOutPortD(dwIoBase + MAC_REG_IMR, dwMask)
+
+#define MACvIntDisable(dwIoBase)                               \
+       VNSvOutPortD(dwIoBase + MAC_REG_IMR, 0)
+
+#define MACvSelectPage0(dwIoBase)                              \
+               VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0)
+
+#define MACvSelectPage1(dwIoBase)                              \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1)
+
+#define MACvReadMIBCounter(dwIoBase, pdwCounter)                       \
+       VNSvInPortD(dwIoBase + MAC_REG_MIBCNTR , pdwCounter)
+
+#define MACvPwrEvntDisable(dwIoBase)                                   \
+       VNSvOutPortW(dwIoBase + MAC_REG_WAKEUPEN0, 0x0000)
+
+#define MACvEnableProtectMD(dwIoBase)                                  \
+do {                                                                   \
+       unsigned long dwOrgValue;                                       \
+       VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);            \
+       dwOrgValue = dwOrgValue | EnCFG_ProtectMd;                      \
+       VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);             \
+} while (0)
+
+#define MACvDisableProtectMD(dwIoBase)                                 \
+do {                                                                   \
+       unsigned long dwOrgValue;                                       \
+       VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);            \
+       dwOrgValue = dwOrgValue & ~EnCFG_ProtectMd;                     \
+       VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);             \
+} while (0)
+
+#define MACvEnableBarkerPreambleMd(dwIoBase)                           \
+do {                                                                   \
+       unsigned long dwOrgValue;                                       \
+       VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);            \
+       dwOrgValue = dwOrgValue | EnCFG_BarkerPream;                    \
+       VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);             \
+} while (0)
+
+#define MACvDisableBarkerPreambleMd(dwIoBase)                          \
+do {                                                                   \
+       unsigned long dwOrgValue;                                       \
+       VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);            \
+       dwOrgValue = dwOrgValue & ~EnCFG_BarkerPream;                   \
+       VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);             \
+} while (0)
+
+#define MACvSetBBType(dwIoBase, byTyp)                                 \
+do {                                                                   \
+       unsigned long dwOrgValue;                                       \
+       VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);            \
+       dwOrgValue = dwOrgValue & ~EnCFG_BBType_MASK;                   \
+       dwOrgValue = dwOrgValue | (unsigned long)byTyp;                 \
+       VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);             \
+} while (0)
+
+#define MACvReadATIMW(dwIoBase, pwCounter)                             \
+       VNSvInPortW(dwIoBase + MAC_REG_AIDATIM, pwCounter)
+
+#define MACvWriteATIMW(dwIoBase, wCounter)                             \
+       VNSvOutPortW(dwIoBase + MAC_REG_AIDATIM, wCounter)
+
+#define MACvWriteCRC16_128(dwIoBase, byRegOfs, wCRC)           \
+do {                                                           \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1);           \
+       VNSvOutPortW(dwIoBase + byRegOfs, wCRC);                \
+       VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0);           \
+} while (0)
+
+#define MACvGPIOIn(dwIoBase, pbyValue)                                 \
+       VNSvInPortB(dwIoBase + MAC_REG_GPIOCTL1, pbyValue)
 
 #define MACvSetRFLE_LatchBase(dwIoBase)                                 \
-{                                                                        \
-    MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_RFLEOPT); \
-}
+       MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_RFLEOPT)
 
 /*---------------------  Export Classes  ----------------------------*/
 
@@ -1107,7 +1029,7 @@ void MACvOneShotTimer1MicroSec(unsigned long dwIoBase, unsigned int uDelayTime);
 
 void MACvSetMISCFifo(unsigned long dwIoBase, unsigned short wOffset, unsigned long dwData);
 
-bool MACbTxDMAOff (unsigned long dwIoBase, unsigned int idx);
+bool MACbTxDMAOff(unsigned long dwIoBase, unsigned int idx);
 
 void MACvClearBusSusInd(unsigned long dwIoBase);
 void MACvEnableBusSusEn(unsigned long dwIoBase);
@@ -1116,15 +1038,14 @@ bool MACbFlushSYNCFifo(unsigned long dwIoBase);
 bool MACbPSWakeup(unsigned long dwIoBase);
 
 void MACvSetKeyEntry(unsigned long dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx,
-               unsigned int uKeyIdx, unsigned char *pbyAddr, unsigned long *pdwKey, unsigned char byLocalID);
+                    unsigned int uKeyIdx, unsigned char *pbyAddr, unsigned long *pdwKey, unsigned char byLocalID);
 void MACvDisableKeyEntry(unsigned long dwIoBase, unsigned int uEntryIdx);
 void MACvSetDefaultKeyEntry(unsigned long dwIoBase, unsigned int uKeyLen,
-               unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID);
+                           unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID);
 //void MACvEnableDefaultKey(unsigned long dwIoBase, unsigned char byLocalID);
 void MACvDisableDefaultKey(unsigned long dwIoBase);
 void MACvSetDefaultTKIPKeyEntry(unsigned long dwIoBase, unsigned int uKeyLen,
-               unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID);
+                               unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID);
 void MACvSetDefaultKeyCtl(unsigned long dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx, unsigned char byLocalID);
 
 #endif // __MAC_H__
-
index 63ae4adddf2fe50200fb1417463e0b1c7d863189..6a59652052b652f1d558f88fad1f152967e7922e 100644 (file)
@@ -45,7 +45,7 @@
 #include "baseband.h"
 
 /*---------------------  Static Definitions -------------------------*/
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 /*---------------------  Static Classes  ----------------------------*/
 
 /*---------------------  Static Variables  --------------------------*/
@@ -56,8 +56,6 @@ static int          msglevel                =MSG_LEVEL_INFO;
 
 /*---------------------  Export Functions  --------------------------*/
 
-
-
 /*
  * Description: Clear All Statistic Counter
  *
@@ -70,13 +68,12 @@ static int          msglevel                =MSG_LEVEL_INFO;
  * Return Value: none
  *
  */
-void STAvClearAllCounter (PSStatCounter pStatistic)
+void STAvClearAllCounter(PSStatCounter pStatistic)
 {
-    // set memory to zero
+       // set memory to zero
        memset(pStatistic, 0, sizeof(SStatCounter));
 }
 
-
 /*
  * Description: Update Isr Statistic Counter
  *
@@ -90,76 +87,59 @@ void STAvClearAllCounter (PSStatCounter pStatistic)
  * Return Value: none
  *
  */
-void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, unsigned long dwIsr)
+void STAvUpdateIsrStatCounter(PSStatCounter pStatistic, unsigned long dwIsr)
 {
-    /**********************/
-    /* ABNORMAL interrupt */
-    /**********************/
-    // not any IMR bit invoke irq
+       /**********************/
+       /* ABNORMAL interrupt */
+       /**********************/
+       // not any IMR bit invoke irq
 
-    if (dwIsr == 0) {
-        pStatistic->ISRStat.dwIsrUnknown++;
-        return;
-    }
+       if (dwIsr == 0) {
+               pStatistic->ISRStat.dwIsrUnknown++;
+               return;
+       }
 
 //Added by Kyle
-    if (dwIsr & ISR_TXDMA0)               // ISR, bit0
-        pStatistic->ISRStat.dwIsrTx0OK++;             // TXDMA0 successful
-
-    if (dwIsr & ISR_AC0DMA)               // ISR, bit1
-        pStatistic->ISRStat.dwIsrAC0TxOK++;           // AC0DMA successful
-
-    if (dwIsr & ISR_BNTX)                 // ISR, bit2
-        pStatistic->ISRStat.dwIsrBeaconTxOK++;        // BeaconTx successful
-
-    if (dwIsr & ISR_RXDMA0)               // ISR, bit3
-        pStatistic->ISRStat.dwIsrRx0OK++;             // Rx0 successful
-
-    if (dwIsr & ISR_TBTT)                 // ISR, bit4
-        pStatistic->ISRStat.dwIsrTBTTInt++;           // TBTT successful
-
-    if (dwIsr & ISR_SOFTTIMER)            // ISR, bit6
-        pStatistic->ISRStat.dwIsrSTIMERInt++;
-
-    if (dwIsr & ISR_WATCHDOG)             // ISR, bit7
-        pStatistic->ISRStat.dwIsrWatchDog++;
+       if (dwIsr & ISR_TXDMA0)               // ISR, bit0
+               pStatistic->ISRStat.dwIsrTx0OK++;             // TXDMA0 successful
 
-    if (dwIsr & ISR_FETALERR)             // ISR, bit8
-        pStatistic->ISRStat.dwIsrUnrecoverableError++;
+       if (dwIsr & ISR_AC0DMA)               // ISR, bit1
+               pStatistic->ISRStat.dwIsrAC0TxOK++;           // AC0DMA successful
 
-    if (dwIsr & ISR_SOFTINT)              // ISR, bit9
-        pStatistic->ISRStat.dwIsrSoftInterrupt++;     // software interrupt
+       if (dwIsr & ISR_BNTX)                 // ISR, bit2
+               pStatistic->ISRStat.dwIsrBeaconTxOK++;        // BeaconTx successful
 
-    if (dwIsr & ISR_MIBNEARFULL)          // ISR, bit10
-        pStatistic->ISRStat.dwIsrMIBNearfull++;
+       if (dwIsr & ISR_RXDMA0)               // ISR, bit3
+               pStatistic->ISRStat.dwIsrRx0OK++;             // Rx0 successful
 
-    if (dwIsr & ISR_RXNOBUF)              // ISR, bit11
-        pStatistic->ISRStat.dwIsrRxNoBuf++;           // Rx No Buff
+       if (dwIsr & ISR_TBTT)                 // ISR, bit4
+               pStatistic->ISRStat.dwIsrTBTTInt++;           // TBTT successful
 
-    if (dwIsr & ISR_RXDMA1)               // ISR, bit12
-        pStatistic->ISRStat.dwIsrRx1OK++;             // Rx1 successful
+       if (dwIsr & ISR_SOFTTIMER)            // ISR, bit6
+               pStatistic->ISRStat.dwIsrSTIMERInt++;
 
-//    if (dwIsr & ISR_ATIMTX)               // ISR, bit13
-//        pStatistic->ISRStat.dwIsrATIMTxOK++;          // ATIMTX successful
+       if (dwIsr & ISR_WATCHDOG)             // ISR, bit7
+               pStatistic->ISRStat.dwIsrWatchDog++;
 
-//    if (dwIsr & ISR_SYNCTX)               // ISR, bit14
-//        pStatistic->ISRStat.dwIsrSYNCTxOK++;          // SYNCTX successful
+       if (dwIsr & ISR_FETALERR)             // ISR, bit8
+               pStatistic->ISRStat.dwIsrUnrecoverableError++;
 
-//    if (dwIsr & ISR_CFPEND)               // ISR, bit18
-//        pStatistic->ISRStat.dwIsrCFPEnd++;
+       if (dwIsr & ISR_SOFTINT)              // ISR, bit9
+               pStatistic->ISRStat.dwIsrSoftInterrupt++;     // software interrupt
 
-//    if (dwIsr & ISR_ATIMEND)              // ISR, bit19
-//        pStatistic->ISRStat.dwIsrATIMEnd++;
+       if (dwIsr & ISR_MIBNEARFULL)          // ISR, bit10
+               pStatistic->ISRStat.dwIsrMIBNearfull++;
 
-//    if (dwIsr & ISR_SYNCFLUSHOK)          // ISR, bit20
-//        pStatistic->ISRStat.dwIsrSYNCFlushOK++;
+       if (dwIsr & ISR_RXNOBUF)              // ISR, bit11
+               pStatistic->ISRStat.dwIsrRxNoBuf++;           // Rx No Buff
 
-    if (dwIsr & ISR_SOFTTIMER1)           // ISR, bit21
-        pStatistic->ISRStat.dwIsrSTIMER1Int++;
+       if (dwIsr & ISR_RXDMA1)               // ISR, bit12
+               pStatistic->ISRStat.dwIsrRx1OK++;             // Rx1 successful
 
+       if (dwIsr & ISR_SOFTTIMER1)           // ISR, bit21
+               pStatistic->ISRStat.dwIsrSTIMER1Int++;
 }
 
-
 /*
  * Description: Update Rx Statistic Counter
  *
@@ -176,199 +156,175 @@ void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, unsigned long dwIsr)
  * Return Value: none
  *
  */
-void STAvUpdateRDStatCounter (PSStatCounter pStatistic,
-                              unsigned char byRSR, unsigned char byNewRSR, unsigned char byRxRate,
-                              unsigned char *pbyBuffer, unsigned int cbFrameLength)
+void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
+                            unsigned char byRSR, unsigned char byNewRSR, unsigned char byRxRate,
+                            unsigned char *pbyBuffer, unsigned int cbFrameLength)
 {
-    //need change
-    PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
-
-    if (byRSR & RSR_ADDROK)
-        pStatistic->dwRsrADDROk++;
-    if (byRSR & RSR_CRCOK) {
-        pStatistic->dwRsrCRCOk++;
-
-        pStatistic->ullRsrOK++;
-
-        if (cbFrameLength >= ETH_ALEN) {
-            // update counters in case of successful transmit
-            if (byRSR & RSR_ADDRBROAD) {
-                pStatistic->ullRxBroadcastFrames++;
-                pStatistic->ullRxBroadcastBytes += (unsigned long long) cbFrameLength;
-            }
-            else if (byRSR & RSR_ADDRMULTI) {
-                pStatistic->ullRxMulticastFrames++;
-                pStatistic->ullRxMulticastBytes += (unsigned long long) cbFrameLength;
-            }
-            else {
-                pStatistic->ullRxDirectedFrames++;
-                pStatistic->ullRxDirectedBytes += (unsigned long long) cbFrameLength;
-            }
-        }
-    }
-
-    if(byRxRate==22) {
-        pStatistic->CustomStat.ullRsr11M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr11MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"11M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr11M, (int)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
-    }
-    else if(byRxRate==11) {
-        pStatistic->CustomStat.ullRsr5M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr5MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 5M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr5M, (int)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
-    }
-    else if(byRxRate==4) {
-        pStatistic->CustomStat.ullRsr2M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr2MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 2M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr2M, (int)pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
-    }
-    else if(byRxRate==2){
-        pStatistic->CustomStat.ullRsr1M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr1MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 1M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr1M, (int)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
-    }
-    else if(byRxRate==12){
-        pStatistic->CustomStat.ullRsr6M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr6MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 6M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr6M, (int)pStatistic->CustomStat.ullRsr6MCRCOk);
-    }
-    else if(byRxRate==18){
-        pStatistic->CustomStat.ullRsr9M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr9MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 9M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr9M, (int)pStatistic->CustomStat.ullRsr9MCRCOk);
-    }
-    else if(byRxRate==24){
-        pStatistic->CustomStat.ullRsr12M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr12MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"12M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr12M, (int)pStatistic->CustomStat.ullRsr12MCRCOk);
-    }
-    else if(byRxRate==36){
-        pStatistic->CustomStat.ullRsr18M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr18MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"18M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr18M, (int)pStatistic->CustomStat.ullRsr18MCRCOk);
-    }
-    else if(byRxRate==48){
-        pStatistic->CustomStat.ullRsr24M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr24MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"24M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr24M, (int)pStatistic->CustomStat.ullRsr24MCRCOk);
-    }
-    else if(byRxRate==72){
-        pStatistic->CustomStat.ullRsr36M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr36MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"36M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr36M, (int)pStatistic->CustomStat.ullRsr36MCRCOk);
-    }
-    else if(byRxRate==96){
-        pStatistic->CustomStat.ullRsr48M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr48MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"48M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr48M, (int)pStatistic->CustomStat.ullRsr48MCRCOk);
-    }
-    else if(byRxRate==108){
-        pStatistic->CustomStat.ullRsr54M++;
-        if(byRSR & RSR_CRCOK) {
-            pStatistic->CustomStat.ullRsr54MCRCOk++;
-        }
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"54M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr54M, (int)pStatistic->CustomStat.ullRsr54MCRCOk);
-    }
-    else {
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown: Total[%d], CRCOK[%d]\n", (int)pStatistic->dwRsrRxPacket+1, (int)pStatistic->dwRsrCRCOk);
-    }
-
-    if (byRSR & RSR_BSSIDOK)
-        pStatistic->dwRsrBSSIDOk++;
-
-    if (byRSR & RSR_BCNSSIDOK)
-        pStatistic->dwRsrBCNSSIDOk++;
-    if (byRSR & RSR_IVLDLEN)  //invalid len (> 2312 byte)
-        pStatistic->dwRsrLENErr++;
-    if (byRSR & RSR_IVLDTYP)  //invalid packet type
-        pStatistic->dwRsrTYPErr++;
-    if (byRSR & (RSR_IVLDTYP | RSR_IVLDLEN))
-        pStatistic->dwRsrErr++;
-
-    if (byNewRSR & NEWRSR_DECRYPTOK)
-        pStatistic->dwNewRsrDECRYPTOK++;
-    if (byNewRSR & NEWRSR_CFPIND)
-        pStatistic->dwNewRsrCFP++;
-    if (byNewRSR & NEWRSR_HWUTSF)
-        pStatistic->dwNewRsrUTSF++;
-    if (byNewRSR & NEWRSR_BCNHITAID)
-        pStatistic->dwNewRsrHITAID++;
-    if (byNewRSR & NEWRSR_BCNHITAID0)
-        pStatistic->dwNewRsrHITAID0++;
-
-    // increase rx packet count
-    pStatistic->dwRsrRxPacket++;
-    pStatistic->dwRsrRxOctet += cbFrameLength;
-
-
-    if (IS_TYPE_DATA(pbyBuffer)) {
-        pStatistic->dwRsrRxData++;
-    } else if (IS_TYPE_MGMT(pbyBuffer)){
-        pStatistic->dwRsrRxManage++;
-    } else if (IS_TYPE_CONTROL(pbyBuffer)){
-        pStatistic->dwRsrRxControl++;
-    }
-
-    if (byRSR & RSR_ADDRBROAD)
-        pStatistic->dwRsrBroadcast++;
-    else if (byRSR & RSR_ADDRMULTI)
-        pStatistic->dwRsrMulticast++;
-    else
-        pStatistic->dwRsrDirected++;
-
-    if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
-        pStatistic->dwRsrRxFragment++;
-
-    if (cbFrameLength < ETH_ZLEN + 4) {
-        pStatistic->dwRsrRunt++;
-    }
-    else if (cbFrameLength == ETH_ZLEN + 4) {
-        pStatistic->dwRsrRxFrmLen64++;
-    }
-    else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
-        pStatistic->dwRsrRxFrmLen65_127++;
-    }
-    else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
-        pStatistic->dwRsrRxFrmLen128_255++;
-    }
-    else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
-        pStatistic->dwRsrRxFrmLen256_511++;
-    }
-    else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
-        pStatistic->dwRsrRxFrmLen512_1023++;
-    }
-    else if ((1024 <= cbFrameLength) && (cbFrameLength <= ETH_FRAME_LEN + 4)) {
-        pStatistic->dwRsrRxFrmLen1024_1518++;
-    } else if (cbFrameLength > ETH_FRAME_LEN + 4) {
-        pStatistic->dwRsrLong++;
-    }
-
+       //need change
+       PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
+
+       if (byRSR & RSR_ADDROK)
+               pStatistic->dwRsrADDROk++;
+       if (byRSR & RSR_CRCOK) {
+               pStatistic->dwRsrCRCOk++;
+
+               pStatistic->ullRsrOK++;
+
+               if (cbFrameLength >= ETH_ALEN) {
+                       // update counters in case of successful transmit
+                       if (byRSR & RSR_ADDRBROAD) {
+                               pStatistic->ullRxBroadcastFrames++;
+                               pStatistic->ullRxBroadcastBytes += (unsigned long long) cbFrameLength;
+                       } else if (byRSR & RSR_ADDRMULTI) {
+                               pStatistic->ullRxMulticastFrames++;
+                               pStatistic->ullRxMulticastBytes += (unsigned long long) cbFrameLength;
+                       } else {
+                               pStatistic->ullRxDirectedFrames++;
+                               pStatistic->ullRxDirectedBytes += (unsigned long long) cbFrameLength;
+                       }
+               }
+       }
+
+       if (byRxRate == 22) {
+               pStatistic->CustomStat.ullRsr11M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr11MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "11M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr11M, (int)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
+       } else if (byRxRate == 11) {
+               pStatistic->CustomStat.ullRsr5M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr5MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 5M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr5M, (int)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
+       } else if (byRxRate == 4) {
+               pStatistic->CustomStat.ullRsr2M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr2MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 2M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr2M, (int)pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
+       } else if (byRxRate == 2) {
+               pStatistic->CustomStat.ullRsr1M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr1MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 1M: ALL[%d], OK[%d]:[%02x]\n", (int)pStatistic->CustomStat.ullRsr1M, (int)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
+       } else if (byRxRate == 12) {
+               pStatistic->CustomStat.ullRsr6M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr6MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 6M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr6M, (int)pStatistic->CustomStat.ullRsr6MCRCOk);
+       } else if (byRxRate == 18) {
+               pStatistic->CustomStat.ullRsr9M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr9MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 9M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr9M, (int)pStatistic->CustomStat.ullRsr9MCRCOk);
+       } else if (byRxRate == 24) {
+               pStatistic->CustomStat.ullRsr12M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr12MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "12M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr12M, (int)pStatistic->CustomStat.ullRsr12MCRCOk);
+       } else if (byRxRate == 36) {
+               pStatistic->CustomStat.ullRsr18M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr18MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "18M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr18M, (int)pStatistic->CustomStat.ullRsr18MCRCOk);
+       } else if (byRxRate == 48) {
+               pStatistic->CustomStat.ullRsr24M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr24MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "24M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr24M, (int)pStatistic->CustomStat.ullRsr24MCRCOk);
+       } else if (byRxRate == 72) {
+               pStatistic->CustomStat.ullRsr36M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr36MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "36M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr36M, (int)pStatistic->CustomStat.ullRsr36MCRCOk);
+       } else if (byRxRate == 96) {
+               pStatistic->CustomStat.ullRsr48M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr48MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "48M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr48M, (int)pStatistic->CustomStat.ullRsr48MCRCOk);
+       } else if (byRxRate == 108) {
+               pStatistic->CustomStat.ullRsr54M++;
+               if (byRSR & RSR_CRCOK) {
+                       pStatistic->CustomStat.ullRsr54MCRCOk++;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "54M: ALL[%d], OK[%d]\n", (int)pStatistic->CustomStat.ullRsr54M, (int)pStatistic->CustomStat.ullRsr54MCRCOk);
+       } else {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unknown: Total[%d], CRCOK[%d]\n", (int)pStatistic->dwRsrRxPacket+1, (int)pStatistic->dwRsrCRCOk);
+       }
+
+       if (byRSR & RSR_BSSIDOK)
+               pStatistic->dwRsrBSSIDOk++;
+
+       if (byRSR & RSR_BCNSSIDOK)
+               pStatistic->dwRsrBCNSSIDOk++;
+       if (byRSR & RSR_IVLDLEN)  //invalid len (> 2312 byte)
+               pStatistic->dwRsrLENErr++;
+       if (byRSR & RSR_IVLDTYP)  //invalid packet type
+               pStatistic->dwRsrTYPErr++;
+       if (byRSR & (RSR_IVLDTYP | RSR_IVLDLEN))
+               pStatistic->dwRsrErr++;
+
+       if (byNewRSR & NEWRSR_DECRYPTOK)
+               pStatistic->dwNewRsrDECRYPTOK++;
+       if (byNewRSR & NEWRSR_CFPIND)
+               pStatistic->dwNewRsrCFP++;
+       if (byNewRSR & NEWRSR_HWUTSF)
+               pStatistic->dwNewRsrUTSF++;
+       if (byNewRSR & NEWRSR_BCNHITAID)
+               pStatistic->dwNewRsrHITAID++;
+       if (byNewRSR & NEWRSR_BCNHITAID0)
+               pStatistic->dwNewRsrHITAID0++;
+
+       // increase rx packet count
+       pStatistic->dwRsrRxPacket++;
+       pStatistic->dwRsrRxOctet += cbFrameLength;
+
+       if (IS_TYPE_DATA(pbyBuffer)) {
+               pStatistic->dwRsrRxData++;
+       } else if (IS_TYPE_MGMT(pbyBuffer)) {
+               pStatistic->dwRsrRxManage++;
+       } else if (IS_TYPE_CONTROL(pbyBuffer)) {
+               pStatistic->dwRsrRxControl++;
+       }
+
+       if (byRSR & RSR_ADDRBROAD)
+               pStatistic->dwRsrBroadcast++;
+       else if (byRSR & RSR_ADDRMULTI)
+               pStatistic->dwRsrMulticast++;
+       else
+               pStatistic->dwRsrDirected++;
+
+       if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
+               pStatistic->dwRsrRxFragment++;
+
+       if (cbFrameLength < ETH_ZLEN + 4) {
+               pStatistic->dwRsrRunt++;
+       } else if (cbFrameLength == ETH_ZLEN + 4) {
+               pStatistic->dwRsrRxFrmLen64++;
+       } else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
+               pStatistic->dwRsrRxFrmLen65_127++;
+       } else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
+               pStatistic->dwRsrRxFrmLen128_255++;
+       } else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
+               pStatistic->dwRsrRxFrmLen256_511++;
+       } else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
+               pStatistic->dwRsrRxFrmLen512_1023++;
+       } else if ((1024 <= cbFrameLength) && (cbFrameLength <= ETH_FRAME_LEN + 4)) {
+               pStatistic->dwRsrRxFrmLen1024_1518++;
+       } else if (cbFrameLength > ETH_FRAME_LEN + 4) {
+               pStatistic->dwRsrLong++;
+       }
 }
 
-
-
 /*
  * Description: Update Rx Statistic Counter and copy Rx buffer
  *
@@ -387,31 +343,30 @@ void STAvUpdateRDStatCounter (PSStatCounter pStatistic,
  */
 
 void
-STAvUpdateRDStatCounterEx (
-    PSStatCounter   pStatistic,
-    unsigned char byRSR,
-    unsigned char byNewRSR,
-    unsigned char byRxRate,
-    unsigned char *pbyBuffer,
-    unsigned int cbFrameLength
-    )
+STAvUpdateRDStatCounterEx(
+       PSStatCounter   pStatistic,
+       unsigned char byRSR,
+       unsigned char byNewRSR,
+       unsigned char byRxRate,
+       unsigned char *pbyBuffer,
+       unsigned int cbFrameLength
+)
 {
-    STAvUpdateRDStatCounter(
-                    pStatistic,
-                    byRSR,
-                    byNewRSR,
-                    byRxRate,
-                    pbyBuffer,
-                    cbFrameLength
-                    );
-
-    // rx length
-    pStatistic->dwCntRxFrmLength = cbFrameLength;
-    // rx pattern, we just see 10 bytes for sample
-    memcpy(pStatistic->abyCntRxPattern, (unsigned char *)pbyBuffer, 10);
+       STAvUpdateRDStatCounter(
+               pStatistic,
+               byRSR,
+               byNewRSR,
+               byRxRate,
+               pbyBuffer,
+               cbFrameLength
+);
+
+       // rx length
+       pStatistic->dwCntRxFrmLength = cbFrameLength;
+       // rx pattern, we just see 10 bytes for sample
+       memcpy(pStatistic->abyCntRxPattern, (unsigned char *)pbyBuffer, 10);
 }
 
-
 /*
  * Description: Update Tx Statistic Counter
  *
@@ -430,81 +385,73 @@ STAvUpdateRDStatCounterEx (
  *
  */
 void
-STAvUpdateTDStatCounter (
-    PSStatCounter   pStatistic,
-    unsigned char byTSR0,
-    unsigned char byTSR1,
-    unsigned char *pbyBuffer,
-    unsigned int cbFrameLength,
-    unsigned int uIdx
-    )
+STAvUpdateTDStatCounter(
+       PSStatCounter   pStatistic,
+       unsigned char byTSR0,
+       unsigned char byTSR1,
+       unsigned char *pbyBuffer,
+       unsigned int cbFrameLength,
+       unsigned int uIdx
+)
 {
-    PWLAN_80211HDR_A4   pHeader;
-    unsigned char *pbyDestAddr;
-    unsigned char byTSR0_NCR = byTSR0 & TSR0_NCR;
-
-
-
-    pHeader = (PWLAN_80211HDR_A4) pbyBuffer;
-    if (WLAN_GET_FC_TODS(pHeader->wFrameCtl) == 0) {
-        pbyDestAddr = &(pHeader->abyAddr1[0]);
-    }
-    else {
-        pbyDestAddr = &(pHeader->abyAddr3[0]);
-    }
-    // increase tx packet count
-    pStatistic->dwTsrTxPacket[uIdx]++;
-    pStatistic->dwTsrTxOctet[uIdx] += cbFrameLength;
-
-    if (byTSR0_NCR != 0) {
-        pStatistic->dwTsrRetry[uIdx]++;
-        pStatistic->dwTsrTotalRetry[uIdx] += byTSR0_NCR;
-
-        if (byTSR0_NCR == 1)
-            pStatistic->dwTsrOnceRetry[uIdx]++;
-        else
-            pStatistic->dwTsrMoreThanOnceRetry[uIdx]++;
-    }
-
-    if ((byTSR1&(TSR1_TERR|TSR1_RETRYTMO|TSR1_TMO|ACK_DATA)) == 0) {
-        pStatistic->ullTsrOK[uIdx]++;
-        pStatistic->CustomStat.ullTsrAllOK =
-            (pStatistic->ullTsrOK[TYPE_AC0DMA] + pStatistic->ullTsrOK[TYPE_TXDMA0]);
-        // update counters in case that successful transmit
-        if (is_broadcast_ether_addr(pbyDestAddr)) {
-            pStatistic->ullTxBroadcastFrames[uIdx]++;
-            pStatistic->ullTxBroadcastBytes[uIdx] += (unsigned long long) cbFrameLength;
-        }
-        else if (is_multicast_ether_addr(pbyDestAddr)) {
-            pStatistic->ullTxMulticastFrames[uIdx]++;
-            pStatistic->ullTxMulticastBytes[uIdx] += (unsigned long long) cbFrameLength;
-        }
-        else {
-            pStatistic->ullTxDirectedFrames[uIdx]++;
-            pStatistic->ullTxDirectedBytes[uIdx] += (unsigned long long) cbFrameLength;
-        }
-    }
-    else {
-        if (byTSR1 & TSR1_TERR)
-            pStatistic->dwTsrErr[uIdx]++;
-        if (byTSR1 & TSR1_RETRYTMO)
-            pStatistic->dwTsrRetryTimeout[uIdx]++;
-        if (byTSR1 & TSR1_TMO)
-            pStatistic->dwTsrTransmitTimeout[uIdx]++;
-        if (byTSR1 & ACK_DATA)
-            pStatistic->dwTsrACKData[uIdx]++;
-    }
-
-    if (is_broadcast_ether_addr(pbyDestAddr))
-        pStatistic->dwTsrBroadcast[uIdx]++;
-    else if (is_multicast_ether_addr(pbyDestAddr))
-        pStatistic->dwTsrMulticast[uIdx]++;
-    else
-        pStatistic->dwTsrDirected[uIdx]++;
-
+       PWLAN_80211HDR_A4   pHeader;
+       unsigned char *pbyDestAddr;
+       unsigned char byTSR0_NCR = byTSR0 & TSR0_NCR;
+
+       pHeader = (PWLAN_80211HDR_A4) pbyBuffer;
+       if (WLAN_GET_FC_TODS(pHeader->wFrameCtl) == 0) {
+               pbyDestAddr = &(pHeader->abyAddr1[0]);
+       } else {
+               pbyDestAddr = &(pHeader->abyAddr3[0]);
+       }
+       // increase tx packet count
+       pStatistic->dwTsrTxPacket[uIdx]++;
+       pStatistic->dwTsrTxOctet[uIdx] += cbFrameLength;
+
+       if (byTSR0_NCR != 0) {
+               pStatistic->dwTsrRetry[uIdx]++;
+               pStatistic->dwTsrTotalRetry[uIdx] += byTSR0_NCR;
+
+               if (byTSR0_NCR == 1)
+                       pStatistic->dwTsrOnceRetry[uIdx]++;
+               else
+                       pStatistic->dwTsrMoreThanOnceRetry[uIdx]++;
+       }
+
+       if ((byTSR1&(TSR1_TERR|TSR1_RETRYTMO|TSR1_TMO|ACK_DATA)) == 0) {
+               pStatistic->ullTsrOK[uIdx]++;
+               pStatistic->CustomStat.ullTsrAllOK =
+                       (pStatistic->ullTsrOK[TYPE_AC0DMA] + pStatistic->ullTsrOK[TYPE_TXDMA0]);
+               // update counters in case that successful transmit
+               if (is_broadcast_ether_addr(pbyDestAddr)) {
+                       pStatistic->ullTxBroadcastFrames[uIdx]++;
+                       pStatistic->ullTxBroadcastBytes[uIdx] += (unsigned long long) cbFrameLength;
+               } else if (is_multicast_ether_addr(pbyDestAddr)) {
+                       pStatistic->ullTxMulticastFrames[uIdx]++;
+                       pStatistic->ullTxMulticastBytes[uIdx] += (unsigned long long) cbFrameLength;
+               } else {
+                       pStatistic->ullTxDirectedFrames[uIdx]++;
+                       pStatistic->ullTxDirectedBytes[uIdx] += (unsigned long long) cbFrameLength;
+               }
+       } else {
+               if (byTSR1 & TSR1_TERR)
+                       pStatistic->dwTsrErr[uIdx]++;
+               if (byTSR1 & TSR1_RETRYTMO)
+                       pStatistic->dwTsrRetryTimeout[uIdx]++;
+               if (byTSR1 & TSR1_TMO)
+                       pStatistic->dwTsrTransmitTimeout[uIdx]++;
+               if (byTSR1 & ACK_DATA)
+                       pStatistic->dwTsrACKData[uIdx]++;
+       }
+
+       if (is_broadcast_ether_addr(pbyDestAddr))
+               pStatistic->dwTsrBroadcast[uIdx]++;
+       else if (is_multicast_ether_addr(pbyDestAddr))
+               pStatistic->dwTsrMulticast[uIdx]++;
+       else
+               pStatistic->dwTsrDirected[uIdx]++;
 }
 
-
 /*
  * Description: Update Tx Statistic Counter and copy Tx buffer
  *
@@ -520,23 +467,22 @@ STAvUpdateTDStatCounter (
  *
  */
 void
-STAvUpdateTDStatCounterEx (
-    PSStatCounter   pStatistic,
-    unsigned char *pbyBuffer,
-    unsigned long cbFrameLength
-    )
+STAvUpdateTDStatCounterEx(
+       PSStatCounter   pStatistic,
+       unsigned char *pbyBuffer,
+       unsigned long cbFrameLength
+)
 {
-    unsigned int uPktLength;
+       unsigned int uPktLength;
 
-    uPktLength = (unsigned int)cbFrameLength;
+       uPktLength = (unsigned int)cbFrameLength;
 
-    // tx length
-    pStatistic->dwCntTxBufLength = uPktLength;
-    // tx pattern, we just see 16 bytes for sample
-    memcpy(pStatistic->abyCntTxPattern, pbyBuffer, 16);
+       // tx length
+       pStatistic->dwCntTxBufLength = uPktLength;
+       // tx pattern, we just see 16 bytes for sample
+       memcpy(pStatistic->abyCntTxPattern, pbyBuffer, 16);
 }
 
-
 /*
  * Description: Update 802.11 mib counter
  *
@@ -553,28 +499,28 @@ STAvUpdateTDStatCounterEx (
  */
 void
 STAvUpdate802_11Counter(
-    PSDot11Counters         p802_11Counter,
-    PSStatCounter           pStatistic,
-    unsigned long dwCounter
-    )
+       PSDot11Counters         p802_11Counter,
+       PSStatCounter           pStatistic,
+       unsigned long dwCounter
+)
 {
-    //p802_11Counter->TransmittedFragmentCount
-    p802_11Counter->MulticastTransmittedFrameCount = (unsigned long long) (pStatistic->dwTsrBroadcast[TYPE_AC0DMA] +
-                                                                  pStatistic->dwTsrBroadcast[TYPE_TXDMA0] +
-                                                                  pStatistic->dwTsrMulticast[TYPE_AC0DMA] +
-                                                                  pStatistic->dwTsrMulticast[TYPE_TXDMA0]);
-    p802_11Counter->FailedCount = (unsigned long long) (pStatistic->dwTsrErr[TYPE_AC0DMA] + pStatistic->dwTsrErr[TYPE_TXDMA0]);
-    p802_11Counter->RetryCount = (unsigned long long) (pStatistic->dwTsrRetry[TYPE_AC0DMA] + pStatistic->dwTsrRetry[TYPE_TXDMA0]);
-    p802_11Counter->MultipleRetryCount = (unsigned long long) (pStatistic->dwTsrMoreThanOnceRetry[TYPE_AC0DMA] +
-                                                          pStatistic->dwTsrMoreThanOnceRetry[TYPE_TXDMA0]);
-    //p802_11Counter->FrameDuplicateCount
-    p802_11Counter->RTSSuccessCount += (unsigned long long)  (dwCounter & 0x000000ff);
-    p802_11Counter->RTSFailureCount += (unsigned long long) ((dwCounter & 0x0000ff00) >> 8);
-    p802_11Counter->ACKFailureCount += (unsigned long long) ((dwCounter & 0x00ff0000) >> 16);
-    p802_11Counter->FCSErrorCount +=   (unsigned long long) ((dwCounter & 0xff000000) >> 24);
-    //p802_11Counter->ReceivedFragmentCount
-    p802_11Counter->MulticastReceivedFrameCount = (unsigned long long) (pStatistic->dwRsrBroadcast +
-                                                               pStatistic->dwRsrMulticast);
+       //p802_11Counter->TransmittedFragmentCount
+       p802_11Counter->MulticastTransmittedFrameCount = (unsigned long long) (pStatistic->dwTsrBroadcast[TYPE_AC0DMA] +
+                                                                              pStatistic->dwTsrBroadcast[TYPE_TXDMA0] +
+                                                                              pStatistic->dwTsrMulticast[TYPE_AC0DMA] +
+                                                                              pStatistic->dwTsrMulticast[TYPE_TXDMA0]);
+       p802_11Counter->FailedCount = (unsigned long long) (pStatistic->dwTsrErr[TYPE_AC0DMA] + pStatistic->dwTsrErr[TYPE_TXDMA0]);
+       p802_11Counter->RetryCount = (unsigned long long) (pStatistic->dwTsrRetry[TYPE_AC0DMA] + pStatistic->dwTsrRetry[TYPE_TXDMA0]);
+       p802_11Counter->MultipleRetryCount = (unsigned long long) (pStatistic->dwTsrMoreThanOnceRetry[TYPE_AC0DMA] +
+                                                                  pStatistic->dwTsrMoreThanOnceRetry[TYPE_TXDMA0]);
+       //p802_11Counter->FrameDuplicateCount
+       p802_11Counter->RTSSuccessCount += (unsigned long long)  (dwCounter & 0x000000ff);
+       p802_11Counter->RTSFailureCount += (unsigned long long) ((dwCounter & 0x0000ff00) >> 8);
+       p802_11Counter->ACKFailureCount += (unsigned long long) ((dwCounter & 0x00ff0000) >> 16);
+       p802_11Counter->FCSErrorCount +=   (unsigned long long) ((dwCounter & 0xff000000) >> 24);
+       //p802_11Counter->ReceivedFragmentCount
+       p802_11Counter->MulticastReceivedFrameCount = (unsigned long long) (pStatistic->dwRsrBroadcast +
+                                                                           pStatistic->dwRsrMulticast);
 }
 
 /*
@@ -592,6 +538,6 @@ STAvUpdate802_11Counter(
 void
 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
 {
-    // set memory to zero
+       // set memory to zero
        memset(p802_11Counter, 0, sizeof(SDot11Counters));
 }
index 5cd697a2bc77a716cedf9629f95659755f3371cb..6b99c119b78f852f4690e19665adbaf38afa5abd 100644 (file)
 //
 
 typedef struct tagSDot11Counters {
-    unsigned long Length;             // Length of structure
-    unsigned long long   TransmittedFragmentCount;
-    unsigned long long   MulticastTransmittedFrameCount;
-    unsigned long long   FailedCount;
-    unsigned long long   RetryCount;
-    unsigned long long   MultipleRetryCount;
-    unsigned long long   RTSSuccessCount;
-    unsigned long long   RTSFailureCount;
-    unsigned long long   ACKFailureCount;
-    unsigned long long   FrameDuplicateCount;
-    unsigned long long   ReceivedFragmentCount;
-    unsigned long long   MulticastReceivedFrameCount;
-    unsigned long long   FCSErrorCount;
-    unsigned long long   TKIPLocalMICFailures;
-    unsigned long long   TKIPRemoteMICFailures;
-    unsigned long long   TKIPICVErrors;
-    unsigned long long   TKIPCounterMeasuresInvoked;
-    unsigned long long   TKIPReplays;
-    unsigned long long   CCMPFormatErrors;
-    unsigned long long   CCMPReplays;
-    unsigned long long   CCMPDecryptErrors;
-    unsigned long long   FourWayHandshakeFailures;
+       unsigned long Length;             // Length of structure
+       unsigned long long   TransmittedFragmentCount;
+       unsigned long long   MulticastTransmittedFrameCount;
+       unsigned long long   FailedCount;
+       unsigned long long   RetryCount;
+       unsigned long long   MultipleRetryCount;
+       unsigned long long   RTSSuccessCount;
+       unsigned long long   RTSFailureCount;
+       unsigned long long   ACKFailureCount;
+       unsigned long long   FrameDuplicateCount;
+       unsigned long long   ReceivedFragmentCount;
+       unsigned long long   MulticastReceivedFrameCount;
+       unsigned long long   FCSErrorCount;
+       unsigned long long   TKIPLocalMICFailures;
+       unsigned long long   TKIPRemoteMICFailures;
+       unsigned long long   TKIPICVErrors;
+       unsigned long long   TKIPCounterMeasuresInvoked;
+       unsigned long long   TKIPReplays;
+       unsigned long long   CCMPFormatErrors;
+       unsigned long long   CCMPReplays;
+       unsigned long long   CCMPDecryptErrors;
+       unsigned long long   FourWayHandshakeFailures;
 //    unsigned long long   WEPUndecryptableCount;
 //    unsigned long long   WEPICVErrorCount;
 //    unsigned long long   DecryptSuccessCount;
 //    unsigned long long   DecryptFailureCount;
 } SDot11Counters, *PSDot11Counters;
 
-
 //
 // MIB2 counter
 //
 typedef struct tagSMib2Counter {
-    long    ifIndex;
-    char    ifDescr[256];               // max size 255 plus zero ending
-                                        // e.g. "interface 1"
-    long    ifType;
-    long    ifMtu;
-    unsigned long ifSpeed;
-    unsigned char ifPhysAddress[ETH_ALEN];
-    long    ifAdminStatus;
-    long    ifOperStatus;
-    unsigned long ifLastChange;
-    unsigned long ifInOctets;
-    unsigned long ifInUcastPkts;
-    unsigned long ifInNUcastPkts;
-    unsigned long ifInDiscards;
-    unsigned long ifInErrors;
-    unsigned long ifInUnknownProtos;
-    unsigned long ifOutOctets;
-    unsigned long ifOutUcastPkts;
-    unsigned long ifOutNUcastPkts;
-    unsigned long ifOutDiscards;
-    unsigned long ifOutErrors;
-    unsigned long ifOutQLen;
-    unsigned long ifSpecific;
+       long    ifIndex;
+       char    ifDescr[256];               // max size 255 plus zero ending
+       // e.g. "interface 1"
+       long    ifType;
+       long    ifMtu;
+       unsigned long ifSpeed;
+       unsigned char ifPhysAddress[ETH_ALEN];
+       long    ifAdminStatus;
+       long    ifOperStatus;
+       unsigned long ifLastChange;
+       unsigned long ifInOctets;
+       unsigned long ifInUcastPkts;
+       unsigned long ifInNUcastPkts;
+       unsigned long ifInDiscards;
+       unsigned long ifInErrors;
+       unsigned long ifInUnknownProtos;
+       unsigned long ifOutOctets;
+       unsigned long ifOutUcastPkts;
+       unsigned long ifOutNUcastPkts;
+       unsigned long ifOutDiscards;
+       unsigned long ifOutErrors;
+       unsigned long ifOutQLen;
+       unsigned long ifSpecific;
 } SMib2Counter, *PSMib2Counter;
 
 // Value in the ifType entry
@@ -105,104 +104,100 @@ typedef struct tagSMib2Counter {
 #define DOWN                2           //
 #define TESTING             3           //
 
-
 //
 // RMON counter
 //
 typedef struct tagSRmonCounter {
-    long    etherStatsIndex;
-    unsigned long etherStatsDataSource;
-    unsigned long etherStatsDropEvents;
-    unsigned long etherStatsOctets;
-    unsigned long etherStatsPkts;
-    unsigned long etherStatsBroadcastPkts;
-    unsigned long etherStatsMulticastPkts;
-    unsigned long etherStatsCRCAlignErrors;
-    unsigned long etherStatsUndersizePkts;
-    unsigned long etherStatsOversizePkts;
-    unsigned long etherStatsFragments;
-    unsigned long etherStatsJabbers;
-    unsigned long etherStatsCollisions;
-    unsigned long etherStatsPkt64Octets;
-    unsigned long etherStatsPkt65to127Octets;
-    unsigned long etherStatsPkt128to255Octets;
-    unsigned long etherStatsPkt256to511Octets;
-    unsigned long etherStatsPkt512to1023Octets;
-    unsigned long etherStatsPkt1024to1518Octets;
-    unsigned long etherStatsOwners;
-    unsigned long etherStatsStatus;
+       long    etherStatsIndex;
+       unsigned long etherStatsDataSource;
+       unsigned long etherStatsDropEvents;
+       unsigned long etherStatsOctets;
+       unsigned long etherStatsPkts;
+       unsigned long etherStatsBroadcastPkts;
+       unsigned long etherStatsMulticastPkts;
+       unsigned long etherStatsCRCAlignErrors;
+       unsigned long etherStatsUndersizePkts;
+       unsigned long etherStatsOversizePkts;
+       unsigned long etherStatsFragments;
+       unsigned long etherStatsJabbers;
+       unsigned long etherStatsCollisions;
+       unsigned long etherStatsPkt64Octets;
+       unsigned long etherStatsPkt65to127Octets;
+       unsigned long etherStatsPkt128to255Octets;
+       unsigned long etherStatsPkt256to511Octets;
+       unsigned long etherStatsPkt512to1023Octets;
+       unsigned long etherStatsPkt1024to1518Octets;
+       unsigned long etherStatsOwners;
+       unsigned long etherStatsStatus;
 } SRmonCounter, *PSRmonCounter;
 
 //
 // Custom counter
 //
 typedef struct tagSCustomCounters {
-    unsigned long Length;
-
-    unsigned long long   ullTsrAllOK;
-
-    unsigned long long   ullRsr11M;
-    unsigned long long   ullRsr5M;
-    unsigned long long   ullRsr2M;
-    unsigned long long   ullRsr1M;
-
-    unsigned long long   ullRsr11MCRCOk;
-    unsigned long long   ullRsr5MCRCOk;
-    unsigned long long   ullRsr2MCRCOk;
-    unsigned long long   ullRsr1MCRCOk;
-
-    unsigned long long   ullRsr54M;
-    unsigned long long   ullRsr48M;
-    unsigned long long   ullRsr36M;
-    unsigned long long   ullRsr24M;
-    unsigned long long   ullRsr18M;
-    unsigned long long   ullRsr12M;
-    unsigned long long   ullRsr9M;
-    unsigned long long   ullRsr6M;
-
-    unsigned long long   ullRsr54MCRCOk;
-    unsigned long long   ullRsr48MCRCOk;
-    unsigned long long   ullRsr36MCRCOk;
-    unsigned long long   ullRsr24MCRCOk;
-    unsigned long long   ullRsr18MCRCOk;
-    unsigned long long   ullRsr12MCRCOk;
-    unsigned long long   ullRsr9MCRCOk;
-    unsigned long long   ullRsr6MCRCOk;
-
+       unsigned long Length;
+
+       unsigned long long   ullTsrAllOK;
+
+       unsigned long long   ullRsr11M;
+       unsigned long long   ullRsr5M;
+       unsigned long long   ullRsr2M;
+       unsigned long long   ullRsr1M;
+
+       unsigned long long   ullRsr11MCRCOk;
+       unsigned long long   ullRsr5MCRCOk;
+       unsigned long long   ullRsr2MCRCOk;
+       unsigned long long   ullRsr1MCRCOk;
+
+       unsigned long long   ullRsr54M;
+       unsigned long long   ullRsr48M;
+       unsigned long long   ullRsr36M;
+       unsigned long long   ullRsr24M;
+       unsigned long long   ullRsr18M;
+       unsigned long long   ullRsr12M;
+       unsigned long long   ullRsr9M;
+       unsigned long long   ullRsr6M;
+
+       unsigned long long   ullRsr54MCRCOk;
+       unsigned long long   ullRsr48MCRCOk;
+       unsigned long long   ullRsr36MCRCOk;
+       unsigned long long   ullRsr24MCRCOk;
+       unsigned long long   ullRsr18MCRCOk;
+       unsigned long long   ullRsr12MCRCOk;
+       unsigned long long   ullRsr9MCRCOk;
+       unsigned long long   ullRsr6MCRCOk;
 } SCustomCounters, *PSCustomCounters;
 
-
 //
 // Custom counter
 //
 typedef struct tagSISRCounters {
-    unsigned long Length;
-
-    unsigned long dwIsrTx0OK;
-    unsigned long dwIsrAC0TxOK;
-    unsigned long dwIsrBeaconTxOK;
-    unsigned long dwIsrRx0OK;
-    unsigned long dwIsrTBTTInt;
-    unsigned long dwIsrSTIMERInt;
-    unsigned long dwIsrWatchDog;
-    unsigned long dwIsrUnrecoverableError;
-    unsigned long dwIsrSoftInterrupt;
-    unsigned long dwIsrMIBNearfull;
-    unsigned long dwIsrRxNoBuf;
-
-    unsigned long dwIsrUnknown;               // unknown interrupt count
-
-    unsigned long dwIsrRx1OK;
-    unsigned long dwIsrATIMTxOK;
-    unsigned long dwIsrSYNCTxOK;
-    unsigned long dwIsrCFPEnd;
-    unsigned long dwIsrATIMEnd;
-    unsigned long dwIsrSYNCFlushOK;
-    unsigned long dwIsrSTIMER1Int;
-    /////////////////////////////////////
+       unsigned long Length;
+
+       unsigned long dwIsrTx0OK;
+       unsigned long dwIsrAC0TxOK;
+       unsigned long dwIsrBeaconTxOK;
+       unsigned long dwIsrRx0OK;
+       unsigned long dwIsrTBTTInt;
+       unsigned long dwIsrSTIMERInt;
+       unsigned long dwIsrWatchDog;
+       unsigned long dwIsrUnrecoverableError;
+       unsigned long dwIsrSoftInterrupt;
+       unsigned long dwIsrMIBNearfull;
+       unsigned long dwIsrRxNoBuf;
+
+       unsigned long dwIsrUnknown;               // unknown interrupt count
+
+       unsigned long dwIsrRx1OK;
+       unsigned long dwIsrATIMTxOK;
+       unsigned long dwIsrSYNCTxOK;
+       unsigned long dwIsrCFPEnd;
+       unsigned long dwIsrATIMEnd;
+       unsigned long dwIsrSYNCFlushOK;
+       unsigned long dwIsrSTIMER1Int;
+       /////////////////////////////////////
 } SISRCounters, *PSISRCounters;
 
-
 // Value in the etherStatsStatus entry
 #define VALID               1           //
 #define CREATE_REQUEST      2           //
@@ -213,125 +208,122 @@ typedef struct tagSISRCounters {
 // statistic counter
 //
 typedef struct tagSStatCounter {
-    //
-    // ISR status count
-    //
-
-
-    // RSR status count
-    //
-    unsigned long dwRsrFrmAlgnErr;
-    unsigned long dwRsrErr;
-    unsigned long dwRsrCRCErr;
-    unsigned long dwRsrCRCOk;
-    unsigned long dwRsrBSSIDOk;
-    unsigned long dwRsrADDROk;
-    unsigned long dwRsrBCNSSIDOk;
-    unsigned long dwRsrLENErr;
-    unsigned long dwRsrTYPErr;
-
-    unsigned long dwNewRsrDECRYPTOK;
-    unsigned long dwNewRsrCFP;
-    unsigned long dwNewRsrUTSF;
-    unsigned long dwNewRsrHITAID;
-    unsigned long dwNewRsrHITAID0;
-
-    unsigned long dwRsrLong;
-    unsigned long dwRsrRunt;
-
-    unsigned long dwRsrRxControl;
-    unsigned long dwRsrRxData;
-    unsigned long dwRsrRxManage;
-
-    unsigned long dwRsrRxPacket;
-    unsigned long dwRsrRxOctet;
-    unsigned long dwRsrBroadcast;
-    unsigned long dwRsrMulticast;
-    unsigned long dwRsrDirected;
-    // 64-bit OID
-    unsigned long long   ullRsrOK;
-
-    // for some optional OIDs (64 bits) and DMI support
-    unsigned long long   ullRxBroadcastBytes;
-    unsigned long long   ullRxMulticastBytes;
-    unsigned long long   ullRxDirectedBytes;
-    unsigned long long   ullRxBroadcastFrames;
-    unsigned long long   ullRxMulticastFrames;
-    unsigned long long   ullRxDirectedFrames;
-
-    unsigned long dwRsrRxFragment;
-    unsigned long dwRsrRxFrmLen64;
-    unsigned long dwRsrRxFrmLen65_127;
-    unsigned long dwRsrRxFrmLen128_255;
-    unsigned long dwRsrRxFrmLen256_511;
-    unsigned long dwRsrRxFrmLen512_1023;
-    unsigned long dwRsrRxFrmLen1024_1518;
-
-    // TSR status count
-    //
-    unsigned long dwTsrTotalRetry[TYPE_MAXTD];        // total collision retry count
-    unsigned long dwTsrOnceRetry[TYPE_MAXTD];         // this packet only occur one collision
-    unsigned long dwTsrMoreThanOnceRetry[TYPE_MAXTD]; // this packet occur more than one collision
-    unsigned long dwTsrRetry[TYPE_MAXTD];             // this packet has ever occur collision,
-                                         // that is (dwTsrOnceCollision0 + dwTsrMoreThanOnceCollision0)
-    unsigned long dwTsrACKData[TYPE_MAXTD];
-    unsigned long dwTsrErr[TYPE_MAXTD];
-    unsigned long dwAllTsrOK[TYPE_MAXTD];
-    unsigned long dwTsrRetryTimeout[TYPE_MAXTD];
-    unsigned long dwTsrTransmitTimeout[TYPE_MAXTD];
-
-    unsigned long dwTsrTxPacket[TYPE_MAXTD];
-    unsigned long dwTsrTxOctet[TYPE_MAXTD];
-    unsigned long dwTsrBroadcast[TYPE_MAXTD];
-    unsigned long dwTsrMulticast[TYPE_MAXTD];
-    unsigned long dwTsrDirected[TYPE_MAXTD];
-
-    // RD/TD count
-    unsigned long dwCntRxFrmLength;
-    unsigned long dwCntTxBufLength;
-
-    unsigned char abyCntRxPattern[16];
-    unsigned char abyCntTxPattern[16];
-
-
-
-    // Software check....
-    unsigned long dwCntRxDataErr;             // rx buffer data software compare CRC err count
-    unsigned long dwCntDecryptErr;            // rx buffer data software compare CRC err count
-    unsigned long dwCntRxICVErr;              // rx buffer data software compare CRC err count
-    unsigned int idxRxErrorDesc[TYPE_MAXRD]; // index for rx data error RD
-
-    // 64-bit OID
-    unsigned long long   ullTsrOK[TYPE_MAXTD];
-
-    // for some optional OIDs (64 bits) and DMI support
-    unsigned long long   ullTxBroadcastFrames[TYPE_MAXTD];
-    unsigned long long   ullTxMulticastFrames[TYPE_MAXTD];
-    unsigned long long   ullTxDirectedFrames[TYPE_MAXTD];
-    unsigned long long   ullTxBroadcastBytes[TYPE_MAXTD];
-    unsigned long long   ullTxMulticastBytes[TYPE_MAXTD];
-    unsigned long long   ullTxDirectedBytes[TYPE_MAXTD];
+       //
+       // ISR status count
+       //
+
+       // RSR status count
+       //
+       unsigned long dwRsrFrmAlgnErr;
+       unsigned long dwRsrErr;
+       unsigned long dwRsrCRCErr;
+       unsigned long dwRsrCRCOk;
+       unsigned long dwRsrBSSIDOk;
+       unsigned long dwRsrADDROk;
+       unsigned long dwRsrBCNSSIDOk;
+       unsigned long dwRsrLENErr;
+       unsigned long dwRsrTYPErr;
+
+       unsigned long dwNewRsrDECRYPTOK;
+       unsigned long dwNewRsrCFP;
+       unsigned long dwNewRsrUTSF;
+       unsigned long dwNewRsrHITAID;
+       unsigned long dwNewRsrHITAID0;
+
+       unsigned long dwRsrLong;
+       unsigned long dwRsrRunt;
+
+       unsigned long dwRsrRxControl;
+       unsigned long dwRsrRxData;
+       unsigned long dwRsrRxManage;
+
+       unsigned long dwRsrRxPacket;
+       unsigned long dwRsrRxOctet;
+       unsigned long dwRsrBroadcast;
+       unsigned long dwRsrMulticast;
+       unsigned long dwRsrDirected;
+       // 64-bit OID
+       unsigned long long   ullRsrOK;
+
+       // for some optional OIDs (64 bits) and DMI support
+       unsigned long long   ullRxBroadcastBytes;
+       unsigned long long   ullRxMulticastBytes;
+       unsigned long long   ullRxDirectedBytes;
+       unsigned long long   ullRxBroadcastFrames;
+       unsigned long long   ullRxMulticastFrames;
+       unsigned long long   ullRxDirectedFrames;
+
+       unsigned long dwRsrRxFragment;
+       unsigned long dwRsrRxFrmLen64;
+       unsigned long dwRsrRxFrmLen65_127;
+       unsigned long dwRsrRxFrmLen128_255;
+       unsigned long dwRsrRxFrmLen256_511;
+       unsigned long dwRsrRxFrmLen512_1023;
+       unsigned long dwRsrRxFrmLen1024_1518;
+
+       // TSR status count
+       //
+       unsigned long dwTsrTotalRetry[TYPE_MAXTD];        // total collision retry count
+       unsigned long dwTsrOnceRetry[TYPE_MAXTD];         // this packet only occur one collision
+       unsigned long dwTsrMoreThanOnceRetry[TYPE_MAXTD]; // this packet occur more than one collision
+       unsigned long dwTsrRetry[TYPE_MAXTD];             // this packet has ever occur collision,
+       // that is (dwTsrOnceCollision0 + dwTsrMoreThanOnceCollision0)
+       unsigned long dwTsrACKData[TYPE_MAXTD];
+       unsigned long dwTsrErr[TYPE_MAXTD];
+       unsigned long dwAllTsrOK[TYPE_MAXTD];
+       unsigned long dwTsrRetryTimeout[TYPE_MAXTD];
+       unsigned long dwTsrTransmitTimeout[TYPE_MAXTD];
+
+       unsigned long dwTsrTxPacket[TYPE_MAXTD];
+       unsigned long dwTsrTxOctet[TYPE_MAXTD];
+       unsigned long dwTsrBroadcast[TYPE_MAXTD];
+       unsigned long dwTsrMulticast[TYPE_MAXTD];
+       unsigned long dwTsrDirected[TYPE_MAXTD];
+
+       // RD/TD count
+       unsigned long dwCntRxFrmLength;
+       unsigned long dwCntTxBufLength;
+
+       unsigned char abyCntRxPattern[16];
+       unsigned char abyCntTxPattern[16];
+
+       // Software check....
+       unsigned long dwCntRxDataErr;             // rx buffer data software compare CRC err count
+       unsigned long dwCntDecryptErr;            // rx buffer data software compare CRC err count
+       unsigned long dwCntRxICVErr;              // rx buffer data software compare CRC err count
+       unsigned int idxRxErrorDesc[TYPE_MAXRD]; // index for rx data error RD
+
+       // 64-bit OID
+       unsigned long long   ullTsrOK[TYPE_MAXTD];
+
+       // for some optional OIDs (64 bits) and DMI support
+       unsigned long long   ullTxBroadcastFrames[TYPE_MAXTD];
+       unsigned long long   ullTxMulticastFrames[TYPE_MAXTD];
+       unsigned long long   ullTxDirectedFrames[TYPE_MAXTD];
+       unsigned long long   ullTxBroadcastBytes[TYPE_MAXTD];
+       unsigned long long   ullTxMulticastBytes[TYPE_MAXTD];
+       unsigned long long   ullTxDirectedBytes[TYPE_MAXTD];
 
 //    unsigned long dwTxRetryCount[8];
-    //
-    // ISR status count
-    //
-    SISRCounters ISRStat;
-
-    SCustomCounters CustomStat;
-
-   #ifdef Calcu_LinkQual
-       //Tx count:
-    unsigned long TxNoRetryOkCount;         //success tx no retry !
-    unsigned long TxRetryOkCount;              //success tx but retry !
-    unsigned long TxFailCount;                      //fail tx ?
-      //Rx count:
-    unsigned long RxOkCnt;                          //success rx !
-    unsigned long RxFcsErrCnt;                    //fail rx ?
-      //statistic
-    unsigned long SignalStren;
-    unsigned long LinkQuality;
-   #endif
+       //
+       // ISR status count
+       //
+       SISRCounters ISRStat;
+
+       SCustomCounters CustomStat;
+
+#ifdef Calcu_LinkQual
+       //Tx count:
+       unsigned long TxNoRetryOkCount;         //success tx no retry !
+       unsigned long TxRetryOkCount;              //success tx but retry !
+       unsigned long TxFailCount;                      //fail tx ?
+       //Rx count:
+       unsigned long RxOkCnt;                          //success rx !
+       unsigned long RxFcsErrCnt;                    //fail rx ?
+       //statistic
+       unsigned long SignalStren;
+       unsigned long LinkQuality;
+#endif
 } SStatCounter, *PSStatCounter;
 
 /*---------------------  Export Classes  ----------------------------*/
@@ -345,31 +337,28 @@ void STAvClearAllCounter(PSStatCounter pStatistic);
 void STAvUpdateIsrStatCounter(PSStatCounter pStatistic, unsigned long dwIsr);
 
 void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
-                              unsigned char byRSR, unsigned char byNewRSR, unsigned char byRxRate,
-                              unsigned char *pbyBuffer, unsigned int cbFrameLength);
+                            unsigned char byRSR, unsigned char byNewRSR, unsigned char byRxRate,
+                            unsigned char *pbyBuffer, unsigned int cbFrameLength);
 
 void STAvUpdateRDStatCounterEx(PSStatCounter pStatistic,
-                              unsigned char byRSR, unsigned char byNewRsr, unsigned char byRxRate,
-                              unsigned char *pbyBuffer, unsigned int cbFrameLength);
+                              unsigned char byRSR, unsigned char byNewRsr, unsigned char byRxRate,
+                              unsigned char *pbyBuffer, unsigned int cbFrameLength);
 
 void STAvUpdateTDStatCounter(PSStatCounter pStatistic, unsigned char byTSR0, unsigned char byTSR1,
-               unsigned char *pbyBuffer, unsigned int cbFrameLength, unsigned int uIdx);
+                            unsigned char *pbyBuffer, unsigned int cbFrameLength, unsigned int uIdx);
 
 void STAvUpdateTDStatCounterEx(
-    PSStatCounter   pStatistic,
-    unsigned char *pbyBuffer,
-    unsigned long cbFrameLength
-    );
+       PSStatCounter   pStatistic,
+       unsigned char *pbyBuffer,
+       unsigned long cbFrameLength
+);
 
 void STAvUpdate802_11Counter(
-    PSDot11Counters p802_11Counter,
-    PSStatCounter   pStatistic,
-    unsigned long dwCounter
-    );
+       PSDot11Counters p802_11Counter,
+       PSStatCounter   pStatistic,
+       unsigned long dwCounter
+);
 
 void STAvClear802_11Counter(PSDot11Counters p802_11Counter);
 
 #endif // __MIB_H__
-
-
-
index 67618f069d0d96425c65faa835e7d20a8d88f010..7ea5f7f82f43c259a806addbc882da5f6e8aae54 100644 (file)
 
 /*---------------------  Static Functions  --------------------------*/
 /*
-static unsigned long s_dwGetUINT32(unsigned char *p);         // Get unsigned long from 4 bytes LSByte first
-static void s_vPutUINT32(unsigned char *p, unsigned long val); // Put unsigned long into 4 bytes LSByte first
+  static unsigned long s_dwGetUINT32(unsigned char *p);         // Get unsigned long from 4 bytes LSByte first
+  static void s_vPutUINT32(unsigned char *p, unsigned long val); // Put unsigned long into 4 bytes LSByte first
 */
 static void s_vClear(void);                       // Clear the internal message,
-                                              // resets the object to the state just after construction.
+// resets the object to the state just after construction.
 static void s_vSetKey(unsigned long dwK0, unsigned long dwK1);
 static void s_vAppendByte(unsigned char b);            // Add a single byte to the internal message
 
@@ -66,116 +66,110 @@ static unsigned int nBytesInM;      // # bytes in M
 /*---------------------  Export Functions  --------------------------*/
 
 /*
-static unsigned long s_dwGetUINT32 (unsigned char *p)
+  static unsigned long s_dwGetUINT32 (unsigned char *p)
 // Convert from unsigned char [] to unsigned long in a portable way
 {
-    unsigned long res = 0;
-    unsigned int i;
-    for(i=0; i<4; i++ )
-    {
-        res |= (*p++) << (8*i);
-    }
-    return res;
+unsigned long res = 0;
+unsigned int i;
+for (i=0; i<4; i++)
+{
+       res |= (*p++) << (8 * i);
+}
+return res;
 }
 
 static void s_vPutUINT32 (unsigned char *p, unsigned long val)
 // Convert from unsigned long to unsigned char [] in a portable way
 {
-    unsigned int i;
-    for(i=0; i<4; i++ )
-    {
-        *p++ = (unsigned char) (val & 0xff);
-        val >>= 8;
-    }
+       unsigned int i;
+       for (i=0; i<4; i++) {
+               *p++ = (unsigned char) (val & 0xff);
+               val >>= 8;
+       }
 }
 */
 
-static void s_vClear (void)
+static void s_vClear(void)
 {
-    // Reset the state to the empty message.
-    L = K0;
-    R = K1;
-    nBytesInM = 0;
-    M = 0;
+       // Reset the state to the empty message.
+       L = K0;
+       R = K1;
+       nBytesInM = 0;
+       M = 0;
 }
 
-static void s_vSetKey (unsigned long dwK0, unsigned long dwK1)
+static void s_vSetKey(unsigned long dwK0, unsigned long dwK1)
 {
-    // Set the key
-    K0 = dwK0;
-    K1 = dwK1;
-    // and reset the message
-    s_vClear();
+       // Set the key
+       K0 = dwK0;
+       K1 = dwK1;
+       // and reset the message
+       s_vClear();
 }
 
-static void s_vAppendByte (unsigned char b)
+static void s_vAppendByte(unsigned char b)
 {
-    // Append the byte to our word-sized buffer
-    M |= b << (8*nBytesInM);
-    nBytesInM++;
-    // Process the word if it is full.
-    if( nBytesInM >= 4 )
-    {
-        L ^= M;
-        R ^= ROL32( L, 17 );
-        L += R;
-        R ^= ((L & 0xff00ff00) >> 8) | ((L & 0x00ff00ff) << 8);
-        L += R;
-        R ^= ROL32( L, 3 );
-        L += R;
-        R ^= ROR32( L, 2 );
-        L += R;
-        // Clear the buffer
-        M = 0;
-        nBytesInM = 0;
-    }
+       // Append the byte to our word-sized buffer
+       M |= b << (8*nBytesInM);
+       nBytesInM++;
+       // Process the word if it is full.
+       if (nBytesInM >= 4) {
+               L ^= M;
+               R ^= ROL32(L, 17);
+               L += R;
+               R ^= ((L & 0xff00ff00) >> 8) | ((L & 0x00ff00ff) << 8);
+               L += R;
+               R ^= ROL32(L, 3);
+               L += R;
+               R ^= ROR32(L, 2);
+               L += R;
+               // Clear the buffer
+               M = 0;
+               nBytesInM = 0;
+       }
 }
 
-void MIC_vInit (unsigned long dwK0, unsigned long dwK1)
+void MIC_vInit(unsigned long dwK0, unsigned long dwK1)
 {
-    // Set the key
-    s_vSetKey(dwK0, dwK1);
+       // Set the key
+       s_vSetKey(dwK0, dwK1);
 }
 
-
-void MIC_vUnInit (void)
+void MIC_vUnInit(void)
 {
-    // Wipe the key material
-    K0 = 0;
-    K1 = 0;
+       // Wipe the key material
+       K0 = 0;
+       K1 = 0;
 
-    // And the other fields as well.
-    //Note that this sets (L,R) to (K0,K1) which is just fine.
-    s_vClear();
+       // And the other fields as well.
+       //Note that this sets (L,R) to (K0,K1) which is just fine.
+       s_vClear();
 }
 
-void MIC_vAppend (unsigned char *src, unsigned int nBytes)
+void MIC_vAppend(unsigned char *src, unsigned int nBytes)
 {
-    // This is simple
-    while (nBytes > 0)
-    {
-        s_vAppendByte(*src++);
-        nBytes--;
-    }
+       // This is simple
+       while (nBytes > 0) {
+               s_vAppendByte(*src++);
+               nBytes--;
+       }
 }
 
-void MIC_vGetMIC (unsigned long *pdwL, unsigned long *pdwR)
+void MIC_vGetMIC(unsigned long *pdwL, unsigned long *pdwR)
 {
-    // Append the minimum padding
-    s_vAppendByte(0x5a);
-    s_vAppendByte(0);
-    s_vAppendByte(0);
-    s_vAppendByte(0);
-    s_vAppendByte(0);
-    // and then zeroes until the length is a multiple of 4
-    while( nBytesInM != 0 )
-    {
-        s_vAppendByte(0);
-    }
-    // The s_vAppendByte function has already computed the result.
-    *pdwL = L;
-    *pdwR = R;
-    // Reset to the empty message.
-    s_vClear();
+       // Append the minimum padding
+       s_vAppendByte(0x5a);
+       s_vAppendByte(0);
+       s_vAppendByte(0);
+       s_vAppendByte(0);
+       s_vAppendByte(0);
+       // and then zeroes until the length is a multiple of 4
+       while (nBytesInM != 0) {
+               s_vAppendByte(0);
+       }
+       // The s_vAppendByte function has already computed the result.
+       *pdwL = L;
+       *pdwR = R;
+       // Reset to the empty message.
+       s_vClear();
 }
-
index 3131b161d6a9a235e7f507067637ee7dbb2f05bf..0828d18ad528ae9ec6ba74f125b7e126052fc4fb 100644 (file)
@@ -49,10 +49,8 @@ void MIC_vGetMIC(unsigned long *pdwL, unsigned long *pdwR);
 /*---------------------  Export Macros ------------------------------*/
 
 // Rotation functions on 32 bit values
-#define ROL32( A, n ) \
( ((A) << (n)) | ( ((A)>>(32-(n)))  & ( (1UL << (n)) - 1 ) ) )
-#define ROR32( A, n ) ROL32( (A), 32-(n) )
+#define ROL32(A, n)                                                    \
      (((A) << (n)) | (((A)>>(32-(n)))  & ((1UL << (n)) - 1)))
+#define ROR32(A, n) ROL32((A), 32-(n))
 
 #endif //__MICHAEL_H__
-
-
index 661d534304cce99f26a275ccedaed34210b7edbf..2340d2f0399b20da7db606837e53c64807986c55 100644 (file)
 
 /*---------------------  Static Definitions -------------------------*/
 
-
-
-
 /*---------------------  Static Classes  ----------------------------*/
 
 /*---------------------  Static Variables  --------------------------*/
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 /*---------------------  Static Functions  --------------------------*/
 
-
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
 /*+
@@ -71,69 +66,62 @@ static int          msglevel                =MSG_LEVEL_INFO;
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 void
 PSvEnablePowerSaving(
-    void *hDeviceContext,
-    unsigned short wListenInterval
-    )
+       void *hDeviceContext,
+       unsigned short wListenInterval
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned short wAID = pMgmt->wCurrAID | BIT14 | BIT15;
-
-    // set period of power up before TBTT
-    VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT);
-    if (pDevice->eOPMode != OP_MODE_ADHOC) {
-        // set AID
-        VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID);
-    } else {
-       // set ATIM Window
-        MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
-    }
-    // Set AutoSleep
-    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
-    // Set HWUTSF
-    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
-
-    if (wListenInterval >= 2) {
-        // clear always listen beacon
-        MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
-        //pDevice->wCFG &= ~CFG_ALB;
-        // first time set listen next beacon
-        MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
-        pMgmt->wCountToWakeUp = wListenInterval;
-    }
-    else {
-        // always listen beacon
-        MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
-        //pDevice->wCFG |= CFG_ALB;
-        pMgmt->wCountToWakeUp = 0;
-    }
-
-    // enable power saving hw function
-    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
-    pDevice->bEnablePSMode = true;
-
-    if (pDevice->eOPMode == OP_MODE_ADHOC) {
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned short wAID = pMgmt->wCurrAID | BIT14 | BIT15;
+
+       // set period of power up before TBTT
+       VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT);
+       if (pDevice->eOPMode != OP_MODE_ADHOC) {
+               // set AID
+               VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID);
+       } else {
+               // set ATIM Window
+               MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
+       }
+       // Set AutoSleep
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
+       // Set HWUTSF
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
+
+       if (wListenInterval >= 2) {
+               // clear always listen beacon
+               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
+               //pDevice->wCFG &= ~CFG_ALB;
+               // first time set listen next beacon
+               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
+               pMgmt->wCountToWakeUp = wListenInterval;
+       } else {
+               // always listen beacon
+               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
+               //pDevice->wCFG |= CFG_ALB;
+               pMgmt->wCountToWakeUp = 0;
+       }
+
+       // enable power saving hw function
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
+       pDevice->bEnablePSMode = true;
+
+       if (pDevice->eOPMode == OP_MODE_ADHOC) {
 //        bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
-    }
-    // We don't send null pkt in ad hoc mode since beacon will handle this.
-    else if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
-        PSbSendNullPacket(pDevice);
-    }
-    pDevice->bPWBitOn = true;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable... \n");
-    return;
+       }
+       // We don't send null pkt in ad hoc mode since beacon will handle this.
+       else if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
+               PSbSendNullPacket(pDevice);
+       }
+       pDevice->bPWBitOn = true;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable... \n");
+       return;
 }
 
-
-
-
-
-
 /*+
  *
  * Routine Description:
@@ -142,35 +130,34 @@ PSvEnablePowerSaving(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 PSvDisablePowerSaving(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
 //    PSMgmtObject    pMgmt = pDevice->pMgmt;
 
-    // disable power saving hw function
-    MACbPSWakeup(pDevice->PortOffset);
-    //clear AutoSleep
-    MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
-    //clear HWUTSF
-    MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
-    // set always listen beacon
-    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
-
-    pDevice->bEnablePSMode = false;
-
-    if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
-        PSbSendNullPacket(pDevice);
-    }
-    pDevice->bPWBitOn = false;
-    return;
+       // disable power saving hw function
+       MACbPSWakeup(pDevice->PortOffset);
+       //clear AutoSleep
+       MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
+       //clear HWUTSF
+       MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
+       // set always listen beacon
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
+
+       pDevice->bEnablePSMode = false;
+
+       if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
+               PSbSendNullPacket(pDevice);
+       }
+       pDevice->bPWBitOn = false;
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -179,65 +166,62 @@ PSvDisablePowerSaving(
  * Return Value:
  *    true, if power down success
  *    false, if fail
--*/
-
+ -*/
 
 bool
 PSbConsiderPowerDown(
-    void *hDeviceContext,
-    bool bCheckRxDMA,
-    bool bCheckCountToWakeUp
-    )
+       void *hDeviceContext,
+       bool bCheckRxDMA,
+       bool bCheckCountToWakeUp
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned int uIdx;
-
-    // check if already in Doze mode
-    if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
-        return true;
-
-    if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
-        // check if in TIM wake period
-        if (pMgmt->bInTIMWake)
-            return false;
-    }
-
-    // check scan state
-    if (pDevice->bCmdRunning)
-        return false;
-
-    // Force PSEN on
-    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
-
-    // check if all TD are empty,
-    for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx ++) {
-        if (pDevice->iTDUsed[uIdx] != 0)
-            return false;
-    }
-
-    // check if rx isr is clear
-    if (bCheckRxDMA &&
-        ((pDevice->dwIsr& ISR_RXDMA0) != 0) &&
-        ((pDevice->dwIsr & ISR_RXDMA1) != 0)){
-        return false;
-    }
-
-    if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
-        if (bCheckCountToWakeUp &&
-           (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) {
-             return false;
-        }
-    }
-
-    // no Tx, no Rx isr, now go to Doze
-    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
-    return true;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned int uIdx;
+
+       // check if already in Doze mode
+       if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
+               return true;
+
+       if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
+               // check if in TIM wake period
+               if (pMgmt->bInTIMWake)
+                       return false;
+       }
+
+       // check scan state
+       if (pDevice->bCmdRunning)
+               return false;
+
+       // Force PSEN on
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
+
+       // check if all TD are empty,
+       for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
+               if (pDevice->iTDUsed[uIdx] != 0)
+                       return false;
+       }
+
+       // check if rx isr is clear
+       if (bCheckRxDMA &&
+           ((pDevice->dwIsr & ISR_RXDMA0) != 0) &&
+           ((pDevice->dwIsr & ISR_RXDMA1) != 0)) {
+               return false;
+       }
+
+       if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
+               if (bCheckCountToWakeUp &&
+                   (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) {
+                       return false;
+               }
+       }
+
+       // no Tx, no Rx isr, now go to Doze
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
+       return true;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -246,47 +230,41 @@ PSbConsiderPowerDown(
  * Return Value:
  *    None.
  *
--*/
-
-
+ -*/
 
 void
 PSvSendPSPOLL(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-    PSDevice            pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject        pMgmt = pDevice->pMgmt;
-    PSTxMgmtPacket      pTxPacket = NULL;
-
-
-    memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN);
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16(
-         (
-         WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) |
-         WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) |
-         WLAN_SET_FC_PWRMGT(0)
-         ));
-    pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15;
-    memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
-    memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN;
-    pTxPacket->cbPayloadLen = 0;
-    // send the frame
-    if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet failed..\n");
-    }
-    else {
+       PSDevice            pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject        pMgmt = pDevice->pMgmt;
+       PSTxMgmtPacket      pTxPacket = NULL;
+
+       memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN);
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) |
+                       WLAN_SET_FC_PWRMGT(0)
+));
+       pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15;
+       memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
+       memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN;
+       pTxPacket->cbPayloadLen = 0;
+       // send the frame
+       if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet failed..\n");
+       } else {
 //        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n");
-    };
+       };
 
-    return;
+       return;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -295,81 +273,75 @@ PSvSendPSPOLL(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 bool
 PSbSendNullPacket(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-    PSDevice            pDevice = (PSDevice)hDeviceContext;
-    PSTxMgmtPacket      pTxPacket = NULL;
-    PSMgmtObject        pMgmt = pDevice->pMgmt;
-    unsigned int uIdx;
-
-
-    if (pDevice->bLinkPass == false) {
-        return false;
-    }
-    #ifdef TxInSleep
-     if ((pDevice->bEnablePSMode == false) &&
-         (pDevice->fTxDataInSleep == false)){
-        return false;
-    }
+       PSDevice            pDevice = (PSDevice)hDeviceContext;
+       PSTxMgmtPacket      pTxPacket = NULL;
+       PSMgmtObject        pMgmt = pDevice->pMgmt;
+       unsigned int uIdx;
+
+       if (pDevice->bLinkPass == false) {
+               return false;
+       }
+#ifdef TxInSleep
+       if ((pDevice->bEnablePSMode == false) &&
+           (pDevice->fTxDataInSleep == false)) {
+               return false;
+       }
 #else
-    if (pDevice->bEnablePSMode == false) {
-        return false;
-    }
+       if (pDevice->bEnablePSMode == false) {
+               return false;
+       }
 #endif
-    if (pDevice->bEnablePSMode) {
-        for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx ++) {
-            if (pDevice->iTDUsed[uIdx] != 0)
-                return false;
-        }
-    }
-
-    memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN);
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-
-    if (pDevice->bEnablePSMode) {
-
-        pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
-             (
-            WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
-            WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
-            WLAN_SET_FC_PWRMGT(1)
-            ));
-    }
-    else {
-        pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
-             (
-            WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
-            WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
-            WLAN_SET_FC_PWRMGT(0)
-            ));
-    }
-
-    if(pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
-        pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_TODS(1));
-    }
-
-    memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
-    memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-    pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN;
-    pTxPacket->cbPayloadLen = 0;
-    // send the frame
-    if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n");
-        return false;
-    }
-    else {
-
+       if (pDevice->bEnablePSMode) {
+               for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
+                       if (pDevice->iTDUsed[uIdx] != 0)
+                               return false;
+               }
+       }
+
+       memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN);
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+
+       if (pDevice->bEnablePSMode) {
+               pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
+                       (
+                               WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
+                               WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
+                               WLAN_SET_FC_PWRMGT(1)
+));
+       } else {
+               pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
+                       (
+                               WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
+                               WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
+                               WLAN_SET_FC_PWRMGT(0)
+));
+       }
+
+       if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
+               pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_TODS(1));
+       }
+
+       memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
+       memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+       pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN;
+       pTxPacket->cbPayloadLen = 0;
+       // send the frame
+       if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n");
+               return false;
+       } else {
 //            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n");
-    }
-
+       }
 
-    return true ;
+       return true;
 }
 
 /*+
@@ -380,33 +352,31 @@ PSbSendNullPacket(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 bool
 PSbIsNextTBTTWakeUp(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
+       PSDevice         pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject        pMgmt = pDevice->pMgmt;
+       bool bWakeUp = false;
 
-    PSDevice         pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject        pMgmt = pDevice->pMgmt;
-    bool bWakeUp = false;
+       if (pMgmt->wListenInterval >= 2) {
+               if (pMgmt->wCountToWakeUp == 0) {
+                       pMgmt->wCountToWakeUp = pMgmt->wListenInterval;
+               }
 
-    if (pMgmt->wListenInterval >= 2) {
-        if (pMgmt->wCountToWakeUp == 0) {
-            pMgmt->wCountToWakeUp = pMgmt->wListenInterval;
-        }
+               pMgmt->wCountToWakeUp--;
 
-        pMgmt->wCountToWakeUp --;
+               if (pMgmt->wCountToWakeUp == 1) {
+                       // Turn on wake up to listen next beacon
+                       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
+                       bWakeUp = true;
+               }
 
-        if (pMgmt->wCountToWakeUp == 1) {
-            // Turn on wake up to listen next beacon
-            MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
-            bWakeUp = true;
-        }
+       }
 
-    }
-
-    return bWakeUp;
+       return bWakeUp;
 }
-
index 01013b592285e53ca65ae33edf36c23f64f2eba4..337dd659f12f69622addd6d80eff50e38f0d8aaa 100644 (file)
@@ -29,7 +29,6 @@
 #ifndef __POWER_H__
 #define __POWER_H__
 
-
 /*---------------------  Export Definitions -------------------------*/
 #define     C_PWBT                   1000      // micro sec. power up before TBTT
 #define     PS_FAST_INTERVAL         1         // Fast power saving listen interval
 
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Types  ------------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
 // PSDevice pDevice
 
 bool
 PSbConsiderPowerDown(
-    void *hDeviceContext,
-    bool bCheckRxDMA,
-    bool bCheckCountToWakeUp
-    );
+       void *hDeviceContext,
+       bool bCheckRxDMA,
+       bool bCheckCountToWakeUp
+);
 
 void
 PSvDisablePowerSaving(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 void
 PSvEnablePowerSaving(
-    void *hDeviceContext,
-    unsigned short wListenInterval
-    );
+       void *hDeviceContext,
+       unsigned short wListenInterval
+);
 
 void
 PSvSendPSPOLL(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 bool
 PSbSendNullPacket(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 bool
 PSbIsNextTBTTWakeUp(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 #endif //__POWER_H__
index 9856c08b3d77e4a1317b32bbcd18deb0e8687052..343b815c0a9e9a89fd08869a80b3769c9c45a7e7 100644 (file)
 
 void rc4_init(PRC4Ext pRC4, unsigned char *pbyKey, unsigned int cbKey_len)
 {
-    unsigned int ust1, ust2;
-    unsigned int keyindex;
-    unsigned int stateindex;
-    unsigned char *pbyst;
-    unsigned int idx;
+       unsigned int ust1, ust2;
+       unsigned int keyindex;
+       unsigned int stateindex;
+       unsigned char *pbyst;
+       unsigned int idx;
 
-    pbyst = pRC4->abystate;
-    pRC4->ux = 0;
-    pRC4->uy = 0;
-    for (idx = 0; idx < 256; idx++)
-        pbyst[idx] = (unsigned char)idx;
-    keyindex = 0;
-    stateindex = 0;
-    for (idx = 0; idx < 256; idx++) {
-        ust1 = pbyst[idx];
-        stateindex = (stateindex + pbyKey[keyindex] + ust1) & 0xff;
-        ust2 = pbyst[stateindex];
-        pbyst[stateindex] = (unsigned char)ust1;
-        pbyst[idx] = (unsigned char)ust2;
-        if (++keyindex >= cbKey_len)
-            keyindex = 0;
-    }
+       pbyst = pRC4->abystate;
+       pRC4->ux = 0;
+       pRC4->uy = 0;
+       for (idx = 0; idx < 256; idx++)
+               pbyst[idx] = (unsigned char)idx;
+       keyindex = 0;
+       stateindex = 0;
+       for (idx = 0; idx < 256; idx++) {
+               ust1 = pbyst[idx];
+               stateindex = (stateindex + pbyKey[keyindex] + ust1) & 0xff;
+               ust2 = pbyst[stateindex];
+               pbyst[stateindex] = (unsigned char)ust1;
+               pbyst[idx] = (unsigned char)ust2;
+               if (++keyindex >= cbKey_len)
+                       keyindex = 0;
+       }
 }
 
 unsigned int rc4_byte(PRC4Ext pRC4)
 {
-    unsigned int ux;
-    unsigned int uy;
-    unsigned int ustx, usty;
-    unsigned char *pbyst;
+       unsigned int ux;
+       unsigned int uy;
+       unsigned int ustx, usty;
+       unsigned char *pbyst;
 
-    pbyst = pRC4->abystate;
-    ux = (pRC4->ux + 1) & 0xff;
-    ustx = pbyst[ux];
-    uy = (ustx + pRC4->uy) & 0xff;
-    usty = pbyst[uy];
-    pRC4->ux = ux;
-    pRC4->uy = uy;
-    pbyst[uy] = (unsigned char)ustx;
-    pbyst[ux] = (unsigned char)usty;
+       pbyst = pRC4->abystate;
+       ux = (pRC4->ux + 1) & 0xff;
+       ustx = pbyst[ux];
+       uy = (ustx + pRC4->uy) & 0xff;
+       usty = pbyst[uy];
+       pRC4->ux = ux;
+       pRC4->uy = uy;
+       pbyst[uy] = (unsigned char)ustx;
+       pbyst[ux] = (unsigned char)usty;
 
-    return pbyst[(ustx + usty) & 0xff];
+       return pbyst[(ustx + usty) & 0xff];
 }
 
 void rc4_encrypt(PRC4Ext pRC4, unsigned char *pbyDest,
-                     unsigned char *pbySrc, unsigned int cbData_len)
+                unsigned char *pbySrc, unsigned int cbData_len)
 {
-    unsigned int ii;
-    for (ii = 0; ii < cbData_len; ii++)
-        pbyDest[ii] = (unsigned char)(pbySrc[ii] ^ rc4_byte(pRC4));
+       unsigned int ii;
+       for (ii = 0; ii < cbData_len; ii++)
+               pbyDest[ii] = (unsigned char)(pbySrc[ii] ^ rc4_byte(pRC4));
 }
index ad04e351365ef332e34e900fc5f3ca7002ce9b16..74b2eed9bce38d4d07ef5e4a43c5a83f5f10d9ab 100644 (file)
@@ -35,9 +35,9 @@
 /*---------------------  Export Definitions -------------------------*/
 /*---------------------  Export Types  ------------------------------*/
 typedef struct {
-    unsigned int ux;
-    unsigned int uy;
-    unsigned char abystate[256];
+       unsigned int ux;
+       unsigned int uy;
+       unsigned char abystate[256];
 } RC4Ext, *PRC4Ext;
 
 void rc4_init(PRC4Ext pRC4, unsigned char *pbyKey, unsigned int cbKey_len);
index aaa231aaf4e95623e4fef83fe05bec2ad5fd0c6d..6948984a25ab0b6295449e5c6b56503179faa240 100644 (file)
@@ -46,7 +46,6 @@
 #define SWITCH_CHANNEL_DELAY_AL2230 200 //us
 #define AL2230_PWR_IDX_LEN    64
 
-
 #define BY_AL7230_REG_LEN     23 //24bit
 #define CB_AL7230_INIT_SEQ    16
 #define SWITCH_CHANNEL_DELAY_AL7230 200 //us
 
 /*---------------------  Static Variables  --------------------------*/
 
-
-
 const unsigned long dwAL2230InitTable[CB_AL2230_INIT_SEQ] = {
-    0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x01A00200+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x00FFF300+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x0F4DC500+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x0805B600+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x0146C700+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x00068800+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x0403B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x00DBBA00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x00099B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
-    0x0BDFFC00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x00000D00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x00580F00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW
-    };
+       0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x01A00200+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x00FFF300+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x0F4DC500+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x0805B600+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x0146C700+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x00068800+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x0403B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x00DBBA00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x00099B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
+       0x0BDFFC00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x00000D00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x00580F00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW
+};
 
 const unsigned long dwAL2230ChannelTable0[CB_MAX_CHANNEL] = {
-    0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz
-    0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz
-    0x03E79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz
-    0x03E79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz
-    0x03F7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz
-    0x03F7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz
-    0x03E7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz
-    0x03E7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz
-    0x03F7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz
-    0x03F7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
-    0x03E7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
-    0x03E7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
-    0x03F7C000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
-    0x03E7C000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW  // channel = 14, Tf = 2412M
-    };
+       0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz
+       0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz
+       0x03E79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz
+       0x03E79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz
+       0x03F7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz
+       0x03F7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz
+       0x03E7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz
+       0x03E7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz
+       0x03F7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz
+       0x03F7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
+       0x03E7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
+       0x03E7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
+       0x03F7C000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
+       0x03E7C000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW  // channel = 14, Tf = 2412M
+};
 
 const unsigned long dwAL2230ChannelTable1[CB_MAX_CHANNEL] = {
-    0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz
-    0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz
-    0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz
-    0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz
-    0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz
-    0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz
-    0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz
-    0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz
-    0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz
-    0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
-    0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
-    0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
-    0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
-    0x06666100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW  // channel = 14, Tf = 2412M
-    };
+       0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz
+       0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz
+       0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz
+       0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz
+       0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz
+       0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz
+       0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz
+       0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz
+       0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz
+       0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
+       0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
+       0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
+       0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
+       0x06666100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW  // channel = 14, Tf = 2412M
+};
 
 unsigned long dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = {
-    0x04040900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04041900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04042900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04043900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04044900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04045900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04046900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04047900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04048900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04049900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0404A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0404B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0404C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0404D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0404E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0404F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04050900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04051900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04052900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04053900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04054900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04055900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04056900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04057900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04058900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04059900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0405A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0405B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0405C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0405D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0405E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0405F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04060900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04061900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04062900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04063900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04064900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04065900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04066900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04067900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04068900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04069900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0406A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0406B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0406C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0406D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0406E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0406F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04070900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04071900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04072900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04073900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04074900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04075900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04076900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04077900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04078900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x04079900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0407A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0407B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0407C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0407D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0407E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x0407F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW
-    };
+       0x04040900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04041900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04042900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04043900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04044900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04045900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04046900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04047900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04048900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04049900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0404A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0404B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0404C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0404D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0404E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0404F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04050900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04051900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04052900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04053900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04054900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04055900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04056900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04057900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04058900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04059900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0405A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0405B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0405C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0405D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0405E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0405F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04060900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04061900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04062900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04063900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04064900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04065900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04066900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04067900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04068900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04069900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0406A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0406B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0406C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0406D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0406E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0406F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04070900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04071900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04072900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04073900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04074900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04075900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04076900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04077900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04078900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x04079900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0407A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0407B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0407C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0407D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0407E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x0407F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW
+};
 
 //{{ RobertYu:20050104
 // 40MHz reference frequency
 // Need to Pull PLLON(PE3) low when writing channel registers through 3-wire.
 const unsigned long dwAL7230InitTable[CB_AL7230_INIT_SEQ] = {
-    0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel1 // Need modify for 11a
-    0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel1 // Need modify for 11a
-    0x841FF200+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 451FE2
-    0x3FDFA300+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 5FDFA3
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // 11b/g    // Need modify for 11a
-    //0x802B4500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 8D1B45
-    // RoberYu:20050113, Rev0.47 Regsiter Setting Guide
-    0x802B5500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 8D1B55
-    0x56AF3600+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
-    0xCE020700+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 860207
-    0x6EBC0800+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
-    0xE0000A00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: E0600A
-    0x08031B00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // init 0x080B1B00 => 0x080F1B00 for 3 wire control TxGain(D10)
-    //0x00093C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 00143C
-    // RoberYu:20050113, Rev0.47 Regsiter Setting Guide
-    0x000A3C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 00143C
-    0xFFFFFD00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x00000E00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x1ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW  // Need modify for 11a: 12BACF
-    };
+       0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel1 // Need modify for 11a
+       0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel1 // Need modify for 11a
+       0x841FF200+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 451FE2
+       0x3FDFA300+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 5FDFA3
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // 11b/g    // Need modify for 11a
+       //0x802B4500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 8D1B45
+       // RoberYu:20050113, Rev0.47 Regsiter Setting Guide
+       0x802B5500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 8D1B55
+       0x56AF3600+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
+       0xCE020700+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 860207
+       0x6EBC0800+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
+       0xE0000A00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: E0600A
+       0x08031B00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // init 0x080B1B00 => 0x080F1B00 for 3 wire control TxGain(D10)
+       //0x00093C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 00143C
+       // RoberYu:20050113, Rev0.47 Regsiter Setting Guide
+       0x000A3C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 00143C
+       0xFFFFFD00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x00000E00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x1ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW  // Need modify for 11a: 12BACF
+};
 
 const unsigned long dwAL7230InitTableAMode[CB_AL7230_INIT_SEQ] = {
-    0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel184 // Need modify for 11b/g
-    0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel184 // Need modify for 11b/g
-    0x451FE200+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
-    0x5FDFA300+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
-    0x67F78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // 11a    // Need modify for 11b/g
-    0x853F5500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g, RoberYu:20050113
-    0x56AF3600+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
-    0xCE020700+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
-    0x6EBC0800+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
-    0xE0600A00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
-    0x08031B00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // init 0x080B1B00 => 0x080F1B00 for 3 wire control TxGain(D10)
-    0x00147C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
-    0xFFFFFD00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x00000E00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
-    0x12BACF00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW  // Need modify for 11b/g
-    };
-
+       0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel184 // Need modify for 11b/g
+       0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel184 // Need modify for 11b/g
+       0x451FE200+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
+       0x5FDFA300+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
+       0x67F78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // 11a    // Need modify for 11b/g
+       0x853F5500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g, RoberYu:20050113
+       0x56AF3600+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
+       0xCE020700+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
+       0x6EBC0800+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
+       0xE0600A00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
+       0x08031B00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // init 0x080B1B00 => 0x080F1B00 for 3 wire control TxGain(D10)
+       0x00147C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
+       0xFFFFFD00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x00000E00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
+       0x12BACF00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW  // Need modify for 11b/g
+};
 
 const unsigned long dwAL7230ChannelTable0[CB_MAX_CHANNEL] = {
-    0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  1, Tf = 2412MHz
-    0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  2, Tf = 2417MHz
-    0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  3, Tf = 2422MHz
-    0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  4, Tf = 2427MHz
-    0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  5, Tf = 2432MHz
-    0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  6, Tf = 2437MHz
-    0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  7, Tf = 2442MHz
-    0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  8, Tf = 2447MHz //RobertYu: 20050218, update for APNode 0.49
-    0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  9, Tf = 2452MHz //RobertYu: 20050218, update for APNode 0.49
-    0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz //RobertYu: 20050218, update for APNode 0.49
-    0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz //RobertYu: 20050218, update for APNode 0.49
-    0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz //RobertYu: 20050218, update for APNode 0.49
-    0x0037C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz //RobertYu: 20050218, update for APNode 0.49
-    0x0037C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz
-
-    // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196  (Value:15 ~ 22)
-    0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15)
-    0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16)
-    0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17)
-    0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18)
-    0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19)
-    0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20)
-    0x0FF53000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21)
-    0x0FF53000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22)
-
-    // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
-    // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165  (Value 23 ~ 56)
-
-    0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   7, Tf = 5035MHz (23)
-    0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   8, Tf = 5040MHz (24)
-    0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   9, Tf = 5045MHz (25)
-    0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  11, Tf = 5055MHz (26)
-    0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  12, Tf = 5060MHz (27)
-    0x0FF55000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  16, Tf = 5080MHz (28)
-    0x0FF56000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  34, Tf = 5170MHz (29)
-    0x0FF56000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  36, Tf = 5180MHz (30)
-    0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  38, Tf = 5190MHz (31) //RobertYu: 20050218, update for APNode 0.49
-    0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  40, Tf = 5200MHz (32)
-    0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  42, Tf = 5210MHz (33)
-    0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  44, Tf = 5220MHz (34)
-    0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  46, Tf = 5230MHz (35)
-    0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  48, Tf = 5240MHz (36)
-    0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  52, Tf = 5260MHz (37)
-    0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  56, Tf = 5280MHz (38)
-    0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  60, Tf = 5300MHz (39)
-    0x0FF59000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  64, Tf = 5320MHz (40)
-
-    0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41)
-    0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42)
-    0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43)
-    0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44)
-    0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45)
-    0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46)
-    0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47)
-    0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48)
-    0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49)
-    0x0FF5F000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50)
-    0x0FF5F000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51)
-    0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52)
-    0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53)
-    0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54)
-    0x0FF61000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55)
-    0x0FF61000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW  // channel = 165, Tf = 5825MHz (56)
-    };
+       0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  1, Tf = 2412MHz
+       0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  2, Tf = 2417MHz
+       0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  3, Tf = 2422MHz
+       0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  4, Tf = 2427MHz
+       0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  5, Tf = 2432MHz
+       0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  6, Tf = 2437MHz
+       0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  7, Tf = 2442MHz
+       0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  8, Tf = 2447MHz //RobertYu: 20050218, update for APNode 0.49
+       0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  9, Tf = 2452MHz //RobertYu: 20050218, update for APNode 0.49
+       0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz //RobertYu: 20050218, update for APNode 0.49
+       0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz //RobertYu: 20050218, update for APNode 0.49
+       0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz //RobertYu: 20050218, update for APNode 0.49
+       0x0037C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz //RobertYu: 20050218, update for APNode 0.49
+       0x0037C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz
+
+       // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196  (Value:15 ~ 22)
+       0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15)
+       0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16)
+       0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17)
+       0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18)
+       0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19)
+       0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20)
+       0x0FF53000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21)
+       0x0FF53000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22)
+
+       // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
+       // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165  (Value 23 ~ 56)
+
+       0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   7, Tf = 5035MHz (23)
+       0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   8, Tf = 5040MHz (24)
+       0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   9, Tf = 5045MHz (25)
+       0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  11, Tf = 5055MHz (26)
+       0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  12, Tf = 5060MHz (27)
+       0x0FF55000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  16, Tf = 5080MHz (28)
+       0x0FF56000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  34, Tf = 5170MHz (29)
+       0x0FF56000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  36, Tf = 5180MHz (30)
+       0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  38, Tf = 5190MHz (31) //RobertYu: 20050218, update for APNode 0.49
+       0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  40, Tf = 5200MHz (32)
+       0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  42, Tf = 5210MHz (33)
+       0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  44, Tf = 5220MHz (34)
+       0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  46, Tf = 5230MHz (35)
+       0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  48, Tf = 5240MHz (36)
+       0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  52, Tf = 5260MHz (37)
+       0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  56, Tf = 5280MHz (38)
+       0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  60, Tf = 5300MHz (39)
+       0x0FF59000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  64, Tf = 5320MHz (40)
+
+       0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41)
+       0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42)
+       0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43)
+       0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44)
+       0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45)
+       0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46)
+       0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47)
+       0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48)
+       0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49)
+       0x0FF5F000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50)
+       0x0FF5F000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51)
+       0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52)
+       0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53)
+       0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54)
+       0x0FF61000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55)
+       0x0FF61000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW  // channel = 165, Tf = 5825MHz (56)
+};
 
 const unsigned long dwAL7230ChannelTable1[CB_MAX_CHANNEL] = {
-    0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  1, Tf = 2412MHz
-    0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  2, Tf = 2417MHz
-    0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  3, Tf = 2422MHz
-    0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  4, Tf = 2427MHz
-    0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  5, Tf = 2432MHz
-    0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  6, Tf = 2437MHz
-    0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  7, Tf = 2442MHz
-    0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  8, Tf = 2447MHz
-    0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  9, Tf = 2452MHz
-    0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
-    0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
-    0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
-    0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
-    0x06666100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz
-
-    // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196  (Value:15 ~ 22)
-    0x1D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15)
-    0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16)
-    0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17)
-    0x08000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18)
-    0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19)
-    0x0D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20)
-    0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21)
-    0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22)
-
-    // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
-    // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165  (Value 23 ~ 56)
-    0x1D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   7, Tf = 5035MHz (23)
-    0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   8, Tf = 5040MHz (24)
-    0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   9, Tf = 5045MHz (25)
-    0x08000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  11, Tf = 5055MHz (26)
-    0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  12, Tf = 5060MHz (27)
-    0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  16, Tf = 5080MHz (28)
-    0x05555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  34, Tf = 5170MHz (29)
-    0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  36, Tf = 5180MHz (30)
-    0x10000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  38, Tf = 5190MHz (31)
-    0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  40, Tf = 5200MHz (32)
-    0x1AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  42, Tf = 5210MHz (33)
-    0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  44, Tf = 5220MHz (34)
-    0x05555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  46, Tf = 5230MHz (35)
-    0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  48, Tf = 5240MHz (36)
-    0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  52, Tf = 5260MHz (37)
-    0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  56, Tf = 5280MHz (38)
-    0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  60, Tf = 5300MHz (39)
-    0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  64, Tf = 5320MHz (40)
-    0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41)
-    0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42)
-    0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43)
-    0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44)
-    0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45)
-    0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46)
-    0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47)
-    0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48)
-    0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49)
-    0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50)
-    0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51)
-    0x18000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52)
-    0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53)
-    0x0D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54)
-    0x18000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55)
-    0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW  // channel = 165, Tf = 5825MHz (56)
-    };
+       0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  1, Tf = 2412MHz
+       0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  2, Tf = 2417MHz
+       0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  3, Tf = 2422MHz
+       0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  4, Tf = 2427MHz
+       0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  5, Tf = 2432MHz
+       0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  6, Tf = 2437MHz
+       0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  7, Tf = 2442MHz
+       0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  8, Tf = 2447MHz
+       0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  9, Tf = 2452MHz
+       0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
+       0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
+       0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
+       0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
+       0x06666100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz
+
+       // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196  (Value:15 ~ 22)
+       0x1D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15)
+       0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16)
+       0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17)
+       0x08000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18)
+       0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19)
+       0x0D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20)
+       0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21)
+       0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22)
+
+       // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
+       // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165  (Value 23 ~ 56)
+       0x1D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   7, Tf = 5035MHz (23)
+       0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   8, Tf = 5040MHz (24)
+       0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   9, Tf = 5045MHz (25)
+       0x08000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  11, Tf = 5055MHz (26)
+       0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  12, Tf = 5060MHz (27)
+       0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  16, Tf = 5080MHz (28)
+       0x05555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  34, Tf = 5170MHz (29)
+       0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  36, Tf = 5180MHz (30)
+       0x10000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  38, Tf = 5190MHz (31)
+       0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  40, Tf = 5200MHz (32)
+       0x1AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  42, Tf = 5210MHz (33)
+       0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  44, Tf = 5220MHz (34)
+       0x05555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  46, Tf = 5230MHz (35)
+       0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  48, Tf = 5240MHz (36)
+       0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  52, Tf = 5260MHz (37)
+       0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  56, Tf = 5280MHz (38)
+       0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  60, Tf = 5300MHz (39)
+       0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  64, Tf = 5320MHz (40)
+       0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41)
+       0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42)
+       0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43)
+       0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44)
+       0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45)
+       0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46)
+       0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47)
+       0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48)
+       0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49)
+       0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50)
+       0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51)
+       0x18000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52)
+       0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53)
+       0x0D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54)
+       0x18000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55)
+       0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW  // channel = 165, Tf = 5825MHz (56)
+};
 
 const unsigned long dwAL7230ChannelTable2[CB_MAX_CHANNEL] = {
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  1, Tf = 2412MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  2, Tf = 2417MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  3, Tf = 2422MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  4, Tf = 2427MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  5, Tf = 2432MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  6, Tf = 2437MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  7, Tf = 2442MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  8, Tf = 2447MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  9, Tf = 2452MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
-    0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz
-
-    // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196  (Value:15 ~ 22)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15)
-    0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21)
-    0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22)
-
-    // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
-    // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165  (Value 23 ~ 56)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   7, Tf = 5035MHz (23)
-    0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   8, Tf = 5040MHz (24)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   9, Tf = 5045MHz (25)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  11, Tf = 5055MHz (26)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  12, Tf = 5060MHz (27)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  16, Tf = 5080MHz (28)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  34, Tf = 5170MHz (29)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  36, Tf = 5180MHz (30)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  38, Tf = 5190MHz (31)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  40, Tf = 5200MHz (32)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  42, Tf = 5210MHz (33)
-    0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  44, Tf = 5220MHz (34)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  46, Tf = 5230MHz (35)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  48, Tf = 5240MHz (36)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  52, Tf = 5260MHz (37)
-    0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  56, Tf = 5280MHz (38)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  60, Tf = 5300MHz (39)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  64, Tf = 5320MHz (40)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41)
-    0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44)
-    0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47)
-    0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50)
-    0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55)
-    0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW  // channel = 165, Tf = 5825MHz (56)
-    };
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  1, Tf = 2412MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  2, Tf = 2417MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  3, Tf = 2422MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  4, Tf = 2427MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  5, Tf = 2432MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  6, Tf = 2437MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  7, Tf = 2442MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  8, Tf = 2447MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  9, Tf = 2452MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
+       0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz
+
+       // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196  (Value:15 ~ 22)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15)
+       0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21)
+       0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22)
+
+       // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
+       // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165  (Value 23 ~ 56)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   7, Tf = 5035MHz (23)
+       0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   8, Tf = 5040MHz (24)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =   9, Tf = 5045MHz (25)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  11, Tf = 5055MHz (26)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  12, Tf = 5060MHz (27)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  16, Tf = 5080MHz (28)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  34, Tf = 5170MHz (29)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  36, Tf = 5180MHz (30)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  38, Tf = 5190MHz (31)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  40, Tf = 5200MHz (32)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  42, Tf = 5210MHz (33)
+       0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  44, Tf = 5220MHz (34)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  46, Tf = 5230MHz (35)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  48, Tf = 5240MHz (36)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  52, Tf = 5260MHz (37)
+       0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  56, Tf = 5280MHz (38)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  60, Tf = 5300MHz (39)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel =  64, Tf = 5320MHz (40)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41)
+       0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44)
+       0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47)
+       0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50)
+       0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55)
+       0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW  // channel = 165, Tf = 5825MHz (56)
+};
 //}} RobertYu
 
-
-
-
 /*---------------------  Static Functions  --------------------------*/
 
-
-
-
 /*
  * Description: AIROHA IFRF chip init function
  *
@@ -438,72 +428,72 @@ const unsigned long dwAL7230ChannelTable2[CB_MAX_CHANNEL] = {
  * Return Value: true if succeeded; false if failed.
  *
  */
-bool s_bAL7230Init (unsigned long dwIoBase)
+bool s_bAL7230Init(unsigned long dwIoBase)
 {
-    int     ii;
-    bool bResult;
+       int     ii;
+       bool bResult;
 
-    bResult = true;
+       bResult = true;
 
-    //3-wire control for normal mode
-    VNSvOutPortB(dwIoBase + MAC_REG_SOFTPWRCTL, 0);
+       //3-wire control for normal mode
+       VNSvOutPortB(dwIoBase + MAC_REG_SOFTPWRCTL, 0);
 
-    MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPECTI  |
-                                                     SOFTPWRCTL_TXPEINV));
-    BBvPowerSaveModeOFF(dwIoBase); //RobertYu:20050106, have DC value for Calibration
+       MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPECTI  |
+                                                        SOFTPWRCTL_TXPEINV));
+       BBvPowerSaveModeOFF(dwIoBase); //RobertYu:20050106, have DC value for Calibration
 
-    for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++)
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[ii]);
+       for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++)
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[ii]);
 
-    // PLL On
-    MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
+       // PLL On
+       MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
 
-    //Calibration
-    MACvTimer0MicroSDelay(dwIoBase, 150);//150us
-    bResult &= IFRFbWriteEmbedded(dwIoBase, (0x9ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW)); //TXDCOC:active, RCK:disable
-    MACvTimer0MicroSDelay(dwIoBase, 30);//30us
-    bResult &= IFRFbWriteEmbedded(dwIoBase, (0x3ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW)); //TXDCOC:disable, RCK:active
-    MACvTimer0MicroSDelay(dwIoBase, 30);//30us
-    bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[CB_AL7230_INIT_SEQ-1]); //TXDCOC:disable, RCK:disable
+       //Calibration
+       MACvTimer0MicroSDelay(dwIoBase, 150);//150us
+       bResult &= IFRFbWriteEmbedded(dwIoBase, (0x9ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW)); //TXDCOC:active, RCK:disable
+       MACvTimer0MicroSDelay(dwIoBase, 30);//30us
+       bResult &= IFRFbWriteEmbedded(dwIoBase, (0x3ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW)); //TXDCOC:disable, RCK:active
+       MACvTimer0MicroSDelay(dwIoBase, 30);//30us
+       bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[CB_AL7230_INIT_SEQ-1]); //TXDCOC:disable, RCK:disable
 
-    MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3    |
-                                                     SOFTPWRCTL_SWPE2    |
-                                                     SOFTPWRCTL_SWPECTI  |
-                                                     SOFTPWRCTL_TXPEINV));
+       MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3    |
+                                                        SOFTPWRCTL_SWPE2    |
+                                                        SOFTPWRCTL_SWPECTI  |
+                                                        SOFTPWRCTL_TXPEINV));
 
-    BBvPowerSaveModeON(dwIoBase); // RobertYu:20050106
+       BBvPowerSaveModeON(dwIoBase); // RobertYu:20050106
 
-    // PE1: TX_ON, PE2: RX_ON, PE3: PLLON
-    //3-wire control for power saving mode
-    VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000
+       // PE1: TX_ON, PE2: RX_ON, PE3: PLLON
+       //3-wire control for power saving mode
+       VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000
 
-    return bResult;
+       return bResult;
 }
 
 // Need to Pull PLLON low when writing channel registers through 3-wire interface
-bool s_bAL7230SelectChannel (unsigned long dwIoBase, unsigned char byChannel)
+bool s_bAL7230SelectChannel(unsigned long dwIoBase, unsigned char byChannel)
 {
-    bool bResult;
+       bool bResult;
 
-    bResult = true;
+       bResult = true;
 
-    // PLLON Off
-    MACvWordRegBitsOff(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
+       // PLLON Off
+       MACvWordRegBitsOff(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
 
-    bResult &= IFRFbWriteEmbedded (dwIoBase, dwAL7230ChannelTable0[byChannel-1]); //Reg0
-    bResult &= IFRFbWriteEmbedded (dwIoBase, dwAL7230ChannelTable1[byChannel-1]); //Reg1
-    bResult &= IFRFbWriteEmbedded (dwIoBase, dwAL7230ChannelTable2[byChannel-1]); //Reg4
+       bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230ChannelTable0[byChannel - 1]); //Reg0
+       bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230ChannelTable1[byChannel - 1]); //Reg1
+       bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230ChannelTable2[byChannel - 1]); //Reg4
 
-    // PLLOn On
-    MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
+       // PLLOn On
+       MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
 
-    // Set Channel[7] = 0 to tell H/W channel is changing now.
-    VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel & 0x7F));
-    MACvTimer0MicroSDelay(dwIoBase, SWITCH_CHANNEL_DELAY_AL7230);
-    // Set Channel[7] = 1 to tell H/W channel change is done.
-    VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel | 0x80));
+       // Set Channel[7] = 0 to tell H/W channel is changing now.
+       VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel & 0x7F));
+       MACvTimer0MicroSDelay(dwIoBase, SWITCH_CHANNEL_DELAY_AL7230);
+       // Set Channel[7] = 1 to tell H/W channel change is done.
+       VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel | 0x80));
 
-    return bResult;
+       return bResult;
 }
 
 /*
@@ -520,7 +510,6 @@ bool s_bAL7230SelectChannel (unsigned long dwIoBase, unsigned char byChannel)
  *
  */
 
-
 //{{ RobertYu: 20041210
 /*
  * Description: UW2452 IFRF chip init function
@@ -535,8 +524,6 @@ bool s_bAL7230SelectChannel (unsigned long dwIoBase, unsigned char byChannel)
  *
  */
 
-
-
 //}} RobertYu
 ////////////////////////////////////////////////////////////////////////////////
 
@@ -567,8 +554,6 @@ bool s_bAL7230SelectChannel (unsigned long dwIoBase, unsigned char byChannel)
  *
  */
 
-
-
 /*---------------------  Export Variables  --------------------------*/
 
 /*---------------------  Export Functions  --------------------------*/
@@ -586,29 +571,27 @@ bool s_bAL7230SelectChannel (unsigned long dwIoBase, unsigned char byChannel)
  * Return Value: true if succeeded; false if failed.
  *
  */
-bool IFRFbWriteEmbedded (unsigned long dwIoBase, unsigned long dwData)
+bool IFRFbWriteEmbedded(unsigned long dwIoBase, unsigned long dwData)
 {
-    unsigned short ww;
-    unsigned long dwValue;
+       unsigned short ww;
+       unsigned long dwValue;
 
-    VNSvOutPortD(dwIoBase + MAC_REG_IFREGCTL, dwData);
+       VNSvOutPortD(dwIoBase + MAC_REG_IFREGCTL, dwData);
 
-    // W_MAX_TIMEOUT is the timeout period
-    for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
-        VNSvInPortD(dwIoBase + MAC_REG_IFREGCTL, &dwValue);
-        if (dwValue & IFREGCTL_DONE)
-            break;
-    }
+       // W_MAX_TIMEOUT is the timeout period
+       for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
+               VNSvInPortD(dwIoBase + MAC_REG_IFREGCTL, &dwValue);
+               if (dwValue & IFREGCTL_DONE)
+                       break;
+       }
 
-    if (ww == W_MAX_TIMEOUT) {
+       if (ww == W_MAX_TIMEOUT) {
 //        DBG_PORT80_ALWAYS(0x32);
-        return false;
-    }
-    return true;
+               return false;
+       }
+       return true;
 }
 
-
-
 /*
  * Description: RFMD RF2959 IFRF chip init function
  *
@@ -648,72 +631,69 @@ bool IFRFbWriteEmbedded (unsigned long dwIoBase, unsigned long dwData)
  * Return Value: true if succeeded; false if failed.
  *
  */
-bool RFbAL2230Init (unsigned long dwIoBase)
+bool RFbAL2230Init(unsigned long dwIoBase)
 {
-    int     ii;
-    bool bResult;
+       int     ii;
+       bool bResult;
 
-    bResult = true;
+       bResult = true;
 
-    //3-wire control for normal mode
-    VNSvOutPortB(dwIoBase + MAC_REG_SOFTPWRCTL, 0);
+       //3-wire control for normal mode
+       VNSvOutPortB(dwIoBase + MAC_REG_SOFTPWRCTL, 0);
 
-    MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPECTI  |
-                                                     SOFTPWRCTL_TXPEINV));
+       MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPECTI  |
+                                                        SOFTPWRCTL_TXPEINV));
 //2008-8-21 chester <add>
-    // PLL  Off
-
-    MACvWordRegBitsOff(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
-
+       // PLL  Off
 
+       MACvWordRegBitsOff(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
 
-    //patch abnormal AL2230 frequency output
+       //patch abnormal AL2230 frequency output
 //2008-8-21 chester <add>
-    IFRFbWriteEmbedded(dwIoBase, (0x07168700+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
+       IFRFbWriteEmbedded(dwIoBase, (0x07168700+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
 
-
-    for (ii = 0; ii < CB_AL2230_INIT_SEQ; ii++)
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL2230InitTable[ii]);
+       for (ii = 0; ii < CB_AL2230_INIT_SEQ; ii++)
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL2230InitTable[ii]);
 //2008-8-21 chester <add>
-MACvTimer0MicroSDelay(dwIoBase, 30); //delay 30 us
+       MACvTimer0MicroSDelay(dwIoBase, 30); //delay 30 us
 
-    // PLL On
-    MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
+       // PLL On
+       MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
 
-    MACvTimer0MicroSDelay(dwIoBase, 150);//150us
-    bResult &= IFRFbWriteEmbedded(dwIoBase, (0x00d80f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
-    MACvTimer0MicroSDelay(dwIoBase, 30);//30us
-    bResult &= IFRFbWriteEmbedded(dwIoBase, (0x00780f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
-    MACvTimer0MicroSDelay(dwIoBase, 30);//30us
-    bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL2230InitTable[CB_AL2230_INIT_SEQ-1]);
+       MACvTimer0MicroSDelay(dwIoBase, 150);//150us
+       bResult &= IFRFbWriteEmbedded(dwIoBase, (0x00d80f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
+       MACvTimer0MicroSDelay(dwIoBase, 30);//30us
+       bResult &= IFRFbWriteEmbedded(dwIoBase, (0x00780f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
+       MACvTimer0MicroSDelay(dwIoBase, 30);//30us
+       bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL2230InitTable[CB_AL2230_INIT_SEQ-1]);
 
-    MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3    |
-                                                     SOFTPWRCTL_SWPE2    |
-                                                     SOFTPWRCTL_SWPECTI  |
-                                                     SOFTPWRCTL_TXPEINV));
+       MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3    |
+                                                        SOFTPWRCTL_SWPE2    |
+                                                        SOFTPWRCTL_SWPECTI  |
+                                                        SOFTPWRCTL_TXPEINV));
 
-    //3-wire control for power saving mode
-    VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000
+       //3-wire control for power saving mode
+       VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000
 
-    return bResult;
+       return bResult;
 }
 
-bool RFbAL2230SelectChannel (unsigned long dwIoBase, unsigned char byChannel)
+bool RFbAL2230SelectChannel(unsigned long dwIoBase, unsigned char byChannel)
 {
-    bool bResult;
+       bool bResult;
 
-    bResult = true;
+       bResult = true;
 
-    bResult &= IFRFbWriteEmbedded (dwIoBase, dwAL2230ChannelTable0[byChannel-1]);
-    bResult &= IFRFbWriteEmbedded (dwIoBase, dwAL2230ChannelTable1[byChannel-1]);
+       bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL2230ChannelTable0[byChannel - 1]);
+       bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL2230ChannelTable1[byChannel - 1]);
 
-    // Set Channel[7] = 0 to tell H/W channel is changing now.
-    VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel & 0x7F));
-    MACvTimer0MicroSDelay(dwIoBase, SWITCH_CHANNEL_DELAY_AL2230);
-    // Set Channel[7] = 1 to tell H/W channel change is done.
-    VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel | 0x80));
+       // Set Channel[7] = 0 to tell H/W channel is changing now.
+       VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel & 0x7F));
+       MACvTimer0MicroSDelay(dwIoBase, SWITCH_CHANNEL_DELAY_AL2230);
+       // Set Channel[7] = 1 to tell H/W channel change is done.
+       VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel | 0x80));
 
-    return bResult;
+       return bResult;
 }
 
 /*
@@ -729,7 +709,6 @@ bool RFbAL2230SelectChannel (unsigned long dwIoBase, unsigned char byChannel)
  *
  */
 
-
 /*
  * Description: Select channel with UW2451 chip
  *
@@ -771,29 +750,29 @@ bool RFbAL2230SelectChannel (unsigned long dwIoBase, unsigned char byChannel)
  * Return Value: true if succeeded; false if failed.
  *
  */
-bool RFbInit (
-    PSDevice  pDevice
-    )
+bool RFbInit(
+       PSDevice  pDevice
+)
 {
-bool bResult = true;
-    switch (pDevice->byRFType) {
-        case RF_AIROHA :
-        case RF_AL2230S:
-            pDevice->byMaxPwrLevel = AL2230_PWR_IDX_LEN;
-            bResult = RFbAL2230Init(pDevice->PortOffset);
-            break;
-        case RF_AIROHA7230 :
-            pDevice->byMaxPwrLevel = AL7230_PWR_IDX_LEN;
-            bResult = s_bAL7230Init(pDevice->PortOffset);
-            break;
-        case RF_NOTHING :
-            bResult = true;
-            break;
-        default :
-            bResult = false;
-            break;
-    }
-    return bResult;
+       bool bResult = true;
+       switch (pDevice->byRFType) {
+       case RF_AIROHA:
+       case RF_AL2230S:
+               pDevice->byMaxPwrLevel = AL2230_PWR_IDX_LEN;
+               bResult = RFbAL2230Init(pDevice->PortOffset);
+               break;
+       case RF_AIROHA7230:
+               pDevice->byMaxPwrLevel = AL7230_PWR_IDX_LEN;
+               bResult = s_bAL7230Init(pDevice->PortOffset);
+               break;
+       case RF_NOTHING:
+               bResult = true;
+               break;
+       default:
+               bResult = false;
+               break;
+       }
+       return bResult;
 }
 
 /*
@@ -809,21 +788,21 @@ bool bResult = true;
  * Return Value: true if succeeded; false if failed.
  *
  */
-bool RFbShutDown (
-    PSDevice  pDevice
-    )
+bool RFbShutDown(
+       PSDevice  pDevice
+)
 {
-bool bResult = true;
-
-    switch (pDevice->byRFType) {
-        case RF_AIROHA7230 :
-            bResult = IFRFbWriteEmbedded (pDevice->PortOffset, 0x1ABAEF00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW);
-            break;
-        default :
-            bResult = true;
-            break;
-    }
-    return bResult;
+       bool bResult = true;
+
+       switch (pDevice->byRFType) {
+       case RF_AIROHA7230:
+               bResult = IFRFbWriteEmbedded(pDevice->PortOffset, 0x1ABAEF00 + (BY_AL7230_REG_LEN << 3) + IFREGCTL_REGW);
+               break;
+       default:
+               bResult = true;
+               break;
+       }
+       return bResult;
 }
 
 /*
@@ -839,28 +818,27 @@ bool bResult = true;
  * Return Value: true if succeeded; false if failed.
  *
  */
-bool RFbSelectChannel (unsigned long dwIoBase, unsigned char byRFType, unsigned char byChannel)
+bool RFbSelectChannel(unsigned long dwIoBase, unsigned char byRFType, unsigned char byChannel)
 {
-bool bResult = true;
-    switch (byRFType) {
-
-        case RF_AIROHA :
-        case RF_AL2230S:
-            bResult = RFbAL2230SelectChannel(dwIoBase, byChannel);
-            break;
-        //{{ RobertYu: 20050104
-        case RF_AIROHA7230 :
-            bResult = s_bAL7230SelectChannel(dwIoBase, byChannel);
-            break;
-        //}} RobertYu
-        case RF_NOTHING :
-            bResult = true;
-            break;
-        default:
-            bResult = false;
-            break;
-    }
-    return bResult;
+       bool bResult = true;
+       switch (byRFType) {
+       case RF_AIROHA:
+       case RF_AL2230S:
+               bResult = RFbAL2230SelectChannel(dwIoBase, byChannel);
+               break;
+               //{{ RobertYu: 20050104
+       case RF_AIROHA7230:
+               bResult = s_bAL7230SelectChannel(dwIoBase, byChannel);
+               break;
+               //}} RobertYu
+       case RF_NOTHING:
+               bResult = true;
+               break;
+       default:
+               bResult = false;
+               break;
+       }
+       return bResult;
 }
 
 /*
@@ -875,76 +853,73 @@ bool bResult = true;
  * Return Value: None.
  *
  */
-bool RFvWriteWakeProgSyn (unsigned long dwIoBase, unsigned char byRFType, unsigned int uChannel)
+bool RFvWriteWakeProgSyn(unsigned long dwIoBase, unsigned char byRFType, unsigned int uChannel)
 {
-    int   ii;
-    unsigned char byInitCount = 0;
-    unsigned char bySleepCount = 0;
-
-    VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, 0);
-    switch (byRFType) {
-        case RF_AIROHA:
-        case RF_AL2230S:
-
-            if (uChannel > CB_MAX_CHANNEL_24G)
-                return false;
-
-            byInitCount = CB_AL2230_INIT_SEQ + 2; // Init Reg + Channel Reg (2)
-            bySleepCount = 0;
-            if (byInitCount > (MISCFIFO_SYNDATASIZE - bySleepCount)) {
-                return false;
-            }
-
-            for (ii = 0; ii < CB_AL2230_INIT_SEQ; ii++ ) {
-                MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL2230InitTable[ii]);
-            }
-            MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL2230ChannelTable0[uChannel-1]);
-            ii ++;
-            MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL2230ChannelTable1[uChannel-1]);
-            break;
-
-        //{{ RobertYu: 20050104
-        // Need to check, PLLON need to be low for channel setting
-        case RF_AIROHA7230:
-            byInitCount = CB_AL7230_INIT_SEQ + 3; // Init Reg + Channel Reg (3)
-            bySleepCount = 0;
-            if (byInitCount > (MISCFIFO_SYNDATASIZE - bySleepCount)) {
-                return false;
-            }
-
-            if (uChannel <= CB_MAX_CHANNEL_24G)
-            {
-                for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++ ) {
-                    MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230InitTable[ii]);
-                }
-            }
-            else
-            {
-                for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++ ) {
-                    MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230InitTableAMode[ii]);
-                }
-            }
-
-            MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230ChannelTable0[uChannel-1]);
-            ii ++;
-            MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230ChannelTable1[uChannel-1]);
-            ii ++;
-            MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230ChannelTable2[uChannel-1]);
-            break;
-        //}} RobertYu
-
-        case RF_NOTHING :
-            return true;
-            break;
-
-        default:
-            return false;
-            break;
-    }
-
-    MACvSetMISCFifo(dwIoBase, MISCFIFO_SYNINFO_IDX, (unsigned long )MAKEWORD(bySleepCount, byInitCount));
-
-    return true;
+       int   ii;
+       unsigned char byInitCount = 0;
+       unsigned char bySleepCount = 0;
+
+       VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, 0);
+       switch (byRFType) {
+       case RF_AIROHA:
+       case RF_AL2230S:
+
+               if (uChannel > CB_MAX_CHANNEL_24G)
+                       return false;
+
+               byInitCount = CB_AL2230_INIT_SEQ + 2; // Init Reg + Channel Reg (2)
+               bySleepCount = 0;
+               if (byInitCount > (MISCFIFO_SYNDATASIZE - bySleepCount)) {
+                       return false;
+               }
+
+               for (ii = 0; ii < CB_AL2230_INIT_SEQ; ii++) {
+                       MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL2230InitTable[ii]);
+               }
+               MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL2230ChannelTable0[uChannel-1]);
+               ii++;
+               MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL2230ChannelTable1[uChannel-1]);
+               break;
+
+               //{{ RobertYu: 20050104
+               // Need to check, PLLON need to be low for channel setting
+       case RF_AIROHA7230:
+               byInitCount = CB_AL7230_INIT_SEQ + 3; // Init Reg + Channel Reg (3)
+               bySleepCount = 0;
+               if (byInitCount > (MISCFIFO_SYNDATASIZE - bySleepCount)) {
+                       return false;
+               }
+
+               if (uChannel <= CB_MAX_CHANNEL_24G) {
+                       for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++) {
+                               MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230InitTable[ii]);
+                       }
+               } else {
+                       for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++) {
+                               MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230InitTableAMode[ii]);
+                       }
+               }
+
+               MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230ChannelTable0[uChannel-1]);
+               ii++;
+               MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230ChannelTable1[uChannel-1]);
+               ii++;
+               MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230ChannelTable2[uChannel-1]);
+               break;
+               //}} RobertYu
+
+       case RF_NOTHING:
+               return true;
+               break;
+
+       default:
+               return false;
+               break;
+       }
+
+       MACvSetMISCFifo(dwIoBase, MISCFIFO_SYNINFO_IDX, (unsigned long)MAKEWORD(bySleepCount, byInitCount));
+
+       return true;
 }
 
 /*
@@ -960,87 +935,81 @@ bool RFvWriteWakeProgSyn (unsigned long dwIoBase, unsigned char byRFType, unsign
  * Return Value: true if succeeded; false if failed.
  *
  */
-bool RFbSetPower (
-    PSDevice  pDevice,
-    unsigned int uRATE,
-    unsigned int uCH
-    )
+bool RFbSetPower(
+       PSDevice  pDevice,
+       unsigned int uRATE,
+       unsigned int uCH
+)
 {
-bool bResult = true;
-unsigned char byPwr = 0;
-unsigned char byDec = 0;
-unsigned char byPwrdBm = 0;
-
-    if (pDevice->dwDiagRefCount != 0) {
-        return true;
-    }
-    if ((uCH < 1) || (uCH > CB_MAX_CHANNEL)) {
-        return false;
-    }
-
-    switch (uRATE) {
-    case RATE_1M:
-    case RATE_2M:
-    case RATE_5M:
-    case RATE_11M:
-        byPwr = pDevice->abyCCKPwrTbl[uCH];
-        byPwrdBm = pDevice->abyCCKDefaultPwr[uCH];
+       bool bResult = true;
+       unsigned char byPwr = 0;
+       unsigned char byDec = 0;
+       unsigned char byPwrdBm = 0;
+
+       if (pDevice->dwDiagRefCount != 0) {
+               return true;
+       }
+       if ((uCH < 1) || (uCH > CB_MAX_CHANNEL)) {
+               return false;
+       }
+
+       switch (uRATE) {
+       case RATE_1M:
+       case RATE_2M:
+       case RATE_5M:
+       case RATE_11M:
+               byPwr = pDevice->abyCCKPwrTbl[uCH];
+               byPwrdBm = pDevice->abyCCKDefaultPwr[uCH];
 //PLICE_DEBUG->
-       //byPwr+=5;
+               //byPwr+=5;
 //PLICE_DEBUG <-
-
-//printk("Rate <11:byPwr is %d\n",byPwr);
                break;
-    case RATE_6M:
-    case RATE_9M:
-    case RATE_18M:
-        byPwr = pDevice->abyOFDMPwrTbl[uCH];
-        if (pDevice->byRFType == RF_UW2452) {
-            byDec = byPwr + 14;
-        } else {
-            byDec = byPwr + 10;
-        }
-        if (byDec >= pDevice->byMaxPwrLevel) {
-            byDec = pDevice->byMaxPwrLevel-1;
-        }
-        if (pDevice->byRFType == RF_UW2452) {
-            byPwrdBm = byDec - byPwr;
-            byPwrdBm /= 3;
-        } else {
-            byPwrdBm = byDec - byPwr;
-            byPwrdBm >>= 1;
-        }
-        byPwrdBm += pDevice->abyOFDMDefaultPwr[uCH];
-        byPwr = byDec;
+       case RATE_6M:
+       case RATE_9M:
+       case RATE_18M:
+               byPwr = pDevice->abyOFDMPwrTbl[uCH];
+               if (pDevice->byRFType == RF_UW2452) {
+                       byDec = byPwr + 14;
+               } else {
+                       byDec = byPwr + 10;
+               }
+               if (byDec >= pDevice->byMaxPwrLevel) {
+                       byDec = pDevice->byMaxPwrLevel-1;
+               }
+               if (pDevice->byRFType == RF_UW2452) {
+                       byPwrdBm = byDec - byPwr;
+                       byPwrdBm /= 3;
+               } else {
+                       byPwrdBm = byDec - byPwr;
+                       byPwrdBm >>= 1;
+               }
+               byPwrdBm += pDevice->abyOFDMDefaultPwr[uCH];
+               byPwr = byDec;
 //PLICE_DEBUG->
-       //byPwr+=5;
+               //byPwr+=5;
 //PLICE_DEBUG<-
-
-//printk("Rate <24:byPwr is %d\n",byPwr);
                break;
-    case RATE_24M:
-    case RATE_36M:
-    case RATE_48M:
-    case RATE_54M:
-        byPwr = pDevice->abyOFDMPwrTbl[uCH];
-        byPwrdBm = pDevice->abyOFDMDefaultPwr[uCH];
+       case RATE_24M:
+       case RATE_36M:
+       case RATE_48M:
+       case RATE_54M:
+               byPwr = pDevice->abyOFDMPwrTbl[uCH];
+               byPwrdBm = pDevice->abyOFDMDefaultPwr[uCH];
 //PLICE_DEBUG->
-       //byPwr+=5;
+               //byPwr+=5;
 //PLICE_DEBUG<-
-//printk("Rate < 54:byPwr is %d\n",byPwr);
                break;
-    }
-
-//    if (pDevice->byLocalID <= REV_ID_VT3253_B1) {
-    if (pDevice->byCurPwr == byPwr) {
-        return true;
-    }
-    bResult = RFbRawSetPower(pDevice, byPwr, uRATE);
-//    }
-    if (bResult == true) {
-       pDevice->byCurPwr = byPwr;
-    }
-    return bResult;
+       }
+
+       if (pDevice->byCurPwr == byPwr) {
+               return true;
+       }
+
+       bResult = RFbRawSetPower(pDevice, byPwr, uRATE);
+       if (bResult == true) {
+               pDevice->byCurPwr = byPwr;
+       }
+       return bResult;
 }
 
 /*
@@ -1057,55 +1026,52 @@ unsigned char byPwrdBm = 0;
  *
  */
 
-bool RFbRawSetPower (
-    PSDevice  pDevice,
-    unsigned char byPwr,
-    unsigned int uRATE
-    )
+bool RFbRawSetPower(
+       PSDevice  pDevice,
+       unsigned char byPwr,
+       unsigned int uRATE
+)
 {
-bool bResult = true;
-unsigned long dwMax7230Pwr = 0;
-
-    if (byPwr >=  pDevice->byMaxPwrLevel) {
-        return (false);
-    }
-    switch (pDevice->byRFType) {
-
-        case RF_AIROHA :
-            bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, dwAL2230PowerTable[byPwr]);
-            if (uRATE <= RATE_11M) {
-                bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x0001B400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
-            } else {
-                bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
-            }
-            break;
-
-
-        case RF_AL2230S :
-            bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, dwAL2230PowerTable[byPwr]);
-            if (uRATE <= RATE_11M) {
-                bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x040C1400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
-                bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x00299B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
-            }else {
-                bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
-                bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x00099B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
-            }
-
-            break;
-
-        case RF_AIROHA7230:
-            //  0x080F1B00 for 3 wire control TxGain(D10) and 0x31 as TX Gain value
-            dwMax7230Pwr = 0x080C0B00 | ( (byPwr) << 12 ) |
-                           (BY_AL7230_REG_LEN << 3 )  | IFREGCTL_REGW;
-
-            bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, dwMax7230Pwr);
-            break;
-
-
-        default :
-            break;
-    }
-    return bResult;
+       bool bResult = true;
+       unsigned long dwMax7230Pwr = 0;
+
+       if (byPwr >=  pDevice->byMaxPwrLevel) {
+               return false;
+       }
+       switch (pDevice->byRFType) {
+       case RF_AIROHA:
+               bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, dwAL2230PowerTable[byPwr]);
+               if (uRATE <= RATE_11M) {
+                       bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x0001B400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
+               } else {
+                       bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
+               }
+               break;
+
+       case RF_AL2230S:
+               bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, dwAL2230PowerTable[byPwr]);
+               if (uRATE <= RATE_11M) {
+                       bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x040C1400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
+                       bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x00299B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
+               } else {
+                       bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
+                       bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x00099B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
+               }
+
+               break;
+
+       case RF_AIROHA7230:
+               //  0x080F1B00 for 3 wire control TxGain(D10) and 0x31 as TX Gain value
+               dwMax7230Pwr = 0x080C0B00 | ((byPwr) << 12) |
+                       (BY_AL7230_REG_LEN << 3)  | IFREGCTL_REGW;
+
+               bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, dwMax7230Pwr);
+               break;
+
+       default:
+               break;
+       }
+       return bResult;
 }
 
 /*+
@@ -1122,74 +1088,68 @@ unsigned long dwMax7230Pwr = 0;
  *
  * Return Value: none
  *
--*/
+ -*/
 void
-RFvRSSITodBm (
-    PSDevice pDevice,
-    unsigned char byCurrRSSI,
-    long *    pldBm
-    )
+RFvRSSITodBm(
+       PSDevice pDevice,
+       unsigned char byCurrRSSI,
+       long *pldBm
+       )
 {
-    unsigned char byIdx = (((byCurrRSSI & 0xC0) >> 6) & 0x03);
-    long b = (byCurrRSSI & 0x3F);
-    long a = 0;
-    unsigned char abyAIROHARF[4] = {0, 18, 0, 40};
-
-    switch (pDevice->byRFType) {
-        case RF_AIROHA:
-        case RF_AL2230S:
-        case RF_AIROHA7230: //RobertYu: 20040104
-            a = abyAIROHARF[byIdx];
-            break;
-        default:
-            break;
-    }
-
-    *pldBm = -1 * (a + b * 2);
+       unsigned char byIdx = (((byCurrRSSI & 0xC0) >> 6) & 0x03);
+       long b = (byCurrRSSI & 0x3F);
+       long a = 0;
+       unsigned char abyAIROHARF[4] = {0, 18, 0, 40};
+
+       switch (pDevice->byRFType) {
+       case RF_AIROHA:
+       case RF_AL2230S:
+       case RF_AIROHA7230: //RobertYu: 20040104
+               a = abyAIROHARF[byIdx];
+               break;
+       default:
+               break;
+       }
+
+       *pldBm = -1 * (a + b * 2);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //{{ RobertYu: 20050104
 
-
 // Post processing for the 11b/g and 11a.
 // for save time on changing Reg2,3,5,7,10,12,15
-bool RFbAL7230SelectChannelPostProcess (unsigned long dwIoBase, unsigned char byOldChannel, unsigned char byNewChannel)
+bool RFbAL7230SelectChannelPostProcess(unsigned long dwIoBase, unsigned char byOldChannel, unsigned char byNewChannel)
 {
-    bool bResult;
-
-    bResult = true;
-
-    // if change between 11 b/g and 11a need to update the following register
-    // Channel Index 1~14
-
-    if( (byOldChannel <= CB_MAX_CHANNEL_24G) && (byNewChannel > CB_MAX_CHANNEL_24G) )
-    {
-        // Change from 2.4G to 5G
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[2]); //Reg2
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[3]); //Reg3
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[5]); //Reg5
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[7]); //Reg7
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[10]);//Reg10
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[12]);//Reg12
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[15]);//Reg15
-    }
-    else if( (byOldChannel > CB_MAX_CHANNEL_24G) && (byNewChannel <= CB_MAX_CHANNEL_24G) )
-    {
-        // change from 5G to 2.4G
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[2]); //Reg2
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[3]); //Reg3
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[5]); //Reg5
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[7]); //Reg7
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[10]);//Reg10
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[12]);//Reg12
-        bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[15]);//Reg15
-    }
-
-    return bResult;
+       bool bResult;
+
+       bResult = true;
+
+       // if change between 11 b/g and 11a need to update the following register
+       // Channel Index 1~14
+
+       if ((byOldChannel <= CB_MAX_CHANNEL_24G) && (byNewChannel > CB_MAX_CHANNEL_24G)) {
+               // Change from 2.4G to 5G
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[2]); //Reg2
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[3]); //Reg3
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[5]); //Reg5
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[7]); //Reg7
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[10]);//Reg10
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[12]);//Reg12
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[15]);//Reg15
+       } else if ((byOldChannel > CB_MAX_CHANNEL_24G) && (byNewChannel <= CB_MAX_CHANNEL_24G)) {
+               // change from 5G to 2.4G
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[2]); //Reg2
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[3]); //Reg3
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[5]); //Reg5
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[7]); //Reg7
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[10]);//Reg10
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[12]);//Reg12
+               bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[15]);//Reg15
+       }
+
+       return bResult;
 }
 
-
 //}} RobertYu
 ////////////////////////////////////////////////////////////////////////////////
-
index 1da0fdeb2e1ce0ead367c273f4360cfc735a9bd3..ef3c6de09fec2b6b6f179375680484cae18e0734 100644 (file)
@@ -68,7 +68,6 @@
 #define CB_MAXIM2829_CHANNEL_5G_HIGH    41 //Index41: channel = 100, Tf = 5500MHz, set the (A3:A0=0101) D6=1
 #define CB_UW2452_CHANNEL_5G_HIGH       41 //[20041210] Index41: channel = 100, Tf = 5500MHz, change VCO2->VCO3
 
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 
 bool IFRFbWriteEmbedded(unsigned long dwIoBase, unsigned long dwData);
 bool RFbSelectChannel(unsigned long dwIoBase, unsigned char byRFType, unsigned char byChannel);
-bool RFbInit (
-    PSDevice  pDevice
-    );
+bool RFbInit(
+       PSDevice  pDevice
+);
 bool RFvWriteWakeProgSyn(unsigned long dwIoBase, unsigned char byRFType, unsigned int uChannel);
 bool RFbSetPower(PSDevice pDevice, unsigned int uRATE, unsigned int uCH);
 bool RFbRawSetPower(
-    PSDevice  pDevice,
-    unsigned char byPwr,
-    unsigned int uRATE
-    );
+       PSDevice  pDevice,
+       unsigned char byPwr,
+       unsigned int uRATE
+);
 
 void
 RFvRSSITodBm(
-    PSDevice pDevice,
-    unsigned char byCurrRSSI,
-    long    *pldBm
-    );
+       PSDevice pDevice,
+       unsigned char byCurrRSSI,
+       long    *pldBm
+);
 
 //{{ RobertYu: 20050104
 bool RFbAL7230SelectChannelPostProcess(unsigned long dwIoBase, unsigned char byOldChannel, unsigned char byNewChannel);
 //}} RobertYu
 
 #endif // __RF_H__
-
-
-
index d66854f5b304ea27994a421e90d71039fb7fc34a..3a2661e2b27c42b8978f5ffb621d438e4b4f0725 100644 (file)
 
 /*---------------------  Static Variables  --------------------------*/
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 
 #define        PLICE_DEBUG
 
-
 /*---------------------  Static Functions  --------------------------*/
 
 /*---------------------  Static Definitions -------------------------*/
@@ -81,19 +80,18 @@ static int          msglevel                =MSG_LEVEL_INFO;
                                         //    packet size >= 256 -> direct send
 
 const unsigned short wTimeStampOff[2][MAX_RATE] = {
-        {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
-        {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
-    };
+       {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
+       {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
+};
 
 const unsigned short wFB_Opt0[2][5] = {
-        {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
-        {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
-    };
+       {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
+       {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
+};
 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_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
+       {RATE_6M , RATE_6M,  RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
+};
 
 #define RTSDUR_BB       0
 #define RTSDUR_BA       1
@@ -112,1009 +110,946 @@ const unsigned short wFB_Opt1[2][5] = {
 
 /*---------------------  Static Functions  --------------------------*/
 
-
-
 static
 void
 s_vFillTxKey(
-    PSDevice   pDevice,
-    unsigned char *pbyBuf,
-    unsigned char *pbyIVHead,
-    PSKeyItem  pTransmitKey,
-    unsigned char *pbyHdrBuf,
-    unsigned short wPayloadLen,
-    unsigned char *pMICHDR
-    );
-
-
+       PSDevice   pDevice,
+       unsigned char *pbyBuf,
+       unsigned char *pbyIVHead,
+       PSKeyItem  pTransmitKey,
+       unsigned char *pbyHdrBuf,
+       unsigned short wPayloadLen,
+       unsigned char *pMICHDR
+);
 
 static
 void
 s_vFillRTSHead(
-    PSDevice         pDevice,
-    unsigned char byPktType,
-    void *           pvRTS,
-    unsigned int       cbFrameLength,
-    bool bNeedAck,
-    bool bDisCRC,
-    PSEthernetHeader psEthHeader,
-    unsigned short wCurrentRate,
-    unsigned char byFBOption
-    );
+       PSDevice         pDevice,
+       unsigned char byPktType,
+       void *pvRTS,
+       unsigned int    cbFrameLength,
+       bool bNeedAck,
+       bool bDisCRC,
+       PSEthernetHeader psEthHeader,
+       unsigned short wCurrentRate,
+       unsigned char byFBOption
+);
 
 static
 void
 s_vGenerateTxParameter(
-    PSDevice         pDevice,
-    unsigned char byPktType,
-    void *           pTxBufHead,
-    void *           pvRrvTime,
-    void *           pvRTS,
-    void *           pvCTS,
-    unsigned int       cbFrameSize,
-    bool bNeedACK,
-    unsigned int       uDMAIdx,
-    PSEthernetHeader psEthHeader,
-    unsigned short wCurrentRate
-    );
-
-
+       PSDevice         pDevice,
+       unsigned char byPktType,
+       void *pTxBufHead,
+       void *pvRrvTime,
+       void *pvRTS,
+       void *pvCTS,
+       unsigned int    cbFrameSize,
+       bool bNeedACK,
+       unsigned int    uDMAIdx,
+       PSEthernetHeader psEthHeader,
+       unsigned short wCurrentRate
+);
 
 static void s_vFillFragParameter(
-    PSDevice pDevice,
-    unsigned char *pbyBuffer,
-    unsigned int       uTxType,
-    void *   pvtdCurr,
-    unsigned short wFragType,
-    unsigned int       cbReqCount
-    );
-
+       PSDevice pDevice,
+       unsigned char *pbyBuffer,
+       unsigned int    uTxType,
+       void *pvtdCurr,
+       unsigned short wFragType,
+       unsigned int    cbReqCount
+);
 
 static unsigned int
 s_cbFillTxBufHead(PSDevice pDevice, unsigned char byPktType, unsigned char *pbyTxBufferAddr,
-       unsigned int cbFrameBodySize, unsigned int uDMAIdx, PSTxDesc pHeadTD,
-       PSEthernetHeader psEthHeader, unsigned char *pPacket, bool bNeedEncrypt,
-       PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum);
-
+                 unsigned int cbFrameBodySize, unsigned int uDMAIdx, PSTxDesc pHeadTD,
+                 PSEthernetHeader psEthHeader, unsigned char *pPacket, bool bNeedEncrypt,
+                 PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum);
 
 static
 unsigned int
-s_uFillDataHead (
-    PSDevice pDevice,
-    unsigned char byPktType,
-    void *   pTxDataHead,
-    unsigned int cbFrameLength,
-    unsigned int uDMAIdx,
-    bool bNeedAck,
-    unsigned int uFragIdx,
-    unsigned int cbLastFragmentSize,
-    unsigned int uMACfragNum,
-    unsigned char byFBOption,
-    unsigned short wCurrentRate
-    );
-
+s_uFillDataHead(
+       PSDevice pDevice,
+       unsigned char byPktType,
+       void *pTxDataHead,
+       unsigned int cbFrameLength,
+       unsigned int uDMAIdx,
+       bool bNeedAck,
+       unsigned int uFragIdx,
+       unsigned int cbLastFragmentSize,
+       unsigned int uMACfragNum,
+       unsigned char byFBOption,
+       unsigned short wCurrentRate
+);
 
 /*---------------------  Export Variables  --------------------------*/
 
-
-
 static
 void
-s_vFillTxKey (
-    PSDevice   pDevice,
-    unsigned char *pbyBuf,
-    unsigned char *pbyIVHead,
-    PSKeyItem  pTransmitKey,
-    unsigned char *pbyHdrBuf,
-    unsigned short wPayloadLen,
-    unsigned char *pMICHDR
-    )
+s_vFillTxKey(
+       PSDevice   pDevice,
+       unsigned char *pbyBuf,
+       unsigned char *pbyIVHead,
+       PSKeyItem  pTransmitKey,
+       unsigned char *pbyHdrBuf,
+       unsigned short wPayloadLen,
+       unsigned char *pMICHDR
+)
 {
-    unsigned long *pdwIV = (unsigned long *) pbyIVHead;
-    unsigned long *pdwExtIV = (unsigned long *) ((unsigned char *)pbyIVHead+4);
-    unsigned short wValue;
-    PS802_11Header  pMACHeader = (PS802_11Header)pbyHdrBuf;
-    unsigned long dwRevIVCounter;
-    unsigned char byKeyIndex = 0;
-
-
-
-    //Fill TXKEY
-    if (pTransmitKey == NULL)
-        return;
-
-    dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
-    *pdwIV = pDevice->dwIVCounter;
-    byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
-
-    if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
-        if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
-            memcpy(pDevice->abyPRNG, (unsigned char *)&(dwRevIVCounter), 3);
-            memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
-        } else {
-            memcpy(pbyBuf, (unsigned char *)&(dwRevIVCounter), 3);
-            memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
-            if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
-                memcpy(pbyBuf+8, (unsigned char *)&(dwRevIVCounter), 3);
-                memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
-            }
-            memcpy(pDevice->abyPRNG, pbyBuf, 16);
-        }
-        // Append IV after Mac Header
-        *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
-        *pdwIV |= (unsigned long)byKeyIndex << 30;
-        *pdwIV = cpu_to_le32(*pdwIV);
-        pDevice->dwIVCounter++;
-        if (pDevice->dwIVCounter > WEP_IV_MASK) {
-            pDevice->dwIVCounter = 0;
-        }
-    } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
-        pTransmitKey->wTSC15_0++;
-        if (pTransmitKey->wTSC15_0 == 0) {
-            pTransmitKey->dwTSC47_16++;
-        }
-        TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
-                    pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
-        memcpy(pbyBuf, pDevice->abyPRNG, 16);
-        // Make IV
-        memcpy(pdwIV, pDevice->abyPRNG, 3);
-
-        *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
-        // Append IV&ExtIV after Mac Header
-        *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
-
-    } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
-        pTransmitKey->wTSC15_0++;
-        if (pTransmitKey->wTSC15_0 == 0) {
-            pTransmitKey->dwTSC47_16++;
-        }
-        memcpy(pbyBuf, pTransmitKey->abyKey, 16);
-
-        // Make IV
-        *pdwIV = 0;
-        *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
-        *pdwIV |= cpu_to_le16((unsigned short)(pTransmitKey->wTSC15_0));
-        //Append IV&ExtIV after Mac Header
-        *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
-
-        //Fill MICHDR0
-        *pMICHDR = 0x59;
-        *((unsigned char *)(pMICHDR+1)) = 0; // TxPriority
-        memcpy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
-        *((unsigned char *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
-        *((unsigned char *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
-        *((unsigned char *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
-        *((unsigned char *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
-        *((unsigned char *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
-        *((unsigned char *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
-        *((unsigned char *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
-        *((unsigned char *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
-
-        //Fill MICHDR1
-        *((unsigned char *)(pMICHDR+16)) = 0; // HLEN[15:8]
-        if (pDevice->bLongHeader) {
-            *((unsigned char *)(pMICHDR+17)) = 28; // HLEN[7:0]
-        } else {
-            *((unsigned char *)(pMICHDR+17)) = 22; // HLEN[7:0]
-        }
-        wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
-        memcpy(pMICHDR+18, (unsigned char *)&wValue, 2); // MSKFRACTL
-        memcpy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
-        memcpy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
-
-        //Fill MICHDR2
-        memcpy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
-        wValue = pMACHeader->wSeqCtl;
-        wValue &= 0x000F;
-        wValue = cpu_to_le16(wValue);
-        memcpy(pMICHDR+38, (unsigned char *)&wValue, 2); // MSKSEQCTL
-        if (pDevice->bLongHeader) {
-            memcpy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
-        }
-    }
+       unsigned long *pdwIV = (unsigned long *)pbyIVHead;
+       unsigned long *pdwExtIV = (unsigned long *)((unsigned char *)pbyIVHead+4);
+       unsigned short wValue;
+       PS802_11Header  pMACHeader = (PS802_11Header)pbyHdrBuf;
+       unsigned long dwRevIVCounter;
+       unsigned char byKeyIndex = 0;
+
+       //Fill TXKEY
+       if (pTransmitKey == NULL)
+               return;
+
+       dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
+       *pdwIV = pDevice->dwIVCounter;
+       byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
+
+       if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
+               if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
+                       memcpy(pDevice->abyPRNG, (unsigned char *)&(dwRevIVCounter), 3);
+                       memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
+               } else {
+                       memcpy(pbyBuf, (unsigned char *)&(dwRevIVCounter), 3);
+                       memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
+                       if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
+                               memcpy(pbyBuf+8, (unsigned char *)&(dwRevIVCounter), 3);
+                               memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
+                       }
+                       memcpy(pDevice->abyPRNG, pbyBuf, 16);
+               }
+               // Append IV after Mac Header
+               *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
+               *pdwIV |= (unsigned long)byKeyIndex << 30;
+               *pdwIV = cpu_to_le32(*pdwIV);
+               pDevice->dwIVCounter++;
+               if (pDevice->dwIVCounter > WEP_IV_MASK) {
+                       pDevice->dwIVCounter = 0;
+               }
+       } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
+               pTransmitKey->wTSC15_0++;
+               if (pTransmitKey->wTSC15_0 == 0) {
+                       pTransmitKey->dwTSC47_16++;
+               }
+               TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
+                           pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
+               memcpy(pbyBuf, pDevice->abyPRNG, 16);
+               // Make IV
+               memcpy(pdwIV, pDevice->abyPRNG, 3);
+
+               *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
+               // Append IV&ExtIV after Mac Header
+               *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
+
+       } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
+               pTransmitKey->wTSC15_0++;
+               if (pTransmitKey->wTSC15_0 == 0) {
+                       pTransmitKey->dwTSC47_16++;
+               }
+               memcpy(pbyBuf, pTransmitKey->abyKey, 16);
+
+               // Make IV
+               *pdwIV = 0;
+               *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
+               *pdwIV |= cpu_to_le16((unsigned short)(pTransmitKey->wTSC15_0));
+               //Append IV&ExtIV after Mac Header
+               *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
+
+               //Fill MICHDR0
+               *pMICHDR = 0x59;
+               *((unsigned char *)(pMICHDR+1)) = 0; // TxPriority
+               memcpy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
+               *((unsigned char *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
+               *((unsigned char *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
+               *((unsigned char *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
+               *((unsigned char *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
+               *((unsigned char *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
+               *((unsigned char *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
+               *((unsigned char *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
+               *((unsigned char *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
+
+               //Fill MICHDR1
+               *((unsigned char *)(pMICHDR+16)) = 0; // HLEN[15:8]
+               if (pDevice->bLongHeader) {
+                       *((unsigned char *)(pMICHDR+17)) = 28; // HLEN[7:0]
+               } else {
+                       *((unsigned char *)(pMICHDR+17)) = 22; // HLEN[7:0]
+               }
+               wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
+               memcpy(pMICHDR+18, (unsigned char *)&wValue, 2); // MSKFRACTL
+               memcpy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
+               memcpy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
+
+               //Fill MICHDR2
+               memcpy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
+               wValue = pMACHeader->wSeqCtl;
+               wValue &= 0x000F;
+               wValue = cpu_to_le16(wValue);
+               memcpy(pMICHDR+38, (unsigned char *)&wValue, 2); // MSKSEQCTL
+               if (pDevice->bLongHeader) {
+                       memcpy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
+               }
+       }
 }
 
-
 static
 void
-s_vSWencryption (
-    PSDevice            pDevice,
-    PSKeyItem           pTransmitKey,
-    unsigned char *pbyPayloadHead,
-    unsigned short wPayloadSize
-    )
+s_vSWencryption(
+       PSDevice            pDevice,
+       PSKeyItem           pTransmitKey,
+       unsigned char *pbyPayloadHead,
+       unsigned short wPayloadSize
+)
 {
-    unsigned int cbICVlen = 4;
-    unsigned long dwICV = 0xFFFFFFFFL;
-    unsigned long *pdwICV;
-
-    if (pTransmitKey == NULL)
-        return;
-
-    if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
-        //=======================================================================
-        // Append ICV after payload
-        dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
-        pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
-        // finally, we must invert dwCRC to get the correct answer
-        *pdwICV = cpu_to_le32(~dwICV);
-        // RC4 encryption
-        rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
-        rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
-        //=======================================================================
-    } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
-        //=======================================================================
-        //Append ICV after payload
-        dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
-        pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
-        // finally, we must invert dwCRC to get the correct answer
-        *pdwICV = cpu_to_le32(~dwICV);
-        // RC4 encryption
-        rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
-        rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
-        //=======================================================================
-    }
+       unsigned int cbICVlen = 4;
+       unsigned long dwICV = 0xFFFFFFFFL;
+       unsigned long *pdwICV;
+
+       if (pTransmitKey == NULL)
+               return;
+
+       if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
+               //=======================================================================
+               // Append ICV after payload
+               dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
+               pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
+               // finally, we must invert dwCRC to get the correct answer
+               *pdwICV = cpu_to_le32(~dwICV);
+               // RC4 encryption
+               rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
+               rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
+               //=======================================================================
+       } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
+               //=======================================================================
+               //Append ICV after payload
+               dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
+               pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
+               // finally, we must invert dwCRC to get the correct answer
+               *pdwICV = cpu_to_le32(~dwICV);
+               // RC4 encryption
+               rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
+               rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
+               //=======================================================================
+       }
 }
 
-
-
-
 /*byPktType : PK_TYPE_11A     0
-             PK_TYPE_11B     1
-             PK_TYPE_11GB    2
-             PK_TYPE_11GA    3
+  PK_TYPE_11B     1
+  PK_TYPE_11GB    2
+  PK_TYPE_11GA    3
 */
 static
 unsigned int
-s_uGetTxRsvTime (
-    PSDevice pDevice,
-    unsigned char byPktType,
-    unsigned int cbFrameLength,
-    unsigned short wRate,
-    bool bNeedAck
-    )
+s_uGetTxRsvTime(
+       PSDevice pDevice,
+       unsigned char byPktType,
+       unsigned int cbFrameLength,
+       unsigned short wRate,
+       bool bNeedAck
+)
 {
-    unsigned int uDataTime, uAckTime;
-
-    uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
-#ifdef PLICE_DEBUG
-       //printk("s_uGetTxRsvTime is %d\n",uDataTime);
-#endif
-    if (byPktType == PK_TYPE_11B) {//llb,CCK mode
-        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopCCKBasicRate);
-    } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
-        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopOFDMBasicRate);
-    }
-
-    if (bNeedAck) {
-        return (uDataTime + pDevice->uSIFS + uAckTime);
-    }
-    else {
-        return uDataTime;
-    }
+       unsigned int uDataTime, uAckTime;
+
+       uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
+       if (byPktType == PK_TYPE_11B) {//llb,CCK mode
+               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopCCKBasicRate);
+       } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
+               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopOFDMBasicRate);
+       }
+
+       if (bNeedAck) {
+               return uDataTime + pDevice->uSIFS + uAckTime;
+       } else {
+               return uDataTime;
+       }
 }
 
 //byFreqType: 0=>5GHZ 1=>2.4GHZ
 static
 unsigned int
-s_uGetRTSCTSRsvTime (
-    PSDevice pDevice,
-    unsigned char byRTSRsvType,
-    unsigned char byPktType,
-    unsigned int cbFrameLength,
-    unsigned short wCurrentRate
-    )
+s_uGetRTSCTSRsvTime(
+       PSDevice pDevice,
+       unsigned char byRTSRsvType,
+       unsigned char byPktType,
+       unsigned int cbFrameLength,
+       unsigned short wCurrentRate
+)
 {
-    unsigned int uRrvTime  , uRTSTime, uCTSTime, uAckTime, uDataTime;
-
-    uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
-
-
-    uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
-    if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
-        uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
-        uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
-    }
-    else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
-        uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
-        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
-        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-    }
-    else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
-        uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
-        uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-    }
-    else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
-        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
-        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-        uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
-        return uRrvTime;
-    }
-
-    //RTSRrvTime
-    uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
-    return uRrvTime;
+       unsigned int uRrvTime  , uRTSTime, uCTSTime, uAckTime, uDataTime;
+
+       uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
+
+       uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
+       if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
+               uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
+               uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
+       } else if (byRTSRsvType == 1) { //RTSTxRrvTime_ba, only in 2.4GHZ
+               uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
+               uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
+               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+       } else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
+               uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
+               uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+       } else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
+               uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
+               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+               uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
+               return uRrvTime;
+       }
+
+       //RTSRrvTime
+       uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
+       return uRrvTime;
 }
 
 //byFreqType 0: 5GHz, 1:2.4Ghz
 static
 unsigned int
-s_uGetDataDuration (
-    PSDevice pDevice,
-    unsigned char byDurType,
-    unsigned int cbFrameLength,
-    unsigned char byPktType,
-    unsigned short wRate,
-    bool bNeedAck,
-    unsigned int uFragIdx,
-    unsigned int cbLastFragmentSize,
-    unsigned int uMACfragNum,
-    unsigned char byFBOption
-    )
+s_uGetDataDuration(
+       PSDevice pDevice,
+       unsigned char byDurType,
+       unsigned int cbFrameLength,
+       unsigned char byPktType,
+       unsigned short wRate,
+       bool bNeedAck,
+       unsigned int uFragIdx,
+       unsigned int cbLastFragmentSize,
+       unsigned int uMACfragNum,
+       unsigned char byFBOption
+)
 {
-    bool bLastFrag = 0;
-    unsigned int uAckTime =0, uNextPktTime = 0;
-
-
-
-    if (uFragIdx == (uMACfragNum-1)) {
-        bLastFrag = 1;
-    }
-
-
-    switch (byDurType) {
-
-    case DATADUR_B:    //DATADUR_B
-        if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
-            if (bNeedAck) {
-               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
-                return (pDevice->uSIFS + uAckTime);
-            } else {
-                return 0;
-            }
-        }
-        else {//First Frag or Mid Frag
-            if (uFragIdx == (uMACfragNum-2)) {
-               uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
-            } else {
-                uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
-            }
-            if (bNeedAck) {
-               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
-                return (pDevice->uSIFS + uAckTime + uNextPktTime);
-            } else {
-                return (pDevice->uSIFS + uNextPktTime);
-            }
-        }
-        break;
-
-    case DATADUR_A:    //DATADUR_A
-        if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
-            if(bNeedAck){
-               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-                return (pDevice->uSIFS + uAckTime);
-            } else {
-                return 0;
-            }
-        }
-        else {//First Frag or Mid Frag
-            if(uFragIdx == (uMACfragNum-2)){
-               uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
-            } else {
-                uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
-            }
-            if(bNeedAck){
-               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-                return (pDevice->uSIFS + uAckTime + uNextPktTime);
-            } else {
-                return (pDevice->uSIFS + uNextPktTime);
-            }
-        }
-        break;
-
-    case DATADUR_A_F0:    //DATADUR_A_F0
-           if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
-            if(bNeedAck){
-               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-                return (pDevice->uSIFS + uAckTime);
-            } else {
-                return 0;
-            }
-        }
-           else { //First Frag or Mid Frag
-               if (byFBOption == AUTO_FB_0) {
-                if (wRate < RATE_18M)
-                    wRate = RATE_18M;
-                else if (wRate > RATE_54M)
-                    wRate = RATE_54M;
-
-                   if(uFragIdx == (uMACfragNum-2)){
-                   uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
-                } else {
-                    uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
-                }
-               } else { // (byFBOption == AUTO_FB_1)
-                if (wRate < RATE_18M)
-                    wRate = RATE_18M;
-                else if (wRate > RATE_54M)
-                    wRate = RATE_54M;
-
-                   if(uFragIdx == (uMACfragNum-2)){
-                   uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
-                } else {
-                    uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
-                }
-               }
-
-               if(bNeedAck){
-               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-                return (pDevice->uSIFS + uAckTime + uNextPktTime);
-            } else {
-                return (pDevice->uSIFS + uNextPktTime);
-            }
-           }
-        break;
-
-    case DATADUR_A_F1:    //DATADUR_A_F1
-        if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
-            if(bNeedAck){
-               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-                return (pDevice->uSIFS + uAckTime);
-            } else {
-                return 0;
-            }
-        }
-           else { //First Frag or Mid Frag
-               if (byFBOption == AUTO_FB_0) {
-                if (wRate < RATE_18M)
-                    wRate = RATE_18M;
-                else if (wRate > RATE_54M)
-                    wRate = RATE_54M;
-
-                   if(uFragIdx == (uMACfragNum-2)){
-                   uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
-                } else {
-                    uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
-                }
-
-               } else { // (byFBOption == AUTO_FB_1)
-                if (wRate < RATE_18M)
-                    wRate = RATE_18M;
-                else if (wRate > RATE_54M)
-                    wRate = RATE_54M;
-
-                   if(uFragIdx == (uMACfragNum-2)){
-                   uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
-                } else {
-                    uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
-                }
-               }
-               if(bNeedAck){
-               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-                return (pDevice->uSIFS + uAckTime + uNextPktTime);
-            } else {
-                return (pDevice->uSIFS + uNextPktTime);
-            }
-           }
-        break;
-
-    default:
-        break;
-    }
+       bool bLastFrag = 0;
+       unsigned int uAckTime = 0, uNextPktTime = 0;
+
+       if (uFragIdx == (uMACfragNum-1)) {
+               bLastFrag = 1;
+       }
+
+       switch (byDurType) {
+       case DATADUR_B:    //DATADUR_B
+               if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
+                       if (bNeedAck) {
+                               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
+                               return pDevice->uSIFS + uAckTime;
+                       } else {
+                               return 0;
+                       }
+               } else {//First Frag or Mid Frag
+                       if (uFragIdx == (uMACfragNum-2)) {
+                               uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
+                       } else {
+                               uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
+                       }
+                       if (bNeedAck) {
+                               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
+                               return pDevice->uSIFS + uAckTime + uNextPktTime;
+                       } else {
+                               return pDevice->uSIFS + uNextPktTime;
+                       }
+               }
+               break;
+
+       case DATADUR_A:    //DATADUR_A
+               if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
+                       if (bNeedAck) {
+                               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+                               return pDevice->uSIFS + uAckTime;
+                       } else {
+                               return 0;
+                       }
+               } else {//First Frag or Mid Frag
+                       if (uFragIdx == (uMACfragNum-2)) {
+                               uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
+                       } else {
+                               uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
+                       }
+                       if (bNeedAck) {
+                               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+                               return pDevice->uSIFS + uAckTime + uNextPktTime;
+                       } else {
+                               return pDevice->uSIFS + uNextPktTime;
+                       }
+               }
+               break;
+
+       case DATADUR_A_F0:    //DATADUR_A_F0
+               if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
+                       if (bNeedAck) {
+                               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+                               return pDevice->uSIFS + uAckTime;
+                       } else {
+                               return 0;
+                       }
+               } else { //First Frag or Mid Frag
+                       if (byFBOption == AUTO_FB_0) {
+                               if (wRate < RATE_18M)
+                                       wRate = RATE_18M;
+                               else if (wRate > RATE_54M)
+                                       wRate = RATE_54M;
+
+                               if (uFragIdx == (uMACfragNum-2)) {
+                                       uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
+                               } else {
+                                       uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
+                               }
+                       } else { // (byFBOption == AUTO_FB_1)
+                               if (wRate < RATE_18M)
+                                       wRate = RATE_18M;
+                               else if (wRate > RATE_54M)
+                                       wRate = RATE_54M;
+
+                               if (uFragIdx == (uMACfragNum-2)) {
+                                       uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
+                               } else {
+                                       uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
+                               }
+                       }
+
+                       if (bNeedAck) {
+                               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+                               return pDevice->uSIFS + uAckTime + uNextPktTime;
+                       } else {
+                               return pDevice->uSIFS + uNextPktTime;
+                       }
+               }
+               break;
+
+       case DATADUR_A_F1:    //DATADUR_A_F1
+               if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
+                       if (bNeedAck) {
+                               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+                               return pDevice->uSIFS + uAckTime;
+                       } else {
+                               return 0;
+                       }
+               } else { //First Frag or Mid Frag
+                       if (byFBOption == AUTO_FB_0) {
+                               if (wRate < RATE_18M)
+                                       wRate = RATE_18M;
+                               else if (wRate > RATE_54M)
+                                       wRate = RATE_54M;
+
+                               if (uFragIdx == (uMACfragNum-2)) {
+                                       uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
+                               } else {
+                                       uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
+                               }
+
+                       } else { // (byFBOption == AUTO_FB_1)
+                               if (wRate < RATE_18M)
+                                       wRate = RATE_18M;
+                               else if (wRate > RATE_54M)
+                                       wRate = RATE_54M;
+
+                               if (uFragIdx == (uMACfragNum-2)) {
+                                       uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
+                               } else {
+                                       uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
+                               }
+                       }
+                       if (bNeedAck) {
+                               uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+                               return pDevice->uSIFS + uAckTime + uNextPktTime;
+                       } else {
+                               return pDevice->uSIFS + uNextPktTime;
+                       }
+               }
+               break;
+
+       default:
+               break;
+       }
 
        ASSERT(false);
        return 0;
 }
 
-
 //byFreqType: 0=>5GHZ 1=>2.4GHZ
 static
 unsigned int
-s_uGetRTSCTSDuration (
-    PSDevice pDevice,
-    unsigned char byDurType,
-    unsigned int cbFrameLength,
-    unsigned char byPktType,
-    unsigned short wRate,
-    bool bNeedAck,
-    unsigned char byFBOption
-    )
+s_uGetRTSCTSDuration(
+       PSDevice pDevice,
+       unsigned char byDurType,
+       unsigned int cbFrameLength,
+       unsigned char byPktType,
+       unsigned short wRate,
+       bool bNeedAck,
+       unsigned char byFBOption
+)
 {
-    unsigned int uCTSTime = 0, uDurTime = 0;
-
-
-    switch (byDurType) {
-
-    case RTSDUR_BB:    //RTSDuration_bb
-        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
-        uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
-        break;
-
-    case RTSDUR_BA:    //RTSDuration_ba
-        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
-        uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
-        break;
-
-    case RTSDUR_AA:    //RTSDuration_aa
-        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-        uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
-        break;
-
-    case CTSDUR_BA:    //CTSDuration_ba
-        uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
-        break;
-
-    case RTSDUR_BA_F0: //RTSDuration_ba_f0
-        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
-        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
-        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
-        }
-        break;
-
-    case RTSDUR_AA_F0: //RTSDuration_aa_f0
-        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
-        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
-        }
-        break;
-
-    case RTSDUR_BA_F1: //RTSDuration_ba_f1
-        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
-        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
-        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
-        }
-        break;
-
-    case RTSDUR_AA_F1: //RTSDuration_aa_f1
-        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
-        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
-        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
-        }
-        break;
-
-    case CTSDUR_BA_F0: //CTSDuration_ba_f0
-        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
-        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
-        }
-        break;
-
-    case CTSDUR_BA_F1: //CTSDuration_ba_f1
-        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
-        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
-            uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
-        }
-        break;
-
-    default:
-        break;
-    }
-
-    return uDurTime;
-
+       unsigned int uCTSTime = 0, uDurTime = 0;
+
+       switch (byDurType) {
+       case RTSDUR_BB:    //RTSDuration_bb
+               uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
+               uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
+               break;
+
+       case RTSDUR_BA:    //RTSDuration_ba
+               uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
+               uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
+               break;
+
+       case RTSDUR_AA:    //RTSDuration_aa
+               uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+               uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
+               break;
+
+       case CTSDUR_BA:    //CTSDuration_ba
+               uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
+               break;
+
+       case RTSDUR_BA_F0: //RTSDuration_ba_f0
+               uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
+               if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
+               } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
+               }
+               break;
+
+       case RTSDUR_AA_F0: //RTSDuration_aa_f0
+               uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+               if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
+               } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
+               }
+               break;
+
+       case RTSDUR_BA_F1: //RTSDuration_ba_f1
+               uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
+               if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
+               } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
+               }
+               break;
+
+       case RTSDUR_AA_F1: //RTSDuration_aa_f1
+               uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
+               if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
+               } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
+               }
+               break;
+
+       case CTSDUR_BA_F0: //CTSDuration_ba_f0
+               if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
+               } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
+               }
+               break;
+
+       case CTSDUR_BA_F1: //CTSDuration_ba_f1
+               if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
+               } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M)) {
+                       uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
+               }
+               break;
+
+       default:
+               break;
+       }
+
+       return uDurTime;
 }
 
-
-
 static
 unsigned int
-s_uFillDataHead (
-    PSDevice pDevice,
-    unsigned char byPktType,
-    void *   pTxDataHead,
-    unsigned int cbFrameLength,
-    unsigned int uDMAIdx,
-    bool bNeedAck,
-    unsigned int uFragIdx,
-    unsigned int cbLastFragmentSize,
-    unsigned int uMACfragNum,
-    unsigned char byFBOption,
-    unsigned short wCurrentRate
-    )
+s_uFillDataHead(
+       PSDevice pDevice,
+       unsigned char byPktType,
+       void *pTxDataHead,
+       unsigned int cbFrameLength,
+       unsigned int uDMAIdx,
+       bool bNeedAck,
+       unsigned int uFragIdx,
+       unsigned int cbLastFragmentSize,
+       unsigned int uMACfragNum,
+       unsigned char byFBOption,
+       unsigned short wCurrentRate
+)
 {
-    unsigned short wLen = 0x0000;
-
-    if (pTxDataHead == NULL) {
-        return 0;
-    }
-
-    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
-        if (byFBOption == AUTO_FB_NONE) {
-            PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
-            //Get SignalField,ServiceField,Length
-            BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
-            );
-            pBuf->wTransmitLength_a = cpu_to_le16(wLen);
-            BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
-            );
-            pBuf->wTransmitLength_b = cpu_to_le16(wLen);
-            //Get Duration and TimeStamp
-            pBuf->wDuration_a = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
-                                                         byPktType, wCurrentRate, bNeedAck, uFragIdx,
-                                                         cbLastFragmentSize, uMACfragNum,
-                                                         byFBOption)); //1: 2.4GHz
-            pBuf->wDuration_b = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
-                                                         PK_TYPE_11B, pDevice->byTopCCKBasicRate,
-                                                         bNeedAck, uFragIdx, cbLastFragmentSize,
-                                                         uMACfragNum, byFBOption)); //1: 2.4
-
-            pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
-            pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
-
-            return (pBuf->wDuration_a);
-         } else {
-            // Auto Fallback
-            PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
-            //Get SignalField,ServiceField,Length
-            BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
-            );
-            pBuf->wTransmitLength_a = cpu_to_le16(wLen);
-            BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
-            );
-            pBuf->wTransmitLength_b = cpu_to_le16(wLen);
-            //Get Duration and TimeStamp
-            pBuf->wDuration_a = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
-                                         wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
-            pBuf->wDuration_b = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
-                                         pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
-            pBuf->wDuration_a_f0 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
-                                         wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
-            pBuf->wDuration_a_f1 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
-                                         wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
-
-            pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
-            pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
-
-            return (pBuf->wDuration_a);
-        } //if (byFBOption == AUTO_FB_NONE)
-    }
-    else if (byPktType == PK_TYPE_11A) {
-        if ((byFBOption != AUTO_FB_NONE)) {
-            // Auto Fallback
-            PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
-            //Get SignalField,ServiceField,Length
-            BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
-            );
-            pBuf->wTransmitLength = cpu_to_le16(wLen);
-            //Get Duration and TimeStampOff
-
-            pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
-                                        wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
-            pBuf->wDuration_f0 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
-                                        wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
-            pBuf->wDuration_f1 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
-                                        wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
-            pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
-            return (pBuf->wDuration);
-        } else {
-            PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
-            //Get SignalField,ServiceField,Length
-            BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
-            );
-            pBuf->wTransmitLength = cpu_to_le16(wLen);
-            //Get Duration and TimeStampOff
-
-            pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
-                                                       wCurrentRate, bNeedAck, uFragIdx,
-                                                       cbLastFragmentSize, uMACfragNum,
-                                                       byFBOption));
-
-            pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
-            return (pBuf->wDuration);
-        }
-    }
-    else {
-            PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
-            //Get SignalField,ServiceField,Length
-            BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
-            );
-            pBuf->wTransmitLength = cpu_to_le16(wLen);
-            //Get Duration and TimeStampOff
-            pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
-                                                       wCurrentRate, bNeedAck, uFragIdx,
-                                                       cbLastFragmentSize, uMACfragNum,
-                                                       byFBOption));
-            pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
-            return (pBuf->wDuration);
-    }
-    return 0;
+       unsigned short wLen = 0x0000;
+
+       if (pTxDataHead == NULL) {
+               return 0;
+       }
+
+       if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
+               if (byFBOption == AUTO_FB_NONE) {
+                       PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
+                       //Get SignalField,ServiceField,Length
+                       BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
+);
+                       pBuf->wTransmitLength_a = cpu_to_le16(wLen);
+                       BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
+);
+                       pBuf->wTransmitLength_b = cpu_to_le16(wLen);
+                       //Get Duration and TimeStamp
+                       pBuf->wDuration_a = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
+                                                                                          byPktType, wCurrentRate, bNeedAck, uFragIdx,
+                                                                                          cbLastFragmentSize, uMACfragNum,
+                                                                                          byFBOption)); //1: 2.4GHz
+                       pBuf->wDuration_b = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
+                                                                                          PK_TYPE_11B, pDevice->byTopCCKBasicRate,
+                                                                                          bNeedAck, uFragIdx, cbLastFragmentSize,
+                                                                                          uMACfragNum, byFBOption)); //1: 2.4
+
+                       pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
+                       pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
+
+                       return pBuf->wDuration_a;
+               } else {
+                       // Auto Fallback
+                       PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
+                       //Get SignalField,ServiceField,Length
+                       BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
+);
+                       pBuf->wTransmitLength_a = cpu_to_le16(wLen);
+                       BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
+);
+                       pBuf->wTransmitLength_b = cpu_to_le16(wLen);
+                       //Get Duration and TimeStamp
+                       pBuf->wDuration_a = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
+                                                                                          wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
+                       pBuf->wDuration_b = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
+                                                                                          pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
+                       pBuf->wDuration_a_f0 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
+                                                                                             wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
+                       pBuf->wDuration_a_f1 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
+                                                                                             wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
+
+                       pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
+                       pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
+
+                       return pBuf->wDuration_a;
+               } //if (byFBOption == AUTO_FB_NONE)
+       } else if (byPktType == PK_TYPE_11A) {
+               if ((byFBOption != AUTO_FB_NONE)) {
+                       // Auto Fallback
+                       PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
+                       //Get SignalField,ServiceField,Length
+                       BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
+);
+                       pBuf->wTransmitLength = cpu_to_le16(wLen);
+                       //Get Duration and TimeStampOff
+
+                       pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
+                                                                                        wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
+                       pBuf->wDuration_f0 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
+                                                                                           wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
+                       pBuf->wDuration_f1 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
+                                                                                           wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
+                       pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
+                       return pBuf->wDuration;
+               } else {
+                       PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
+                       //Get SignalField,ServiceField,Length
+                       BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
+);
+                       pBuf->wTransmitLength = cpu_to_le16(wLen);
+                       //Get Duration and TimeStampOff
+
+                       pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
+                                                                                        wCurrentRate, bNeedAck, uFragIdx,
+                                                                                        cbLastFragmentSize, uMACfragNum,
+                                                                                        byFBOption));
+
+                       pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
+                       return pBuf->wDuration;
+               }
+       } else {
+               PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
+               //Get SignalField,ServiceField,Length
+               BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
+                                     (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
+);
+               pBuf->wTransmitLength = cpu_to_le16(wLen);
+               //Get Duration and TimeStampOff
+               pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
+                                                                                wCurrentRate, bNeedAck, uFragIdx,
+                                                                                cbLastFragmentSize, uMACfragNum,
+                                                                                byFBOption));
+               pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
+               return pBuf->wDuration;
+       }
+       return 0;
 }
 
-
 static
 void
-s_vFillRTSHead (
-    PSDevice         pDevice,
-    unsigned char byPktType,
-    void *           pvRTS,
-    unsigned int cbFrameLength,
-    bool bNeedAck,
-    bool bDisCRC,
-    PSEthernetHeader psEthHeader,
-    unsigned short wCurrentRate,
-    unsigned char byFBOption
-    )
+s_vFillRTSHead(
+       PSDevice         pDevice,
+       unsigned char byPktType,
+       void *pvRTS,
+       unsigned int cbFrameLength,
+       bool bNeedAck,
+       bool bDisCRC,
+       PSEthernetHeader psEthHeader,
+       unsigned short wCurrentRate,
+       unsigned char byFBOption
+)
 {
-    unsigned int uRTSFrameLen = 20;
-    unsigned short wLen = 0x0000;
-
-    if (pvRTS == NULL)
-       return;
-
-    if (bDisCRC) {
-        // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
-        // in this case we need to decrease its length by 4.
-        uRTSFrameLen -= 4;
-    }
-
-    // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
-    //       Otherwise, we need to modify codes for them.
-    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
-        if (byFBOption == AUTO_FB_NONE) {
-            PSRTS_g pBuf = (PSRTS_g)pvRTS;
-            //Get SignalField,ServiceField,Length
-            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
-            );
-            pBuf->wTransmitLength_b = cpu_to_le16(wLen);
-            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
-            );
-            pBuf->wTransmitLength_a = cpu_to_le16(wLen);
-            //Get Duration
-            pBuf->wDuration_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption));    //0:RTSDuration_bb, 1:2.4G, 1:CCKData
-            pBuf->wDuration_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
-            pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
-
-            pBuf->Data.wDurationID = pBuf->wDuration_aa;
-            //Get RTS Frame body
-            pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
-            if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
-                (pDevice->eOPMode == OP_MODE_AP)) {
-                memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
-            }
-            else {
-                memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-            }
-            if (pDevice->eOPMode == OP_MODE_AP) {
-                memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-            }
-            else {
-                memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
-            }
-        }
-        else {
-           PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
-            //Get SignalField,ServiceField,Length
-            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
-            );
-            pBuf->wTransmitLength_b = cpu_to_le16(wLen);
-            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
-            );
-            pBuf->wTransmitLength_a = cpu_to_le16(wLen);
-
-            //Get Duration
-            pBuf->wDuration_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption));    //0:RTSDuration_bb, 1:2.4G, 1:CCKData
-            pBuf->wDuration_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
-            pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
-            pBuf->wRTSDuration_ba_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
-            pBuf->wRTSDuration_aa_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
-            pBuf->wRTSDuration_ba_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
-            pBuf->wRTSDuration_aa_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
-            pBuf->Data.wDurationID = pBuf->wDuration_aa;
-            //Get RTS Frame body
-            pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
-
-            if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
-                (pDevice->eOPMode == OP_MODE_AP)) {
-                memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
-            }
-            else {
-                memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-            }
-
-            if (pDevice->eOPMode == OP_MODE_AP) {
-                memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-            }
-            else {
-                memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
-            }
-
-        } // if (byFBOption == AUTO_FB_NONE)
-    }
-    else if (byPktType == PK_TYPE_11A) {
-        if (byFBOption == AUTO_FB_NONE) {
-            PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
-            //Get SignalField,ServiceField,Length
-            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
-            );
-            pBuf->wTransmitLength = cpu_to_le16(wLen);
-            //Get Duration
-            pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
-           pBuf->Data.wDurationID = pBuf->wDuration;
-            //Get RTS Frame body
-            pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
-
-            if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
-                (pDevice->eOPMode == OP_MODE_AP)) {
-                memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
-            }
-            else {
-                memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-            }
-
-            if (pDevice->eOPMode == OP_MODE_AP) {
-                memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-            }
-            else {
-                memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
-            }
-
-        }
-        else {
-            PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
-            //Get SignalField,ServiceField,Length
-            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
-            );
-            pBuf->wTransmitLength = cpu_to_le16(wLen);
-            //Get Duration
-            pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
-           pBuf->wRTSDuration_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
-           pBuf->wRTSDuration_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:RTSDuration_aa_f1, 0:5G, 0:
-           pBuf->Data.wDurationID = pBuf->wDuration;
-           //Get RTS Frame body
-            pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
-
-            if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
-                (pDevice->eOPMode == OP_MODE_AP)) {
-                memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
-            }
-            else {
-                memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-            }
-            if (pDevice->eOPMode == OP_MODE_AP) {
-                memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-            }
-            else {
-                memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
-            }
-        }
-    }
-    else if (byPktType == PK_TYPE_11B) {
-        PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
-        //Get SignalField,ServiceField,Length
-        BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-            (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
-        );
-        pBuf->wTransmitLength = cpu_to_le16(wLen);
-        //Get Duration
-        pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
-        pBuf->Data.wDurationID = pBuf->wDuration;
-        //Get RTS Frame body
-        pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
-
-
-        if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
-            (pDevice->eOPMode == OP_MODE_AP)) {
-            memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
-        }
-        else {
-            memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-        }
-
-        if (pDevice->eOPMode == OP_MODE_AP) {
-            memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-        }
-        else {
-            memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
-        }
-    }
+       unsigned int uRTSFrameLen = 20;
+       unsigned short wLen = 0x0000;
+
+       if (pvRTS == NULL)
+               return;
+
+       if (bDisCRC) {
+               // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
+               // in this case we need to decrease its length by 4.
+               uRTSFrameLen -= 4;
+       }
+
+       // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
+       //       Otherwise, we need to modify codes for them.
+       if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
+               if (byFBOption == AUTO_FB_NONE) {
+                       PSRTS_g pBuf = (PSRTS_g)pvRTS;
+                       //Get SignalField,ServiceField,Length
+                       BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
+);
+                       pBuf->wTransmitLength_b = cpu_to_le16(wLen);
+                       BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
+);
+                       pBuf->wTransmitLength_a = cpu_to_le16(wLen);
+                       //Get Duration
+                       pBuf->wDuration_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption));    //0:RTSDuration_bb, 1:2.4G, 1:CCKData
+                       pBuf->wDuration_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
+                       pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
+
+                       pBuf->Data.wDurationID = pBuf->wDuration_aa;
+                       //Get RTS Frame body
+                       pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
+                       if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
+                           (pDevice->eOPMode == OP_MODE_AP)) {
+                               memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
+                       } else {
+                               memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+                       }
+                       if (pDevice->eOPMode == OP_MODE_AP) {
+                               memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+                       } else {
+                               memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
+                       }
+               } else {
+                       PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
+                       //Get SignalField,ServiceField,Length
+                       BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
+);
+                       pBuf->wTransmitLength_b = cpu_to_le16(wLen);
+                       BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
+);
+                       pBuf->wTransmitLength_a = cpu_to_le16(wLen);
+
+                       //Get Duration
+                       pBuf->wDuration_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption));    //0:RTSDuration_bb, 1:2.4G, 1:CCKData
+                       pBuf->wDuration_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
+                       pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
+                       pBuf->wRTSDuration_ba_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
+                       pBuf->wRTSDuration_aa_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
+                       pBuf->wRTSDuration_ba_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
+                       pBuf->wRTSDuration_aa_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
+                       pBuf->Data.wDurationID = pBuf->wDuration_aa;
+                       //Get RTS Frame body
+                       pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
+
+                       if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
+                           (pDevice->eOPMode == OP_MODE_AP)) {
+                               memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
+                       } else {
+                               memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+                       }
+
+                       if (pDevice->eOPMode == OP_MODE_AP) {
+                               memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+                       } else {
+                               memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
+                       }
+
+               } // if (byFBOption == AUTO_FB_NONE)
+       } else if (byPktType == PK_TYPE_11A) {
+               if (byFBOption == AUTO_FB_NONE) {
+                       PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
+                       //Get SignalField,ServiceField,Length
+                       BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
+);
+                       pBuf->wTransmitLength = cpu_to_le16(wLen);
+                       //Get Duration
+                       pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
+                       pBuf->Data.wDurationID = pBuf->wDuration;
+                       //Get RTS Frame body
+                       pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
+
+                       if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
+                           (pDevice->eOPMode == OP_MODE_AP)) {
+                               memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
+                       } else {
+                               memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+                       }
+
+                       if (pDevice->eOPMode == OP_MODE_AP) {
+                               memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+                       } else {
+                               memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
+                       }
+
+               } else {
+                       PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
+                       //Get SignalField,ServiceField,Length
+                       BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
+);
+                       pBuf->wTransmitLength = cpu_to_le16(wLen);
+                       //Get Duration
+                       pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
+                       pBuf->wRTSDuration_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
+                       pBuf->wRTSDuration_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:RTSDuration_aa_f1, 0:5G, 0:
+                       pBuf->Data.wDurationID = pBuf->wDuration;
+                       //Get RTS Frame body
+                       pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
+
+                       if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
+                           (pDevice->eOPMode == OP_MODE_AP)) {
+                               memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
+                       } else {
+                               memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+                       }
+                       if (pDevice->eOPMode == OP_MODE_AP) {
+                               memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+                       } else {
+                               memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
+                       }
+               }
+       } else if (byPktType == PK_TYPE_11B) {
+               PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
+               //Get SignalField,ServiceField,Length
+               BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
+                                     (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
+);
+               pBuf->wTransmitLength = cpu_to_le16(wLen);
+               //Get Duration
+               pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
+               pBuf->Data.wDurationID = pBuf->wDuration;
+               //Get RTS Frame body
+               pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
+
+               if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
+                   (pDevice->eOPMode == OP_MODE_AP)) {
+                       memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
+               } else {
+                       memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+               }
+
+               if (pDevice->eOPMode == OP_MODE_AP) {
+                       memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+               } else {
+                       memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
+               }
+       }
 }
 
 static
 void
-s_vFillCTSHead (
-    PSDevice pDevice,
-    unsigned int uDMAIdx,
-    unsigned char byPktType,
-    void *   pvCTS,
-    unsigned int cbFrameLength,
-    bool bNeedAck,
-    bool bDisCRC,
-    unsigned short wCurrentRate,
-    unsigned char byFBOption
-    )
+s_vFillCTSHead(
+       PSDevice pDevice,
+       unsigned int uDMAIdx,
+       unsigned char byPktType,
+       void *pvCTS,
+       unsigned int cbFrameLength,
+       bool bNeedAck,
+       bool bDisCRC,
+       unsigned short wCurrentRate,
+       unsigned char byFBOption
+)
 {
-    unsigned int uCTSFrameLen = 14;
-    unsigned short wLen = 0x0000;
-
-    if (pvCTS == NULL) {
-        return;
-    }
-
-    if (bDisCRC) {
-        // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
-        // in this case we need to decrease its length by 4.
-        uCTSFrameLen -= 4;
-    }
-
-    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
-        if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
-            // Auto Fall back
-            PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
-            //Get SignalField,ServiceField,Length
-            BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
-            );
-
-
-            pBuf->wTransmitLength_b = cpu_to_le16(wLen);
-
-            pBuf->wDuration_ba = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
-            pBuf->wDuration_ba += pDevice->wCTSDuration;
-            pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
-            //Get CTSDuration_ba_f0
-            pBuf->wCTSDuration_ba_f0 = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
-            pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
-            pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
-            //Get CTSDuration_ba_f1
-            pBuf->wCTSDuration_ba_f1 = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
-            pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
-            pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
-            //Get CTS Frame body
-            pBuf->Data.wDurationID = pBuf->wDuration_ba;
-            pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
-            pBuf->Data.wReserved = 0x0000;
-            memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), ETH_ALEN);
-
-        } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
-            PSCTS pBuf = (PSCTS)pvCTS;
-            //Get SignalField,ServiceField,Length
-            BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
-            );
-            pBuf->wTransmitLength_b = cpu_to_le16(wLen);
-            //Get CTSDuration_ba
-            pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
-            pBuf->wDuration_ba += pDevice->wCTSDuration;
-            pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
-
-            //Get CTS Frame body
-            pBuf->Data.wDurationID = pBuf->wDuration_ba;
-            pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
-            pBuf->Data.wReserved = 0x0000;
-            memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), ETH_ALEN);
-        }
-    }
+       unsigned int uCTSFrameLen = 14;
+       unsigned short wLen = 0x0000;
+
+       if (pvCTS == NULL) {
+               return;
+       }
+
+       if (bDisCRC) {
+               // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
+               // in this case we need to decrease its length by 4.
+               uCTSFrameLen -= 4;
+       }
+
+       if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
+               if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
+                       // Auto Fall back
+                       PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
+                       //Get SignalField,ServiceField,Length
+                       BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
+);
+
+                       pBuf->wTransmitLength_b = cpu_to_le16(wLen);
+
+                       pBuf->wDuration_ba = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
+                       pBuf->wDuration_ba += pDevice->wCTSDuration;
+                       pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
+                       //Get CTSDuration_ba_f0
+                       pBuf->wCTSDuration_ba_f0 = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
+                       pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
+                       pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
+                       //Get CTSDuration_ba_f1
+                       pBuf->wCTSDuration_ba_f1 = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
+                       pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
+                       pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
+                       //Get CTS Frame body
+                       pBuf->Data.wDurationID = pBuf->wDuration_ba;
+                       pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
+                       pBuf->Data.wReserved = 0x0000;
+                       memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), ETH_ALEN);
+
+               } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
+                       PSCTS pBuf = (PSCTS)pvCTS;
+                       //Get SignalField,ServiceField,Length
+                       BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
+                                             (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
+);
+                       pBuf->wTransmitLength_b = cpu_to_le16(wLen);
+                       //Get CTSDuration_ba
+                       pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
+                       pBuf->wDuration_ba += pDevice->wCTSDuration;
+                       pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
+
+                       //Get CTS Frame body
+                       pBuf->Data.wDurationID = pBuf->wDuration_ba;
+                       pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
+                       pBuf->Data.wReserved = 0x0000;
+                       memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), ETH_ALEN);
+               }
+       }
 }
 
-
-
-
-
-
 /*+
  *
  * Description:
@@ -1136,1079 +1071,977 @@ s_vFillCTSHead (
  *
  * Return Value: none
  *
--*/
+ -*/
 // unsigned int cbFrameSize,//Hdr+Payload+FCS
 static
 void
-s_vGenerateTxParameter (
-    PSDevice         pDevice,
-    unsigned char byPktType,
-    void *           pTxBufHead,
-    void *           pvRrvTime,
-    void *           pvRTS,
-    void *           pvCTS,
-    unsigned int cbFrameSize,
-    bool bNeedACK,
-    unsigned int uDMAIdx,
-    PSEthernetHeader psEthHeader,
-    unsigned short wCurrentRate
-    )
+s_vGenerateTxParameter(
+       PSDevice         pDevice,
+       unsigned char byPktType,
+       void *pTxBufHead,
+       void *pvRrvTime,
+       void *pvRTS,
+       void *pvCTS,
+       unsigned int cbFrameSize,
+       bool bNeedACK,
+       unsigned int uDMAIdx,
+       PSEthernetHeader psEthHeader,
+       unsigned short wCurrentRate
+)
 {
-    unsigned int cbMACHdLen = WLAN_HDR_ADDR3_LEN; //24
-    unsigned short wFifoCtl;
-    bool bDisCRC = false;
-    unsigned char byFBOption = AUTO_FB_NONE;
+       unsigned int cbMACHdLen = WLAN_HDR_ADDR3_LEN; //24
+       unsigned short wFifoCtl;
+       bool bDisCRC = false;
+       unsigned char byFBOption = AUTO_FB_NONE;
 //    unsigned short wCurrentRate = pDevice->wCurrentRate;
 
-    //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
-    PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
-    pFifoHead->wReserved = wCurrentRate;
-    wFifoCtl = pFifoHead->wFIFOCtl;
-
-    if (wFifoCtl & FIFOCTL_CRCDIS) {
-        bDisCRC = true;
-    }
-
-    if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
-        byFBOption = AUTO_FB_0;
-    }
-    else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
-        byFBOption = AUTO_FB_1;
-    }
-
-    if (pDevice->bLongHeader)
-        cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
-
-    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
-
-        if (pvRTS != NULL) { //RTS_need
-            //Fill RsvTime
-            if (pvRrvTime) {
-                PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
-                pBuf->wRTSTxRrvTime_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
-                pBuf->wRTSTxRrvTime_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
-                pBuf->wRTSTxRrvTime_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
-                pBuf->wTxRrvTime_a = cpu_to_le16((unsigned short) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
-                pBuf->wTxRrvTime_b = cpu_to_le16((unsigned short) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
-            }
-            //Fill RTS
-            s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
-        }
-        else {//RTS_needless, PCF mode
-
-            //Fill RsvTime
-            if (pvRrvTime) {
-                PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
-                pBuf->wTxRrvTime_a = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
-                pBuf->wTxRrvTime_b = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
-                pBuf->wCTSTxRrvTime_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
-            }
-
-
-            //Fill CTS
-            s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
-        }
-    }
-    else if (byPktType == PK_TYPE_11A) {
-
-        if (pvRTS != NULL) {//RTS_need, non PCF mode
-            //Fill RsvTime
-            if (pvRrvTime) {
-                PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
-                pBuf->wRTSTxRrvTime = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
-                pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
-            }
-            //Fill RTS
-            s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
-        }
-        else if (pvRTS == NULL) {//RTS_needless, non PCF mode
-            //Fill RsvTime
-            if (pvRrvTime) {
-                PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
-                pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
-            }
-        }
-    }
-    else if (byPktType == PK_TYPE_11B) {
-
-        if ((pvRTS != NULL)) {//RTS_need, non PCF mode
-            //Fill RsvTime
-            if (pvRrvTime) {
-                PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
-                pBuf->wRTSTxRrvTime = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
-                pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
-            }
-            //Fill RTS
-            s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
-        }
-        else { //RTS_needless, non PCF mode
-            //Fill RsvTime
-            if (pvRrvTime) {
-                PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
-                pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
-            }
-        }
-    }
-    //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
+       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "s_vGenerateTxParameter...\n");
+       PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
+       pFifoHead->wReserved = wCurrentRate;
+       wFifoCtl = pFifoHead->wFIFOCtl;
+
+       if (wFifoCtl & FIFOCTL_CRCDIS) {
+               bDisCRC = true;
+       }
+
+       if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
+               byFBOption = AUTO_FB_0;
+       } else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
+               byFBOption = AUTO_FB_1;
+       }
+
+       if (pDevice->bLongHeader)
+               cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
+
+       if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
+               if (pvRTS != NULL) { //RTS_need
+                       //Fill RsvTime
+                       if (pvRrvTime) {
+                               PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
+                               pBuf->wRTSTxRrvTime_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
+                               pBuf->wRTSTxRrvTime_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
+                               pBuf->wRTSTxRrvTime_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
+                               pBuf->wTxRrvTime_a = cpu_to_le16((unsigned short) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
+                               pBuf->wTxRrvTime_b = cpu_to_le16((unsigned short) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
+                       }
+                       //Fill RTS
+                       s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
+               } else {//RTS_needless, PCF mode
+
+                       //Fill RsvTime
+                       if (pvRrvTime) {
+                               PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
+                               pBuf->wTxRrvTime_a = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
+                               pBuf->wTxRrvTime_b = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
+                               pBuf->wCTSTxRrvTime_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
+                       }
+
+                       //Fill CTS
+                       s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
+               }
+       } else if (byPktType == PK_TYPE_11A) {
+               if (pvRTS != NULL) {//RTS_need, non PCF mode
+                       //Fill RsvTime
+                       if (pvRrvTime) {
+                               PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
+                               pBuf->wRTSTxRrvTime = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
+                               pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
+                       }
+                       //Fill RTS
+                       s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
+               } else if (pvRTS == NULL) {//RTS_needless, non PCF mode
+                       //Fill RsvTime
+                       if (pvRrvTime) {
+                               PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
+                               pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
+                       }
+               }
+       } else if (byPktType == PK_TYPE_11B) {
+               if ((pvRTS != NULL)) {//RTS_need, non PCF mode
+                       //Fill RsvTime
+                       if (pvRrvTime) {
+                               PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
+                               pBuf->wRTSTxRrvTime = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
+                               pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
+                       }
+                       //Fill RTS
+                       s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
+               } else { //RTS_needless, non PCF mode
+                       //Fill RsvTime
+                       if (pvRrvTime) {
+                               PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
+                               pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
+                       }
+               }
+       }
+       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "s_vGenerateTxParameter END.\n");
 }
 /*
-    unsigned char *pbyBuffer,//point to pTxBufHead
-    unsigned short wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
-    unsigned int cbFragmentSize,//Hdr+payoad+FCS
+  unsigned char *pbyBuffer,//point to pTxBufHead
+  unsigned short wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
+  unsigned int cbFragmentSize,//Hdr+payoad+FCS
 */
 static
 void
 s_vFillFragParameter(
-    PSDevice pDevice,
-    unsigned char *pbyBuffer,
-    unsigned int uTxType,
-    void *   pvtdCurr,
-    unsigned short wFragType,
-    unsigned int cbReqCount
-    )
+       PSDevice pDevice,
+       unsigned char *pbyBuffer,
+       unsigned int uTxType,
+       void *pvtdCurr,
+       unsigned short wFragType,
+       unsigned int cbReqCount
+)
 {
-    PSTxBufHead pTxBufHead = (PSTxBufHead) pbyBuffer;
-    //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter...\n");
-
-    if (uTxType == TYPE_SYNCDMA) {
-        //PSTxSyncDesc ptdCurr = (PSTxSyncDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
-        PSTxSyncDesc ptdCurr = (PSTxSyncDesc)pvtdCurr;
-
-         //Set FIFOCtl & TimeStamp in TxSyncDesc
-        ptdCurr->m_wFIFOCtl = pTxBufHead->wFIFOCtl;
-        ptdCurr->m_wTimeStamp = pTxBufHead->wTimeStamp;
-        //Set TSR1 & ReqCount in TxDescHead
-        ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
-        if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
-            ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
-        }
-        else {
-            ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
-        }
-    }
-    else {
-        //PSTxDesc ptdCurr = (PSTxDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
-        PSTxDesc ptdCurr = (PSTxDesc)pvtdCurr;
-        //Set TSR1 & ReqCount in TxDescHead
-        ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
-        if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
-            ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
-        }
-        else {
-            ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
-        }
-    }
-
-    pTxBufHead->wFragCtl |= (unsigned short)wFragType;//0x0001; //0000 0000 0000 0001
-
-    //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter END\n");
+       PSTxBufHead pTxBufHead = (PSTxBufHead) pbyBuffer;
+       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "s_vFillFragParameter...\n");
+
+       if (uTxType == TYPE_SYNCDMA) {
+               //PSTxSyncDesc ptdCurr = (PSTxSyncDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
+               PSTxSyncDesc ptdCurr = (PSTxSyncDesc)pvtdCurr;
+
+               //Set FIFOCtl & TimeStamp in TxSyncDesc
+               ptdCurr->m_wFIFOCtl = pTxBufHead->wFIFOCtl;
+               ptdCurr->m_wTimeStamp = pTxBufHead->wTimeStamp;
+               //Set TSR1 & ReqCount in TxDescHead
+               ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
+               if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
+                       ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
+               } else {
+                       ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
+               }
+       } else {
+               //PSTxDesc ptdCurr = (PSTxDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
+               PSTxDesc ptdCurr = (PSTxDesc)pvtdCurr;
+               //Set TSR1 & ReqCount in TxDescHead
+               ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
+               if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
+                       ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
+               } else {
+                       ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
+               }
+       }
+
+       pTxBufHead->wFragCtl |= (unsigned short)wFragType;//0x0001; //0000 0000 0000 0001
+
+       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "s_vFillFragParameter END\n");
 }
 
 static unsigned int
 s_cbFillTxBufHead(PSDevice pDevice, unsigned char byPktType, unsigned char *pbyTxBufferAddr,
-       unsigned int cbFrameBodySize, unsigned int uDMAIdx, PSTxDesc pHeadTD,
-       PSEthernetHeader psEthHeader, unsigned char *pPacket, bool bNeedEncrypt,
-       PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum)
+                 unsigned int cbFrameBodySize, unsigned int uDMAIdx, PSTxDesc pHeadTD,
+                 PSEthernetHeader psEthHeader, unsigned char *pPacket, bool bNeedEncrypt,
+                 PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum)
 {
-    unsigned int cbMACHdLen;
-    unsigned int cbFrameSize;
-    unsigned int cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
-    unsigned int cbFragPayloadSize;
-    unsigned int cbLastFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
-    unsigned int cbLastFragPayloadSize;
-    unsigned int uFragIdx;
-    unsigned char *pbyPayloadHead;
-    unsigned char *pbyIVHead;
-    unsigned char *pbyMacHdr;
-    unsigned short wFragType; //00:Non-Frag, 01:Start, 10:Mid, 11:Last
-    unsigned int uDuration;
-    unsigned char *pbyBuffer;
+       unsigned int cbMACHdLen;
+       unsigned int cbFrameSize;
+       unsigned int cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
+       unsigned int cbFragPayloadSize;
+       unsigned int cbLastFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
+       unsigned int cbLastFragPayloadSize;
+       unsigned int uFragIdx;
+       unsigned char *pbyPayloadHead;
+       unsigned char *pbyIVHead;
+       unsigned char *pbyMacHdr;
+       unsigned short wFragType; //00:Non-Frag, 01:Start, 10:Mid, 11:Last
+       unsigned int uDuration;
+       unsigned char *pbyBuffer;
 //    unsigned int uKeyEntryIdx = NUM_KEY_ENTRY+1;
 //    unsigned char byKeySel = 0xFF;
-    unsigned int cbIVlen = 0;
-    unsigned int cbICVlen = 0;
-    unsigned int cbMIClen = 0;
-    unsigned int cbFCSlen = 4;
-    unsigned int cb802_1_H_len = 0;
-    unsigned int uLength = 0;
-    unsigned int uTmpLen = 0;
+       unsigned int cbIVlen = 0;
+       unsigned int cbICVlen = 0;
+       unsigned int cbMIClen = 0;
+       unsigned int cbFCSlen = 4;
+       unsigned int cb802_1_H_len = 0;
+       unsigned int uLength = 0;
+       unsigned int uTmpLen = 0;
 //    unsigned char abyTmp[8];
 //    unsigned long dwCRC;
-    unsigned int cbMICHDR = 0;
-    unsigned long dwMICKey0, dwMICKey1;
-    unsigned long dwMIC_Priority;
-    unsigned long *pdwMIC_L;
-    unsigned long *pdwMIC_R;
-    unsigned long dwSafeMIC_L, dwSafeMIC_R; //Fix "Last Frag Size" < "MIC length".
-    bool bMIC2Frag = false;
-    unsigned int uMICFragLen = 0;
-    unsigned int uMACfragNum = 1;
-    unsigned int uPadding = 0;
-    unsigned int cbReqCount = 0;
-
-    bool bNeedACK;
-    bool bRTS;
-    bool bIsAdhoc;
-    unsigned char *pbyType;
-    PSTxDesc       ptdCurr;
-    PSTxBufHead    psTxBufHd = (PSTxBufHead) pbyTxBufferAddr;
+       unsigned int cbMICHDR = 0;
+       unsigned long dwMICKey0, dwMICKey1;
+       unsigned long dwMIC_Priority;
+       unsigned long *pdwMIC_L;
+       unsigned long *pdwMIC_R;
+       unsigned long dwSafeMIC_L, dwSafeMIC_R; //Fix "Last Frag Size" < "MIC length".
+       bool bMIC2Frag = false;
+       unsigned int uMICFragLen = 0;
+       unsigned int uMACfragNum = 1;
+       unsigned int uPadding = 0;
+       unsigned int cbReqCount = 0;
+
+       bool bNeedACK;
+       bool bRTS;
+       bool bIsAdhoc;
+       unsigned char *pbyType;
+       PSTxDesc       ptdCurr;
+       PSTxBufHead    psTxBufHd = (PSTxBufHead) pbyTxBufferAddr;
 //    unsigned int tmpDescIdx;
-    unsigned int cbHeaderLength = 0;
-    void *         pvRrvTime;
-    PSMICHDRHead   pMICHDR;
-    void *         pvRTS;
-    void *         pvCTS;
-    void *         pvTxDataHd;
-    unsigned short wTxBufSize;   // FFinfo size
-    unsigned int uTotalCopyLength = 0;
-    unsigned char byFBOption = AUTO_FB_NONE;
-    bool bIsWEP256 = false;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-
-
-    pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
-
-    //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_cbFillTxBufHead...\n");
-    if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
-        (pDevice->eOPMode == OP_MODE_AP)) {
-
-       if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0])))
-               bNeedACK = false;
-        else
-            bNeedACK = true;
-        bIsAdhoc = true;
-    }
-    else {
-        // MSDUs in Infra mode always need ACK
-        bNeedACK = true;
-        bIsAdhoc = false;
-    }
-
-    if (pDevice->bLongHeader)
-        cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
-    else
-        cbMACHdLen = WLAN_HDR_ADDR3_LEN;
-
-
-    if ((bNeedEncrypt == true) && (pTransmitKey != NULL)) {
-        if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
-            cbIVlen = 4;
-            cbICVlen = 4;
-            if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
-                bIsWEP256 = true;
-            }
-        }
-        if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
-            cbIVlen = 8;//IV+ExtIV
-            cbMIClen = 8;
-            cbICVlen = 4;
-        }
-        if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
-            cbIVlen = 8;//RSN Header
-            cbICVlen = 8;//MIC
-            cbMICHDR = sizeof(SMICHDRHead);
-        }
-        if (pDevice->byLocalID > REV_ID_VT3253_A1) {
-            //MAC Header should be padding 0 to DW alignment.
-            uPadding = 4 - (cbMACHdLen%4);
-            uPadding %= 4;
-        }
-    }
-
-
-    cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
-
-    if ((bNeedACK == false) ||
-        (cbFrameSize < pDevice->wRTSThreshold) ||
-        ((cbFrameSize >= pDevice->wFragmentationThreshold) && (pDevice->wFragmentationThreshold <= pDevice->wRTSThreshold))
-        ) {
-        bRTS = false;
-    }
-    else {
-        bRTS = true;
-        psTxBufHd->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
-    }
-    //
-    // Use for AUTO FALL BACK
-    //
-    if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
-        byFBOption = AUTO_FB_0;
-    }
-    else if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
-        byFBOption = AUTO_FB_1;
-    }
-
-    //////////////////////////////////////////////////////
-    //Set RrvTime/RTS/CTS Buffer
-    wTxBufSize = sizeof(STxBufHead);
-    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
-
-        if (byFBOption == AUTO_FB_NONE) {
-            if (bRTS == true) {//RTS_need
-                pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
-                pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
-                pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
-                pvCTS = NULL;
-                pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
-                cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
-            }
-            else { //RTS_needless
-                pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
-                pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
-                pvRTS = NULL;
-                pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
-                pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
-                cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
-            }
-        } else {
-            // Auto Fall Back
-            if (bRTS == true) {//RTS_need
-                pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
-                pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
-                pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
-                pvCTS = NULL;
-                pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
-                cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
-            }
-            else { //RTS_needless
-                pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
-                pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
-                pvRTS = NULL;
-                pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
-                pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
-                cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
-            }
-        } // Auto Fall Back
-    }
-    else {//802.11a/b packet
-
-        if (byFBOption == AUTO_FB_NONE) {
-            if (bRTS == true) {
-                pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
-                pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
-                pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
-                pvCTS = NULL;
-                pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
-                cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
-            }
-            else { //RTS_needless, need MICHDR
-                pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
-                pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
-                pvRTS = NULL;
-                pvCTS = NULL;
-                pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
-                cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
-            }
-        } else {
-            // Auto Fall Back
-            if (bRTS == true) {//RTS_need
-                pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
-                pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
-                pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
-                pvCTS = NULL;
-                pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
-                cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
-            }
-            else { //RTS_needless
-                pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
-                pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
-                pvRTS = NULL;
-                pvCTS = NULL;
-                pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
-                cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
-            }
-        } // Auto Fall Back
-    }
-    memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderLength - wTxBufSize));
+       unsigned int cbHeaderLength = 0;
+       void *pvRrvTime;
+       PSMICHDRHead   pMICHDR;
+       void *pvRTS;
+       void *pvCTS;
+       void *pvTxDataHd;
+       unsigned short wTxBufSize;   // FFinfo size
+       unsigned int uTotalCopyLength = 0;
+       unsigned char byFBOption = AUTO_FB_NONE;
+       bool bIsWEP256 = false;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+
+       pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
+
+       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "s_cbFillTxBufHead...\n");
+       if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
+           (pDevice->eOPMode == OP_MODE_AP)) {
+               if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0])))
+                       bNeedACK = false;
+               else
+                       bNeedACK = true;
+               bIsAdhoc = true;
+       } else {
+               // MSDUs in Infra mode always need ACK
+               bNeedACK = true;
+               bIsAdhoc = false;
+       }
+
+       if (pDevice->bLongHeader)
+               cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
+       else
+               cbMACHdLen = WLAN_HDR_ADDR3_LEN;
+
+       if ((bNeedEncrypt == true) && (pTransmitKey != NULL)) {
+               if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
+                       cbIVlen = 4;
+                       cbICVlen = 4;
+                       if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
+                               bIsWEP256 = true;
+                       }
+               }
+               if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
+                       cbIVlen = 8;//IV+ExtIV
+                       cbMIClen = 8;
+                       cbICVlen = 4;
+               }
+               if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
+                       cbIVlen = 8;//RSN Header
+                       cbICVlen = 8;//MIC
+                       cbMICHDR = sizeof(SMICHDRHead);
+               }
+               if (pDevice->byLocalID > REV_ID_VT3253_A1) {
+                       //MAC Header should be padding 0 to DW alignment.
+                       uPadding = 4 - (cbMACHdLen%4);
+                       uPadding %= 4;
+               }
+       }
+
+       cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
+
+       if ((bNeedACK == false) ||
+           (cbFrameSize < pDevice->wRTSThreshold) ||
+           ((cbFrameSize >= pDevice->wFragmentationThreshold) && (pDevice->wFragmentationThreshold <= pDevice->wRTSThreshold))
+) {
+               bRTS = false;
+       } else {
+               bRTS = true;
+               psTxBufHd->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
+       }
+       //
+       // Use for AUTO FALL BACK
+       //
+       if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
+               byFBOption = AUTO_FB_0;
+       } else if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
+               byFBOption = AUTO_FB_1;
+       }
+
+       //////////////////////////////////////////////////////
+       //Set RrvTime/RTS/CTS Buffer
+       wTxBufSize = sizeof(STxBufHead);
+       if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
+
+               if (byFBOption == AUTO_FB_NONE) {
+                       if (bRTS == true) {//RTS_need
+                               pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
+                               pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
+                               pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
+                               pvCTS = NULL;
+                               pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
+                               cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
+                       } else { //RTS_needless
+                               pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
+                               pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
+                               pvRTS = NULL;
+                               pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
+                               pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
+                               cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
+                       }
+               } else {
+                       // Auto Fall Back
+                       if (bRTS == true) {//RTS_need
+                               pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
+                               pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
+                               pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
+                               pvCTS = NULL;
+                               pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
+                               cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
+                       } else { //RTS_needless
+                               pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
+                               pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
+                               pvRTS = NULL;
+                               pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
+                               pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
+                               cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
+                       }
+               } // Auto Fall Back
+       } else {//802.11a/b packet
+
+               if (byFBOption == AUTO_FB_NONE) {
+                       if (bRTS == true) {
+                               pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
+                               pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
+                               pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
+                               pvCTS = NULL;
+                               pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
+                               cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
+                       } else { //RTS_needless, need MICHDR
+                               pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
+                               pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
+                               pvRTS = NULL;
+                               pvCTS = NULL;
+                               pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
+                               cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
+                       }
+               } else {
+                       // Auto Fall Back
+                       if (bRTS == true) {//RTS_need
+                               pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
+                               pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
+                               pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
+                               pvCTS = NULL;
+                               pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
+                               cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
+                       } else { //RTS_needless
+                               pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
+                               pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
+                               pvRTS = NULL;
+                               pvCTS = NULL;
+                               pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
+                               cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
+                       }
+               } // Auto Fall Back
+       }
+       memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderLength - wTxBufSize));
 
 //////////////////////////////////////////////////////////////////
-    if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
-        if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
-            dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
-            dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
-        }
-        else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
-            dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
-            dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
-        }
-        else {
-            dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[24]);
-            dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[28]);
-        }
-        // DO Software Michael
-        MIC_vInit(dwMICKey0, dwMICKey1);
-        MIC_vAppend((unsigned char *)&(psEthHeader->abyDstAddr[0]), 12);
-        dwMIC_Priority = 0;
-        MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
-    }
+       if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
+               if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
+                       dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
+                       dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
+               } else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
+                       dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
+                       dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
+               } else {
+                       dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[24]);
+                       dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[28]);
+               }
+               // DO Software Michael
+               MIC_vInit(dwMICKey0, dwMICKey1);
+               MIC_vAppend((unsigned char *)&(psEthHeader->abyDstAddr[0]), 12);
+               dwMIC_Priority = 0;
+               MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
+       }
 
 ///////////////////////////////////////////////////////////////////
 
-    pbyMacHdr = (unsigned char *)(pbyTxBufferAddr + cbHeaderLength);
-    pbyPayloadHead = (unsigned char *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
-    pbyIVHead = (unsigned char *)(pbyMacHdr + cbMACHdLen + uPadding);
-
-    if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == true) && (bIsWEP256 == false)) {
-        // Fragmentation
-        // FragThreshold = Fragment size(Hdr+(IV)+fragment payload+(MIC)+(ICV)+FCS)
-        cbFragmentSize = pDevice->wFragmentationThreshold;
-        cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
-        //FragNum = (FrameSize-(Hdr+FCS))/(Fragment Size -(Hrd+FCS)))
-        uMACfragNum = (unsigned short) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
-        cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
-        if (cbLastFragPayloadSize == 0) {
-            cbLastFragPayloadSize = cbFragPayloadSize;
-        } else {
-            uMACfragNum++;
-        }
-        //[Hdr+(IV)+last fragment payload+(MIC)+(ICV)+FCS]
-        cbLastFragmentSize = cbMACHdLen + cbLastFragPayloadSize + cbIVlen + cbICVlen + cbFCSlen;
-
-        for (uFragIdx = 0; uFragIdx < uMACfragNum; uFragIdx ++) {
-            if (uFragIdx == 0) {
-                //=========================
-                //    Start Fragmentation
-                //=========================
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start Fragmentation...\n");
-                wFragType = FRAGCTL_STAFRAG;
-
-
-                //Fill FIFO,RrvTime,RTS,and CTS
-                s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
-                                       cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
-                //Fill DataHead
-                uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
-                                            uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
-                // Generate TX MAC Header
-                vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
-                                   wFragType, uDMAIdx, uFragIdx);
-
-                if (bNeedEncrypt == true) {
-                    //Fill TXKEY
-                    s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
-                                 pbyMacHdr, (unsigned short)cbFragPayloadSize, (unsigned char *)pMICHDR);
-                    //Fill IV(ExtIV,RSNHDR)
-                    if (pDevice->bEnableHostWEP) {
-                        pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
-                        pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
-                    }
-                }
-
-
-                // 802.1H
-                if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
-                    if ((psEthHeader->wType == TYPE_PKT_IPX) ||
-                        (psEthHeader->wType == cpu_to_le16(0xF380))) {
-                        memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
-                    }
-                    else {
-                        memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
-                    }
-                    pbyType = (unsigned char *) (pbyPayloadHead + 6);
-                    memcpy(pbyType, &(psEthHeader->wType), sizeof(unsigned short));
-                    cb802_1_H_len = 8;
-                }
-
-                cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
-                //---------------------------
-                // S/W or H/W Encryption
-                //---------------------------
-                //Fill MICHDR
-                //if (pDevice->bAES) {
-                //    s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, pbyMacHdr, (unsigned short)cbFragPayloadSize);
-                //}
-                //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (void *)psTxBufHd, byKeySel,
-                //                                pbyPayloadHead, (unsigned short)cbFragPayloadSize, uDMAIdx);
-
-
-
-                //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
-                pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
-
-                uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
-                //copy TxBufferHeader + MacHeader to desc
-                memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
-
-                // Copy the Packet into a tx Buffer
-                memcpy((pbyBuffer + uLength), (pPacket + 14), (cbFragPayloadSize - cb802_1_H_len));
-
-
-                uTotalCopyLength += cbFragPayloadSize - cb802_1_H_len;
-
-                if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start MIC: %d\n", cbFragPayloadSize);
-                    MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFragPayloadSize);
-
-                }
-
-                //---------------------------
-                // S/W Encryption
-                //---------------------------
-                if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
-                    if (bNeedEncrypt) {
-                        s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len), (unsigned short)cbFragPayloadSize);
-                        cbReqCount += cbICVlen;
-                    }
-                }
-
-                ptdCurr = (PSTxDesc)pHeadTD;
-                //--------------------
-                //1.Set TSR1 & ReqCount in TxDescHead
-                //2.Set FragCtl in TxBufferHead
-                //3.Set Frame Control
-                //4.Set Sequence Control
-                //5.Get S/W generate FCS
-                //--------------------
-                s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
-
-                ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
-                ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
-                ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
-                ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
-                pDevice->iTDUsed[uDMAIdx]++;
-                pHeadTD = ptdCurr->next;
-            }
-            else if (uFragIdx == (uMACfragNum-1)) {
-                //=========================
-                //    Last Fragmentation
-                //=========================
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last Fragmentation...\n");
-                //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
-
-                wFragType = FRAGCTL_ENDFRAG;
-
-                //Fill FIFO,RrvTime,RTS,and CTS
-                s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
-                                       cbLastFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
-                //Fill DataHead
-                uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbLastFragmentSize, uDMAIdx, bNeedACK,
-                                            uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
-
-                // Generate TX MAC Header
-                vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
-                                   wFragType, uDMAIdx, uFragIdx);
-
-                if (bNeedEncrypt == true) {
-                    //Fill TXKEY
-                    s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
-                                 pbyMacHdr, (unsigned short)cbLastFragPayloadSize, (unsigned char *)pMICHDR);
-
-                    if (pDevice->bEnableHostWEP) {
-                        pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
-                        pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
-                    }
-
-                }
-
-
-                cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbLastFragPayloadSize;
-                //---------------------------
-                // S/W or H/W Encryption
-                //---------------------------
-
-
-
-                pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
-                //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
-
-                uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
-
-                //copy TxBufferHeader + MacHeader to desc
-                memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
-
-                // Copy the Packet into a tx Buffer
-                if (bMIC2Frag == false) {
-
-                    memcpy((pbyBuffer + uLength),
-                             (pPacket + 14 + uTotalCopyLength),
-                             (cbLastFragPayloadSize - cbMIClen)
-                             );
-                    //TODO check uTmpLen !
-                    uTmpLen = cbLastFragPayloadSize - cbMIClen;
-
-                }
-                if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen:%d, cbLastFragPayloadSize:%d, uTmpLen:%d\n",
-                                   uMICFragLen, cbLastFragPayloadSize, uTmpLen);
-
-                    if (bMIC2Frag == false) {
-                        if (uTmpLen != 0)
-                            MIC_vAppend((pbyBuffer + uLength), uTmpLen);
-                        pdwMIC_L = (unsigned long *)(pbyBuffer + uLength + uTmpLen);
-                        pdwMIC_R = (unsigned long *)(pbyBuffer + uLength + uTmpLen + 4);
-                        MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
-                    } else {
-                        if (uMICFragLen >= 4) {
-                            memcpy((pbyBuffer + uLength), ((unsigned char *)&dwSafeMIC_R + (uMICFragLen - 4)),
-                                     (cbMIClen - uMICFragLen));
-                            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen >= 4: %X, %d\n",
-                                           *(unsigned char *)((unsigned char *)&dwSafeMIC_R + (uMICFragLen - 4)),
-                                           (cbMIClen - uMICFragLen));
-
-                        } else {
-                            memcpy((pbyBuffer + uLength), ((unsigned char *)&dwSafeMIC_L + uMICFragLen),
-                                     (4 - uMICFragLen));
-                            memcpy((pbyBuffer + uLength + (4 - uMICFragLen)), &dwSafeMIC_R, 4);
-                            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen < 4: %X, %d\n",
-                                           *(unsigned char *)((unsigned char *)&dwSafeMIC_R + uMICFragLen - 4),
-                                           (cbMIClen - uMICFragLen));
-                        }
-                        /*
-                        for (ii = 0; ii < cbLastFragPayloadSize + 8 + 24; ii++) {
-                            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii - 8 - 24)));
-                        }
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
-                        */
-                    }
-                    MIC_vUnInit();
-                } else {
-                    ASSERT(uTmpLen == (cbLastFragPayloadSize - cbMIClen));
-                }
-
-
-                //---------------------------
-                // S/W Encryption
-                //---------------------------
-                if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
-                    if (bNeedEncrypt) {
-                        s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (unsigned short)cbLastFragPayloadSize);
-                        cbReqCount += cbICVlen;
-                    }
-                }
-
-                ptdCurr = (PSTxDesc)pHeadTD;
-
-                //--------------------
-                //1.Set TSR1 & ReqCount in TxDescHead
-                //2.Set FragCtl in TxBufferHead
-                //3.Set Frame Control
-                //4.Set Sequence Control
-                //5.Get S/W generate FCS
-                //--------------------
-
-
-                s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
-
-                ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
-                ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
-                ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
-                ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
-                pDevice->iTDUsed[uDMAIdx]++;
-                pHeadTD = ptdCurr->next;
-
-            }
-            else {
-                //=========================
-                //    Middle Fragmentation
-                //=========================
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle Fragmentation...\n");
-                //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
-
-                wFragType = FRAGCTL_MIDFRAG;
-
-                //Fill FIFO,RrvTime,RTS,and CTS
-                s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
-                                       cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
-                //Fill DataHead
-                uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
-                                            uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
-
-                // Generate TX MAC Header
-                vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
-                                   wFragType, uDMAIdx, uFragIdx);
-
-
-                if (bNeedEncrypt == true) {
-                    //Fill TXKEY
-                    s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
-                                 pbyMacHdr, (unsigned short)cbFragPayloadSize, (unsigned char *)pMICHDR);
-
-                    if (pDevice->bEnableHostWEP) {
-                        pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
-                        pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
-                    }
-                }
-
-                cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
-                //---------------------------
-                // S/W or H/W Encryption
-                //---------------------------
-                //Fill MICHDR
-                //if (pDevice->bAES) {
-                //    s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, pbyMacHdr, (unsigned short)cbFragPayloadSize);
-                //}
-                //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (void *)psTxBufHd, byKeySel,
-                //                              pbyPayloadHead, (unsigned short)cbFragPayloadSize, uDMAIdx);
-
-
-                pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
-                //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
-
-
-                uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
-
-                //copy TxBufferHeader + MacHeader to desc
-                memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
-
-                // Copy the Packet into a tx Buffer
-                memcpy((pbyBuffer + uLength),
-                         (pPacket + 14 + uTotalCopyLength),
-                         cbFragPayloadSize
-                        );
-                uTmpLen = cbFragPayloadSize;
-
-                uTotalCopyLength += uTmpLen;
-
-                if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
-
-                    MIC_vAppend((pbyBuffer + uLength), uTmpLen);
-
-                    if (uTmpLen < cbFragPayloadSize) {
-                        bMIC2Frag = true;
-                        uMICFragLen = cbFragPayloadSize - uTmpLen;
-                        ASSERT(uMICFragLen < cbMIClen);
-
-                        pdwMIC_L = (unsigned long *)(pbyBuffer + uLength + uTmpLen);
-                        pdwMIC_R = (unsigned long *)(pbyBuffer + uLength + uTmpLen + 4);
-                        MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
-                        dwSafeMIC_L = *pdwMIC_L;
-                        dwSafeMIC_R = *pdwMIC_R;
-
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIDDLE: uMICFragLen:%d, cbFragPayloadSize:%d, uTmpLen:%d\n",
-                                       uMICFragLen, cbFragPayloadSize, uTmpLen);
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MIC in Middle frag [%d]\n", uMICFragLen);
-                        /*
-                        for (ii = 0; ii < uMICFragLen; ii++) {
-                            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength + uTmpLen) + ii)));
-                        }
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
-                        */
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
-                    }
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle frag len: %d\n", uTmpLen);
-                    /*
-                    for (ii = 0; ii < uTmpLen; ii++) {
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii)));
-                    }
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
-                    */
-
-                } else {
-                    ASSERT(uTmpLen == (cbFragPayloadSize));
-                }
-
-                if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
-                    if (bNeedEncrypt) {
-                        s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (unsigned short)cbFragPayloadSize);
-                        cbReqCount += cbICVlen;
-                    }
-                }
-
-                ptdCurr = (PSTxDesc)pHeadTD;
-
-                //--------------------
-                //1.Set TSR1 & ReqCount in TxDescHead
-                //2.Set FragCtl in TxBufferHead
-                //3.Set Frame Control
-                //4.Set Sequence Control
-                //5.Get S/W generate FCS
-                //--------------------
-
-                s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
-
-                ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
-                ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
-                ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
-                ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
-                pDevice->iTDUsed[uDMAIdx]++;
-                pHeadTD = ptdCurr->next;
-            }
-        }  // for (uMACfragNum)
-    }
-    else {
-        //=========================
-        //    No Fragmentation
-        //=========================
-        //DBG_PRTGRP03(("No Fragmentation...\n"));
-        //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
-        wFragType = FRAGCTL_NONFRAG;
-
-        //Set FragCtl in TxBufferHead
-        psTxBufHd->wFragCtl |= (unsigned short)wFragType;
-
-        //Fill FIFO,RrvTime,RTS,and CTS
-        s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
-                               cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
-        //Fill DataHead
-        uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
-                                    0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate);
-
-        // Generate TX MAC Header
-        vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
-                           wFragType, uDMAIdx, 0);
-
-        if (bNeedEncrypt == true) {
-            //Fill TXKEY
-            s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
-                         pbyMacHdr, (unsigned short)cbFrameBodySize, (unsigned char *)pMICHDR);
-
-            if (pDevice->bEnableHostWEP) {
-                pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
-                pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
-            }
-        }
-
-        // 802.1H
-        if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
-            if ((psEthHeader->wType == TYPE_PKT_IPX) ||
-                (psEthHeader->wType == cpu_to_le16(0xF380))) {
-                memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
-            }
-            else {
-                memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
-            }
-            pbyType = (unsigned char *) (pbyPayloadHead + 6);
-            memcpy(pbyType, &(psEthHeader->wType), sizeof(unsigned short));
-            cb802_1_H_len = 8;
-        }
-
-        cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen);
-        //---------------------------
-        // S/W or H/W Encryption
-        //---------------------------
-        //Fill MICHDR
-        //if (pDevice->bAES) {
-        //    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MICHDR...\n");
-        //    s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, pbyMacHdr, (unsigned short)cbFrameBodySize);
-        //}
-
-        pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
-        //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
-
-        uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
-
-        //copy TxBufferHeader + MacHeader to desc
-        memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
-
-        // Copy the Packet into a tx Buffer
-        memcpy((pbyBuffer + uLength),
-                 (pPacket + 14),
-                 cbFrameBodySize - cb802_1_H_len
-                 );
-
-        if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)){
-
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Length:%d, %d\n", cbFrameBodySize - cb802_1_H_len, uLength);
-            /*
-            for (ii = 0; ii < (cbFrameBodySize - cb802_1_H_len); ii++) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii)));
-            }
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
-            */
-
-            MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFrameBodySize);
-
-            pdwMIC_L = (unsigned long *)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize);
-            pdwMIC_R = (unsigned long *)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize + 4);
-
-            MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
-            MIC_vUnInit();
-
-
-            if (pDevice->bTxMICFail == true) {
-                *pdwMIC_L = 0;
-                *pdwMIC_R = 0;
-                pDevice->bTxMICFail = false;
-            }
-
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
+       pbyMacHdr = (unsigned char *)(pbyTxBufferAddr + cbHeaderLength);
+       pbyPayloadHead = (unsigned char *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
+       pbyIVHead = (unsigned char *)(pbyMacHdr + cbMACHdLen + uPadding);
+
+       if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == true) && (bIsWEP256 == false)) {
+               // Fragmentation
+               // FragThreshold = Fragment size(Hdr+(IV)+fragment payload+(MIC)+(ICV)+FCS)
+               cbFragmentSize = pDevice->wFragmentationThreshold;
+               cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
+               //FragNum = (FrameSize-(Hdr+FCS))/(Fragment Size -(Hrd+FCS)))
+               uMACfragNum = (unsigned short) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
+               cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
+               if (cbLastFragPayloadSize == 0) {
+                       cbLastFragPayloadSize = cbFragPayloadSize;
+               } else {
+                       uMACfragNum++;
+               }
+               //[Hdr+(IV)+last fragment payload+(MIC)+(ICV)+FCS]
+               cbLastFragmentSize = cbMACHdLen + cbLastFragPayloadSize + cbIVlen + cbICVlen + cbFCSlen;
+
+               for (uFragIdx = 0; uFragIdx < uMACfragNum; uFragIdx++) {
+                       if (uFragIdx == 0) {
+                               //=========================
+                               //    Start Fragmentation
+                               //=========================
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Start Fragmentation...\n");
+                               wFragType = FRAGCTL_STAFRAG;
+
+                               //Fill FIFO,RrvTime,RTS,and CTS
+                               s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
+                                                      cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
+                               //Fill DataHead
+                               uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
+                                                           uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
+                               // Generate TX MAC Header
+                               vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
+                                                  wFragType, uDMAIdx, uFragIdx);
+
+                               if (bNeedEncrypt == true) {
+                                       //Fill TXKEY
+                                       s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
+                                                    pbyMacHdr, (unsigned short)cbFragPayloadSize, (unsigned char *)pMICHDR);
+                                       //Fill IV(ExtIV,RSNHDR)
+                                       if (pDevice->bEnableHostWEP) {
+                                               pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
+                                               pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
+                                       }
+                               }
+
+                               // 802.1H
+                               if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
+                                       if ((psEthHeader->wType == TYPE_PKT_IPX) ||
+                                           (psEthHeader->wType == cpu_to_le16(0xF380))) {
+                                               memcpy((unsigned char *)(pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
+                                       } else {
+                                               memcpy((unsigned char *)(pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
+                                       }
+                                       pbyType = (unsigned char *)(pbyPayloadHead + 6);
+                                       memcpy(pbyType, &(psEthHeader->wType), sizeof(unsigned short));
+                                       cb802_1_H_len = 8;
+                               }
+
+                               cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
+                               //---------------------------
+                               // S/W or H/W Encryption
+                               //---------------------------
+                               pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
+
+                               uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
+                               //copy TxBufferHeader + MacHeader to desc
+                               memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
+
+                               // Copy the Packet into a tx Buffer
+                               memcpy((pbyBuffer + uLength), (pPacket + 14), (cbFragPayloadSize - cb802_1_H_len));
+
+                               uTotalCopyLength += cbFragPayloadSize - cb802_1_H_len;
+
+                               if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Start MIC: %d\n", cbFragPayloadSize);
+                                       MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFragPayloadSize);
+
+                               }
+
+                               //---------------------------
+                               // S/W Encryption
+                               //---------------------------
+                               if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
+                                       if (bNeedEncrypt) {
+                                               s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len), (unsigned short)cbFragPayloadSize);
+                                               cbReqCount += cbICVlen;
+                                       }
+                               }
+
+                               ptdCurr = (PSTxDesc)pHeadTD;
+                               //--------------------
+                               //1.Set TSR1 & ReqCount in TxDescHead
+                               //2.Set FragCtl in TxBufferHead
+                               //3.Set Frame Control
+                               //4.Set Sequence Control
+                               //5.Get S/W generate FCS
+                               //--------------------
+                               s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
+
+                               ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
+                               ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
+                               ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
+                               ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
+                               pDevice->iTDUsed[uDMAIdx]++;
+                               pHeadTD = ptdCurr->next;
+                       } else if (uFragIdx == (uMACfragNum-1)) {
+                               //=========================
+                               //    Last Fragmentation
+                               //=========================
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last Fragmentation...\n");
+                               //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
+
+                               wFragType = FRAGCTL_ENDFRAG;
+
+                               //Fill FIFO,RrvTime,RTS,and CTS
+                               s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
+                                                      cbLastFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
+                               //Fill DataHead
+                               uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbLastFragmentSize, uDMAIdx, bNeedACK,
+                                                           uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
+
+                               // Generate TX MAC Header
+                               vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
+                                                  wFragType, uDMAIdx, uFragIdx);
+
+                               if (bNeedEncrypt == true) {
+                                       //Fill TXKEY
+                                       s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
+                                                    pbyMacHdr, (unsigned short)cbLastFragPayloadSize, (unsigned char *)pMICHDR);
+
+                                       if (pDevice->bEnableHostWEP) {
+                                               pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
+                                               pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
+                                       }
+
+                               }
+
+                               cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbLastFragPayloadSize;
+                               //---------------------------
+                               // S/W or H/W Encryption
+                               //---------------------------
+
+                               pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
+                               //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
+
+                               uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
+
+                               //copy TxBufferHeader + MacHeader to desc
+                               memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
+
+                               // Copy the Packet into a tx Buffer
+                               if (bMIC2Frag == false) {
+                                       memcpy((pbyBuffer + uLength),
+                                              (pPacket + 14 + uTotalCopyLength),
+                                              (cbLastFragPayloadSize - cbMIClen)
+);
+                                       //TODO check uTmpLen !
+                                       uTmpLen = cbLastFragPayloadSize - cbMIClen;
+
+                               }
+                               if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "LAST: uMICFragLen:%d, cbLastFragPayloadSize:%d, uTmpLen:%d\n",
+                                               uMICFragLen, cbLastFragPayloadSize, uTmpLen);
+
+                                       if (bMIC2Frag == false) {
+                                               if (uTmpLen != 0)
+                                                       MIC_vAppend((pbyBuffer + uLength), uTmpLen);
+                                               pdwMIC_L = (unsigned long *)(pbyBuffer + uLength + uTmpLen);
+                                               pdwMIC_R = (unsigned long *)(pbyBuffer + uLength + uTmpLen + 4);
+                                               MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
+                                       } else {
+                                               if (uMICFragLen >= 4) {
+                                                       memcpy((pbyBuffer + uLength), ((unsigned char *)&dwSafeMIC_R + (uMICFragLen - 4)),
+                                                              (cbMIClen - uMICFragLen));
+                                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "LAST: uMICFragLen >= 4: %X, %d\n",
+                                                               *(unsigned char *)((unsigned char *)&dwSafeMIC_R + (uMICFragLen - 4)),
+                                                               (cbMIClen - uMICFragLen));
+
+                                               } else {
+                                                       memcpy((pbyBuffer + uLength), ((unsigned char *)&dwSafeMIC_L + uMICFragLen),
+                                                              (4 - uMICFragLen));
+                                                       memcpy((pbyBuffer + uLength + (4 - uMICFragLen)), &dwSafeMIC_R, 4);
+                                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "LAST: uMICFragLen < 4: %X, %d\n",
+                                                               *(unsigned char *)((unsigned char *)&dwSafeMIC_R + uMICFragLen - 4),
+                                                               (cbMIClen - uMICFragLen));
+                                               }
+                                               /*
+                                                 for (ii = 0; ii < cbLastFragPayloadSize + 8 + 24; ii++) {
+                                                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii - 8 - 24)));
+                                                 }
+                                                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n\n");
+                                               */
+                                       }
+                                       MIC_vUnInit();
+                               } else {
+                                       ASSERT(uTmpLen == (cbLastFragPayloadSize - cbMIClen));
+                               }
+
+                               //---------------------------
+                               // S/W Encryption
+                               //---------------------------
+                               if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
+                                       if (bNeedEncrypt) {
+                                               s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (unsigned short)cbLastFragPayloadSize);
+                                               cbReqCount += cbICVlen;
+                                       }
+                               }
+
+                               ptdCurr = (PSTxDesc)pHeadTD;
+
+                               //--------------------
+                               //1.Set TSR1 & ReqCount in TxDescHead
+                               //2.Set FragCtl in TxBufferHead
+                               //3.Set Frame Control
+                               //4.Set Sequence Control
+                               //5.Get S/W generate FCS
+                               //--------------------
+
+                               s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
+
+                               ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
+                               ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
+                               ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
+                               ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
+                               pDevice->iTDUsed[uDMAIdx]++;
+                               pHeadTD = ptdCurr->next;
+
+                       } else {
+                               //=========================
+                               //    Middle Fragmentation
+                               //=========================
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Middle Fragmentation...\n");
+                               //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
+
+                               wFragType = FRAGCTL_MIDFRAG;
+
+                               //Fill FIFO,RrvTime,RTS,and CTS
+                               s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
+                                                      cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
+                               //Fill DataHead
+                               uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
+                                                           uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
+
+                               // Generate TX MAC Header
+                               vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
+                                                  wFragType, uDMAIdx, uFragIdx);
+
+                               if (bNeedEncrypt == true) {
+                                       //Fill TXKEY
+                                       s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
+                                                    pbyMacHdr, (unsigned short)cbFragPayloadSize, (unsigned char *)pMICHDR);
+
+                                       if (pDevice->bEnableHostWEP) {
+                                               pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
+                                               pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
+                                       }
+                               }
+
+                               cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
+                               //---------------------------
+                               // S/W or H/W Encryption
+                               //---------------------------
+
+                               pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
+                               uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
+
+                               //copy TxBufferHeader + MacHeader to desc
+                               memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
+
+                               // Copy the Packet into a tx Buffer
+                               memcpy((pbyBuffer + uLength),
+                                      (pPacket + 14 + uTotalCopyLength),
+                                      cbFragPayloadSize
+);
+                               uTmpLen = cbFragPayloadSize;
+
+                               uTotalCopyLength += uTmpLen;
+
+                               if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
+                                       MIC_vAppend((pbyBuffer + uLength), uTmpLen);
+
+                                       if (uTmpLen < cbFragPayloadSize) {
+                                               bMIC2Frag = true;
+                                               uMICFragLen = cbFragPayloadSize - uTmpLen;
+                                               ASSERT(uMICFragLen < cbMIClen);
+
+                                               pdwMIC_L = (unsigned long *)(pbyBuffer + uLength + uTmpLen);
+                                               pdwMIC_R = (unsigned long *)(pbyBuffer + uLength + uTmpLen + 4);
+                                               MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
+                                               dwSafeMIC_L = *pdwMIC_L;
+                                               dwSafeMIC_R = *pdwMIC_R;
+
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MIDDLE: uMICFragLen:%d, cbFragPayloadSize:%d, uTmpLen:%d\n",
+                                                       uMICFragLen, cbFragPayloadSize, uTmpLen);
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fill MIC in Middle frag [%d]\n", uMICFragLen);
+                                               /*
+                                                 for (ii = 0; ii < uMICFragLen; ii++) {
+                                                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", *((unsigned char *)((pbyBuffer + uLength + uTmpLen) + ii)));
+                                                 }
+                                                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
+                                               */
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
+                                       }
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Middle frag len: %d\n", uTmpLen);
+                                       /*
+                                         for (ii = 0; ii < uTmpLen; ii++) {
+                                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii)));
+                                         }
+                                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n\n");
+                                       */
+
+                               } else {
+                                       ASSERT(uTmpLen == (cbFragPayloadSize));
+                               }
+
+                               if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
+                                       if (bNeedEncrypt) {
+                                               s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (unsigned short)cbFragPayloadSize);
+                                               cbReqCount += cbICVlen;
+                                       }
+                               }
+
+                               ptdCurr = (PSTxDesc)pHeadTD;
+
+                               //--------------------
+                               //1.Set TSR1 & ReqCount in TxDescHead
+                               //2.Set FragCtl in TxBufferHead
+                               //3.Set Frame Control
+                               //4.Set Sequence Control
+                               //5.Get S/W generate FCS
+                               //--------------------
+
+                               s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
+
+                               ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
+                               ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
+                               ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
+                               ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
+                               pDevice->iTDUsed[uDMAIdx]++;
+                               pHeadTD = ptdCurr->next;
+                       }
+               }  // for (uMACfragNum)
+       } else {
+               //=========================
+               //    No Fragmentation
+               //=========================
+               //DBG_PRTGRP03(("No Fragmentation...\n"));
+               //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "No Fragmentation...\n");
+               wFragType = FRAGCTL_NONFRAG;
+
+               //Set FragCtl in TxBufferHead
+               psTxBufHd->wFragCtl |= (unsigned short)wFragType;
+
+               //Fill FIFO,RrvTime,RTS,and CTS
+               s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
+                                      cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
+               //Fill DataHead
+               uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
+                                           0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate);
+
+               // Generate TX MAC Header
+               vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
+                                  wFragType, uDMAIdx, 0);
+
+               if (bNeedEncrypt == true) {
+                       //Fill TXKEY
+                       s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
+                                    pbyMacHdr, (unsigned short)cbFrameBodySize, (unsigned char *)pMICHDR);
+
+                       if (pDevice->bEnableHostWEP) {
+                               pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
+                               pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
+                       }
+               }
+
+               // 802.1H
+               if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
+                       if ((psEthHeader->wType == TYPE_PKT_IPX) ||
+                           (psEthHeader->wType == cpu_to_le16(0xF380))) {
+                               memcpy((unsigned char *)(pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
+                       } else {
+                               memcpy((unsigned char *)(pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
+                       }
+                       pbyType = (unsigned char *)(pbyPayloadHead + 6);
+                       memcpy(pbyType, &(psEthHeader->wType), sizeof(unsigned short));
+                       cb802_1_H_len = 8;
+               }
+
+               cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen);
+               //---------------------------
+               // S/W or H/W Encryption
+               //---------------------------
+               pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
+               uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
+
+               //copy TxBufferHeader + MacHeader to desc
+               memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
+
+               // Copy the Packet into a tx Buffer
+               memcpy((pbyBuffer + uLength),
+                      (pPacket + 14),
+                      cbFrameBodySize - cb802_1_H_len
+);
+
+               if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Length:%d, %d\n", cbFrameBodySize - cb802_1_H_len, uLength);
+                       /*
+                         for (ii = 0; ii < (cbFrameBodySize - cb802_1_H_len); ii++) {
+                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii)));
+                         }
+                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
+                       */
+
+                       MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFrameBodySize);
+
+                       pdwMIC_L = (unsigned long *)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize);
+                       pdwMIC_R = (unsigned long *)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize + 4);
+
+                       MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
+                       MIC_vUnInit();
+
+                       if (pDevice->bTxMICFail == true) {
+                               *pdwMIC_L = 0;
+                               *pdwMIC_R = 0;
+                               pDevice->bTxMICFail = false;
+                       }
+
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "uLength: %d, %d\n", uLength, cbFrameBodySize);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
 /*
-            for (ii = 0; ii < 8; ii++) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(((unsigned char *)(pdwMIC_L) + ii)));
-            }
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
+  for (ii = 0; ii < 8; ii++) {
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", *(((unsigned char *)(pdwMIC_L) + ii)));
+  }
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\n");
 */
 
-        }
-
-
-        if ((pDevice->byLocalID <= REV_ID_VT3253_A1)){
-            if (bNeedEncrypt) {
-                s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len),
-                                (unsigned short)(cbFrameBodySize + cbMIClen));
-                cbReqCount += cbICVlen;
-            }
-        }
+               }
 
+               if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
+                       if (bNeedEncrypt) {
+                               s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len),
+                                               (unsigned short)(cbFrameBodySize + cbMIClen));
+                               cbReqCount += cbICVlen;
+                       }
+               }
 
-        ptdCurr = (PSTxDesc)pHeadTD;
+               ptdCurr = (PSTxDesc)pHeadTD;
 
-        ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
-        ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
-        ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
-        ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
-           //Set TSR1 & ReqCount in TxDescHead
-        ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
-        ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
+               ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
+               ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
+               ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
+               ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
+               //Set TSR1 & ReqCount in TxDescHead
+               ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
+               ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
 
-        pDevice->iTDUsed[uDMAIdx]++;
+               pDevice->iTDUsed[uDMAIdx]++;
 
+//   DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ptdCurr->m_dwReserved0[%d] ptdCurr->m_dwReserved1[%d].\n", ptdCurr->pTDInfo->dwReqCount, ptdCurr->pTDInfo->dwHeaderLength);
+//   DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " cbHeaderLength[%d]\n", cbHeaderLength);
 
-//   DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ptdCurr->m_dwReserved0[%d] ptdCurr->m_dwReserved1[%d].\n", ptdCurr->pTDInfo->dwReqCount, ptdCurr->pTDInfo->dwHeaderLength);
-//   DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cbHeaderLength[%d]\n", cbHeaderLength);
-
-    }
-    *puMACfragNum = uMACfragNum;
-    //DBG_PRTGRP03(("s_cbFillTxBufHead END\n"));
-    return cbHeaderLength;
+       }
+       *puMACfragNum = uMACfragNum;
+       //DBG_PRTGRP03(("s_cbFillTxBufHead END\n"));
+       return cbHeaderLength;
 }
 
-
 void
 vGenerateFIFOHeader(PSDevice pDevice, unsigned char byPktType, unsigned char *pbyTxBufferAddr,
-       bool bNeedEncrypt, unsigned int cbPayloadSize, unsigned int uDMAIdx,
-       PSTxDesc pHeadTD, PSEthernetHeader psEthHeader, unsigned char *pPacket,
-       PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum,
-       unsigned int *pcbHeaderSize)
+                   bool bNeedEncrypt, unsigned int cbPayloadSize, unsigned int uDMAIdx,
+                   PSTxDesc pHeadTD, PSEthernetHeader psEthHeader, unsigned char *pPacket,
+                   PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum,
+                   unsigned int *pcbHeaderSize)
 {
-    unsigned int wTxBufSize;       // FFinfo size
-    bool bNeedACK;
-    bool bIsAdhoc;
-    unsigned short cbMacHdLen;
-    PSTxBufHead     pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
-
-    wTxBufSize = sizeof(STxBufHead);
-
-    memset(pTxBufHead, 0, wTxBufSize);
-    //Set FIFOCTL_NEEDACK
-
-    if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
-        (pDevice->eOPMode == OP_MODE_AP)) {
-        if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0]))) {
-            bNeedACK = false;
-            pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
-        }
-        else {
-            bNeedACK = true;
-            pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
-        }
-        bIsAdhoc = true;
-    }
-    else {
-        // MSDUs in Infra mode always need ACK
-        bNeedACK = true;
-        pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
-        bIsAdhoc = false;
-    }
-
-
-    pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
-    pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
-
-    //Set FIFOCTL_LHEAD
-    if (pDevice->bLongHeader)
-        pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
-
-    //Set FIFOCTL_GENINT
-
-    pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
-
-
-    //Set FIFOCTL_ISDMA0
-    if (TYPE_TXDMA0 == uDMAIdx) {
-        pTxBufHead->wFIFOCtl |= FIFOCTL_ISDMA0;
-    }
-
-    //Set FRAGCTL_MACHDCNT
-    if (pDevice->bLongHeader) {
-        cbMacHdLen = WLAN_HDR_ADDR3_LEN + 6;
-    } else {
-        cbMacHdLen = WLAN_HDR_ADDR3_LEN;
-    }
-    pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
-
-    //Set packet type
-    if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
-        ;
-    }
-    else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
-        pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
-    }
-    else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
-        pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
-    }
-    else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
-        pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
-    }
-    //Set FIFOCTL_GrpAckPolicy
-    if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
-        pTxBufHead->wFIFOCtl |=        FIFOCTL_GRPACK;
-    }
-
-    //Set Auto Fallback Ctl
-    if (pDevice->wCurrentRate >= RATE_18M) {
-        if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
-            pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
-        } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
-            pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
-        }
-    }
-
-    //Set FRAGCTL_WEPTYP
-    pDevice->bAES = false;
-
-    //Set FRAGCTL_WEPTYP
-    if (pDevice->byLocalID > REV_ID_VT3253_A1) {
-        if ((bNeedEncrypt) && (pTransmitKey != NULL))  { //WEP enabled
-            if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
-                pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
-            }
-            else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
-                if (pTransmitKey->uKeyLength != WLAN_WEP232_KEYLEN)
-                    pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
-            }
-            else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
-                pTxBufHead->wFragCtl |= FRAGCTL_AES;
-            }
-        }
-    }
+       unsigned int wTxBufSize;       // FFinfo size
+       bool bNeedACK;
+       bool bIsAdhoc;
+       unsigned short cbMacHdLen;
+       PSTxBufHead     pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
+
+       wTxBufSize = sizeof(STxBufHead);
+
+       memset(pTxBufHead, 0, wTxBufSize);
+       //Set FIFOCTL_NEEDACK
+
+       if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
+           (pDevice->eOPMode == OP_MODE_AP)) {
+               if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0]))) {
+                       bNeedACK = false;
+                       pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
+               } else {
+                       bNeedACK = true;
+                       pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
+               }
+               bIsAdhoc = true;
+       } else {
+               // MSDUs in Infra mode always need ACK
+               bNeedACK = true;
+               pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
+               bIsAdhoc = false;
+       }
+
+       pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
+       pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
+
+       //Set FIFOCTL_LHEAD
+       if (pDevice->bLongHeader)
+               pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
+
+       //Set FIFOCTL_GENINT
+
+       pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
+
+       //Set FIFOCTL_ISDMA0
+       if (TYPE_TXDMA0 == uDMAIdx) {
+               pTxBufHead->wFIFOCtl |= FIFOCTL_ISDMA0;
+       }
+
+       //Set FRAGCTL_MACHDCNT
+       if (pDevice->bLongHeader) {
+               cbMacHdLen = WLAN_HDR_ADDR3_LEN + 6;
+       } else {
+               cbMacHdLen = WLAN_HDR_ADDR3_LEN;
+       }
+       pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
+
+       //Set packet type
+       if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
+               ;
+       } else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
+       } else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
+       } else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
+       }
+       //Set FIFOCTL_GrpAckPolicy
+       if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
+       }
+
+       //Set Auto Fallback Ctl
+       if (pDevice->wCurrentRate >= RATE_18M) {
+               if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
+                       pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
+               } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
+                       pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
+               }
+       }
+
+       //Set FRAGCTL_WEPTYP
+       pDevice->bAES = false;
+
+       //Set FRAGCTL_WEPTYP
+       if (pDevice->byLocalID > REV_ID_VT3253_A1) {
+               if ((bNeedEncrypt) && (pTransmitKey != NULL))  { //WEP enabled
+                       if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
+                               pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
+                       } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
+                               if (pTransmitKey->uKeyLength != WLAN_WEP232_KEYLEN)
+                                       pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
+                       } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
+                               pTxBufHead->wFragCtl |= FRAGCTL_AES;
+                       }
+               }
+       }
 
 #ifdef PLICE_DEBUG
-       //printk("Func:vGenerateFIFOHeader:TxDataRate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
-
-       //if (pDevice->wCurrentRate <= 3)
-       //{
-       //      RFbRawSetPower(pDevice,36,pDevice->wCurrentRate);
-       //}
-       //else
-
        RFbSetPower(pDevice, pDevice->wCurrentRate, pDevice->byCurrentCh);
 #endif
-               //if (pDevice->wCurrentRate == 3)
-               //pDevice->byCurPwr = 46;
-               pTxBufHead->byTxPower = pDevice->byCurPwr;
-
-
-
+       pTxBufHead->byTxPower = pDevice->byCurPwr;
 
 /*
-    if(pDevice->bEnableHostWEP)
-        pTxBufHead->wFragCtl &=  ~(FRAGCTL_TKIP | FRAGCTL_LEGACY |FRAGCTL_AES);
+  if (pDevice->bEnableHostWEP)
+  pTxBufHead->wFragCtl &=  ~(FRAGCTL_TKIP | FRAGCTL_LEGACY |FRAGCTL_AES);
 */
-    *pcbHeaderSize = s_cbFillTxBufHead(pDevice, byPktType, pbyTxBufferAddr, cbPayloadSize,
-                                   uDMAIdx, pHeadTD, psEthHeader, pPacket, bNeedEncrypt,
-                                   pTransmitKey, uNodeIndex, puMACfragNum);
+       *pcbHeaderSize = s_cbFillTxBufHead(pDevice, byPktType, pbyTxBufferAddr, cbPayloadSize,
+                                          uDMAIdx, pHeadTD, psEthHeader, pPacket, bNeedEncrypt,
+                                          pTransmitKey, uNodeIndex, puMACfragNum);
 
-    return;
+       return;
 }
 
-
-
-
 /*+
  *
  * Description:
@@ -2226,964 +2059,882 @@ vGenerateFIFOHeader(PSDevice pDevice, unsigned char byPktType, unsigned char *pb
  *
  * Return Value: none
  *
--*/
+ -*/
 
 void
-vGenerateMACHeader (
-    PSDevice         pDevice,
-    unsigned char *pbyBufferAddr,
-    unsigned short wDuration,
-    PSEthernetHeader psEthHeader,
-    bool bNeedEncrypt,
-    unsigned short wFragType,
-    unsigned int uDMAIdx,
-    unsigned int uFragIdx
-    )
+vGenerateMACHeader(
+       PSDevice         pDevice,
+       unsigned char *pbyBufferAddr,
+       unsigned short wDuration,
+       PSEthernetHeader psEthHeader,
+       bool bNeedEncrypt,
+       unsigned short wFragType,
+       unsigned int uDMAIdx,
+       unsigned int uFragIdx
+)
 {
-    PS802_11Header  pMACHeader = (PS802_11Header)pbyBufferAddr;
-
-    memset(pMACHeader, 0, (sizeof(S802_11Header)));  //- sizeof(pMACHeader->dwIV)));
-
-    if (uDMAIdx == TYPE_ATIMDMA) {
-       pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
-    } else {
-        pMACHeader->wFrameCtl = TYPE_802_11_DATA;
-    }
-
-    if (pDevice->eOPMode == OP_MODE_AP) {
-        memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
-        memcpy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-        memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
-        pMACHeader->wFrameCtl |= FC_FROMDS;
-    }
-    else {
-        if (pDevice->eOPMode == OP_MODE_ADHOC) {
-            memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
-            memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
-            memcpy(&(pMACHeader->abyAddr3[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-        }
-        else {
-            memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
-            memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
-            memcpy(&(pMACHeader->abyAddr1[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-            pMACHeader->wFrameCtl |= FC_TODS;
-        }
-    }
-
-    if (bNeedEncrypt)
-        pMACHeader->wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_ISWEP(1));
-
-    pMACHeader->wDurationID = cpu_to_le16(wDuration);
-
-    if (pDevice->bLongHeader) {
-        PWLAN_80211HDR_A4 pMACA4Header  = (PWLAN_80211HDR_A4) pbyBufferAddr;
-        pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
-        memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
-    }
-    pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
-
-    //Set FragNumber in Sequence Control
-    pMACHeader->wSeqCtl |= cpu_to_le16((unsigned short)uFragIdx);
-
-    if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
-        pDevice->wSeqCounter++;
-        if (pDevice->wSeqCounter > 0x0fff)
-            pDevice->wSeqCounter = 0;
-    }
-
-    if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
-        pMACHeader->wFrameCtl |= FC_MOREFRAG;
-    }
+       PS802_11Header  pMACHeader = (PS802_11Header)pbyBufferAddr;
+
+       memset(pMACHeader, 0, (sizeof(S802_11Header)));  //- sizeof(pMACHeader->dwIV)));
+
+       if (uDMAIdx == TYPE_ATIMDMA) {
+               pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
+       } else {
+               pMACHeader->wFrameCtl = TYPE_802_11_DATA;
+       }
+
+       if (pDevice->eOPMode == OP_MODE_AP) {
+               memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
+               memcpy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+               memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
+               pMACHeader->wFrameCtl |= FC_FROMDS;
+       } else {
+               if (pDevice->eOPMode == OP_MODE_ADHOC) {
+                       memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
+                       memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
+                       memcpy(&(pMACHeader->abyAddr3[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+               } else {
+                       memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
+                       memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
+                       memcpy(&(pMACHeader->abyAddr1[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+                       pMACHeader->wFrameCtl |= FC_TODS;
+               }
+       }
+
+       if (bNeedEncrypt)
+               pMACHeader->wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_ISWEP(1));
+
+       pMACHeader->wDurationID = cpu_to_le16(wDuration);
+
+       if (pDevice->bLongHeader) {
+               PWLAN_80211HDR_A4 pMACA4Header  = (PWLAN_80211HDR_A4) pbyBufferAddr;
+               pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
+               memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
+       }
+       pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
+
+       //Set FragNumber in Sequence Control
+       pMACHeader->wSeqCtl |= cpu_to_le16((unsigned short)uFragIdx);
+
+       if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
+               pDevice->wSeqCounter++;
+               if (pDevice->wSeqCounter > 0x0fff)
+                       pDevice->wSeqCounter = 0;
+       }
+
+       if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
+               pMACHeader->wFrameCtl |= FC_MOREFRAG;
+       }
 }
 
-
-
-
-
-
 CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
-
-    PSTxDesc        pFrstTD;
-    unsigned char byPktType;
-    unsigned char *pbyTxBufferAddr;
-    void *          pvRTS;
-    PSCTS           pCTS;
-    void *          pvTxDataHd;
-    unsigned int uDuration;
-    unsigned int cbReqCount;
-    PS802_11Header  pMACHeader;
-    unsigned int cbHeaderSize;
-    unsigned int cbFrameBodySize;
-    bool bNeedACK;
-    bool bIsPSPOLL = false;
-    PSTxBufHead     pTxBufHead;
-    unsigned int cbFrameSize;
-    unsigned int cbIVlen = 0;
-    unsigned int cbICVlen = 0;
-    unsigned int cbMIClen = 0;
-    unsigned int cbFCSlen = 4;
-    unsigned int uPadding = 0;
-    unsigned short wTxBufSize;
-    unsigned int cbMacHdLen;
-    SEthernetHeader sEthHeader;
-    void *          pvRrvTime;
-    void *          pMICHDR;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned short wCurrentRate = RATE_1M;
-
-
-    if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
-        return CMD_STATUS_RESOURCES;
-    }
-
-    pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
-    pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf;
-    cbFrameBodySize = pPacket->cbPayloadLen;
-    pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
-    wTxBufSize = sizeof(STxBufHead);
-    memset(pTxBufHead, 0, wTxBufSize);
-
-    if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
-        wCurrentRate = RATE_6M;
-        byPktType = PK_TYPE_11A;
-    } else {
-        wCurrentRate = RATE_1M;
-        byPktType = PK_TYPE_11B;
-    }
-
-    // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
-    // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
-    //                    And cmd timer will wait data pkt TX finish before scanning so it's OK
-    //                    to set power here.
-    if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
-
+       PSTxDesc        pFrstTD;
+       unsigned char byPktType;
+       unsigned char *pbyTxBufferAddr;
+       void *pvRTS;
+       PSCTS           pCTS;
+       void *pvTxDataHd;
+       unsigned int uDuration;
+       unsigned int cbReqCount;
+       PS802_11Header  pMACHeader;
+       unsigned int cbHeaderSize;
+       unsigned int cbFrameBodySize;
+       bool bNeedACK;
+       bool bIsPSPOLL = false;
+       PSTxBufHead     pTxBufHead;
+       unsigned int cbFrameSize;
+       unsigned int cbIVlen = 0;
+       unsigned int cbICVlen = 0;
+       unsigned int cbMIClen = 0;
+       unsigned int cbFCSlen = 4;
+       unsigned int uPadding = 0;
+       unsigned short wTxBufSize;
+       unsigned int cbMacHdLen;
+       SEthernetHeader sEthHeader;
+       void *pvRrvTime;
+       void *pMICHDR;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned short wCurrentRate = RATE_1M;
+
+       if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
+               return CMD_STATUS_RESOURCES;
+       }
+
+       pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
+       pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf;
+       cbFrameBodySize = pPacket->cbPayloadLen;
+       pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
+       wTxBufSize = sizeof(STxBufHead);
+       memset(pTxBufHead, 0, wTxBufSize);
+
+       if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
+               wCurrentRate = RATE_6M;
+               byPktType = PK_TYPE_11A;
+       } else {
+               wCurrentRate = RATE_1M;
+               byPktType = PK_TYPE_11B;
+       }
+
+       // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
+       // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
+       //                    And cmd timer will wait data pkt TX finish before scanning so it's OK
+       //                    to set power here.
+       if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
                RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
-    } else {
-        RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
-    }
-    pTxBufHead->byTxPower = pDevice->byCurPwr;
-    //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
-    if (pDevice->byFOETuning) {
-        if ((pPacket->p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
-            wCurrentRate = RATE_24M;
-            byPktType = PK_TYPE_11GA;
-        }
-    }
-
-    //Set packet type
-    if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
-        pTxBufHead->wFIFOCtl = 0;
-    }
-    else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
-        pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
-    }
-    else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
-        pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
-    }
-    else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
-        pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
-    }
-
-    pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
-    pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
-
-
-    if (is_multicast_ether_addr(&(pPacket->p80211Header->sA3.abyAddr1[0])))
-        bNeedACK = false;
-    else {
-        bNeedACK = true;
-        pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
-    };
-
-    if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
-        (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
-
-        pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
-        //Set Preamble type always long
-        //pDevice->byPreambleType = PREAMBLE_LONG;
-        // probe-response don't retry
-        //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
-        //     bNeedACK = false;
-        //     pTxBufHead->wFIFOCtl  &= (~FIFOCTL_NEEDACK);
-        //}
-    }
-
-    pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
-
-    if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
-        bIsPSPOLL = true;
-        cbMacHdLen = WLAN_HDR_ADDR2_LEN;
-    } else {
-        cbMacHdLen = WLAN_HDR_ADDR3_LEN;
-    }
-
-    //Set FRAGCTL_MACHDCNT
-    pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
-
-    // Notes:
-    // Although spec says MMPDU can be fragmented; In most cases,
-    // no one will send a MMPDU under fragmentation. With RTS may occur.
-    pDevice->bAES = false;  //Set FRAGCTL_WEPTYP
-
-    if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
-        if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
-            cbIVlen = 4;
-            cbICVlen = 4;
-           pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
-        }
-        else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
-            cbIVlen = 8;//IV+ExtIV
-            cbMIClen = 8;
-            cbICVlen = 4;
-           pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
-           //We need to get seed here for filling TxKey entry.
-            //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
-            //            pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
-        }
-        else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
-            cbIVlen = 8;//RSN Header
-            cbICVlen = 8;//MIC
-            pTxBufHead->wFragCtl |= FRAGCTL_AES;
-            pDevice->bAES = true;
-        }
-        //MAC Header should be padding 0 to DW alignment.
-        uPadding = 4 - (cbMacHdLen%4);
-        uPadding %= 4;
-    }
-
-    cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
-
-    //Set FIFOCTL_GrpAckPolicy
-    if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
-        pTxBufHead->wFIFOCtl |=        FIFOCTL_GRPACK;
-    }
-    //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
-
-    //Set RrvTime/RTS/CTS Buffer
-    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
-
-        pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
-        pMICHDR = NULL;
-        pvRTS = NULL;
-        pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
-        pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
-        cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
-    }
-    else { // 802.11a/b packet
-        pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
-        pMICHDR = NULL;
-        pvRTS = NULL;
-        pCTS = NULL;
-        pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
-        cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
-    }
-
-    memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
-
-    memcpy(&(sEthHeader.abyDstAddr[0]), &(pPacket->p80211Header->sA3.abyAddr1[0]), ETH_ALEN);
-    memcpy(&(sEthHeader.abySrcAddr[0]), &(pPacket->p80211Header->sA3.abyAddr2[0]), ETH_ALEN);
-    //=========================
-    //    No Fragmentation
-    //=========================
-    pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
-
-
-    //Fill FIFO,RrvTime,RTS,and CTS
-    s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
-                           cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
-
-    //Fill DataHead
-    uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
-                                0, 0, 1, AUTO_FB_NONE, wCurrentRate);
-
-    pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
-
-    cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
-
-    if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
-        unsigned char *pbyIVHead;
-        unsigned char *pbyPayloadHead;
-        unsigned char *pbyBSSID;
-        PSKeyItem       pTransmitKey = NULL;
-
-        pbyIVHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
-        pbyPayloadHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
-
-        //Fill TXKEY
-        //Kyle: Need fix: TKIP and AES did't encrypt Mnt Packet.
-        //s_vFillTxKey(pDevice, (unsigned char *)pTxBufHead->adwTxKey, NULL);
-
-        //Fill IV(ExtIV,RSNHDR)
-        //s_vFillPrePayload(pDevice, pbyIVHead, NULL);
-        //---------------------------
-        // S/W or H/W Encryption
-        //---------------------------
-        //Fill MICHDR
-        //if (pDevice->bAES) {
-        //    s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, (unsigned char *)pMACHeader, (unsigned short)cbFrameBodySize);
-        //}
-        do {
-            if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
-                (pDevice->bLinkPass == true)) {
-                pbyBSSID = pDevice->abyBSSID;
-                // get pairwise key
-                if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
-                    // get group key
-                    if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
-                        break;
-                    }
-                } else {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
-                    break;
-                }
-            }
-            // get group key
-            pbyBSSID = pDevice->abyBroadcastAddr;
-            if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
-                pTransmitKey = NULL;
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
-            } else {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
-            }
-        } while(false);
-        //Fill TXKEY
-        s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
-                     (unsigned char *)pMACHeader, (unsigned short)cbFrameBodySize, NULL);
-
-        memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
-        memcpy(pbyPayloadHead, ((unsigned char *)(pPacket->p80211Header) + cbMacHdLen),
-                 cbFrameBodySize);
-    }
-    else {
-        // Copy the Packet into a tx Buffer
-        memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
-    }
-
-    pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
-    pDevice->wSeqCounter++ ;
-    if (pDevice->wSeqCounter > 0x0fff)
-        pDevice->wSeqCounter = 0;
-
-    if (bIsPSPOLL) {
-        // The MAC will automatically replace the Duration-field of MAC header by Duration-field
-        // of  FIFO control header.
-        // This will cause AID-field of PS-POLL packet to be incorrect (Because PS-POLL's AID field is
-        // in the same place of other packet's Duration-field).
-        // And it will cause Cisco-AP to issue Disassociation-packet
-        if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
-            ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
-            ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
-        } else {
-            ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
-        }
-    }
-
-
-    // first TD is the only TD
-    //Set TSR1 & ReqCount in TxDescHead
-    pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
-    pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
-    pFrstTD->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
-    pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
-    pFrstTD->pTDInfo->byFlags = 0;
-
-    if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
-        // Disable PS
-        MACbPSWakeup(pDevice->PortOffset);
-    }
-    pDevice->bPWBitOn = false;
-
-    wmb();
-    pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
-    wmb();
-
-    pDevice->iTDUsed[TYPE_TXDMA0]++;
-
-    if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
-    }
-
-    pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
-#ifdef PLICE_DEBUG
-               //printk("SCAN:CurrentRate is  %d,TxPower is %d\n",wCurrentRate,pTxBufHead->byTxPower);
-#endif
+       } else {
+               RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
+       }
+       pTxBufHead->byTxPower = pDevice->byCurPwr;
+       //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
+       if (pDevice->byFOETuning) {
+               if ((pPacket->p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
+                       wCurrentRate = RATE_24M;
+                       byPktType = PK_TYPE_11GA;
+               }
+       }
+
+       //Set packet type
+       if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
+               pTxBufHead->wFIFOCtl = 0;
+       } else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
+       } else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
+       } else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
+       }
+
+       pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
+       pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
+
+       if (is_multicast_ether_addr(&(pPacket->p80211Header->sA3.abyAddr1[0])))
+               bNeedACK = false;
+       else {
+               bNeedACK = true;
+               pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
+       };
+
+       if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
+           (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
+               pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
+       }
+
+       pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
+
+       if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
+               bIsPSPOLL = true;
+               cbMacHdLen = WLAN_HDR_ADDR2_LEN;
+       } else {
+               cbMacHdLen = WLAN_HDR_ADDR3_LEN;
+       }
+
+       //Set FRAGCTL_MACHDCNT
+       pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
+
+       // Notes:
+       // Although spec says MMPDU can be fragmented; In most cases,
+       // no one will send a MMPDU under fragmentation. With RTS may occur.
+       pDevice->bAES = false;  //Set FRAGCTL_WEPTYP
+
+       if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
+               if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
+                       cbIVlen = 4;
+                       cbICVlen = 4;
+                       pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
+               } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
+                       cbIVlen = 8;//IV+ExtIV
+                       cbMIClen = 8;
+                       cbICVlen = 4;
+                       pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
+                       //We need to get seed here for filling TxKey entry.
+                       //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
+                       //            pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
+               } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
+                       cbIVlen = 8;//RSN Header
+                       cbICVlen = 8;//MIC
+                       pTxBufHead->wFragCtl |= FRAGCTL_AES;
+                       pDevice->bAES = true;
+               }
+               //MAC Header should be padding 0 to DW alignment.
+               uPadding = 4 - (cbMacHdLen%4);
+               uPadding %= 4;
+       }
+
+       cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
+
+       //Set FIFOCTL_GrpAckPolicy
+       if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
+       }
+       //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
+
+       //Set RrvTime/RTS/CTS Buffer
+       if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
+
+               pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
+               pMICHDR = NULL;
+               pvRTS = NULL;
+               pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
+               pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
+               cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
+       } else { // 802.11a/b packet
+               pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
+               pMICHDR = NULL;
+               pvRTS = NULL;
+               pCTS = NULL;
+               pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
+               cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
+       }
+
+       memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
+
+       memcpy(&(sEthHeader.abyDstAddr[0]), &(pPacket->p80211Header->sA3.abyAddr1[0]), ETH_ALEN);
+       memcpy(&(sEthHeader.abySrcAddr[0]), &(pPacket->p80211Header->sA3.abyAddr2[0]), ETH_ALEN);
+       //=========================
+       //    No Fragmentation
+       //=========================
+       pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
+
+       //Fill FIFO,RrvTime,RTS,and CTS
+       s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
+                              cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
+
+       //Fill DataHead
+       uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
+                                   0, 0, 1, AUTO_FB_NONE, wCurrentRate);
+
+       pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
+
+       cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
+
+       if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
+               unsigned char *pbyIVHead;
+               unsigned char *pbyPayloadHead;
+               unsigned char *pbyBSSID;
+               PSKeyItem       pTransmitKey = NULL;
+
+               pbyIVHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
+               pbyPayloadHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
+
+               //Fill TXKEY
+               //Kyle: Need fix: TKIP and AES did't encrypt Mnt Packet.
+               //s_vFillTxKey(pDevice, (unsigned char *)pTxBufHead->adwTxKey, NULL);
+
+               //Fill IV(ExtIV,RSNHDR)
+               //s_vFillPrePayload(pDevice, pbyIVHead, NULL);
+               //---------------------------
+               // S/W or H/W Encryption
+               //---------------------------
+               do {
+                       if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
+                           (pDevice->bLinkPass == true)) {
+                               pbyBSSID = pDevice->abyBSSID;
+                               // get pairwise key
+                               if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
+                                       // get group key
+                                       if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get GTK.\n");
+                                               break;
+                                       }
+                               } else {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get PTK.\n");
+                                       break;
+                               }
+                       }
+                       // get group key
+                       pbyBSSID = pDevice->abyBroadcastAddr;
+                       if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
+                               pTransmitKey = NULL;
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
+                       } else {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get GTK.\n");
+                       }
+               } while (false);
+               //Fill TXKEY
+               s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
+                            (unsigned char *)pMACHeader, (unsigned short)cbFrameBodySize, NULL);
+
+               memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
+               memcpy(pbyPayloadHead, ((unsigned char *)(pPacket->p80211Header) + cbMacHdLen),
+                      cbFrameBodySize);
+       } else {
+               // Copy the Packet into a tx Buffer
+               memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
+       }
+
+       pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
+       pDevice->wSeqCounter++;
+       if (pDevice->wSeqCounter > 0x0fff)
+               pDevice->wSeqCounter = 0;
+
+       if (bIsPSPOLL) {
+               // The MAC will automatically replace the Duration-field of MAC header by Duration-field
+               // of  FIFO control header.
+               // This will cause AID-field of PS-POLL packet to be incorrect (Because PS-POLL's AID field is
+               // in the same place of other packet's Duration-field).
+               // And it will cause Cisco-AP to issue Disassociation-packet
+               if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
+                       ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
+                       ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
+               } else {
+                       ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
+               }
+       }
+
+       // first TD is the only TD
+       //Set TSR1 & ReqCount in TxDescHead
+       pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
+       pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
+       pFrstTD->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
+       pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
+       pFrstTD->pTDInfo->byFlags = 0;
+
+       if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
+               // Disable PS
+               MACbPSWakeup(pDevice->PortOffset);
+       }
+       pDevice->bPWBitOn = false;
+
+       wmb();
+       pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
+       wmb();
+
+       pDevice->iTDUsed[TYPE_TXDMA0]++;
+
+       if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
+       }
+
+       pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
 
 #ifdef TxInSleep
-  pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
-  #endif
-
-    // Poll Transmit the adapter
-    MACvTransmit0(pDevice->PortOffset);
+       pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
+#endif
 
-    return CMD_STATUS_PENDING;
+       // Poll Transmit the adapter
+       MACvTransmit0(pDevice->PortOffset);
 
+       return CMD_STATUS_PENDING;
 }
 
-
 CMD_STATUS csBeacon_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
-
-    unsigned char byPktType;
-    unsigned char *pbyBuffer = (unsigned char *)pDevice->tx_beacon_bufs;
-    unsigned int cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
-    unsigned int cbHeaderSize = 0;
-    unsigned short wTxBufSize = sizeof(STxShortBufHead);
-    PSTxShortBufHead pTxBufHead = (PSTxShortBufHead) pbyBuffer;
-    PSTxDataHead_ab  pTxDataHead = (PSTxDataHead_ab) (pbyBuffer + wTxBufSize);
-    PS802_11Header   pMACHeader;
-    unsigned short wCurrentRate;
-    unsigned short wLen = 0x0000;
-
-
-    memset(pTxBufHead, 0, wTxBufSize);
-
-    if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
-        wCurrentRate = RATE_6M;
-        byPktType = PK_TYPE_11A;
-    } else {
-        wCurrentRate = RATE_2M;
-        byPktType = PK_TYPE_11B;
-    }
-
-    //Set Preamble type always long
-    pDevice->byPreambleType = PREAMBLE_LONG;
-
-    //Set FIFOCTL_GENINT
-
-    pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
-
-
-    //Set packet type & Get Duration
-    if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
-        pTxDataHead->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, byPktType,
-                                                          wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
-    }
-    else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
-        pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
-        pTxDataHead->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, byPktType,
-                                                          wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
-    }
-
-    BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, byPktType,
-        (unsigned short *)&(wLen), (unsigned char *)&(pTxDataHead->byServiceField), (unsigned char *)&(pTxDataHead->bySignalField)
-    );
-    pTxDataHead->wTransmitLength = cpu_to_le16(wLen);
-    //Get TimeStampOff
-    pTxDataHead->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
-    cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
-
-   //Generate Beacon Header
-    pMACHeader = (PS802_11Header)(pbyBuffer + cbHeaderSize);
-    memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
-
-    pMACHeader->wDurationID = 0;
-    pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
-    pDevice->wSeqCounter++ ;
-    if (pDevice->wSeqCounter > 0x0fff)
-        pDevice->wSeqCounter = 0;
-
-    // Set Beacon buffer length
-    pDevice->wBCNBufLen = pPacket->cbMPDULen + cbHeaderSize;
-
-    MACvSetCurrBCNTxDescAddr(pDevice->PortOffset, (pDevice->tx_beacon_dma));
-
-    MACvSetCurrBCNLength(pDevice->PortOffset, pDevice->wBCNBufLen);
-    // Set auto Transmit on
-    MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
-    // Poll Transmit the adapter
-    MACvTransmitBCN(pDevice->PortOffset);
-
-    return CMD_STATUS_PENDING;
+       unsigned char byPktType;
+       unsigned char *pbyBuffer = (unsigned char *)pDevice->tx_beacon_bufs;
+       unsigned int cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
+       unsigned int cbHeaderSize = 0;
+       unsigned short wTxBufSize = sizeof(STxShortBufHead);
+       PSTxShortBufHead pTxBufHead = (PSTxShortBufHead) pbyBuffer;
+       PSTxDataHead_ab  pTxDataHead = (PSTxDataHead_ab) (pbyBuffer + wTxBufSize);
+       PS802_11Header   pMACHeader;
+       unsigned short wCurrentRate;
+       unsigned short wLen = 0x0000;
+
+       memset(pTxBufHead, 0, wTxBufSize);
+
+       if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
+               wCurrentRate = RATE_6M;
+               byPktType = PK_TYPE_11A;
+       } else {
+               wCurrentRate = RATE_2M;
+               byPktType = PK_TYPE_11B;
+       }
+
+       //Set Preamble type always long
+       pDevice->byPreambleType = PREAMBLE_LONG;
+
+       //Set FIFOCTL_GENINT
+
+       pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
+
+       //Set packet type & Get Duration
+       if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
+               pTxDataHead->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, byPktType,
+                                                                                       wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
+       } else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
+               pTxDataHead->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, byPktType,
+                                                                                       wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
+       }
+
+       BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, byPktType,
+                             (unsigned short *)&(wLen), (unsigned char *)&(pTxDataHead->byServiceField), (unsigned char *)&(pTxDataHead->bySignalField)
+);
+       pTxDataHead->wTransmitLength = cpu_to_le16(wLen);
+       //Get TimeStampOff
+       pTxDataHead->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
+       cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
+
+       //Generate Beacon Header
+       pMACHeader = (PS802_11Header)(pbyBuffer + cbHeaderSize);
+       memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
+
+       pMACHeader->wDurationID = 0;
+       pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
+       pDevice->wSeqCounter++;
+       if (pDevice->wSeqCounter > 0x0fff)
+               pDevice->wSeqCounter = 0;
+
+       // Set Beacon buffer length
+       pDevice->wBCNBufLen = pPacket->cbMPDULen + cbHeaderSize;
+
+       MACvSetCurrBCNTxDescAddr(pDevice->PortOffset, (pDevice->tx_beacon_dma));
+
+       MACvSetCurrBCNLength(pDevice->PortOffset, pDevice->wBCNBufLen);
+       // Set auto Transmit on
+       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
+       // Poll Transmit the adapter
+       MACvTransmitBCN(pDevice->PortOffset);
+
+       return CMD_STATUS_PENDING;
 }
 
-
-
 unsigned int
-cbGetFragCount (
-    PSDevice         pDevice,
-    PSKeyItem        pTransmitKey,
-    unsigned int cbFrameBodySize,
-    PSEthernetHeader psEthHeader
-    )
+cbGetFragCount(
+       PSDevice         pDevice,
+       PSKeyItem        pTransmitKey,
+       unsigned int cbFrameBodySize,
+       PSEthernetHeader psEthHeader
+)
 {
-    unsigned int cbMACHdLen;
-    unsigned int cbFrameSize;
-    unsigned int cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
-    unsigned int cbFragPayloadSize;
-    unsigned int cbLastFragPayloadSize;
-    unsigned int cbIVlen = 0;
-    unsigned int cbICVlen = 0;
-    unsigned int cbMIClen = 0;
-    unsigned int cbFCSlen = 4;
-    unsigned int uMACfragNum = 1;
-    bool bNeedACK;
-
-
-
-    if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
-        (pDevice->eOPMode == OP_MODE_AP)) {
-        if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0])))
-            bNeedACK = false;
-        else
-            bNeedACK = true;
-    }
-    else {
-        // MSDUs in Infra mode always need ACK
-        bNeedACK = true;
-    }
-
-    if (pDevice->bLongHeader)
-        cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
-    else
-        cbMACHdLen = WLAN_HDR_ADDR3_LEN;
-
-
-    if (pDevice->bEncryptionEnable == true) {
-
-        if (pTransmitKey == NULL) {
-            if ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) ||
-                (pDevice->pMgmt->eAuthenMode < WMAC_AUTH_WPA)) {
-                cbIVlen = 4;
-                cbICVlen = 4;
-            } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
-                cbIVlen = 8;//IV+ExtIV
-                cbMIClen = 8;
-                cbICVlen = 4;
-            } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
-                cbIVlen = 8;//RSN Header
-                cbICVlen = 8;//MIC
-            }
-        } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
-            cbIVlen = 4;
-            cbICVlen = 4;
-        } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
-            cbIVlen = 8;//IV+ExtIV
-            cbMIClen = 8;
-            cbICVlen = 4;
-        } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
-            cbIVlen = 8;//RSN Header
-            cbICVlen = 8;//MIC
-        }
-    }
-
-    cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
-
-    if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == true)) {
-        // Fragmentation
-        cbFragmentSize = pDevice->wFragmentationThreshold;
-        cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
-        uMACfragNum = (unsigned short) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
-        cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
-        if (cbLastFragPayloadSize == 0) {
-            cbLastFragPayloadSize = cbFragPayloadSize;
-        } else {
-            uMACfragNum++;
-        }
-    }
-    return uMACfragNum;
+       unsigned int cbMACHdLen;
+       unsigned int cbFrameSize;
+       unsigned int cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
+       unsigned int cbFragPayloadSize;
+       unsigned int cbLastFragPayloadSize;
+       unsigned int cbIVlen = 0;
+       unsigned int cbICVlen = 0;
+       unsigned int cbMIClen = 0;
+       unsigned int cbFCSlen = 4;
+       unsigned int uMACfragNum = 1;
+       bool bNeedACK;
+
+       if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
+           (pDevice->eOPMode == OP_MODE_AP)) {
+               if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0])))
+                       bNeedACK = false;
+               else
+                       bNeedACK = true;
+       } else {
+               // MSDUs in Infra mode always need ACK
+               bNeedACK = true;
+       }
+
+       if (pDevice->bLongHeader)
+               cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
+       else
+               cbMACHdLen = WLAN_HDR_ADDR3_LEN;
+
+       if (pDevice->bEncryptionEnable == true) {
+               if (pTransmitKey == NULL) {
+                       if ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) ||
+                           (pDevice->pMgmt->eAuthenMode < WMAC_AUTH_WPA)) {
+                               cbIVlen = 4;
+                               cbICVlen = 4;
+                       } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
+                               cbIVlen = 8;//IV+ExtIV
+                               cbMIClen = 8;
+                               cbICVlen = 4;
+                       } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
+                               cbIVlen = 8;//RSN Header
+                               cbICVlen = 8;//MIC
+                       }
+               } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
+                       cbIVlen = 4;
+                       cbICVlen = 4;
+               } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
+                       cbIVlen = 8;//IV+ExtIV
+                       cbMIClen = 8;
+                       cbICVlen = 4;
+               } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
+                       cbIVlen = 8;//RSN Header
+                       cbICVlen = 8;//MIC
+               }
+       }
+
+       cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
+
+       if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == true)) {
+               // Fragmentation
+               cbFragmentSize = pDevice->wFragmentationThreshold;
+               cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
+               uMACfragNum = (unsigned short) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
+               cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
+               if (cbLastFragPayloadSize == 0) {
+                       cbLastFragPayloadSize = cbFragPayloadSize;
+               } else {
+                       uMACfragNum++;
+               }
+       }
+       return uMACfragNum;
 }
 
-
 void
 vDMA0_tx_80211(PSDevice  pDevice, struct sk_buff *skb, unsigned char *pbMPDU, unsigned int cbMPDULen) {
-
-    PSTxDesc        pFrstTD;
-    unsigned char byPktType;
-    unsigned char *pbyTxBufferAddr;
-    void *          pvRTS;
-    void *          pvCTS;
-    void *          pvTxDataHd;
-    unsigned int uDuration;
-    unsigned int cbReqCount;
-    PS802_11Header  pMACHeader;
-    unsigned int cbHeaderSize;
-    unsigned int cbFrameBodySize;
-    bool bNeedACK;
-    bool bIsPSPOLL = false;
-    PSTxBufHead     pTxBufHead;
-    unsigned int cbFrameSize;
-    unsigned int cbIVlen = 0;
-    unsigned int cbICVlen = 0;
-    unsigned int cbMIClen = 0;
-    unsigned int cbFCSlen = 4;
-    unsigned int uPadding = 0;
-    unsigned int cbMICHDR = 0;
-    unsigned int uLength = 0;
-    unsigned long dwMICKey0, dwMICKey1;
-    unsigned long dwMIC_Priority;
-    unsigned long *pdwMIC_L;
-    unsigned long *pdwMIC_R;
-    unsigned short wTxBufSize;
-    unsigned int cbMacHdLen;
-    SEthernetHeader sEthHeader;
-    void *          pvRrvTime;
-    void *          pMICHDR;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned short wCurrentRate = RATE_1M;
-    PUWLAN_80211HDR  p80211Header;
-    unsigned int uNodeIndex = 0;
-    bool bNodeExist = false;
-    SKeyItem        STempKey;
-    PSKeyItem       pTransmitKey = NULL;
-    unsigned char *pbyIVHead;
-    unsigned char *pbyPayloadHead;
-    unsigned char *pbyMacHdr;
-
-    unsigned int cbExtSuppRate = 0;
+       PSTxDesc        pFrstTD;
+       unsigned char byPktType;
+       unsigned char *pbyTxBufferAddr;
+       void *pvRTS;
+       void *pvCTS;
+       void *pvTxDataHd;
+       unsigned int uDuration;
+       unsigned int cbReqCount;
+       PS802_11Header  pMACHeader;
+       unsigned int cbHeaderSize;
+       unsigned int cbFrameBodySize;
+       bool bNeedACK;
+       bool bIsPSPOLL = false;
+       PSTxBufHead     pTxBufHead;
+       unsigned int cbFrameSize;
+       unsigned int cbIVlen = 0;
+       unsigned int cbICVlen = 0;
+       unsigned int cbMIClen = 0;
+       unsigned int cbFCSlen = 4;
+       unsigned int uPadding = 0;
+       unsigned int cbMICHDR = 0;
+       unsigned int uLength = 0;
+       unsigned long dwMICKey0, dwMICKey1;
+       unsigned long dwMIC_Priority;
+       unsigned long *pdwMIC_L;
+       unsigned long *pdwMIC_R;
+       unsigned short wTxBufSize;
+       unsigned int cbMacHdLen;
+       SEthernetHeader sEthHeader;
+       void *pvRrvTime;
+       void *pMICHDR;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned short wCurrentRate = RATE_1M;
+       PUWLAN_80211HDR  p80211Header;
+       unsigned int uNodeIndex = 0;
+       bool bNodeExist = false;
+       SKeyItem        STempKey;
+       PSKeyItem       pTransmitKey = NULL;
+       unsigned char *pbyIVHead;
+       unsigned char *pbyPayloadHead;
+       unsigned char *pbyMacHdr;
+
+       unsigned int cbExtSuppRate = 0;
 //    PWLAN_IE        pItem;
 
-
-    pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
-
-    if(cbMPDULen <= WLAN_HDR_ADDR3_LEN) {
-       cbFrameBodySize = 0;
-    }
-    else {
-       cbFrameBodySize = cbMPDULen - WLAN_HDR_ADDR3_LEN;
-    }
-    p80211Header = (PUWLAN_80211HDR)pbMPDU;
-
-
-    pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
-    pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf;
-    pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
-    wTxBufSize = sizeof(STxBufHead);
-    memset(pTxBufHead, 0, wTxBufSize);
-
-    if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
-        wCurrentRate = RATE_6M;
-        byPktType = PK_TYPE_11A;
-    } else {
-        wCurrentRate = RATE_1M;
-        byPktType = PK_TYPE_11B;
-    }
-
-    // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
-    // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
-    //                    And cmd timer will wait data pkt TX to finish before scanning so it's OK
-    //                    to set power here.
-    if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
-        RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
-    } else {
-        RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
-    }
-    pTxBufHead->byTxPower = pDevice->byCurPwr;
-
-    //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
-    if (pDevice->byFOETuning) {
-        if ((p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
-            wCurrentRate = RATE_24M;
-            byPktType = PK_TYPE_11GA;
-        }
-    }
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
-
-    //Set packet type
-    if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
-        pTxBufHead->wFIFOCtl = 0;
-    }
-    else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
-        pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
-    }
-    else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
-        pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
-    }
-    else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
-        pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
-    }
-
-    pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
-    pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
-
-
-    if (is_multicast_ether_addr(&(p80211Header->sA3.abyAddr1[0]))) {
-        bNeedACK = false;
-        if (pDevice->bEnableHostWEP) {
-            uNodeIndex = 0;
-            bNodeExist = true;
-        }
-    }
-    else {
-        if (pDevice->bEnableHostWEP) {
-            if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, (unsigned char *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
-                bNodeExist = true;
-        }
-        bNeedACK = true;
-        pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
-    };
-
-    if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
-        (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
-
-        pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
-        //Set Preamble type always long
-        //pDevice->byPreambleType = PREAMBLE_LONG;
-
-        // probe-response don't retry
-        //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
-        //     bNeedACK = false;
-        //     pTxBufHead->wFIFOCtl  &= (~FIFOCTL_NEEDACK);
-        //}
-    }
-
-    pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
-
-    if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
-        bIsPSPOLL = true;
-        cbMacHdLen = WLAN_HDR_ADDR2_LEN;
-    } else {
-        cbMacHdLen = WLAN_HDR_ADDR3_LEN;
-    }
-
-    // hostapd deamon ext support rate patch
-    if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
-
-        if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
-            cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
-         }
-
-        if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
-            cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
-         }
-
-         if (cbExtSuppRate >0) {
-            cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
-         }
-    }
-
-
-    //Set FRAGCTL_MACHDCNT
-    pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)cbMacHdLen << 10);
-
-    // Notes:
-    // Although spec says MMPDU can be fragmented; In most cases,
-    // no one will send a MMPDU under fragmentation. With RTS may occur.
-    pDevice->bAES = false;  //Set FRAGCTL_WEPTYP
-
-
-    if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
-        if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
-            cbIVlen = 4;
-            cbICVlen = 4;
-           pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
-        }
-        else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
-            cbIVlen = 8;//IV+ExtIV
-            cbMIClen = 8;
-            cbICVlen = 4;
-           pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
-           //We need to get seed here for filling TxKey entry.
-            //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
-            //            pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
-        }
-        else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
-            cbIVlen = 8;//RSN Header
-            cbICVlen = 8;//MIC
-            cbMICHDR = sizeof(SMICHDRHead);
-            pTxBufHead->wFragCtl |= FRAGCTL_AES;
-            pDevice->bAES = true;
-        }
-        //MAC Header should be padding 0 to DW alignment.
-        uPadding = 4 - (cbMacHdLen%4);
-        uPadding %= 4;
-    }
-
-    cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
-
-    //Set FIFOCTL_GrpAckPolicy
-    if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
-        pTxBufHead->wFIFOCtl |=        FIFOCTL_GRPACK;
-    }
-    //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
-
-
-    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
-
-        pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
-        pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
-        pvRTS = NULL;
-        pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
-        pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
-        cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
-
-    }
-    else {//802.11a/b packet
-
-        pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
-        pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
-        pvRTS = NULL;
-        pvCTS = NULL;
-        pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
-        cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
-
-    }
-
-    memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
-    memcpy(&(sEthHeader.abyDstAddr[0]), &(p80211Header->sA3.abyAddr1[0]), ETH_ALEN);
-    memcpy(&(sEthHeader.abySrcAddr[0]), &(p80211Header->sA3.abyAddr2[0]), ETH_ALEN);
-    //=========================
-    //    No Fragmentation
-    //=========================
-    pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
-
-
-    //Fill FIFO,RrvTime,RTS,and CTS
-    s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
-                           cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
-
-    //Fill DataHead
-    uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
-                                0, 0, 1, AUTO_FB_NONE, wCurrentRate);
-
-    pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
-
-    cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
-
-    pbyMacHdr = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize);
-    pbyPayloadHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
-    pbyIVHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding);
-
-    // Copy the Packet into a tx Buffer
-    memcpy(pbyMacHdr, pbMPDU, cbMacHdLen);
-
-    // version set to 0, patch for hostapd deamon
-    pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
-    memcpy(pbyPayloadHead, (pbMPDU + cbMacHdLen), cbFrameBodySize);
-
-    // replace support rate, patch for hostapd deamon( only support 11M)
-    if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
-        if (cbExtSuppRate != 0) {
-            if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
-                memcpy((pbyPayloadHead + cbFrameBodySize),
-                        pMgmt->abyCurrSuppRates,
-                        ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
-                       );
-             if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
-                memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
-                        pMgmt->abyCurrExtSuppRates,
-                        ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
-                       );
-         }
-    }
-
-    // Set wep
-    if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
-
-        if (pDevice->bEnableHostWEP) {
-            pTransmitKey = &STempKey;
-            pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
-            pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
-            pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
-            pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
-            pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
-            memcpy(pTransmitKey->abyKey,
-                &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
-                pTransmitKey->uKeyLength
-                );
-        }
-
-        if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
-
-            dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
-            dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
-
-            // DO Software Michael
-            MIC_vInit(dwMICKey0, dwMICKey1);
-            MIC_vAppend((unsigned char *)&(sEthHeader.abyDstAddr[0]), 12);
-            dwMIC_Priority = 0;
-            MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
-
-            uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
-
-            MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
-
-            pdwMIC_L = (unsigned long *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
-            pdwMIC_R = (unsigned long *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
-
-            MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
-            MIC_vUnInit();
-
-            if (pDevice->bTxMICFail == true) {
-                *pdwMIC_L = 0;
-                *pdwMIC_R = 0;
-                pDevice->bTxMICFail = false;
-            }
-
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
-
-        }
-
-
-        s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
-                     pbyMacHdr, (unsigned short)cbFrameBodySize, (unsigned char *)pMICHDR);
-
-        if (pDevice->bEnableHostWEP) {
-            pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
-            pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
-        }
-
-        if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
-            s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (unsigned short)(cbFrameBodySize + cbMIClen));
-        }
-    }
-
-    pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
-    pDevice->wSeqCounter++ ;
-    if (pDevice->wSeqCounter > 0x0fff)
-        pDevice->wSeqCounter = 0;
-
-
-    if (bIsPSPOLL) {
-        // The MAC will automatically replace the Duration-field of MAC header by Duration-field
-        // of  FIFO control header.
-        // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
-        // in the same place of other packet's Duration-field).
-        // And it will cause Cisco-AP to issue Disassociation-packet
-        if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
-            ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
-            ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
-        } else {
-            ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
-        }
-    }
-
-
-    // first TD is the only TD
-    //Set TSR1 & ReqCount in TxDescHead
-    pFrstTD->pTDInfo->skb = skb;
-    pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
-    pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
-    pFrstTD->m_td1TD1.wReqCount = cpu_to_le16(cbReqCount);
-    pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
-    pFrstTD->pTDInfo->byFlags = 0;
-    pFrstTD->pTDInfo->byFlags |= TD_FLAGS_PRIV_SKB;
-
-    if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
-        // Disable PS
-        MACbPSWakeup(pDevice->PortOffset);
-    }
-    pDevice->bPWBitOn = false;
-
-    wmb();
-    pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
-    wmb();
-
-    pDevice->iTDUsed[TYPE_TXDMA0]++;
-
-    if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
-    }
-
-    pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
-
-    // Poll Transmit the adapter
-    MACvTransmit0(pDevice->PortOffset);
-
-    return;
+       pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
+
+       if (cbMPDULen <= WLAN_HDR_ADDR3_LEN) {
+               cbFrameBodySize = 0;
+       } else {
+               cbFrameBodySize = cbMPDULen - WLAN_HDR_ADDR3_LEN;
+       }
+       p80211Header = (PUWLAN_80211HDR)pbMPDU;
+
+       pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
+       pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf;
+       pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
+       wTxBufSize = sizeof(STxBufHead);
+       memset(pTxBufHead, 0, wTxBufSize);
+
+       if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
+               wCurrentRate = RATE_6M;
+               byPktType = PK_TYPE_11A;
+       } else {
+               wCurrentRate = RATE_1M;
+               byPktType = PK_TYPE_11B;
+       }
+
+       // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
+       // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
+       //                    And cmd timer will wait data pkt TX to finish before scanning so it's OK
+       //                    to set power here.
+       if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
+               RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
+       } else {
+               RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
+       }
+       pTxBufHead->byTxPower = pDevice->byCurPwr;
+
+       //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
+       if (pDevice->byFOETuning) {
+               if ((p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
+                       wCurrentRate = RATE_24M;
+                       byPktType = PK_TYPE_11GA;
+               }
+       }
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
+
+       //Set packet type
+       if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
+               pTxBufHead->wFIFOCtl = 0;
+       } else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
+       } else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
+       } else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
+       }
+
+       pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
+       pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
+
+       if (is_multicast_ether_addr(&(p80211Header->sA3.abyAddr1[0]))) {
+               bNeedACK = false;
+               if (pDevice->bEnableHostWEP) {
+                       uNodeIndex = 0;
+                       bNodeExist = true;
+               }
+       } else {
+               if (pDevice->bEnableHostWEP) {
+                       if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, (unsigned char *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
+                               bNodeExist = true;
+               }
+               bNeedACK = true;
+               pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
+       };
+
+       if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
+           (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
+               pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
+       }
+
+       pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
+
+       if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
+               bIsPSPOLL = true;
+               cbMacHdLen = WLAN_HDR_ADDR2_LEN;
+       } else {
+               cbMacHdLen = WLAN_HDR_ADDR3_LEN;
+       }
+
+       // hostapd deamon ext support rate patch
+       if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
+               if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
+                       cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
+               }
+
+               if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
+                       cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
+               }
+
+               if (cbExtSuppRate > 0) {
+                       cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
+               }
+       }
+
+       //Set FRAGCTL_MACHDCNT
+       pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)cbMacHdLen << 10);
+
+       // Notes:
+       // Although spec says MMPDU can be fragmented; In most cases,
+       // no one will send a MMPDU under fragmentation. With RTS may occur.
+       pDevice->bAES = false;  //Set FRAGCTL_WEPTYP
+
+       if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
+               if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
+                       cbIVlen = 4;
+                       cbICVlen = 4;
+                       pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
+               } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
+                       cbIVlen = 8;//IV+ExtIV
+                       cbMIClen = 8;
+                       cbICVlen = 4;
+                       pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
+                       //We need to get seed here for filling TxKey entry.
+                       //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
+                       //            pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
+               } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
+                       cbIVlen = 8;//RSN Header
+                       cbICVlen = 8;//MIC
+                       cbMICHDR = sizeof(SMICHDRHead);
+                       pTxBufHead->wFragCtl |= FRAGCTL_AES;
+                       pDevice->bAES = true;
+               }
+               //MAC Header should be padding 0 to DW alignment.
+               uPadding = 4 - (cbMacHdLen%4);
+               uPadding %= 4;
+       }
+
+       cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
+
+       //Set FIFOCTL_GrpAckPolicy
+       if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
+               pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
+       }
+       //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
+
+       if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
+
+               pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
+               pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
+               pvRTS = NULL;
+               pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
+               pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
+               cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
+
+       } else {//802.11a/b packet
+
+               pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
+               pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
+               pvRTS = NULL;
+               pvCTS = NULL;
+               pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
+               cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
+
+       }
+
+       memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
+       memcpy(&(sEthHeader.abyDstAddr[0]), &(p80211Header->sA3.abyAddr1[0]), ETH_ALEN);
+       memcpy(&(sEthHeader.abySrcAddr[0]), &(p80211Header->sA3.abyAddr2[0]), ETH_ALEN);
+       //=========================
+       //    No Fragmentation
+       //=========================
+       pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
+
+       //Fill FIFO,RrvTime,RTS,and CTS
+       s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
+                              cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
+
+       //Fill DataHead
+       uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
+                                   0, 0, 1, AUTO_FB_NONE, wCurrentRate);
+
+       pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
+
+       cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
+
+       pbyMacHdr = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize);
+       pbyPayloadHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
+       pbyIVHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding);
+
+       // Copy the Packet into a tx Buffer
+       memcpy(pbyMacHdr, pbMPDU, cbMacHdLen);
+
+       // version set to 0, patch for hostapd deamon
+       pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
+       memcpy(pbyPayloadHead, (pbMPDU + cbMacHdLen), cbFrameBodySize);
+
+       // replace support rate, patch for hostapd deamon(only support 11M)
+       if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
+               if (cbExtSuppRate != 0) {
+                       if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
+                               memcpy((pbyPayloadHead + cbFrameBodySize),
+                                      pMgmt->abyCurrSuppRates,
+                                      ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
+);
+                       if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
+                               memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
+                                      pMgmt->abyCurrExtSuppRates,
+                                      ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
+);
+               }
+       }
+
+       // Set wep
+       if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
+               if (pDevice->bEnableHostWEP) {
+                       pTransmitKey = &STempKey;
+                       pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
+                       pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
+                       pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
+                       pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
+                       pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
+                       memcpy(pTransmitKey->abyKey,
+                              &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
+                              pTransmitKey->uKeyLength
+);
+               }
+
+               if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
+                       dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
+                       dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
+
+                       // DO Software Michael
+                       MIC_vInit(dwMICKey0, dwMICKey1);
+                       MIC_vAppend((unsigned char *)&(sEthHeader.abyDstAddr[0]), 12);
+                       dwMIC_Priority = 0;
+                       MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
+
+                       uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
+
+                       MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
+
+                       pdwMIC_L = (unsigned long *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
+                       pdwMIC_R = (unsigned long *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
+
+                       MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
+                       MIC_vUnInit();
+
+                       if (pDevice->bTxMICFail == true) {
+                               *pdwMIC_L = 0;
+                               *pdwMIC_R = 0;
+                               pDevice->bTxMICFail = false;
+                       }
+
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "uLength: %d, %d\n", uLength, cbFrameBodySize);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
+
+               }
+
+               s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
+                            pbyMacHdr, (unsigned short)cbFrameBodySize, (unsigned char *)pMICHDR);
+
+               if (pDevice->bEnableHostWEP) {
+                       pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
+                       pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
+               }
+
+               if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
+                       s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (unsigned short)(cbFrameBodySize + cbMIClen));
+               }
+       }
+
+       pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
+       pDevice->wSeqCounter++;
+       if (pDevice->wSeqCounter > 0x0fff)
+               pDevice->wSeqCounter = 0;
+
+       if (bIsPSPOLL) {
+               // The MAC will automatically replace the Duration-field of MAC header by Duration-field
+               // of  FIFO control header.
+               // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
+               // in the same place of other packet's Duration-field).
+               // And it will cause Cisco-AP to issue Disassociation-packet
+               if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
+                       ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
+                       ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
+               } else {
+                       ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
+               }
+       }
+
+       // first TD is the only TD
+       //Set TSR1 & ReqCount in TxDescHead
+       pFrstTD->pTDInfo->skb = skb;
+       pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
+       pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
+       pFrstTD->m_td1TD1.wReqCount = cpu_to_le16(cbReqCount);
+       pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
+       pFrstTD->pTDInfo->byFlags = 0;
+       pFrstTD->pTDInfo->byFlags |= TD_FLAGS_PRIV_SKB;
+
+       if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
+               // Disable PS
+               MACbPSWakeup(pDevice->PortOffset);
+       }
+       pDevice->bPWBitOn = false;
+
+       wmb();
+       pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
+       wmb();
+
+       pDevice->iTDUsed[TYPE_TXDMA0]++;
+
+       if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
+       }
+
+       pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
+
+       // Poll Transmit the adapter
+       MACvTransmit0(pDevice->PortOffset);
+
+       return;
 }
-
-
index fa827b828a300d9d8c19a9d9aab74b4c55d1f3a2..4f2cf34dc39fef22b8e95eab1b6e03e798f5ec39 100644 (file)
 /*---------------------  Export Functions  --------------------------*/
 
 /*
-void
-vGenerateMACHeader(PSDevice pDevice, unsigned long dwTxBufferAddr, unsigned char *pbySkbData,
-       unsigned int cbPacketSize, bool bDMA0Used, unsigned int *pcbHeadSize,
-       unsigned int *pcbAppendPayload);
-
-void
-vProcessRxMACHeader(PSDevice pDevice, unsigned long dwRxBufferAddr, unsigned int cbPacketSize,
-       bool bIsWEP, unsigned int *pcbHeadSize);
+  void
+  vGenerateMACHeader(PSDevice pDevice, unsigned long dwTxBufferAddr, unsigned char *pbySkbData,
+  unsigned int cbPacketSize, bool bDMA0Used, unsigned int *pcbHeadSize,
+  unsigned int *pcbAppendPayload);
+
+  void
+  vProcessRxMACHeader(PSDevice pDevice, unsigned long dwRxBufferAddr, unsigned int cbPacketSize,
+  bool bIsWEP, unsigned int *pcbHeadSize);
 */
 
-
 void
-vGenerateMACHeader (
-    PSDevice         pDevice,
-    unsigned char *pbyBufferAddr,
-    unsigned short wDuration,
-    PSEthernetHeader psEthHeader,
-    bool bNeedEncrypt,
-    unsigned short wFragType,
-    unsigned int uDMAIdx,
-    unsigned int uFragIdx
-    );
-
+vGenerateMACHeader(
+       PSDevice         pDevice,
+       unsigned char *pbyBufferAddr,
+       unsigned short wDuration,
+       PSEthernetHeader psEthHeader,
+       bool bNeedEncrypt,
+       unsigned short wFragType,
+       unsigned int uDMAIdx,
+       unsigned int uFragIdx
+);
 
 unsigned int
 cbGetFragCount(
-    PSDevice         pDevice,
-    PSKeyItem        pTransmitKey,
-    unsigned int       cbFrameBodySize,
-    PSEthernetHeader psEthHeader
-    );
-
+       PSDevice         pDevice,
+       PSKeyItem        pTransmitKey,
+       unsigned int    cbFrameBodySize,
+       PSEthernetHeader psEthHeader
+);
 
 void
 vGenerateFIFOHeader(PSDevice pDevice, unsigned char byPktTyp, unsigned char *pbyTxBufferAddr,
-       bool bNeedEncrypt, unsigned int cbPayloadSize, unsigned int uDMAIdx, PSTxDesc pHeadTD,
-       PSEthernetHeader psEthHeader, unsigned char *pPacket, PSKeyItem pTransmitKey,
-       unsigned int uNodeIndex, unsigned int *puMACfragNum, unsigned int *pcbHeaderSize);
-
+                   bool bNeedEncrypt, unsigned int     cbPayloadSize, unsigned int uDMAIdx, PSTxDesc pHeadTD,
+                   PSEthernetHeader psEthHeader, unsigned char *pPacket, PSKeyItem pTransmitKey,
+                   unsigned int uNodeIndex, unsigned int *puMACfragNum, unsigned int *pcbHeaderSize);
 
 void vDMA0_tx_80211(PSDevice  pDevice, struct sk_buff *skb, unsigned char *pbMPDU, unsigned int cbMPDULen);
 CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket);
index 6a0a232d1a0c80b14d53f9312f0fb870a31a3b7e..eaddc33c9d2d79d2855d6103cc634ded3dd78dc0 100644 (file)
@@ -60,9 +60,6 @@
 
 /*---------------------  Export Functions  --------------------------*/
 
-
-
-
 /*
  * Description: Read a byte from EEPROM, by MAC I2C
  *
  */
 unsigned char SROMbyReadEmbedded(unsigned long dwIoBase, unsigned char byContntOffset)
 {
-    unsigned short wDelay, wNoACK;
-    unsigned char byWait;
-    unsigned char byData;
-    unsigned char byOrg;
-
-    byData = 0xFF;
-    VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
-    /* turn off hardware retry for getting NACK */
-    VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
-    for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
-        VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
-        VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
-
-        /* issue read command */
-        VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMR);
-        /* wait DONE be set */
-        for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
-            VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
-            if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
-                break;
-            PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
-        }
-        if ((wDelay < W_MAX_TIMEOUT) &&
-             !(byWait & I2MCSR_NACK))) {
-            break;
-        }
-    }
-    VNSvInPortB(dwIoBase + MAC_REG_I2MDIPT, &byData);
-    VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
-    return byData;
+       unsigned short wDelay, wNoACK;
+       unsigned char byWait;
+       unsigned char byData;
+       unsigned char byOrg;
+
+       byData = 0xFF;
+       VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
+       /* turn off hardware retry for getting NACK */
+       VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
+       for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
+               VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
+               VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
+
+               /* issue read command */
+               VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMR);
+               /* wait DONE be set */
+               for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
+                       VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
+                       if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
+                               break;
+                       PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
+               }
+               if ((wDelay < W_MAX_TIMEOUT) &&
+                   (!(byWait & I2MCSR_NACK))) {
+                       break;
+               }
+       }
+       VNSvInPortB(dwIoBase + MAC_REG_I2MDIPT, &byData);
+       VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
+       return byData;
 }
 
-
 /*
  * Description: Write a byte to EEPROM, by MAC I2C
  *
@@ -127,43 +123,42 @@ unsigned char SROMbyReadEmbedded(unsigned long dwIoBase, unsigned char byContntO
  */
 bool SROMbWriteEmbedded(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byData)
 {
-    unsigned short wDelay, wNoACK;
-    unsigned char byWait;
-
-    unsigned char byOrg;
-
-    VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
-    /* turn off hardware retry for getting NACK */
-    VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
-    for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
-        VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
-        VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
-        VNSvOutPortB(dwIoBase + MAC_REG_I2MDOPT, byData);
-
-        /* issue write command */
-        VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMW);
-        /* wait DONE be set */
-        for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
-            VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
-            if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
-                break;
-            PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
-        }
-
-        if ((wDelay < W_MAX_TIMEOUT) &&
-             !(byWait & I2MCSR_NACK))) {
-            break;
-        }
-    }
-    if (wNoACK == W_MAX_I2CRETRY) {
-        VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
-        return false;
-    }
-    VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
-    return true;
+       unsigned short wDelay, wNoACK;
+       unsigned char byWait;
+
+       unsigned char byOrg;
+
+       VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
+       /* turn off hardware retry for getting NACK */
+       VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
+       for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
+               VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
+               VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
+               VNSvOutPortB(dwIoBase + MAC_REG_I2MDOPT, byData);
+
+               /* issue write command */
+               VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMW);
+               /* wait DONE be set */
+               for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
+                       VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
+                       if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
+                               break;
+                       PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
+               }
+
+               if ((wDelay < W_MAX_TIMEOUT) &&
+                   (!(byWait & I2MCSR_NACK))) {
+                       break;
+               }
+       }
+       if (wNoACK == W_MAX_I2CRETRY) {
+               VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
+               return false;
+       }
+       VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
+       return true;
 }
 
-
 /*
  * Description: Turn bits on in eeprom
  *
@@ -180,13 +175,12 @@ bool SROMbWriteEmbedded(unsigned long dwIoBase, unsigned char byContntOffset, un
  */
 void SROMvRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byBits)
 {
-    unsigned char byOrgData;
+       unsigned char byOrgData;
 
-    byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
-    SROMbWriteEmbedded(dwIoBase, byContntOffset,(unsigned char)(byOrgData | byBits));
+       byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
+       SROMbWriteEmbedded(dwIoBase, byContntOffset, (unsigned char)(byOrgData | byBits));
 }
 
-
 /*
  * Description: Turn bits off in eeprom
  *
@@ -201,13 +195,12 @@ void SROMvRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsign
  */
 void SROMvRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byBits)
 {
-    unsigned char byOrgData;
+       unsigned char byOrgData;
 
-    byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
-    SROMbWriteEmbedded(dwIoBase, byContntOffset,(unsigned char)(byOrgData & (~byBits)));
+       byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
+       SROMbWriteEmbedded(dwIoBase, byContntOffset, (unsigned char)(byOrgData & (~byBits)));
 }
 
-
 /*
  * Description: Test if bits on in eeprom
  *
@@ -224,13 +217,12 @@ void SROMvRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, unsig
  */
 bool SROMbIsRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byTestBits)
 {
-    unsigned char byOrgData;
+       unsigned char byOrgData;
 
-    byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
-    return (byOrgData & byTestBits) == byTestBits;
+       byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
+       return (byOrgData & byTestBits) == byTestBits;
 }
 
-
 /*
  * Description: Test if bits off in eeprom
  *
@@ -247,13 +239,12 @@ bool SROMbIsRegBitsOn(unsigned long dwIoBase, unsigned char byContntOffset, unsi
  */
 bool SROMbIsRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, unsigned char byTestBits)
 {
-    unsigned char byOrgData;
+       unsigned char byOrgData;
 
-    byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
-    return !(byOrgData & byTestBits);
+       byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
+       return !(byOrgData & byTestBits);
 }
 
-
 /*
  * Description: Read all contents of eeprom to buffer
  *
@@ -268,16 +259,15 @@ bool SROMbIsRegBitsOff(unsigned long dwIoBase, unsigned char byContntOffset, uns
  */
 void SROMvReadAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs)
 {
-    int     ii;
+       int     ii;
 
-    /* ii = Rom Address */
-    for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
-        *pbyEepromRegs = SROMbyReadEmbedded(dwIoBase,(unsigned char) ii);
-        pbyEepromRegs++;
-    }
+       /* ii = Rom Address */
+       for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
+               *pbyEepromRegs = SROMbyReadEmbedded(dwIoBase, (unsigned char)ii);
+               pbyEepromRegs++;
+       }
 }
 
-
 /*
  * Description: Write all contents of buffer to eeprom
  *
@@ -293,16 +283,15 @@ void SROMvReadAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs)
  */
 void SROMvWriteAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs)
 {
-    int     ii;
+       int     ii;
 
-    /* ii = Rom Address */
-    for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
-        SROMbWriteEmbedded(dwIoBase,(unsigned char) ii, *pbyEepromRegs);
-        pbyEepromRegs++;
-    }
+       /* ii = Rom Address */
+       for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
+               SROMbWriteEmbedded(dwIoBase, (unsigned char)ii, *pbyEepromRegs);
+               pbyEepromRegs++;
+       }
 }
 
-
 /*
  * Description: Read Ethernet Address from eeprom to buffer
  *
@@ -317,16 +306,15 @@ void SROMvWriteAllContents(unsigned long dwIoBase, unsigned char *pbyEepromRegs)
  */
 void SROMvReadEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddress)
 {
-    unsigned char ii;
+       unsigned char ii;
 
-    /* ii = Rom Address */
-    for (ii = 0; ii < ETH_ALEN; ii++) {
-        *pbyEtherAddress = SROMbyReadEmbedded(dwIoBase, ii);
-        pbyEtherAddress++;
-    }
+       /* ii = Rom Address */
+       for (ii = 0; ii < ETH_ALEN; ii++) {
+               *pbyEtherAddress = SROMbyReadEmbedded(dwIoBase, ii);
+               pbyEtherAddress++;
+       }
 }
 
-
 /*
  * Description: Write Ethernet Address from buffer to eeprom
  *
@@ -342,16 +330,15 @@ void SROMvReadEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddres
  */
 void SROMvWriteEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddress)
 {
-    unsigned char ii;
+       unsigned char ii;
 
-    /* ii = Rom Address */
-    for (ii = 0; ii < ETH_ALEN; ii++) {
-        SROMbWriteEmbedded(dwIoBase, ii, *pbyEtherAddress);
-        pbyEtherAddress++;
-    }
+       /* ii = Rom Address */
+       for (ii = 0; ii < ETH_ALEN; ii++) {
+               SROMbWriteEmbedded(dwIoBase, ii, *pbyEtherAddress);
+               pbyEtherAddress++;
+       }
 }
 
-
 /*
  * Description: Read Sub_VID and Sub_SysId from eeprom to buffer
  *
@@ -366,15 +353,15 @@ void SROMvWriteEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddre
  */
 void SROMvReadSubSysVenId(unsigned long dwIoBase, unsigned long *pdwSubSysVenId)
 {
-    unsigned char *pbyData;
-
-    pbyData = (unsigned char *)pdwSubSysVenId;
-    /* sub vendor */
-    *pbyData = SROMbyReadEmbedded(dwIoBase, 6);
-    *(pbyData+1) = SROMbyReadEmbedded(dwIoBase, 7);
-    /* sub system */
-    *(pbyData+2) = SROMbyReadEmbedded(dwIoBase, 8);
-    *(pbyData+3) = SROMbyReadEmbedded(dwIoBase, 9);
+       unsigned char *pbyData;
+
+       pbyData = (unsigned char *)pdwSubSysVenId;
+       /* sub vendor */
+       *pbyData = SROMbyReadEmbedded(dwIoBase, 6);
+       *(pbyData+1) = SROMbyReadEmbedded(dwIoBase, 7);
+       /* sub system */
+       *(pbyData+2) = SROMbyReadEmbedded(dwIoBase, 8);
+       *(pbyData+3) = SROMbyReadEmbedded(dwIoBase, 9);
 }
 
 /*
@@ -391,30 +378,28 @@ void SROMvReadSubSysVenId(unsigned long dwIoBase, unsigned long *pdwSubSysVenId)
  */
 bool SROMbAutoLoad(unsigned long dwIoBase)
 {
-    unsigned char byWait;
-    int     ii;
+       unsigned char byWait;
+       int     ii;
 
-    unsigned char byOrg;
+       unsigned char byOrg;
 
-    VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
-    /* turn on hardware retry */
-    VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg | I2MCFG_NORETRY));
+       VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
+       /* turn on hardware retry */
+       VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg | I2MCFG_NORETRY));
 
-    MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD);
+       MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD);
 
-    /* ii = Rom Address */
-    for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
-        MACvTimer0MicroSDelay(dwIoBase, CB_EEPROM_READBYTE_WAIT);
-        VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
-        if ( !(byWait & I2MCSR_AUTOLD))
-            break;
-    }
+       /* ii = Rom Address */
+       for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
+               MACvTimer0MicroSDelay(dwIoBase, CB_EEPROM_READBYTE_WAIT);
+               VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
+               if (!(byWait & I2MCSR_AUTOLD))
+                       break;
+       }
 
-    VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
+       VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
 
-    if (ii == EEP_MAX_CONTEXT_SIZE)
-        return false;
-    return true;
+       if (ii == EEP_MAX_CONTEXT_SIZE)
+               return false;
+       return true;
 }
-
-
index 4c261dac01b5b1bcec5e9a39cc8fd438e21c990e..1df58c516ddc94a9f6ad1bd7ff000fe76e8243ec 100644 (file)
@@ -69,7 +69,6 @@
 //}}
 #define EEP_OFS_OFDMA_PWR_dBm       0xD2
 
-
 //----------need to remove --------------------
 #define EEP_OFS_BBTAB_LEN   0x70        // BB Table Length
 #define EEP_OFS_BBTAB_ADR   0x71        // BB Table Offset
@@ -77,7 +76,6 @@
 
 #define EEP_I2C_DEV_ID      0x50        // EEPROM device address on the I2C bus
 
-
 //
 // Bits in EEP_OFS_ANTENNA
 //
 //      2048 bits = 256 bytes = 128 words
 //
 typedef struct tagSSromReg {
-    unsigned char abyPAR[6];                  // 0x00 (unsigned short)
-
-    unsigned short wSUB_VID;                   // 0x03 (unsigned short)
-    unsigned short wSUB_SID;
-
-    unsigned char byBCFG0;                    // 0x05 (unsigned short)
-    unsigned char byBCFG1;
-
-    unsigned char byFCR0;                     // 0x06 (unsigned short)
-    unsigned char byFCR1;
-    unsigned char byPMC0;                     // 0x07 (unsigned short)
-    unsigned char byPMC1;
-    unsigned char byMAXLAT;                   // 0x08 (unsigned short)
-    unsigned char byMINGNT;
-    unsigned char byCFG0;                     // 0x09 (unsigned short)
-    unsigned char byCFG1;
-    unsigned short wCISPTR;                    // 0x0A (unsigned short)
-    unsigned short wRsv0;                      // 0x0B (unsigned short)
-    unsigned short wRsv1;                      // 0x0C (unsigned short)
-    unsigned char byBBPAIR;                   // 0x0D (unsigned short)
-    unsigned char byRFTYPE;
-    unsigned char byMinChannel;               // 0x0E (unsigned short)
-    unsigned char byMaxChannel;
-    unsigned char bySignature;                // 0x0F (unsigned short)
-    unsigned char byCheckSum;
-
-    unsigned char abyReserved0[96];           // 0x10 (unsigned short)
-    unsigned char abyCIS[128];                // 0x80 (unsigned short)
+       unsigned char abyPAR[6];                  // 0x00 (unsigned short)
+
+       unsigned short wSUB_VID;                   // 0x03 (unsigned short)
+       unsigned short wSUB_SID;
+
+       unsigned char byBCFG0;                    // 0x05 (unsigned short)
+       unsigned char byBCFG1;
+
+       unsigned char byFCR0;                     // 0x06 (unsigned short)
+       unsigned char byFCR1;
+       unsigned char byPMC0;                     // 0x07 (unsigned short)
+       unsigned char byPMC1;
+       unsigned char byMAXLAT;                   // 0x08 (unsigned short)
+       unsigned char byMINGNT;
+       unsigned char byCFG0;                     // 0x09 (unsigned short)
+       unsigned char byCFG1;
+       unsigned short wCISPTR;                    // 0x0A (unsigned short)
+       unsigned short wRsv0;                      // 0x0B (unsigned short)
+       unsigned short wRsv1;                      // 0x0C (unsigned short)
+       unsigned char byBBPAIR;                   // 0x0D (unsigned short)
+       unsigned char byRFTYPE;
+       unsigned char byMinChannel;               // 0x0E (unsigned short)
+       unsigned char byMaxChannel;
+       unsigned char bySignature;                // 0x0F (unsigned short)
+       unsigned char byCheckSum;
+
+       unsigned char abyReserved0[96];           // 0x10 (unsigned short)
+       unsigned char abyCIS[128];                // 0x80 (unsigned short)
 } SSromReg, *PSSromReg;
 
 /*---------------------  Export Macros ------------------------------*/
@@ -152,6 +150,6 @@ void SROMvWriteEtherAddress(unsigned long dwIoBase, unsigned char *pbyEtherAddre
 
 void SROMvReadSubSysVenId(unsigned long dwIoBase, unsigned long *pdwSubSysVenId);
 
-bool SROMbAutoLoad (unsigned long dwIoBase);
+bool SROMbAutoLoad(unsigned long dwIoBase);
 
 #endif // __EEPROM_H__
index 1313c4cd0860a421ad17afaeace5525c9ff2204a..ed6868a9c16e0d16cc117c6e62643dc9a51f335a 100644 (file)
 
 // 32-bit CRC table
 static const unsigned long s_adwCrc32Table[256] = {
-    0x00000000L, 0x77073096L, 0xEE0E612CL, 0x990951BAL,
-    0x076DC419L, 0x706AF48FL, 0xE963A535L, 0x9E6495A3L,
-    0x0EDB8832L, 0x79DCB8A4L, 0xE0D5E91EL, 0x97D2D988L,
-    0x09B64C2BL, 0x7EB17CBDL, 0xE7B82D07L, 0x90BF1D91L,
-    0x1DB71064L, 0x6AB020F2L, 0xF3B97148L, 0x84BE41DEL,
-    0x1ADAD47DL, 0x6DDDE4EBL, 0xF4D4B551L, 0x83D385C7L,
-    0x136C9856L, 0x646BA8C0L, 0xFD62F97AL, 0x8A65C9ECL,
-    0x14015C4FL, 0x63066CD9L, 0xFA0F3D63L, 0x8D080DF5L,
-    0x3B6E20C8L, 0x4C69105EL, 0xD56041E4L, 0xA2677172L,
-    0x3C03E4D1L, 0x4B04D447L, 0xD20D85FDL, 0xA50AB56BL,
-    0x35B5A8FAL, 0x42B2986CL, 0xDBBBC9D6L, 0xACBCF940L,
-    0x32D86CE3L, 0x45DF5C75L, 0xDCD60DCFL, 0xABD13D59L,
-    0x26D930ACL, 0x51DE003AL, 0xC8D75180L, 0xBFD06116L,
-    0x21B4F4B5L, 0x56B3C423L, 0xCFBA9599L, 0xB8BDA50FL,
-    0x2802B89EL, 0x5F058808L, 0xC60CD9B2L, 0xB10BE924L,
-    0x2F6F7C87L, 0x58684C11L, 0xC1611DABL, 0xB6662D3DL,
-    0x76DC4190L, 0x01DB7106L, 0x98D220BCL, 0xEFD5102AL,
-    0x71B18589L, 0x06B6B51FL, 0x9FBFE4A5L, 0xE8B8D433L,
-    0x7807C9A2L, 0x0F00F934L, 0x9609A88EL, 0xE10E9818L,
-    0x7F6A0DBBL, 0x086D3D2DL, 0x91646C97L, 0xE6635C01L,
-    0x6B6B51F4L, 0x1C6C6162L, 0x856530D8L, 0xF262004EL,
-    0x6C0695EDL, 0x1B01A57BL, 0x8208F4C1L, 0xF50FC457L,
-    0x65B0D9C6L, 0x12B7E950L, 0x8BBEB8EAL, 0xFCB9887CL,
-    0x62DD1DDFL, 0x15DA2D49L, 0x8CD37CF3L, 0xFBD44C65L,
-    0x4DB26158L, 0x3AB551CEL, 0xA3BC0074L, 0xD4BB30E2L,
-    0x4ADFA541L, 0x3DD895D7L, 0xA4D1C46DL, 0xD3D6F4FBL,
-    0x4369E96AL, 0x346ED9FCL, 0xAD678846L, 0xDA60B8D0L,
-    0x44042D73L, 0x33031DE5L, 0xAA0A4C5FL, 0xDD0D7CC9L,
-    0x5005713CL, 0x270241AAL, 0xBE0B1010L, 0xC90C2086L,
-    0x5768B525L, 0x206F85B3L, 0xB966D409L, 0xCE61E49FL,
-    0x5EDEF90EL, 0x29D9C998L, 0xB0D09822L, 0xC7D7A8B4L,
-    0x59B33D17L, 0x2EB40D81L, 0xB7BD5C3BL, 0xC0BA6CADL,
-    0xEDB88320L, 0x9ABFB3B6L, 0x03B6E20CL, 0x74B1D29AL,
-    0xEAD54739L, 0x9DD277AFL, 0x04DB2615L, 0x73DC1683L,
-    0xE3630B12L, 0x94643B84L, 0x0D6D6A3EL, 0x7A6A5AA8L,
-    0xE40ECF0BL, 0x9309FF9DL, 0x0A00AE27L, 0x7D079EB1L,
-    0xF00F9344L, 0x8708A3D2L, 0x1E01F268L, 0x6906C2FEL,
-    0xF762575DL, 0x806567CBL, 0x196C3671L, 0x6E6B06E7L,
-    0xFED41B76L, 0x89D32BE0L, 0x10DA7A5AL, 0x67DD4ACCL,
-    0xF9B9DF6FL, 0x8EBEEFF9L, 0x17B7BE43L, 0x60B08ED5L,
-    0xD6D6A3E8L, 0xA1D1937EL, 0x38D8C2C4L, 0x4FDFF252L,
-    0xD1BB67F1L, 0xA6BC5767L, 0x3FB506DDL, 0x48B2364BL,
-    0xD80D2BDAL, 0xAF0A1B4CL, 0x36034AF6L, 0x41047A60L,
-    0xDF60EFC3L, 0xA867DF55L, 0x316E8EEFL, 0x4669BE79L,
-    0xCB61B38CL, 0xBC66831AL, 0x256FD2A0L, 0x5268E236L,
-    0xCC0C7795L, 0xBB0B4703L, 0x220216B9L, 0x5505262FL,
-    0xC5BA3BBEL, 0xB2BD0B28L, 0x2BB45A92L, 0x5CB36A04L,
-    0xC2D7FFA7L, 0xB5D0CF31L, 0x2CD99E8BL, 0x5BDEAE1DL,
-    0x9B64C2B0L, 0xEC63F226L, 0x756AA39CL, 0x026D930AL,
-    0x9C0906A9L, 0xEB0E363FL, 0x72076785L, 0x05005713L,
-    0x95BF4A82L, 0xE2B87A14L, 0x7BB12BAEL, 0x0CB61B38L,
-    0x92D28E9BL, 0xE5D5BE0DL, 0x7CDCEFB7L, 0x0BDBDF21L,
-    0x86D3D2D4L, 0xF1D4E242L, 0x68DDB3F8L, 0x1FDA836EL,
-    0x81BE16CDL, 0xF6B9265BL, 0x6FB077E1L, 0x18B74777L,
-    0x88085AE6L, 0xFF0F6A70L, 0x66063BCAL, 0x11010B5CL,
-    0x8F659EFFL, 0xF862AE69L, 0x616BFFD3L, 0x166CCF45L,
-    0xA00AE278L, 0xD70DD2EEL, 0x4E048354L, 0x3903B3C2L,
-    0xA7672661L, 0xD06016F7L, 0x4969474DL, 0x3E6E77DBL,
-    0xAED16A4AL, 0xD9D65ADCL, 0x40DF0B66L, 0x37D83BF0L,
-    0xA9BCAE53L, 0xDEBB9EC5L, 0x47B2CF7FL, 0x30B5FFE9L,
-    0xBDBDF21CL, 0xCABAC28AL, 0x53B39330L, 0x24B4A3A6L,
-    0xBAD03605L, 0xCDD70693L, 0x54DE5729L, 0x23D967BFL,
-    0xB3667A2EL, 0xC4614AB8L, 0x5D681B02L, 0x2A6F2B94L,
-    0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL, 0x2D02EF8DL
+       0x00000000L, 0x77073096L, 0xEE0E612CL, 0x990951BAL,
+       0x076DC419L, 0x706AF48FL, 0xE963A535L, 0x9E6495A3L,
+       0x0EDB8832L, 0x79DCB8A4L, 0xE0D5E91EL, 0x97D2D988L,
+       0x09B64C2BL, 0x7EB17CBDL, 0xE7B82D07L, 0x90BF1D91L,
+       0x1DB71064L, 0x6AB020F2L, 0xF3B97148L, 0x84BE41DEL,
+       0x1ADAD47DL, 0x6DDDE4EBL, 0xF4D4B551L, 0x83D385C7L,
+       0x136C9856L, 0x646BA8C0L, 0xFD62F97AL, 0x8A65C9ECL,
+       0x14015C4FL, 0x63066CD9L, 0xFA0F3D63L, 0x8D080DF5L,
+       0x3B6E20C8L, 0x4C69105EL, 0xD56041E4L, 0xA2677172L,
+       0x3C03E4D1L, 0x4B04D447L, 0xD20D85FDL, 0xA50AB56BL,
+       0x35B5A8FAL, 0x42B2986CL, 0xDBBBC9D6L, 0xACBCF940L,
+       0x32D86CE3L, 0x45DF5C75L, 0xDCD60DCFL, 0xABD13D59L,
+       0x26D930ACL, 0x51DE003AL, 0xC8D75180L, 0xBFD06116L,
+       0x21B4F4B5L, 0x56B3C423L, 0xCFBA9599L, 0xB8BDA50FL,
+       0x2802B89EL, 0x5F058808L, 0xC60CD9B2L, 0xB10BE924L,
+       0x2F6F7C87L, 0x58684C11L, 0xC1611DABL, 0xB6662D3DL,
+       0x76DC4190L, 0x01DB7106L, 0x98D220BCL, 0xEFD5102AL,
+       0x71B18589L, 0x06B6B51FL, 0x9FBFE4A5L, 0xE8B8D433L,
+       0x7807C9A2L, 0x0F00F934L, 0x9609A88EL, 0xE10E9818L,
+       0x7F6A0DBBL, 0x086D3D2DL, 0x91646C97L, 0xE6635C01L,
+       0x6B6B51F4L, 0x1C6C6162L, 0x856530D8L, 0xF262004EL,
+       0x6C0695EDL, 0x1B01A57BL, 0x8208F4C1L, 0xF50FC457L,
+       0x65B0D9C6L, 0x12B7E950L, 0x8BBEB8EAL, 0xFCB9887CL,
+       0x62DD1DDFL, 0x15DA2D49L, 0x8CD37CF3L, 0xFBD44C65L,
+       0x4DB26158L, 0x3AB551CEL, 0xA3BC0074L, 0xD4BB30E2L,
+       0x4ADFA541L, 0x3DD895D7L, 0xA4D1C46DL, 0xD3D6F4FBL,
+       0x4369E96AL, 0x346ED9FCL, 0xAD678846L, 0xDA60B8D0L,
+       0x44042D73L, 0x33031DE5L, 0xAA0A4C5FL, 0xDD0D7CC9L,
+       0x5005713CL, 0x270241AAL, 0xBE0B1010L, 0xC90C2086L,
+       0x5768B525L, 0x206F85B3L, 0xB966D409L, 0xCE61E49FL,
+       0x5EDEF90EL, 0x29D9C998L, 0xB0D09822L, 0xC7D7A8B4L,
+       0x59B33D17L, 0x2EB40D81L, 0xB7BD5C3BL, 0xC0BA6CADL,
+       0xEDB88320L, 0x9ABFB3B6L, 0x03B6E20CL, 0x74B1D29AL,
+       0xEAD54739L, 0x9DD277AFL, 0x04DB2615L, 0x73DC1683L,
+       0xE3630B12L, 0x94643B84L, 0x0D6D6A3EL, 0x7A6A5AA8L,
+       0xE40ECF0BL, 0x9309FF9DL, 0x0A00AE27L, 0x7D079EB1L,
+       0xF00F9344L, 0x8708A3D2L, 0x1E01F268L, 0x6906C2FEL,
+       0xF762575DL, 0x806567CBL, 0x196C3671L, 0x6E6B06E7L,
+       0xFED41B76L, 0x89D32BE0L, 0x10DA7A5AL, 0x67DD4ACCL,
+       0xF9B9DF6FL, 0x8EBEEFF9L, 0x17B7BE43L, 0x60B08ED5L,
+       0xD6D6A3E8L, 0xA1D1937EL, 0x38D8C2C4L, 0x4FDFF252L,
+       0xD1BB67F1L, 0xA6BC5767L, 0x3FB506DDL, 0x48B2364BL,
+       0xD80D2BDAL, 0xAF0A1B4CL, 0x36034AF6L, 0x41047A60L,
+       0xDF60EFC3L, 0xA867DF55L, 0x316E8EEFL, 0x4669BE79L,
+       0xCB61B38CL, 0xBC66831AL, 0x256FD2A0L, 0x5268E236L,
+       0xCC0C7795L, 0xBB0B4703L, 0x220216B9L, 0x5505262FL,
+       0xC5BA3BBEL, 0xB2BD0B28L, 0x2BB45A92L, 0x5CB36A04L,
+       0xC2D7FFA7L, 0xB5D0CF31L, 0x2CD99E8BL, 0x5BDEAE1DL,
+       0x9B64C2B0L, 0xEC63F226L, 0x756AA39CL, 0x026D930AL,
+       0x9C0906A9L, 0xEB0E363FL, 0x72076785L, 0x05005713L,
+       0x95BF4A82L, 0xE2B87A14L, 0x7BB12BAEL, 0x0CB61B38L,
+       0x92D28E9BL, 0xE5D5BE0DL, 0x7CDCEFB7L, 0x0BDBDF21L,
+       0x86D3D2D4L, 0xF1D4E242L, 0x68DDB3F8L, 0x1FDA836EL,
+       0x81BE16CDL, 0xF6B9265BL, 0x6FB077E1L, 0x18B74777L,
+       0x88085AE6L, 0xFF0F6A70L, 0x66063BCAL, 0x11010B5CL,
+       0x8F659EFFL, 0xF862AE69L, 0x616BFFD3L, 0x166CCF45L,
+       0xA00AE278L, 0xD70DD2EEL, 0x4E048354L, 0x3903B3C2L,
+       0xA7672661L, 0xD06016F7L, 0x4969474DL, 0x3E6E77DBL,
+       0xAED16A4AL, 0xD9D65ADCL, 0x40DF0B66L, 0x37D83BF0L,
+       0xA9BCAE53L, 0xDEBB9EC5L, 0x47B2CF7FL, 0x30B5FFE9L,
+       0xBDBDF21CL, 0xCABAC28AL, 0x53B39330L, 0x24B4A3A6L,
+       0xBAD03605L, 0xCDD70693L, 0x54DE5729L, 0x23D967BFL,
+       0xB3667A2EL, 0xC4614AB8L, 0x5D681B02L, 0x2A6F2B94L,
+       0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL, 0x2D02EF8DL
 };
 
 /*---------------------  Static Functions  --------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 
-
-
-
 /*+
  *
  * Description:
@@ -131,21 +128,20 @@ static const unsigned long s_adwCrc32Table[256] = {
  *
  * Return Value: CRC-32
  *
--*/
-unsigned long CRCdwCrc32 (unsigned char *pbyData, unsigned int cbByte, unsigned long dwCrcSeed)
+ -*/
+unsigned long CRCdwCrc32(unsigned char *pbyData, unsigned int cbByte, unsigned long dwCrcSeed)
 {
-    unsigned long dwCrc;
+       unsigned long dwCrc;
 
-    dwCrc = dwCrcSeed;
-    while (cbByte--) {
-        dwCrc = s_adwCrc32Table[(unsigned char)((dwCrc ^ (*pbyData)) & 0xFF)] ^ (dwCrc >> 8);
-        pbyData++;
-    }
+       dwCrc = dwCrcSeed;
+       while (cbByte--) {
+               dwCrc = s_adwCrc32Table[(unsigned char)((dwCrc ^ (*pbyData)) & 0xFF)] ^ (dwCrc >> 8);
+               pbyData++;
+       }
 
-    return dwCrc;
+       return dwCrc;
 }
 
-
 /*+
  *
  * Description:
@@ -163,13 +159,12 @@ unsigned long CRCdwCrc32 (unsigned char *pbyData, unsigned int cbByte, unsigned
  *
  * Return Value: CRC-32
  *
--*/
-unsigned long CRCdwGetCrc32 (unsigned char *pbyData, unsigned int cbByte)
+ -*/
+unsigned long CRCdwGetCrc32(unsigned char *pbyData, unsigned int cbByte)
 {
-    return ~CRCdwCrc32(pbyData, cbByte, 0xFFFFFFFFL);
+       return ~CRCdwCrc32(pbyData, cbByte, 0xFFFFFFFFL);
 }
 
-
 /*+
  *
  * Description:
@@ -189,10 +184,8 @@ unsigned long CRCdwGetCrc32 (unsigned char *pbyData, unsigned int cbByte)
  *
  * Return Value: CRC-32
  *
--*/
+ -*/
 unsigned long CRCdwGetCrc32Ex(unsigned char *pbyData, unsigned int cbByte, unsigned long dwPreCRC)
 {
-    return CRCdwCrc32(pbyData, cbByte, dwPreCRC);
+       return CRCdwCrc32(pbyData, cbByte, dwPreCRC);
 }
-
-
index a2044212d1c98938b33d096fdcd5728ba0828be4..82b5ddafae55cbe7c709005e7d5c98346e2eceb3 100644 (file)
@@ -48,6 +48,3 @@ unsigned long CRCdwGetCrc32(unsigned char *pbyData, unsigned int cbByte);
 unsigned long CRCdwGetCrc32Ex(unsigned char *pbyData, unsigned int cbByte, unsigned long dwPreCRC);
 
 #endif // __TCRC_H__
-
-
-
index 28554bf75549e40a2913bf5a6bff87fda297492e..a5dc3c09cfd776a830cd38da1ac69169c7d54855 100644 (file)
@@ -47,8 +47,6 @@
 
 /*---------------------  Export Variables  --------------------------*/
 
-
-
 /*
  * Description: Calculate multicast hash value by CRC32
  *
  * Return Value: Hash value
  *
  */
-unsigned char ETHbyGetHashIndexByCrc32 (unsigned char *pbyMultiAddr)
+unsigned char ETHbyGetHashIndexByCrc32(unsigned char *pbyMultiAddr)
 {
-    int     ii;
-    unsigned char byTmpHash;
-    unsigned char byHash = 0;
+       int     ii;
+       unsigned char byTmpHash;
+       unsigned char byHash = 0;
 
-    // get the least 6-bits from CRC generator
-    byTmpHash = (unsigned char)(CRCdwCrc32(pbyMultiAddr, ETH_ALEN,
-            0xFFFFFFFFL) & 0x3F);
-    // reverse most bit to least bit
-    for (ii = 0; ii < (sizeof(byTmpHash) * 8); ii++) {
-        byHash <<= 1;
-        if (byTmpHash & 0x01)
-            byHash |= 1;
-        byTmpHash >>= 1;
-    }
+       // get the least 6-bits from CRC generator
+       byTmpHash = (unsigned char)(CRCdwCrc32(pbyMultiAddr, ETH_ALEN,
+                                              0xFFFFFFFFL) & 0x3F);
+       // reverse most bit to least bit
+       for (ii = 0; ii < (sizeof(byTmpHash) * 8); ii++) {
+               byHash <<= 1;
+               if (byTmpHash & 0x01)
+                       byHash |= 1;
+               byTmpHash >>= 1;
+       }
 
-    // adjust 6-bits to the right most
-    return (byHash >> 2);
+       // adjust 6-bits to the right most
+       return byHash >> 2;
 }
 
-
 /*
  * Description: Check CRC value of the buffer if Ok or not
  *
@@ -96,14 +93,13 @@ unsigned char ETHbyGetHashIndexByCrc32 (unsigned char *pbyMultiAddr)
  * Return Value: true if ok; false if error.
  *
  */
-bool ETHbIsBufferCrc32Ok (unsigned char *pbyBuffer, unsigned int cbFrameLength)
+bool ETHbIsBufferCrc32Ok(unsigned char *pbyBuffer, unsigned int cbFrameLength)
 {
-    unsigned long dwCRC;
+       unsigned long dwCRC;
 
-    dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4);
-    if (cpu_to_le32(*((unsigned long *)(pbyBuffer + cbFrameLength - 4))) != dwCRC) {
-        return false;
-    }
-    return true;
+       dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4);
+       if (cpu_to_le32(*((unsigned long *)(pbyBuffer + cbFrameLength - 4))) != dwCRC) {
+               return false;
+       }
+       return true;
 }
-
index 6a68f97d9a327b678501f3144640df36dc6dbf38..94cc8830d8ccc3dd2c3d4fd333a3bfcef070ec8c 100644 (file)
 // constants
 //
 #define U_ETHER_ADDR_STR_LEN (ETH_ALEN * 2 + 1)
-                                        // Ethernet address string length
+// Ethernet address string length
 
 #define MAX_LOOKAHEAD_SIZE  ETH_FRAME_LEN
 
 #define U_MULTI_ADDR_LEN    8           // multicast address length
 
-
 #ifdef __BIG_ENDIAN
 
 #define TYPE_PKT_IP         0x0800      //
@@ -89,7 +88,6 @@
 #define TYPE_CTL_CTS        0xc400
 #define TYPE_CTL_ACK        0xd400
 
-
 #else //if LITTLE_ENDIAN
 //
 // wType field in the SEthernetHeader
 #define TYPE_CTL_CTS        0x00c4
 #define TYPE_CTL_ACK        0x00d4
 
-
-
 #endif //#ifdef __BIG_ENDIAN
 
 #define WEP_IV_MASK         0x00FFFFFF
 // Ethernet packet
 //
 typedef struct tagSEthernetHeader {
-    unsigned char abyDstAddr[ETH_ALEN];
-    unsigned char abySrcAddr[ETH_ALEN];
-    unsigned short wType;
-}__attribute__ ((__packed__))
+       unsigned char abyDstAddr[ETH_ALEN];
+       unsigned char abySrcAddr[ETH_ALEN];
+       unsigned short wType;
+} __attribute__ ((__packed__))
 SEthernetHeader, *PSEthernetHeader;
 
-
 //
 // 802_3 packet
 //
 typedef struct tagS802_3Header {
-    unsigned char abyDstAddr[ETH_ALEN];
-    unsigned char abySrcAddr[ETH_ALEN];
-    unsigned short wLen;
-}__attribute__ ((__packed__))
+       unsigned char abyDstAddr[ETH_ALEN];
+       unsigned char abySrcAddr[ETH_ALEN];
+       unsigned short wLen;
+} __attribute__ ((__packed__))
 S802_3Header, *PS802_3Header;
 
 //
 // 802_11 packet
 //
 typedef struct tagS802_11Header {
-    unsigned short wFrameCtl;
-    unsigned short wDurationID;
-    unsigned char abyAddr1[ETH_ALEN];
-    unsigned char abyAddr2[ETH_ALEN];
-    unsigned char abyAddr3[ETH_ALEN];
-    unsigned short wSeqCtl;
-    unsigned char abyAddr4[ETH_ALEN];
-}__attribute__ ((__packed__))
+       unsigned short wFrameCtl;
+       unsigned short wDurationID;
+       unsigned char abyAddr1[ETH_ALEN];
+       unsigned char abyAddr2[ETH_ALEN];
+       unsigned char abyAddr3[ETH_ALEN];
+       unsigned short wSeqCtl;
+       unsigned char abyAddr4[ETH_ALEN];
+} __attribute__ ((__packed__))
 S802_11Header, *PS802_11Header;
 
 /*---------------------  Export Macros ------------------------------*/
@@ -195,6 +190,3 @@ unsigned char ETHbyGetHashIndexByCrc32(unsigned char *pbyMultiAddr);
 bool ETHbIsBufferCrc32Ok(unsigned char *pbyBuffer, unsigned int cbFrameLength);
 
 #endif // __TETHER_H__
-
-
-
index f141ba1cbb9bee64253ff7587f9cbb5fc7e0b314..b3e087e19034f31d5aca3494add801586fad3b2e 100644 (file)
 /* bytes swapped. To allow an endian tolerant implementation, the byte */
 /* halves have been expressed independently here.                      */
 const unsigned char TKIP_Sbox_Lower[256] = {
-    0xA5,0x84,0x99,0x8D,0x0D,0xBD,0xB1,0x54,
-    0x50,0x03,0xA9,0x7D,0x19,0x62,0xE6,0x9A,
-    0x45,0x9D,0x40,0x87,0x15,0xEB,0xC9,0x0B,
-    0xEC,0x67,0xFD,0xEA,0xBF,0xF7,0x96,0x5B,
-    0xC2,0x1C,0xAE,0x6A,0x5A,0x41,0x02,0x4F,
-    0x5C,0xF4,0x34,0x08,0x93,0x73,0x53,0x3F,
-    0x0C,0x52,0x65,0x5E,0x28,0xA1,0x0F,0xB5,
-    0x09,0x36,0x9B,0x3D,0x26,0x69,0xCD,0x9F,
-    0x1B,0x9E,0x74,0x2E,0x2D,0xB2,0xEE,0xFB,
-    0xF6,0x4D,0x61,0xCE,0x7B,0x3E,0x71,0x97,
-    0xF5,0x68,0x00,0x2C,0x60,0x1F,0xC8,0xED,
-    0xBE,0x46,0xD9,0x4B,0xDE,0xD4,0xE8,0x4A,
-    0x6B,0x2A,0xE5,0x16,0xC5,0xD7,0x55,0x94,
-    0xCF,0x10,0x06,0x81,0xF0,0x44,0xBA,0xE3,
-    0xF3,0xFE,0xC0,0x8A,0xAD,0xBC,0x48,0x04,
-    0xDF,0xC1,0x75,0x63,0x30,0x1A,0x0E,0x6D,
-    0x4C,0x14,0x35,0x2F,0xE1,0xA2,0xCC,0x39,
-    0x57,0xF2,0x82,0x47,0xAC,0xE7,0x2B,0x95,
-    0xA0,0x98,0xD1,0x7F,0x66,0x7E,0xAB,0x83,
-    0xCA,0x29,0xD3,0x3C,0x79,0xE2,0x1D,0x76,
-    0x3B,0x56,0x4E,0x1E,0xDB,0x0A,0x6C,0xE4,
-    0x5D,0x6E,0xEF,0xA6,0xA8,0xA4,0x37,0x8B,
-    0x32,0x43,0x59,0xB7,0x8C,0x64,0xD2,0xE0,
-    0xB4,0xFA,0x07,0x25,0xAF,0x8E,0xE9,0x18,
-    0xD5,0x88,0x6F,0x72,0x24,0xF1,0xC7,0x51,
-    0x23,0x7C,0x9C,0x21,0xDD,0xDC,0x86,0x85,
-    0x90,0x42,0xC4,0xAA,0xD8,0x05,0x01,0x12,
-    0xA3,0x5F,0xF9,0xD0,0x91,0x58,0x27,0xB9,
-    0x38,0x13,0xB3,0x33,0xBB,0x70,0x89,0xA7,
-    0xB6,0x22,0x92,0x20,0x49,0xFF,0x78,0x7A,
-    0x8F,0xF8,0x80,0x17,0xDA,0x31,0xC6,0xB8,
-    0xC3,0xB0,0x77,0x11,0xCB,0xFC,0xD6,0x3A
+       0xA5, 0x84, 0x99, 0x8D, 0x0D, 0xBD, 0xB1, 0x54,
+       0x50, 0x03, 0xA9, 0x7D, 0x19, 0x62, 0xE6, 0x9A,
+       0x45, 0x9D, 0x40, 0x87, 0x15, 0xEB, 0xC9, 0x0B,
+       0xEC, 0x67, 0xFD, 0xEA, 0xBF, 0xF7, 0x96, 0x5B,
+       0xC2, 0x1C, 0xAE, 0x6A, 0x5A, 0x41, 0x02, 0x4F,
+       0x5C, 0xF4, 0x34, 0x08, 0x93, 0x73, 0x53, 0x3F,
+       0x0C, 0x52, 0x65, 0x5E, 0x28, 0xA1, 0x0F, 0xB5,
+       0x09, 0x36, 0x9B, 0x3D, 0x26, 0x69, 0xCD, 0x9F,
+       0x1B, 0x9E, 0x74, 0x2E, 0x2D, 0xB2, 0xEE, 0xFB,
+       0xF6, 0x4D, 0x61, 0xCE, 0x7B, 0x3E, 0x71, 0x97,
+       0xF5, 0x68, 0x00, 0x2C, 0x60, 0x1F, 0xC8, 0xED,
+       0xBE, 0x46, 0xD9, 0x4B, 0xDE, 0xD4, 0xE8, 0x4A,
+       0x6B, 0x2A, 0xE5, 0x16, 0xC5, 0xD7, 0x55, 0x94,
+       0xCF, 0x10, 0x06, 0x81, 0xF0, 0x44, 0xBA, 0xE3,
+       0xF3, 0xFE, 0xC0, 0x8A, 0xAD, 0xBC, 0x48, 0x04,
+       0xDF, 0xC1, 0x75, 0x63, 0x30, 0x1A, 0x0E, 0x6D,
+       0x4C, 0x14, 0x35, 0x2F, 0xE1, 0xA2, 0xCC, 0x39,
+       0x57, 0xF2, 0x82, 0x47, 0xAC, 0xE7, 0x2B, 0x95,
+       0xA0, 0x98, 0xD1, 0x7F, 0x66, 0x7E, 0xAB, 0x83,
+       0xCA, 0x29, 0xD3, 0x3C, 0x79, 0xE2, 0x1D, 0x76,
+       0x3B, 0x56, 0x4E, 0x1E, 0xDB, 0x0A, 0x6C, 0xE4,
+       0x5D, 0x6E, 0xEF, 0xA6, 0xA8, 0xA4, 0x37, 0x8B,
+       0x32, 0x43, 0x59, 0xB7, 0x8C, 0x64, 0xD2, 0xE0,
+       0xB4, 0xFA, 0x07, 0x25, 0xAF, 0x8E, 0xE9, 0x18,
+       0xD5, 0x88, 0x6F, 0x72, 0x24, 0xF1, 0xC7, 0x51,
+       0x23, 0x7C, 0x9C, 0x21, 0xDD, 0xDC, 0x86, 0x85,
+       0x90, 0x42, 0xC4, 0xAA, 0xD8, 0x05, 0x01, 0x12,
+       0xA3, 0x5F, 0xF9, 0xD0, 0x91, 0x58, 0x27, 0xB9,
+       0x38, 0x13, 0xB3, 0x33, 0xBB, 0x70, 0x89, 0xA7,
+       0xB6, 0x22, 0x92, 0x20, 0x49, 0xFF, 0x78, 0x7A,
+       0x8F, 0xF8, 0x80, 0x17, 0xDA, 0x31, 0xC6, 0xB8,
+       0xC3, 0xB0, 0x77, 0x11, 0xCB, 0xFC, 0xD6, 0x3A
 };
 
 const unsigned char TKIP_Sbox_Upper[256] = {
-    0xC6,0xF8,0xEE,0xF6,0xFF,0xD6,0xDE,0x91,
-    0x60,0x02,0xCE,0x56,0xE7,0xB5,0x4D,0xEC,
-    0x8F,0x1F,0x89,0xFA,0xEF,0xB2,0x8E,0xFB,
-    0x41,0xB3,0x5F,0x45,0x23,0x53,0xE4,0x9B,
-    0x75,0xE1,0x3D,0x4C,0x6C,0x7E,0xF5,0x83,
-    0x68,0x51,0xD1,0xF9,0xE2,0xAB,0x62,0x2A,
-    0x08,0x95,0x46,0x9D,0x30,0x37,0x0A,0x2F,
-    0x0E,0x24,0x1B,0xDF,0xCD,0x4E,0x7F,0xEA,
-    0x12,0x1D,0x58,0x34,0x36,0xDC,0xB4,0x5B,
-    0xA4,0x76,0xB7,0x7D,0x52,0xDD,0x5E,0x13,
-    0xA6,0xB9,0x00,0xC1,0x40,0xE3,0x79,0xB6,
-    0xD4,0x8D,0x67,0x72,0x94,0x98,0xB0,0x85,
-    0xBB,0xC5,0x4F,0xED,0x86,0x9A,0x66,0x11,
-    0x8A,0xE9,0x04,0xFE,0xA0,0x78,0x25,0x4B,
-    0xA2,0x5D,0x80,0x05,0x3F,0x21,0x70,0xF1,
-    0x63,0x77,0xAF,0x42,0x20,0xE5,0xFD,0xBF,
-    0x81,0x18,0x26,0xC3,0xBE,0x35,0x88,0x2E,
-    0x93,0x55,0xFC,0x7A,0xC8,0xBA,0x32,0xE6,
-    0xC0,0x19,0x9E,0xA3,0x44,0x54,0x3B,0x0B,
-    0x8C,0xC7,0x6B,0x28,0xA7,0xBC,0x16,0xAD,
-    0xDB,0x64,0x74,0x14,0x92,0x0C,0x48,0xB8,
-    0x9F,0xBD,0x43,0xC4,0x39,0x31,0xD3,0xF2,
-    0xD5,0x8B,0x6E,0xDA,0x01,0xB1,0x9C,0x49,
-    0xD8,0xAC,0xF3,0xCF,0xCA,0xF4,0x47,0x10,
-    0x6F,0xF0,0x4A,0x5C,0x38,0x57,0x73,0x97,
-    0xCB,0xA1,0xE8,0x3E,0x96,0x61,0x0D,0x0F,
-    0xE0,0x7C,0x71,0xCC,0x90,0x06,0xF7,0x1C,
-    0xC2,0x6A,0xAE,0x69,0x17,0x99,0x3A,0x27,
-    0xD9,0xEB,0x2B,0x22,0xD2,0xA9,0x07,0x33,
-    0x2D,0x3C,0x15,0xC9,0x87,0xAA,0x50,0xA5,
-    0x03,0x59,0x09,0x1A,0x65,0xD7,0x84,0xD0,
-    0x82,0x29,0x5A,0x1E,0x7B,0xA8,0x6D,0x2C
+       0xC6, 0xF8, 0xEE, 0xF6, 0xFF, 0xD6, 0xDE, 0x91,
+       0x60, 0x02, 0xCE, 0x56, 0xE7, 0xB5, 0x4D, 0xEC,
+       0x8F, 0x1F, 0x89, 0xFA, 0xEF, 0xB2, 0x8E, 0xFB,
+       0x41, 0xB3, 0x5F, 0x45, 0x23, 0x53, 0xE4, 0x9B,
+       0x75, 0xE1, 0x3D, 0x4C, 0x6C, 0x7E, 0xF5, 0x83,
+       0x68, 0x51, 0xD1, 0xF9, 0xE2, 0xAB, 0x62, 0x2A,
+       0x08, 0x95, 0x46, 0x9D, 0x30, 0x37, 0x0A, 0x2F,
+       0x0E, 0x24, 0x1B, 0xDF, 0xCD, 0x4E, 0x7F, 0xEA,
+       0x12, 0x1D, 0x58, 0x34, 0x36, 0xDC, 0xB4, 0x5B,
+       0xA4, 0x76, 0xB7, 0x7D, 0x52, 0xDD, 0x5E, 0x13,
+       0xA6, 0xB9, 0x00, 0xC1, 0x40, 0xE3, 0x79, 0xB6,
+       0xD4, 0x8D, 0x67, 0x72, 0x94, 0x98, 0xB0, 0x85,
+       0xBB, 0xC5, 0x4F, 0xED, 0x86, 0x9A, 0x66, 0x11,
+       0x8A, 0xE9, 0x04, 0xFE, 0xA0, 0x78, 0x25, 0x4B,
+       0xA2, 0x5D, 0x80, 0x05, 0x3F, 0x21, 0x70, 0xF1,
+       0x63, 0x77, 0xAF, 0x42, 0x20, 0xE5, 0xFD, 0xBF,
+       0x81, 0x18, 0x26, 0xC3, 0xBE, 0x35, 0x88, 0x2E,
+       0x93, 0x55, 0xFC, 0x7A, 0xC8, 0xBA, 0x32, 0xE6,
+       0xC0, 0x19, 0x9E, 0xA3, 0x44, 0x54, 0x3B, 0x0B,
+       0x8C, 0xC7, 0x6B, 0x28, 0xA7, 0xBC, 0x16, 0xAD,
+       0xDB, 0x64, 0x74, 0x14, 0x92, 0x0C, 0x48, 0xB8,
+       0x9F, 0xBD, 0x43, 0xC4, 0x39, 0x31, 0xD3, 0xF2,
+       0xD5, 0x8B, 0x6E, 0xDA, 0x01, 0xB1, 0x9C, 0x49,
+       0xD8, 0xAC, 0xF3, 0xCF, 0xCA, 0xF4, 0x47, 0x10,
+       0x6F, 0xF0, 0x4A, 0x5C, 0x38, 0x57, 0x73, 0x97,
+       0xCB, 0xA1, 0xE8, 0x3E, 0x96, 0x61, 0x0D, 0x0F,
+       0xE0, 0x7C, 0x71, 0xCC, 0x90, 0x06, 0xF7, 0x1C,
+       0xC2, 0x6A, 0xAE, 0x69, 0x17, 0x99, 0x3A, 0x27,
+       0xD9, 0xEB, 0x2B, 0x22, 0xD2, 0xA9, 0x07, 0x33,
+       0x2D, 0x3C, 0x15, 0xC9, 0x87, 0xAA, 0x50, 0xA5,
+       0x03, 0x59, 0x09, 0x1A, 0x65, 0xD7, 0x84, 0xD0,
+       0x82, 0x29, 0x5A, 0x1E, 0x7B, 0xA8, 0x6D, 0x2C
 };
 
-
 //STKIPKeyManagement  sTKIPKeyTable[MAX_TKIP_KEY];
 
 /*---------------------  Static Functions  --------------------------*/
@@ -141,34 +140,32 @@ unsigned int rotr1(unsigned int a);
 /************************************************************/
 unsigned int tkip_sbox(unsigned int index)
 {
-    unsigned int index_low;
-    unsigned int index_high;
-    unsigned int left, right;
+       unsigned int index_low;
+       unsigned int index_high;
+       unsigned int left, right;
 
-    index_low = (index % 256);
-    index_high = ((index >> 8) % 256);
+       index_low = (index % 256);
+       index_high = ((index >> 8) % 256);
 
-    left = TKIP_Sbox_Lower[index_low] + (TKIP_Sbox_Upper[index_low] * 256);
-    right = TKIP_Sbox_Upper[index_high] + (TKIP_Sbox_Lower[index_high] * 256);
+       left = TKIP_Sbox_Lower[index_low] + (TKIP_Sbox_Upper[index_low] * 256);
+       right = TKIP_Sbox_Upper[index_high] + (TKIP_Sbox_Lower[index_high] * 256);
 
-    return (left ^ right);
+       return left ^ right;
 };
 
-
 unsigned int rotr1(unsigned int a)
 {
-    unsigned int b;
-
-    if ((a & 0x01) == 0x01) {
-        b = (a >> 1) | 0x8000;
-    } else {
-        b = (a >> 1) & 0x7fff;
-    }
-    b = b % 65536;
-    return b;
+       unsigned int b;
+
+       if ((a & 0x01) == 0x01) {
+               b = (a >> 1) | 0x8000;
+       } else {
+               b = (a >> 1) & 0x7fff;
+       }
+       b = b % 65536;
+       return b;
 }
 
-
 /*
  * Description: Calculate RC4Key fom TK, TA, and TSC
  *
@@ -184,89 +181,89 @@ unsigned int rotr1(unsigned int a)
  *
  */
 void TKIPvMixKey(
-    unsigned char *pbyTKey,
-    unsigned char *pbyTA,
-    unsigned short wTSC15_0,
-    unsigned long dwTSC47_16,
-    unsigned char *pbyRC4Key
-    )
+       unsigned char *pbyTKey,
+       unsigned char *pbyTA,
+       unsigned short wTSC15_0,
+       unsigned long dwTSC47_16,
+       unsigned char *pbyRC4Key
+)
 {
-    unsigned int p1k[5];
+       unsigned int p1k[5];
 //    unsigned int ttak0, ttak1, ttak2, ttak3, ttak4;
-    unsigned int tsc0, tsc1, tsc2;
-    unsigned int ppk0, ppk1, ppk2, ppk3, ppk4, ppk5;
-    unsigned long int pnl,pnh;
-
-    int i, j;
-
-    pnl = wTSC15_0;
-    pnh = dwTSC47_16;
-
-    tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */
-    tsc1 = (unsigned int)(pnh % 65536);
-    tsc2 = (unsigned int)(pnl % 65536); /* lsb */
-
-    /* Phase 1, step 1 */
-    p1k[0] = tsc1;
-    p1k[1] = tsc0;
-    p1k[2] = (unsigned int)(pbyTA[0] + (pbyTA[1]*256));
-    p1k[3] = (unsigned int)(pbyTA[2] + (pbyTA[3]*256));
-    p1k[4] = (unsigned int)(pbyTA[4] + (pbyTA[5]*256));
-
-    /* Phase 1, step 2 */
-    for (i=0; i<8; i++) {
-        j = 2*(i & 1);
-        p1k[0] = (p1k[0] + tkip_sbox( (p1k[4] ^ ((256*pbyTKey[1+j]) + pbyTKey[j])) % 65536 )) % 65536;
-        p1k[1] = (p1k[1] + tkip_sbox( (p1k[0] ^ ((256*pbyTKey[5+j]) + pbyTKey[4+j])) % 65536 )) % 65536;
-        p1k[2] = (p1k[2] + tkip_sbox( (p1k[1] ^ ((256*pbyTKey[9+j]) + pbyTKey[8+j])) % 65536 )) % 65536;
-        p1k[3] = (p1k[3] + tkip_sbox( (p1k[2] ^ ((256*pbyTKey[13+j]) + pbyTKey[12+j])) % 65536 )) % 65536;
-        p1k[4] = (p1k[4] + tkip_sbox( (p1k[3] ^ (((256*pbyTKey[1+j]) + pbyTKey[j]))) % 65536 )) % 65536;
-        p1k[4] = (p1k[4] + i) % 65536;
-    }
-    /* Phase 2, Step 1 */
-    ppk0 = p1k[0];
-    ppk1 = p1k[1];
-    ppk2 = p1k[2];
-    ppk3 = p1k[3];
-    ppk4 = p1k[4];
-    ppk5 = (p1k[4] + tsc2) % 65536;
-
-    /* Phase2, Step 2 */
-    ppk0 = ppk0 + tkip_sbox( (ppk5 ^ ((256*pbyTKey[1]) + pbyTKey[0])) % 65536);
-    ppk1 = ppk1 + tkip_sbox( (ppk0 ^ ((256*pbyTKey[3]) + pbyTKey[2])) % 65536);
-    ppk2 = ppk2 + tkip_sbox( (ppk1 ^ ((256*pbyTKey[5]) + pbyTKey[4])) % 65536);
-    ppk3 = ppk3 + tkip_sbox( (ppk2 ^ ((256*pbyTKey[7]) + pbyTKey[6])) % 65536);
-    ppk4 = ppk4 + tkip_sbox( (ppk3 ^ ((256*pbyTKey[9]) + pbyTKey[8])) % 65536);
-    ppk5 = ppk5 + tkip_sbox( (ppk4 ^ ((256*pbyTKey[11]) + pbyTKey[10])) % 65536);
-
-    ppk0 = ppk0 + rotr1(ppk5 ^ ((256*pbyTKey[13]) + pbyTKey[12]));
-    ppk1 = ppk1 + rotr1(ppk0 ^ ((256*pbyTKey[15]) + pbyTKey[14]));
-    ppk2 = ppk2 + rotr1(ppk1);
-    ppk3 = ppk3 + rotr1(ppk2);
-    ppk4 = ppk4 + rotr1(ppk3);
-    ppk5 = ppk5 + rotr1(ppk4);
-
-    /* Phase 2, Step 3 */
-    pbyRC4Key[0] = (tsc2 >> 8) % 256;
-    pbyRC4Key[1] = (((tsc2 >> 8) % 256) | 0x20) & 0x7f;
-    pbyRC4Key[2] = tsc2 % 256;
-    pbyRC4Key[3] = ((ppk5 ^ ((256*pbyTKey[1]) + pbyTKey[0])) >> 1) % 256;
-
-    pbyRC4Key[4] = ppk0 % 256;
-    pbyRC4Key[5] = (ppk0 >> 8) % 256;
-
-    pbyRC4Key[6] = ppk1 % 256;
-    pbyRC4Key[7] = (ppk1 >> 8) % 256;
-
-    pbyRC4Key[8] = ppk2 % 256;
-    pbyRC4Key[9] = (ppk2 >> 8) % 256;
-
-    pbyRC4Key[10] = ppk3 % 256;
-    pbyRC4Key[11] = (ppk3 >> 8) % 256;
-
-    pbyRC4Key[12] = ppk4 % 256;
-    pbyRC4Key[13] = (ppk4 >> 8) % 256;
-
-    pbyRC4Key[14] = ppk5 % 256;
-    pbyRC4Key[15] = (ppk5 >> 8) % 256;
+       unsigned int tsc0, tsc1, tsc2;
+       unsigned int ppk0, ppk1, ppk2, ppk3, ppk4, ppk5;
+       unsigned long int pnl, pnh;
+
+       int i, j;
+
+       pnl = wTSC15_0;
+       pnh = dwTSC47_16;
+
+       tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */
+       tsc1 = (unsigned int)(pnh % 65536);
+       tsc2 = (unsigned int)(pnl % 65536); /* lsb */
+
+       /* Phase 1, step 1 */
+       p1k[0] = tsc1;
+       p1k[1] = tsc0;
+       p1k[2] = (unsigned int)(pbyTA[0] + (pbyTA[1]*256));
+       p1k[3] = (unsigned int)(pbyTA[2] + (pbyTA[3]*256));
+       p1k[4] = (unsigned int)(pbyTA[4] + (pbyTA[5]*256));
+
+       /* Phase 1, step 2 */
+       for (i = 0; i < 8; i++) {
+               j = 2 * (i & 1);
+               p1k[0] = (p1k[0] + tkip_sbox((p1k[4] ^ ((256*pbyTKey[1+j]) + pbyTKey[j])) % 65536)) % 65536;
+               p1k[1] = (p1k[1] + tkip_sbox((p1k[0] ^ ((256*pbyTKey[5+j]) + pbyTKey[4+j])) % 65536)) % 65536;
+               p1k[2] = (p1k[2] + tkip_sbox((p1k[1] ^ ((256*pbyTKey[9+j]) + pbyTKey[8+j])) % 65536)) % 65536;
+               p1k[3] = (p1k[3] + tkip_sbox((p1k[2] ^ ((256*pbyTKey[13+j]) + pbyTKey[12+j])) % 65536)) % 65536;
+               p1k[4] = (p1k[4] + tkip_sbox((p1k[3] ^ (((256*pbyTKey[1+j]) + pbyTKey[j]))) % 65536)) % 65536;
+               p1k[4] = (p1k[4] + i) % 65536;
+       }
+       /* Phase 2, Step 1 */
+       ppk0 = p1k[0];
+       ppk1 = p1k[1];
+       ppk2 = p1k[2];
+       ppk3 = p1k[3];
+       ppk4 = p1k[4];
+       ppk5 = (p1k[4] + tsc2) % 65536;
+
+       /* Phase2, Step 2 */
+       ppk0 = ppk0 + tkip_sbox((ppk5 ^ ((256*pbyTKey[1]) + pbyTKey[0])) % 65536);
+       ppk1 = ppk1 + tkip_sbox((ppk0 ^ ((256*pbyTKey[3]) + pbyTKey[2])) % 65536);
+       ppk2 = ppk2 + tkip_sbox((ppk1 ^ ((256*pbyTKey[5]) + pbyTKey[4])) % 65536);
+       ppk3 = ppk3 + tkip_sbox((ppk2 ^ ((256*pbyTKey[7]) + pbyTKey[6])) % 65536);
+       ppk4 = ppk4 + tkip_sbox((ppk3 ^ ((256*pbyTKey[9]) + pbyTKey[8])) % 65536);
+       ppk5 = ppk5 + tkip_sbox((ppk4 ^ ((256*pbyTKey[11]) + pbyTKey[10])) % 65536);
+
+       ppk0 = ppk0 + rotr1(ppk5 ^ ((256*pbyTKey[13]) + pbyTKey[12]));
+       ppk1 = ppk1 + rotr1(ppk0 ^ ((256*pbyTKey[15]) + pbyTKey[14]));
+       ppk2 = ppk2 + rotr1(ppk1);
+       ppk3 = ppk3 + rotr1(ppk2);
+       ppk4 = ppk4 + rotr1(ppk3);
+       ppk5 = ppk5 + rotr1(ppk4);
+
+       /* Phase 2, Step 3 */
+       pbyRC4Key[0] = (tsc2 >> 8) % 256;
+       pbyRC4Key[1] = (((tsc2 >> 8) % 256) | 0x20) & 0x7f;
+       pbyRC4Key[2] = tsc2 % 256;
+       pbyRC4Key[3] = ((ppk5 ^ ((256*pbyTKey[1]) + pbyTKey[0])) >> 1) % 256;
+
+       pbyRC4Key[4] = ppk0 % 256;
+       pbyRC4Key[5] = (ppk0 >> 8) % 256;
+
+       pbyRC4Key[6] = ppk1 % 256;
+       pbyRC4Key[7] = (ppk1 >> 8) % 256;
+
+       pbyRC4Key[8] = ppk2 % 256;
+       pbyRC4Key[9] = (ppk2 >> 8) % 256;
+
+       pbyRC4Key[10] = ppk3 % 256;
+       pbyRC4Key[11] = (ppk3 >> 8) % 256;
+
+       pbyRC4Key[12] = ppk4 % 256;
+       pbyRC4Key[13] = (ppk4 >> 8) % 256;
+
+       pbyRC4Key[14] = ppk5 % 256;
+       pbyRC4Key[15] = (ppk5 >> 8) % 256;
 }
index eb5951d726e0f36763e4357fa9458b8e8732d92b..3b6357ac6deec5f8f51985a81d9f10a3f9806b90 100644 (file)
 /*---------------------  Export Functions  --------------------------*/
 
 void TKIPvMixKey(
-    unsigned char *pbyTKey,
-    unsigned char *pbyTA,
-    unsigned short wTSC15_0,
-    unsigned long dwTSC47_16,
-    unsigned char *pbyRC4Key
-    );
+       unsigned char *pbyTKey,
+       unsigned char *pbyTA,
+       unsigned short wTSC15_0,
+       unsigned long dwTSC47_16,
+       unsigned char *pbyRC4Key
+);
 
 #endif // __TKIP_H__
-
-
-
index e8b177d4128b5f45c9ef9b81d1da12d5a5742b33..59c6e72f993a6b604692aa2cec893b9ce68e12a1 100644 (file)
@@ -58,5 +58,3 @@
 #endif
 
 #endif // __TMACRO_H__
-
-
index be223bd25d2c4ce07dcaf4ecf5b8ab95f56755f8..b1d8ae732774f3552ec679f3ab16fc171bd9582e 100644 (file)
  *
  */
 
-
 #ifndef __TTYPE_H__
 #define __TTYPE_H__
 
-
 /******* Common definitions and typedefs ***********************************/
 
 #ifndef TxInSleep
 // an 8-byte-aligned 8 byte long structure
 // which is NOT really a floating point number.
 typedef union tagUQuadWord {
-    struct {
-        unsigned int dwLowDword;
-        unsigned int dwHighDword;
-    } u;
-    double      DoNotUseThisField;
+       struct {
+               unsigned int dwLowDword;
+               unsigned int dwHighDword;
+       } u;
+       double      DoNotUseThisField;
 } UQuadWord;
 typedef UQuadWord       QWORD;          // 64-bit
 
 /****** Common pointer types ***********************************************/
 
-typedef QWORD *          PQWORD;
+typedef QWORD *PQWORD;
 
 #endif // __TTYPE_H__
index 9596fdef0e3cc01c5a7336c808c78090f8fdab0c..155e66439073f10407870c53b536b882ebbdcd29 100644 (file)
 
 /*---------------------  Export Definitions -------------------------*/
 
-
 //
 //  For IO mapped
 //
 
 #ifdef IO_MAP
 
-#define VNSvInPortB(dwIOAddress, pbyData) {                     \
-       *(pbyData) = inb(dwIOAddress);                              \
-}
-
-
-#define VNSvInPortW(dwIOAddress, pwData) {                      \
-           *(pwData) = inw(dwIOAddress);                           \
-}
-
-#define VNSvInPortD(dwIOAddress, pdwData) {                     \
-           *(pdwData) = inl(dwIOAddress);                          \
-}
+#define VNSvInPortB(dwIOAddress, pbyData)      \
+do {                                           \
+       *(pbyData) = inb(dwIOAddress);          \
+} while (0)
 
+#define VNSvInPortW(dwIOAddress, pwData)       \
+do {                                           \
+       *(pwData) = inw(dwIOAddress);           \
+} while (0)
 
-#define VNSvOutPortB(dwIOAddress, byData) {                     \
-        outb(byData, dwIOAddress);                              \
-}
+#define VNSvInPortD(dwIOAddress, pdwData)      \
+do {                                           \
+       *(pdwData) = inl(dwIOAddress);          \
+} while (0)
 
+#define VNSvOutPortB(dwIOAddress, byData)      \
+       outb(byData, dwIOAddress)
 
-#define VNSvOutPortW(dwIOAddress, wData) {                      \
-        outw(wData, dwIOAddress);                               \
-}
+#define VNSvOutPortW(dwIOAddress, wData)       \
+       outw(wData, dwIOAddress)
 
-#define VNSvOutPortD(dwIOAddress, dwData) {                     \
-        outl(dwData, dwIOAddress);                              \
-}
+#define VNSvOutPortD(dwIOAddress, dwData)      \
+       outl(dwData, dwIOAddress)
 
 #else
 
 //  For memory mapped IO
 //
 
-
-#define VNSvInPortB(dwIOAddress, pbyData) {                     \
-       volatile unsigned char * pbyAddr = ((unsigned char *)(dwIOAddress));            \
-       *(pbyData) = readb(pbyAddr);                           \
-}
-
-
-#define VNSvInPortW(dwIOAddress, pwData) {                      \
-       volatile unsigned short *pwAddr = ((unsigned short *)(dwIOAddress));             \
-       *(pwData) = readw(pwAddr);                             \
-}
-
-#define VNSvInPortD(dwIOAddress, pdwData) {                     \
-       volatile unsigned long *pdwAddr = ((unsigned long *)(dwIOAddress));          \
-       *(pdwData) = readl(pdwAddr);                           \
-}
-
-
-#define VNSvOutPortB(dwIOAddress, byData) {                     \
-    volatile unsigned char * pbyAddr = ((unsigned char *)(dwIOAddress));            \
-    writeb((unsigned char)byData, pbyAddr);                                                    \
-}
-
-
-#define VNSvOutPortW(dwIOAddress, wData) {                      \
-    volatile unsigned short *pwAddr = ((unsigned short *)(dwIOAddress));             \
-    writew((unsigned short)wData, pwAddr);                                                     \
-}
-
-#define VNSvOutPortD(dwIOAddress, dwData) {                     \
-    volatile unsigned long *pdwAddr = ((unsigned long *)(dwIOAddress));          \
-    writel((unsigned long)dwData, pdwAddr);                                        \
-}
+#define VNSvInPortB(dwIOAddress, pbyData)                              \
+do {                                                                   \
+       volatile unsigned char *pbyAddr = (unsigned char *)(dwIOAddress); \
+       *(pbyData) = readb(pbyAddr);                                    \
+} while (0)
+
+#define VNSvInPortW(dwIOAddress, pwData)                               \
+do {                                                                   \
+       volatile unsigned short *pwAddr = (unsigned short *)(dwIOAddress); \
+       *(pwData) = readw(pwAddr);                                      \
+} while (0)
+
+#define VNSvInPortD(dwIOAddress, pdwData)                              \
+do {                                                                   \
+       volatile unsigned long *pdwAddr = (unsigned long *)(dwIOAddress); \
+       *(pdwData) = readl(pdwAddr);                                    \
+} while (0)
+
+#define VNSvOutPortB(dwIOAddress, byData)                              \
+do {                                                                   \
+       volatile unsigned char *pbyAddr = (unsigned char *)(dwIOAddress); \
+       writeb((unsigned char)byData, pbyAddr);                         \
+} while (0)
+
+#define VNSvOutPortW(dwIOAddress, wData)                               \
+do {                                                                   \
+       volatile unsigned short *pwAddr = ((unsigned short *)(dwIOAddress)); \
+       writew((unsigned short)wData, pwAddr);                          \
+} while (0)
+
+#define VNSvOutPortD(dwIOAddress, dwData)                              \
+do {                                                                   \
+       volatile unsigned long *pdwAddr = (unsigned long *)(dwIOAddress); \
+       writel((unsigned long)dwData, pdwAddr);                         \
+} while (0)
 
 #endif
 
-
 //
 // ALWAYS IO-Mapped IO when in 16-bit/32-bit environment
 //
-#define PCBvInPortB(dwIOAddress, pbyData) {     \
-           *(pbyData) = inb(dwIOAddress);          \
-}
-
-#define PCBvInPortW(dwIOAddress, pwData) {      \
-           *(pwData) = inw(dwIOAddress);           \
-}
-
-#define PCBvInPortD(dwIOAddress, pdwData) {     \
-           *(pdwData) = inl(dwIOAddress);          \
-}
-
-#define PCBvOutPortB(dwIOAddress, byData) {     \
-        outb(byData, dwIOAddress);              \
-}
-
-#define PCBvOutPortW(dwIOAddress, wData) {      \
-        outw(wData, dwIOAddress);               \
-}
-
-#define PCBvOutPortD(dwIOAddress, dwData) {     \
-        outl(dwData, dwIOAddress);              \
-}
-
-
-#define PCAvDelayByIO(uDelayUnit) {             \
-    unsigned char byData;                       \
-    unsigned long ii;                           \
-                                                \
-    if (uDelayUnit <= 50) {                     \
-        udelay(uDelayUnit);                     \
-    }                                           \
-    else {                                      \
-        for (ii = 0; ii < (uDelayUnit); ii++)   \
-                    byData = inb(0x61);                                \
-    }                                           \
-}
-
+#define PCBvInPortB(dwIOAddress, pbyData)      \
+do {                                           \
+       *(pbyData) = inb(dwIOAddress);          \
+} while (0)
+
+#define PCBvInPortW(dwIOAddress, pwData)       \
+do {                                           \
+       *(pwData) = inw(dwIOAddress);           \
+} while (0)
+
+#define PCBvInPortD(dwIOAddress, pdwData)      \
+do {                                           \
+       *(pdwData) = inl(dwIOAddress);          \
+} while (0)
+
+#define PCBvOutPortB(dwIOAddress, byData)      \
+       outb(byData, dwIOAddress)
+
+#define PCBvOutPortW(dwIOAddress, wData)       \
+       outw(wData, dwIOAddress)
+
+#define PCBvOutPortD(dwIOAddress, dwData)      \
+       outl(dwData, dwIOAddress)
+
+#define PCAvDelayByIO(uDelayUnit)                              \
+do {                                                           \
+       unsigned char byData;                                   \
+       unsigned long ii;                                       \
+                                                               \
+       if (uDelayUnit <= 50) {                                 \
+               udelay(uDelayUnit);                             \
+       } else {                                                \
+               for (ii = 0; ii < (uDelayUnit); ii++)           \
+                       byData = inb(0x61);                     \
+       }                                                       \
+} while (0)
 
 /*---------------------  Export Classes  ----------------------------*/
 
 
 /*---------------------  Export Functions  --------------------------*/
 
-
-
-
 #endif // __UPC_H__
-
index 62c44b87d310841d521af16ad583ed17a7113d3a..d8f4f8e7d05eba72281375483ca35fe09f7fbd46 100644 (file)
  *
  * Return Value: none
  *
--*/
+ -*/
 void
-VNTWIFIvSetOPMode (
-    void *pMgmtHandle,
-    WMAC_CONFIG_MODE eOPMode
-    )
+VNTWIFIvSetOPMode(
+       void *pMgmtHandle,
+       WMAC_CONFIG_MODE eOPMode
+)
 {
-    PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
+       PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
 
-    pMgmt->eConfigMode = eOPMode;
+       pMgmt->eConfigMode = eOPMode;
 }
 
-
 /*+
  *
  * Description:
@@ -95,20 +94,20 @@ VNTWIFIvSetOPMode (
  *
  * Return Value: none
  *
--*/
+ -*/
 void
-VNTWIFIvSetIBSSParameter (
-    void *pMgmtHandle,
-    unsigned short wBeaconPeriod,
-    unsigned short wATIMWindow,
-    unsigned int uChannel
-    )
+VNTWIFIvSetIBSSParameter(
+       void *pMgmtHandle,
+       unsigned short wBeaconPeriod,
+       unsigned short wATIMWindow,
+       unsigned int uChannel
+)
 {
-    PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
+       PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
 
-    pMgmt->wIBSSBeaconPeriod = wBeaconPeriod;
-    pMgmt->wIBSSATIMWindow = wATIMWindow;
-    pMgmt->uIBSSChannel = uChannel;
+       pMgmt->wIBSSBeaconPeriod = wBeaconPeriod;
+       pMgmt->wIBSSATIMWindow = wATIMWindow;
+       pMgmt->uIBSSChannel = uChannel;
 }
 
 /*+
@@ -124,14 +123,14 @@ VNTWIFIvSetIBSSParameter (
  *
  * Return Value: current SSID pointer.
  *
--*/
+ -*/
 PWLAN_IE_SSID
-VNTWIFIpGetCurrentSSID (
-    void *pMgmtHandle
-    )
+VNTWIFIpGetCurrentSSID(
+       void *pMgmtHandle
+)
 {
-    PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
-    return((PWLAN_IE_SSID) pMgmt->abyCurrSSID);
+       PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
+       return (PWLAN_IE_SSID) pMgmt->abyCurrSSID;
 }
 
 /*+
@@ -147,17 +146,17 @@ VNTWIFIpGetCurrentSSID (
  *
  * Return Value: current Channel.
  *
--*/
+ -*/
 unsigned int
-VNTWIFIpGetCurrentChannel (
-    void *pMgmtHandle
-    )
+VNTWIFIpGetCurrentChannel(
+       void *pMgmtHandle
+)
 {
-    PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
-    if (pMgmtHandle != NULL) {
-        return (pMgmt->uCurrChannel);
-    }
-    return 0;
+       PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
+       if (pMgmtHandle != NULL) {
+               return pMgmt->uCurrChannel;
+       }
+       return 0;
 }
 
 /*+
@@ -173,18 +172,16 @@ VNTWIFIpGetCurrentChannel (
  *
  * Return Value: current Assoc ID
  *
--*/
+ -*/
 unsigned short
-VNTWIFIwGetAssocID (
-    void *pMgmtHandle
-    )
+VNTWIFIwGetAssocID(
+       void *pMgmtHandle
+)
 {
-    PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
-    return(pMgmt->wCurrAID);
+       PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
+       return pMgmt->wCurrAID;
 }
 
-
-
 /*+
  *
  * Description:
@@ -199,35 +196,35 @@ VNTWIFIwGetAssocID (
  *
  * Return Value: max support rate
  *
--*/
+ -*/
 unsigned char
-VNTWIFIbyGetMaxSupportRate (
-    PWLAN_IE_SUPP_RATES pSupportRateIEs,
-    PWLAN_IE_SUPP_RATES pExtSupportRateIEs
-    )
+VNTWIFIbyGetMaxSupportRate(
+       PWLAN_IE_SUPP_RATES pSupportRateIEs,
+       PWLAN_IE_SUPP_RATES pExtSupportRateIEs
+)
 {
-    unsigned char byMaxSupportRate = RATE_1M;
-    unsigned char bySupportRate = RATE_1M;
-    unsigned int ii = 0;
-
-    if (pSupportRateIEs) {
-        for (ii = 0; ii < pSupportRateIEs->len; ii++) {
-            bySupportRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
-            if (bySupportRate > byMaxSupportRate) {
-                byMaxSupportRate = bySupportRate;
-            }
-        }
-    }
-    if (pExtSupportRateIEs) {
-        for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
-            bySupportRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
-            if (bySupportRate > byMaxSupportRate) {
-                byMaxSupportRate = bySupportRate;
-            }
-        }
-    }
-
-    return byMaxSupportRate;
+       unsigned char byMaxSupportRate = RATE_1M;
+       unsigned char bySupportRate = RATE_1M;
+       unsigned int ii = 0;
+
+       if (pSupportRateIEs) {
+               for (ii = 0; ii < pSupportRateIEs->len; ii++) {
+                       bySupportRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
+                       if (bySupportRate > byMaxSupportRate) {
+                               byMaxSupportRate = bySupportRate;
+                       }
+               }
+       }
+       if (pExtSupportRateIEs) {
+               for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
+                       bySupportRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
+                       if (bySupportRate > byMaxSupportRate) {
+                               byMaxSupportRate = bySupportRate;
+                       }
+               }
+       }
+
+       return byMaxSupportRate;
 }
 
 /*+
@@ -245,48 +242,48 @@ VNTWIFIbyGetMaxSupportRate (
  *
  * Return Value: max support rate
  *
--*/
+ -*/
 unsigned char
-VNTWIFIbyGetACKTxRate (
-    unsigned char byRxDataRate,
-    PWLAN_IE_SUPP_RATES pSupportRateIEs,
-    PWLAN_IE_SUPP_RATES pExtSupportRateIEs
-    )
+VNTWIFIbyGetACKTxRate(
+       unsigned char byRxDataRate,
+       PWLAN_IE_SUPP_RATES pSupportRateIEs,
+       PWLAN_IE_SUPP_RATES pExtSupportRateIEs
+)
 {
-    unsigned char byMaxAckRate;
-    unsigned char byBasicRate;
-    unsigned int ii;
-
-    if (byRxDataRate <= RATE_11M) {
-        byMaxAckRate = RATE_1M;
-    } else  {
-        // 24M is mandatory for 802.11a and 802.11g
-        byMaxAckRate = RATE_24M;
-    }
-    if (pSupportRateIEs) {
-        for (ii = 0; ii < pSupportRateIEs->len; ii++) {
-            if (pSupportRateIEs->abyRates[ii] & 0x80) {
-                byBasicRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
-                if ((byBasicRate <= byRxDataRate) &&
-                    (byBasicRate > byMaxAckRate))  {
-                    byMaxAckRate = byBasicRate;
-                }
-            }
-        }
-    }
-    if (pExtSupportRateIEs) {
-        for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
-            if (pExtSupportRateIEs->abyRates[ii] & 0x80) {
-                byBasicRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
-                if ((byBasicRate <= byRxDataRate) &&
-                    (byBasicRate > byMaxAckRate))  {
-                    byMaxAckRate = byBasicRate;
-                }
-            }
-        }
-    }
-
-    return byMaxAckRate;
+       unsigned char byMaxAckRate;
+       unsigned char byBasicRate;
+       unsigned int ii;
+
+       if (byRxDataRate <= RATE_11M) {
+               byMaxAckRate = RATE_1M;
+       } else  {
+               // 24M is mandatory for 802.11a and 802.11g
+               byMaxAckRate = RATE_24M;
+       }
+       if (pSupportRateIEs) {
+               for (ii = 0; ii < pSupportRateIEs->len; ii++) {
+                       if (pSupportRateIEs->abyRates[ii] & 0x80) {
+                               byBasicRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
+                               if ((byBasicRate <= byRxDataRate) &&
+                                   (byBasicRate > byMaxAckRate))  {
+                                       byMaxAckRate = byBasicRate;
+                               }
+                       }
+               }
+       }
+       if (pExtSupportRateIEs) {
+               for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
+                       if (pExtSupportRateIEs->abyRates[ii] & 0x80) {
+                               byBasicRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
+                               if ((byBasicRate <= byRxDataRate) &&
+                                   (byBasicRate > byMaxAckRate))  {
+                                       byMaxAckRate = byBasicRate;
+                               }
+                       }
+               }
+       }
+
+       return byMaxAckRate;
 }
 
 /*+
@@ -303,22 +300,22 @@ VNTWIFIbyGetACKTxRate (
  *
  * Return Value: none
  *
--*/
+ -*/
 void
-VNTWIFIvSetAuthenticationMode (
-    void *pMgmtHandle,
-    WMAC_AUTHENTICATION_MODE eAuthMode
-    )
+VNTWIFIvSetAuthenticationMode(
+       void *pMgmtHandle,
+       WMAC_AUTHENTICATION_MODE eAuthMode
+)
 {
-    PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
-
-    pMgmt->eAuthenMode = eAuthMode;
-    if ((eAuthMode == WMAC_AUTH_SHAREKEY) ||
-        (eAuthMode == WMAC_AUTH_AUTO)) {
-        pMgmt->bShareKeyAlgorithm = true;
-    } else {
-        pMgmt->bShareKeyAlgorithm = false;
-    }
+       PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
+
+       pMgmt->eAuthenMode = eAuthMode;
+       if ((eAuthMode == WMAC_AUTH_SHAREKEY) ||
+           (eAuthMode == WMAC_AUTH_AUTO)) {
+               pMgmt->bShareKeyAlgorithm = true;
+       } else {
+               pMgmt->bShareKeyAlgorithm = false;
+       }
 }
 
 /*+
@@ -335,59 +332,56 @@ VNTWIFIvSetAuthenticationMode (
  *
  * Return Value: none
  *
--*/
+ -*/
 void
-VNTWIFIvSetEncryptionMode (
-    void *pMgmtHandle,
-    WMAC_ENCRYPTION_MODE eEncryptionMode
-    )
+VNTWIFIvSetEncryptionMode(
+       void *pMgmtHandle,
+       WMAC_ENCRYPTION_MODE eEncryptionMode
+)
 {
-    PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
-
-    pMgmt->eEncryptionMode = eEncryptionMode;
-    if ((eEncryptionMode == WMAC_ENCRYPTION_WEPEnabled) ||
-        (eEncryptionMode == WMAC_ENCRYPTION_TKIPEnabled) ||
-        (eEncryptionMode == WMAC_ENCRYPTION_AESEnabled) ) {
-        pMgmt->bPrivacyInvoked = true;
-    } else {
-        pMgmt->bPrivacyInvoked = false;
-    }
+       PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
+
+       pMgmt->eEncryptionMode = eEncryptionMode;
+       if ((eEncryptionMode == WMAC_ENCRYPTION_WEPEnabled) ||
+           (eEncryptionMode == WMAC_ENCRYPTION_TKIPEnabled) ||
+           (eEncryptionMode == WMAC_ENCRYPTION_AESEnabled)) {
+               pMgmt->bPrivacyInvoked = true;
+       } else {
+               pMgmt->bPrivacyInvoked = false;
+       }
 }
 
-
-
 bool
-VNTWIFIbConfigPhyMode (
-    void *pMgmtHandle,
-    CARD_PHY_TYPE ePhyType
-    )
+VNTWIFIbConfigPhyMode(
+       void *pMgmtHandle,
+       CARD_PHY_TYPE ePhyType
+)
 {
-    PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
-
-    if ((ePhyType != PHY_TYPE_AUTO) &&
-        (ePhyType != pMgmt->eCurrentPHYMode)) {
-        if (CARDbSetPhyParameter(pMgmt->pAdapter, ePhyType, 0, 0, NULL, NULL)==true) {
-            pMgmt->eCurrentPHYMode = ePhyType;
-        } else {
-            return(false);
-        }
-    }
-    pMgmt->eConfigPHYMode = ePhyType;
-    return(true);
+       PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
+
+       if ((ePhyType != PHY_TYPE_AUTO) &&
+           (ePhyType != pMgmt->eCurrentPHYMode)) {
+               if (CARDbSetPhyParameter(pMgmt->pAdapter, ePhyType, 0, 0, NULL, NULL) == true) {
+                       pMgmt->eCurrentPHYMode = ePhyType;
+               } else {
+                       return false;
+               }
+       }
+       pMgmt->eConfigPHYMode = ePhyType;
+       return true;
 }
 
-
 void
-VNTWIFIbGetConfigPhyMode (
-    void *pMgmtHandle,
-    void *pePhyType
-    )
+VNTWIFIbGetConfigPhyMode(
+       void *pMgmtHandle,
+       void *pePhyType
+)
 {
-    PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
+       PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
 
-    if ((pMgmt != NULL) && (pePhyType != NULL)) {
-        *(PCARD_PHY_TYPE)pePhyType = pMgmt->eConfigPHYMode;
-    }
+       if ((pMgmt != NULL) && (pePhyType != NULL)) {
+               *(PCARD_PHY_TYPE)pePhyType = pMgmt->eConfigPHYMode;
+       }
 }
 
 /*+
@@ -403,8 +397,7 @@ VNTWIFIbGetConfigPhyMode (
  *
  * Return Value: None.
  *
--*/
-
+ -*/
 
 /*+
  *
@@ -420,62 +413,55 @@ VNTWIFIbGetConfigPhyMode (
  *
  * Return Value: None.
  *
--*/
+ -*/
 
 void
 VNTWIFIvQueryBSSList(void *pMgmtHandle, unsigned int *puBSSCount, void **pvFirstBSS)
 {
-    unsigned int ii = 0;
-    PSMgmtObject    pMgmt = (PSMgmtObject)pMgmtHandle;
-    PKnownBSS       pBSS = NULL;
-    unsigned int uCount = 0;
-
-    *pvFirstBSS = NULL;
-
-    for (ii = 0; ii < MAX_BSS_NUM; ii++) {
-        pBSS = &(pMgmt->sBSSList[ii]);
-        if (!pBSS->bActive) {
-            continue;
-        }
-        if (*pvFirstBSS == NULL) {
-            *pvFirstBSS = &(pMgmt->sBSSList[ii]);
-        }
-        uCount++;
-    }
-    *puBSSCount = uCount;
+       unsigned int ii = 0;
+       PSMgmtObject    pMgmt = (PSMgmtObject)pMgmtHandle;
+       PKnownBSS       pBSS = NULL;
+       unsigned int uCount = 0;
+
+       *pvFirstBSS = NULL;
+
+       for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+               pBSS = &(pMgmt->sBSSList[ii]);
+               if (!pBSS->bActive) {
+                       continue;
+               }
+               if (*pvFirstBSS == NULL) {
+                       *pvFirstBSS = &(pMgmt->sBSSList[ii]);
+               }
+               uCount++;
+       }
+       *puBSSCount = uCount;
 }
 
-
-
-
 void
-VNTWIFIvGetNextBSS (
-    void *pMgmtHandle,
-    void *pvCurrentBSS,
-    void **pvNextBSS
-    )
+VNTWIFIvGetNextBSS(
+       void *pMgmtHandle,
+       void *pvCurrentBSS,
+       void **pvNextBSS
+)
 {
-    PKnownBSS       pBSS = (PKnownBSS) pvCurrentBSS;
-    PSMgmtObject    pMgmt = (PSMgmtObject)pMgmtHandle;
-
-    *pvNextBSS = NULL;
-
-    while (*pvNextBSS == NULL) {
-        pBSS++;
-        if (pBSS > &(pMgmt->sBSSList[MAX_BSS_NUM])) {
-            return;
-        }
-        if (pBSS->bActive == true) {
-            *pvNextBSS = pBSS;
-            return;
-        }
-    }
+       PKnownBSS       pBSS = (PKnownBSS) pvCurrentBSS;
+       PSMgmtObject    pMgmt = (PSMgmtObject)pMgmtHandle;
+
+       *pvNextBSS = NULL;
+
+       while (*pvNextBSS == NULL) {
+               pBSS++;
+               if (pBSS > &(pMgmt->sBSSList[MAX_BSS_NUM])) {
+                       return;
+               }
+               if (pBSS->bActive == true) {
+                       *pvNextBSS = pBSS;
+                       return;
+               }
+       }
 }
 
-
-
-
-
 /*+
  *
  * Description:
@@ -487,319 +473,304 @@ VNTWIFIvGetNextBSS (
  *
  * Return Value: none
  *
--*/
+ -*/
 void
 VNTWIFIvUpdateNodeTxCounter(
-    void *pMgmtHandle,
-    unsigned char *pbyDestAddress,
-    bool bTxOk,
-    unsigned short wRate,
-    unsigned char *pbyTxFailCount
-    )
+       void *pMgmtHandle,
+       unsigned char *pbyDestAddress,
+       bool bTxOk,
+       unsigned short wRate,
+       unsigned char *pbyTxFailCount
+)
 {
-    PSMgmtObject    pMgmt = (PSMgmtObject)pMgmtHandle;
-    unsigned int uNodeIndex = 0;
-    unsigned int ii;
-
-    if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
-        (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
-        if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex) == false) {
-            return;
-        }
-    }
-    pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts++;
-    if (bTxOk == true) {
-        // transmit success, TxAttempts at least plus one
-        pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
-        pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wRate]++;
-    } else {
-        pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
-    }
-    pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += pbyTxFailCount[MAX_RATE];
-    for(ii=0;ii<MAX_RATE;ii++) {
-        pMgmt->sNodeDBTable[uNodeIndex].uTxFail[ii] += pbyTxFailCount[ii];
-    }
-    return;
+       PSMgmtObject    pMgmt = (PSMgmtObject)pMgmtHandle;
+       unsigned int uNodeIndex = 0;
+       unsigned int ii;
+
+       if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
+           (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
+               if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex) == false) {
+                       return;
+               }
+       }
+       pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts++;
+       if (bTxOk == true) {
+               // transmit success, TxAttempts at least plus one
+               pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
+               pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wRate]++;
+       } else {
+               pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
+       }
+       pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += pbyTxFailCount[MAX_RATE];
+       for (ii = 0; ii < MAX_RATE; ii++) {
+               pMgmt->sNodeDBTable[uNodeIndex].uTxFail[ii] += pbyTxFailCount[ii];
+       }
+       return;
 }
 
-
 void
 VNTWIFIvGetTxRate(
-    void *pMgmtHandle,
-    unsigned char *pbyDestAddress,
-    unsigned short *pwTxDataRate,
-    unsigned char *pbyACKRate,
-    unsigned char *pbyCCKBasicRate,
-    unsigned char *pbyOFDMBasicRate
-    )
+       void *pMgmtHandle,
+       unsigned char *pbyDestAddress,
+       unsigned short *pwTxDataRate,
+       unsigned char *pbyACKRate,
+       unsigned char *pbyCCKBasicRate,
+       unsigned char *pbyOFDMBasicRate
+)
 {
-    PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
-    unsigned int uNodeIndex = 0;
-    unsigned short wTxDataRate = RATE_1M;
-    unsigned char byACKRate = RATE_1M;
-    unsigned char byCCKBasicRate = RATE_1M;
-    unsigned char byOFDMBasicRate = RATE_24M;
-    PWLAN_IE_SUPP_RATES pSupportRateIEs = NULL;
-    PWLAN_IE_SUPP_RATES pExtSupportRateIEs = NULL;
-
-
-    if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
-        (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
-        // Adhoc Tx rate decided from node DB
-        if(BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex)) {
-            wTxDataRate = (pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
-            pSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrSuppRates);
-            pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrExtSuppRates);
-        } else {
-            if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
-                wTxDataRate = RATE_2M;
-            } else {
-                wTxDataRate = RATE_24M;
-            }
-            pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
-            pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
-        }
-    } else { // Infrastructure: rate decided from AP Node, index = 0
+       PSMgmtObject        pMgmt = (PSMgmtObject)pMgmtHandle;
+       unsigned int uNodeIndex = 0;
+       unsigned short wTxDataRate = RATE_1M;
+       unsigned char byACKRate = RATE_1M;
+       unsigned char byCCKBasicRate = RATE_1M;
+       unsigned char byOFDMBasicRate = RATE_24M;
+       PWLAN_IE_SUPP_RATES pSupportRateIEs = NULL;
+       PWLAN_IE_SUPP_RATES pExtSupportRateIEs = NULL;
+
+       if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
+           (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
+               // Adhoc Tx rate decided from node DB
+               if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex)) {
+                       wTxDataRate = (pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
+                       pSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrSuppRates);
+                       pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrExtSuppRates);
+               } else {
+                       if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
+                               wTxDataRate = RATE_2M;
+                       } else {
+                               wTxDataRate = RATE_24M;
+                       }
+                       pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
+                       pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
+               }
+       } else { // Infrastructure: rate decided from AP Node, index = 0
 
                wTxDataRate = (pMgmt->sNodeDBTable[0].wTxDataRate);
 #ifdef PLICE_DEBUG
                printk(KERN_DEBUG "GetTxRate:AP MAC is %pM,TxRate is %d\n",
-                               pMgmt->sNodeDBTable[0].abyMACAddr, wTxDataRate);
+                      pMgmt->sNodeDBTable[0].abyMACAddr, wTxDataRate);
 #endif
 
-
-        pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
-        pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
-    }
-    byACKRate = VNTWIFIbyGetACKTxRate(  (unsigned char) wTxDataRate,
-                                        pSupportRateIEs,
-                                        pExtSupportRateIEs
-                                        );
-    if (byACKRate > (unsigned char) wTxDataRate) {
-        byACKRate = (unsigned char) wTxDataRate;
-    }
-    byCCKBasicRate = VNTWIFIbyGetACKTxRate( RATE_11M,
-                                            pSupportRateIEs,
-                                            pExtSupportRateIEs
-                                            );
-    byOFDMBasicRate = VNTWIFIbyGetACKTxRate(RATE_54M,
-                                            pSupportRateIEs,
-                                            pExtSupportRateIEs
-                                            );
-    *pwTxDataRate = wTxDataRate;
-    *pbyACKRate = byACKRate;
-    *pbyCCKBasicRate = byCCKBasicRate;
-    *pbyOFDMBasicRate = byOFDMBasicRate;
-    return;
+               pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
+               pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
+       }
+       byACKRate = VNTWIFIbyGetACKTxRate((unsigned char) wTxDataRate,
+                                           pSupportRateIEs,
+                                           pExtSupportRateIEs
+);
+       if (byACKRate > (unsigned char) wTxDataRate) {
+               byACKRate = (unsigned char) wTxDataRate;
+       }
+       byCCKBasicRate = VNTWIFIbyGetACKTxRate(RATE_11M,
+                                               pSupportRateIEs,
+                                               pExtSupportRateIEs
+);
+       byOFDMBasicRate = VNTWIFIbyGetACKTxRate(RATE_54M,
+                                               pSupportRateIEs,
+                                               pExtSupportRateIEs
+);
+       *pwTxDataRate = wTxDataRate;
+       *pbyACKRate = byACKRate;
+       *pbyCCKBasicRate = byCCKBasicRate;
+       *pbyOFDMBasicRate = byOFDMBasicRate;
+       return;
 }
 
 unsigned char
 VNTWIFIbyGetKeyCypher(
-    void *pMgmtHandle,
-    bool bGroupKey
-    )
+       void *pMgmtHandle,
+       bool bGroupKey
+)
 {
-    PSMgmtObject    pMgmt = (PSMgmtObject)pMgmtHandle;
+       PSMgmtObject    pMgmt = (PSMgmtObject)pMgmtHandle;
 
-    if (bGroupKey == true) {
-        return (pMgmt->byCSSGK);
-    } else {
-        return (pMgmt->byCSSPK);
-    }
+       if (bGroupKey == true) {
+               return pMgmt->byCSSGK;
+       } else {
+               return pMgmt->byCSSPK;
+       }
 }
 
-
 /*
-bool
-VNTWIFIbInit(
-    void *pAdapterHandler,
-    void **pMgmtHandler
-    )
-{
-
-    PSMgmtObject        pMgmt = NULL;
-    unsigned int ii;
-
-
-    pMgmt = (PSMgmtObject)kmalloc(sizeof(SMgmtObject), (int)GFP_ATOMIC);
-    if (pMgmt == NULL) {
-        *pMgmtHandler = NULL;
-        return false;
-    }
-
-    memset(pMgmt, 0, sizeof(SMgmtObject));
-    pMgmt->pAdapter = (void *) pAdapterHandler;
-
-    // should initial MAC address abyMACAddr
-    for(ii=0;ii<WLAN_BSSID_LEN;ii++) {
-        pMgmt->abyDesireBSSID[ii] = 0xFF;
-    }
-    pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
-    pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
-    pMgmt->byCSSPK = KEY_CTL_NONE;
-    pMgmt->byCSSGK = KEY_CTL_NONE;
-    pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
-
-    pMgmt->cbFreeCmdQueue = CMD_Q_SIZE;
-    pMgmt->uCmdDequeueIdx = 0;
-    pMgmt->uCmdEnqueueIdx = 0;
-    pMgmt->eCommandState = WLAN_CMD_STATE_IDLE;
-    pMgmt->bCmdStop = false;
-    pMgmt->bCmdRunning = false;
-
-    *pMgmtHandler = pMgmt;
-    return true;
-}
+  bool
+  VNTWIFIbInit(
+  void *pAdapterHandler,
+  void **pMgmtHandler
+) {
+  PSMgmtObject        pMgmt = NULL;
+  unsigned int ii;
+
+  pMgmt = (PSMgmtObject)kmalloc(sizeof(SMgmtObject), (int)GFP_ATOMIC);
+  if (pMgmt == NULL) {
+  *pMgmtHandler = NULL;
+  return false;
+  }
+
+  memset(pMgmt, 0, sizeof(SMgmtObject));
+  pMgmt->pAdapter = (void *) pAdapterHandler;
+
+  // should initial MAC address abyMACAddr
+  for (ii=0; ii<WLAN_BSSID_LEN; ii++) {
+  pMgmt->abyDesireBSSID[ii] = 0xFF;
+  }
+  pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
+  pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
+  pMgmt->byCSSPK = KEY_CTL_NONE;
+  pMgmt->byCSSGK = KEY_CTL_NONE;
+  pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
+
+  pMgmt->cbFreeCmdQueue = CMD_Q_SIZE;
+  pMgmt->uCmdDequeueIdx = 0;
+  pMgmt->uCmdEnqueueIdx = 0;
+  pMgmt->eCommandState = WLAN_CMD_STATE_IDLE;
+  pMgmt->bCmdStop = false;
+  pMgmt->bCmdRunning = false;
+
+  *pMgmtHandler = pMgmt;
+  return true;
+  }
 */
 
-
-
 bool
-VNTWIFIbSetPMKIDCache (
-    void *pMgmtObject,
-    unsigned long ulCount,
-    void *pPMKIDInfo
-    )
+VNTWIFIbSetPMKIDCache(
+       void *pMgmtObject,
+       unsigned long ulCount,
+       void *pPMKIDInfo
+)
 {
-    PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
-
-    if (ulCount > MAX_PMKID_CACHE) {
-        return (false);
-    }
-    pMgmt->gsPMKIDCache.BSSIDInfoCount = ulCount;
-    memcpy(pMgmt->gsPMKIDCache.BSSIDInfo, pPMKIDInfo, (ulCount*sizeof(PMKIDInfo)));
-    return (true);
+       PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
+
+       if (ulCount > MAX_PMKID_CACHE) {
+               return false;
+       }
+       pMgmt->gsPMKIDCache.BSSIDInfoCount = ulCount;
+       memcpy(pMgmt->gsPMKIDCache.BSSIDInfo, pPMKIDInfo, (ulCount*sizeof(PMKIDInfo)));
+       return true;
 }
 
-
-
 unsigned short
 VNTWIFIwGetMaxSupportRate(
-    void *pMgmtObject
-    )
+       void *pMgmtObject
+)
 {
-    unsigned short wRate = RATE_54M;
-    PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
-
-    for(wRate = RATE_54M; wRate > RATE_1M; wRate--) {
-        if (pMgmt->sNodeDBTable[0].wSuppRate & (1<<wRate)) {
-            return (wRate);
-        }
-    }
-    if (pMgmt->eCurrentPHYMode == PHY_TYPE_11A) {
-        return (RATE_6M);
-    } else {
-        return (RATE_1M);
-    }
+       unsigned short wRate = RATE_54M;
+       PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
+
+       for (wRate = RATE_54M; wRate > RATE_1M; wRate--) {
+               if (pMgmt->sNodeDBTable[0].wSuppRate & (1<<wRate)) {
+                       return wRate;
+               }
+       }
+       if (pMgmt->eCurrentPHYMode == PHY_TYPE_11A) {
+               return RATE_6M;
+       } else {
+               return RATE_1M;
+       }
 }
 
-
 void
-VNTWIFIvSet11h (
-    void *pMgmtObject,
-    bool b11hEnable
-    )
+VNTWIFIvSet11h(
+       void *pMgmtObject,
+       bool b11hEnable
+)
 {
-    PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
+       PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
 
-    pMgmt->b11hEnable = b11hEnable;
+       pMgmt->b11hEnable = b11hEnable;
 }
 
 bool
 VNTWIFIbMeasureReport(
-    void *pMgmtObject,
-    bool bEndOfReport,
-    void *pvMeasureEID,
-    unsigned char byReportMode,
-    unsigned char byBasicMap,
-    unsigned char byCCAFraction,
-    unsigned char *pbyRPIs
-    )
+       void *pMgmtObject,
+       bool bEndOfReport,
+       void *pvMeasureEID,
+       unsigned char byReportMode,
+       unsigned char byBasicMap,
+       unsigned char byCCAFraction,
+       unsigned char *pbyRPIs
+)
 {
-    PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
-    unsigned char *pbyCurrentEID = (unsigned char *) (pMgmt->pCurrMeasureEIDRep);
-
-    //spin_lock_irq(&pDevice->lock);
-    if ((pvMeasureEID != NULL) &&
-        (pMgmt->uLengthOfRepEIDs < (WLAN_A3FR_MAXLEN - sizeof(MEASEURE_REP) - sizeof(WLAN_80211HDR_A3) - 3))
-        ) {
-        pMgmt->pCurrMeasureEIDRep->byElementID = WLAN_EID_MEASURE_REP;
-        pMgmt->pCurrMeasureEIDRep->len = 3;
-        pMgmt->pCurrMeasureEIDRep->byToken = ((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->byToken;
-        pMgmt->pCurrMeasureEIDRep->byMode = byReportMode;
-        pMgmt->pCurrMeasureEIDRep->byType = ((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->byType;
-        switch (pMgmt->pCurrMeasureEIDRep->byType) {
-            case MEASURE_TYPE_BASIC :
-                pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_BASIC);
-                memcpy(   &(pMgmt->pCurrMeasureEIDRep->sRep.sBasic),
-                            &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
-                            sizeof(MEASEURE_REQ));
-                pMgmt->pCurrMeasureEIDRep->sRep.sBasic.byMap = byBasicMap;
-                break;
-            case MEASURE_TYPE_CCA :
-                pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_CCA);
-                memcpy(   &(pMgmt->pCurrMeasureEIDRep->sRep.sCCA),
-                            &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
-                            sizeof(MEASEURE_REQ));
-                pMgmt->pCurrMeasureEIDRep->sRep.sCCA.byCCABusyFraction = byCCAFraction;
-                break;
-            case MEASURE_TYPE_RPI :
-                pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_RPI);
-                memcpy(   &(pMgmt->pCurrMeasureEIDRep->sRep.sRPI),
-                            &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
-                            sizeof(MEASEURE_REQ));
-                memcpy(pMgmt->pCurrMeasureEIDRep->sRep.sRPI.abyRPIdensity, pbyRPIs, 8);
-                break;
-            default :
-                break;
-        }
-        pbyCurrentEID += (2 + pMgmt->pCurrMeasureEIDRep->len);
-        pMgmt->uLengthOfRepEIDs += (2 + pMgmt->pCurrMeasureEIDRep->len);
-        pMgmt->pCurrMeasureEIDRep = (PWLAN_IE_MEASURE_REP) pbyCurrentEID;
-    }
-    if (bEndOfReport == true) {
-        IEEE11hbMSRRepTx(pMgmt);
-    }
-    //spin_unlock_irq(&pDevice->lock);
-    return (true);
+       PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
+       unsigned char *pbyCurrentEID = (unsigned char *)(pMgmt->pCurrMeasureEIDRep);
+
+       //spin_lock_irq(&pDevice->lock);
+       if ((pvMeasureEID != NULL) &&
+           (pMgmt->uLengthOfRepEIDs < (WLAN_A3FR_MAXLEN - sizeof(MEASEURE_REP) - sizeof(WLAN_80211HDR_A3) - 3))
+) {
+               pMgmt->pCurrMeasureEIDRep->byElementID = WLAN_EID_MEASURE_REP;
+               pMgmt->pCurrMeasureEIDRep->len = 3;
+               pMgmt->pCurrMeasureEIDRep->byToken = ((PWLAN_IE_MEASURE_REQ)pvMeasureEID)->byToken;
+               pMgmt->pCurrMeasureEIDRep->byMode = byReportMode;
+               pMgmt->pCurrMeasureEIDRep->byType = ((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->byType;
+               switch (pMgmt->pCurrMeasureEIDRep->byType) {
+               case MEASURE_TYPE_BASIC:
+                       pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_BASIC);
+                       memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sBasic),
+                              &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
+                              sizeof(MEASEURE_REQ));
+                       pMgmt->pCurrMeasureEIDRep->sRep.sBasic.byMap = byBasicMap;
+                       break;
+               case MEASURE_TYPE_CCA:
+                       pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_CCA);
+                       memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sCCA),
+                              &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
+                              sizeof(MEASEURE_REQ));
+                       pMgmt->pCurrMeasureEIDRep->sRep.sCCA.byCCABusyFraction = byCCAFraction;
+                       break;
+               case MEASURE_TYPE_RPI:
+                       pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_RPI);
+                       memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sRPI),
+                              &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
+                              sizeof(MEASEURE_REQ));
+                       memcpy(pMgmt->pCurrMeasureEIDRep->sRep.sRPI.abyRPIdensity, pbyRPIs, 8);
+                       break;
+               default:
+                       break;
+               }
+               pbyCurrentEID += (2 + pMgmt->pCurrMeasureEIDRep->len);
+               pMgmt->uLengthOfRepEIDs += (2 + pMgmt->pCurrMeasureEIDRep->len);
+               pMgmt->pCurrMeasureEIDRep = (PWLAN_IE_MEASURE_REP) pbyCurrentEID;
+       }
+       if (bEndOfReport == true) {
+               IEEE11hbMSRRepTx(pMgmt);
+       }
+       //spin_unlock_irq(&pDevice->lock);
+       return true;
 }
 
-
 bool
 VNTWIFIbChannelSwitch(
-    void *pMgmtObject,
-    unsigned char byNewChannel
-    )
+       void *pMgmtObject,
+       unsigned char byNewChannel
+)
 {
-    PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
+       PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
 
-    //spin_lock_irq(&pDevice->lock);
-    pMgmt->uCurrChannel = byNewChannel;
-    pMgmt->bSwitchChannel = false;
-    //spin_unlock_irq(&pDevice->lock);
-    return true;
+       //spin_lock_irq(&pDevice->lock);
+       pMgmt->uCurrChannel = byNewChannel;
+       pMgmt->bSwitchChannel = false;
+       //spin_unlock_irq(&pDevice->lock);
+       return true;
 }
 
 /*
-bool
-VNTWIFIbRadarPresent(
-    void *pMgmtObject,
-    unsigned char byChannel
-    )
-{
-    PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
-    if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
-        (byChannel == (unsigned char) pMgmt->uCurrChannel) &&
-        (pMgmt->bSwitchChannel != true) &&
-        (pMgmt->b11hEnable == true)) {
-        if (!compare_ether_addr(pMgmt->abyIBSSDFSOwner, CARDpGetCurrentAddress(pMgmt->pAdapter))) {
-            pMgmt->byNewChannel = CARDbyAutoChannelSelect(pMgmt->pAdapter,(unsigned char) pMgmt->uCurrChannel);
-            pMgmt->bSwitchChannel = true;
-        }
-        BEACONbSendBeacon(pMgmt);
-        CARDbChannelSwitch(pMgmt->pAdapter, 0, pMgmt->byNewChannel, 10);
-    }
-    return true;
-}
+  bool
+  VNTWIFIbRadarPresent(
+  void *pMgmtObject,
+  unsigned char byChannel
+) {
+  PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
+  if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
+  (byChannel == (unsigned char) pMgmt->uCurrChannel) &&
+  (pMgmt->bSwitchChannel != true) &&
+  (pMgmt->b11hEnable == true)) {
+  if (!compare_ether_addr(pMgmt->abyIBSSDFSOwner, CARDpGetCurrentAddress(pMgmt->pAdapter))) {
+  pMgmt->byNewChannel = CARDbyAutoChannelSelect(pMgmt->pAdapter,(unsigned char) pMgmt->uCurrChannel);
+  pMgmt->bSwitchChannel = true;
+  }
+  BEACONbSendBeacon(pMgmt);
+  CARDbChannelSwitch(pMgmt->pAdapter, 0, pMgmt->byNewChannel, 10);
+  }
+  return true;
+  }
 */
-
index f4327abaa773f400e1a5a7131c8f20e3f9ace4dc..4b01ebd7299a658099fc45c2136e7c7252c042e6 100644 (file)
 
 // Pre-configured Authenticaiton Mode (from XP)
 typedef enum tagWMAC_AUTHENTICATION_MODE {
-
-    WMAC_AUTH_OPEN,
-    WMAC_AUTH_SHAREKEY,
-    WMAC_AUTH_AUTO,
-    WMAC_AUTH_WPA,
-    WMAC_AUTH_WPAPSK,
-    WMAC_AUTH_WPANONE,
-    WMAC_AUTH_WPA2,
-    WMAC_AUTH_WPA2PSK,
-    WMAC_AUTH_MAX       // Not a real mode, defined as upper bound
-
+       WMAC_AUTH_OPEN,
+       WMAC_AUTH_SHAREKEY,
+       WMAC_AUTH_AUTO,
+       WMAC_AUTH_WPA,
+       WMAC_AUTH_WPAPSK,
+       WMAC_AUTH_WPANONE,
+       WMAC_AUTH_WPA2,
+       WMAC_AUTH_WPA2PSK,
+       WMAC_AUTH_MAX       // Not a real mode, defined as upper bound
 } WMAC_AUTHENTICATION_MODE, *PWMAC_AUTHENTICATION_MODE;
 
 typedef enum tagWMAC_ENCRYPTION_MODE {
-
-    WMAC_ENCRYPTION_WEPEnabled,
-    WMAC_ENCRYPTION_WEPDisabled,
-    WMAC_ENCRYPTION_WEPKeyAbsent,
-    WMAC_ENCRYPTION_WEPNotSupported,
-    WMAC_ENCRYPTION_TKIPEnabled,
-    WMAC_ENCRYPTION_TKIPKeyAbsent,
-    WMAC_ENCRYPTION_AESEnabled,
-    WMAC_ENCRYPTION_AESKeyAbsent
-
+       WMAC_ENCRYPTION_WEPEnabled,
+       WMAC_ENCRYPTION_WEPDisabled,
+       WMAC_ENCRYPTION_WEPKeyAbsent,
+       WMAC_ENCRYPTION_WEPNotSupported,
+       WMAC_ENCRYPTION_TKIPEnabled,
+       WMAC_ENCRYPTION_TKIPKeyAbsent,
+       WMAC_ENCRYPTION_AESEnabled,
+       WMAC_ENCRYPTION_AESKeyAbsent
 } WMAC_ENCRYPTION_MODE, *PWMAC_ENCRYPTION_MODE;
 
 // Pre-configured Mode (from XP)
 
 typedef enum tagWMAC_CONFIG_MODE {
-
-    WMAC_CONFIG_ESS_STA = 0,
-    WMAC_CONFIG_IBSS_STA,
-    WMAC_CONFIG_AUTO,
-    WMAC_CONFIG_AP
-
+       WMAC_CONFIG_ESS_STA = 0,
+       WMAC_CONFIG_IBSS_STA,
+       WMAC_CONFIG_AUTO,
+       WMAC_CONFIG_AP
 } WMAC_CONFIG_MODE, *PWMAC_CONFIG_MODE;
 
-
-
 typedef enum tagWMAC_POWER_MODE {
-
-    WMAC_POWER_CAM,
-    WMAC_POWER_FAST,
-    WMAC_POWER_MAX
-
+       WMAC_POWER_CAM,
+       WMAC_POWER_FAST,
+       WMAC_POWER_MAX
 } WMAC_POWER_MODE, *PWMAC_POWER_MODE;
 
 #define VNTWIFIbIsShortSlotTime(wCapInfo)               \
-        WLAN_GET_CAP_INFO_SHORTSLOTTIME(wCapInfo)       \
+       WLAN_GET_CAP_INFO_SHORTSLOTTIME(wCapInfo)       \
 
 #define VNTWIFIbIsProtectMode(byERP)                    \
-        ((byERP & WLAN_EID_ERP_USE_PROTECTION) != 0)    \
+       ((byERP & WLAN_EID_ERP_USE_PROTECTION) != 0)    \
 
 #define VNTWIFIbIsBarkerMode(byERP)                     \
-        ((byERP & WLAN_EID_ERP_BARKER_MODE) != 0)       \
+       ((byERP & WLAN_EID_ERP_BARKER_MODE) != 0)       \
 
 #define VNTWIFIbIsShortPreamble(wCapInfo)               \
-        WLAN_GET_CAP_INFO_SHORTPREAMBLE(wCapInfo)       \
-
-#define VNTWIFIbIsEncryption(wCapInfo)                  \
-        WLAN_GET_CAP_INFO_PRIVACY(wCapInfo)             \
+       WLAN_GET_CAP_INFO_SHORTPREAMBLE(wCapInfo)       \
 
-#define VNTWIFIbIsESS(wCapInfo)                         \
-        WLAN_GET_CAP_INFO_ESS(wCapInfo)                 \
+#define VNTWIFIbIsEncryption(wCapInfo)         \
+       WLAN_GET_CAP_INFO_PRIVACY(wCapInfo)     \
 
+#define VNTWIFIbIsESS(wCapInfo)                        \
+       WLAN_GET_CAP_INFO_ESS(wCapInfo)         \
 
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Types  ------------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
 void
-VNTWIFIvSetIBSSParameter (
-    void *pMgmtHandle,
-    unsigned short wBeaconPeriod,
-    unsigned short wATIMWindow,
-    unsigned int uChannel
-    );
+VNTWIFIvSetIBSSParameter(
+       void *pMgmtHandle,
+       unsigned short wBeaconPeriod,
+       unsigned short wATIMWindow,
+       unsigned int uChannel
+);
 
 void
-VNTWIFIvSetOPMode (
-    void *pMgmtHandle,
-    WMAC_CONFIG_MODE eOPMode
-    );
+VNTWIFIvSetOPMode(
+       void *pMgmtHandle,
+       WMAC_CONFIG_MODE eOPMode
+);
 
 PWLAN_IE_SSID
 VNTWIFIpGetCurrentSSID(
-    void *pMgmtHandle
-    );
+       void *pMgmtHandle
+);
 
 unsigned int
 VNTWIFIpGetCurrentChannel(
-    void *pMgmtHandle
-    );
+       void *pMgmtHandle
+);
 
 unsigned short
-VNTWIFIwGetAssocID (
-    void *pMgmtHandle
-    );
+VNTWIFIwGetAssocID(
+       void *pMgmtHandle
+);
 
 unsigned char
-VNTWIFIbyGetMaxSupportRate (
-    PWLAN_IE_SUPP_RATES pSupportRateIEs,
-    PWLAN_IE_SUPP_RATES pExtSupportRateIEs
-    );
+VNTWIFIbyGetMaxSupportRate(
+       PWLAN_IE_SUPP_RATES pSupportRateIEs,
+       PWLAN_IE_SUPP_RATES pExtSupportRateIEs
+);
 
 unsigned char
-VNTWIFIbyGetACKTxRate (
-    unsigned char byRxDataRate,
-    PWLAN_IE_SUPP_RATES pSupportRateIEs,
-    PWLAN_IE_SUPP_RATES pExtSupportRateIEs
-    );
+VNTWIFIbyGetACKTxRate(
+       unsigned char byRxDataRate,
+       PWLAN_IE_SUPP_RATES pSupportRateIEs,
+       PWLAN_IE_SUPP_RATES pExtSupportRateIEs
+);
 
 void
-VNTWIFIvSetAuthenticationMode (
-    void *pMgmtHandle,
-    WMAC_AUTHENTICATION_MODE eAuthMode
-    );
+VNTWIFIvSetAuthenticationMode(
+       void *pMgmtHandle,
+       WMAC_AUTHENTICATION_MODE eAuthMode
+);
 
 void
-VNTWIFIvSetEncryptionMode (
-    void *pMgmtHandle,
-    WMAC_ENCRYPTION_MODE eEncryptionMode
-    );
-
+VNTWIFIvSetEncryptionMode(
+       void *pMgmtHandle,
+       WMAC_ENCRYPTION_MODE eEncryptionMode
+);
 
 bool
 VNTWIFIbConfigPhyMode(
-    void *pMgmtHandle,
-    CARD_PHY_TYPE ePhyType
-    );
+       void *pMgmtHandle,
+       CARD_PHY_TYPE ePhyType
+);
 
 void
 VNTWIFIbGetConfigPhyMode(
-    void *pMgmtHandle,
-    void *pePhyType
-    );
+       void *pMgmtHandle,
+       void *pePhyType
+);
 
 void
 VNTWIFIvQueryBSSList(void *pMgmtHandle, unsigned int *puBSSCount,
-               void **pvFirstBSS);
+                    void **pvFirstBSS);
 
 void
-VNTWIFIvGetNextBSS (
-    void *pMgmtHandle,
-    void *pvCurrentBSS,
-    void **pvNextBSS
-    );
-
-
+VNTWIFIvGetNextBSS(
+       void *pMgmtHandle,
+       void *pvCurrentBSS,
+       void **pvNextBSS
+);
 
 void
 VNTWIFIvUpdateNodeTxCounter(
-    void *pMgmtHandle,
-    unsigned char *pbyDestAddress,
-    bool bTxOk,
-    unsigned short wRate,
-    unsigned char *pbyTxFailCount
-    );
-
+       void *pMgmtHandle,
+       unsigned char *pbyDestAddress,
+       bool bTxOk,
+       unsigned short wRate,
+       unsigned char *pbyTxFailCount
+);
 
 void
 VNTWIFIvGetTxRate(
-    void *pMgmtHandle,
-    unsigned char *pbyDestAddress,
-    unsigned short *pwTxDataRate,
-    unsigned char *pbyACKRate,
-    unsigned char *pbyCCKBasicRate,
-    unsigned char *pbyOFDMBasicRate
-    );
+       void *pMgmtHandle,
+       unsigned char *pbyDestAddress,
+       unsigned short *pwTxDataRate,
+       unsigned char *pbyACKRate,
+       unsigned char *pbyCCKBasicRate,
+       unsigned char *pbyOFDMBasicRate
+);
 /*
-bool
-VNTWIFIbInit(
-    void *pAdapterHandler,
-    void **pMgmtHandler
-    );
+  bool
+  VNTWIFIbInit(
+  void *pAdapterHandler,
+  void **pMgmtHandler
+);
 */
 
 unsigned char
 VNTWIFIbyGetKeyCypher(
-    void *pMgmtHandle,
-    bool bGroupKey
-    );
-
-
-
+       void *pMgmtHandle,
+       bool bGroupKey
+);
 
 bool
-VNTWIFIbSetPMKIDCache (
-    void *pMgmtObject,
-    unsigned long ulCount,
-    void *pPMKIDInfo
-    );
+VNTWIFIbSetPMKIDCache(
+       void *pMgmtObject,
+       unsigned long ulCount,
+       void *pPMKIDInfo
+);
 
 bool
-VNTWIFIbCommandRunning (
-    void *pMgmtObject
-    );
+VNTWIFIbCommandRunning(
+       void *pMgmtObject
+);
 
 unsigned short
 VNTWIFIwGetMaxSupportRate(
-    void *pMgmtObject
-    );
+       void *pMgmtObject
+);
 
 // for 802.11h
 void
-VNTWIFIvSet11h (
-    void *pMgmtObject,
-    bool b11hEnable
-    );
+VNTWIFIvSet11h(
+       void *pMgmtObject,
+       bool b11hEnable
+);
 
 bool
 VNTWIFIbMeasureReport(
-    void *pMgmtObject,
-    bool bEndOfReport,
-    void *pvMeasureEID,
-    unsigned char byReportMode,
-    unsigned char byBasicMap,
-    unsigned char byCCAFraction,
-    unsigned char *pbyRPIs
-    );
+       void *pMgmtObject,
+       bool bEndOfReport,
+       void *pvMeasureEID,
+       unsigned char byReportMode,
+       unsigned char byBasicMap,
+       unsigned char byCCAFraction,
+       unsigned char *pbyRPIs
+);
 
 bool
 VNTWIFIbChannelSwitch(
-    void *pMgmtObject,
-    unsigned char byNewChannel
-    );
+       void *pMgmtObject,
+       unsigned char byNewChannel
+);
 /*
-bool
-VNTWIFIbRadarPresent(
-    void *pMgmtObject,
-    unsigned char byChannel
-    );
+  bool
+  VNTWIFIbRadarPresent(
+  void *pMgmtObject,
+  unsigned char byChannel
+);
 */
 
 #endif //__VNTWIFI_H__
index 101c7359f414ebfab4147fd52c57121442b6f232..d551653537b4a305c4045b65feadd5714ad84237 100644 (file)
 
 /*---------------------  Static Definitions -------------------------*/
 
-
-
-
 /*---------------------  Static Classes  ----------------------------*/
 
 /*---------------------  Static Variables  --------------------------*/
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 /*---------------------  Static Functions  --------------------------*/
 
 static
 void
 s_vProbeChannel(
-    PSDevice pDevice
-    );
-
+       PSDevice pDevice
+);
 
 static
 PSTxMgmtPacket
 s_MgrMakeProbeRequest(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned char *pScanBSSID,
-    PWLAN_IE_SSID pSSID,
-    PWLAN_IE_SUPP_RATES pCurrRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-    );
-
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned char *pScanBSSID,
+       PWLAN_IE_SSID pSSID,
+       PWLAN_IE_SUPP_RATES pCurrRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+);
 
 static
 bool
-s_bCommandComplete (
-    PSDevice pDevice
-    );
+s_bCommandComplete(
+       PSDevice pDevice
+);
 
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
-
-
 /*
  * Description:
  *      Stop AdHoc beacon during scan process
@@ -115,44 +107,37 @@ static
 void
 vAdHocBeaconStop(PSDevice  pDevice)
 {
-
-    PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
-    bool bStop;
-
-    /*
-     * temporarily stop Beacon packet for AdHoc Server
-     * if all of the following conditions are met:
-     *  (1) STA is in AdHoc mode
-     *  (2) VT3253 is programmed as automatic Beacon Transmitting
-     *  (3) One of the following conditions is met
-     *      (3.1) AdHoc channel is in B/G band and the
-     *      current scan channel is in A band
-     *      or
-     *      (3.2) AdHoc channel is in A mode
-     */
-    bStop = false;
-    if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
-    (pMgmt->eCurrState >= WMAC_STATE_STARTED))
-    {
-        if ((pMgmt->uIBSSChannel <=  CB_MAX_CHANNEL_24G) &&
-             (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
-        {
-            bStop = true;
-        }
-        if (pMgmt->uIBSSChannel >  CB_MAX_CHANNEL_24G)
-        {
-            bStop = true;
-        }
-    }
-
-    if (bStop)
-    {
-        MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
-    }
-
+       PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
+       bool bStop;
+
+       /*
+        * temporarily stop Beacon packet for AdHoc Server
+        * if all of the following conditions are met:
+        *  (1) STA is in AdHoc mode
+        *  (2) VT3253 is programmed as automatic Beacon Transmitting
+        *  (3) One of the following conditions is met
+        *      (3.1) AdHoc channel is in B/G band and the
+        *      current scan channel is in A band
+        *      or
+        *      (3.2) AdHoc channel is in A mode
+        */
+       bStop = false;
+       if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
+           (pMgmt->eCurrState >= WMAC_STATE_STARTED)) {
+               if ((pMgmt->uIBSSChannel <=  CB_MAX_CHANNEL_24G) &&
+                   (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) {
+                       bStop = true;
+               }
+               if (pMgmt->uIBSSChannel >  CB_MAX_CHANNEL_24G) {
+                       bStop = true;
+               }
+       }
+
+       if (bStop) {
+               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
+       }
 } /* vAdHocBeaconStop */
 
-
 /*
  * Description:
  *      Restart AdHoc beacon after scan process complete
@@ -170,27 +155,20 @@ static
 void
 vAdHocBeaconRestart(PSDevice pDevice)
 {
-    PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
-
-    /*
-     * Restart Beacon packet for AdHoc Server
-     * if all of the following coditions are met:
-     *  (1) STA is in AdHoc mode
-     *  (2) VT3253 is programmed as automatic Beacon Transmitting
-     */
-    if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
-    (pMgmt->eCurrState >= WMAC_STATE_STARTED))
-    {
-         MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
-    }
-
+       PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
+
+       /*
+        * Restart Beacon packet for AdHoc Server
+        * if all of the following coditions are met:
+        *  (1) STA is in AdHoc mode
+        *  (2) VT3253 is programmed as automatic Beacon Transmitting
+        */
+       if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
+           (pMgmt->eCurrState >= WMAC_STATE_STARTED)) {
+               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
+       }
 }
 
-
-
-
-
-
 /*+
  *
  * Routine Description:
@@ -200,60 +178,54 @@ vAdHocBeaconRestart(PSDevice pDevice)
  * Return Value:
  *    none.
  *
--*/
+ -*/
 
 static
 void
 s_vProbeChannel(
-    PSDevice pDevice
-    )
+       PSDevice pDevice
+)
 {
-                                                     //1M,   2M,   5M,   11M,  18M,  24M,  36M,  54M
-    unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
-    unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
-                                                           //6M,   9M,   12M,  48M
-    unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
-    unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
-    unsigned char *pbyRate;
-    PSTxMgmtPacket  pTxPacket;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    unsigned int ii;
-
-
-    if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
-        pbyRate = &abyCurrSuppRatesA[0];
-    } else if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
-        pbyRate = &abyCurrSuppRatesB[0];
-    } else {
-        pbyRate = &abyCurrSuppRatesG[0];
-    }
-    // build an assocreq frame and send it
-    pTxPacket = s_MgrMakeProbeRequest
-                (
-                  pDevice,
-                  pMgmt,
-                  pMgmt->abyScanBSSID,
-                  (PWLAN_IE_SSID)pMgmt->abyScanSSID,
-                  (PWLAN_IE_SUPP_RATES)pbyRate,
-                  (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
-                );
-
-    if (pTxPacket != NULL ){
-        for (ii = 0; ii < 2 ; ii++) {
-            if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
-            }
-            else {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
-            }
-        }
-    }
-
+       //1M,   2M,   5M,   11M,  18M,  24M,  36M,  54M
+       unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
+       unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
+       //6M,   9M,   12M,  48M
+       unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
+       unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
+       unsigned char *pbyRate;
+       PSTxMgmtPacket  pTxPacket;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       unsigned int ii;
+
+       if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
+               pbyRate = &abyCurrSuppRatesA[0];
+       } else if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
+               pbyRate = &abyCurrSuppRatesB[0];
+       } else {
+               pbyRate = &abyCurrSuppRatesG[0];
+       }
+       // build an assocreq frame and send it
+       pTxPacket = s_MgrMakeProbeRequest
+               (
+                       pDevice,
+                       pMgmt,
+                       pMgmt->abyScanBSSID,
+                       (PWLAN_IE_SSID)pMgmt->abyScanSSID,
+                       (PWLAN_IE_SUPP_RATES)pbyRate,
+                       (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
+                       );
+
+       if (pTxPacket != NULL) {
+               for (ii = 0; ii < 2; ii++) {
+                       if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
+                       } else {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
+                       }
+               }
+       }
 }
 
-
-
-
 /*+
  *
  * Routine Description:
@@ -263,765 +235,724 @@ s_vProbeChannel(
  * Return Value:
  *    A ptr to Tx frame or NULL on allocation failue
  *
--*/
-
+ -*/
 
 PSTxMgmtPacket
 s_MgrMakeProbeRequest(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned char *pScanBSSID,
-    PWLAN_IE_SSID pSSID,
-    PWLAN_IE_SUPP_RATES pCurrRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned char *pScanBSSID,
+       PWLAN_IE_SSID pSSID,
+       PWLAN_IE_SUPP_RATES pCurrRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+
+)
 {
-    PSTxMgmtPacket      pTxPacket = NULL;
-    WLAN_FR_PROBEREQ    sFrame;
-
-
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
-    vMgrEncodeProbeRequest(&sFrame);
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-        (
-        WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-        WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
-        ));
-    memcpy( sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
-    // Copy the SSID, pSSID->len=0 indicate broadcast SSID
-    sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
-    sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
-    sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-    sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
-    // Copy the extension rate set
-    if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
-        sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-        sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
-        memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
-    }
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-
-    return pTxPacket;
+       PSTxMgmtPacket      pTxPacket = NULL;
+       WLAN_FR_PROBEREQ    sFrame;
+
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
+       vMgrEncodeProbeRequest(&sFrame);
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
+));
+       memcpy(sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
+       // Copy the SSID, pSSID->len=0 indicate broadcast SSID
+       sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
+       sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
+       sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+       sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
+       // Copy the extension rate set
+       if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
+               sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+               sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
+               memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
+       }
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
+
+       return pTxPacket;
 }
 
-
-
-
-
 void
 vCommandTimerWait(
-    void *hDeviceContext,
-    unsigned int MSecond
-    )
+       void *hDeviceContext,
+       unsigned int MSecond
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-
-    init_timer(&pDevice->sTimerCommand);
-    pDevice->sTimerCommand.data = (unsigned long) pDevice;
-    pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
-    // RUN_AT :1 msec ~= (HZ/1024)
-    pDevice->sTimerCommand.expires = (unsigned int)RUN_AT((MSecond * HZ) >> 10);
-    add_timer(&pDevice->sTimerCommand);
-    return;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+
+       init_timer(&pDevice->sTimerCommand);
+       pDevice->sTimerCommand.data = (unsigned long) pDevice;
+       pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
+       // RUN_AT :1 msec ~= (HZ/1024)
+       pDevice->sTimerCommand.expires = (unsigned int)RUN_AT((MSecond * HZ) >> 10);
+       add_timer(&pDevice->sTimerCommand);
+       return;
 }
 
-
-
-
 void
-vCommandTimer (
-    void *hDeviceContext
-    )
+vCommandTimer(
+       void *hDeviceContext
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    PWLAN_IE_SSID   pItemSSID;
-    PWLAN_IE_SSID   pItemSSIDCurr;
-    CMD_STATUS      Status;
-    unsigned int ii;
-    unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
-    struct sk_buff  *skb;
-
-
-    if (pDevice->dwDiagRefCount != 0)
-        return;
-    if (pDevice->bCmdRunning != true)
-        return;
-
-    spin_lock_irq(&pDevice->lock);
-
-    switch ( pDevice->eCommandState ) {
-
-        case WLAN_CMD_SCAN_START:
-
-       pDevice->byReAssocCount = 0;
-            if (pDevice->bRadioOff == true) {
-                s_bCommandComplete(pDevice);
-                spin_unlock_irq(&pDevice->lock);
-                return;
-            }
-
-            if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-                s_bCommandComplete(pDevice);
-                CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_AP);
-                spin_unlock_irq(&pDevice->lock);
-                return;
-            }
-
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SCAN_START\n");
-            pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
-            // wait all Data TD complete
-            if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
-                spin_unlock_irq(&pDevice->lock);
-                vCommandTimerWait((void *)pDevice, 10);
-                return;
-            }
-
-            if (pMgmt->uScanChannel == 0 ) {
-                pMgmt->uScanChannel = pDevice->byMinChannel;
-                // Set Baseband to be more sensitive.
-
-            }
-            if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
-                pMgmt->eScanState = WMAC_NO_SCANNING;
-
-                // Set Baseband's sensitivity back.
-                // Set channel back
-                set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
-                if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-                    CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
-                } else {
-                    CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
-                }
-                vAdHocBeaconRestart(pDevice);
-                s_bCommandComplete(pDevice);
-
-            } else {
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PWLAN_IE_SSID   pItemSSID;
+       PWLAN_IE_SSID   pItemSSIDCurr;
+       CMD_STATUS      Status;
+       unsigned int ii;
+       unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
+       struct sk_buff  *skb;
+
+       if (pDevice->dwDiagRefCount != 0)
+               return;
+       if (pDevice->bCmdRunning != true)
+               return;
+
+       spin_lock_irq(&pDevice->lock);
+
+       switch (pDevice->eCommandState) {
+       case WLAN_CMD_SCAN_START:
+
+               pDevice->byReAssocCount = 0;
+               if (pDevice->bRadioOff == true) {
+                       s_bCommandComplete(pDevice);
+                       spin_unlock_irq(&pDevice->lock);
+                       return;
+               }
+
+               if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+                       s_bCommandComplete(pDevice);
+                       CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_AP);
+                       spin_unlock_irq(&pDevice->lock);
+                       return;
+               }
+
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState= WLAN_CMD_SCAN_START\n");
+               pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
+               // wait all Data TD complete
+               if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
+                       spin_unlock_irq(&pDevice->lock);
+                       vCommandTimerWait((void *)pDevice, 10);
+                       return;
+               }
+
+               if (pMgmt->uScanChannel == 0) {
+                       pMgmt->uScanChannel = pDevice->byMinChannel;
+                       // Set Baseband to be more sensitive.
+
+               }
+               if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
+                       pMgmt->eScanState = WMAC_NO_SCANNING;
+
+                       // Set Baseband's sensitivity back.
+                       // Set channel back
+                       set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
+                       if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+                               CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
+                       } else {
+                               CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
+                       }
+                       vAdHocBeaconRestart(pDevice);
+                       s_bCommandComplete(pDevice);
+
+               } else {
 //2008-8-4 <add> by chester
-               if (!is_channel_valid(pMgmt->uScanChannel)) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n",pMgmt->uScanChannel);
-                    s_bCommandComplete(pDevice);
-                    spin_unlock_irq(&pDevice->lock);
-                    return;
-                }
-//printk("chester-pMgmt->uScanChannel=%d,pDevice->byMaxChannel=%d\n",pMgmt->uScanChannel,pDevice->byMaxChannel);
-                if (pMgmt->uScanChannel == pDevice->byMinChannel) {
-                    //pMgmt->eScanType = WMAC_SCAN_ACTIVE;
-                    pMgmt->abyScanBSSID[0] = 0xFF;
-                    pMgmt->abyScanBSSID[1] = 0xFF;
-                    pMgmt->abyScanBSSID[2] = 0xFF;
-                    pMgmt->abyScanBSSID[3] = 0xFF;
-                    pMgmt->abyScanBSSID[4] = 0xFF;
-                    pMgmt->abyScanBSSID[5] = 0xFF;
-                    pItemSSID->byElementID = WLAN_EID_SSID;
-                    // clear bssid list
-                    // BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
-                    pMgmt->eScanState = WMAC_IS_SCANNING;
-
-                }
-
-                vAdHocBeaconStop(pDevice);
-
-                if (set_channel(pMgmt->pAdapter, pMgmt->uScanChannel) == true) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SCAN Channel: %d\n", pMgmt->uScanChannel);
-                } else {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SET SCAN Channel Fail: %d\n", pMgmt->uScanChannel);
-                }
-                CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_UNKNOWN);
-//     printk("chester-mxch=%d\n",pDevice->byMaxChannel);
-      //          printk("chester-ch=%d\n",pMgmt->uScanChannel);
-       pMgmt->uScanChannel++;
+                       if (!is_channel_valid(pMgmt->uScanChannel)) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n", pMgmt->uScanChannel);
+                               s_bCommandComplete(pDevice);
+                               spin_unlock_irq(&pDevice->lock);
+                               return;
+                       }
+                       if (pMgmt->uScanChannel == pDevice->byMinChannel) {
+                               //pMgmt->eScanType = WMAC_SCAN_ACTIVE;
+                               pMgmt->abyScanBSSID[0] = 0xFF;
+                               pMgmt->abyScanBSSID[1] = 0xFF;
+                               pMgmt->abyScanBSSID[2] = 0xFF;
+                               pMgmt->abyScanBSSID[3] = 0xFF;
+                               pMgmt->abyScanBSSID[4] = 0xFF;
+                               pMgmt->abyScanBSSID[5] = 0xFF;
+                               pItemSSID->byElementID = WLAN_EID_SSID;
+                               // clear bssid list
+                               // BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
+                               pMgmt->eScanState = WMAC_IS_SCANNING;
+
+                       }
+
+                       vAdHocBeaconStop(pDevice);
+
+                       if (set_channel(pMgmt->pAdapter, pMgmt->uScanChannel) == true) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "SCAN Channel: %d\n", pMgmt->uScanChannel);
+                       } else {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "SET SCAN Channel Fail: %d\n", pMgmt->uScanChannel);
+                       }
+                       CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_UNKNOWN);
+                       pMgmt->uScanChannel++;
 //2008-8-4 <modify> by chester
-               if (!is_channel_valid(pMgmt->uScanChannel) &&
-                        pMgmt->uScanChannel <= pDevice->byMaxChannel ){
-                    pMgmt->uScanChannel=pDevice->byMaxChannel+1;
-                pMgmt->eCommandState = WLAN_CMD_SCAN_END;
-
-                }
-
-
-                if ((pMgmt->b11hEnable == false) ||
-                    (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
-                    s_vProbeChannel(pDevice);
-                    spin_unlock_irq(&pDevice->lock);
-                    vCommandTimerWait((void *)pDevice, WCMD_ACTIVE_SCAN_TIME);
-                    return;
-                } else {
-                    spin_unlock_irq(&pDevice->lock);
-                    vCommandTimerWait((void *)pDevice, WCMD_PASSIVE_SCAN_TIME);
-                    return;
-                }
-
-            }
-
-            break;
-
-        case WLAN_CMD_SCAN_END:
-
-            // Set Baseband's sensitivity back.
-            // Set channel back
-            set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
-            if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-                CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
-            } else {
-                CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
-            }
-
-            pMgmt->eScanState = WMAC_NO_SCANNING;
-            vAdHocBeaconRestart(pDevice);
+                       if (!is_channel_valid(pMgmt->uScanChannel) &&
+                           pMgmt->uScanChannel <= pDevice->byMaxChannel) {
+                               pMgmt->uScanChannel = pDevice->byMaxChannel + 1;
+                               pMgmt->eCommandState = WLAN_CMD_SCAN_END;
+
+                       }
+
+                       if ((pMgmt->b11hEnable == false) ||
+                           (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
+                               s_vProbeChannel(pDevice);
+                               spin_unlock_irq(&pDevice->lock);
+                               vCommandTimerWait((void *)pDevice, WCMD_ACTIVE_SCAN_TIME);
+                               return;
+                       } else {
+                               spin_unlock_irq(&pDevice->lock);
+                               vCommandTimerWait((void *)pDevice, WCMD_PASSIVE_SCAN_TIME);
+                               return;
+                       }
+
+               }
+
+               break;
+
+       case WLAN_CMD_SCAN_END:
+
+               // Set Baseband's sensitivity back.
+               // Set channel back
+               set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
+               if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+                       CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
+               } else {
+                       CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
+               }
+
+               pMgmt->eScanState = WMAC_NO_SCANNING;
+               vAdHocBeaconRestart(pDevice);
 //2008-0409-07, <Add> by Einsn Liu
 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-       if(pMgmt->eScanType == WMAC_SCAN_PASSIVE)
-                       {//send scan event to wpa_Supplicant
-                               union iwreq_data wrqu;
-                               memset(&wrqu, 0, sizeof(wrqu));
-                               wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
-                       }
+               if (pMgmt->eScanType == WMAC_SCAN_PASSIVE)
+               {//send scan event to wpa_Supplicant
+                       union iwreq_data wrqu;
+                       memset(&wrqu, 0, sizeof(wrqu));
+                       wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
+               }
 #endif
-            s_bCommandComplete(pDevice);
-            break;
-
-        case WLAN_CMD_DISASSOCIATE_START :
-       pDevice->byReAssocCount = 0;
-            if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
-                (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
-                s_bCommandComplete(pDevice);
-                spin_unlock_irq(&pDevice->lock);
-                return;
-            } else {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
-                // reason = 8 : disassoc because sta has left
-                vMgrDisassocBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (8), &Status);
-                pDevice->bLinkPass = false;
-                // unlock command busy
-                pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
-                pItemSSID->len = 0;
-                memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
-                pMgmt->eCurrState = WMAC_STATE_IDLE;
-                pMgmt->sNodeDBTable[0].bActive = false;
+               s_bCommandComplete(pDevice);
+               break;
+
+       case WLAN_CMD_DISASSOCIATE_START:
+               pDevice->byReAssocCount = 0;
+               if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
+                   (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
+                       s_bCommandComplete(pDevice);
+                       spin_unlock_irq(&pDevice->lock);
+                       return;
+               } else {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Disassociation Packet..\n");
+                       // reason = 8 : disassoc because sta has left
+                       vMgrDisassocBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (8), &Status);
+                       pDevice->bLinkPass = false;
+                       // unlock command busy
+                       pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
+                       pItemSSID->len = 0;
+                       memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
+                       pMgmt->eCurrState = WMAC_STATE_IDLE;
+                       pMgmt->sNodeDBTable[0].bActive = false;
 //                pDevice->bBeaconBufReady = false;
-            }
-            netif_stop_queue(pDevice->dev);
-            pDevice->eCommandState = WLAN_DISASSOCIATE_WAIT;
-            // wait all Control TD complete
-            if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
-                vCommandTimerWait((void *)pDevice, 10);
-                spin_unlock_irq(&pDevice->lock);
-                return;
-            }
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" CARDbRadioPowerOff\n");
-       //2008-09-02  <mark>    by chester
-           // CARDbRadioPowerOff(pDevice);
-            s_bCommandComplete(pDevice);
-            break;
-
-        case WLAN_DISASSOCIATE_WAIT :
-            // wait all Control TD complete
-            if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
-                vCommandTimerWait((void *)pDevice, 10);
-                spin_unlock_irq(&pDevice->lock);
-                return;
-            }
+               }
+               netif_stop_queue(pDevice->dev);
+               pDevice->eCommandState = WLAN_DISASSOCIATE_WAIT;
+               // wait all Control TD complete
+               if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
+                       vCommandTimerWait((void *)pDevice, 10);
+                       spin_unlock_irq(&pDevice->lock);
+                       return;
+               }
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " CARDbRadioPowerOff\n");
+               //2008-09-02  <mark>    by chester
+               // CARDbRadioPowerOff(pDevice);
+               s_bCommandComplete(pDevice);
+               break;
+
+       case WLAN_DISASSOCIATE_WAIT:
+               // wait all Control TD complete
+               if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
+                       vCommandTimerWait((void *)pDevice, 10);
+                       spin_unlock_irq(&pDevice->lock);
+                       return;
+               }
 //2008-09-02  <mark> by chester
-           // CARDbRadioPowerOff(pDevice);
-            s_bCommandComplete(pDevice);
-            break;
-
-        case WLAN_CMD_SSID_START:
-               pDevice->byReAssocCount = 0;
-            if (pDevice->bRadioOff == true) {
-                s_bCommandComplete(pDevice);
-                spin_unlock_irq(&pDevice->lock);
-                return;
-            }
-//printk("chester-currmode=%d\n",pMgmt->eCurrMode);
-printk("chester-abyDesireSSID=%s\n",((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID);
-                     //memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
-                              //((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
-            pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
-            pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: desire ssid = %s\n", pItemSSID->abySSID);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
-
-            if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSID->len =%d\n",pItemSSID->len);
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSIDCurr->len = %d\n",pItemSSIDCurr->len);
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" desire ssid = %s\n", pItemSSID->abySSID);
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" curr ssid = %s\n", pItemSSIDCurr->abySSID);
-            }
-
-            if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
-                ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)&& (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
-
-                if (pItemSSID->len == pItemSSIDCurr->len) {
-                    if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
-                        s_bCommandComplete(pDevice);
-                        spin_unlock_irq(&pDevice->lock);
-                        return;
-                    }
-                }
-
-                netif_stop_queue(pDevice->dev);
-                pDevice->bLinkPass = false;
-            }
-            // set initial state
-            pMgmt->eCurrState = WMAC_STATE_IDLE;
-            pMgmt->eCurrMode = WMAC_MODE_STANDBY;
-            PSvDisablePowerSaving((void *)pDevice);
-            BSSvClearNodeDBTable(pDevice, 0);
-
-            vMgrJoinBSSBegin((void *)pDevice, &Status);
-            // if Infra mode
-            if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
-
-               // Call mgr to begin the deauthentication
-                // reason = (3) because sta has left ESS
-                if (pMgmt->eCurrState>= WMAC_STATE_AUTH) {
-                    vMgrDeAuthenBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (3), &Status);
-                }
-                // Call mgr to begin the authentication
-                vMgrAuthenBeginSta((void *)pDevice, pMgmt, &Status);
-                if (Status == CMD_STATUS_SUCCESS) {
+               // CARDbRadioPowerOff(pDevice);
+               s_bCommandComplete(pDevice);
+               break;
+
+       case WLAN_CMD_SSID_START:
+               pDevice->byReAssocCount = 0;
+               if (pDevice->bRadioOff == true) {
+                       s_bCommandComplete(pDevice);
+                       spin_unlock_irq(&pDevice->lock);
+                       return;
+               }
+               printk("chester-abyDesireSSID=%s\n", ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID);
+               //memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
+               //((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
+               pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
+               pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " cmd: desire ssid = %s\n", pItemSSID->abySSID);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
+
+               if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pItemSSID->len =%d\n", pItemSSID->len);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pItemSSIDCurr->len = %d\n", pItemSSIDCurr->len);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " desire ssid = %s\n", pItemSSID->abySSID);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " curr ssid = %s\n", pItemSSIDCurr->abySSID);
+               }
+
+               if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
+                   ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
+                       if (pItemSSID->len == pItemSSIDCurr->len) {
+                               if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
+                                       s_bCommandComplete(pDevice);
+                                       spin_unlock_irq(&pDevice->lock);
+                                       return;
+                               }
+                       }
+
+                       netif_stop_queue(pDevice->dev);
+                       pDevice->bLinkPass = false;
+               }
+               // set initial state
+               pMgmt->eCurrState = WMAC_STATE_IDLE;
+               pMgmt->eCurrMode = WMAC_MODE_STANDBY;
+               PSvDisablePowerSaving((void *)pDevice);
+               BSSvClearNodeDBTable(pDevice, 0);
+
+               vMgrJoinBSSBegin((void *)pDevice, &Status);
+               // if Infra mode
+               if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
+                       // Call mgr to begin the deauthentication
+                       // reason = (3) because sta has left ESS
+                       if (pMgmt->eCurrState >= WMAC_STATE_AUTH) {
+                               vMgrDeAuthenBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (3), &Status);
+                       }
+                       // Call mgr to begin the authentication
+                       vMgrAuthenBeginSta((void *)pDevice, pMgmt, &Status);
+                       if (Status == CMD_STATUS_SUCCESS) {
+                               pDevice->byLinkWaitCount = 0;
+                               pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
+                               vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT);
+                               spin_unlock_irq(&pDevice->lock);
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
+                               return;
+                       }
+               }
+               // if Adhoc mode
+               else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+                       if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
+                               if (netif_queue_stopped(pDevice->dev)) {
+                                       netif_wake_queue(pDevice->dev);
+                               }
+                               pDevice->bLinkPass = true;
+
+                               pMgmt->sNodeDBTable[0].bActive = true;
+                               pMgmt->sNodeDBTable[0].uInActiveCount = 0;
+                               bClearBSSID_SCAN(pDevice);
+                       } else {
+                               // start own IBSS
+                               vMgrCreateOwnIBSS((void *)pDevice, &Status);
+                               if (Status != CMD_STATUS_SUCCESS) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " WLAN_CMD_IBSS_CREATE fail ! \n");
+                               }
+                               BSSvAddMulticastNode(pDevice);
+                       }
+               }
+               // if SSID not found
+               else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
+                       if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
+                           pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
+                               // start own IBSS
+                               vMgrCreateOwnIBSS((void *)pDevice, &Status);
+                               if (Status != CMD_STATUS_SUCCESS) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " WLAN_CMD_IBSS_CREATE fail ! \n");
+                               }
+                               BSSvAddMulticastNode(pDevice);
+                               if (netif_queue_stopped(pDevice->dev)) {
+                                       netif_wake_queue(pDevice->dev);
+                               }
+                               pDevice->bLinkPass = true;
+                       } else {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+                               {
+                                       union iwreq_data  wrqu;
+                                       memset(&wrqu, 0, sizeof(wrqu));
+                                       wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+                                       printk("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
+                                       wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
+                               }
+#endif
+
+                       }
+               }
+               s_bCommandComplete(pDevice);
+               break;
+
+       case WLAN_AUTHENTICATE_WAIT:
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState == WLAN_AUTHENTICATE_WAIT\n");
+               if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
+                       // Call mgr to begin the association
+                       pDevice->byLinkWaitCount = 0;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCurrState == WMAC_STATE_AUTH\n");
+                       vMgrAssocBeginSta((void *)pDevice, pMgmt, &Status);
+                       if (Status == CMD_STATUS_SUCCESS) {
+                               pDevice->byLinkWaitCount = 0;
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState = WLAN_ASSOCIATE_WAIT\n");
+                               pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
+                               vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT);
+                               spin_unlock_irq(&pDevice->lock);
+                               return;
+                       }
+               }
+
+               else if (pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
+                       printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
+               } else if (pDevice->byLinkWaitCount <= 4) {    //mike add:wait another 2 sec if authenticated_frame delay!
+                       pDevice->byLinkWaitCount++;
+                       printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n", pDevice->byLinkWaitCount);
+                       spin_unlock_irq(&pDevice->lock);
+                       vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT/2);
+                       return;
+               }
                pDevice->byLinkWaitCount = 0;
-                    pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
-                    vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT);
-                    spin_unlock_irq(&pDevice->lock);
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
-                    return;
-                }
-            }
-            // if Adhoc mode
-            else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-                if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
-                    if (netif_queue_stopped(pDevice->dev)){
-                        netif_wake_queue(pDevice->dev);
-                    }
-                    pDevice->bLinkPass = true;
-
-                    pMgmt->sNodeDBTable[0].bActive = true;
-                    pMgmt->sNodeDBTable[0].uInActiveCount = 0;
-                    bClearBSSID_SCAN(pDevice);
-                }
-                else {
-                    // start own IBSS
-                    vMgrCreateOwnIBSS((void *)pDevice, &Status);
-                    if (Status != CMD_STATUS_SUCCESS){
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " WLAN_CMD_IBSS_CREATE fail ! \n");
-                    }
-                    BSSvAddMulticastNode(pDevice);
-                }
-            }
-            // if SSID not found
-            else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
-                if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
-                    pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
-                    // start own IBSS
-                    vMgrCreateOwnIBSS((void *)pDevice, &Status);
-                    if (Status != CMD_STATUS_SUCCESS){
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_IBSS_CREATE fail ! \n");
-                    }
-                    BSSvAddMulticastNode(pDevice);
-                    if (netif_queue_stopped(pDevice->dev)){
-                        netif_wake_queue(pDevice->dev);
-                    }
-                    pDevice->bLinkPass = true;
-                }
-                else {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
-                 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-                    // if(pDevice->bWPASuppWextEnabled == true)
-                        {
-                       union iwreq_data  wrqu;
-                       memset(&wrqu, 0, sizeof (wrqu));
-                          wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-                       printk("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
-                       wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
-                       }
-                    #endif
-
-                }
-            }
-            s_bCommandComplete(pDevice);
-            break;
-
-        case WLAN_AUTHENTICATE_WAIT :
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
-            if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
-                // Call mgr to begin the association
-                       pDevice->byLinkWaitCount = 0;
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_AUTH\n");
-                vMgrAssocBeginSta((void *)pDevice, pMgmt, &Status);
-                if (Status == CMD_STATUS_SUCCESS) {
+               s_bCommandComplete(pDevice);
+               break;
+
+       case WLAN_ASSOCIATE_WAIT:
+               if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCurrState == WMAC_STATE_ASSOC\n");
+                       if (pDevice->ePSMode != WMAC_POWER_CAM) {
+                               PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
+                       }
+                       if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
+                               KeybRemoveAllKey(&(pDevice->sKey), pDevice->abyBSSID, pDevice->PortOffset);
+                       }
+                       pDevice->bLinkPass = true;
+                       pDevice->byLinkWaitCount = 0;
+                       pDevice->byReAssocCount = 0;
+                       bClearBSSID_SCAN(pDevice);
+                       if (pDevice->byFOETuning) {
+                               BBvSetFOE(pDevice->PortOffset);
+                               PSbSendNullPacket(pDevice);
+                       }
+                       if (netif_queue_stopped(pDevice->dev)) {
+                               netif_wake_queue(pDevice->dev);
+                       }
+#ifdef TxInSleep
+                       if (pDevice->IsTxDataTrigger != false)   {    //TxDataTimer is not triggered at the first time
+                               del_timer(&pDevice->sTimerTxData);
+                               init_timer(&pDevice->sTimerTxData);
+                               pDevice->sTimerTxData.data = (unsigned long) pDevice;
+                               pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
+                               pDevice->sTimerTxData.expires = RUN_AT(10*HZ);      //10s callback
+                               pDevice->fTxDataInSleep = false;
+                               pDevice->nTxDataTimeCout = 0;
+                       } else {
+                       }
+                       pDevice->IsTxDataTrigger = true;
+                       add_timer(&pDevice->sTimerTxData);
+#endif
+               } else if (pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
+                       printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
+               } else if (pDevice->byLinkWaitCount <= 4) {    //mike add:wait another 2 sec if associated_frame delay!
+                       pDevice->byLinkWaitCount++;
+                       printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n", pDevice->byLinkWaitCount);
+                       spin_unlock_irq(&pDevice->lock);
+                       vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT/2);
+                       return;
+               }
                pDevice->byLinkWaitCount = 0;
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState = WLAN_ASSOCIATE_WAIT\n");
-                    pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
-                    vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT);
-                    spin_unlock_irq(&pDevice->lock);
-                    return;
-                }
-            }
-
-       else if(pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
-               printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
-          }
-          else  if(pDevice->byLinkWaitCount <= 4){    //mike add:wait another 2 sec if authenticated_frame delay!
-                pDevice->byLinkWaitCount ++;
-              printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
-              spin_unlock_irq(&pDevice->lock);
-              vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT/2);
-              return;
-          }
-                 pDevice->byLinkWaitCount = 0;
-            s_bCommandComplete(pDevice);
-            break;
-
-        case WLAN_ASSOCIATE_WAIT :
-            if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_ASSOC\n");
-                if (pDevice->ePSMode != WMAC_POWER_CAM) {
-                    PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
-                }
-                if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
-                    KeybRemoveAllKey(&(pDevice->sKey), pDevice->abyBSSID, pDevice->PortOffset);
-                }
-                pDevice->bLinkPass = true;
-                pDevice->byLinkWaitCount = 0;
-                pDevice->byReAssocCount = 0;
-                bClearBSSID_SCAN(pDevice);
-                if (pDevice->byFOETuning) {
-                    BBvSetFOE(pDevice->PortOffset);
-                    PSbSendNullPacket(pDevice);
-                }
-                if (netif_queue_stopped(pDevice->dev)){
-                    netif_wake_queue(pDevice->dev);
-                }
-            #ifdef TxInSleep
-                if(pDevice->IsTxDataTrigger != false)   {    //TxDataTimer is not triggered at the first time
-                     // printk("Re-initial TxDataTimer****\n");
-                   del_timer(&pDevice->sTimerTxData);
-                      init_timer(&pDevice->sTimerTxData);
-                      pDevice->sTimerTxData.data = (unsigned long) pDevice;
-                      pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
-                      pDevice->sTimerTxData.expires = RUN_AT(10*HZ);      //10s callback
-                      pDevice->fTxDataInSleep = false;
-                      pDevice->nTxDataTimeCout = 0;
-                }
-                else {
-                  // printk("mike:-->First time trigger TimerTxData InSleep\n");
-                }
-               pDevice->IsTxDataTrigger = true;
-                add_timer(&pDevice->sTimerTxData);
-             #endif
-            }
-                  else if(pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
-               printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
-          }
-          else  if(pDevice->byLinkWaitCount <= 4){    //mike add:wait another 2 sec if associated_frame delay!
-                pDevice->byLinkWaitCount ++;
-              printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
-              spin_unlock_irq(&pDevice->lock);
-              vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT/2);
-              return;
-          }
-                 pDevice->byLinkWaitCount = 0;
-
-            s_bCommandComplete(pDevice);
-            break;
-
-        case WLAN_CMD_AP_MODE_START :
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_AP_MODE_START\n");
-
-            if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
-                del_timer(&pMgmt->sTimerSecondCallback);
-                pMgmt->eCurrState = WMAC_STATE_IDLE;
-                pMgmt->eCurrMode = WMAC_MODE_STANDBY;
-                pDevice->bLinkPass = false;
-                if (pDevice->bEnableHostWEP == true)
-                    BSSvClearNodeDBTable(pDevice, 1);
-                else
-                    BSSvClearNodeDBTable(pDevice, 0);
-                pDevice->uAssocCount = 0;
-                pMgmt->eCurrState = WMAC_STATE_IDLE;
-                pDevice->bFixRate = false;
-
-                vMgrCreateOwnIBSS((void *)pDevice, &Status);
-                if (Status != CMD_STATUS_SUCCESS){
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " vMgrCreateOwnIBSS fail ! \n");
-                }
-                // alway turn off unicast bit
-                MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_UNICAST);
-                pDevice->byRxMode &= ~RCR_UNICAST;
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
-                BSSvAddMulticastNode(pDevice);
-                if (netif_queue_stopped(pDevice->dev)){
-                    netif_wake_queue(pDevice->dev);
-                }
-                pDevice->bLinkPass = true;
-                add_timer(&pMgmt->sTimerSecondCallback);
-            }
-            s_bCommandComplete(pDevice);
-            break;
-
-        case WLAN_CMD_TX_PSPACKET_START :
-            // DTIM Multicast tx
-            if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
-                while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
-                    if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
-                        pMgmt->abyPSTxMap[0] &= ~byMask[0];
-                        pDevice->bMoreData = false;
-                    }
-                    else {
-                        pDevice->bMoreData = true;
-                    }
-                    if (!device_dma0_xmit(pDevice, skb, 0)) {
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
-                    }
-                    pMgmt->sNodeDBTable[0].wEnQueueCnt--;
-                }
-            }
-
-            // PS nodes tx
-            for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
-                if (pMgmt->sNodeDBTable[ii].bActive &&
-                    pMgmt->sNodeDBTable[ii].bRxPSPoll) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
-                               ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
-                    while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
-                        if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
-                            // clear tx map
-                            pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
-                                    ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
-                            pDevice->bMoreData = false;
-                        }
-                        else {
-                            pDevice->bMoreData = true;
-                        }
-                        if (!device_dma0_xmit(pDevice, skb, ii)) {
-                            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
-                        }
-                        pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
-                        // check if sta ps enabled, and wait next pspoll.
-                        // if sta ps disable, then send all pending buffers.
-                        if (pMgmt->sNodeDBTable[ii].bPSEnable)
-                            break;
-                    }
-                    if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
-                        // clear tx map
-                        pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
-                                    ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
-                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
-                    }
-                    pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
-                }
-            }
-
-            s_bCommandComplete(pDevice);
-            break;
-
-
-        case WLAN_CMD_RADIO_START :
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
-            if (pDevice->bRadioCmd == true)
-                CARDbRadioPowerOn(pDevice);
-            else
-                CARDbRadioPowerOff(pDevice);
-
-            s_bCommandComplete(pDevice);
-            break;
-
-
-        case WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE :
-            //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_CHECK_BBSENSITIVITY_START\n");
-            // wait all TD complete
-            if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
-                vCommandTimerWait((void *)pDevice, 10);
-                spin_unlock_irq(&pDevice->lock);
-                return;
-            }
-            if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
-                vCommandTimerWait((void *)pDevice, 10);
-                spin_unlock_irq(&pDevice->lock);
-                return;
-            }
-            pDevice->byBBVGACurrent = pDevice->byBBVGANew;
-            BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SetVGAGainOffset %02X\n", pDevice->byBBVGACurrent);
-            s_bCommandComplete(pDevice);
-            break;
-
-        default :
-            s_bCommandComplete(pDevice);
-            break;
-
-    } //switch
-    spin_unlock_irq(&pDevice->lock);
-    return;
 
+               s_bCommandComplete(pDevice);
+               break;
+
+       case WLAN_CMD_AP_MODE_START:
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState == WLAN_CMD_AP_MODE_START\n");
+
+               if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
+                       del_timer(&pMgmt->sTimerSecondCallback);
+                       pMgmt->eCurrState = WMAC_STATE_IDLE;
+                       pMgmt->eCurrMode = WMAC_MODE_STANDBY;
+                       pDevice->bLinkPass = false;
+                       if (pDevice->bEnableHostWEP == true)
+                               BSSvClearNodeDBTable(pDevice, 1);
+                       else
+                               BSSvClearNodeDBTable(pDevice, 0);
+                       pDevice->uAssocCount = 0;
+                       pMgmt->eCurrState = WMAC_STATE_IDLE;
+                       pDevice->bFixRate = false;
+
+                       vMgrCreateOwnIBSS((void *)pDevice, &Status);
+                       if (Status != CMD_STATUS_SUCCESS) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " vMgrCreateOwnIBSS fail ! \n");
+                       }
+                       // alway turn off unicast bit
+                       MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_UNICAST);
+                       pDevice->byRxMode &= ~RCR_UNICAST;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode);
+                       BSSvAddMulticastNode(pDevice);
+                       if (netif_queue_stopped(pDevice->dev)) {
+                               netif_wake_queue(pDevice->dev);
+                       }
+                       pDevice->bLinkPass = true;
+                       add_timer(&pMgmt->sTimerSecondCallback);
+               }
+               s_bCommandComplete(pDevice);
+               break;
+
+       case WLAN_CMD_TX_PSPACKET_START:
+               // DTIM Multicast tx
+               if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
+                       while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
+                               if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
+                                       pMgmt->abyPSTxMap[0] &= ~byMask[0];
+                                       pDevice->bMoreData = false;
+                               } else {
+                                       pDevice->bMoreData = true;
+                               }
+                               if (!device_dma0_xmit(pDevice, skb, 0)) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
+                               }
+                               pMgmt->sNodeDBTable[0].wEnQueueCnt--;
+                       }
+               }
+
+               // PS nodes tx
+               for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
+                       if (pMgmt->sNodeDBTable[ii].bActive &&
+                           pMgmt->sNodeDBTable[ii].bRxPSPoll) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
+                                       ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
+                               while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
+                                       if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
+                                               // clear tx map
+                                               pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
+                                                       ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
+                                               pDevice->bMoreData = false;
+                                       } else {
+                                               pDevice->bMoreData = true;
+                                       }
+                                       if (!device_dma0_xmit(pDevice, skb, ii)) {
+                                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
+                                       }
+                                       pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
+                                       // check if sta ps enabled, and wait next pspoll.
+                                       // if sta ps disable, then send all pending buffers.
+                                       if (pMgmt->sNodeDBTable[ii].bPSEnable)
+                                               break;
+                               }
+                               if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
+                                       // clear tx map
+                                       pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
+                                               ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
+                               }
+                               pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
+                       }
+               }
+
+               s_bCommandComplete(pDevice);
+               break;
+
+       case WLAN_CMD_RADIO_START:
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState == WLAN_CMD_RADIO_START\n");
+               if (pDevice->bRadioCmd == true)
+                       CARDbRadioPowerOn(pDevice);
+               else
+                       CARDbRadioPowerOff(pDevice);
+
+               s_bCommandComplete(pDevice);
+               break;
+
+       case WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE:
+               //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState == WLAN_CMD_CHECK_BBSENSITIVITY_START\n");
+               // wait all TD complete
+               if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
+                       vCommandTimerWait((void *)pDevice, 10);
+                       spin_unlock_irq(&pDevice->lock);
+                       return;
+               }
+               if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
+                       vCommandTimerWait((void *)pDevice, 10);
+                       spin_unlock_irq(&pDevice->lock);
+                       return;
+               }
+               pDevice->byBBVGACurrent = pDevice->byBBVGANew;
+               BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "SetVGAGainOffset %02X\n", pDevice->byBBVGACurrent);
+               s_bCommandComplete(pDevice);
+               break;
+
+       default:
+               s_bCommandComplete(pDevice);
+               break;
+
+       } //switch
+       spin_unlock_irq(&pDevice->lock);
+       return;
 }
 
-
 static
 bool
-s_bCommandComplete (
-    PSDevice pDevice
-    )
+s_bCommandComplete(
+       PSDevice pDevice
+)
 {
-    PWLAN_IE_SSID pSSID;
-    bool bRadioCmd = false;
-    //unsigned short wDeAuthenReason = 0;
-    bool bForceSCAN = true;
-    PSMgmtObject  pMgmt = pDevice->pMgmt;
-
-
-    pDevice->eCommandState = WLAN_CMD_IDLE;
-    if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
-        //Command Queue Empty
-        pDevice->bCmdRunning = false;
-        return true;
-    }
-    else {
-        pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
-        pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
-        bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
-        bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
-        ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
-        pDevice->cbFreeCmdQueue++;
-        pDevice->bCmdRunning = true;
-        switch ( pDevice->eCommand ) {
-            case WLAN_CMD_BSSID_SCAN:
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
-                pDevice->eCommandState = WLAN_CMD_SCAN_START;
-                pMgmt->uScanChannel = 0;
-                if (pSSID->len != 0) {
-                    memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-                } else {
-                    memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-                }
+       PWLAN_IE_SSID pSSID;
+       bool bRadioCmd = false;
+       //unsigned short wDeAuthenReason = 0;
+       bool bForceSCAN = true;
+       PSMgmtObject  pMgmt = pDevice->pMgmt;
+
+       pDevice->eCommandState = WLAN_CMD_IDLE;
+       if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
+               //Command Queue Empty
+               pDevice->bCmdRunning = false;
+               return true;
+       } else {
+               pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
+               pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
+               bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
+               bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
+               ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
+               pDevice->cbFreeCmdQueue++;
+               pDevice->bCmdRunning = true;
+               switch (pDevice->eCommand) {
+               case WLAN_CMD_BSSID_SCAN:
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState= WLAN_CMD_BSSID_SCAN\n");
+                       pDevice->eCommandState = WLAN_CMD_SCAN_START;
+                       pMgmt->uScanChannel = 0;
+                       if (pSSID->len != 0) {
+                               memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+                       } else {
+                               memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+                       }
 /*
-                if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
-                    if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
-                        ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
-                        pDevice->eCommandState = WLAN_CMD_IDLE;
-                    }
-                }
+  if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
+  if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
+  (!memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
+  pDevice->eCommandState = WLAN_CMD_IDLE;
+  }
+  }
 */
-                break;
-            case WLAN_CMD_SSID:
-                pDevice->eCommandState = WLAN_CMD_SSID_START;
-                if (pSSID->len > WLAN_SSID_MAXLEN)
-                    pSSID->len = WLAN_SSID_MAXLEN;
-                if (pSSID->len != 0)
-                    memcpy(pDevice->pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SSID_START\n");
-                break;
-            case WLAN_CMD_DISASSOCIATE:
-                pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
-                break;
-            case WLAN_CMD_RX_PSPOLL:
-                pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
-                break;
-            case WLAN_CMD_RUN_AP:
-                pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
-                break;
-            case WLAN_CMD_RADIO:
-                pDevice->eCommandState = WLAN_CMD_RADIO_START;
-                pDevice->bRadioCmd = bRadioCmd;
-                break;
-            case WLAN_CMD_CHANGE_BBSENSITIVITY:
-                pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
-                break;
-
-            default:
-                break;
-
-        }
-
-        vCommandTimerWait((void *)pDevice, 0);
-    }
-
-    return true;
+                       break;
+               case WLAN_CMD_SSID:
+                       pDevice->eCommandState = WLAN_CMD_SSID_START;
+                       if (pSSID->len > WLAN_SSID_MAXLEN)
+                               pSSID->len = WLAN_SSID_MAXLEN;
+                       if (pSSID->len != 0)
+                               memcpy(pDevice->pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "eCommandState= WLAN_CMD_SSID_START\n");
+                       break;
+               case WLAN_CMD_DISASSOCIATE:
+                       pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
+                       break;
+               case WLAN_CMD_RX_PSPOLL:
+                       pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
+                       break;
+               case WLAN_CMD_RUN_AP:
+                       pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
+                       break;
+               case WLAN_CMD_RADIO:
+                       pDevice->eCommandState = WLAN_CMD_RADIO_START;
+                       pDevice->bRadioCmd = bRadioCmd;
+                       break;
+               case WLAN_CMD_CHANGE_BBSENSITIVITY:
+                       pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
+                       break;
+
+               default:
+                       break;
+
+               }
+
+               vCommandTimerWait((void *)pDevice, 0);
+       }
+
+       return true;
 }
 
-
-
-bool bScheduleCommand (
-    void *hDeviceContext,
-    CMD_CODE    eCommand,
-    unsigned char *pbyItem0
-    )
+bool bScheduleCommand(
+       void *hDeviceContext,
+       CMD_CODE    eCommand,
+       unsigned char *pbyItem0
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-
-
-    if (pDevice->cbFreeCmdQueue == 0) {
-        return (false);
-    }
-    pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
-    pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
-    memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-
-    if (pbyItem0 != NULL) {
-        switch (eCommand) {
-
-            case WLAN_CMD_BSSID_SCAN:
-                memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
-                         pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-                pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
-                break;
-
-            case WLAN_CMD_SSID:
-                memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
-                         pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-                break;
-
-            case WLAN_CMD_DISASSOCIATE:
-                pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
-                break;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+
+       if (pDevice->cbFreeCmdQueue == 0) {
+               return false;
+       }
+       pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
+       pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
+       memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+
+       if (pbyItem0 != NULL) {
+               switch (eCommand) {
+               case WLAN_CMD_BSSID_SCAN:
+                       memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
+                              pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+                       pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
+                       break;
+
+               case WLAN_CMD_SSID:
+                       memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
+                              pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+                       break;
+
+               case WLAN_CMD_DISASSOCIATE:
+                       pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
+                       break;
 /*
-            case WLAN_CMD_DEAUTH:
-                pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((unsigned short *)pbyItem0);
-                break;
+  case WLAN_CMD_DEAUTH:
+  pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((unsigned short *)pbyItem0);
+  break;
 */
 
-            case WLAN_CMD_RX_PSPOLL:
-                break;
+               case WLAN_CMD_RX_PSPOLL:
+                       break;
 
-            case WLAN_CMD_RADIO:
-                pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
-                break;
+               case WLAN_CMD_RADIO:
+                       pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
+                       break;
 
-            case WLAN_CMD_CHANGE_BBSENSITIVITY:
-                pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
-                break;
+               case WLAN_CMD_CHANGE_BBSENSITIVITY:
+                       pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
+                       break;
 
-            default:
-                break;
-        }
-    }
+               default:
+                       break;
+               }
+       }
 
-    ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
-    pDevice->cbFreeCmdQueue--;
-
-    if (pDevice->bCmdRunning == false) {
-        s_bCommandComplete(pDevice);
-    }
-    else {
-    }
-    return (true);
+       ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
+       pDevice->cbFreeCmdQueue--;
 
+       if (pDevice->bCmdRunning == false) {
+               s_bCommandComplete(pDevice);
+       } else {
+       }
+       return true;
 }
 
 /*
@@ -1038,87 +969,81 @@ bool bScheduleCommand (
  * Return Value: true if success; otherwise false
  *
  */
-bool bClearBSSID_SCAN (
-    void *hDeviceContext
-    )
+bool bClearBSSID_SCAN(
+       void *hDeviceContext
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
-    unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
-    unsigned int ii;
-
-    if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
-        for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) {
-            if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
-                pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
-            ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
-            if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
-                break;
-        }
-    }
-    return true;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
+       unsigned int ii;
+
+       if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
+               for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii++) {
+                       if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
+                               pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
+                       ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
+                       if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
+                               break;
+               }
+       }
+       return true;
 }
 
 //mike add:reset command timer
 void
 vResetCommandTimer(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-  PSDevice        pDevice = (PSDevice)hDeviceContext;
-
-  //delete timer
-      del_timer(&pDevice->sTimerCommand);
-  //init timer
-      init_timer(&pDevice->sTimerCommand);
-    pDevice->sTimerCommand.data = (unsigned long) pDevice;
-    pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
-    pDevice->sTimerCommand.expires = RUN_AT(HZ);
-    pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
-    pDevice->uCmdDequeueIdx = 0;
-    pDevice->uCmdEnqueueIdx = 0;
-    pDevice->eCommandState = WLAN_CMD_IDLE;
-    pDevice->bCmdRunning = false;
-    pDevice->bCmdClear = false;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+
+       //delete timer
+       del_timer(&pDevice->sTimerCommand);
+       //init timer
+       init_timer(&pDevice->sTimerCommand);
+       pDevice->sTimerCommand.data = (unsigned long) pDevice;
+       pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
+       pDevice->sTimerCommand.expires = RUN_AT(HZ);
+       pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
+       pDevice->uCmdDequeueIdx = 0;
+       pDevice->uCmdEnqueueIdx = 0;
+       pDevice->eCommandState = WLAN_CMD_IDLE;
+       pDevice->bCmdRunning = false;
+       pDevice->bCmdClear = false;
 }
 
-
 #ifdef TxInSleep
 void
 BSSvSecondTxData(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-  PSDevice        pDevice = (PSDevice)hDeviceContext;
-  PSMgmtObject  pMgmt = &(pDevice->sMgmtObj);
-  pDevice->nTxDataTimeCout++;
-
-  if(pDevice->nTxDataTimeCout<4)     //don't tx data if timer less than 40s
-    {
-     // printk("mike:%s-->no data Tx not exceed the desired Time as %d\n",__FUNCTION__,
-       //      (int)pDevice->nTxDataTimeCout);
-     pDevice->sTimerTxData.expires = RUN_AT(10*HZ);      //10s callback
-     add_timer(&pDevice->sTimerTxData);
-      return;
-    }
-
-  spin_lock_irq(&pDevice->lock);
-  #if 1
-  if(((pDevice->bLinkPass ==true)&&(pMgmt->eAuthenMode < WMAC_AUTH_WPA)) ||  //open && sharekey linking
-      (pDevice->fWPA_Authened == true)) {   //wpa linking
- #else
-  if(pDevice->bLinkPass ==true) {
- #endif
-
-        //   printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__);
-         pDevice->fTxDataInSleep = true;
-         PSbSendNullPacket(pDevice);      //send null packet
-         pDevice->fTxDataInSleep = false;
-       }
-  spin_unlock_irq(&pDevice->lock);
-
-  pDevice->sTimerTxData.expires = RUN_AT(10*HZ);      //10s callback
-  add_timer(&pDevice->sTimerTxData);
-  return;
-}
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject  pMgmt = &(pDevice->sMgmtObj);
+       pDevice->nTxDataTimeCout++;
+
+       if (pDevice->nTxDataTimeCout < 4)     //don't tx data if timer less than 40s
+       {
+               pDevice->sTimerTxData.expires = RUN_AT(10*HZ);      //10s callback
+               add_timer(&pDevice->sTimerTxData);
+               return;
+       }
+
+       spin_lock_irq(&pDevice->lock);
+#if 1
+       if (((pDevice->bLinkPass == true) && (pMgmt->eAuthenMode < WMAC_AUTH_WPA)) ||  //open && sharekey linking
+          (pDevice->fWPA_Authened == true)) {   //wpa linking
+#else
+               if (pDevice->bLinkPass == true) {
+#endif
+                       pDevice->fTxDataInSleep = true;
+                       PSbSendNullPacket(pDevice);      //send null packet
+                       pDevice->fTxDataInSleep = false;
+               }
+               spin_unlock_irq(&pDevice->lock);
+
+               pDevice->sTimerTxData.expires = RUN_AT(10*HZ);      //10s callback
+               add_timer(&pDevice->sTimerTxData);
+               return;
+       }
 #endif
-
index 69d4fc55b843e14b8774d7ee0789e7f0ee206c7a..2844476d5dc9dfedb88566a73bfbd25286c9f957 100644 (file)
 
 /*---------------------  Export Definitions -------------------------*/
 
-
-
 #define AUTHENTICATE_TIMEOUT   1000 //ms
 #define ASSOCIATE_TIMEOUT      1000 //ms
 
-
 // Command code
 typedef enum tagCMD_CODE {
-    WLAN_CMD_BSSID_SCAN,
-    WLAN_CMD_SSID,
-    WLAN_CMD_DISASSOCIATE,
-    WLAN_CMD_DEAUTH,
-    WLAN_CMD_RX_PSPOLL,
-    WLAN_CMD_RADIO,
-    WLAN_CMD_CHANGE_BBSENSITIVITY,
-    WLAN_CMD_SETPOWER,
-    WLAN_CMD_TBTT_WAKEUP,
-    WLAN_CMD_BECON_SEND,
-    WLAN_CMD_CHANGE_ANTENNA,
-    WLAN_CMD_REMOVE_ALLKEY,
-    WLAN_CMD_MAC_DISPOWERSAVING,
-    WLAN_CMD_11H_CHSW,
-    WLAN_CMD_RUN_AP
+       WLAN_CMD_BSSID_SCAN,
+       WLAN_CMD_SSID,
+       WLAN_CMD_DISASSOCIATE,
+       WLAN_CMD_DEAUTH,
+       WLAN_CMD_RX_PSPOLL,
+       WLAN_CMD_RADIO,
+       WLAN_CMD_CHANGE_BBSENSITIVITY,
+       WLAN_CMD_SETPOWER,
+       WLAN_CMD_TBTT_WAKEUP,
+       WLAN_CMD_BECON_SEND,
+       WLAN_CMD_CHANGE_ANTENNA,
+       WLAN_CMD_REMOVE_ALLKEY,
+       WLAN_CMD_MAC_DISPOWERSAVING,
+       WLAN_CMD_11H_CHSW,
+       WLAN_CMD_RUN_AP
 } CMD_CODE, *PCMD_CODE;
 
 #define CMD_Q_SIZE              32
 
 typedef enum tagCMD_STATUS {
-
-    CMD_STATUS_SUCCESS = 0,
-    CMD_STATUS_FAILURE,
-    CMD_STATUS_RESOURCES,
-    CMD_STATUS_TIMEOUT,
-    CMD_STATUS_PENDING
-
+       CMD_STATUS_SUCCESS = 0,
+       CMD_STATUS_FAILURE,
+       CMD_STATUS_RESOURCES,
+       CMD_STATUS_TIMEOUT,
+       CMD_STATUS_PENDING
 } CMD_STATUS, *PCMD_STATUS;
 
-
 typedef struct tagCMD_ITEM {
-    CMD_CODE eCmd;
-    unsigned char abyCmdDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
-    bool bNeedRadioOFF;
-    unsigned short wDeAuthenReason;
-    bool bRadioCmd;
-    bool bForceSCAN;
+       CMD_CODE eCmd;
+       unsigned char abyCmdDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
+       bool bNeedRadioOFF;
+       unsigned short wDeAuthenReason;
+       bool bRadioCmd;
+       bool bForceSCAN;
 } CMD_ITEM, *PCMD_ITEM;
 
 // Command state
 typedef enum tagCMD_STATE {
-    WLAN_CMD_SCAN_START,
-    WLAN_CMD_SCAN_END,
-    WLAN_CMD_DISASSOCIATE_START,
-    WLAN_CMD_SSID_START,
-    WLAN_AUTHENTICATE_WAIT,
-    WLAN_ASSOCIATE_WAIT,
-    WLAN_DISASSOCIATE_WAIT,
-    WLAN_CMD_TX_PSPACKET_START,
-    WLAN_CMD_AP_MODE_START,
-    WLAN_CMD_RADIO_START,
-    WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE,
-    WLAN_CMD_IDLE
+       WLAN_CMD_SCAN_START,
+       WLAN_CMD_SCAN_END,
+       WLAN_CMD_DISASSOCIATE_START,
+       WLAN_CMD_SSID_START,
+       WLAN_AUTHENTICATE_WAIT,
+       WLAN_ASSOCIATE_WAIT,
+       WLAN_DISASSOCIATE_WAIT,
+       WLAN_CMD_TX_PSPACKET_START,
+       WLAN_CMD_AP_MODE_START,
+       WLAN_CMD_RADIO_START,
+       WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE,
+       WLAN_CMD_IDLE
 } CMD_STATE, *PCMD_STATE;
 
-
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Types  ------------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 void
 vResetCommandTimer(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 void
-vCommandTimer (
-    void *hDeviceContext
-    );
+vCommandTimer(
+       void *hDeviceContext
+);
 
 bool bClearBSSID_SCAN(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 bool
 bScheduleCommand(
-    void *hDeviceContext,
-    CMD_CODE    eCommand,
-    unsigned char *pbyItem0
-    );
+       void *hDeviceContext,
+       CMD_CODE    eCommand,
+       unsigned char *pbyItem0
+);
 
 void
 vCommandTimerWait(
-    void *hDeviceContext,
-    unsigned int MSecond
-    );
+       void *hDeviceContext,
+       unsigned int MSecond
+);
 #ifdef TxInSleep
 void
 BSSvSecondTxData(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 #endif
 
 #endif //__WCMD_H__
index c096583a7726110043f76a7288752d6f68a4a722..9eb81b4eee806b3ccda7331c4a0245182a22ec4d 100644 (file)
@@ -48,8 +48,6 @@
 
 /*---------------------  Export Variables  --------------------------*/
 
-
-
 /*
  * Description:
  *      Scan Rx cache.  Return true if packet is duplicate, else
  *
  */
 
-bool WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
+bool WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader)
 {
-    unsigned int uIndex;
-    unsigned int ii;
-    PSCacheEntry    pCacheEntry;
-
-    if (IS_FC_RETRY(pMACHeader)) {
-
-        uIndex = pCache->uInPtr;
-        for (ii = 0; ii < DUPLICATE_RX_CACHE_LENGTH; ii++) {
-            pCacheEntry = &(pCache->asCacheEntry[uIndex]);
-            if ((pCacheEntry->wFmSequence == pMACHeader->wSeqCtl) &&
-                (!compare_ether_addr(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0])))
-                ) {
-                /* Duplicate match */
-                return true;
-            }
-            ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH);
-        }
-    }
-    /* Not fount in cache - insert */
-    pCacheEntry = &pCache->asCacheEntry[pCache->uInPtr];
-    pCacheEntry->wFmSequence = pMACHeader->wSeqCtl;
-    memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN);
-    ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH);
-    return false;
+       unsigned int uIndex;
+       unsigned int ii;
+       PSCacheEntry    pCacheEntry;
+
+       if (IS_FC_RETRY(pMACHeader)) {
+               uIndex = pCache->uInPtr;
+               for (ii = 0; ii < DUPLICATE_RX_CACHE_LENGTH; ii++) {
+                       pCacheEntry = &(pCache->asCacheEntry[uIndex]);
+                       if ((pCacheEntry->wFmSequence == pMACHeader->wSeqCtl) &&
+                           (!compare_ether_addr(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0])))
+) {
+                               /* Duplicate match */
+                               return true;
+                       }
+                       ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH);
+               }
+       }
+       /* Not fount in cache - insert */
+       pCacheEntry = &pCache->asCacheEntry[pCache->uInPtr];
+       pCacheEntry->wFmSequence = pMACHeader->wSeqCtl;
+       memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN);
+       ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH);
+       return false;
 }
 
 /*
@@ -108,22 +105,21 @@ bool WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
  * Return Value: index number in Defragment Database
  *
  */
-unsigned int WCTLuSearchDFCB (PSDevice pDevice, PS802_11Header pMACHeader)
+unsigned int WCTLuSearchDFCB(PSDevice pDevice, PS802_11Header pMACHeader)
 {
-unsigned int ii;
-
-    for(ii=0;ii<pDevice->cbDFCB;ii++) {
-        if ((pDevice->sRxDFCB[ii].bInUse == true) &&
-            (!compare_ether_addr(&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0])))
-            ) {
-            //
-            return(ii);
-        }
-    }
-    return(pDevice->cbDFCB);
+       unsigned int ii;
+
+       for (ii = 0; ii < pDevice->cbDFCB; ii++) {
+               if ((pDevice->sRxDFCB[ii].bInUse == true) &&
+                   (!compare_ether_addr(&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0])))
+) {
+                       //
+                       return ii;
+               }
+       }
+       return pDevice->cbDFCB;
 }
 
-
 /*
  * Description:
  *      Insert received fragment packet in Defragment Database
@@ -138,27 +134,26 @@ unsigned int ii;
  * Return Value: index number in Defragment Database
  *
  */
-unsigned int WCTLuInsertDFCB (PSDevice pDevice, PS802_11Header pMACHeader)
+unsigned int WCTLuInsertDFCB(PSDevice pDevice, PS802_11Header pMACHeader)
 {
-unsigned int ii;
-
-    if (pDevice->cbFreeDFCB == 0)
-        return(pDevice->cbDFCB);
-    for(ii=0;ii<pDevice->cbDFCB;ii++) {
-        if (pDevice->sRxDFCB[ii].bInUse == false) {
-            pDevice->cbFreeDFCB--;
-            pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime;
-            pDevice->sRxDFCB[ii].bInUse = true;
-            pDevice->sRxDFCB[ii].wSequence = (pMACHeader->wSeqCtl >> 4);
-            pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
-            memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN);
-            return(ii);
-        }
-    }
-    return(pDevice->cbDFCB);
+       unsigned int ii;
+
+       if (pDevice->cbFreeDFCB == 0)
+               return pDevice->cbDFCB;
+       for (ii = 0; ii < pDevice->cbDFCB; ii++) {
+               if (pDevice->sRxDFCB[ii].bInUse == false) {
+                       pDevice->cbFreeDFCB--;
+                       pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime;
+                       pDevice->sRxDFCB[ii].bInUse = true;
+                       pDevice->sRxDFCB[ii].wSequence = (pMACHeader->wSeqCtl >> 4);
+                       pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
+                       memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN);
+                       return ii;
+               }
+       }
+       return pDevice->cbDFCB;
 }
 
-
 /*
  * Description:
  *      Handle received fragment packet
@@ -175,76 +170,67 @@ unsigned int ii;
  * Return Value: true if it is valid fragment packet and we have resource to defragment; otherwise false
  *
  */
-bool WCTLbHandleFragment (PSDevice pDevice, PS802_11Header pMACHeader, unsigned int cbFrameLength, bool bWEP, bool bExtIV)
+bool WCTLbHandleFragment(PSDevice pDevice, PS802_11Header pMACHeader, unsigned int cbFrameLength, bool bWEP, bool bExtIV)
 {
-unsigned int uHeaderSize;
-
-
-    if (bWEP == true) {
-        uHeaderSize = 28;
-        if (bExtIV)
-        // ExtIV
-            uHeaderSize +=4;
-    }
-    else {
-        uHeaderSize = 24;
-    }
-
-    if (IS_FIRST_FRAGMENT_PKT(pMACHeader)) {
-        pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
-        if (pDevice->uCurrentDFCBIdx < pDevice->cbDFCB) {
-            // duplicate, we must flush previous DCB
-            pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].uLifetime = pDevice->dwMaxReceiveLifetime;
-            pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence = (pMACHeader->wSeqCtl >> 4);
-            pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
-        }
-        else {
-            pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader);
-            if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) {
-                return(false);
-            }
-        }
-        // reserve 4 byte to match MAC RX Buffer
-        pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (unsigned char *) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4);
-        memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, pMACHeader, cbFrameLength);
-        pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength = cbFrameLength;
-        pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength;
-        pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
-        //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
-        return(false);
-    }
-    else {
-        pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
-        if (pDevice->uCurrentDFCBIdx != pDevice->cbDFCB) {
-            if ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence == (pMACHeader->wSeqCtl >> 4)) &&
-                (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum == (pMACHeader->wSeqCtl & 0x000F)) &&
-                ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength + cbFrameLength - uHeaderSize) < 2346)) {
-
-                memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, ((unsigned char *) (pMACHeader) + uHeaderSize), (cbFrameLength - uHeaderSize));
-                pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength += (cbFrameLength - uHeaderSize);
-                pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += (cbFrameLength - uHeaderSize);
-                pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
-                //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Second pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
-            }
-            else {
-                // seq error or frag # error flush DFCB
-                pDevice->cbFreeDFCB++;
-                pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
-                return(false);
-            }
-        }
-        else {
-            return(false);
-        }
-        if (IS_LAST_FRAGMENT_PKT(pMACHeader)) {
-            //enq defragcontrolblock
-            pDevice->cbFreeDFCB++;
-            pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
-            //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
-            return(true);
-        }
-        return(false);
-    }
+       unsigned int uHeaderSize;
+
+       if (bWEP == true) {
+               uHeaderSize = 28;
+               if (bExtIV)
+                       // ExtIV
+                       uHeaderSize += 4;
+       } else {
+               uHeaderSize = 24;
+       }
+
+       if (IS_FIRST_FRAGMENT_PKT(pMACHeader)) {
+               pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
+               if (pDevice->uCurrentDFCBIdx < pDevice->cbDFCB) {
+                       // duplicate, we must flush previous DCB
+                       pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].uLifetime = pDevice->dwMaxReceiveLifetime;
+                       pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence = (pMACHeader->wSeqCtl >> 4);
+                       pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
+               } else {
+                       pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader);
+                       if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) {
+                               return false;
+                       }
+               }
+               // reserve 4 byte to match MAC RX Buffer
+               pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (unsigned char *)(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4);
+               memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, pMACHeader, cbFrameLength);
+               pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength = cbFrameLength;
+               pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength;
+               pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
+               //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
+               return false;
+       } else {
+               pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
+               if (pDevice->uCurrentDFCBIdx != pDevice->cbDFCB) {
+                       if ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence == (pMACHeader->wSeqCtl >> 4)) &&
+                           (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum == (pMACHeader->wSeqCtl & 0x000F)) &&
+                           ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength + cbFrameLength - uHeaderSize) < 2346)) {
+                               memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, ((unsigned char *)(pMACHeader) + uHeaderSize), (cbFrameLength - uHeaderSize));
+                               pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength += (cbFrameLength - uHeaderSize);
+                               pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += (cbFrameLength - uHeaderSize);
+                               pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
+                               //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Second pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
+                       } else {
+                               // seq error or frag # error flush DFCB
+                               pDevice->cbFreeDFCB++;
+                               pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
+                               return false;
+                       }
+               } else {
+                       return false;
+               }
+               if (IS_LAST_FRAGMENT_PKT(pMACHeader)) {
+                       //enq defragcontrolblock
+                       pDevice->cbFreeDFCB++;
+                       pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
+                       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
+                       return true;
+               }
+               return false;
+       }
 }
-
-
index a92bb6d2b3f0e9868fdc1ab2624366609922844e..1ffb2734cfae080dde03b3148ed1d24bd5884ea5 100644 (file)
 
 /*---------------------  Export Definitions -------------------------*/
 
-#define IS_TYPE_DATA(pMACHeader)                                                        \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_DATA)
+#define IS_TYPE_DATA(pMACHeader)                                       \
+       ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_DATA)
 
-#define IS_TYPE_MGMT(pMACHeader)                                                        \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_MGMT)
+#define IS_TYPE_MGMT(pMACHeader)                                       \
+       ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_MGMT)
 
-#define IS_TYPE_CONTROL(pMACHeader)                                                     \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_CTL)
+#define IS_TYPE_CONTROL(pMACHeader)                                    \
+       ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_CTL)
 
-#define IS_FC_MOREDATA(pMACHeader)                                                      \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREDATA) == FC_MOREDATA)
+#define IS_FC_MOREDATA(pMACHeader)                                     \
+       ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREDATA) == FC_MOREDATA)
 
-#define IS_FC_POWERMGT(pMACHeader)                                                      \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_POWERMGT) == FC_POWERMGT)
+#define IS_FC_POWERMGT(pMACHeader)                                     \
+       ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_POWERMGT) == FC_POWERMGT)
 
-#define IS_FC_RETRY(pMACHeader)                                                         \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_RETRY) == FC_RETRY)
+#define IS_FC_RETRY(pMACHeader)                                                \
+       ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_RETRY) == FC_RETRY)
 
-#define IS_FC_WEP(pMACHeader)                                                           \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_WEP) == FC_WEP)
+#define IS_FC_WEP(pMACHeader)                                          \
+       ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_WEP) == FC_WEP)
 
 #ifdef __BIG_ENDIAN
 
-#define IS_FRAGMENT_PKT(pMACHeader)                                                     \
-    (((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) != 0) |                  \
-     ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x0F00) != 0))
+#define IS_FRAGMENT_PKT(pMACHeader)                                    \
+       (((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) != 0) | \
+        ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x0F00) != 0))
 
-#define IS_FIRST_FRAGMENT_PKT(pMACHeader)                                               \
-    ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x0F00) == 0)
+#define IS_FIRST_FRAGMENT_PKT(pMACHeader)                              \
+       ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x0F00) == 0)
 
 #else
 
-#define IS_FRAGMENT_PKT(pMACHeader)                                                     \
-    (((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) != 0) |                  \
-     ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x000F) != 0))
+#define IS_FRAGMENT_PKT(pMACHeader)                                    \
+       (((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) != 0) | \
+        ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x000F) != 0))
 
-#define IS_FIRST_FRAGMENT_PKT(pMACHeader)                                               \
-    ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x000F) == 0)
+#define IS_FIRST_FRAGMENT_PKT(pMACHeader)                              \
+       ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x000F) == 0)
 
 #endif//#ifdef __BIG_ENDIAN
 
-#define IS_LAST_FRAGMENT_PKT(pMACHeader)                                                \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) == 0)
+#define IS_LAST_FRAGMENT_PKT(pMACHeader)                               \
+       ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) == 0)
 
-#define IS_CTL_PSPOLL(pMACHeader)                                                       \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL)
-
-
-#define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) {   \
-    if ((uVar) >= ((uModulo) - 1))                  \
-        (uVar) = 0;                                 \
-    else                                            \
-        (uVar)++;                                   \
-}
+#define IS_CTL_PSPOLL(pMACHeader)                                      \
+       ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL)
 
+#define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo)                \
+do {                                                   \
+       if ((uVar) >= ((uModulo) - 1))                  \
+               (uVar) = 0;                             \
+       else                                            \
+               (uVar)++;                               \
+} while (0)
 
 /*---------------------  Export Classes  ----------------------------*/
 
 
 bool WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader);
 bool WCTLbHandleFragment(PSDevice pDevice, PS802_11Header pMACHeader,
-               unsigned int cbFrameLength, bool bWEP, bool bExtIV);
+                        unsigned int cbFrameLength, bool bWEP, bool bExtIV);
 unsigned int WCTLuSearchDFCB(PSDevice pDevice, PS802_11Header pMACHeader);
 unsigned int WCTLuInsertDFCB(PSDevice pDevice, PS802_11Header pMACHeader);
 
 #endif // __WCTL_H__
-
-
-
index b08a611a184aa80a9bdd647ff7e027cc05acd810..9938813f997a276227d1cdaae10fc245e97f886b 100644 (file)
 
 /*---------------------  Static Definitions -------------------------*/
 
-
-
 /*---------------------  Static Classes  ----------------------------*/
 
 /*---------------------  Static Variables  --------------------------*/
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 
 /*---------------------  Static Functions  --------------------------*/
 //2008-8-4 <add> by chester
 static bool ChannelExceedZoneType(
-    PSDevice pDevice,
-    unsigned char byCurrChannel
-    );
+       PSDevice pDevice,
+       unsigned char byCurrChannel
+);
 
 // Association/diassociation functions
 static
 PSTxMgmtPacket
 s_MgrMakeAssocRequest(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned char *pDAddr,
-    unsigned short wCurrCapInfo,
-    unsigned short wListenInterval,
-    PWLAN_IE_SSID pCurrSSID,
-    PWLAN_IE_SUPP_RATES pCurrRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned char *pDAddr,
+       unsigned short wCurrCapInfo,
+       unsigned short wListenInterval,
+       PWLAN_IE_SSID pCurrSSID,
+       PWLAN_IE_SUPP_RATES pCurrRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+);
 
 static
 void
 s_vMgrRxAssocRequest(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket,
-    unsigned int uNodeIndex
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket,
+       unsigned int uNodeIndex
+);
 
 static
 PSTxMgmtPacket
 s_MgrMakeReAssocRequest(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned char *pDAddr,
-    unsigned short wCurrCapInfo,
-    unsigned short wListenInterval,
-    PWLAN_IE_SSID pCurrSSID,
-    PWLAN_IE_SUPP_RATES pCurrRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned char *pDAddr,
+       unsigned short wCurrCapInfo,
+       unsigned short wListenInterval,
+       PWLAN_IE_SSID pCurrSSID,
+       PWLAN_IE_SUPP_RATES pCurrRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+);
 
 static
 void
 s_vMgrRxAssocResponse(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket,
-    bool bReAssocType
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket,
+       bool bReAssocType
+);
 
 static
 void
 s_vMgrRxDisassociation(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+);
 
 // Authentication/deauthen functions
 static
 void
 s_vMgrRxAuthenSequence_1(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PWLAN_FR_AUTHEN pFrame
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PWLAN_FR_AUTHEN pFrame
+);
 
 static
 void
 s_vMgrRxAuthenSequence_2(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PWLAN_FR_AUTHEN pFrame
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PWLAN_FR_AUTHEN pFrame
+);
 
 static
 void
 s_vMgrRxAuthenSequence_3(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PWLAN_FR_AUTHEN pFrame
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PWLAN_FR_AUTHEN pFrame
+);
 
 static
 void
 s_vMgrRxAuthenSequence_4(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PWLAN_FR_AUTHEN pFrame
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PWLAN_FR_AUTHEN pFrame
+);
 
 static
 void
 s_vMgrRxAuthentication(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+);
 
 static
 void
 s_vMgrRxDeauthentication(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+);
 
 // Scan functions
 // probe request/response functions
 static
 void
 s_vMgrRxProbeRequest(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+);
 
 static
 void
 s_vMgrRxProbeResponse(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+);
 
 // beacon functions
 static
 void
 s_vMgrRxBeacon(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket,
-    bool bInScan
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket,
+       bool bInScan
+);
 
 static
 void
 s_vMgrFormatTIM(
-    PSMgmtObject pMgmt,
-    PWLAN_IE_TIM pTIM
-    );
+       PSMgmtObject pMgmt,
+       PWLAN_IE_TIM pTIM
+);
 
 static
 PSTxMgmtPacket
 s_MgrMakeBeacon(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned short wCurrCapInfo,
-    unsigned short wCurrBeaconPeriod,
-    unsigned int uCurrChannel,
-    unsigned short wCurrATIMWinodw,
-    PWLAN_IE_SSID pCurrSSID,
-    unsigned char *pCurrBSSID,
-    PWLAN_IE_SUPP_RATES pCurrSuppRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-    );
-
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned short wCurrCapInfo,
+       unsigned short wCurrBeaconPeriod,
+       unsigned int uCurrChannel,
+       unsigned short wCurrATIMWinodw,
+       PWLAN_IE_SSID pCurrSSID,
+       unsigned char *pCurrBSSID,
+       PWLAN_IE_SUPP_RATES pCurrSuppRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+);
 
 // Association response
 static
 PSTxMgmtPacket
 s_MgrMakeAssocResponse(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned short wCurrCapInfo,
-    unsigned short wAssocStatus,
-    unsigned short wAssocAID,
-    unsigned char *pDstAddr,
-    PWLAN_IE_SUPP_RATES pCurrSuppRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned short wCurrCapInfo,
+       unsigned short wAssocStatus,
+       unsigned short wAssocAID,
+       unsigned char *pDstAddr,
+       PWLAN_IE_SUPP_RATES pCurrSuppRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+);
 
 // ReAssociation response
 static
 PSTxMgmtPacket
 s_MgrMakeReAssocResponse(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned short wCurrCapInfo,
-    unsigned short wAssocStatus,
-    unsigned short wAssocAID,
-    unsigned char *pDstAddr,
-    PWLAN_IE_SUPP_RATES pCurrSuppRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned short wCurrCapInfo,
+       unsigned short wAssocStatus,
+       unsigned short wAssocAID,
+       unsigned char *pDstAddr,
+       PWLAN_IE_SUPP_RATES pCurrSuppRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+);
 
 // Probe response
 static
 PSTxMgmtPacket
 s_MgrMakeProbeResponse(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned short wCurrCapInfo,
-    unsigned short wCurrBeaconPeriod,
-    unsigned int uCurrChannel,
-    unsigned short wCurrATIMWinodw,
-    unsigned char *pDstAddr,
-    PWLAN_IE_SSID pCurrSSID,
-    unsigned char *pCurrBSSID,
-    PWLAN_IE_SUPP_RATES pCurrSuppRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
-    unsigned char byPHYType
-    );
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned short wCurrCapInfo,
+       unsigned short wCurrBeaconPeriod,
+       unsigned int uCurrChannel,
+       unsigned short wCurrATIMWinodw,
+       unsigned char *pDstAddr,
+       PWLAN_IE_SSID pCurrSSID,
+       unsigned char *pCurrBSSID,
+       PWLAN_IE_SUPP_RATES pCurrSuppRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
+       unsigned char byPHYType
+);
 
 // received status
 static
 void
 s_vMgrLogStatus(
-    PSMgmtObject pMgmt,
-    unsigned short wStatus
-    );
-
+       PSMgmtObject pMgmt,
+       unsigned short wStatus
+);
 
 static
 void
-s_vMgrSynchBSS (
-    PSDevice      pDevice,
-    unsigned int uBSSMode,
-    PKnownBSS     pCurr,
-    PCMD_STATUS  pStatus
-    );
-
+s_vMgrSynchBSS(
+       PSDevice      pDevice,
+       unsigned int uBSSMode,
+       PKnownBSS     pCurr,
+       PCMD_STATUS  pStatus
+);
 
 static bool
-s_bCipherMatch (
-    PKnownBSS                        pBSSNode,
-    NDIS_802_11_ENCRYPTION_STATUS    EncStatus,
-    unsigned char *pbyCCSPK,
-    unsigned char *pbyCCSGK
-    );
-
- static void  Encyption_Rebuild(
-    PSDevice pDevice,
-    PKnownBSS pCurr
- );
-
-
+s_bCipherMatch(
+       PKnownBSS                        pBSSNode,
+       NDIS_802_11_ENCRYPTION_STATUS    EncStatus,
+       unsigned char *pbyCCSPK,
+       unsigned char *pbyCCSGK
+);
+
+static void  Encyption_Rebuild(
+       PSDevice pDevice,
+       PKnownBSS pCurr
+);
 
 /*---------------------  Export Variables  --------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
-
 /*+
  *
  * Routine Description:
@@ -346,32 +337,31 @@ s_bCipherMatch (
  * Return Value:
  *    Ndis_staus.
  *
--*/
+ -*/
 
 void
 vMgrObjectInit(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-    PSDevice     pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    int ii;
-
-
-    pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
-    pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
-    pMgmt->uCurrChannel = pDevice->uChannel;
-    for(ii=0;ii<WLAN_BSSID_LEN;ii++) {
-        pMgmt->abyDesireBSSID[ii] = 0xFF;
-    }
-    pMgmt->sAssocInfo.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
-    //memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN +1);
-    pMgmt->byCSSPK = KEY_CTL_NONE;
-    pMgmt->byCSSGK = KEY_CTL_NONE;
-    pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
-    BSSvClearBSSList((void *)pDevice, false);
-
-    return;
+       PSDevice     pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       int ii;
+
+       pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
+       pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
+       pMgmt->uCurrChannel = pDevice->uChannel;
+       for (ii = 0; ii < WLAN_BSSID_LEN; ii++) {
+               pMgmt->abyDesireBSSID[ii] = 0xFF;
+       }
+       pMgmt->sAssocInfo.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
+       //memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN +1);
+       pMgmt->byCSSPK = KEY_CTL_NONE;
+       pMgmt->byCSSGK = KEY_CTL_NONE;
+       pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
+       BSSvClearBSSList((void *)pDevice, false);
+
+       return;
 }
 
 /*+
@@ -382,45 +372,42 @@ vMgrObjectInit(
  * Return Value:
  *    Ndis_staus.
  *
--*/
+ -*/
 
 void
 vMgrTimerInit(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-    PSDevice     pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-
-
-    init_timer(&pMgmt->sTimerSecondCallback);
-    pMgmt->sTimerSecondCallback.data = (unsigned long) pDevice;
-    pMgmt->sTimerSecondCallback.function = (TimerFunction)BSSvSecondCallBack;
-    pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
-
-    init_timer(&pDevice->sTimerCommand);
-    pDevice->sTimerCommand.data = (unsigned long) pDevice;
-    pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
-    pDevice->sTimerCommand.expires = RUN_AT(HZ);
-
-   #ifdef TxInSleep
-    init_timer(&pDevice->sTimerTxData);
-    pDevice->sTimerTxData.data = (unsigned long) pDevice;
-    pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
-    pDevice->sTimerTxData.expires = RUN_AT(10*HZ);      //10s callback
-    pDevice->fTxDataInSleep = false;
-    pDevice->IsTxDataTrigger = false;
-    pDevice->nTxDataTimeCout = 0;
-   #endif
-
-    pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
-    pDevice->uCmdDequeueIdx = 0;
-    pDevice->uCmdEnqueueIdx = 0;
-
-    return;
-}
+       PSDevice     pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+
+       init_timer(&pMgmt->sTimerSecondCallback);
+       pMgmt->sTimerSecondCallback.data = (unsigned long) pDevice;
+       pMgmt->sTimerSecondCallback.function = (TimerFunction)BSSvSecondCallBack;
+       pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
+
+       init_timer(&pDevice->sTimerCommand);
+       pDevice->sTimerCommand.data = (unsigned long) pDevice;
+       pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
+       pDevice->sTimerCommand.expires = RUN_AT(HZ);
+
+#ifdef TxInSleep
+       init_timer(&pDevice->sTimerTxData);
+       pDevice->sTimerTxData.data = (unsigned long) pDevice;
+       pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
+       pDevice->sTimerTxData.expires = RUN_AT(10*HZ);      //10s callback
+       pDevice->fTxDataInSleep = false;
+       pDevice->IsTxDataTrigger = false;
+       pDevice->nTxDataTimeCout = 0;
+#endif
 
+       pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
+       pDevice->uCmdDequeueIdx = 0;
+       pDevice->uCmdEnqueueIdx = 0;
 
+       return;
+}
 
 /*+
  *
@@ -430,25 +417,24 @@ vMgrTimerInit(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrObjectReset(
-    void *hDeviceContext
-    )
+       void *hDeviceContext
+)
 {
-    PSDevice         pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject        pMgmt = pDevice->pMgmt;
+       PSDevice         pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject        pMgmt = pDevice->pMgmt;
 
-    pMgmt->eCurrMode = WMAC_MODE_STANDBY;
-    pMgmt->eCurrState = WMAC_STATE_IDLE;
-    pDevice->bEnablePSMode = false;
-    // TODO: timer
+       pMgmt->eCurrMode = WMAC_MODE_STANDBY;
+       pMgmt->eCurrState = WMAC_STATE_IDLE;
+       pDevice->bEnablePSMode = false;
+       // TODO: timer
 
-    return;
+       return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -458,74 +444,66 @@ vMgrObjectReset(
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 void
 vMgrAssocBeginSta(
-    void *hDeviceContext,
-    PSMgmtObject pMgmt,
-    PCMD_STATUS pStatus
-    )
+       void *hDeviceContext,
+       PSMgmtObject pMgmt,
+       PCMD_STATUS pStatus
+)
 {
-    PSDevice             pDevice = (PSDevice)hDeviceContext;
-    PSTxMgmtPacket          pTxPacket;
-
-
-    pMgmt->wCurrCapInfo = 0;
-    pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
-    if (pDevice->bEncryptionEnable) {
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
-    }
-    // always allow receive short preamble
-    //if (pDevice->byPreambleType == 1) {
-    //    pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
-    //}
-    pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
-    if (pMgmt->wListenInterval == 0)
-        pMgmt->wListenInterval = 1;    // at least one.
-
-    // ERP Phy (802.11g) should support short preamble.
-    if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
-        if (CARDbIsShorSlotTime(pMgmt->pAdapter) == true) {
-            pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
-        }
-    } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
-        if (CARDbIsShortPreamble(pMgmt->pAdapter) == true) {
-            pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
-        }
-    }
-    if (pMgmt->b11hEnable == true)
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
-
-    /* build an assocreq frame and send it */
-    pTxPacket = s_MgrMakeAssocRequest
-                (
-                  pDevice,
-                  pMgmt,
-                  pMgmt->abyCurrBSSID,
-                  pMgmt->wCurrCapInfo,
-                  pMgmt->wListenInterval,
-                  (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
-                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
-                );
-
-    if (pTxPacket != NULL ){
-        /* send the frame */
-        *pStatus = csMgmt_xmit(pDevice, pTxPacket);
-        if (*pStatus == CMD_STATUS_PENDING) {
-            pMgmt->eCurrState = WMAC_STATE_ASSOCPENDING;
-            *pStatus = CMD_STATUS_SUCCESS;
-        }
-    }
-    else
-        *pStatus = CMD_STATUS_RESOURCES;
-
-    return ;
-}
+       PSDevice             pDevice = (PSDevice)hDeviceContext;
+       PSTxMgmtPacket          pTxPacket;
+
+       pMgmt->wCurrCapInfo = 0;
+       pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
+       if (pDevice->bEncryptionEnable) {
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
+       }
+       pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
+       if (pMgmt->wListenInterval == 0)
+               pMgmt->wListenInterval = 1;    // at least one.
+
+       // ERP Phy (802.11g) should support short preamble.
+       if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
+               if (CARDbIsShorSlotTime(pMgmt->pAdapter) == true) {
+                       pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
+               }
+       } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
+               if (CARDbIsShortPreamble(pMgmt->pAdapter) == true) {
+                       pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
+               }
+       }
+       if (pMgmt->b11hEnable == true)
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
+
+       /* build an assocreq frame and send it */
+       pTxPacket = s_MgrMakeAssocRequest
+               (
+                       pDevice,
+                       pMgmt,
+                       pMgmt->abyCurrBSSID,
+                       pMgmt->wCurrCapInfo,
+                       pMgmt->wListenInterval,
+                       (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
+                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
+);
+
+       if (pTxPacket != NULL) {
+               /* send the frame */
+               *pStatus = csMgmt_xmit(pDevice, pTxPacket);
+               if (*pStatus == CMD_STATUS_PENDING) {
+                       pMgmt->eCurrState = WMAC_STATE_ASSOCPENDING;
+                       *pStatus = CMD_STATUS_SUCCESS;
+               }
+       } else
+               *pStatus = CMD_STATUS_RESOURCES;
 
+       return;
+}
 
 /*+
  *
@@ -535,75 +513,66 @@ vMgrAssocBeginSta(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrReAssocBeginSta(
-    void *hDeviceContext,
-    PSMgmtObject pMgmt,
-    PCMD_STATUS pStatus
-    )
+       void *hDeviceContext,
+       PSMgmtObject pMgmt,
+       PCMD_STATUS pStatus
+)
 {
-    PSDevice             pDevice = (PSDevice)hDeviceContext;
-    PSTxMgmtPacket          pTxPacket;
-
-
-
-    pMgmt->wCurrCapInfo = 0;
-    pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
-    if (pDevice->bEncryptionEnable) {
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
-    }
-
-    //if (pDevice->byPreambleType == 1) {
-    //    pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
-    //}
-    pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
-
-    if (pMgmt->wListenInterval == 0)
-        pMgmt->wListenInterval = 1;    // at least one.
-
-
-    // ERP Phy (802.11g) should support short preamble.
-    if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
-        if (CARDbIsShorSlotTime(pMgmt->pAdapter) == true) {
-            pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
-        }
-    } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
-        if (CARDbIsShortPreamble(pMgmt->pAdapter) == true) {
-            pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
-        }
-    }
-    if (pMgmt->b11hEnable == true)
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
-
-
-    pTxPacket = s_MgrMakeReAssocRequest
-                (
-                  pDevice,
-                  pMgmt,
-                  pMgmt->abyCurrBSSID,
-                  pMgmt->wCurrCapInfo,
-                  pMgmt->wListenInterval,
-                  (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
-                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
-                );
-
-    if (pTxPacket != NULL ){
-        /* send the frame */
-        *pStatus = csMgmt_xmit(pDevice, pTxPacket);
-        if (*pStatus != CMD_STATUS_PENDING) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx failed.\n");
-        }
-        else {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx sending.\n");
-        }
-    }
-
-
-    return ;
+       PSDevice             pDevice = (PSDevice)hDeviceContext;
+       PSTxMgmtPacket          pTxPacket;
+
+       pMgmt->wCurrCapInfo = 0;
+       pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
+       if (pDevice->bEncryptionEnable) {
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
+       }
+
+       pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
+
+       if (pMgmt->wListenInterval == 0)
+               pMgmt->wListenInterval = 1;    // at least one.
+
+       // ERP Phy (802.11g) should support short preamble.
+       if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
+               if (CARDbIsShorSlotTime(pMgmt->pAdapter) == true) {
+                       pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
+               }
+       } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
+               if (CARDbIsShortPreamble(pMgmt->pAdapter) == true) {
+                       pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
+               }
+       }
+       if (pMgmt->b11hEnable == true)
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
+
+       pTxPacket = s_MgrMakeReAssocRequest
+               (
+                       pDevice,
+                       pMgmt,
+                       pMgmt->abyCurrBSSID,
+                       pMgmt->wCurrCapInfo,
+                       pMgmt->wListenInterval,
+                       (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
+                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
+);
+
+       if (pTxPacket != NULL) {
+               /* send the frame */
+               *pStatus = csMgmt_xmit(pDevice, pTxPacket);
+               if (*pStatus != CMD_STATUS_PENDING) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx failed.\n");
+               } else {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx sending.\n");
+               }
+       }
+
+       return;
 }
 
 /*+
@@ -614,59 +583,57 @@ vMgrReAssocBeginSta(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrDisassocBeginSta(
-    void *hDeviceContext,
-    PSMgmtObject pMgmt,
-    unsigned char *abyDestAddress,
-    unsigned short wReason,
-    PCMD_STATUS pStatus
-    )
+       void *hDeviceContext,
+       PSMgmtObject pMgmt,
+       unsigned char *abyDestAddress,
+       unsigned short wReason,
+       PCMD_STATUS pStatus
+)
 {
-    PSDevice            pDevice = (PSDevice)hDeviceContext;
-    PSTxMgmtPacket      pTxPacket = NULL;
-    WLAN_FR_DISASSOC    sFrame;
-
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DISASSOC_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-
-    // Setup the sFrame structure
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_DISASSOC_FR_MAXLEN;
-
-    // format fixed field frame structure
-    vMgrEncodeDisassociation(&sFrame);
-
-    // Setup the header
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-        (
-        WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-        WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DISASSOC)
-        ));
-
-    memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-
-    // Set reason code
-    *(sFrame.pwReason) = cpu_to_le16(wReason);
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-
-    // send the frame
-    *pStatus = csMgmt_xmit(pDevice, pTxPacket);
-    if (*pStatus == CMD_STATUS_PENDING) {
-        pMgmt->eCurrState = WMAC_STATE_IDLE;
-        *pStatus = CMD_STATUS_SUCCESS;
-    }
-
-    return;
-}
-
+       PSDevice            pDevice = (PSDevice)hDeviceContext;
+       PSTxMgmtPacket      pTxPacket = NULL;
+       WLAN_FR_DISASSOC    sFrame;
+
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DISASSOC_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+
+       // Setup the sFrame structure
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_DISASSOC_FR_MAXLEN;
+
+       // format fixed field frame structure
+       vMgrEncodeDisassociation(&sFrame);
+
+       // Setup the header
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DISASSOC)
+));
+
+       memcpy(sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+
+       // Set reason code
+       *(sFrame.pwReason) = cpu_to_le16(wReason);
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
+
+       // send the frame
+       *pStatus = csMgmt_xmit(pDevice, pTxPacket);
+       if (*pStatus == CMD_STATUS_PENDING) {
+               pMgmt->eCurrState = WMAC_STATE_IDLE;
+               *pStatus = CMD_STATUS_SUCCESS;
+       }
 
+       return;
+}
 
 /*+
  *
@@ -676,153 +643,147 @@ vMgrDisassocBeginSta(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 static
 void
 s_vMgrRxAssocRequest(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket,
-    unsigned int uNodeIndex
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket,
+       unsigned int uNodeIndex
+)
 {
-    WLAN_FR_ASSOCREQ    sFrame;
-    CMD_STATUS          Status;
-    PSTxMgmtPacket      pTxPacket;
-    unsigned short wAssocStatus = 0;
-    unsigned short wAssocAID = 0;
-    unsigned int uRateLen = WLAN_RATES_MAXLEN;
-    unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
-    unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
-
-
-    if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
-        return;
-    //  node index not found
-    if (!uNodeIndex)
-        return;
-
-    //check if node is authenticated
-    //decode the frame
-    memset(&sFrame, 0, sizeof(WLAN_FR_ASSOCREQ));
-    memset(abyCurrSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
-    memset(abyCurrExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
-    sFrame.len = pRxPacket->cbMPDULen;
-    sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
-
-    vMgrDecodeAssocRequest(&sFrame);
-
-    if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
-        pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
-        pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
-        pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
-        pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
-                WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
-        // Todo: check sta basic rate, if ap can't support, set status code
-        if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
-            uRateLen = WLAN_RATES_MAXLEN_11B;
-        }
-        abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
-        abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
-                                         (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
-                                         uRateLen);
-        abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
-        if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
-            abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
-                                                (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
-                                                uRateLen);
-        } else {
-            abyCurrExtSuppRates[1] = 0;
-        }
-
-
-        RATEvParseMaxRate((void *)pDevice,
-                           (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
-                           (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
-                           false, // do not change our basic rate
-                           &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
-                           &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
-                           &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
-                           &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
-                           &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
-                          );
-
-        // set max tx rate
-        pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
-                pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
+       WLAN_FR_ASSOCREQ    sFrame;
+       CMD_STATUS          Status;
+       PSTxMgmtPacket      pTxPacket;
+       unsigned short wAssocStatus = 0;
+       unsigned short wAssocAID = 0;
+       unsigned int uRateLen = WLAN_RATES_MAXLEN;
+       unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
+       unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
+
+       if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
+               return;
+       //  node index not found
+       if (!uNodeIndex)
+               return;
+
+       //check if node is authenticated
+       //decode the frame
+       memset(&sFrame, 0, sizeof(WLAN_FR_ASSOCREQ));
+       memset(abyCurrSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
+       memset(abyCurrExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
+       sFrame.len = pRxPacket->cbMPDULen;
+       sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
+
+       vMgrDecodeAssocRequest(&sFrame);
+
+       if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
+               pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
+               pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
+               pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
+               pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
+                       WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
+               // Todo: check sta basic rate, if ap can't support, set status code
+               if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
+                       uRateLen = WLAN_RATES_MAXLEN_11B;
+               }
+               abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
+               abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
+                                                (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
+                                                uRateLen);
+               abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
+               if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
+                       abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
+                                                           (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
+                                                           uRateLen);
+               } else {
+                       abyCurrExtSuppRates[1] = 0;
+               }
+
+               RATEvParseMaxRate((void *)pDevice,
+                                 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
+                                 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
+                                 false, // do not change our basic rate
+                                 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
+                                 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
+                                 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
+                                 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
+                                 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
+);
+
+               // set max tx rate
+               pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
+                       pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
 #ifdef PLICE_DEBUG
-       printk("RxAssocRequest:wTxDataRate is %d\n",pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
+               printk("RxAssocRequest:wTxDataRate is %d\n", pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
 #endif
                // Todo: check sta preamble, if ap can't support, set status code
-        pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
-                WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
-        pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
-                WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
-        pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)uNodeIndex;
-        wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
-        wAssocAID = (unsigned short)uNodeIndex;
-        // check if ERP support
-        if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
-           pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
-
-        if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
-            // B only STA join
-            pDevice->bProtectMode = true;
-            pDevice->bNonERPPresent = true;
-        }
-        if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
-            pDevice->bBarkerPreambleMd = true;
-        }
-
-        DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Associate AID= %d \n", wAssocAID);
-        DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
-                   sFrame.pHdr->sA3.abyAddr2[0],
-                   sFrame.pHdr->sA3.abyAddr2[1],
-                   sFrame.pHdr->sA3.abyAddr2[2],
-                   sFrame.pHdr->sA3.abyAddr2[3],
-                   sFrame.pHdr->sA3.abyAddr2[4],
-                   sFrame.pHdr->sA3.abyAddr2[5]
-                  ) ;
-        DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
-                   pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
-    }//else { TODO: received STA under state1 handle }
-    else {
-        return;
-    }
-
-
-    // assoc response reply..
-    pTxPacket = s_MgrMakeAssocResponse
-                (
-                  pDevice,
-                  pMgmt,
-                  pMgmt->wCurrCapInfo,
-                  wAssocStatus,
-                  wAssocAID,
-                  sFrame.pHdr->sA3.abyAddr2,
-                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
-                );
-    if (pTxPacket != NULL ){
-
-        if (pDevice->bEnableHostapd) {
-            return;
-        }
-        /* send the frame */
-        Status = csMgmt_xmit(pDevice, pTxPacket);
-        if (Status != CMD_STATUS_PENDING) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx failed\n");
-        }
-        else {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx sending..\n");
-        }
-
-    }
-
-    return;
-}
+               pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
+                       WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
+               pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
+                       WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
+               pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)uNodeIndex;
+               wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
+               wAssocAID = (unsigned short)uNodeIndex;
+               // check if ERP support
+               if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
+                       pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
+
+               if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
+                       // B only STA join
+                       pDevice->bProtectMode = true;
+                       pDevice->bNonERPPresent = true;
+               }
+               if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
+                       pDevice->bBarkerPreambleMd = true;
+               }
+
+               DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Associate AID= %d \n", wAssocAID);
+               DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
+                       sFrame.pHdr->sA3.abyAddr2[0],
+                       sFrame.pHdr->sA3.abyAddr2[1],
+                       sFrame.pHdr->sA3.abyAddr2[2],
+                       sFrame.pHdr->sA3.abyAddr2[3],
+                       sFrame.pHdr->sA3.abyAddr2[4],
+                       sFrame.pHdr->sA3.abyAddr2[5]
+                       );
+               DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
+                       pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
+       }//else { TODO: received STA under state1 handle }
+       else {
+               return;
+       }
+
+       // assoc response reply..
+       pTxPacket = s_MgrMakeAssocResponse
+               (
+                       pDevice,
+                       pMgmt,
+                       pMgmt->wCurrCapInfo,
+                       wAssocStatus,
+                       wAssocAID,
+                       sFrame.pHdr->sA3.abyAddr2,
+                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
+);
+       if (pTxPacket != NULL) {
+               if (pDevice->bEnableHostapd) {
+                       return;
+               }
+               /* send the frame */
+               Status = csMgmt_xmit(pDevice, pTxPacket);
+               if (Status != CMD_STATUS_PENDING) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx failed\n");
+               } else {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx sending..\n");
+               }
 
+       }
+
+       return;
+}
 
 /*+
  *
@@ -838,147 +799,143 @@ s_vMgrRxAssocRequest(
  *
  * Return Value: None.
  *
--*/
+ -*/
 
 static
 void
 s_vMgrRxReAssocRequest(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket,
-    unsigned int uNodeIndex
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket,
+       unsigned int uNodeIndex
+)
 {
-    WLAN_FR_REASSOCREQ    sFrame;
-    CMD_STATUS          Status;
-    PSTxMgmtPacket      pTxPacket;
-    unsigned short wAssocStatus = 0;
-    unsigned short wAssocAID = 0;
-    unsigned int       uRateLen = WLAN_RATES_MAXLEN;
-    unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
-    unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
-
-    if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
-        return;
-    //  node index not found
-    if (!uNodeIndex)
-        return;
-    //check if node is authenticated
-    //decode the frame
-    memset(&sFrame, 0, sizeof(WLAN_FR_REASSOCREQ));
-    sFrame.len = pRxPacket->cbMPDULen;
-    sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
-    vMgrDecodeReassocRequest(&sFrame);
-
-    if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
-        pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
-        pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
-        pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
-        pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
-                WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
-        // Todo: check sta basic rate, if ap can't support, set status code
-
-        if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
-            uRateLen = WLAN_RATES_MAXLEN_11B;
-        }
-
-        abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
-        abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
-                                         (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
-                                         uRateLen);
-        abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
-        if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
-            abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
-                                                (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
-                                                uRateLen);
-        } else {
-            abyCurrExtSuppRates[1] = 0;
-        }
-
-
-        RATEvParseMaxRate((void *)pDevice,
-                          (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
-                          (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
-                           false, // do not change our basic rate
-                           &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
-                           &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
-                           &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
-                           &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
-                           &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
-                          );
-
-        // set max tx rate
-        pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
-                pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
+       WLAN_FR_REASSOCREQ    sFrame;
+       CMD_STATUS          Status;
+       PSTxMgmtPacket      pTxPacket;
+       unsigned short wAssocStatus = 0;
+       unsigned short wAssocAID = 0;
+       unsigned int    uRateLen = WLAN_RATES_MAXLEN;
+       unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
+       unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
+
+       if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
+               return;
+       //  node index not found
+       if (!uNodeIndex)
+               return;
+       //check if node is authenticated
+       //decode the frame
+       memset(&sFrame, 0, sizeof(WLAN_FR_REASSOCREQ));
+       sFrame.len = pRxPacket->cbMPDULen;
+       sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
+       vMgrDecodeReassocRequest(&sFrame);
+
+       if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
+               pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
+               pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
+               pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
+               pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
+                       WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
+               // Todo: check sta basic rate, if ap can't support, set status code
+
+               if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
+                       uRateLen = WLAN_RATES_MAXLEN_11B;
+               }
+
+               abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
+               abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
+                                                (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
+                                                uRateLen);
+               abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
+               if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
+                       abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
+                                                           (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
+                                                           uRateLen);
+               } else {
+                       abyCurrExtSuppRates[1] = 0;
+               }
+
+               RATEvParseMaxRate((void *)pDevice,
+                                 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
+                                 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
+                                 false, // do not change our basic rate
+                                 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
+                                 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
+                                 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
+                                 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
+                                 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
+);
+
+               // set max tx rate
+               pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
+                       pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
 #ifdef PLICE_DEBUG
-       printk("RxReAssocRequest:TxDataRate is %d\n",pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
+               printk("RxReAssocRequest:TxDataRate is %d\n", pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
 #endif
                // Todo: check sta preamble, if ap can't support, set status code
-        pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
-                WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
-        pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
-                WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
-        pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)uNodeIndex;
-        wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
-        wAssocAID = (unsigned short)uNodeIndex;
-
-        // if suppurt ERP
-        if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
-           pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
-
-        if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
-            // B only STA join
-            pDevice->bProtectMode = true;
-            pDevice->bNonERPPresent = true;
-        }
-        if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
-            pDevice->bBarkerPreambleMd = true;
-        }
-
-        DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Rx ReAssociate AID= %d \n", wAssocAID);
-        DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
-                   sFrame.pHdr->sA3.abyAddr2[0],
-                   sFrame.pHdr->sA3.abyAddr2[1],
-                   sFrame.pHdr->sA3.abyAddr2[2],
-                   sFrame.pHdr->sA3.abyAddr2[3],
-                   sFrame.pHdr->sA3.abyAddr2[4],
-                   sFrame.pHdr->sA3.abyAddr2[5]
-                  ) ;
-        DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
-                   pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
-
-    }
-
-
-    // assoc response reply..
-    pTxPacket = s_MgrMakeReAssocResponse
-                (
-                  pDevice,
-                  pMgmt,
-                  pMgmt->wCurrCapInfo,
-                  wAssocStatus,
-                  wAssocAID,
-                  sFrame.pHdr->sA3.abyAddr2,
-                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
-                );
-
-    if (pTxPacket != NULL ){
-        /* send the frame */
-        if (pDevice->bEnableHostapd) {
-            return;
-        }
-        Status = csMgmt_xmit(pDevice, pTxPacket);
-        if (Status != CMD_STATUS_PENDING) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx failed\n");
-        }
-        else {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx sending..\n");
-        }
-    }
-    return;
-}
+               pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
+                       WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
+               pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
+                       WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
+               pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)uNodeIndex;
+               wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
+               wAssocAID = (unsigned short)uNodeIndex;
+
+               // if suppurt ERP
+               if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
+                       pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
+
+               if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
+                       // B only STA join
+                       pDevice->bProtectMode = true;
+                       pDevice->bNonERPPresent = true;
+               }
+               if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
+                       pDevice->bBarkerPreambleMd = true;
+               }
+
+               DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Rx ReAssociate AID= %d \n", wAssocAID);
+               DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
+                       sFrame.pHdr->sA3.abyAddr2[0],
+                       sFrame.pHdr->sA3.abyAddr2[1],
+                       sFrame.pHdr->sA3.abyAddr2[2],
+                       sFrame.pHdr->sA3.abyAddr2[3],
+                       sFrame.pHdr->sA3.abyAddr2[4],
+                       sFrame.pHdr->sA3.abyAddr2[5]
+                       );
+               DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
+                       pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
 
+       }
+
+       // assoc response reply..
+       pTxPacket = s_MgrMakeReAssocResponse
+               (
+                       pDevice,
+                       pMgmt,
+                       pMgmt->wCurrCapInfo,
+                       wAssocStatus,
+                       wAssocAID,
+                       sFrame.pHdr->sA3.abyAddr2,
+                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
+                       );
+
+       if (pTxPacket != NULL) {
+               /* send the frame */
+               if (pDevice->bEnableHostapd) {
+                       return;
+               }
+               Status = csMgmt_xmit(pDevice, pTxPacket);
+               if (Status != CMD_STATUS_PENDING) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx failed\n");
+               } else {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx sending..\n");
+               }
+       }
+       return;
+}
 
 /*+
  *
@@ -988,158 +945,147 @@ s_vMgrRxReAssocRequest(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 static
 void
 s_vMgrRxAssocResponse(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket,
-    bool bReAssocType
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket,
+       bool bReAssocType
+)
 {
-    WLAN_FR_ASSOCRESP   sFrame;
-    PWLAN_IE_SSID   pItemSSID;
-    unsigned char *pbyIEs;
-    viawget_wpa_header *wpahdr;
-
-
-
-    if (pMgmt->eCurrState == WMAC_STATE_ASSOCPENDING ||
-         pMgmt->eCurrState == WMAC_STATE_ASSOC) {
-
-        sFrame.len = pRxPacket->cbMPDULen;
-        sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
-        // decode the frame
-        vMgrDecodeAssocResponse(&sFrame);
-        if ((sFrame.pwCapInfo == 0) ||
-            (sFrame.pwStatus == 0) ||
-            (sFrame.pwAid == 0) ||
-            (sFrame.pSuppRates == 0)){
-            DBG_PORT80(0xCC);
-            return;
-        }
-
-        pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.Capabilities = *(sFrame.pwCapInfo);
-        pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.StatusCode = *(sFrame.pwStatus);
-        pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.AssociationId = *(sFrame.pwAid);
-        pMgmt->sAssocInfo.AssocInfo.AvailableResponseFixedIEs |= 0x07;
-
-        pMgmt->sAssocInfo.AssocInfo.ResponseIELength = sFrame.len - 24 - 6;
-        pMgmt->sAssocInfo.AssocInfo.OffsetResponseIEs = pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs + pMgmt->sAssocInfo.AssocInfo.RequestIELength;
-        pbyIEs = pMgmt->sAssocInfo.abyIEs;
-        pbyIEs += pMgmt->sAssocInfo.AssocInfo.RequestIELength;
-        memcpy(pbyIEs, (sFrame.pBuf + 24 +6), pMgmt->sAssocInfo.AssocInfo.ResponseIELength);
-
-        // save values and set current BSS state
-        if (cpu_to_le16((*(sFrame.pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
-            // set AID
-            pMgmt->wCurrAID = cpu_to_le16((*(sFrame.pwAid)));
-            if ( (pMgmt->wCurrAID >> 14) != (BIT0 | BIT1) )
-            {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AID from AP, has two msb clear.\n");
-            }
-            DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Association Successful, AID=%d.\n", pMgmt->wCurrAID & ~(BIT14|BIT15));
-            pMgmt->eCurrState = WMAC_STATE_ASSOC;
-            BSSvUpdateAPNode((void *)pDevice, sFrame.pwCapInfo, sFrame.pSuppRates, sFrame.pExtSuppRates);
-            pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
-            DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Link with AP(SSID): %s\n", pItemSSID->abySSID);
-            pDevice->bLinkPass = true;
-            pDevice->uBBVGADiffCount = 0;
-            if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
-         if(skb_tailroom(pDevice->skb) <(sizeof(viawget_wpa_header)+pMgmt->sAssocInfo.AssocInfo.ResponseIELength+
-                                                                        pMgmt->sAssocInfo.AssocInfo.RequestIELength)) {    //data room not enough
-                     dev_kfree_skb(pDevice->skb);
-                  pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-               }
-                wpahdr = (viawget_wpa_header *)pDevice->skb->data;
-                wpahdr->type = VIAWGET_ASSOC_MSG;
-                wpahdr->resp_ie_len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
-                wpahdr->req_ie_len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
-                memcpy(pDevice->skb->data + sizeof(viawget_wpa_header), pMgmt->sAssocInfo.abyIEs, wpahdr->req_ie_len);
-                memcpy(pDevice->skb->data + sizeof(viawget_wpa_header) + wpahdr->req_ie_len,
-                       pbyIEs,
-                       wpahdr->resp_ie_len
-                       );
-                skb_put(pDevice->skb, sizeof(viawget_wpa_header) + wpahdr->resp_ie_len + wpahdr->req_ie_len);
-                pDevice->skb->dev = pDevice->wpadev;
-               skb_reset_mac_header(pDevice->skb);
-                pDevice->skb->pkt_type = PACKET_HOST;
-                pDevice->skb->protocol = htons(ETH_P_802_2);
-                memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
-                netif_rx(pDevice->skb);
-                pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-            }
-
-//2008-0409-07, <Add> by Einsn Liu
-#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-       //if(pDevice->bWPADevEnable == true)
-               {
-               unsigned char buf[512];
-               size_t len;
-               union iwreq_data  wrqu;
-               int we_event;
-
-               memset(buf, 0, 512);
-
-               len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
-               if(len) {
-                       memcpy(buf, pMgmt->sAssocInfo.abyIEs, len);
-                       memset(&wrqu, 0, sizeof (wrqu));
-                       wrqu.data.length = len;
-                       we_event = IWEVASSOCREQIE;
-                       wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
-               }
-
-               memset(buf, 0, 512);
-               len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
-
-               if(len) {
-                       memcpy(buf, pbyIEs, len);
-                       memset(&wrqu, 0, sizeof (wrqu));
-                       wrqu.data.length = len;
-                       we_event = IWEVASSOCRESPIE;
-                       wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
+       WLAN_FR_ASSOCRESP   sFrame;
+       PWLAN_IE_SSID   pItemSSID;
+       unsigned char *pbyIEs;
+       viawget_wpa_header *wpahdr;
+
+       if (pMgmt->eCurrState == WMAC_STATE_ASSOCPENDING ||
+           pMgmt->eCurrState == WMAC_STATE_ASSOC) {
+               sFrame.len = pRxPacket->cbMPDULen;
+               sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
+               // decode the frame
+               vMgrDecodeAssocResponse(&sFrame);
+               if ((sFrame.pwCapInfo == 0) ||
+                   (sFrame.pwStatus == 0) ||
+                   (sFrame.pwAid == 0) ||
+                   (sFrame.pSuppRates == 0)) {
+                       DBG_PORT80(0xCC);
+                       return;
                }
 
+               pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.Capabilities = *(sFrame.pwCapInfo);
+               pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.StatusCode = *(sFrame.pwStatus);
+               pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.AssociationId = *(sFrame.pwAid);
+               pMgmt->sAssocInfo.AssocInfo.AvailableResponseFixedIEs |= 0x07;
+
+               pMgmt->sAssocInfo.AssocInfo.ResponseIELength = sFrame.len - 24 - 6;
+               pMgmt->sAssocInfo.AssocInfo.OffsetResponseIEs = pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs + pMgmt->sAssocInfo.AssocInfo.RequestIELength;
+               pbyIEs = pMgmt->sAssocInfo.abyIEs;
+               pbyIEs += pMgmt->sAssocInfo.AssocInfo.RequestIELength;
+               memcpy(pbyIEs, (sFrame.pBuf + 24 + 6), pMgmt->sAssocInfo.AssocInfo.ResponseIELength);
+
+               // save values and set current BSS state
+               if (cpu_to_le16((*(sFrame.pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
+                       // set AID
+                       pMgmt->wCurrAID = cpu_to_le16((*(sFrame.pwAid)));
+                       if ((pMgmt->wCurrAID >> 14) != (BIT0 | BIT1)) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AID from AP, has two msb clear.\n");
+                       }
+                       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Association Successful, AID=%d.\n", pMgmt->wCurrAID & ~(BIT14 | BIT15));
+                       pMgmt->eCurrState = WMAC_STATE_ASSOC;
+                       BSSvUpdateAPNode((void *)pDevice, sFrame.pwCapInfo, sFrame.pSuppRates, sFrame.pExtSuppRates);
+                       pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
+                       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Link with AP(SSID): %s\n", pItemSSID->abySSID);
+                       pDevice->bLinkPass = true;
+                       pDevice->uBBVGADiffCount = 0;
+                       if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
+                               if (skb_tailroom(pDevice->skb) < (sizeof(viawget_wpa_header) + pMgmt->sAssocInfo.AssocInfo.ResponseIELength +
+                                                                 pMgmt->sAssocInfo.AssocInfo.RequestIELength)) {    //data room not enough
+                                       dev_kfree_skb(pDevice->skb);
+                                       pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
+                               }
+                               wpahdr = (viawget_wpa_header *)pDevice->skb->data;
+                               wpahdr->type = VIAWGET_ASSOC_MSG;
+                               wpahdr->resp_ie_len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
+                               wpahdr->req_ie_len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
+                               memcpy(pDevice->skb->data + sizeof(viawget_wpa_header), pMgmt->sAssocInfo.abyIEs, wpahdr->req_ie_len);
+                               memcpy(pDevice->skb->data + sizeof(viawget_wpa_header) + wpahdr->req_ie_len,
+                                      pbyIEs,
+                                      wpahdr->resp_ie_len
+);
+                               skb_put(pDevice->skb, sizeof(viawget_wpa_header) + wpahdr->resp_ie_len + wpahdr->req_ie_len);
+                               pDevice->skb->dev = pDevice->wpadev;
+                               skb_reset_mac_header(pDevice->skb);
+                               pDevice->skb->pkt_type = PACKET_HOST;
+                               pDevice->skb->protocol = htons(ETH_P_802_2);
+                               memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
+                               netif_rx(pDevice->skb);
+                               pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
+                       }
 
-  memset(&wrqu, 0, sizeof (wrqu));
-       memcpy(wrqu.ap_addr.sa_data, &pMgmt->abyCurrBSSID[0], ETH_ALEN);
-        wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-       wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
-       }
+//2008-0409-07, <Add> by Einsn Liu
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+                       {
+                               unsigned char buf[512];
+                               size_t len;
+                               union iwreq_data  wrqu;
+                               int we_event;
+
+                               memset(buf, 0, 512);
+
+                               len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
+                               if (len)        {
+                                       memcpy(buf, pMgmt->sAssocInfo.abyIEs, len);
+                                       memset(&wrqu, 0, sizeof(wrqu));
+                                       wrqu.data.length = len;
+                                       we_event = IWEVASSOCREQIE;
+                                       wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
+                               }
+
+                               memset(buf, 0, 512);
+                               len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
+
+                               if (len)        {
+                                       memcpy(buf, pbyIEs, len);
+                                       memset(&wrqu, 0, sizeof(wrqu));
+                                       wrqu.data.length = len;
+                                       we_event = IWEVASSOCRESPIE;
+                                       wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
+                               }
+
+                               memset(&wrqu, 0, sizeof(wrqu));
+                               memcpy(wrqu.ap_addr.sa_data, &pMgmt->abyCurrBSSID[0], ETH_ALEN);
+                               wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+                               wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
+                       }
 #endif //#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
 //End Add -- //2008-0409-07, <Add> by Einsn Liu
+               } else {
+                       if (bReAssocType) {
+                               pMgmt->eCurrState = WMAC_STATE_IDLE;
+                       } else {
+                               // jump back to the auth state and indicate the error
+                               pMgmt->eCurrState = WMAC_STATE_AUTH;
+                       }
+                       s_vMgrLogStatus(pMgmt, cpu_to_le16((*(sFrame.pwStatus))));
                }
-        else {
-            if (bReAssocType) {
-                pMgmt->eCurrState = WMAC_STATE_IDLE;
-            }
-            else {
-                // jump back to the auth state and indicate the error
-                pMgmt->eCurrState = WMAC_STATE_AUTH;
-            }
-            s_vMgrLogStatus(pMgmt,cpu_to_le16((*(sFrame.pwStatus))));
-        }
-
-    }
+
+       }
 
 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
 //need clear flags related to Networkmanager
 
-              pDevice->bwextcount = 0;
-              pDevice->bWPASuppWextEnabled = false;
+       pDevice->bwextcount = 0;
+       pDevice->bWPASuppWextEnabled = false;
 #endif
 
-
-if(pMgmt->eCurrState == WMAC_STATE_ASSOC)
-      timer_expire(pDevice->sTimerCommand, 0);
-    return;
+       if (pMgmt->eCurrState == WMAC_STATE_ASSOC)
+               timer_expire(pDevice->sTimerCommand, 0);
+       return;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -1149,54 +1095,52 @@ if(pMgmt->eCurrState == WMAC_STATE_ASSOC)
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrAuthenBeginSta(
-    void *hDeviceContext,
-    PSMgmtObject  pMgmt,
-    PCMD_STATUS pStatus
-    )
+       void *hDeviceContext,
+       PSMgmtObject  pMgmt,
+       PCMD_STATUS pStatus
+)
 {
-    PSDevice     pDevice = (PSDevice)hDeviceContext;
-    WLAN_FR_AUTHEN  sFrame;
-    PSTxMgmtPacket  pTxPacket = NULL;
-
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
-    vMgrEncodeAuthen(&sFrame);
-    /* insert values */
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-        (
-        WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-        WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)
-        ));
-    memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-    if (pMgmt->bShareKeyAlgorithm)
-        *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_SHAREDKEY);
-    else
-        *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_OPENSYSTEM);
-
-    *(sFrame.pwAuthSequence) = cpu_to_le16(1);
-    /* Adjust the length fields */
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-
-    *pStatus = csMgmt_xmit(pDevice, pTxPacket);
-    if (*pStatus == CMD_STATUS_PENDING){
-        pMgmt->eCurrState = WMAC_STATE_AUTHPENDING;
-        *pStatus = CMD_STATUS_SUCCESS;
-    }
-
-    return ;
-}
-
+       PSDevice     pDevice = (PSDevice)hDeviceContext;
+       WLAN_FR_AUTHEN  sFrame;
+       PSTxMgmtPacket  pTxPacket = NULL;
+
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
+       vMgrEncodeAuthen(&sFrame);
+       /* insert values */
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)
+));
+       memcpy(sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+       if (pMgmt->bShareKeyAlgorithm)
+               *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_SHAREDKEY);
+       else
+               *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_OPENSYSTEM);
+
+       *(sFrame.pwAuthSequence) = cpu_to_le16(1);
+       /* Adjust the length fields */
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
+
+       *pStatus = csMgmt_xmit(pDevice, pTxPacket);
+       if (*pStatus == CMD_STATUS_PENDING) {
+               pMgmt->eCurrState = WMAC_STATE_AUTHPENDING;
+               *pStatus = CMD_STATUS_SUCCESS;
+       }
 
+       return;
+}
 
 /*+
  *
@@ -1207,53 +1151,50 @@ vMgrAuthenBeginSta(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrDeAuthenBeginSta(
-    void *hDeviceContext,
-    PSMgmtObject  pMgmt,
-    unsigned char *abyDestAddress,
-    unsigned short wReason,
-    PCMD_STATUS pStatus
-    )
+       void *hDeviceContext,
+       PSMgmtObject  pMgmt,
+       unsigned char *abyDestAddress,
+       unsigned short wReason,
+       PCMD_STATUS pStatus
+)
 {
-    PSDevice            pDevice = (PSDevice)hDeviceContext;
-    WLAN_FR_DEAUTHEN    sFrame;
-    PSTxMgmtPacket      pTxPacket = NULL;
-
-
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DEAUTHEN_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
-    vMgrEncodeDeauthen(&sFrame);
-    /* insert values */
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-        (
-        WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-        WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DEAUTHEN)
-        ));
-
-    memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-
-    *(sFrame.pwReason) = cpu_to_le16(wReason);       // deauthen. bcs left BSS
-    /* Adjust the length fields */
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-
-    *pStatus = csMgmt_xmit(pDevice, pTxPacket);
-    if (*pStatus == CMD_STATUS_PENDING){
-        *pStatus = CMD_STATUS_SUCCESS;
-    }
-
-
-    return ;
-}
+       PSDevice            pDevice = (PSDevice)hDeviceContext;
+       WLAN_FR_DEAUTHEN    sFrame;
+       PSTxMgmtPacket      pTxPacket = NULL;
+
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DEAUTHEN_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
+       vMgrEncodeDeauthen(&sFrame);
+       /* insert values */
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DEAUTHEN)
+));
+
+       memcpy(sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+
+       *(sFrame.pwReason) = cpu_to_le16(wReason);       // deauthen. bcs left BSS
+       /* Adjust the length fields */
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
+
+       *pStatus = csMgmt_xmit(pDevice, pTxPacket);
+       if (*pStatus == CMD_STATUS_PENDING) {
+               *pStatus = CMD_STATUS_SUCCESS;
+       }
 
+       return;
+}
 
 /*+
  *
@@ -1263,52 +1204,50 @@ vMgrDeAuthenBeginSta(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 static
 void
 s_vMgrRxAuthentication(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+)
 {
-    WLAN_FR_AUTHEN  sFrame;
-
-    // we better be an AP or a STA in AUTHPENDING otherwise ignore
-    if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP ||
-          pMgmt->eCurrState == WMAC_STATE_AUTHPENDING)) {
-        return;
-    }
-
-    // decode the frame
-    sFrame.len = pRxPacket->cbMPDULen;
-    sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
-    vMgrDecodeAuthen(&sFrame);
-    switch (cpu_to_le16((*(sFrame.pwAuthSequence )))){
-        case 1:
-            //AP function
-            s_vMgrRxAuthenSequence_1(pDevice,pMgmt, &sFrame);
-            break;
-        case 2:
-            s_vMgrRxAuthenSequence_2(pDevice, pMgmt, &sFrame);
-            break;
-        case 3:
-            //AP function
-            s_vMgrRxAuthenSequence_3(pDevice, pMgmt, &sFrame);
-            break;
-        case 4:
-            s_vMgrRxAuthenSequence_4(pDevice, pMgmt, &sFrame);
-            break;
-        default:
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Auth Sequence error, seq = %d\n",
-                        cpu_to_le16((*(sFrame.pwAuthSequence))));
-            break;
-    }
-    return;
-}
+       WLAN_FR_AUTHEN  sFrame;
 
+       // we better be an AP or a STA in AUTHPENDING otherwise ignore
+       if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP ||
+             pMgmt->eCurrState == WMAC_STATE_AUTHPENDING)) {
+               return;
+       }
 
+       // decode the frame
+       sFrame.len = pRxPacket->cbMPDULen;
+       sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
+       vMgrDecodeAuthen(&sFrame);
+       switch (cpu_to_le16((*(sFrame.pwAuthSequence)))) {
+       case 1:
+               //AP function
+               s_vMgrRxAuthenSequence_1(pDevice, pMgmt, &sFrame);
+               break;
+       case 2:
+               s_vMgrRxAuthenSequence_2(pDevice, pMgmt, &sFrame);
+               break;
+       case 3:
+               //AP function
+               s_vMgrRxAuthenSequence_3(pDevice, pMgmt, &sFrame);
+               break;
+       case 4:
+               s_vMgrRxAuthenSequence_4(pDevice, pMgmt, &sFrame);
+               break;
+       default:
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Auth Sequence error, seq = %d\n",
+                       cpu_to_le16((*(sFrame.pwAuthSequence))));
+               break;
+       }
+       return;
+}
 
 /*+
  *
@@ -1320,102 +1259,96 @@ s_vMgrRxAuthentication(
  * Return Value:
  *    None.
  *
--*/
-
+ -*/
 
 static
 void
 s_vMgrRxAuthenSequence_1(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PWLAN_FR_AUTHEN pFrame
-     )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PWLAN_FR_AUTHEN pFrame
+)
 {
-    PSTxMgmtPacket      pTxPacket = NULL;
-    unsigned int       uNodeIndex;
-    WLAN_FR_AUTHEN      sFrame;
-    PSKeyItem           pTransmitKey;
-
-    // Insert a Node entry
-    if (!BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
-        BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
-        memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, pFrame->pHdr->sA3.abyAddr2,
-               WLAN_ADDR_LEN);
-    }
-
-    if (pMgmt->bShareKeyAlgorithm) {
-        pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN;
-        pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 1;
-    }
-    else {
-        pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
-    }
-
-    // send auth reply
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
-    // format buffer structure
-    vMgrEncodeAuthen(&sFrame);
-    // insert values
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-         (
-         WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-         WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
-         WLAN_SET_FC_ISWEP(0)
-         ));
-    memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-    *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
-    *(sFrame.pwAuthSequence) = cpu_to_le16(2);
-
-    if (cpu_to_le16(*(pFrame->pwAuthAlgorithm)) == WLAN_AUTH_ALG_SHAREDKEY) {
-        if (pMgmt->bShareKeyAlgorithm)
-            *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
-        else
-            *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
-    }
-    else {
-        if (pMgmt->bShareKeyAlgorithm)
-            *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
-        else
-            *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
-    }
-
-    if (pMgmt->bShareKeyAlgorithm &&
-        (cpu_to_le16(*(sFrame.pwStatus)) == WLAN_MGMT_STATUS_SUCCESS)) {
-
-        sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
-        sFrame.len += WLAN_CHALLENGE_IE_LEN;
-        sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
-        sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
-        memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN);
-        // get group key
-        if(KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == true) {
-            rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3);
-            rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN);
-        }
-        memcpy(sFrame.pChallenge->abyChallenge, pMgmt->abyChallenge , WLAN_CHALLENGE_LEN);
-    }
-
-    /* Adjust the length fields */
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-    // send the frame
-    if (pDevice->bEnableHostapd) {
-        return;
-    }
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx.. \n");
-    if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx failed.\n");
-    }
-    return;
-}
+       PSTxMgmtPacket      pTxPacket = NULL;
+       unsigned int    uNodeIndex;
+       WLAN_FR_AUTHEN      sFrame;
+       PSKeyItem           pTransmitKey;
+
+       // Insert a Node entry
+       if (!BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
+               BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
+               memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, pFrame->pHdr->sA3.abyAddr2,
+                      WLAN_ADDR_LEN);
+       }
+
+       if (pMgmt->bShareKeyAlgorithm) {
+               pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN;
+               pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 1;
+       } else {
+               pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
+       }
 
+       // send auth reply
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
+       // format buffer structure
+       vMgrEncodeAuthen(&sFrame);
+       // insert values
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
+                       WLAN_SET_FC_ISWEP(0)
+));
+       memcpy(sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+       *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
+       *(sFrame.pwAuthSequence) = cpu_to_le16(2);
+
+       if (cpu_to_le16(*(pFrame->pwAuthAlgorithm)) == WLAN_AUTH_ALG_SHAREDKEY) {
+               if (pMgmt->bShareKeyAlgorithm)
+                       *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
+               else
+                       *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
+       } else {
+               if (pMgmt->bShareKeyAlgorithm)
+                       *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
+               else
+                       *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
+       }
+
+       if (pMgmt->bShareKeyAlgorithm &&
+           (cpu_to_le16(*(sFrame.pwStatus)) == WLAN_MGMT_STATUS_SUCCESS)) {
+               sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
+               sFrame.len += WLAN_CHALLENGE_IE_LEN;
+               sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
+               sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
+               memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN);
+               // get group key
+               if (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == true) {
+                       rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3);
+                       rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN);
+               }
+               memcpy(sFrame.pChallenge->abyChallenge, pMgmt->abyChallenge , WLAN_CHALLENGE_LEN);
+       }
 
+       /* Adjust the length fields */
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
+       // send the frame
+       if (pDevice->bEnableHostapd) {
+               return;
+       }
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx.. \n");
+       if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx failed.\n");
+       }
+       return;
+}
 
 /*+
  *
@@ -1427,97 +1360,91 @@ s_vMgrRxAuthenSequence_1(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 static
 void
 s_vMgrRxAuthenSequence_2(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PWLAN_FR_AUTHEN pFrame
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PWLAN_FR_AUTHEN pFrame
+)
 {
-    WLAN_FR_AUTHEN      sFrame;
-    PSTxMgmtPacket      pTxPacket = NULL;
-
-
-    switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm))))
-    {
-        case WLAN_AUTH_ALG_OPENSYSTEM:
-            if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
-                DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Successful.\n");
-                pMgmt->eCurrState = WMAC_STATE_AUTH;
-        timer_expire(pDevice->sTimerCommand, 0);
-            }
-            else {
-                DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Failed.\n");
-                s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
-                pMgmt->eCurrState = WMAC_STATE_IDLE;
-            }
-            if (pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
+       WLAN_FR_AUTHEN      sFrame;
+       PSTxMgmtPacket      pTxPacket = NULL;
+
+       switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm)))) {
+       case WLAN_AUTH_ALG_OPENSYSTEM:
+               if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
+                       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Successful.\n");
+                       pMgmt->eCurrState = WMAC_STATE_AUTH;
+                       timer_expire(pDevice->sTimerCommand, 0);
+               } else {
+                       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Failed.\n");
+                       s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
+                       pMgmt->eCurrState = WMAC_STATE_IDLE;
+               }
+               if (pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT) {
 //                spin_unlock_irq(&pDevice->lock);
 //                vCommandTimerWait((void *)pDevice, 0);
 //                spin_lock_irq(&pDevice->lock);
-            }
-
-            break;
-
-        case WLAN_AUTH_ALG_SHAREDKEY:
-
-            if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
-                pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-                memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
-                pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-                sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-                sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
-                // format buffer structure
-                vMgrEncodeAuthen(&sFrame);
-                // insert values
-                sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-                     (
-                     WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-                     WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
-                     WLAN_SET_FC_ISWEP(1)
-                     ));
-                memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-                memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-                memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-                *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
-                *(sFrame.pwAuthSequence) = cpu_to_le16(3);
-                *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
-                sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
-                sFrame.len += WLAN_CHALLENGE_IE_LEN;
-                sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
-                sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
-                memcpy( sFrame.pChallenge->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN);
-                // Adjust the length fields
-                pTxPacket->cbMPDULen = sFrame.len;
-                pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-                // send the frame
-                if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx failed.\n");
-                }
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx ...\n");
-            }
-            else {
-               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:rx Auth_reply sequence_2 status error ...\n");
-                if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
+               }
+
+               break;
+
+       case WLAN_AUTH_ALG_SHAREDKEY:
+
+               if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
+                       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+                       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
+                       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+                       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+                       sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
+                       // format buffer structure
+                       vMgrEncodeAuthen(&sFrame);
+                       // insert values
+                       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+                               (
+                                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
+                                       WLAN_SET_FC_ISWEP(1)
+));
+                       memcpy(sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+                       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+                       memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+                       *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
+                       *(sFrame.pwAuthSequence) = cpu_to_le16(3);
+                       *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
+                       sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
+                       sFrame.len += WLAN_CHALLENGE_IE_LEN;
+                       sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
+                       sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
+                       memcpy(sFrame.pChallenge->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN);
+                       // Adjust the length fields
+                       pTxPacket->cbMPDULen = sFrame.len;
+                       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
+                       // send the frame
+                       if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx failed.\n");
+                       }
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx ...\n");
+               } else {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:rx Auth_reply sequence_2 status error ...\n");
+                       if (pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT) {
 //                    spin_unlock_irq(&pDevice->lock);
 //                    vCommandTimerWait((void *)pDevice, 0);
 //                    spin_lock_irq(&pDevice->lock);
-                }
-                s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
-            }
-            break;
-        default:
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt: rx auth.seq = 2 unknown AuthAlgorithm=%d\n", cpu_to_le16((*(pFrame->pwAuthAlgorithm))));
-            break;
-    }
-    return;
+                       }
+                       s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
+               }
+               break;
+       default:
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt: rx auth.seq = 2 unknown AuthAlgorithm=%d\n", cpu_to_le16((*(pFrame->pwAuthAlgorithm))));
+               break;
+       }
+       return;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -1529,86 +1456,82 @@ s_vMgrRxAuthenSequence_2(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 static
 void
 s_vMgrRxAuthenSequence_3(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PWLAN_FR_AUTHEN pFrame
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PWLAN_FR_AUTHEN pFrame
+)
 {
-    PSTxMgmtPacket      pTxPacket = NULL;
-    unsigned int uStatusCode = 0 ;
-    unsigned int uNodeIndex = 0;
-    WLAN_FR_AUTHEN      sFrame;
-
-    if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) {
-        uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
-        goto reply;
-    }
-    if (BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
-         if (pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence != 1) {
-            uStatusCode = WLAN_MGMT_STATUS_RX_AUTH_NOSEQ;
-            goto reply;
-         }
-         if (memcmp(pMgmt->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN) != 0) {
-            uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
-            goto reply;
-         }
-    }
-    else {
-        uStatusCode = WLAN_MGMT_STATUS_UNSPEC_FAILURE;
-        goto reply;
-    }
-
-    if (uNodeIndex) {
-        pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
-        pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 0;
-    }
-    uStatusCode = WLAN_MGMT_STATUS_SUCCESS;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Challenge text check ok..\n");
+       PSTxMgmtPacket      pTxPacket = NULL;
+       unsigned int uStatusCode = 0;
+       unsigned int uNodeIndex = 0;
+       WLAN_FR_AUTHEN      sFrame;
+
+       if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) {
+               uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
+               goto reply;
+       }
+       if (BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
+               if (pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence != 1) {
+                       uStatusCode = WLAN_MGMT_STATUS_RX_AUTH_NOSEQ;
+                       goto reply;
+               }
+               if (memcmp(pMgmt->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN) != 0) {
+                       uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
+                       goto reply;
+               }
+       } else {
+               uStatusCode = WLAN_MGMT_STATUS_UNSPEC_FAILURE;
+               goto reply;
+       }
 
-reply:
-    // send auth reply
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
-    // format buffer structure
-    vMgrEncodeAuthen(&sFrame);
-    /* insert values */
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-         (
-         WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-         WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
-         WLAN_SET_FC_ISWEP(0)
-         ));
-    memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-    *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
-    *(sFrame.pwAuthSequence) = cpu_to_le16(4);
-    *(sFrame.pwStatus) = cpu_to_le16(uStatusCode);
-
-    /* Adjust the length fields */
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-    // send the frame
-    if (pDevice->bEnableHostapd) {
-        return;
-    }
-    if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_4 tx failed.\n");
-    }
-    return;
+       if (uNodeIndex) {
+               pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
+               pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 0;
+       }
+       uStatusCode = WLAN_MGMT_STATUS_SUCCESS;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Challenge text check ok..\n");
 
+reply:
+       // send auth reply
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
+       // format buffer structure
+       vMgrEncodeAuthen(&sFrame);
+       /* insert values */
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
+                       WLAN_SET_FC_ISWEP(0)
+));
+       memcpy(sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+       *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
+       *(sFrame.pwAuthSequence) = cpu_to_le16(4);
+       *(sFrame.pwStatus) = cpu_to_le16(uStatusCode);
+
+       /* Adjust the length fields */
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
+       // send the frame
+       if (pDevice->bEnableHostapd) {
+               return;
+       }
+       if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_4 tx failed.\n");
+       }
+       return;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -1618,33 +1541,30 @@ reply:
  * Return Value:
  *    None.
  *
--*/
+ -*/
 static
 void
 s_vMgrRxAuthenSequence_4(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PWLAN_FR_AUTHEN pFrame
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PWLAN_FR_AUTHEN pFrame
+)
 {
+       if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
+               DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Successful.\n");
+               pMgmt->eCurrState = WMAC_STATE_AUTH;
+               timer_expire(pDevice->sTimerCommand, 0);
+       } else{
+               DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Failed.\n");
+               s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
+               pMgmt->eCurrState = WMAC_STATE_IDLE;
+       }
 
-    if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
-        DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Successful.\n");
-        pMgmt->eCurrState = WMAC_STATE_AUTH;
-         timer_expire(pDevice->sTimerCommand, 0);
-    }
-    else{
-        DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Failed.\n");
-        s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))) );
-        pMgmt->eCurrState = WMAC_STATE_IDLE;
-    }
-
-    if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
+       if (pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT) {
 //        spin_unlock_irq(&pDevice->lock);
 //        vCommandTimerWait((void *)pDevice, 0);
 //        spin_lock_irq(&pDevice->lock);
-    }
-
+       }
 }
 
 /*+
@@ -1656,75 +1576,68 @@ s_vMgrRxAuthenSequence_4(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 static
 void
 s_vMgrRxDisassociation(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+)
 {
-    WLAN_FR_DISASSOC    sFrame;
-    unsigned int uNodeIndex = 0;
+       WLAN_FR_DISASSOC    sFrame;
+       unsigned int uNodeIndex = 0;
 //    CMD_STATUS          CmdStatus;
-    viawget_wpa_header *wpahdr;
-
-    if ( pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
-        // if is acting an AP..
-        // a STA is leaving this BSS..
-        sFrame.len = pRxPacket->cbMPDULen;
-        sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
-        if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
-            BSSvRemoveOneNode(pDevice, uNodeIndex);
-        }
-        else {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx disassoc, sta not found\n");
-        }
-    }
-    else if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ){
-        sFrame.len = pRxPacket->cbMPDULen;
-        sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
-        vMgrDecodeDisassociation(&sFrame);
-        DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason)));
-        //TODO: do something let upper layer know or
-        //try to send associate packet again because of inactivity timeout
-      //  if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
-       //     vMgrReAssocBeginSta((PSDevice)pDevice, pMgmt, &CmdStatus);
-      //  }
-        if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
-             wpahdr = (viawget_wpa_header *)pDevice->skb->data;
-             wpahdr->type = VIAWGET_DISASSOC_MSG;
-             wpahdr->resp_ie_len = 0;
-             wpahdr->req_ie_len = 0;
-             skb_put(pDevice->skb, sizeof(viawget_wpa_header));
-             pDevice->skb->dev = pDevice->wpadev;
-            skb_reset_mac_header(pDevice->skb);
-
-             pDevice->skb->pkt_type = PACKET_HOST;
-             pDevice->skb->protocol = htons(ETH_P_802_2);
-             memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
-             netif_rx(pDevice->skb);
-             pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-         }
-
- #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-  // if(pDevice->bWPASuppWextEnabled == true)
-      {
-       union iwreq_data  wrqu;
-       memset(&wrqu, 0, sizeof (wrqu));
-        wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-       printk("wireless_send_event--->SIOCGIWAP(disassociated)\n");
-       wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
-     }
-  #endif
-    }
-    /* else, ignore it */
-
-    return;
-}
+       viawget_wpa_header *wpahdr;
+
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               // if is acting an AP..
+               // a STA is leaving this BSS..
+               sFrame.len = pRxPacket->cbMPDULen;
+               sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
+               if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
+                       BSSvRemoveOneNode(pDevice, uNodeIndex);
+               } else {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx disassoc, sta not found\n");
+               }
+       } else if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
+               sFrame.len = pRxPacket->cbMPDULen;
+               sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
+               vMgrDecodeDisassociation(&sFrame);
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason)));
+               //TODO: do something let upper layer know or
+               //try to send associate packet again because of inactivity timeout
+               if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
+                       wpahdr = (viawget_wpa_header *)pDevice->skb->data;
+                       wpahdr->type = VIAWGET_DISASSOC_MSG;
+                       wpahdr->resp_ie_len = 0;
+                       wpahdr->req_ie_len = 0;
+                       skb_put(pDevice->skb, sizeof(viawget_wpa_header));
+                       pDevice->skb->dev = pDevice->wpadev;
+                       skb_reset_mac_header(pDevice->skb);
+
+                       pDevice->skb->pkt_type = PACKET_HOST;
+                       pDevice->skb->protocol = htons(ETH_P_802_2);
+                       memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
+                       netif_rx(pDevice->skb);
+                       pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
+               }
 
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+               {
+                       union iwreq_data  wrqu;
+                       memset(&wrqu, 0, sizeof(wrqu));
+                       wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+                       printk("wireless_send_event--->SIOCGIWAP(disassociated)\n");
+                       wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
+               }
+#endif
+       }
+       /* else, ignore it */
+
+       return;
+}
 
 /*+
  *
@@ -1735,84 +1648,79 @@ s_vMgrRxDisassociation(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 static
 void
 s_vMgrRxDeauthentication(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+)
 {
-    WLAN_FR_DEAUTHEN    sFrame;
-    unsigned int uNodeIndex = 0;
-    viawget_wpa_header *wpahdr;
-
-
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
-        //Todo:
-        // if is acting an AP..
-        // a STA is leaving this BSS..
-        sFrame.len = pRxPacket->cbMPDULen;
-        sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
-        if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
-            BSSvRemoveOneNode(pDevice, uNodeIndex);
-        }
-        else {
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Rx deauth, sta not found\n");
-        }
-    }
-    else {
-        if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ) {
-            sFrame.len = pRxPacket->cbMPDULen;
-            sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
-            vMgrDecodeDeauthen(&sFrame);
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO  "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason))));
-            // TODO: update BSS list for specific BSSID if pre-authentication case
-            if (!compare_ether_addr(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID)) {
-                if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) {
-                    pMgmt->sNodeDBTable[0].bActive = false;
-                    pMgmt->eCurrMode = WMAC_MODE_STANDBY;
-                    pMgmt->eCurrState = WMAC_STATE_IDLE;
-                    netif_stop_queue(pDevice->dev);
-                    pDevice->bLinkPass = false;
-                }
-            }
-
-            if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
-                 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
-                 wpahdr->type = VIAWGET_DISASSOC_MSG;
-                 wpahdr->resp_ie_len = 0;
-                 wpahdr->req_ie_len = 0;
-                 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
-                 pDevice->skb->dev = pDevice->wpadev;
-                skb_reset_mac_header(pDevice->skb);
-                 pDevice->skb->pkt_type = PACKET_HOST;
-                 pDevice->skb->protocol = htons(ETH_P_802_2);
-                 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
-                 netif_rx(pDevice->skb);
-                 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-           }
-
-   #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-  // if(pDevice->bWPASuppWextEnabled == true)
-      {
-       union iwreq_data  wrqu;
-       memset(&wrqu, 0, sizeof (wrqu));
-        wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-       PRINT_K("wireless_send_event--->SIOCGIWAP(disauthen)\n");
-       wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
-     }
-  #endif
-
-        }
-        /* else, ignore it.  TODO: IBSS authentication service
-            would be implemented here */
-    };
-    return;
-}
+       WLAN_FR_DEAUTHEN    sFrame;
+       unsigned int uNodeIndex = 0;
+       viawget_wpa_header *wpahdr;
+
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               //Todo:
+               // if is acting an AP..
+               // a STA is leaving this BSS..
+               sFrame.len = pRxPacket->cbMPDULen;
+               sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
+               if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
+                       BSSvRemoveOneNode(pDevice, uNodeIndex);
+               } else {
+                       DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Rx deauth, sta not found\n");
+               }
+       } else {
+               if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
+                       sFrame.len = pRxPacket->cbMPDULen;
+                       sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
+                       vMgrDecodeDeauthen(&sFrame);
+                       DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO  "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason))));
+                       // TODO: update BSS list for specific BSSID if pre-authentication case
+                       if (!compare_ether_addr(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID)) {
+                               if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) {
+                                       pMgmt->sNodeDBTable[0].bActive = false;
+                                       pMgmt->eCurrMode = WMAC_MODE_STANDBY;
+                                       pMgmt->eCurrState = WMAC_STATE_IDLE;
+                                       netif_stop_queue(pDevice->dev);
+                                       pDevice->bLinkPass = false;
+                               }
+                       }
+
+                       if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
+                               wpahdr = (viawget_wpa_header *)pDevice->skb->data;
+                               wpahdr->type = VIAWGET_DISASSOC_MSG;
+                               wpahdr->resp_ie_len = 0;
+                               wpahdr->req_ie_len = 0;
+                               skb_put(pDevice->skb, sizeof(viawget_wpa_header));
+                               pDevice->skb->dev = pDevice->wpadev;
+                               skb_reset_mac_header(pDevice->skb);
+                               pDevice->skb->pkt_type = PACKET_HOST;
+                               pDevice->skb->protocol = htons(ETH_P_802_2);
+                               memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
+                               netif_rx(pDevice->skb);
+                               pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
+                       }
 
+#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
+                       {
+                               union iwreq_data  wrqu;
+                               memset(&wrqu, 0, sizeof(wrqu));
+                               wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+                               PRINT_K("wireless_send_event--->SIOCGIWAP(disauthen)\n");
+                               wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
+                       }
+#endif
+
+               }
+               /* else, ignore it.  TODO: IBSS authentication service
+                  would be implemented here */
+       };
+       return;
+}
 
 //2008-8-4 <add> by chester
 /*+
@@ -1825,33 +1733,32 @@ s_vMgrRxDeauthentication(
  * Return Value:
  *               True:exceed;
  *                False:normal case
--*/
+ -*/
 static bool
 ChannelExceedZoneType(
-    PSDevice pDevice,
-    unsigned char byCurrChannel
-    )
+       PSDevice pDevice,
+       unsigned char byCurrChannel
+)
 {
-  bool exceed=false;
+       bool exceed = false;
 
-  switch(pDevice->byZoneType) {
-       case 0x00:                  //USA:1~11
-                     if((byCurrChannel<1) ||(byCurrChannel>11))
-                       exceed = true;
-                break;
+       switch (pDevice->byZoneType) {
+       case 0x00:                  //USA:1~11
+               if ((byCurrChannel < 1) || (byCurrChannel > 11))
+                       exceed = true;
+               break;
        case 0x01:                  //Japan:1~13
        case 0x02:                  //Europe:1~13
-                     if((byCurrChannel<1) ||(byCurrChannel>13))
-                       exceed = true;
-                break;
+               if ((byCurrChannel < 1) || (byCurrChannel > 13))
+                       exceed = true;
+               break;
        default:                    //reserve for other zonetype
                break;
-  }
+       }
 
-  return exceed;
+       return exceed;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -1861,517 +1768,487 @@ ChannelExceedZoneType(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 static
 void
 s_vMgrRxBeacon(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket,
-    bool bInScan
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket,
+       bool bInScan
+)
 {
+       PKnownBSS           pBSSList;
+       WLAN_FR_BEACON      sFrame;
+       QWORD               qwTSFOffset;
+       bool bIsBSSIDEqual = false;
+       bool bIsSSIDEqual = false;
+       bool bTSFLargeDiff = false;
+       bool bTSFOffsetPostive = false;
+       bool bUpdateTSF = false;
+       bool bIsAPBeacon = false;
+       bool bIsChannelEqual = false;
+       unsigned int uLocateByteIndex;
+       unsigned char byTIMBitOn = 0;
+       unsigned short wAIDNumber = 0;
+       unsigned int uNodeIndex;
+       QWORD               qwTimestamp, qwLocalTSF;
+       QWORD               qwCurrTSF;
+       unsigned short wStartIndex = 0;
+       unsigned short wAIDIndex = 0;
+       unsigned char byCurrChannel = pRxPacket->byRxChannel;
+       ERPObject           sERP;
+       unsigned int uRateLen = WLAN_RATES_MAXLEN;
+       bool bChannelHit = false;
+       bool bUpdatePhyParameter = false;
+       unsigned char byIEChannel = 0;
+
+       memset(&sFrame, 0, sizeof(WLAN_FR_BEACON));
+       sFrame.len = pRxPacket->cbMPDULen;
+       sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
+
+       // decode the beacon frame
+       vMgrDecodeBeacon(&sFrame);
+
+       if ((sFrame.pwBeaconInterval == 0) ||
+           (sFrame.pwCapInfo == 0) ||
+           (sFrame.pSSID == 0) ||
+           (sFrame.pSuppRates == 0)) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx beacon frame error\n");
+               return;
+       }
 
-    PKnownBSS           pBSSList;
-    WLAN_FR_BEACON      sFrame;
-    QWORD               qwTSFOffset;
-    bool bIsBSSIDEqual = false;
-    bool bIsSSIDEqual = false;
-    bool bTSFLargeDiff = false;
-    bool bTSFOffsetPostive = false;
-    bool bUpdateTSF = false;
-    bool bIsAPBeacon = false;
-    bool bIsChannelEqual = false;
-    unsigned int uLocateByteIndex;
-    unsigned char byTIMBitOn = 0;
-    unsigned short wAIDNumber = 0;
-    unsigned int uNodeIndex;
-    QWORD               qwTimestamp, qwLocalTSF;
-    QWORD               qwCurrTSF;
-    unsigned short wStartIndex = 0;
-    unsigned short wAIDIndex = 0;
-    unsigned char byCurrChannel = pRxPacket->byRxChannel;
-    ERPObject           sERP;
-    unsigned int uRateLen = WLAN_RATES_MAXLEN;
-    bool bChannelHit = false;
-    bool bUpdatePhyParameter = false;
-    unsigned char byIEChannel = 0;
-
-
-    memset(&sFrame, 0, sizeof(WLAN_FR_BEACON));
-    sFrame.len = pRxPacket->cbMPDULen;
-    sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
-
-    // decode the beacon frame
-    vMgrDecodeBeacon(&sFrame);
-
-    if ((sFrame.pwBeaconInterval == 0) ||
-        (sFrame.pwCapInfo == 0) ||
-        (sFrame.pSSID == 0) ||
-        (sFrame.pSuppRates == 0) ) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx beacon frame error\n");
-        return;
-    }
-
-
-    if (sFrame.pDSParms != NULL) {
-        if (byCurrChannel > CB_MAX_CHANNEL_24G) {
-            // channel remapping to
-            byIEChannel = get_channel_mapping(pDevice, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
-        } else {
-            byIEChannel = sFrame.pDSParms->byCurrChannel;
-        }
-        if (byCurrChannel != byIEChannel) {
-            // adjust channel info. bcs we rcv adjacent channel packets
-            bChannelHit = false;
-            byCurrChannel = byIEChannel;
-        }
-    } else {
-        // no DS channel info
-        bChannelHit = true;
-    }
+       if (sFrame.pDSParms != NULL) {
+               if (byCurrChannel > CB_MAX_CHANNEL_24G) {
+                       // channel remapping to
+                       byIEChannel = get_channel_mapping(pDevice, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
+               } else {
+                       byIEChannel = sFrame.pDSParms->byCurrChannel;
+               }
+               if (byCurrChannel != byIEChannel) {
+                       // adjust channel info. bcs we rcv adjacent channel packets
+                       bChannelHit = false;
+                       byCurrChannel = byIEChannel;
+               }
+       } else {
+               // no DS channel info
+               bChannelHit = true;
+       }
 //2008-0730-01<Add>by MikeLiu
-if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
-      return;
-
-    if (sFrame.pERP != NULL) {
-        sERP.byERP = sFrame.pERP->byContext;
-        sERP.bERPExist = true;
-
-    } else {
-        sERP.bERPExist = false;
-        sERP.byERP = 0;
-    }
-
-    pBSSList = BSSpAddrIsInBSSList((void *)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
-    if (pBSSList == NULL) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon/insert: RxChannel = : %d\n", byCurrChannel);
-        BSSbInsertToBSSList((void *)pDevice,
-                            sFrame.pHdr->sA3.abyAddr3,
-                            *sFrame.pqwTimestamp,
-                            *sFrame.pwBeaconInterval,
-                            *sFrame.pwCapInfo,
-                            byCurrChannel,
-                            sFrame.pSSID,
-                            sFrame.pSuppRates,
-                            sFrame.pExtSuppRates,
-                            &sERP,
-                            sFrame.pRSN,
-                            sFrame.pRSNWPA,
-                            sFrame.pIE_Country,
-                            sFrame.pIE_Quiet,
-                            sFrame.len - WLAN_HDR_ADDR3_LEN,
-                            sFrame.pHdr->sA4.abyAddr4,   // payload of beacon
-                            (void *)pRxPacket
-                           );
-    }
-    else {
-//        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"update bcn: RxChannel = : %d\n", byCurrChannel);
-        BSSbUpdateToBSSList((void *)pDevice,
-                            *sFrame.pqwTimestamp,
-                            *sFrame.pwBeaconInterval,
-                            *sFrame.pwCapInfo,
-                            byCurrChannel,
-                            bChannelHit,
-                            sFrame.pSSID,
-                            sFrame.pSuppRates,
-                            sFrame.pExtSuppRates,
-                            &sERP,
-                            sFrame.pRSN,
-                            sFrame.pRSNWPA,
-                            sFrame.pIE_Country,
-                            sFrame.pIE_Quiet,
-                            pBSSList,
-                            sFrame.len - WLAN_HDR_ADDR3_LEN,
-                            sFrame.pHdr->sA4.abyAddr4,   // payload of probresponse
-                            (void *)pRxPacket
-                           );
-
-    }
-
-    if (bInScan) {
-        return;
-    }
-
-    if(byCurrChannel == (unsigned char)pMgmt->uCurrChannel)
-       bIsChannelEqual = true;
-
-    if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
-
-        // if rx beacon without ERP field
-        if (sERP.bERPExist) {
-            if (WLAN_GET_ERP_USE_PROTECTION(sERP.byERP)){
-                pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
-                pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
-            }
-        }
-        else {
-            pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
-            pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
-        }
-
-        if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-            if(!WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo))
-                pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
-            if(!sERP.bERPExist)
-                pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
-        }
-
-        // set to MAC&BBP
-        if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)){
-            if (!pDevice->bProtectMode) {
-                 MACvEnableProtectMD(pDevice->PortOffset);
-                 pDevice->bProtectMode = true;
-            }
-        }
-    }
-
-
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
-        return;
-
-    // check if BSSID the same
-    if (memcmp(sFrame.pHdr->sA3.abyAddr3,
-               pMgmt->abyCurrBSSID,
-               WLAN_BSSID_LEN) == 0) {
-
-        bIsBSSIDEqual = true;
+       if (ChannelExceedZoneType(pDevice, byCurrChannel) == true)
+               return;
+
+       if (sFrame.pERP != NULL) {
+               sERP.byERP = sFrame.pERP->byContext;
+               sERP.bERPExist = true;
+
+       } else {
+               sERP.bERPExist = false;
+               sERP.byERP = 0;
+       }
+
+       pBSSList = BSSpAddrIsInBSSList((void *)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
+       if (pBSSList == NULL) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Beacon/insert: RxChannel = : %d\n", byCurrChannel);
+               BSSbInsertToBSSList((void *)pDevice,
+                                   sFrame.pHdr->sA3.abyAddr3,
+                                   *sFrame.pqwTimestamp,
+                                   *sFrame.pwBeaconInterval,
+                                   *sFrame.pwCapInfo,
+                                   byCurrChannel,
+                                   sFrame.pSSID,
+                                   sFrame.pSuppRates,
+                                   sFrame.pExtSuppRates,
+                                   &sERP,
+                                   sFrame.pRSN,
+                                   sFrame.pRSNWPA,
+                                   sFrame.pIE_Country,
+                                   sFrame.pIE_Quiet,
+                                   sFrame.len - WLAN_HDR_ADDR3_LEN,
+                                   sFrame.pHdr->sA4.abyAddr4,   // payload of beacon
+                                   (void *)pRxPacket
+);
+       } else {
+//        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "update bcn: RxChannel = : %d\n", byCurrChannel);
+               BSSbUpdateToBSSList((void *)pDevice,
+                                   *sFrame.pqwTimestamp,
+                                   *sFrame.pwBeaconInterval,
+                                   *sFrame.pwCapInfo,
+                                   byCurrChannel,
+                                   bChannelHit,
+                                   sFrame.pSSID,
+                                   sFrame.pSuppRates,
+                                   sFrame.pExtSuppRates,
+                                   &sERP,
+                                   sFrame.pRSN,
+                                   sFrame.pRSNWPA,
+                                   sFrame.pIE_Country,
+                                   sFrame.pIE_Quiet,
+                                   pBSSList,
+                                   sFrame.len - WLAN_HDR_ADDR3_LEN,
+                                   sFrame.pHdr->sA4.abyAddr4,   // payload of probresponse
+                                   (void *)pRxPacket
+);
+
+       }
+
+       if (bInScan) {
+               return;
+       }
+
+       if (byCurrChannel == (unsigned char)pMgmt->uCurrChannel)
+               bIsChannelEqual = true;
+
+       if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
+               // if rx beacon without ERP field
+               if (sERP.bERPExist) {
+                       if (WLAN_GET_ERP_USE_PROTECTION(sERP.byERP)) {
+                               pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
+                               pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
+                       }
+               } else {
+                       pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
+                       pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
+               }
+
+               if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+                       if (!WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo))
+                               pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
+                       if (!sERP.bERPExist)
+                               pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
+               }
+
+               // set to MAC&BBP
+               if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
+                       if (!pDevice->bProtectMode) {
+                               MACvEnableProtectMD(pDevice->PortOffset);
+                               pDevice->bProtectMode = true;
+                       }
+               }
+       }
+
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
+               return;
+
+       // check if BSSID the same
+       if (memcmp(sFrame.pHdr->sA3.abyAddr3,
+                  pMgmt->abyCurrBSSID,
+                  WLAN_BSSID_LEN) == 0) {
+               bIsBSSIDEqual = true;
 
 // 2008-05-21 <add> by Richardtai
-        pDevice->uCurrRSSI = pRxPacket->uRSSI;
-        pDevice->byCurrSQ = pRxPacket->bySQ;
-
-        if (pMgmt->sNodeDBTable[0].uInActiveCount != 0) {
-            pMgmt->sNodeDBTable[0].uInActiveCount = 0;
-            //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BCN:Wake Count= [%d]\n", pMgmt->wCountToWakeUp);
-        }
-    }
-    // check if SSID the same
-    if (sFrame.pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) {
-        if (memcmp(sFrame.pSSID->abySSID,
-                   ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
-                   sFrame.pSSID->len
-                   ) == 0) {
-            bIsSSIDEqual = true;
-        }
-    }
-
-    if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)== true) &&
-        (bIsBSSIDEqual == true) &&
-        (bIsSSIDEqual == true) &&
-        (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
-        (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
-        // add state check to prevent reconnect fail since we'll receive Beacon
-
-        bIsAPBeacon = true;
-
-        if (pBSSList != NULL) {
-
-            // Compare PHY parameter setting
-            if (pMgmt->wCurrCapInfo != pBSSList->wCapInfo) {
-                bUpdatePhyParameter = true;
-                pMgmt->wCurrCapInfo = pBSSList->wCapInfo;
-            }
-            if (sFrame.pERP != NULL) {
-                if ((sFrame.pERP->byElementID == WLAN_EID_ERP) &&
-                    (pMgmt->byERPContext != sFrame.pERP->byContext)) {
-                    bUpdatePhyParameter = true;
-                    pMgmt->byERPContext = sFrame.pERP->byContext;
-                }
-            }
-            //
-            // Basic Rate Set may change dynamically
-            //
-            if (pBSSList->eNetworkTypeInUse == PHY_TYPE_11B) {
-                uRateLen = WLAN_RATES_MAXLEN_11B;
-            }
-            pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abySuppRates,
-                                                    (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                                                    uRateLen);
-            pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abyExtSuppRates,
-                                                    (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
-                                                    uRateLen);
-            RATEvParseMaxRate( (void *)pDevice,
-                               (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                               (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
-                               true,
-                               &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
-                               &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
-                               &(pMgmt->sNodeDBTable[0].wSuppRate),
-                               &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
-                               &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
-                              );
-#ifdef PLICE_DEBUG
-               //printk("RxBeacon:MaxSuppRate is %d\n",pMgmt->sNodeDBTable[0].wMaxSuppRate);
-#endif
+               pDevice->uCurrRSSI = pRxPacket->uRSSI;
+               pDevice->byCurrSQ = pRxPacket->bySQ;
+
+               if (pMgmt->sNodeDBTable[0].uInActiveCount != 0) {
+                       pMgmt->sNodeDBTable[0].uInActiveCount = 0;
+                       //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN:Wake Count= [%d]\n", pMgmt->wCountToWakeUp);
+               }
+       }
+       // check if SSID the same
+       if (sFrame.pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) {
+               if (memcmp(sFrame.pSSID->abySSID,
+                          ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
+                          sFrame.pSSID->len
+) == 0) {
+                       bIsSSIDEqual = true;
+               }
+       }
+
+       if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo) == true) &&
+           (bIsBSSIDEqual == true) &&
+           (bIsSSIDEqual == true) &&
+           (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
+           (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
+               // add state check to prevent reconnect fail since we'll receive Beacon
+
+               bIsAPBeacon = true;
+
+               if (pBSSList != NULL) {
+                       // Compare PHY parameter setting
+                       if (pMgmt->wCurrCapInfo != pBSSList->wCapInfo) {
+                               bUpdatePhyParameter = true;
+                               pMgmt->wCurrCapInfo = pBSSList->wCapInfo;
+                       }
+                       if (sFrame.pERP != NULL) {
+                               if ((sFrame.pERP->byElementID == WLAN_EID_ERP) &&
+                                   (pMgmt->byERPContext != sFrame.pERP->byContext)) {
+                                       bUpdatePhyParameter = true;
+                                       pMgmt->byERPContext = sFrame.pERP->byContext;
+                               }
+                       }
+                       //
+                       // Basic Rate Set may change dynamically
+                       //
+                       if (pBSSList->eNetworkTypeInUse == PHY_TYPE_11B) {
+                               uRateLen = WLAN_RATES_MAXLEN_11B;
+                       }
+                       pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abySuppRates,
+                                                               (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                                                               uRateLen);
+                       pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abyExtSuppRates,
+                                                                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
+                                                                  uRateLen);
+                       RATEvParseMaxRate((void *)pDevice,
+                                         (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                                         (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
+                                         true,
+                                         &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
+                                         &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
+                                         &(pMgmt->sNodeDBTable[0].wSuppRate),
+                                         &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
+                                         &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
+                               );
                        if (bUpdatePhyParameter == true) {
-                CARDbSetPhyParameter( pMgmt->pAdapter,
-                                      pMgmt->eCurrentPHYMode,
-                                      pMgmt->wCurrCapInfo,
-                                      pMgmt->byERPContext,
-                                      pMgmt->abyCurrSuppRates,
-                                      pMgmt->abyCurrExtSuppRates
-                                      );
-            }
-            if (sFrame.pIE_PowerConstraint != NULL) {
-                CARDvSetPowerConstraint(pMgmt->pAdapter,
-                                        (unsigned char) pBSSList->uChannel,
-                                        sFrame.pIE_PowerConstraint->byPower
-                                        );
-            }
-            if (sFrame.pIE_CHSW != NULL) {
-                CARDbChannelSwitch( pMgmt->pAdapter,
-                                    sFrame.pIE_CHSW->byMode,
-                                    get_channel_mapping(pMgmt->pAdapter, sFrame.pIE_CHSW->byMode, pMgmt->eCurrentPHYMode),
-                                    sFrame.pIE_CHSW->byCount
-                                    );
-
-            } else if (bIsChannelEqual == false) {
-                set_channel(pMgmt->pAdapter, pBSSList->uChannel);
-            }
-        }
-    }
-
-//    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon 2 \n");
-    // check if CF field exists
-    if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)) {
-        if (sFrame.pCFParms->wCFPDurRemaining > 0) {
-            // TODO: deal with CFP period to set NAV
-        }
-    }
-
-    HIDWORD(qwTimestamp) = cpu_to_le32(HIDWORD(*sFrame.pqwTimestamp));
-    LODWORD(qwTimestamp) = cpu_to_le32(LODWORD(*sFrame.pqwTimestamp));
-    HIDWORD(qwLocalTSF) = HIDWORD(pRxPacket->qwLocalTSF);
-    LODWORD(qwLocalTSF) = LODWORD(pRxPacket->qwLocalTSF);
-
-    // check if beacon TSF larger or small than our local TSF
-    if (HIDWORD(qwTimestamp) == HIDWORD(qwLocalTSF)) {
-        if (LODWORD(qwTimestamp) >= LODWORD(qwLocalTSF)) {
-            bTSFOffsetPostive = true;
-        }
-        else {
-            bTSFOffsetPostive = false;
-        }
-    }
-    else if (HIDWORD(qwTimestamp) > HIDWORD(qwLocalTSF)) {
-        bTSFOffsetPostive = true;
-    }
-    else if (HIDWORD(qwTimestamp) < HIDWORD(qwLocalTSF)) {
-        bTSFOffsetPostive = false;
-    }
-
-    if (bTSFOffsetPostive) {
-        qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF));
-    }
-    else {
-        qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp));
-    }
-
-    if (HIDWORD(qwTSFOffset) != 0 ||
-        (LODWORD(qwTSFOffset) > TRIVIAL_SYNC_DIFFERENCE )) {
-         bTSFLargeDiff = true;
-    }
-
-
-    // if infra mode
-    if (bIsAPBeacon == true) {
-
-        // Infra mode: Local TSF always follow AP's TSF if Difference huge.
-        if (bTSFLargeDiff)
-            bUpdateTSF = true;
-
-        if ((pDevice->bEnablePSMode == true) &&(sFrame.pTIM != 0)) {
-
-            // deal with DTIM, analysis TIM
-            pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? true : false ;
-            pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount;
-            pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod;
-            wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15);
-
-            // check if AID in TIM field bit on
-            // wStartIndex = N1
-            wStartIndex = WLAN_MGMT_GET_TIM_OFFSET(sFrame.pTIM->byBitMapCtl) << 1;
-            // AIDIndex = N2
-            wAIDIndex = (wAIDNumber >> 3);
-            if ((wAIDNumber > 0) && (wAIDIndex >= wStartIndex)) {
-                uLocateByteIndex = wAIDIndex - wStartIndex;
-                // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250]
-                if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) {
-                    byTIMBitOn  = (0x01) << ((wAIDNumber) % 8);
-                    pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? true : false;
-                }
-                else {
-                    pMgmt->bInTIM = false;
-                };
-            }
-            else {
-                pMgmt->bInTIM = false;
-            };
-
-            if (pMgmt->bInTIM ||
-                (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) {
-                pMgmt->bInTIMWake = true;
-                // send out ps-poll packet
+                               CARDbSetPhyParameter(pMgmt->pAdapter,
+                                                    pMgmt->eCurrentPHYMode,
+                                                    pMgmt->wCurrCapInfo,
+                                                    pMgmt->byERPContext,
+                                                    pMgmt->abyCurrSuppRates,
+                                                    pMgmt->abyCurrExtSuppRates
+                                       );
+                       }
+                       if (sFrame.pIE_PowerConstraint != NULL) {
+                               CARDvSetPowerConstraint(pMgmt->pAdapter,
+                                                       (unsigned char) pBSSList->uChannel,
+                                                       sFrame.pIE_PowerConstraint->byPower
+);
+                       }
+                       if (sFrame.pIE_CHSW != NULL) {
+                               CARDbChannelSwitch(pMgmt->pAdapter,
+                                                  sFrame.pIE_CHSW->byMode,
+                                                  get_channel_mapping(pMgmt->pAdapter, sFrame.pIE_CHSW->byMode, pMgmt->eCurrentPHYMode),
+                                                  sFrame.pIE_CHSW->byCount
+                                       );
+
+                       } else if (bIsChannelEqual == false) {
+                               set_channel(pMgmt->pAdapter, pBSSList->uChannel);
+                       }
+               }
+       }
+
+//    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Beacon 2 \n");
+       // check if CF field exists
+       if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)) {
+               if (sFrame.pCFParms->wCFPDurRemaining > 0) {
+                       // TODO: deal with CFP period to set NAV
+               }
+       }
+
+       HIDWORD(qwTimestamp) = cpu_to_le32(HIDWORD(*sFrame.pqwTimestamp));
+       LODWORD(qwTimestamp) = cpu_to_le32(LODWORD(*sFrame.pqwTimestamp));
+       HIDWORD(qwLocalTSF) = HIDWORD(pRxPacket->qwLocalTSF);
+       LODWORD(qwLocalTSF) = LODWORD(pRxPacket->qwLocalTSF);
+
+       // check if beacon TSF larger or small than our local TSF
+       if (HIDWORD(qwTimestamp) == HIDWORD(qwLocalTSF)) {
+               if (LODWORD(qwTimestamp) >= LODWORD(qwLocalTSF)) {
+                       bTSFOffsetPostive = true;
+               } else {
+                       bTSFOffsetPostive = false;
+               }
+       } else if (HIDWORD(qwTimestamp) > HIDWORD(qwLocalTSF)) {
+               bTSFOffsetPostive = true;
+       } else if (HIDWORD(qwTimestamp) < HIDWORD(qwLocalTSF)) {
+               bTSFOffsetPostive = false;
+       }
+
+       if (bTSFOffsetPostive) {
+               qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF));
+       } else {
+               qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp));
+       }
+
+       if (HIDWORD(qwTSFOffset) != 0 ||
+           (LODWORD(qwTSFOffset) > TRIVIAL_SYNC_DIFFERENCE)) {
+               bTSFLargeDiff = true;
+       }
+
+       // if infra mode
+       if (bIsAPBeacon == true) {
+               // Infra mode: Local TSF always follow AP's TSF if Difference huge.
+               if (bTSFLargeDiff)
+                       bUpdateTSF = true;
+
+               if ((pDevice->bEnablePSMode == true) && (sFrame.pTIM != 0)) {
+                       // deal with DTIM, analysis TIM
+                       pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? true : false;
+                       pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount;
+                       pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod;
+                       wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15);
+
+                       // check if AID in TIM field bit on
+                       // wStartIndex = N1
+                       wStartIndex = WLAN_MGMT_GET_TIM_OFFSET(sFrame.pTIM->byBitMapCtl) << 1;
+                       // AIDIndex = N2
+                       wAIDIndex = (wAIDNumber >> 3);
+                       if ((wAIDNumber > 0) && (wAIDIndex >= wStartIndex)) {
+                               uLocateByteIndex = wAIDIndex - wStartIndex;
+                               // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250]
+                               if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) {
+                                       byTIMBitOn  = (0x01) << ((wAIDNumber) % 8);
+                                       pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? true : false;
+                               } else {
+                                       pMgmt->bInTIM = false;
+                               };
+                       } else {
+                               pMgmt->bInTIM = false;
+                       };
+
+                       if (pMgmt->bInTIM ||
+                           (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) {
+                               pMgmt->bInTIMWake = true;
+                               // send out ps-poll packet
 //                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN:In TIM\n");
-                if (pMgmt->bInTIM) {
-                    PSvSendPSPOLL((PSDevice)pDevice);
+                               if (pMgmt->bInTIM) {
+                                       PSvSendPSPOLL((PSDevice)pDevice);
 //                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN:PS-POLL sent..\n");
-                }
-
-            }
-            else {
-                pMgmt->bInTIMWake = false;
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Not In TIM..\n");
-                if (pDevice->bPWBitOn == false) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n");
-                    if (PSbSendNullPacket(pDevice))
-                        pDevice->bPWBitOn = true;
-                }
-                if(PSbConsiderPowerDown(pDevice, false, false)) {
-                   DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n");
-                }
-            }
-
-        }
-
-    }
-    // if adhoc mode
-    if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && !bIsAPBeacon && bIsChannelEqual) {
-        if (bIsBSSIDEqual) {
-            // Use sNodeDBTable[0].uInActiveCount as IBSS beacons received count.
-                   if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
-                           pMgmt->sNodeDBTable[0].uInActiveCount = 0;
-
-            // adhoc mode:TSF updated only when beacon larger than local TSF
-            if (bTSFLargeDiff && bTSFOffsetPostive &&
-                (pMgmt->eCurrState == WMAC_STATE_JOINTED))
-                bUpdateTSF = true;
-
-            // During dpc, already in spinlocked.
-            if (BSSDBbIsSTAInNodeDB(pMgmt, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) {
-
-                // Update the STA, (Technically the Beacons of all the IBSS nodes
-                       // should be identical, but that's not happening in practice.
-                pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
-                                                        (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                                                        WLAN_RATES_MAXLEN_11B);
-                RATEvParseMaxRate( (void *)pDevice,
-                                   (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                                   NULL,
-                                   true,
-                                   &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
-                                   &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
-                                   &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
-                                   &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
-                                   &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
-                                  );
-                pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
-                pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
-                pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0;
-            }
-            else {
-                // Todo, initial Node content
-                BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
-
-                pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
-                                                        (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                                                        WLAN_RATES_MAXLEN_11B);
-                RATEvParseMaxRate( (void *)pDevice,
-                                   (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                                   NULL,
-                                   true,
-                                   &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
-                                   &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
-                                   &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
-                                   &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
-                                   &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
-                                 );
-
-                memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, sFrame.pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
-                pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
-                pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
-#ifdef PLICE_DEBUG
-               //if (uNodeIndex == 0)
-               {
-                       printk("s_vMgrRxBeacon:TxDataRate is %d,Index is %d\n",pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate,uNodeIndex);
+                               }
+
+                       } else {
+                               pMgmt->bInTIMWake = false;
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Not In TIM..\n");
+                               if (pDevice->bPWBitOn == false) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n");
+                                       if (PSbSendNullPacket(pDevice))
+                                               pDevice->bPWBitOn = true;
+                               }
+                               if (PSbConsiderPowerDown(pDevice, false, false)) {
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n");
+                               }
+                       }
+
                }
+
+       }
+       // if adhoc mode
+       if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && !bIsAPBeacon && bIsChannelEqual) {
+               if (bIsBSSIDEqual) {
+                       // Use sNodeDBTable[0].uInActiveCount as IBSS beacons received count.
+                       if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
+                               pMgmt->sNodeDBTable[0].uInActiveCount = 0;
+
+                       // adhoc mode:TSF updated only when beacon larger than local TSF
+                       if (bTSFLargeDiff && bTSFOffsetPostive &&
+                           (pMgmt->eCurrState == WMAC_STATE_JOINTED))
+                               bUpdateTSF = true;
+
+                       // During dpc, already in spinlocked.
+                       if (BSSDBbIsSTAInNodeDB(pMgmt, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) {
+                               // Update the STA, (Technically the Beacons of all the IBSS nodes
+                               // should be identical, but that's not happening in practice.
+                               pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
+                                                                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                                                                       WLAN_RATES_MAXLEN_11B);
+                               RATEvParseMaxRate((void *)pDevice,
+                                                 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                                                 NULL,
+                                                 true,
+                                                 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
+                                                 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
+                                                 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
+                                                 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
+                                                 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
+                                       );
+                               pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
+                               pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
+                               pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0;
+                       } else {
+                               // Todo, initial Node content
+                               BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
+
+                               pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
+                                                                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                                                                       WLAN_RATES_MAXLEN_11B);
+                               RATEvParseMaxRate((void *)pDevice,
+                                                 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                                                 NULL,
+                                                 true,
+                                                 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
+                                                 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
+                                                 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
+                                                 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
+                                                 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
+                                       );
+
+                               memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, sFrame.pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
+                               pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
+                               pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
+#ifdef PLICE_DEBUG
+                               {
+                                       printk("s_vMgrRxBeacon:TxDataRate is %d,Index is %d\n", pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate, uNodeIndex);
+                               }
 #endif
 /*
-                pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
-                if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
-                       pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
+  pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
+  if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
+  pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
 */
-            }
-
-            // if other stations joined, indicate connection to upper layer..
-            if (pMgmt->eCurrState == WMAC_STATE_STARTED) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Current IBSS State: [Started]........to: [Jointed] \n");
-                pMgmt->eCurrState = WMAC_STATE_JOINTED;
-                pDevice->bLinkPass = true;
-                if (netif_queue_stopped(pDevice->dev)){
-                    netif_wake_queue(pDevice->dev);
-                }
-                pMgmt->sNodeDBTable[0].bActive = true;
-                pMgmt->sNodeDBTable[0].uInActiveCount = 0;
-
-            }
-        }
-        else if (bIsSSIDEqual) {
-
-            // See other adhoc sta with the same SSID but BSSID is different.
-            // adpot this vars only when TSF larger then us.
-            if (bTSFLargeDiff && bTSFOffsetPostive) {
-                 // we don't support ATIM under adhoc mode
-               // if ( sFrame.pIBSSParms->wATIMWindow == 0) {
-                     // adpot this vars
-                     // TODO: check sFrame cap if privacy on, and support rate syn
-                     memcpy(pMgmt->abyCurrBSSID, sFrame.pHdr->sA3.abyAddr3, WLAN_BSSID_LEN);
-                     memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-                     pMgmt->wCurrATIMWindow = cpu_to_le16(sFrame.pIBSSParms->wATIMWindow);
-                     pMgmt->wCurrBeaconPeriod = cpu_to_le16(*sFrame.pwBeaconInterval);
-                     pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
-                                                      (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                                                      WLAN_RATES_MAXLEN_11B);
-                     // set HW beacon interval and re-synchronizing....
-                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rejoining to Other Adhoc group with same SSID........\n");
-                     VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, pMgmt->wCurrBeaconPeriod);
-                     CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, qwLocalTSF);
-                     CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
-                     // Turn off bssid filter to avoid filter others adhoc station which bssid is different.
-                     MACvWriteBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
-
-                     CARDbSetPhyParameter (  pMgmt->pAdapter,
-                                            pMgmt->eCurrentPHYMode,
-                                            pMgmt->wCurrCapInfo,
-                                            pMgmt->byERPContext,
-                                            pMgmt->abyCurrSuppRates,
-                                            pMgmt->abyCurrExtSuppRates);
-
-
-                     // MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
-                     // set highest basic rate
-                     // s_vSetHighestBasicRate(pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates);
-                     // Prepare beacon frame
-                     bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
-              //  }
-            }
-        }
-    }
-    // endian issue ???
-    // Update TSF
-    if (bUpdateTSF) {
-        CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
-        CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, pRxPacket->qwLocalTSF);
-        CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
-        CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
-    }
-
-    return;
-}
-
+                       }
+
+                       // if other stations joined, indicate connection to upper layer..
+                       if (pMgmt->eCurrState == WMAC_STATE_STARTED) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Current IBSS State: [Started]........to: [Jointed] \n");
+                               pMgmt->eCurrState = WMAC_STATE_JOINTED;
+                               pDevice->bLinkPass = true;
+                               if (netif_queue_stopped(pDevice->dev)) {
+                                       netif_wake_queue(pDevice->dev);
+                               }
+                               pMgmt->sNodeDBTable[0].bActive = true;
+                               pMgmt->sNodeDBTable[0].uInActiveCount = 0;
+
+                       }
+               } else if (bIsSSIDEqual) {
+                       // See other adhoc sta with the same SSID but BSSID is different.
+                       // adpot this vars only when TSF larger then us.
+                       if (bTSFLargeDiff && bTSFOffsetPostive) {
+                               // we don't support ATIM under adhoc mode
+                               // if (sFrame.pIBSSParms->wATIMWindow == 0) {
+                               // adpot this vars
+                               // TODO: check sFrame cap if privacy on, and support rate syn
+                               memcpy(pMgmt->abyCurrBSSID, sFrame.pHdr->sA3.abyAddr3, WLAN_BSSID_LEN);
+                               memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+                               pMgmt->wCurrATIMWindow = cpu_to_le16(sFrame.pIBSSParms->wATIMWindow);
+                               pMgmt->wCurrBeaconPeriod = cpu_to_le16(*sFrame.pwBeaconInterval);
+                               pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
+                                                                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                                                                       WLAN_RATES_MAXLEN_11B);
+                               // set HW beacon interval and re-synchronizing....
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rejoining to Other Adhoc group with same SSID........\n");
+                               VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, pMgmt->wCurrBeaconPeriod);
+                               CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, qwLocalTSF);
+                               CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
+                               // Turn off bssid filter to avoid filter others adhoc station which bssid is different.
+                               MACvWriteBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
+
+                               CARDbSetPhyParameter(pMgmt->pAdapter,
+                                                    pMgmt->eCurrentPHYMode,
+                                                    pMgmt->wCurrCapInfo,
+                                                    pMgmt->byERPContext,
+                                                    pMgmt->abyCurrSuppRates,
+                                                    pMgmt->abyCurrExtSuppRates);
+
+                               // MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
+                               // set highest basic rate
+                               // s_vSetHighestBasicRate(pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates);
+                               // Prepare beacon frame
+                               bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
+                               //  }
+                       }
+               }
+       }
+       // endian issue ???
+       // Update TSF
+if (bUpdateTSF) {
+               CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
+               CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, pRxPacket->qwLocalTSF);
+               CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
+               CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
+       }
 
+       return;
+}
 
 /*+
  *
@@ -2384,248 +2261,239 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
  * Return Value:
  *    CMD_STATUS
  *
--*/
+ -*/
 void
 vMgrCreateOwnIBSS(
-    void *hDeviceContext,
-    PCMD_STATUS pStatus
-    )
+       void *hDeviceContext,
+       PCMD_STATUS pStatus
+)
 {
-    PSDevice            pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject        pMgmt = pDevice->pMgmt;
-    unsigned short wMaxBasicRate;
-    unsigned short wMaxSuppRate;
-    unsigned char byTopCCKBasicRate;
-    unsigned char byTopOFDMBasicRate;
-    QWORD               qwCurrTSF;
-    unsigned int ii;
-    unsigned char abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C, 0x12, 0x18, 0x60};
-    unsigned char abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96};
-    unsigned char abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
-    unsigned short wSuppRate;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n");
-
-    if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
-        if ((pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) &&
-            (pDevice->eEncryptionStatus != Ndis802_11Encryption2Enabled) &&
-            (pDevice->eEncryptionStatus != Ndis802_11Encryption3Enabled)) {
-            // encryption mode error
-            *pStatus = CMD_STATUS_FAILURE;
-            return;
-        }
-    }
-
-    pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
-    pMgmt->abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
-
-    if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
-        pMgmt->eCurrentPHYMode = pMgmt->byAPBBType;
-    } else {
-        if (pDevice->byBBType == BB_TYPE_11G)
-            pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
-        if (pDevice->byBBType == BB_TYPE_11B)
-            pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
-        if (pDevice->byBBType == BB_TYPE_11A)
-            pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
-    }
-
-    if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
-        pMgmt->abyCurrSuppRates[1] = WLAN_RATES_MAXLEN_11B;
-        pMgmt->abyCurrExtSuppRates[1] = 0;
-        for (ii = 0; ii < 4; ii++)
-            pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
-    } else {
-        pMgmt->abyCurrSuppRates[1] = 8;
-        pMgmt->abyCurrExtSuppRates[1] = 0;
-        for (ii = 0; ii < 8; ii++)
-            pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
-    }
-
-
-    if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
-        pMgmt->abyCurrSuppRates[1] = 8;
-        pMgmt->abyCurrExtSuppRates[1] = 4;
-        for (ii = 0; ii < 4; ii++)
-            pMgmt->abyCurrSuppRates[2+ii] =  abyCCK_RATE[ii];
-        for (ii = 4; ii < 8; ii++)
-            pMgmt->abyCurrSuppRates[2+ii] =  abyOFDM_RATE[ii-4];
-        for (ii = 0; ii < 4; ii++)
-            pMgmt->abyCurrExtSuppRates[2+ii] =  abyOFDM_RATE[ii+4];
-    }
-
-
-    // Disable Protect Mode
-    pDevice->bProtectMode = 0;
-    MACvDisableProtectMD(pDevice->PortOffset);
-
-    pDevice->bBarkerPreambleMd = 0;
-    MACvDisableBarkerPreambleMd(pDevice->PortOffset);
-
-    // Kyle Test 2003.11.04
-
-    // set HW beacon interval
-    if (pMgmt->wIBSSBeaconPeriod == 0)
-        pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
-
-
-    CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
-    // clear TSF counter
-    VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
-    // enable TSF counter
-    VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
-
-    // set Next TBTT
-    CARDvSetFirstNextTBTT(pDevice->PortOffset, pMgmt->wIBSSBeaconPeriod);
-
-    pMgmt->uIBSSChannel = pDevice->uChannel;
-
-    if (pMgmt->uIBSSChannel == 0)
-        pMgmt->uIBSSChannel = DEFAULT_IBSS_CHANNEL;
-
-
-    // set basic rate
-
-    RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                      (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, true,
-                      &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
-                      &byTopCCKBasicRate, &byTopOFDMBasicRate);
-
-
-    if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
-        pMgmt->eCurrMode = WMAC_MODE_ESS_AP;
-    }
-
-    if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
-        memcpy(pMgmt->abyIBSSDFSOwner, pDevice->abyCurrentNetAddr, 6);
-        pMgmt->byIBSSDFSRecovery = 10;
-        pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
-    }
-
-    // Adopt pre-configured IBSS vars to current vars
-    pMgmt->eCurrState = WMAC_STATE_STARTED;
-    pMgmt->wCurrBeaconPeriod = pMgmt->wIBSSBeaconPeriod;
-    pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
-    pMgmt->wCurrATIMWindow = pMgmt->wIBSSATIMWindow;
-    MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
-    pDevice->uCurrRSSI = 0;
-    pDevice->byCurrSQ = 0;
-    //memcpy(pMgmt->abyDesireSSID,pMgmt->abyAdHocSSID,
-                     // ((PWLAN_IE_SSID)pMgmt->abyAdHocSSID)->len + WLAN_IEHDR_LEN);
-    memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-    memcpy(pMgmt->abyCurrSSID,
-           pMgmt->abyDesireSSID,
-           ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN
-          );
-
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-        // AP mode BSSID = MAC addr
-        memcpy(pMgmt->abyCurrBSSID, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"AP beacon created BSSID:%pM\n",
-               pMgmt->abyCurrBSSID);
-    }
-
-    if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-
-        // BSSID selected must be randomized as spec 11.1.3
-        pMgmt->abyCurrBSSID[5] = (unsigned char) (LODWORD(qwCurrTSF)& 0x000000ff);
-        pMgmt->abyCurrBSSID[4] = (unsigned char)((LODWORD(qwCurrTSF)& 0x0000ff00) >> 8);
-        pMgmt->abyCurrBSSID[3] = (unsigned char)((LODWORD(qwCurrTSF)& 0x00ff0000) >> 16);
-        pMgmt->abyCurrBSSID[2] = (unsigned char)((LODWORD(qwCurrTSF)& 0x00000ff0) >> 4);
-        pMgmt->abyCurrBSSID[1] = (unsigned char)((LODWORD(qwCurrTSF)& 0x000ff000) >> 12);
-        pMgmt->abyCurrBSSID[0] = (unsigned char)((LODWORD(qwCurrTSF)& 0x0ff00000) >> 20);
-        pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0];
-        pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1];
-        pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2];
-        pMgmt->abyCurrBSSID[2] ^= pMgmt->abyMACAddr[3];
-        pMgmt->abyCurrBSSID[1] ^= pMgmt->abyMACAddr[4];
-        pMgmt->abyCurrBSSID[0] ^= pMgmt->abyMACAddr[5];
-        pMgmt->abyCurrBSSID[0] &= ~IEEE_ADDR_GROUP;
-        pMgmt->abyCurrBSSID[0] |= IEEE_ADDR_UNIVERSAL;
-
-
-       DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"Adhoc beacon created bssid:%pM\n",
-               pMgmt->abyCurrBSSID);
-    }
-
-    // Set Capability Info
-    pMgmt->wCurrCapInfo = 0;
-
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
-        pMgmt->byDTIMPeriod = DEFAULT_DTIM_PERIOD;
-        pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
-    }
-
-    if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_IBSS(1);
-    }
-
-    if (pDevice->bEncryptionEnable) {
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
-        if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
-            if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
-                pMgmt->byCSSPK = KEY_CTL_CCMP;
-                pMgmt->byCSSGK = KEY_CTL_CCMP;
-            } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
-                pMgmt->byCSSPK = KEY_CTL_TKIP;
-                pMgmt->byCSSGK = KEY_CTL_TKIP;
-            } else {
-                pMgmt->byCSSPK = KEY_CTL_NONE;
-                pMgmt->byCSSGK = KEY_CTL_WEP;
-            }
-        } else {
-            pMgmt->byCSSPK = KEY_CTL_WEP;
-            pMgmt->byCSSGK = KEY_CTL_WEP;
-        }
-    }
-
-    pMgmt->byERPContext = 0;
+       PSDevice            pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject        pMgmt = pDevice->pMgmt;
+       unsigned short wMaxBasicRate;
+       unsigned short wMaxSuppRate;
+       unsigned char byTopCCKBasicRate;
+       unsigned char byTopOFDMBasicRate;
+       QWORD               qwCurrTSF;
+       unsigned int ii;
+       unsigned char abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C, 0x12, 0x18, 0x60};
+       unsigned char abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96};
+       unsigned char abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
+       unsigned short wSuppRate;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n");
+
+       if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
+               if ((pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) &&
+                   (pDevice->eEncryptionStatus != Ndis802_11Encryption2Enabled) &&
+                   (pDevice->eEncryptionStatus != Ndis802_11Encryption3Enabled)) {
+                       // encryption mode error
+                       *pStatus = CMD_STATUS_FAILURE;
+                       return;
+               }
+       }
+
+       pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
+       pMgmt->abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
+
+       if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
+               pMgmt->eCurrentPHYMode = pMgmt->byAPBBType;
+       } else {
+               if (pDevice->byBBType == BB_TYPE_11G)
+                       pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
+               if (pDevice->byBBType == BB_TYPE_11B)
+                       pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
+               if (pDevice->byBBType == BB_TYPE_11A)
+                       pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
+       }
+
+       if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
+               pMgmt->abyCurrSuppRates[1] = WLAN_RATES_MAXLEN_11B;
+               pMgmt->abyCurrExtSuppRates[1] = 0;
+               for (ii = 0; ii < 4; ii++)
+                       pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
+       } else {
+               pMgmt->abyCurrSuppRates[1] = 8;
+               pMgmt->abyCurrExtSuppRates[1] = 0;
+               for (ii = 0; ii < 8; ii++)
+                       pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
+       }
+
+       if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
+               pMgmt->abyCurrSuppRates[1] = 8;
+               pMgmt->abyCurrExtSuppRates[1] = 4;
+               for (ii = 0; ii < 4; ii++)
+                       pMgmt->abyCurrSuppRates[2+ii] =  abyCCK_RATE[ii];
+               for (ii = 4; ii < 8; ii++)
+                       pMgmt->abyCurrSuppRates[2+ii] =  abyOFDM_RATE[ii-4];
+               for (ii = 0; ii < 4; ii++)
+                       pMgmt->abyCurrExtSuppRates[2+ii] =  abyOFDM_RATE[ii+4];
+       }
+
+       // Disable Protect Mode
+       pDevice->bProtectMode = 0;
+       MACvDisableProtectMD(pDevice->PortOffset);
+
+       pDevice->bBarkerPreambleMd = 0;
+       MACvDisableBarkerPreambleMd(pDevice->PortOffset);
+
+       // Kyle Test 2003.11.04
+
+       // set HW beacon interval
+       if (pMgmt->wIBSSBeaconPeriod == 0)
+               pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
+
+       CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
+       // clear TSF counter
+       VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
+       // enable TSF counter
+       VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
+
+       // set Next TBTT
+       CARDvSetFirstNextTBTT(pDevice->PortOffset, pMgmt->wIBSSBeaconPeriod);
+
+       pMgmt->uIBSSChannel = pDevice->uChannel;
+
+       if (pMgmt->uIBSSChannel == 0)
+               pMgmt->uIBSSChannel = DEFAULT_IBSS_CHANNEL;
+
+       // set basic rate
+
+       RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                         (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, true,
+                         &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
+                         &byTopCCKBasicRate, &byTopOFDMBasicRate);
+
+       if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
+               pMgmt->eCurrMode = WMAC_MODE_ESS_AP;
+       }
+
+       if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
+               memcpy(pMgmt->abyIBSSDFSOwner, pDevice->abyCurrentNetAddr, 6);
+               pMgmt->byIBSSDFSRecovery = 10;
+               pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
+       }
+
+       // Adopt pre-configured IBSS vars to current vars
+       pMgmt->eCurrState = WMAC_STATE_STARTED;
+       pMgmt->wCurrBeaconPeriod = pMgmt->wIBSSBeaconPeriod;
+       pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
+       pMgmt->wCurrATIMWindow = pMgmt->wIBSSATIMWindow;
+       MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
+       pDevice->uCurrRSSI = 0;
+       pDevice->byCurrSQ = 0;
+       //memcpy(pMgmt->abyDesireSSID,pMgmt->abyAdHocSSID,
+       // ((PWLAN_IE_SSID)pMgmt->abyAdHocSSID)->len + WLAN_IEHDR_LEN);
+       memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+       memcpy(pMgmt->abyCurrSSID,
+              pMgmt->abyDesireSSID,
+              ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN
+);
+
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               // AP mode BSSID = MAC addr
+               memcpy(pMgmt->abyCurrBSSID, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+               DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "AP beacon created BSSID:%pM\n",
+                       pMgmt->abyCurrBSSID);
+       }
+
+       if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+               // BSSID selected must be randomized as spec 11.1.3
+               pMgmt->abyCurrBSSID[5] = (unsigned char) (LODWORD(qwCurrTSF) & 0x000000ff);
+               pMgmt->abyCurrBSSID[4] = (unsigned char)((LODWORD(qwCurrTSF) & 0x0000ff00) >> 8);
+               pMgmt->abyCurrBSSID[3] = (unsigned char)((LODWORD(qwCurrTSF) & 0x00ff0000) >> 16);
+               pMgmt->abyCurrBSSID[2] = (unsigned char)((LODWORD(qwCurrTSF) & 0x00000ff0) >> 4);
+               pMgmt->abyCurrBSSID[1] = (unsigned char)((LODWORD(qwCurrTSF) & 0x000ff000) >> 12);
+               pMgmt->abyCurrBSSID[0] = (unsigned char)((LODWORD(qwCurrTSF) & 0x0ff00000) >> 20);
+               pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0];
+               pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1];
+               pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2];
+               pMgmt->abyCurrBSSID[2] ^= pMgmt->abyMACAddr[3];
+               pMgmt->abyCurrBSSID[1] ^= pMgmt->abyMACAddr[4];
+               pMgmt->abyCurrBSSID[0] ^= pMgmt->abyMACAddr[5];
+               pMgmt->abyCurrBSSID[0] &= ~IEEE_ADDR_GROUP;
+               pMgmt->abyCurrBSSID[0] |= IEEE_ADDR_UNIVERSAL;
+
+               DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Adhoc beacon created bssid:%pM\n",
+                       pMgmt->abyCurrBSSID);
+       }
+
+       // Set Capability Info
+       pMgmt->wCurrCapInfo = 0;
+
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
+               pMgmt->byDTIMPeriod = DEFAULT_DTIM_PERIOD;
+               pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
+       }
+
+       if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_IBSS(1);
+       }
+
+       if (pDevice->bEncryptionEnable) {
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
+               if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
+                       if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
+                               pMgmt->byCSSPK = KEY_CTL_CCMP;
+                               pMgmt->byCSSGK = KEY_CTL_CCMP;
+                       } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
+                               pMgmt->byCSSPK = KEY_CTL_TKIP;
+                               pMgmt->byCSSGK = KEY_CTL_TKIP;
+                       } else {
+                               pMgmt->byCSSPK = KEY_CTL_NONE;
+                               pMgmt->byCSSGK = KEY_CTL_WEP;
+                       }
+               } else {
+                       pMgmt->byCSSPK = KEY_CTL_WEP;
+                       pMgmt->byCSSGK = KEY_CTL_WEP;
+               }
+       }
+
+       pMgmt->byERPContext = 0;
 
 //    memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
 
-    if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
-        CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_AP);
-    } else {
-        CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
-    }
-
-    CARDbSetPhyParameter(   pMgmt->pAdapter,
-                            pMgmt->eCurrentPHYMode,
-                            pMgmt->wCurrCapInfo,
-                            pMgmt->byERPContext,
-                            pMgmt->abyCurrSuppRates,
-                            pMgmt->abyCurrExtSuppRates
-                            );
-
-    CARDbSetBeaconPeriod(pMgmt->pAdapter, pMgmt->wIBSSBeaconPeriod);
-    // set channel and clear NAV
-    set_channel(pMgmt->pAdapter, pMgmt->uIBSSChannel);
-    pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
-
-    if (CARDbIsShortPreamble(pMgmt->pAdapter)) {
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
-    } else {
-        pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SHORTPREAMBLE(1));
-    }
-
-    if ((pMgmt->b11hEnable == true) &&
-        (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
-    } else {
-        pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SPECTRUMMNG(1));
-    }
-
-    pMgmt->eCurrState = WMAC_STATE_STARTED;
-    // Prepare beacon to send
-    if (bMgrPrepareBeaconToSend((void *)pDevice, pMgmt)) {
-        *pStatus = CMD_STATUS_SUCCESS;
-    }
-
-    return ;
-}
+       if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
+               CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_AP);
+       } else {
+               CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
+       }
+
+       CARDbSetPhyParameter(pMgmt->pAdapter,
+                            pMgmt->eCurrentPHYMode,
+                            pMgmt->wCurrCapInfo,
+                            pMgmt->byERPContext,
+                            pMgmt->abyCurrSuppRates,
+                            pMgmt->abyCurrExtSuppRates
+               );
+
+       CARDbSetBeaconPeriod(pMgmt->pAdapter, pMgmt->wIBSSBeaconPeriod);
+       // set channel and clear NAV
+       set_channel(pMgmt->pAdapter, pMgmt->uIBSSChannel);
+       pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
+
+       if (CARDbIsShortPreamble(pMgmt->pAdapter)) {
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
+       } else {
+               pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SHORTPREAMBLE(1));
+       }
 
+       if ((pMgmt->b11hEnable == true) &&
+           (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
+       } else {
+               pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SPECTRUMMNG(1));
+       }
+
+       pMgmt->eCurrState = WMAC_STATE_STARTED;
+       // Prepare beacon to send
+       if (bMgrPrepareBeaconToSend((void *)pDevice, pMgmt)) {
+               *pStatus = CMD_STATUS_SUCCESS;
+       }
 
+       return;
+}
 
 /*+
  *
@@ -2638,260 +2506,244 @@ vMgrCreateOwnIBSS(
  * Return Value:
  *    None.
  *
--*/
+ -*/
 
 void
 vMgrJoinBSSBegin(
-    void *hDeviceContext,
-    PCMD_STATUS pStatus
-    )
+       void *hDeviceContext,
+       PCMD_STATUS pStatus
+)
 {
+       PSDevice     pDevice = (PSDevice)hDeviceContext;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PKnownBSS       pCurr = NULL;
+       unsigned int ii, uu;
+       PWLAN_IE_SUPP_RATES pItemRates = NULL;
+       PWLAN_IE_SUPP_RATES pItemExtRates = NULL;
+       PWLAN_IE_SSID   pItemSSID;
+       unsigned int uRateLen = WLAN_RATES_MAXLEN;
+       unsigned short wMaxBasicRate = RATE_1M;
+       unsigned short wMaxSuppRate = RATE_1M;
+       unsigned short wSuppRate;
+       unsigned char byTopCCKBasicRate = RATE_1M;
+       unsigned char byTopOFDMBasicRate = RATE_1M;
+
+       for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+               if (pMgmt->sBSSList[ii].bActive == true)
+                       break;
+       }
+
+       if (ii == MAX_BSS_NUM) {
+               *pStatus = CMD_STATUS_RESOURCES;
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "BSS finding:BSS list is empty.\n");
+               return;
+       }
+
+       // memset(pMgmt->abyDesireBSSID, 0,  WLAN_BSSID_LEN);
+       // Search known BSS list for prefer BSSID or SSID
 
-    PSDevice     pDevice = (PSDevice)hDeviceContext;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    PKnownBSS       pCurr = NULL;
-    unsigned int ii, uu;
-    PWLAN_IE_SUPP_RATES pItemRates = NULL;
-    PWLAN_IE_SUPP_RATES pItemExtRates = NULL;
-    PWLAN_IE_SSID   pItemSSID;
-    unsigned int uRateLen = WLAN_RATES_MAXLEN;
-    unsigned short wMaxBasicRate = RATE_1M;
-    unsigned short wMaxSuppRate = RATE_1M;
-    unsigned short wSuppRate;
-    unsigned char byTopCCKBasicRate = RATE_1M;
-    unsigned char byTopOFDMBasicRate = RATE_1M;
-
-
-    for (ii = 0; ii < MAX_BSS_NUM; ii++) {
-        if (pMgmt->sBSSList[ii].bActive == true)
-            break;
-    }
-
-    if (ii == MAX_BSS_NUM) {
-       *pStatus = CMD_STATUS_RESOURCES;
-        DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "BSS finding:BSS list is empty.\n");
-       return;
-    }
-
-    // memset(pMgmt->abyDesireBSSID, 0,  WLAN_BSSID_LEN);
-    // Search known BSS list for prefer BSSID or SSID
-
-    pCurr = BSSpSearchBSSList(pDevice,
-                              pMgmt->abyDesireBSSID,
-                              pMgmt->abyDesireSSID,
-                              pMgmt->eConfigPHYMode
-                              );
-
-    if (pCurr == NULL){
-       *pStatus = CMD_STATUS_RESOURCES;
-       pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
-       DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Scanning [%s] not found, disconnected !\n", pItemSSID->abySSID);
-       return;
-    }
-
-    DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP(BSS) finding:Found a AP(BSS)..\n");
-    if (WLAN_GET_CAP_INFO_ESS(cpu_to_le16(pCurr->wCapInfo))){
-
-        if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA)||(pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
-
-    // patch for CISCO migration mode
+       pCurr = BSSpSearchBSSList(pDevice,
+                                 pMgmt->abyDesireBSSID,
+                                 pMgmt->abyDesireSSID,
+                                 pMgmt->eConfigPHYMode
+);
+
+       if (pCurr == NULL) {
+               *pStatus = CMD_STATUS_RESOURCES;
+               pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Scanning [%s] not found, disconnected !\n", pItemSSID->abySSID);
+               return;
+       }
+
+       DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP(BSS) finding:Found a AP(BSS)..\n");
+       if (WLAN_GET_CAP_INFO_ESS(cpu_to_le16(pCurr->wCapInfo))) {
+               if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) || (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
+                       // patch for CISCO migration mode
 /*
-            if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
-                if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
-                    // encryption mode error
-                    pMgmt->eCurrState = WMAC_STATE_IDLE;
-                    return;
-                }
-            } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
-                if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
-                    // encryption mode error
-                    pMgmt->eCurrState = WMAC_STATE_IDLE;
-                    return;
-                }
-            }
+  if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
+  if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+  // encryption mode error
+  pMgmt->eCurrState = WMAC_STATE_IDLE;
+  return;
+  }
+  } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
+  if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+  // encryption mode error
+  pMgmt->eCurrState = WMAC_STATE_IDLE;
+  return;
+  }
+  }
 */
-        }
+               }
 
 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-       //if(pDevice->bWPASuppWextEnabled == true)
-            Encyption_Rebuild(pDevice, pCurr);
+               Encyption_Rebuild(pDevice, pCurr);
 #endif
-        // Infrastructure BSS
-        s_vMgrSynchBSS(pDevice,
-                       WMAC_MODE_ESS_STA,
-                       pCurr,
-                       pStatus
-                       );
-
-        if (*pStatus == CMD_STATUS_SUCCESS){
-
-            // Adopt this BSS state vars in Mgmt Object
-            pMgmt->uCurrChannel = pCurr->uChannel;
-
-            memset(pMgmt->abyCurrSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
-            memset(pMgmt->abyCurrExtSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
-
-            if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
-                uRateLen = WLAN_RATES_MAXLEN_11B;
-            }
-
-            pItemRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates;
-            pItemExtRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates;
-
-            // Parse Support Rate IE
-            pItemRates->byElementID = WLAN_EID_SUPP_RATES;
-            pItemRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
-                                         pItemRates,
-                                         uRateLen);
-
-            // Parse Extension Support Rate IE
-            pItemExtRates->byElementID = WLAN_EID_EXTSUPP_RATES;
-            pItemExtRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abyExtSuppRates,
-                                            pItemExtRates,
-                                            uRateLen);
-            // Stuffing Rate IE
-            if ((pItemExtRates->len > 0) && (pItemRates->len < 8)) {
-                for (ii = 0; ii < (unsigned int)(8 - pItemRates->len); ) {
-                    pItemRates->abyRates[pItemRates->len + ii] = pItemExtRates->abyRates[ii];
-                    ii ++;
-                    if (pItemExtRates->len <= ii)
-                        break;
-                }
-                pItemRates->len += (unsigned char)ii;
-                if (pItemExtRates->len - ii > 0) {
-                    pItemExtRates->len -= (unsigned char)ii;
-                    for (uu = 0; uu < pItemExtRates->len; uu ++) {
-                        pItemExtRates->abyRates[uu] = pItemExtRates->abyRates[uu + ii];
-                    }
-                } else {
-                    pItemExtRates->len = 0;
-                }
-            }
-
-            RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, true,
-                              &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
-                              &byTopCCKBasicRate, &byTopOFDMBasicRate);
-
-            // TODO: deal with if wCapInfo the privacy is on, but station WEP is off
-            // TODO: deal with if wCapInfo the PS-Pollable is on.
-            pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
-            memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-            memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
-            memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-
-            pMgmt->eCurrMode = WMAC_MODE_ESS_STA;
-
-            pMgmt->eCurrState = WMAC_STATE_JOINTED;
-            // Adopt BSS state in Adapter Device Object
-            //pDevice->byOpMode = OP_MODE_INFRASTRUCTURE;
+               // Infrastructure BSS
+               s_vMgrSynchBSS(pDevice,
+                              WMAC_MODE_ESS_STA,
+                              pCurr,
+                              pStatus
+);
+
+               if (*pStatus == CMD_STATUS_SUCCESS) {
+                       // Adopt this BSS state vars in Mgmt Object
+                       pMgmt->uCurrChannel = pCurr->uChannel;
+
+                       memset(pMgmt->abyCurrSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
+                       memset(pMgmt->abyCurrExtSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
+
+                       if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
+                               uRateLen = WLAN_RATES_MAXLEN_11B;
+                       }
+
+                       pItemRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates;
+                       pItemExtRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates;
+
+                       // Parse Support Rate IE
+                       pItemRates->byElementID = WLAN_EID_SUPP_RATES;
+                       pItemRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
+                                                    pItemRates,
+                                                    uRateLen);
+
+                       // Parse Extension Support Rate IE
+                       pItemExtRates->byElementID = WLAN_EID_EXTSUPP_RATES;
+                       pItemExtRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abyExtSuppRates,
+                                                       pItemExtRates,
+                                                       uRateLen);
+                       // Stuffing Rate IE
+                       if ((pItemExtRates->len > 0) && (pItemRates->len < 8)) {
+                               for (ii = 0; ii < (unsigned int)(8 - pItemRates->len);) {
+                                       pItemRates->abyRates[pItemRates->len + ii] = pItemExtRates->abyRates[ii];
+                                       ii++;
+                                       if (pItemExtRates->len <= ii)
+                                               break;
+                               }
+                               pItemRates->len += (unsigned char)ii;
+                               if (pItemExtRates->len - ii > 0) {
+                                       pItemExtRates->len -= (unsigned char)ii;
+                                       for (uu = 0; uu < pItemExtRates->len; uu++) {
+                                               pItemExtRates->abyRates[uu] = pItemExtRates->abyRates[uu + ii];
+                                       }
+                               } else {
+                                       pItemExtRates->len = 0;
+                               }
+                       }
+
+                       RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, true,
+                                         &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
+                                         &byTopCCKBasicRate, &byTopOFDMBasicRate);
+
+                       // TODO: deal with if wCapInfo the privacy is on, but station WEP is off
+                       // TODO: deal with if wCapInfo the PS-Pollable is on.
+                       pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
+                       memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+                       memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
+                       memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
+
+                       pMgmt->eCurrMode = WMAC_MODE_ESS_STA;
+
+                       pMgmt->eCurrState = WMAC_STATE_JOINTED;
+                       // Adopt BSS state in Adapter Device Object
+                       //pDevice->byOpMode = OP_MODE_INFRASTRUCTURE;
 //            memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
 
-            // Add current BSS to Candidate list
-            // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
-            if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
-                bool bResult = bAdd_PMKID_Candidate((void *)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate: 1(%d)\n", bResult);
-                if (bResult == false) {
-                    vFlush_PMKID_Candidate((void *)pDevice);
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFlush_PMKID_Candidate: 4\n");
-                    bAdd_PMKID_Candidate((void *)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
-                }
-            }
-
-            // Preamble type auto-switch: if AP can receive short-preamble cap,
-            // we can turn on too.
-
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join ESS\n");
-
-
-
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"End of Join AP -- A/B/G Action\n");
-        }
-        else {
-            pMgmt->eCurrState = WMAC_STATE_IDLE;
-        };
-
-
-     }
-     else {
-        // ad-hoc mode BSS
-        if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
-
-            if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
-                if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
-                    // encryption mode error
-                    pMgmt->eCurrState = WMAC_STATE_IDLE;
-                    return;
-                }
-            } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
-                if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
-                    // encryption mode error
-                    pMgmt->eCurrState = WMAC_STATE_IDLE;
-                    return;
-                }
-            } else {
-                // encryption mode error
-                pMgmt->eCurrState = WMAC_STATE_IDLE;
-                return;
-            }
-        }
-
-        s_vMgrSynchBSS(pDevice,
-                       WMAC_MODE_IBSS_STA,
-                       pCurr,
-                       pStatus
-                       );
-
-        if (*pStatus == CMD_STATUS_SUCCESS){
-            // Adopt this BSS state vars in Mgmt Object
-            // TODO: check if CapInfo privacy on, but we don't..
-            pMgmt->uCurrChannel = pCurr->uChannel;
-
-
-            // Parse Support Rate IE
-            pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
-            pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
-                                                    (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                                                    WLAN_RATES_MAXLEN_11B);
-            // set basic rate
-            RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                              NULL, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
-                              &byTopCCKBasicRate, &byTopOFDMBasicRate);
-
-            pMgmt->wCurrCapInfo = pCurr->wCapInfo;
-            pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
-            memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
-            memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
-            memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
+                       // Add current BSS to Candidate list
+                       // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
+                       if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
+                               bool bResult = bAdd_PMKID_Candidate((void *)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bAdd_PMKID_Candidate: 1(%d)\n", bResult);
+                               if (bResult == false) {
+                                       vFlush_PMKID_Candidate((void *)pDevice);
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "vFlush_PMKID_Candidate: 4\n");
+                                       bAdd_PMKID_Candidate((void *)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
+                               }
+                       }
+
+                       // Preamble type auto-switch: if AP can receive short-preamble cap,
+                       // we can turn on too.
+
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Join ESS\n");
+
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "End of Join AP -- A/B/G Action\n");
+               } else {
+                       pMgmt->eCurrState = WMAC_STATE_IDLE;
+               };
+
+       } else {
+               // ad-hoc mode BSS
+               if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
+                       if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
+                               if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
+                                       // encryption mode error
+                                       pMgmt->eCurrState = WMAC_STATE_IDLE;
+                                       return;
+                               }
+                       } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
+                               if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
+                                       // encryption mode error
+                                       pMgmt->eCurrState = WMAC_STATE_IDLE;
+                                       return;
+                               }
+                       } else {
+                               // encryption mode error
+                               pMgmt->eCurrState = WMAC_STATE_IDLE;
+                               return;
+                       }
+               }
+
+               s_vMgrSynchBSS(pDevice,
+                              WMAC_MODE_IBSS_STA,
+                              pCurr,
+                              pStatus
+);
+
+               if (*pStatus == CMD_STATUS_SUCCESS) {
+                       // Adopt this BSS state vars in Mgmt Object
+                       // TODO: check if CapInfo privacy on, but we don't..
+                       pMgmt->uCurrChannel = pCurr->uChannel;
+
+                       // Parse Support Rate IE
+                       pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
+                       pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
+                                                               (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                                                               WLAN_RATES_MAXLEN_11B);
+                       // set basic rate
+                       RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                                         NULL, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
+                                         &byTopCCKBasicRate, &byTopOFDMBasicRate);
+
+                       pMgmt->wCurrCapInfo = pCurr->wCapInfo;
+                       pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
+                       memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
+                       memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
+                       memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
 //          pMgmt->wCurrATIMWindow = pCurr->wATIMWindow;
-            MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
-            pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
+                       MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
+                       pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
 
-            pMgmt->eCurrState = WMAC_STATE_STARTED;
-            // Adopt BSS state in Adapter Device Object
-            //pDevice->byOpMode = OP_MODE_ADHOC;
+                       pMgmt->eCurrState = WMAC_STATE_STARTED;
+                       // Adopt BSS state in Adapter Device Object
+                       //pDevice->byOpMode = OP_MODE_ADHOC;
 //            pDevice->bLinkPass = true;
 //            memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
 
-               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join IBSS ok:%pM\n",
-                       pMgmt->abyCurrBSSID);
-            // Preamble type auto-switch: if AP can receive short-preamble cap,
-            // and if registry setting is short preamble we can turn on too.
-
-            // Prepare beacon
-            bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
-        }
-        else {
-            pMgmt->eCurrState = WMAC_STATE_IDLE;
-        };
-     };
-    return;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Join IBSS ok:%pM\n",
+                               pMgmt->abyCurrBSSID);
+                       // Preamble type auto-switch: if AP can receive short-preamble cap,
+                       // and if registry setting is short preamble we can turn on too.
+
+                       // Prepare beacon
+                       bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
+               } else {
+                       pMgmt->eCurrState = WMAC_STATE_IDLE;
+               };
+       };
+       return;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -2901,215 +2753,199 @@ vMgrJoinBSSBegin(
  * Return Value:
  *    PCM_STATUS
  *
--*/
+ -*/
 static
 void
-s_vMgrSynchBSS (
-    PSDevice      pDevice,
-    unsigned int uBSSMode,
-    PKnownBSS     pCurr,
-    PCMD_STATUS  pStatus
-    )
+s_vMgrSynchBSS(
+       PSDevice      pDevice,
+       unsigned int uBSSMode,
+       PKnownBSS     pCurr,
+       PCMD_STATUS  pStatus
+)
 {
-    CARD_PHY_TYPE   ePhyType = PHY_TYPE_11B;
-    PSMgmtObject  pMgmt = pDevice->pMgmt;
+       CARD_PHY_TYPE   ePhyType = PHY_TYPE_11B;
+       PSMgmtObject  pMgmt = pDevice->pMgmt;
 //    int     ii;
-                                                     //1M,   2M,   5M,   11M,  18M,  24M,  36M,  54M
-    unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
-    unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
-                                                           //6M,   9M,   12M,  48M
-    unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
-    unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
-
-
-    *pStatus = CMD_STATUS_FAILURE;
-
-    if (s_bCipherMatch(pCurr,
-                       pDevice->eEncryptionStatus,
-                       &(pMgmt->byCSSPK),
-                       &(pMgmt->byCSSGK)) == false) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "s_bCipherMatch Fail .......\n");
-        return;
-    }
-
-    pMgmt->pCurrBSS = pCurr;
-
-    // if previous mode is IBSS.
-    if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-        MACvRegBitsOff(pDevice->PortOffset, MAC_REG_BCNDMACTL, BEACON_READY);
-        MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
-    }
-
-    // Init the BSS informations
-    pDevice->bCCK = true;
-    pDevice->bProtectMode = false;
-    MACvDisableProtectMD(pDevice->PortOffset);
-    pDevice->bBarkerPreambleMd = false;
-    MACvDisableBarkerPreambleMd(pDevice->PortOffset);
-    pDevice->bNonERPPresent = false;
-    pDevice->byPreambleType = 0;
-    pDevice->wBasicRate = 0;
-    // Set Basic Rate
-    CARDbAddBasicRate((void *)pDevice, RATE_1M);
-    // calculate TSF offset
-    // TSF Offset = Received Timestamp TSF - Marked Local's TSF
-    CARDbUpdateTSF(pDevice, pCurr->byRxRate, pCurr->qwBSSTimestamp, pCurr->qwLocalTSF);
-
-    CARDbSetBeaconPeriod(pDevice, pCurr->wBeaconInterval);
-
-    // set Next TBTT
-    // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
-    CARDvSetFirstNextTBTT(pDevice->PortOffset, pCurr->wBeaconInterval);
-
-    // set BSSID
-    MACvWriteBSSIDAddress(pDevice->PortOffset, pCurr->abyBSSID);
-
-    MACvReadBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
+       //1M,   2M,   5M,   11M,  18M,  24M,  36M,  54M
+       unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
+       unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
+       //6M,   9M,   12M,  48M
+       unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
+       unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
+
+       *pStatus = CMD_STATUS_FAILURE;
+
+       if (s_bCipherMatch(pCurr,
+                          pDevice->eEncryptionStatus,
+                          &(pMgmt->byCSSPK),
+                          &(pMgmt->byCSSGK)) == false) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "s_bCipherMatch Fail .......\n");
+               return;
+       }
+
+       pMgmt->pCurrBSS = pCurr;
+
+       // if previous mode is IBSS.
+       if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_BCNDMACTL, BEACON_READY);
+               MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
+       }
+
+       // Init the BSS informations
+       pDevice->bCCK = true;
+       pDevice->bProtectMode = false;
+       MACvDisableProtectMD(pDevice->PortOffset);
+       pDevice->bBarkerPreambleMd = false;
+       MACvDisableBarkerPreambleMd(pDevice->PortOffset);
+       pDevice->bNonERPPresent = false;
+       pDevice->byPreambleType = 0;
+       pDevice->wBasicRate = 0;
+       // Set Basic Rate
+       CARDbAddBasicRate((void *)pDevice, RATE_1M);
+       // calculate TSF offset
+       // TSF Offset = Received Timestamp TSF - Marked Local's TSF
+       CARDbUpdateTSF(pDevice, pCurr->byRxRate, pCurr->qwBSSTimestamp, pCurr->qwLocalTSF);
+
+       CARDbSetBeaconPeriod(pDevice, pCurr->wBeaconInterval);
+
+       // set Next TBTT
+       // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
+       CARDvSetFirstNextTBTT(pDevice->PortOffset, pCurr->wBeaconInterval);
+
+       // set BSSID
+       MACvWriteBSSIDAddress(pDevice->PortOffset, pCurr->abyBSSID);
+
+       MACvReadBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
 
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Sync:set CurrBSSID address = "
                "%pM\n", pMgmt->abyCurrBSSID);
 
-    if (pCurr->eNetworkTypeInUse == PHY_TYPE_11A) {
-        if ((pMgmt->eConfigPHYMode == PHY_TYPE_11A) ||
-            (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
-            ePhyType = PHY_TYPE_11A;
-        } else {
-            return;
-        }
-    } else if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
-        if ((pMgmt->eConfigPHYMode == PHY_TYPE_11B) ||
-            (pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
-            (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
-            ePhyType = PHY_TYPE_11B;
-        } else {
-            return;
-        }
-    } else {
-        if ((pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
-            (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
-            ePhyType = PHY_TYPE_11G;
-        } else if (pMgmt->eConfigPHYMode == PHY_TYPE_11B) {
-            ePhyType = PHY_TYPE_11B;
-        } else {
-            return;
-        }
-    }
-
-    if (ePhyType == PHY_TYPE_11A) {
-        memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesA[0], sizeof(abyCurrSuppRatesA));
-        pMgmt->abyCurrExtSuppRates[1] = 0;
-    } else if (ePhyType == PHY_TYPE_11B) {
-        memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesB[0], sizeof(abyCurrSuppRatesB));
-        pMgmt->abyCurrExtSuppRates[1] = 0;
-    } else {
-        memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesG[0], sizeof(abyCurrSuppRatesG));
-        memcpy(pMgmt->abyCurrExtSuppRates, &abyCurrExtSuppRatesG[0], sizeof(abyCurrExtSuppRatesG));
-    }
-
-
-    if (WLAN_GET_CAP_INFO_ESS(pCurr->wCapInfo)) {
-        CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, OP_MODE_INFRASTRUCTURE);
-        // Add current BSS to Candidate list
-        // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
-        if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
-            CARDbAdd_PMKID_Candidate(pMgmt->pAdapter, pMgmt->abyCurrBSSID, pCurr->sRSNCapObj.bRSNCapExist, pCurr->sRSNCapObj.wRSNCap);
-        }
-    } else {
-        CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, OP_MODE_ADHOC);
-    }
-
-    if (CARDbSetPhyParameter(   pMgmt->pAdapter,
-                                ePhyType,
-                                pCurr->wCapInfo,
-                                pCurr->sERP.byERP,
-                                pMgmt->abyCurrSuppRates,
-                                pMgmt->abyCurrExtSuppRates
-                            ) != true) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "<----s_bSynchBSS Set Phy Mode Fail [%d]\n", ePhyType);
-        return;
-    }
-    // set channel and clear NAV
-    if (set_channel(pMgmt->pAdapter, pCurr->uChannel) == false) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "<----s_bSynchBSS Set Channel [%d]\n", pCurr->uChannel);
-        return;
-    }
+       if (pCurr->eNetworkTypeInUse == PHY_TYPE_11A) {
+               if ((pMgmt->eConfigPHYMode == PHY_TYPE_11A) ||
+                   (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
+                       ePhyType = PHY_TYPE_11A;
+               } else {
+                       return;
+               }
+       } else if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
+               if ((pMgmt->eConfigPHYMode == PHY_TYPE_11B) ||
+                   (pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
+                   (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
+                       ePhyType = PHY_TYPE_11B;
+               } else {
+                       return;
+               }
+       } else {
+               if ((pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
+                   (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
+                       ePhyType = PHY_TYPE_11G;
+               } else if (pMgmt->eConfigPHYMode == PHY_TYPE_11B) {
+                       ePhyType = PHY_TYPE_11B;
+               } else {
+                       return;
+               }
+       }
 
-/*
-    for (ii=0;ii<BB_VGA_LEVEL;ii++) {
-        if (pCurr->ldBmMAX< pDevice->ldBmThreshold[ii]) {
-            pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
-            break;
-        }
-    }
-
-    if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RSSI[%d] NewGain[%d] OldGain[%d] \n",
-                        (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
-        printk("RSSI[%d] NewGain[%d] OldGain[%d] \n",
-                        (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
-        BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
-    }
-    printk("ldBmMAX[%d] NewGain[%d] OldGain[%d] \n",
-           (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
-*/
-    pMgmt->uCurrChannel = pCurr->uChannel;
-    pMgmt->eCurrentPHYMode = ePhyType;
-    pMgmt->byERPContext = pCurr->sERP.byERP;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Sync:Set to channel = [%d]\n", (int)pCurr->uChannel);
+       if (ePhyType == PHY_TYPE_11A) {
+               memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesA[0], sizeof(abyCurrSuppRatesA));
+               pMgmt->abyCurrExtSuppRates[1] = 0;
+       } else if (ePhyType == PHY_TYPE_11B) {
+               memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesB[0], sizeof(abyCurrSuppRatesB));
+               pMgmt->abyCurrExtSuppRates[1] = 0;
+       } else {
+               memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesG[0], sizeof(abyCurrSuppRatesG));
+               memcpy(pMgmt->abyCurrExtSuppRates, &abyCurrExtSuppRatesG[0], sizeof(abyCurrExtSuppRatesG));
+       }
+
+       if (WLAN_GET_CAP_INFO_ESS(pCurr->wCapInfo)) {
+               CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, OP_MODE_INFRASTRUCTURE);
+               // Add current BSS to Candidate list
+               // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
+               if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
+                       CARDbAdd_PMKID_Candidate(pMgmt->pAdapter, pMgmt->abyCurrBSSID, pCurr->sRSNCapObj.bRSNCapExist, pCurr->sRSNCapObj.wRSNCap);
+               }
+       } else {
+               CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, OP_MODE_ADHOC);
+       }
 
+       if (CARDbSetPhyParameter(pMgmt->pAdapter,
+                                ePhyType,
+                                pCurr->wCapInfo,
+                                pCurr->sERP.byERP,
+                                pMgmt->abyCurrSuppRates,
+                                pMgmt->abyCurrExtSuppRates
+                   ) != true) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "<----s_bSynchBSS Set Phy Mode Fail [%d]\n", ePhyType);
+               return;
+       }
+       // set channel and clear NAV
+       if (set_channel(pMgmt->pAdapter, pCurr->uChannel) == false) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "<----s_bSynchBSS Set Channel [%d]\n", pCurr->uChannel);
+               return;
+       }
 
-    *pStatus = CMD_STATUS_SUCCESS;
+/*
+  for (ii=0; ii<BB_VGA_LEVEL; ii++) {
+  if (pCurr->ldBmMAX< pDevice->ldBmThreshold[ii]) {
+  pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
+  break;
+  }
+  }
 
+  if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "RSSI[%d] NewGain[%d] OldGain[%d] \n",
+  (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
+  printk("RSSI[%d] NewGain[%d] OldGain[%d] \n",
+  (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
+  BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
+  }
+  printk("ldBmMAX[%d] NewGain[%d] OldGain[%d] \n",
+  (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
+*/
+       pMgmt->uCurrChannel = pCurr->uChannel;
+       pMgmt->eCurrentPHYMode = ePhyType;
+       pMgmt->byERPContext = pCurr->sERP.byERP;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Sync:Set to channel = [%d]\n", (int)pCurr->uChannel);
 
-    return;
+       *pStatus = CMD_STATUS_SUCCESS;
+
+       return;
 };
 
 //mike add: fix NetworkManager 0.7.0 hidden ssid mode in WPA encryption
 //                   ,need reset eAuthenMode and eEncryptionStatus
- static void  Encyption_Rebuild(
-    PSDevice pDevice,
-    PKnownBSS pCurr
- )
- {
-  PSMgmtObject  pMgmt = &(pDevice->sMgmtObj);
- // unsigned int ii , uSameBssidNum=0;
-
-        //  for (ii = 0; ii < MAX_BSS_NUM; ii++) {
-          //   if (pMgmt->sBSSList[ii].bActive &&
-            //      !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
-             //       uSameBssidNum++;
-               //   }
-           // }
-  //   if( uSameBssidNum>=2) {  //we only check AP in hidden sssid  mode
-        if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||           //networkmanager 0.7.0 does not give the pairwise-key selection,
-             (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {         // so we need re-select it according to real pairwise-key info.
-               if(pCurr->bWPAValid == true)  {   //WPA-PSK
-                          pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
-                   if(pCurr->abyPKType[0] == WPA_TKIP) {
-                       pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;    //TKIP
-                       PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-TKIP]\n");
-                     }
-                  else if(pCurr->abyPKType[0] == WPA_AESCCMP) {
-                       pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;    //AES
-                          PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n");
-                    }
-                       }
-               else if(pCurr->bWPA2Valid == true) {  //WPA2-PSK
-                         pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
-                      if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) {
-                          pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;     //TKIP
-                             PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-TKIP]\n");
-                       }
-                      else if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_CCMP) {
-                          pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;    //AES
-                            PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-AES]\n");
-                       }
-                       }
-              }
-        //  }
-      return;
- }
-
+static void  Encyption_Rebuild(
+       PSDevice pDevice,
+       PKnownBSS pCurr
+)
+{
+       PSMgmtObject  pMgmt = &(pDevice->sMgmtObj);
+
+       if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||           //networkmanager 0.7.0 does not give the pairwise-key selection,
+           (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {         // so we need re-select it according to real pairwise-key info.
+               if (pCurr->bWPAValid == true)  {   //WPA-PSK
+                       pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
+                       if (pCurr->abyPKType[0] == WPA_TKIP) {
+                               pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;    //TKIP
+                               PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-TKIP]\n");
+                       } else if (pCurr->abyPKType[0] == WPA_AESCCMP) {
+                               pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;    //AES
+                               PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n");
+                       }
+               } else if (pCurr->bWPA2Valid == true) {  //WPA2-PSK
+                       pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
+                       if (pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) {
+                               pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;     //TKIP
+                               PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-TKIP]\n");
+                       } else if (pCurr->abyCSSPK[0] == WLAN_11i_CSS_CCMP) {
+                               pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;    //AES
+                               PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-AES]\n");
+                       }
+               }
+       }
+       //  }
+       return;
+}
 
 /*+
  *
@@ -3120,298 +2956,290 @@ s_vMgrSynchBSS (
  * Return Value:
  *    void
  *
--*/
+ -*/
 
 static
 void
 s_vMgrFormatTIM(
-    PSMgmtObject pMgmt,
-    PWLAN_IE_TIM pTIM
-    )
+       PSMgmtObject pMgmt,
+       PWLAN_IE_TIM pTIM
+)
 {
-    unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
-    unsigned char byMap;
-    unsigned int ii, jj;
-    bool bStartFound = false;
-    bool bMulticast = false;
-    unsigned short wStartIndex = 0;
-    unsigned short wEndIndex = 0;
-
-
-    // Find size of partial virtual bitmap
-    for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
-        byMap = pMgmt->abyPSTxMap[ii];
-        if (!ii) {
-            // Mask out the broadcast bit which is indicated separately.
-            bMulticast = (byMap & byMask[0]) != 0;
-            if(bMulticast) {
-               pMgmt->sNodeDBTable[0].bRxPSPoll = true;
-            }
-            byMap = 0;
-        }
-        if (byMap) {
-            if (!bStartFound) {
-                bStartFound = true;
-                wStartIndex = ii;
-            }
-            wEndIndex = ii;
-        }
-    }
-
-
-    // Round start index down to nearest even number
-    wStartIndex &=  ~BIT0;
-
-    // Round end index up to nearest even number
-    wEndIndex = ((wEndIndex + 1) & ~BIT0);
-
-    // Size of element payload
-
-    pTIM->len =  3 + (wEndIndex - wStartIndex) + 1;
-
-    // Fill in the Fixed parts of the TIM
-    pTIM->byDTIMCount = pMgmt->byDTIMCount;
-    pTIM->byDTIMPeriod = pMgmt->byDTIMPeriod;
-    pTIM->byBitMapCtl = (bMulticast ? TIM_MULTICAST_MASK : 0) |
-        (((wStartIndex >> 1) << 1) & TIM_BITMAPOFFSET_MASK);
-
-    // Append variable part of TIM
-
-    for (ii = wStartIndex, jj =0 ; ii <= wEndIndex; ii++, jj++) {
-         pTIM->byVirtBitMap[jj] = pMgmt->abyPSTxMap[ii];
-    }
-
-    // Aid = 0 don't used.
-    pTIM->byVirtBitMap[0]  &= ~BIT0;
-}
+       unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
+       unsigned char byMap;
+       unsigned int ii, jj;
+       bool bStartFound = false;
+       bool bMulticast = false;
+       unsigned short wStartIndex = 0;
+       unsigned short wEndIndex = 0;
+
+       // Find size of partial virtual bitmap
+       for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
+               byMap = pMgmt->abyPSTxMap[ii];
+               if (!ii) {
+                       // Mask out the broadcast bit which is indicated separately.
+                       bMulticast = (byMap & byMask[0]) != 0;
+                       if (bMulticast) {
+                               pMgmt->sNodeDBTable[0].bRxPSPoll = true;
+                       }
+                       byMap = 0;
+               }
+               if (byMap) {
+                       if (!bStartFound) {
+                               bStartFound = true;
+                               wStartIndex = ii;
+                       }
+                       wEndIndex = ii;
+               }
+       }
+
+       // Round start index down to nearest even number
+       wStartIndex &=  ~BIT0;
+
+       // Round end index up to nearest even number
+       wEndIndex = ((wEndIndex + 1) & ~BIT0);
+
+       // Size of element payload
+
+       pTIM->len =  3 + (wEndIndex - wStartIndex) + 1;
+
+       // Fill in the Fixed parts of the TIM
+       pTIM->byDTIMCount = pMgmt->byDTIMCount;
+       pTIM->byDTIMPeriod = pMgmt->byDTIMPeriod;
+       pTIM->byBitMapCtl = (bMulticast ? TIM_MULTICAST_MASK : 0) |
+               (((wStartIndex >> 1) << 1) & TIM_BITMAPOFFSET_MASK);
 
+       // Append variable part of TIM
+
+       for (ii = wStartIndex, jj = 0; ii <= wEndIndex; ii++, jj++) {
+               pTIM->byVirtBitMap[jj] = pMgmt->abyPSTxMap[ii];
+       }
+
+       // Aid = 0 don't used.
+       pTIM->byVirtBitMap[0]  &= ~BIT0;
+}
 
 /*+
  *
  * Routine Description:
- *  Constructs an Beacon frame( Ad-hoc mode)
+ *  Constructs an Beacon frame(Ad-hoc mode)
  *
  *
  * Return Value:
  *    PTR to frame; or NULL on allocation failure
  *
--*/
+ -*/
 
 static
 PSTxMgmtPacket
 s_MgrMakeBeacon(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned short wCurrCapInfo,
-    unsigned short wCurrBeaconPeriod,
-    unsigned int uCurrChannel,
-    unsigned short wCurrATIMWinodw,
-    PWLAN_IE_SSID pCurrSSID,
-    unsigned char *pCurrBSSID,
-    PWLAN_IE_SUPP_RATES pCurrSuppRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned short wCurrCapInfo,
+       unsigned short wCurrBeaconPeriod,
+       unsigned int uCurrChannel,
+       unsigned short wCurrATIMWinodw,
+       PWLAN_IE_SSID pCurrSSID,
+       unsigned char *pCurrBSSID,
+       PWLAN_IE_SUPP_RATES pCurrSuppRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+)
 {
-    PSTxMgmtPacket      pTxPacket = NULL;
-    WLAN_FR_BEACON      sFrame;
-    unsigned char abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-    unsigned char *pbyBuffer;
-    unsigned int uLength = 0;
-    PWLAN_IE_IBSS_DFS   pIBSSDFS = NULL;
-    unsigned int ii;
-
-    // prepare beacon frame
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_BEACON_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    // Setup the sFrame structure.
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_BEACON_FR_MAXLEN;
-    vMgrEncodeBeacon(&sFrame);
-    // Setup the header
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-        (
-        WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-        WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_BEACON)
-        ));
-
-    if (pDevice->bEnablePSMode) {
-        sFrame.pHdr->sA3.wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_PWRMGT(1));
-    }
-
-    memcpy( sFrame.pHdr->sA3.abyAddr1, abyBroadcastAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
-    *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
-    *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
-    // Copy SSID
-    sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
-    sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSSID,
-             pCurrSSID,
-             ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
-            );
-    // Copy the rate set
-    sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-    sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSuppRates,
-           pCurrSuppRates,
-           ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
-          );
-    // DS parameter
-    if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
-        sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
-        sFrame.len += (1) + WLAN_IEHDR_LEN;
-        sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
-        sFrame.pDSParms->len = 1;
-        sFrame.pDSParms->byCurrChannel = (unsigned char)uCurrChannel;
-    }
-    // TIM field
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-        sFrame.pTIM = (PWLAN_IE_TIM)(sFrame.pBuf + sFrame.len);
-        sFrame.pTIM->byElementID = WLAN_EID_TIM;
-        s_vMgrFormatTIM(pMgmt, sFrame.pTIM);
-        sFrame.len += (WLAN_IEHDR_LEN + sFrame.pTIM->len);
-    }
-
-    if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-
-        // IBSS parameter
-        sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
-        sFrame.len += (2) + WLAN_IEHDR_LEN;
-        sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
-        sFrame.pIBSSParms->len = 2;
-        sFrame.pIBSSParms->wATIMWindow = wCurrATIMWinodw;
-        if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
-            /* RSN parameter */
-            sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
-            sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
-            sFrame.pRSNWPA->len = 12;
-            sFrame.pRSNWPA->abyOUI[0] = 0x00;
-            sFrame.pRSNWPA->abyOUI[1] = 0x50;
-            sFrame.pRSNWPA->abyOUI[2] = 0xf2;
-            sFrame.pRSNWPA->abyOUI[3] = 0x01;
-            sFrame.pRSNWPA->wVersion = 1;
-            sFrame.pRSNWPA->abyMulticast[0] = 0x00;
-            sFrame.pRSNWPA->abyMulticast[1] = 0x50;
-            sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
-            if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
-                sFrame.pRSNWPA->abyMulticast[3] = 0x04;//AES
-            else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
-                sFrame.pRSNWPA->abyMulticast[3] = 0x02;//TKIP
-            else if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled)
-                sFrame.pRSNWPA->abyMulticast[3] = 0x01;//WEP40
-            else
-                sFrame.pRSNWPA->abyMulticast[3] = 0x00;//NONE
-
-            // Pairwise Key Cipher Suite
-            sFrame.pRSNWPA->wPKCount = 0;
-            // Auth Key Management Suite
-            *((unsigned short *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
-            sFrame.pRSNWPA->len +=2;
-
-            // RSN Capabilities
-            *((unsigned short *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
-            sFrame.pRSNWPA->len +=2;
-            sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
-        }
-    }
-
-    if ((pMgmt->b11hEnable == true) &&
-        (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
-        // Country IE
-        pbyBuffer = (unsigned char *)(sFrame.pBuf + sFrame.len);
-        set_country_IE(pMgmt->pAdapter, pbyBuffer);
-        set_country_info(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
-        uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
-        pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
-        // Power Constrain IE
-        ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
-        ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
-        ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
-        pbyBuffer += (1) + WLAN_IEHDR_LEN;
-        uLength += (1) + WLAN_IEHDR_LEN;
-        if (pMgmt->bSwitchChannel == true) {
-            // Channel Switch IE
-            ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
-            ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
-            ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
-            ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = get_channel_number(pMgmt->pAdapter, pMgmt->byNewChannel);
-            ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
-            pbyBuffer += (3) + WLAN_IEHDR_LEN;
-            uLength += (3) + WLAN_IEHDR_LEN;
-        }
-        // TPC report
-        ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
-        ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
-        ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
-        ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
-        pbyBuffer += (2) + WLAN_IEHDR_LEN;
-        uLength += (2) + WLAN_IEHDR_LEN;
-        // IBSS DFS
-        if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
-            pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
-            pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
-            pIBSSDFS->len = 7;
-            memcpy(   pIBSSDFS->abyDFSOwner,
-                        pMgmt->abyIBSSDFSOwner,
-                        6);
-            pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
-            pbyBuffer += (7) + WLAN_IEHDR_LEN;
-            uLength += (7) + WLAN_IEHDR_LEN;
-            for(ii=CB_MAX_CHANNEL_24G+1; ii<=CB_MAX_CHANNEL; ii++ ) {
-                if (get_channel_map_info(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1) == true) {
-                    pbyBuffer += 2;
-                    uLength += 2;
-                    pIBSSDFS->len += 2;
-                }
-            }
-        }
-        sFrame.len += uLength;
-    }
-
-    if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
-        sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
-        sFrame.len += 1 + WLAN_IEHDR_LEN;
-        sFrame.pERP->byElementID = WLAN_EID_ERP;
-        sFrame.pERP->len = 1;
-        sFrame.pERP->byContext = 0;
-        if (pDevice->bProtectMode == true)
-            sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
-        if (pDevice->bNonERPPresent == true)
-            sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
-        if (pDevice->bBarkerPreambleMd == true)
-            sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
-    }
-    if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
-        sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-        sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
-        memcpy(sFrame.pExtSuppRates,
-             pCurrExtSuppRates,
-             ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
-             );
-    }
-    // hostapd wpa/wpa2 IE
-    if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
-         if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
-             if (pMgmt->wWPAIELen != 0) {
-                 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
-                 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
-                 sFrame.len += pMgmt->wWPAIELen;
-             }
-         }
-    }
-
-    /* Adjust the length fields */
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-
-    return pTxPacket;
-}
+       PSTxMgmtPacket      pTxPacket = NULL;
+       WLAN_FR_BEACON      sFrame;
+       unsigned char abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+       unsigned char *pbyBuffer;
+       unsigned int uLength = 0;
+       PWLAN_IE_IBSS_DFS   pIBSSDFS = NULL;
+       unsigned int ii;
+
+       // prepare beacon frame
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_BEACON_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       // Setup the sFrame structure.
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_BEACON_FR_MAXLEN;
+       vMgrEncodeBeacon(&sFrame);
+       // Setup the header
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_BEACON)
+));
+
+       if (pDevice->bEnablePSMode) {
+               sFrame.pHdr->sA3.wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_PWRMGT(1));
+       }
 
+       memcpy(sFrame.pHdr->sA3.abyAddr1, abyBroadcastAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
+       *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
+       *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
+       // Copy SSID
+       sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
+       sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSSID,
+              pCurrSSID,
+              ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
+);
+       // Copy the rate set
+       sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+       sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSuppRates,
+              pCurrSuppRates,
+              ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
+);
+       // DS parameter
+       if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
+               sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
+               sFrame.len += (1) + WLAN_IEHDR_LEN;
+               sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
+               sFrame.pDSParms->len = 1;
+               sFrame.pDSParms->byCurrChannel = (unsigned char)uCurrChannel;
+       }
+       // TIM field
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               sFrame.pTIM = (PWLAN_IE_TIM)(sFrame.pBuf + sFrame.len);
+               sFrame.pTIM->byElementID = WLAN_EID_TIM;
+               s_vMgrFormatTIM(pMgmt, sFrame.pTIM);
+               sFrame.len += (WLAN_IEHDR_LEN + sFrame.pTIM->len);
+       }
 
+       if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
+               // IBSS parameter
+               sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
+               sFrame.len += (2) + WLAN_IEHDR_LEN;
+               sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
+               sFrame.pIBSSParms->len = 2;
+               sFrame.pIBSSParms->wATIMWindow = wCurrATIMWinodw;
+               if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
+                       /* RSN parameter */
+                       sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
+                       sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
+                       sFrame.pRSNWPA->len = 12;
+                       sFrame.pRSNWPA->abyOUI[0] = 0x00;
+                       sFrame.pRSNWPA->abyOUI[1] = 0x50;
+                       sFrame.pRSNWPA->abyOUI[2] = 0xf2;
+                       sFrame.pRSNWPA->abyOUI[3] = 0x01;
+                       sFrame.pRSNWPA->wVersion = 1;
+                       sFrame.pRSNWPA->abyMulticast[0] = 0x00;
+                       sFrame.pRSNWPA->abyMulticast[1] = 0x50;
+                       sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
+                       if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
+                               sFrame.pRSNWPA->abyMulticast[3] = 0x04;//AES
+                       else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
+                               sFrame.pRSNWPA->abyMulticast[3] = 0x02;//TKIP
+                       else if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled)
+                               sFrame.pRSNWPA->abyMulticast[3] = 0x01;//WEP40
+                       else
+                               sFrame.pRSNWPA->abyMulticast[3] = 0x00;//NONE
+
+                       // Pairwise Key Cipher Suite
+                       sFrame.pRSNWPA->wPKCount = 0;
+                       // Auth Key Management Suite
+                       *((unsigned short *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len)) = 0;
+                       sFrame.pRSNWPA->len += 2;
+
+                       // RSN Capabilities
+                       *((unsigned short *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len)) = 0;
+                       sFrame.pRSNWPA->len += 2;
+                       sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
+               }
+       }
 
+       if ((pMgmt->b11hEnable == true) &&
+           (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
+               // Country IE
+               pbyBuffer = (unsigned char *)(sFrame.pBuf + sFrame.len);
+               set_country_IE(pMgmt->pAdapter, pbyBuffer);
+               set_country_info(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
+               uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
+               pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
+               // Power Constrain IE
+               ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
+               ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
+               ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
+               pbyBuffer += (1) + WLAN_IEHDR_LEN;
+               uLength += (1) + WLAN_IEHDR_LEN;
+               if (pMgmt->bSwitchChannel == true) {
+                       // Channel Switch IE
+                       ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
+                       ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
+                       ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
+                       ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = get_channel_number(pMgmt->pAdapter, pMgmt->byNewChannel);
+                       ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
+                       pbyBuffer += (3) + WLAN_IEHDR_LEN;
+                       uLength += (3) + WLAN_IEHDR_LEN;
+               }
+               // TPC report
+               ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
+               ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
+               ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
+               ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
+               pbyBuffer += (2) + WLAN_IEHDR_LEN;
+               uLength += (2) + WLAN_IEHDR_LEN;
+               // IBSS DFS
+               if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
+                       pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
+                       pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
+                       pIBSSDFS->len = 7;
+                       memcpy(pIBSSDFS->abyDFSOwner,
+                              pMgmt->abyIBSSDFSOwner,
+                              6);
+                       pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
+                       pbyBuffer += (7) + WLAN_IEHDR_LEN;
+                       uLength += (7) + WLAN_IEHDR_LEN;
+                       for (ii = CB_MAX_CHANNEL_24G+1; ii <= CB_MAX_CHANNEL; ii++) {
+                               if (get_channel_map_info(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1) == true) {
+                                       pbyBuffer += 2;
+                                       uLength += 2;
+                                       pIBSSDFS->len += 2;
+                               }
+                       }
+               }
+               sFrame.len += uLength;
+       }
 
+       if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
+               sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
+               sFrame.len += 1 + WLAN_IEHDR_LEN;
+               sFrame.pERP->byElementID = WLAN_EID_ERP;
+               sFrame.pERP->len = 1;
+               sFrame.pERP->byContext = 0;
+               if (pDevice->bProtectMode == true)
+                       sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
+               if (pDevice->bNonERPPresent == true)
+                       sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
+               if (pDevice->bBarkerPreambleMd == true)
+                       sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
+       }
+       if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
+               sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+               sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
+               memcpy(sFrame.pExtSuppRates,
+                      pCurrExtSuppRates,
+                      ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
+);
+       }
+       // hostapd wpa/wpa2 IE
+       if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
+               if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
+                       if (pMgmt->wWPAIELen != 0) {
+                               sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
+                               memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
+                               sFrame.len += pMgmt->wWPAIELen;
+                       }
+               }
+       }
+
+       /* Adjust the length fields */
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
+
+       return pTxPacket;
+}
 
 /*+
  *
@@ -3422,187 +3250,180 @@ s_MgrMakeBeacon(
  * Return Value:
  *    PTR to frame; or NULL on allocation failure
  *
--*/
-
-
-
+ -*/
 
 PSTxMgmtPacket
 s_MgrMakeProbeResponse(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned short wCurrCapInfo,
-    unsigned short wCurrBeaconPeriod,
-    unsigned int uCurrChannel,
-    unsigned short wCurrATIMWinodw,
-    unsigned char *pDstAddr,
-    PWLAN_IE_SSID pCurrSSID,
-    unsigned char *pCurrBSSID,
-    PWLAN_IE_SUPP_RATES pCurrSuppRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
-    unsigned char byPHYType
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned short wCurrCapInfo,
+       unsigned short wCurrBeaconPeriod,
+       unsigned int uCurrChannel,
+       unsigned short wCurrATIMWinodw,
+       unsigned char *pDstAddr,
+       PWLAN_IE_SSID pCurrSSID,
+       unsigned char *pCurrBSSID,
+       PWLAN_IE_SUPP_RATES pCurrSuppRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
+       unsigned char byPHYType
+)
 {
-    PSTxMgmtPacket      pTxPacket = NULL;
-    WLAN_FR_PROBERESP   sFrame;
-    unsigned char *pbyBuffer;
-    unsigned int uLength = 0;
-    PWLAN_IE_IBSS_DFS   pIBSSDFS = NULL;
-    unsigned int ii;
-
-
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBERESP_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    // Setup the sFrame structure.
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_PROBERESP_FR_MAXLEN;
-    vMgrEncodeProbeResponse(&sFrame);
-    // Setup the header
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-        (
-        WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-        WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBERESP)
-        ));
-    memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
-    *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
-    *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
-
-    if (byPHYType == BB_TYPE_11B) {
-        *sFrame.pwCapInfo &= cpu_to_le16((unsigned short)~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)));
-    }
-
-    // Copy SSID
-    sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
-    sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSSID,
-           pCurrSSID,
-           ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
-           );
-    // Copy the rate set
-    sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-
-    sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSuppRates,
-           pCurrSuppRates,
-           ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
-          );
-
-    // DS parameter
-    if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
-        sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
-        sFrame.len += (1) + WLAN_IEHDR_LEN;
-        sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
-        sFrame.pDSParms->len = 1;
-        sFrame.pDSParms->byCurrChannel = (unsigned char)uCurrChannel;
-    }
-
-    if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
-        // IBSS parameter
-        sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
-        sFrame.len += (2) + WLAN_IEHDR_LEN;
-        sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
-        sFrame.pIBSSParms->len = 2;
-        sFrame.pIBSSParms->wATIMWindow = 0;
-    }
-    if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
-        sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
-        sFrame.len += 1 + WLAN_IEHDR_LEN;
-        sFrame.pERP->byElementID = WLAN_EID_ERP;
-        sFrame.pERP->len = 1;
-        sFrame.pERP->byContext = 0;
-        if (pDevice->bProtectMode == true)
-            sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
-        if (pDevice->bNonERPPresent == true)
-            sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
-        if (pDevice->bBarkerPreambleMd == true)
-            sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
-    }
-
-    if ((pMgmt->b11hEnable == true) &&
-        (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
-        // Country IE
-        pbyBuffer = (unsigned char *)(sFrame.pBuf + sFrame.len);
-        set_country_IE(pMgmt->pAdapter, pbyBuffer);
-        set_country_info(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
-        uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
-        pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
-        // Power Constrain IE
-        ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
-        ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
-        ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
-        pbyBuffer += (1) + WLAN_IEHDR_LEN;
-        uLength += (1) + WLAN_IEHDR_LEN;
-        if (pMgmt->bSwitchChannel == true) {
-            // Channel Switch IE
-            ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
-            ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
-            ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
-            ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = get_channel_number(pMgmt->pAdapter, pMgmt->byNewChannel);
-            ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
-            pbyBuffer += (3) + WLAN_IEHDR_LEN;
-            uLength += (3) + WLAN_IEHDR_LEN;
-        }
-        // TPC report
-        ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
-        ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
-        ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
-        ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
-        pbyBuffer += (2) + WLAN_IEHDR_LEN;
-        uLength += (2) + WLAN_IEHDR_LEN;
-        // IBSS DFS
-        if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
-            pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
-            pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
-            pIBSSDFS->len = 7;
-            memcpy(   pIBSSDFS->abyDFSOwner,
-                        pMgmt->abyIBSSDFSOwner,
-                        6);
-            pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
-            pbyBuffer += (7) + WLAN_IEHDR_LEN;
-            uLength += (7) + WLAN_IEHDR_LEN;
-            for(ii=CB_MAX_CHANNEL_24G+1; ii<=CB_MAX_CHANNEL; ii++ ) {
-                if (get_channel_map_info(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1) == true) {
-                    pbyBuffer += 2;
-                    uLength += 2;
-                    pIBSSDFS->len += 2;
-                }
-            }
-        }
-        sFrame.len += uLength;
-    }
-
-
-    if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
-        sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-        sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
-        memcpy(sFrame.pExtSuppRates,
-             pCurrExtSuppRates,
-             ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
-             );
-    }
-
-    // hostapd wpa/wpa2 IE
-    if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
-         if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
-             if (pMgmt->wWPAIELen != 0) {
-                 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
-                 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
-                 sFrame.len += pMgmt->wWPAIELen;
-             }
-         }
-    }
-
-    // Adjust the length fields
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-
-    return pTxPacket;
-}
+       PSTxMgmtPacket      pTxPacket = NULL;
+       WLAN_FR_PROBERESP   sFrame;
+       unsigned char *pbyBuffer;
+       unsigned int uLength = 0;
+       PWLAN_IE_IBSS_DFS   pIBSSDFS = NULL;
+       unsigned int ii;
+
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBERESP_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       // Setup the sFrame structure.
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_PROBERESP_FR_MAXLEN;
+       vMgrEncodeProbeResponse(&sFrame);
+       // Setup the header
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBERESP)
+));
+       memcpy(sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
+       *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
+       *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
+
+       if (byPHYType == BB_TYPE_11B) {
+               *sFrame.pwCapInfo &= cpu_to_le16((unsigned short)~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)));
+       }
+
+       // Copy SSID
+       sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
+       sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSSID,
+              pCurrSSID,
+              ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
+);
+       // Copy the rate set
+       sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+
+       sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSuppRates,
+              pCurrSuppRates,
+              ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
+);
+
+       // DS parameter
+       if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
+               sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
+               sFrame.len += (1) + WLAN_IEHDR_LEN;
+               sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
+               sFrame.pDSParms->len = 1;
+               sFrame.pDSParms->byCurrChannel = (unsigned char)uCurrChannel;
+       }
+
+       if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
+               // IBSS parameter
+               sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
+               sFrame.len += (2) + WLAN_IEHDR_LEN;
+               sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
+               sFrame.pIBSSParms->len = 2;
+               sFrame.pIBSSParms->wATIMWindow = 0;
+       }
+       if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
+               sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
+               sFrame.len += 1 + WLAN_IEHDR_LEN;
+               sFrame.pERP->byElementID = WLAN_EID_ERP;
+               sFrame.pERP->len = 1;
+               sFrame.pERP->byContext = 0;
+               if (pDevice->bProtectMode == true)
+                       sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
+               if (pDevice->bNonERPPresent == true)
+                       sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
+               if (pDevice->bBarkerPreambleMd == true)
+                       sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
+       }
+
+       if ((pMgmt->b11hEnable == true) &&
+           (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
+               // Country IE
+               pbyBuffer = (unsigned char *)(sFrame.pBuf + sFrame.len);
+               set_country_IE(pMgmt->pAdapter, pbyBuffer);
+               set_country_info(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
+               uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
+               pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
+               // Power Constrain IE
+               ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
+               ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
+               ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
+               pbyBuffer += (1) + WLAN_IEHDR_LEN;
+               uLength += (1) + WLAN_IEHDR_LEN;
+               if (pMgmt->bSwitchChannel == true) {
+                       // Channel Switch IE
+                       ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
+                       ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
+                       ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
+                       ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = get_channel_number(pMgmt->pAdapter, pMgmt->byNewChannel);
+                       ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
+                       pbyBuffer += (3) + WLAN_IEHDR_LEN;
+                       uLength += (3) + WLAN_IEHDR_LEN;
+               }
+               // TPC report
+               ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
+               ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
+               ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
+               ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
+               pbyBuffer += (2) + WLAN_IEHDR_LEN;
+               uLength += (2) + WLAN_IEHDR_LEN;
+               // IBSS DFS
+               if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
+                       pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
+                       pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
+                       pIBSSDFS->len = 7;
+                       memcpy(pIBSSDFS->abyDFSOwner,
+                              pMgmt->abyIBSSDFSOwner,
+                              6);
+                       pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
+                       pbyBuffer += (7) + WLAN_IEHDR_LEN;
+                       uLength += (7) + WLAN_IEHDR_LEN;
+                       for (ii = CB_MAX_CHANNEL_24G + 1; ii <= CB_MAX_CHANNEL; ii++) {
+                               if (get_channel_map_info(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1) == true) {
+                                       pbyBuffer += 2;
+                                       uLength += 2;
+                                       pIBSSDFS->len += 2;
+                               }
+                       }
+               }
+               sFrame.len += uLength;
+       }
+
+       if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
+               sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+               sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
+               memcpy(sFrame.pExtSuppRates,
+                      pCurrExtSuppRates,
+                      ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
+);
+       }
+
+       // hostapd wpa/wpa2 IE
+       if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
+               if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
+                       if (pMgmt->wWPAIELen != 0) {
+                               sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
+                               memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
+                               sFrame.len += pMgmt->wWPAIELen;
+                       }
+               }
+       }
 
+       // Adjust the length fields
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
 
+       return pTxPacket;
+}
 
 /*+
  *
@@ -3613,271 +3434,259 @@ s_MgrMakeProbeResponse(
  * Return Value:
  *    A ptr to frame or NULL on allocation failure
  *
--*/
-
+ -*/
 
 PSTxMgmtPacket
 s_MgrMakeAssocRequest(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned char *pDAddr,
-    unsigned short wCurrCapInfo,
-    unsigned short wListenInterval,
-    PWLAN_IE_SSID pCurrSSID,
-    PWLAN_IE_SUPP_RATES pCurrRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned char *pDAddr,
+       unsigned short wCurrCapInfo,
+       unsigned short wListenInterval,
+       PWLAN_IE_SSID pCurrSSID,
+       PWLAN_IE_SUPP_RATES pCurrRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+)
 {
-    PSTxMgmtPacket      pTxPacket = NULL;
-    WLAN_FR_ASSOCREQ    sFrame;
-    unsigned char *pbyIEs;
-    unsigned char *pbyRSN;
-
-
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    // Setup the sFrame structure.
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN;
-    // format fixed field frame structure
-    vMgrEncodeAssocRequest(&sFrame);
-    // Setup the header
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-        (
-        WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-        WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCREQ)
-        ));
-    memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-
-    // Set the capability and listen interval
-    *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
-    *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
-
-    // sFrame.len point to end of fixed field
-    sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
-    sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
-
-    pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
-    pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
-    pbyIEs = pMgmt->sAssocInfo.abyIEs;
-    memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
-    pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
-
-    // Copy the rate set
-    sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-    if ((pDevice->eCurrentPHYType == PHY_TYPE_11B) && (pCurrRates->len > 4))
-        sFrame.len += 4 + WLAN_IEHDR_LEN;
-    else
-        sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
-
-    // Copy the extension rate set
-    if ((pDevice->eCurrentPHYType == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
-        sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-        sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
-        memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
-    }
-
-    pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
-    memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
-    pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
-
-    // for 802.11h
-    if (pMgmt->b11hEnable == true) {
-        if (sFrame.pCurrPowerCap == NULL) {
-            sFrame.pCurrPowerCap = (PWLAN_IE_PW_CAP)(sFrame.pBuf + sFrame.len);
-            sFrame.len += (2 + WLAN_IEHDR_LEN);
-            sFrame.pCurrPowerCap->byElementID = WLAN_EID_PWR_CAPABILITY;
-            sFrame.pCurrPowerCap->len = 2;
-            CARDvGetPowerCapability(pMgmt->pAdapter,
-                                    &(sFrame.pCurrPowerCap->byMinPower),
-                                    &(sFrame.pCurrPowerCap->byMaxPower)
-                                    );
-        }
-        if (sFrame.pCurrSuppCh == NULL) {
-            sFrame.pCurrSuppCh = (PWLAN_IE_SUPP_CH)(sFrame.pBuf + sFrame.len);
-            sFrame.len += set_support_channels(pMgmt->pAdapter,(unsigned char *)sFrame.pCurrSuppCh);
-        }
-    }
-
-    if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
-         (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
-         (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
-        (pMgmt->pCurrBSS != NULL)) {
-        /* WPA IE */
-        sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
-        sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
-        sFrame.pRSNWPA->len = 16;
-        sFrame.pRSNWPA->abyOUI[0] = 0x00;
-        sFrame.pRSNWPA->abyOUI[1] = 0x50;
-        sFrame.pRSNWPA->abyOUI[2] = 0xf2;
-        sFrame.pRSNWPA->abyOUI[3] = 0x01;
-        sFrame.pRSNWPA->wVersion = 1;
-        //Group Key Cipher Suite
-        sFrame.pRSNWPA->abyMulticast[0] = 0x00;
-        sFrame.pRSNWPA->abyMulticast[1] = 0x50;
-        sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
-        if (pMgmt->byCSSGK == KEY_CTL_WEP) {
-            sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
-        } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
-            sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
-        } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
-            sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
-        } else {
-            sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
-        }
-        // Pairwise Key Cipher Suite
-        sFrame.pRSNWPA->wPKCount = 1;
-        sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
-        sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
-        sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
-        if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
-            sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
-        } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
-            sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
-        } else {
-            sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
-        }
-        // Auth Key Management Suite
-        pbyRSN = (unsigned char *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
-        *pbyRSN++=0x01;
-        *pbyRSN++=0x00;
-        *pbyRSN++=0x00;
-
-        *pbyRSN++=0x50;
-        *pbyRSN++=0xf2;
-        if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
-            *pbyRSN++=WPA_AUTH_PSK;
-        }
-        else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
-            *pbyRSN++=WPA_AUTH_IEEE802_1X;
-        }
-        else {
-            *pbyRSN++=WPA_NONE;
-        }
-
-        sFrame.pRSNWPA->len +=6;
-
-        // RSN Capabilities
-
-        *pbyRSN++=0x00;
-        *pbyRSN++=0x00;
-        sFrame.pRSNWPA->len +=2;
-
-        sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
-        // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
-        pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
-        memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
-        pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
-
-    } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
-                (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
-               (pMgmt->pCurrBSS != NULL)) {
-        unsigned int ii;
-        unsigned short *pwPMKID;
-
-        // WPA IE
-        sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
-        sFrame.pRSN->byElementID = WLAN_EID_RSN;
-        sFrame.pRSN->len = 6; //Version(2)+GK(4)
-        sFrame.pRSN->wVersion = 1;
-        //Group Key Cipher Suite
-        sFrame.pRSN->abyRSN[0] = 0x00;
-        sFrame.pRSN->abyRSN[1] = 0x0F;
-        sFrame.pRSN->abyRSN[2] = 0xAC;
-        if (pMgmt->byCSSGK == KEY_CTL_WEP) {
-            sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
-        } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
-            sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
-        } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
-            sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
-        } else {
-            sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
-        }
-
-        // Pairwise Key Cipher Suite
-        sFrame.pRSN->abyRSN[4] = 1;
-        sFrame.pRSN->abyRSN[5] = 0;
-        sFrame.pRSN->abyRSN[6] = 0x00;
-        sFrame.pRSN->abyRSN[7] = 0x0F;
-        sFrame.pRSN->abyRSN[8] = 0xAC;
-        if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
-            sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
-        } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
-            sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
-        } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
-            sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
-        } else {
-            sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
-        }
-        sFrame.pRSN->len += 6;
-
-        // Auth Key Management Suite
-        sFrame.pRSN->abyRSN[10] = 1;
-        sFrame.pRSN->abyRSN[11] = 0;
-        sFrame.pRSN->abyRSN[12] = 0x00;
-        sFrame.pRSN->abyRSN[13] = 0x0F;
-        sFrame.pRSN->abyRSN[14] = 0xAC;
-        if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
-            sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
-        } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
-            sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
-        } else {
-            sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
-        }
-        sFrame.pRSN->len +=6;
-
-        // RSN Capabilities
-        if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
-            memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
-        } else {
-            sFrame.pRSN->abyRSN[16] = 0;
-            sFrame.pRSN->abyRSN[17] = 0;
-        }
-        sFrame.pRSN->len +=2;
-
-        if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
-            // RSN PMKID
-            pbyRSN = &sFrame.pRSN->abyRSN[18];
-            pwPMKID = (unsigned short *)pbyRSN; // Point to PMKID count
-            *pwPMKID = 0;            // Initialize PMKID count
-            pbyRSN += 2;             // Point to PMKID list
-            for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
-                if ( !memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
-                    (*pwPMKID) ++;
-                    memcpy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
-                    pbyRSN += 16;
-                }
-            }
-            if (*pwPMKID != 0) {
-                sFrame.pRSN->len += (2 + (*pwPMKID)*16);
-            }
-        }
-
-        sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
-        // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
-        pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
-        memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
-        pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
-    }
-
-
-    // Adjust the length fields
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-    return pTxPacket;
-}
-
+       PSTxMgmtPacket      pTxPacket = NULL;
+       WLAN_FR_ASSOCREQ    sFrame;
+       unsigned char *pbyIEs;
+       unsigned char *pbyRSN;
+
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       // Setup the sFrame structure.
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN;
+       // format fixed field frame structure
+       vMgrEncodeAssocRequest(&sFrame);
+       // Setup the header
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCREQ)
+));
+       memcpy(sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+
+       // Set the capability and listen interval
+       *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
+       *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
+
+       // sFrame.len point to end of fixed field
+       sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
+       sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
+
+       pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
+       pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
+       pbyIEs = pMgmt->sAssocInfo.abyIEs;
+       memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
+       pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
+
+       // Copy the rate set
+       sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+       if ((pDevice->eCurrentPHYType == PHY_TYPE_11B) && (pCurrRates->len > 4))
+               sFrame.len += 4 + WLAN_IEHDR_LEN;
+       else
+               sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
+
+       // Copy the extension rate set
+       if ((pDevice->eCurrentPHYType == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
+               sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+               sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
+               memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
+       }
 
+       pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
+       memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
+       pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
+
+       // for 802.11h
+       if (pMgmt->b11hEnable == true) {
+               if (sFrame.pCurrPowerCap == NULL) {
+                       sFrame.pCurrPowerCap = (PWLAN_IE_PW_CAP)(sFrame.pBuf + sFrame.len);
+                       sFrame.len += (2 + WLAN_IEHDR_LEN);
+                       sFrame.pCurrPowerCap->byElementID = WLAN_EID_PWR_CAPABILITY;
+                       sFrame.pCurrPowerCap->len = 2;
+                       CARDvGetPowerCapability(pMgmt->pAdapter,
+                                               &(sFrame.pCurrPowerCap->byMinPower),
+                                               &(sFrame.pCurrPowerCap->byMaxPower)
+);
+               }
+               if (sFrame.pCurrSuppCh == NULL) {
+                       sFrame.pCurrSuppCh = (PWLAN_IE_SUPP_CH)(sFrame.pBuf + sFrame.len);
+                       sFrame.len += set_support_channels(pMgmt->pAdapter, (unsigned char *)sFrame.pCurrSuppCh);
+               }
+       }
 
+       if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
+            (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
+            (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
+           (pMgmt->pCurrBSS != NULL)) {
+               /* WPA IE */
+               sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
+               sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
+               sFrame.pRSNWPA->len = 16;
+               sFrame.pRSNWPA->abyOUI[0] = 0x00;
+               sFrame.pRSNWPA->abyOUI[1] = 0x50;
+               sFrame.pRSNWPA->abyOUI[2] = 0xf2;
+               sFrame.pRSNWPA->abyOUI[3] = 0x01;
+               sFrame.pRSNWPA->wVersion = 1;
+               //Group Key Cipher Suite
+               sFrame.pRSNWPA->abyMulticast[0] = 0x00;
+               sFrame.pRSNWPA->abyMulticast[1] = 0x50;
+               sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
+               if (pMgmt->byCSSGK == KEY_CTL_WEP) {
+                       sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
+               } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
+                       sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
+               } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
+                       sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
+               } else {
+                       sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
+               }
+               // Pairwise Key Cipher Suite
+               sFrame.pRSNWPA->wPKCount = 1;
+               sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
+               sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
+               sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
+               if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
+                       sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
+               } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
+                       sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
+               } else {
+                       sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
+               }
+               // Auth Key Management Suite
+               pbyRSN = (unsigned char *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
+               *pbyRSN++ = 0x01;
+               *pbyRSN++ = 0x00;
+               *pbyRSN++ = 0x00;
+
+               *pbyRSN++ = 0x50;
+               *pbyRSN++ = 0xf2;
+               if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
+                       *pbyRSN++ = WPA_AUTH_PSK;
+               } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
+                       *pbyRSN++ = WPA_AUTH_IEEE802_1X;
+               } else {
+                       *pbyRSN++ = WPA_NONE;
+               }
 
+               sFrame.pRSNWPA->len += 6;
+
+               // RSN Capabilities
+
+               *pbyRSN++ = 0x00;
+               *pbyRSN++ = 0x00;
+               sFrame.pRSNWPA->len += 2;
+
+               sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
+               // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
+               pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
+               memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
+               pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
+
+       } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
+                   (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
+                  (pMgmt->pCurrBSS != NULL)) {
+               unsigned int ii;
+               unsigned short *pwPMKID;
+
+               // WPA IE
+               sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
+               sFrame.pRSN->byElementID = WLAN_EID_RSN;
+               sFrame.pRSN->len = 6; //Version(2)+GK(4)
+               sFrame.pRSN->wVersion = 1;
+               //Group Key Cipher Suite
+               sFrame.pRSN->abyRSN[0] = 0x00;
+               sFrame.pRSN->abyRSN[1] = 0x0F;
+               sFrame.pRSN->abyRSN[2] = 0xAC;
+               if (pMgmt->byCSSGK == KEY_CTL_WEP) {
+                       sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
+               } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
+                       sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
+               } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
+                       sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
+               } else {
+                       sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
+               }
 
+               // Pairwise Key Cipher Suite
+               sFrame.pRSN->abyRSN[4] = 1;
+               sFrame.pRSN->abyRSN[5] = 0;
+               sFrame.pRSN->abyRSN[6] = 0x00;
+               sFrame.pRSN->abyRSN[7] = 0x0F;
+               sFrame.pRSN->abyRSN[8] = 0xAC;
+               if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
+                       sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
+               } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
+                       sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
+               } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
+                       sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
+               } else {
+                       sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
+               }
+               sFrame.pRSN->len += 6;
+
+               // Auth Key Management Suite
+               sFrame.pRSN->abyRSN[10] = 1;
+               sFrame.pRSN->abyRSN[11] = 0;
+               sFrame.pRSN->abyRSN[12] = 0x00;
+               sFrame.pRSN->abyRSN[13] = 0x0F;
+               sFrame.pRSN->abyRSN[14] = 0xAC;
+               if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
+                       sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
+               } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
+                       sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
+               } else {
+                       sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
+               }
+               sFrame.pRSN->len += 6;
+
+               // RSN Capabilities
+               if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
+                       memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
+               } else {
+                       sFrame.pRSN->abyRSN[16] = 0;
+                       sFrame.pRSN->abyRSN[17] = 0;
+               }
+               sFrame.pRSN->len += 2;
+
+               if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
+                       // RSN PMKID
+                       pbyRSN = &sFrame.pRSN->abyRSN[18];
+                       pwPMKID = (unsigned short *)pbyRSN; // Point to PMKID count
+                       *pwPMKID = 0;            // Initialize PMKID count
+                       pbyRSN += 2;             // Point to PMKID list
+                       for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
+                               if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
+                                       (*pwPMKID)++;
+                                       memcpy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
+                                       pbyRSN += 16;
+                               }
+                       }
+                       if (*pwPMKID != 0) {
+                               sFrame.pRSN->len += (2 + (*pwPMKID)*16);
+                       }
+               }
 
+               sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
+               // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
+               pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
+               memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
+               pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
+       }
 
+       // Adjust the length fields
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
+       return pTxPacket;
+}
 
 /*+
  *
@@ -3888,248 +3697,243 @@ s_MgrMakeAssocRequest(
  * Return Value:
  *    A ptr to frame or NULL on allocation failure
  *
--*/
-
+ -*/
 
 PSTxMgmtPacket
 s_MgrMakeReAssocRequest(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned char *pDAddr,
-    unsigned short wCurrCapInfo,
-    unsigned short wListenInterval,
-    PWLAN_IE_SSID pCurrSSID,
-    PWLAN_IE_SUPP_RATES pCurrRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned char *pDAddr,
+       unsigned short wCurrCapInfo,
+       unsigned short wListenInterval,
+       PWLAN_IE_SSID pCurrSSID,
+       PWLAN_IE_SUPP_RATES pCurrRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+)
 {
-    PSTxMgmtPacket      pTxPacket = NULL;
-    WLAN_FR_REASSOCREQ  sFrame;
-    unsigned char *pbyIEs;
-    unsigned char *pbyRSN;
-
-
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset( pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_REASSOCREQ_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    /* Setup the sFrame structure. */
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN;
-
-    // format fixed field frame structure
-    vMgrEncodeReassocRequest(&sFrame);
-
-    /* Setup the header */
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-        (
-        WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-        WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCREQ)
-        ));
-    memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-
-    /* Set the capability and listen interval */
-    *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
-    *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
-
-    memcpy(sFrame.pAddrCurrAP, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-    /* Copy the SSID */
-    /* sFrame.len point to end of fixed field */
-    sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
-    sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
-
-    pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
-    pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
-    pbyIEs = pMgmt->sAssocInfo.abyIEs;
-    memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
-    pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
-
-    /* Copy the rate set */
-    /* sFrame.len point to end of SSID */
-    sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-    sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
-
-    // Copy the extension rate set
-    if ((pMgmt->eCurrentPHYMode == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
-        sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-        sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
-        memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
-    }
-
-    pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
-    memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
-    pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
-
-    if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
-         (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
-         (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
-        (pMgmt->pCurrBSS != NULL)) {
-        /* WPA IE */
-        sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
-        sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
-        sFrame.pRSNWPA->len = 16;
-        sFrame.pRSNWPA->abyOUI[0] = 0x00;
-        sFrame.pRSNWPA->abyOUI[1] = 0x50;
-        sFrame.pRSNWPA->abyOUI[2] = 0xf2;
-        sFrame.pRSNWPA->abyOUI[3] = 0x01;
-        sFrame.pRSNWPA->wVersion = 1;
-        //Group Key Cipher Suite
-        sFrame.pRSNWPA->abyMulticast[0] = 0x00;
-        sFrame.pRSNWPA->abyMulticast[1] = 0x50;
-        sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
-        if (pMgmt->byCSSGK == KEY_CTL_WEP) {
-            sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
-        } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
-            sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
-        } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
-            sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
-        } else {
-            sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
-        }
-        // Pairwise Key Cipher Suite
-        sFrame.pRSNWPA->wPKCount = 1;
-        sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
-        sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
-        sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
-        if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
-            sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
-        } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
-            sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
-        } else {
-            sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
-        }
-        // Auth Key Management Suite
-        pbyRSN = (unsigned char *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
-        *pbyRSN++=0x01;
-        *pbyRSN++=0x00;
-        *pbyRSN++=0x00;
-
-        *pbyRSN++=0x50;
-        *pbyRSN++=0xf2;
-        if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
-            *pbyRSN++=WPA_AUTH_PSK;
-        } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
-            *pbyRSN++=WPA_AUTH_IEEE802_1X;
-        } else {
-            *pbyRSN++=WPA_NONE;
-        }
-
-        sFrame.pRSNWPA->len +=6;
-
-        // RSN Capabilities
-        *pbyRSN++=0x00;
-        *pbyRSN++=0x00;
-        sFrame.pRSNWPA->len +=2;
-
-        sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
-        // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
-        pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
-        memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
-        pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
-
-    } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
-                (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
-               (pMgmt->pCurrBSS != NULL)) {
-        unsigned int ii;
-        unsigned short *pwPMKID;
-
-        /* WPA IE */
-        sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
-        sFrame.pRSN->byElementID = WLAN_EID_RSN;
-        sFrame.pRSN->len = 6; //Version(2)+GK(4)
-        sFrame.pRSN->wVersion = 1;
-        //Group Key Cipher Suite
-        sFrame.pRSN->abyRSN[0] = 0x00;
-        sFrame.pRSN->abyRSN[1] = 0x0F;
-        sFrame.pRSN->abyRSN[2] = 0xAC;
-        if (pMgmt->byCSSGK == KEY_CTL_WEP) {
-            sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
-        } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
-            sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
-        } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
-            sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
-        } else {
-            sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
-        }
-
-        // Pairwise Key Cipher Suite
-        sFrame.pRSN->abyRSN[4] = 1;
-        sFrame.pRSN->abyRSN[5] = 0;
-        sFrame.pRSN->abyRSN[6] = 0x00;
-        sFrame.pRSN->abyRSN[7] = 0x0F;
-        sFrame.pRSN->abyRSN[8] = 0xAC;
-        if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
-            sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
-        } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
-            sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
-        } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
-            sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
-        } else {
-            sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
-        }
-        sFrame.pRSN->len += 6;
-
-        // Auth Key Management Suite
-        sFrame.pRSN->abyRSN[10] = 1;
-        sFrame.pRSN->abyRSN[11] = 0;
-        sFrame.pRSN->abyRSN[12] = 0x00;
-        sFrame.pRSN->abyRSN[13] = 0x0F;
-        sFrame.pRSN->abyRSN[14] = 0xAC;
-        if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
-            sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
-        } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
-            sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
-        } else {
-            sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
-        }
-        sFrame.pRSN->len +=6;
-
-        // RSN Capabilities
-        if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
-            memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
-        } else {
-            sFrame.pRSN->abyRSN[16] = 0;
-            sFrame.pRSN->abyRSN[17] = 0;
-        }
-        sFrame.pRSN->len +=2;
-
-        if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
-            // RSN PMKID
-            pbyRSN = &sFrame.pRSN->abyRSN[18];
-            pwPMKID = (unsigned short *)pbyRSN; // Point to PMKID count
-            *pwPMKID = 0;            // Initialize PMKID count
-            pbyRSN += 2;             // Point to PMKID list
-            for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
-                if ( !memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
-                    (*pwPMKID) ++;
-                    memcpy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
-                    pbyRSN += 16;
-                }
-            }
-            if (*pwPMKID != 0) {
-                sFrame.pRSN->len += (2 + (*pwPMKID)*16);
-            }
-        }
-
-        sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
-        // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
-        pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
-        memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
-        pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
-    }
-
-
-    /* Adjust the length fields */
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-
-    return pTxPacket;
-}
+       PSTxMgmtPacket      pTxPacket = NULL;
+       WLAN_FR_REASSOCREQ  sFrame;
+       unsigned char *pbyIEs;
+       unsigned char *pbyRSN;
+
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_REASSOCREQ_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       /* Setup the sFrame structure. */
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN;
+
+       // format fixed field frame structure
+       vMgrEncodeReassocRequest(&sFrame);
+
+       /* Setup the header */
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCREQ)
+));
+       memcpy(sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+
+       /* Set the capability and listen interval */
+       *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
+       *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
+
+       memcpy(sFrame.pAddrCurrAP, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+       /* Copy the SSID */
+       /* sFrame.len point to end of fixed field */
+       sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
+       sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
+
+       pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
+       pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
+       pbyIEs = pMgmt->sAssocInfo.abyIEs;
+       memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
+       pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
+
+       /* Copy the rate set */
+       /* sFrame.len point to end of SSID */
+       sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+       sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
+
+       // Copy the extension rate set
+       if ((pMgmt->eCurrentPHYMode == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
+               sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+               sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
+               memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
+       }
+
+       pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
+       memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
+       pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
+
+       if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
+            (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
+            (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
+           (pMgmt->pCurrBSS != NULL)) {
+               /* WPA IE */
+               sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
+               sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
+               sFrame.pRSNWPA->len = 16;
+               sFrame.pRSNWPA->abyOUI[0] = 0x00;
+               sFrame.pRSNWPA->abyOUI[1] = 0x50;
+               sFrame.pRSNWPA->abyOUI[2] = 0xf2;
+               sFrame.pRSNWPA->abyOUI[3] = 0x01;
+               sFrame.pRSNWPA->wVersion = 1;
+               //Group Key Cipher Suite
+               sFrame.pRSNWPA->abyMulticast[0] = 0x00;
+               sFrame.pRSNWPA->abyMulticast[1] = 0x50;
+               sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
+               if (pMgmt->byCSSGK == KEY_CTL_WEP) {
+                       sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
+               } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
+                       sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
+               } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
+                       sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
+               } else {
+                       sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
+               }
+               // Pairwise Key Cipher Suite
+               sFrame.pRSNWPA->wPKCount = 1;
+               sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
+               sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
+               sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
+               if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
+                       sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
+               } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
+                       sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
+               } else {
+                       sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
+               }
+               // Auth Key Management Suite
+               pbyRSN = (unsigned char *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
+               *pbyRSN++ = 0x01;
+               *pbyRSN++ = 0x00;
+               *pbyRSN++ = 0x00;
+
+               *pbyRSN++ = 0x50;
+               *pbyRSN++ = 0xf2;
+               if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
+                       *pbyRSN++ = WPA_AUTH_PSK;
+               } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
+                       *pbyRSN++ = WPA_AUTH_IEEE802_1X;
+               } else {
+                       *pbyRSN++ = WPA_NONE;
+               }
 
+               sFrame.pRSNWPA->len += 6;
+
+               // RSN Capabilities
+               *pbyRSN++ = 0x00;
+               *pbyRSN++ = 0x00;
+               sFrame.pRSNWPA->len += 2;
+
+               sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
+               // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
+               pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
+               memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
+               pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
+
+       } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
+                   (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
+                  (pMgmt->pCurrBSS != NULL)) {
+               unsigned int ii;
+               unsigned short *pwPMKID;
+
+               /* WPA IE */
+               sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
+               sFrame.pRSN->byElementID = WLAN_EID_RSN;
+               sFrame.pRSN->len = 6; //Version(2)+GK(4)
+               sFrame.pRSN->wVersion = 1;
+               //Group Key Cipher Suite
+               sFrame.pRSN->abyRSN[0] = 0x00;
+               sFrame.pRSN->abyRSN[1] = 0x0F;
+               sFrame.pRSN->abyRSN[2] = 0xAC;
+               if (pMgmt->byCSSGK == KEY_CTL_WEP) {
+                       sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
+               } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
+                       sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
+               } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
+                       sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
+               } else {
+                       sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
+               }
 
+               // Pairwise Key Cipher Suite
+               sFrame.pRSN->abyRSN[4] = 1;
+               sFrame.pRSN->abyRSN[5] = 0;
+               sFrame.pRSN->abyRSN[6] = 0x00;
+               sFrame.pRSN->abyRSN[7] = 0x0F;
+               sFrame.pRSN->abyRSN[8] = 0xAC;
+               if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
+                       sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
+               } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
+                       sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
+               } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
+                       sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
+               } else {
+                       sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
+               }
+               sFrame.pRSN->len += 6;
+
+               // Auth Key Management Suite
+               sFrame.pRSN->abyRSN[10] = 1;
+               sFrame.pRSN->abyRSN[11] = 0;
+               sFrame.pRSN->abyRSN[12] = 0x00;
+               sFrame.pRSN->abyRSN[13] = 0x0F;
+               sFrame.pRSN->abyRSN[14] = 0xAC;
+               if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
+                       sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
+               } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
+                       sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
+               } else {
+                       sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
+               }
+               sFrame.pRSN->len += 6;
+
+               // RSN Capabilities
+               if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
+                       memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
+               } else {
+                       sFrame.pRSN->abyRSN[16] = 0;
+                       sFrame.pRSN->abyRSN[17] = 0;
+               }
+               sFrame.pRSN->len += 2;
+
+               if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
+                       // RSN PMKID
+                       pbyRSN = &sFrame.pRSN->abyRSN[18];
+                       pwPMKID = (unsigned short *)pbyRSN; // Point to PMKID count
+                       *pwPMKID = 0;            // Initialize PMKID count
+                       pbyRSN += 2;             // Point to PMKID list
+                       for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
+                               if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
+                                       (*pwPMKID)++;
+                                       memcpy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
+                                       pbyRSN += 16;
+                               }
+                       }
+                       if (*pwPMKID != 0) {
+                               sFrame.pRSN->len += (2 + (*pwPMKID) * 16);
+                       }
+               }
+
+               sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
+               // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
+               pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
+               memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
+               pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
+       }
+
+       /* Adjust the length fields */
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
+
+       return pTxPacket;
+}
 
 /*+
  *
@@ -4140,70 +3944,67 @@ s_MgrMakeReAssocRequest(
  * Return Value:
  *    PTR to frame; or NULL on allocation failure
  *
--*/
-
+ -*/
 
 PSTxMgmtPacket
 s_MgrMakeAssocResponse(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned short wCurrCapInfo,
-    unsigned short wAssocStatus,
-    unsigned short wAssocAID,
-    unsigned char *pDstAddr,
-    PWLAN_IE_SUPP_RATES pCurrSuppRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned short wCurrCapInfo,
+       unsigned short wAssocStatus,
+       unsigned short wAssocAID,
+       unsigned char *pDstAddr,
+       PWLAN_IE_SUPP_RATES pCurrSuppRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+)
 {
-    PSTxMgmtPacket      pTxPacket = NULL;
-    WLAN_FR_ASSOCRESP   sFrame;
-
-
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    // Setup the sFrame structure
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
-    vMgrEncodeAssocResponse(&sFrame);
-    // Setup the header
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-        (
-        WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-        WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCRESP)
-        ));
-    memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-
-    *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
-    *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
-    *sFrame.pwAid = cpu_to_le16((unsigned short)(wAssocAID | BIT14 | BIT15));
-
-    // Copy the rate set
-    sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-    sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSuppRates,
-           pCurrSuppRates,
-           ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
-          );
-
-    if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
-        sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-        sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
-        memcpy(sFrame.pExtSuppRates,
-             pCurrExtSuppRates,
-             ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
-             );
-    }
-
-    // Adjust the length fields
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-
-    return pTxPacket;
-}
+       PSTxMgmtPacket      pTxPacket = NULL;
+       WLAN_FR_ASSOCRESP   sFrame;
+
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       // Setup the sFrame structure
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
+       vMgrEncodeAssocResponse(&sFrame);
+       // Setup the header
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCRESP)
+));
+       memcpy(sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+
+       *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
+       *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
+       *sFrame.pwAid = cpu_to_le16((unsigned short)(wAssocAID | BIT14 | BIT15));
+
+       // Copy the rate set
+       sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+       sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSuppRates,
+              pCurrSuppRates,
+              ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
+);
+
+       if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
+               sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+               sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
+               memcpy(sFrame.pExtSuppRates,
+                      pCurrExtSuppRates,
+                      ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
+);
+       }
 
+       // Adjust the length fields
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
+
+       return pTxPacket;
+}
 
 /*+
  *
@@ -4214,70 +4015,67 @@ s_MgrMakeAssocResponse(
  * Return Value:
  *    PTR to frame; or NULL on allocation failure
  *
--*/
-
+ -*/
 
 PSTxMgmtPacket
 s_MgrMakeReAssocResponse(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    unsigned short wCurrCapInfo,
-    unsigned short wAssocStatus,
-    unsigned short wAssocAID,
-    unsigned char *pDstAddr,
-    PWLAN_IE_SUPP_RATES pCurrSuppRates,
-    PWLAN_IE_SUPP_RATES pCurrExtSuppRates
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       unsigned short wCurrCapInfo,
+       unsigned short wAssocStatus,
+       unsigned short wAssocAID,
+       unsigned char *pDstAddr,
+       PWLAN_IE_SUPP_RATES pCurrSuppRates,
+       PWLAN_IE_SUPP_RATES pCurrExtSuppRates
+)
 {
-    PSTxMgmtPacket      pTxPacket = NULL;
-    WLAN_FR_REASSOCRESP   sFrame;
-
-
-    pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
-    memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
-    pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
-    // Setup the sFrame structure
-    sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
-    sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
-    vMgrEncodeReassocResponse(&sFrame);
-    // Setup the header
-    sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
-        (
-        WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
-        WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCRESP)
-        ));
-    memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
-    memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
-
-    *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
-    *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
-    *sFrame.pwAid = cpu_to_le16((unsigned short)(wAssocAID | BIT14 | BIT15));
-
-    // Copy the rate set
-    sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-    sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
-    memcpy(sFrame.pSuppRates,
-             pCurrSuppRates,
-             ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
-             );
-
-    if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
-        sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
-        sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
-        memcpy(sFrame.pExtSuppRates,
-             pCurrExtSuppRates,
-             ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
-             );
-    }
-
-    // Adjust the length fields
-    pTxPacket->cbMPDULen = sFrame.len;
-    pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
-
-    return pTxPacket;
-}
+       PSTxMgmtPacket      pTxPacket = NULL;
+       WLAN_FR_REASSOCRESP   sFrame;
+
+       pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
+       memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
+       pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
+       // Setup the sFrame structure
+       sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
+       sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
+       vMgrEncodeReassocResponse(&sFrame);
+       // Setup the header
+       sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
+               (
+                       WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
+                       WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCRESP)
+));
+       memcpy(sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
+       memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
+
+       *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
+       *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
+       *sFrame.pwAid = cpu_to_le16((unsigned short)(wAssocAID | BIT14 | BIT15));
+
+       // Copy the rate set
+       sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+       sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
+       memcpy(sFrame.pSuppRates,
+              pCurrSuppRates,
+              ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
+);
+
+       if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
+               sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
+               sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
+               memcpy(sFrame.pExtSuppRates,
+                      pCurrExtSuppRates,
+                      ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
+);
+       }
+
+       // Adjust the length fields
+       pTxPacket->cbMPDULen = sFrame.len;
+       pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
 
+       return pTxPacket;
+}
 
 /*+
  *
@@ -4288,119 +4086,115 @@ s_MgrMakeReAssocResponse(
  * Return Value:
  *    none.
  *
--*/
+ -*/
 
 static
 void
 s_vMgrRxProbeResponse(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+)
 {
-    PKnownBSS           pBSSList = NULL;
-    WLAN_FR_PROBERESP   sFrame;
-    unsigned char byCurrChannel = pRxPacket->byRxChannel;
-    ERPObject           sERP;
-    unsigned char byIEChannel = 0;
-    bool bChannelHit = true;
-
-
-    memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP));
-    // decode the frame
-    sFrame.len = pRxPacket->cbMPDULen;
-    sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
-    vMgrDecodeProbeResponse(&sFrame);
-
-    if ((sFrame.pqwTimestamp == 0) ||
-        (sFrame.pwBeaconInterval == 0) ||
-        (sFrame.pwCapInfo == 0) ||
-        (sFrame.pSSID == 0) ||
-        (sFrame.pSuppRates == 0)) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe resp:Fail addr:[%p] \n", pRxPacket->p80211Header);
-        DBG_PORT80(0xCC);
-        return;
-    }
-
-    if(sFrame.pSSID->len == 0)
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx Probe resp: SSID len = 0 \n");
-
-    if (sFrame.pDSParms != 0) {
-        if (byCurrChannel > CB_MAX_CHANNEL_24G) {
-            // channel remapping to
-            byIEChannel = get_channel_mapping(pMgmt->pAdapter, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
-        } else {
-            byIEChannel = sFrame.pDSParms->byCurrChannel;
-        }
-        if (byCurrChannel != byIEChannel) {
-            // adjust channel info. bcs we rcv adjacent channel packets
-            bChannelHit = false;
-            byCurrChannel = byIEChannel;
-        }
-    } else {
-        // no DS channel info
-        bChannelHit = true;
-    }
+       PKnownBSS           pBSSList = NULL;
+       WLAN_FR_PROBERESP   sFrame;
+       unsigned char byCurrChannel = pRxPacket->byRxChannel;
+       ERPObject           sERP;
+       unsigned char byIEChannel = 0;
+       bool bChannelHit = true;
+
+       memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP));
+       // decode the frame
+       sFrame.len = pRxPacket->cbMPDULen;
+       sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
+       vMgrDecodeProbeResponse(&sFrame);
+
+       if ((sFrame.pqwTimestamp == 0) ||
+           (sFrame.pwBeaconInterval == 0) ||
+           (sFrame.pwCapInfo == 0) ||
+           (sFrame.pSSID == 0) ||
+           (sFrame.pSuppRates == 0)) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe resp:Fail addr:[%p] \n", pRxPacket->p80211Header);
+               DBG_PORT80(0xCC);
+               return;
+       }
+
+       if (sFrame.pSSID->len == 0)
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx Probe resp: SSID len = 0 \n");
+
+       if (sFrame.pDSParms != 0) {
+               if (byCurrChannel > CB_MAX_CHANNEL_24G) {
+                       // channel remapping to
+                       byIEChannel = get_channel_mapping(pMgmt->pAdapter, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
+               } else {
+                       byIEChannel = sFrame.pDSParms->byCurrChannel;
+               }
+               if (byCurrChannel != byIEChannel) {
+                       // adjust channel info. bcs we rcv adjacent channel packets
+                       bChannelHit = false;
+                       byCurrChannel = byIEChannel;
+               }
+       } else {
+               // no DS channel info
+               bChannelHit = true;
+       }
 
 //2008-0730-01<Add>by MikeLiu
-if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
-      return;
-
-    if (sFrame.pERP != NULL) {
-        sERP.byERP = sFrame.pERP->byContext;
-        sERP.bERPExist = true;
-    } else {
-        sERP.bERPExist = false;
-        sERP.byERP = 0;
-    }
-
-
-    // update or insert the bss
-    pBSSList = BSSpAddrIsInBSSList((void *)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
-    if (pBSSList) {
-        BSSbUpdateToBSSList((void *)pDevice,
-                            *sFrame.pqwTimestamp,
-                            *sFrame.pwBeaconInterval,
-                            *sFrame.pwCapInfo,
-                            byCurrChannel,
-                            bChannelHit,
-                            sFrame.pSSID,
-                            sFrame.pSuppRates,
-                            sFrame.pExtSuppRates,
-                            &sERP,
-                            sFrame.pRSN,
-                            sFrame.pRSNWPA,
-                            sFrame.pIE_Country,
-                            sFrame.pIE_Quiet,
-                            pBSSList,
-                            sFrame.len - WLAN_HDR_ADDR3_LEN,
-                            sFrame.pHdr->sA4.abyAddr4,   // payload of probresponse
-                            (void *)pRxPacket
-                           );
-    }
-    else {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Probe resp/insert: RxChannel = : %d\n", byCurrChannel);
-        BSSbInsertToBSSList((void *)pDevice,
-                            sFrame.pHdr->sA3.abyAddr3,
-                            *sFrame.pqwTimestamp,
-                            *sFrame.pwBeaconInterval,
-                            *sFrame.pwCapInfo,
-                            byCurrChannel,
-                            sFrame.pSSID,
-                            sFrame.pSuppRates,
-                            sFrame.pExtSuppRates,
-                            &sERP,
-                            sFrame.pRSN,
-                            sFrame.pRSNWPA,
-                            sFrame.pIE_Country,
-                            sFrame.pIE_Quiet,
-                            sFrame.len - WLAN_HDR_ADDR3_LEN,
-                            sFrame.pHdr->sA4.abyAddr4,   // payload of beacon
-                            (void *)pRxPacket
-                           );
-    }
-    return;
+       if (ChannelExceedZoneType(pDevice, byCurrChannel) == true)
+               return;
+
+       if (sFrame.pERP != NULL) {
+               sERP.byERP = sFrame.pERP->byContext;
+               sERP.bERPExist = true;
+       } else {
+               sERP.bERPExist = false;
+               sERP.byERP = 0;
+       }
 
+       // update or insert the bss
+       pBSSList = BSSpAddrIsInBSSList((void *)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
+       if (pBSSList) {
+               BSSbUpdateToBSSList((void *)pDevice,
+                                   *sFrame.pqwTimestamp,
+                                   *sFrame.pwBeaconInterval,
+                                   *sFrame.pwCapInfo,
+                                   byCurrChannel,
+                                   bChannelHit,
+                                   sFrame.pSSID,
+                                   sFrame.pSuppRates,
+                                   sFrame.pExtSuppRates,
+                                   &sERP,
+                                   sFrame.pRSN,
+                                   sFrame.pRSNWPA,
+                                   sFrame.pIE_Country,
+                                   sFrame.pIE_Quiet,
+                                   pBSSList,
+                                   sFrame.len - WLAN_HDR_ADDR3_LEN,
+                                   sFrame.pHdr->sA4.abyAddr4,   // payload of probresponse
+                                   (void *)pRxPacket
+);
+       } else {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe resp/insert: RxChannel = : %d\n", byCurrChannel);
+               BSSbInsertToBSSList((void *)pDevice,
+                                   sFrame.pHdr->sA3.abyAddr3,
+                                   *sFrame.pqwTimestamp,
+                                   *sFrame.pwBeaconInterval,
+                                   *sFrame.pwCapInfo,
+                                   byCurrChannel,
+                                   sFrame.pSSID,
+                                   sFrame.pSuppRates,
+                                   sFrame.pExtSuppRates,
+                                   &sERP,
+                                   sFrame.pRSN,
+                                   sFrame.pRSNWPA,
+                                   sFrame.pIE_Country,
+                                   sFrame.pIE_Quiet,
+                                   sFrame.len - WLAN_HDR_ADDR3_LEN,
+                                   sFrame.pHdr->sA4.abyAddr4,   // payload of beacon
+                                   (void *)pRxPacket
+);
+       }
+       return;
 }
 
 /*+
@@ -4412,84 +4206,77 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
  * Return Value:
  *    none.
  *
--*/
-
+ -*/
 
 static
 void
 s_vMgrRxProbeRequest(
-    PSDevice pDevice,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-    )
+       PSDevice pDevice,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+)
 {
-    WLAN_FR_PROBEREQ    sFrame;
-    CMD_STATUS          Status;
-    PSTxMgmtPacket      pTxPacket;
-    unsigned char byPHYType = BB_TYPE_11B;
-
-    // STA in Ad-hoc mode: when latest TBTT beacon transmit success,
-    // STA have to response this request.
-    if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
-        ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && pDevice->bBeaconSent)) {
-
-        memset(&sFrame, 0, sizeof(WLAN_FR_PROBEREQ));
-        // decode the frame
-        sFrame.len = pRxPacket->cbMPDULen;
-        sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
-        vMgrDecodeProbeRequest(&sFrame);
+       WLAN_FR_PROBEREQ    sFrame;
+       CMD_STATUS          Status;
+       PSTxMgmtPacket      pTxPacket;
+       unsigned char byPHYType = BB_TYPE_11B;
+
+       // STA in Ad-hoc mode: when latest TBTT beacon transmit success,
+       // STA have to response this request.
+       if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
+           ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && pDevice->bBeaconSent)) {
+               memset(&sFrame, 0, sizeof(WLAN_FR_PROBEREQ));
+               // decode the frame
+               sFrame.len = pRxPacket->cbMPDULen;
+               sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
+               vMgrDecodeProbeRequest(&sFrame);
 /*
-       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request rx:MAC addr:%pM\n",
-               sFrame.pHdr->sA3.abyAddr2);
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request rx:MAC addr:%pM\n",
+  sFrame.pHdr->sA3.abyAddr2);
 */
-        if (sFrame.pSSID->len != 0) {
-            if (sFrame.pSSID->len != ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)
-                return;
-            if (memcmp(sFrame.pSSID->abySSID,
-                       ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
-                       ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) != 0) {
-                       return;
-            }
-        }
-
-        if ((sFrame.pSuppRates->len > 4) || (sFrame.pExtSuppRates != NULL)) {
-            byPHYType = BB_TYPE_11G;
-        }
-
-        // Probe response reply..
-        pTxPacket = s_MgrMakeProbeResponse
-                    (
-                      pDevice,
-                      pMgmt,
-                      pMgmt->wCurrCapInfo,
-                      pMgmt->wCurrBeaconPeriod,
-                      pMgmt->uCurrChannel,
-                      0,
-                      sFrame.pHdr->sA3.abyAddr2,
-                      (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
-                      (unsigned char *)pMgmt->abyCurrBSSID,
-                      (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                      (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
-                       byPHYType
-                    );
-        if (pTxPacket != NULL ){
-            /* send the frame */
-            Status = csMgmt_xmit(pDevice, pTxPacket);
-            if (Status != CMD_STATUS_PENDING) {
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx failed\n");
-            }
-            else {
-//                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx sending..\n");
-            }
-        }
-    }
-
-    return;
-}
-
+               if (sFrame.pSSID->len != 0) {
+                       if (sFrame.pSSID->len != ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)
+                               return;
+                       if (memcmp(sFrame.pSSID->abySSID,
+                                  ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
+                                  ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) != 0) {
+                               return;
+                       }
+               }
 
+               if ((sFrame.pSuppRates->len > 4) || (sFrame.pExtSuppRates != NULL)) {
+                       byPHYType = BB_TYPE_11G;
+               }
 
+               // Probe response reply..
+               pTxPacket = s_MgrMakeProbeResponse
+                       (
+                               pDevice,
+                               pMgmt,
+                               pMgmt->wCurrCapInfo,
+                               pMgmt->wCurrBeaconPeriod,
+                               pMgmt->uCurrChannel,
+                               0,
+                               sFrame.pHdr->sA3.abyAddr2,
+                               (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
+                               (unsigned char *)pMgmt->abyCurrBSSID,
+                               (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                               (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
+                               byPHYType
+);
+               if (pTxPacket != NULL) {
+                       /* send the frame */
+                       Status = csMgmt_xmit(pDevice, pTxPacket);
+                       if (Status != CMD_STATUS_PENDING) {
+                               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx failed\n");
+                       } else {
+//                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx sending..\n");
+                       }
+               }
+       }
 
+       return;
+}
 
 /*+
  *
@@ -4503,146 +4290,139 @@ s_vMgrRxProbeRequest(
  * Return Value:
  *    none.
  *
--*/
-
+ -*/
 
 void
 vMgrRxManagePacket(
-    void *hDeviceContext,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-     )
+       void *hDeviceContext,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+)
 {
-    PSDevice    pDevice = (PSDevice)hDeviceContext;
-    bool bInScan = false;
-    unsigned int uNodeIndex = 0;
-    NODE_STATE  eNodeState = 0;
-    CMD_STATUS  Status;
-
-
-    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-        if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
-            eNodeState = pMgmt->sNodeDBTable[uNodeIndex].eNodeState;
-    }
-
-    switch( WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) ){
-
-        case WLAN_FSTYPE_ASSOCREQ:
-            // Frame Clase = 2
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocreq\n");
-            if (eNodeState < NODE_AUTH) {
-                // send deauth notification
-                // reason = (6) class 2 received from nonauth sta
-                vMgrDeAuthenBeginSta(pDevice,
-                                     pMgmt,
-                                     pRxPacket->p80211Header->sA3.abyAddr2,
-                                     (6),
-                                     &Status
-                                     );
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 1\n");
-            }
-            else {
-                s_vMgrRxAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
-            }
-            break;
-
-        case WLAN_FSTYPE_ASSOCRESP:
-            // Frame Clase = 2
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp1\n");
-            s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, false);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp2\n");
-            break;
-
-        case WLAN_FSTYPE_REASSOCREQ:
-            // Frame Clase = 2
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocreq\n");
-            // Todo: reassoc
-            if (eNodeState < NODE_AUTH) {
-                // send deauth notification
-                // reason = (6) class 2 received from nonauth sta
-                vMgrDeAuthenBeginSta(pDevice,
-                                     pMgmt,
-                                     pRxPacket->p80211Header->sA3.abyAddr2,
-                                     (6),
-                                     &Status
-                                     );
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 2\n");
-
-            }
-            s_vMgrRxReAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
-            break;
-
-        case WLAN_FSTYPE_REASSOCRESP:
-            // Frame Clase = 2
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocresp\n");
-            s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, true);
-            break;
-
-        case WLAN_FSTYPE_PROBEREQ:
-            // Frame Clase = 0
-            //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx probereq\n");
-            s_vMgrRxProbeRequest(pDevice, pMgmt, pRxPacket);
-            break;
-
-        case WLAN_FSTYPE_PROBERESP:
-            // Frame Clase = 0
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx proberesp\n");
-
-            s_vMgrRxProbeResponse(pDevice, pMgmt, pRxPacket);
-            break;
-
-        case WLAN_FSTYPE_BEACON:
-            // Frame Clase = 0
-            //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx beacon\n");
-            if (pMgmt->eScanState != WMAC_NO_SCANNING) {
-                bInScan = true;
-            }
-            s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan);
-            break;
-
-        case WLAN_FSTYPE_ATIM:
-            // Frame Clase = 1
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx atim\n");
-            break;
-
-        case WLAN_FSTYPE_DISASSOC:
-            // Frame Clase = 2
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx disassoc\n");
-            if (eNodeState < NODE_AUTH) {
-                // send deauth notification
-                // reason = (6) class 2 received from nonauth sta
-                vMgrDeAuthenBeginSta(pDevice,
-                                     pMgmt,
-                                     pRxPacket->p80211Header->sA3.abyAddr2,
-                                     (6),
-                                     &Status
-                                     );
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 3\n");
-            }
-            s_vMgrRxDisassociation(pDevice, pMgmt, pRxPacket);
-            break;
-
-        case WLAN_FSTYPE_AUTHEN:
-            // Frame Clase = 1
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO  "rx authen\n");
-            s_vMgrRxAuthentication(pDevice, pMgmt, pRxPacket);
-            break;
-
-        case WLAN_FSTYPE_DEAUTHEN:
-            // Frame Clase = 1
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx deauthen\n");
-            s_vMgrRxDeauthentication(pDevice, pMgmt, pRxPacket);
-            break;
-
-        default:
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx unknown mgmt\n");
-    }
-
-    return;
-}
+       PSDevice    pDevice = (PSDevice)hDeviceContext;
+       bool bInScan = false;
+       unsigned int uNodeIndex = 0;
+       NODE_STATE  eNodeState = 0;
+       CMD_STATUS  Status;
+
+       if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
+               if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
+                       eNodeState = pMgmt->sNodeDBTable[uNodeIndex].eNodeState;
+       }
+
+       switch (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl))) {
+       case WLAN_FSTYPE_ASSOCREQ:
+               // Frame Clase = 2
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocreq\n");
+               if (eNodeState < NODE_AUTH) {
+                       // send deauth notification
+                       // reason = (6) class 2 received from nonauth sta
+                       vMgrDeAuthenBeginSta(pDevice,
+                                            pMgmt,
+                                            pRxPacket->p80211Header->sA3.abyAddr2,
+                                            (6),
+                                            &Status
+);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 1\n");
+               } else {
+                       s_vMgrRxAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
+               }
+               break;
+
+       case WLAN_FSTYPE_ASSOCRESP:
+               // Frame Clase = 2
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp1\n");
+               s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, false);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp2\n");
+               break;
+
+       case WLAN_FSTYPE_REASSOCREQ:
+               // Frame Clase = 2
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocreq\n");
+               // Todo: reassoc
+               if (eNodeState < NODE_AUTH) {
+                       // send deauth notification
+                       // reason = (6) class 2 received from nonauth sta
+                       vMgrDeAuthenBeginSta(pDevice,
+                                            pMgmt,
+                                            pRxPacket->p80211Header->sA3.abyAddr2,
+                                            (6),
+                                            &Status
+);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 2\n");
+
+               }
+               s_vMgrRxReAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
+               break;
+
+       case WLAN_FSTYPE_REASSOCRESP:
+               // Frame Clase = 2
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocresp\n");
+               s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, true);
+               break;
+
+       case WLAN_FSTYPE_PROBEREQ:
+               // Frame Clase = 0
+               //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx probereq\n");
+               s_vMgrRxProbeRequest(pDevice, pMgmt, pRxPacket);
+               break;
+
+       case WLAN_FSTYPE_PROBERESP:
+               // Frame Clase = 0
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx proberesp\n");
+
+               s_vMgrRxProbeResponse(pDevice, pMgmt, pRxPacket);
+               break;
 
+       case WLAN_FSTYPE_BEACON:
+               // Frame Clase = 0
+               //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx beacon\n");
+               if (pMgmt->eScanState != WMAC_NO_SCANNING) {
+                       bInScan = true;
+               }
+               s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan);
+               break;
+
+       case WLAN_FSTYPE_ATIM:
+               // Frame Clase = 1
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx atim\n");
+               break;
 
+       case WLAN_FSTYPE_DISASSOC:
+               // Frame Clase = 2
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx disassoc\n");
+               if (eNodeState < NODE_AUTH) {
+                       // send deauth notification
+                       // reason = (6) class 2 received from nonauth sta
+                       vMgrDeAuthenBeginSta(pDevice,
+                                            pMgmt,
+                                            pRxPacket->p80211Header->sA3.abyAddr2,
+                                            (6),
+                                            &Status
+);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 3\n");
+               }
+               s_vMgrRxDisassociation(pDevice, pMgmt, pRxPacket);
+               break;
 
+       case WLAN_FSTYPE_AUTHEN:
+               // Frame Clase = 1
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO  "rx authen\n");
+               s_vMgrRxAuthentication(pDevice, pMgmt, pRxPacket);
+               break;
+
+       case WLAN_FSTYPE_DEAUTHEN:
+               // Frame Clase = 1
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx deauthen\n");
+               s_vMgrRxDeauthentication(pDevice, pMgmt, pRxPacket);
+               break;
+
+       default:
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx unknown mgmt\n");
+       }
+
+       return;
+}
 
 /*+
  *
@@ -4654,49 +4434,45 @@ vMgrRxManagePacket(
  * Return Value:
  *    true if success; false if failed.
  *
--*/
+ -*/
 bool
 bMgrPrepareBeaconToSend(
-    void *hDeviceContext,
-    PSMgmtObject pMgmt
-    )
+       void *hDeviceContext,
+       PSMgmtObject pMgmt
+)
 {
-    PSDevice            pDevice = (PSDevice)hDeviceContext;
-    PSTxMgmtPacket      pTxPacket;
+       PSDevice            pDevice = (PSDevice)hDeviceContext;
+       PSTxMgmtPacket      pTxPacket;
 
 //    pDevice->bBeaconBufReady = false;
-    if (pDevice->bEncryptionEnable || pDevice->bEnable8021x){
-        pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
-    }
-    else {
-        pMgmt->wCurrCapInfo &= ~WLAN_SET_CAP_INFO_PRIVACY(1);
-    }
-    pTxPacket = s_MgrMakeBeacon
-                (
-                  pDevice,
-                  pMgmt,
-                  pMgmt->wCurrCapInfo,
-                  pMgmt->wCurrBeaconPeriod,
-                  pMgmt->uCurrChannel,
-                  pMgmt->wCurrATIMWindow, //0,
-                  (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
-                  (unsigned char *)pMgmt->abyCurrBSSID,
-                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
-                  (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
-                );
-
-    if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
-        (pMgmt->abyCurrBSSID[0] == 0))
-        return false;
-
-    csBeacon_xmit(pDevice, pTxPacket);
-
-    return true;
+       if (pDevice->bEncryptionEnable || pDevice->bEnable8021x) {
+               pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
+       } else {
+               pMgmt->wCurrCapInfo &= ~WLAN_SET_CAP_INFO_PRIVACY(1);
+       }
+       pTxPacket = s_MgrMakeBeacon
+               (
+                       pDevice,
+                       pMgmt,
+                       pMgmt->wCurrCapInfo,
+                       pMgmt->wCurrBeaconPeriod,
+                       pMgmt->uCurrChannel,
+                       pMgmt->wCurrATIMWindow, //0,
+                       (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
+                       (unsigned char *)pMgmt->abyCurrBSSID,
+                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
+                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
+);
+
+       if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
+           (pMgmt->abyCurrBSSID[0] == 0))
+               return false;
+
+       csBeacon_xmit(pDevice, pTxPacket);
+
+       return true;
 }
 
-
-
-
 /*+
  *
  * Routine Description:
@@ -4708,61 +4484,60 @@ bMgrPrepareBeaconToSend(
  * Return Value:
  *    none.
  *
--*/
+ -*/
 static
 void
 s_vMgrLogStatus(
-    PSMgmtObject pMgmt,
-    unsigned short wStatus
-    )
+       PSMgmtObject pMgmt,
+       unsigned short wStatus
+)
 {
-    switch( wStatus ){
-        case WLAN_MGMT_STATUS_UNSPEC_FAILURE:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Unspecified error.\n");
-            break;
-        case WLAN_MGMT_STATUS_CAPS_UNSUPPORTED:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Can't support all requested capabilities.\n");
-            break;
-        case WLAN_MGMT_STATUS_REASSOC_NO_ASSOC:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Reassoc denied, can't confirm original Association.\n");
-            break;
-        case WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, undefine in spec\n");
-            break;
-        case WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Peer doesn't support authen algorithm.\n");
-            break;
-        case WLAN_MGMT_STATUS_RX_AUTH_NOSEQ:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen frame received out of sequence.\n");
-            break;
-        case WLAN_MGMT_STATUS_CHALLENGE_FAIL:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, challenge  failure.\n");
-            break;
-        case WLAN_MGMT_STATUS_AUTH_TIMEOUT:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, timeout waiting for next frame.\n");
-            break;
-        case WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, AP too busy.\n");
-            break;
-        case WLAN_MGMT_STATUS_ASSOC_DENIED_RATES:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we haven't enough basic rates.\n");
-            break;
-        case WLAN_MGMT_STATUS_ASSOC_DENIED_SHORTPREAMBLE:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support short preamble.\n");
-            break;
-        case WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support PBCC.\n");
-            break;
-        case WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support channel agility.\n");
-            break;
-        default:
-            DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Unknown status code %d.\n", wStatus);
-            break;
-    }
+       switch (wStatus) {
+       case WLAN_MGMT_STATUS_UNSPEC_FAILURE:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Unspecified error.\n");
+               break;
+       case WLAN_MGMT_STATUS_CAPS_UNSUPPORTED:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Can't support all requested capabilities.\n");
+               break;
+       case WLAN_MGMT_STATUS_REASSOC_NO_ASSOC:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Reassoc denied, can't confirm original Association.\n");
+               break;
+       case WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, undefine in spec\n");
+               break;
+       case WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Peer doesn't support authen algorithm.\n");
+               break;
+       case WLAN_MGMT_STATUS_RX_AUTH_NOSEQ:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen frame received out of sequence.\n");
+               break;
+       case WLAN_MGMT_STATUS_CHALLENGE_FAIL:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, challenge  failure.\n");
+               break;
+       case WLAN_MGMT_STATUS_AUTH_TIMEOUT:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, timeout waiting for next frame.\n");
+               break;
+       case WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, AP too busy.\n");
+               break;
+       case WLAN_MGMT_STATUS_ASSOC_DENIED_RATES:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we haven't enough basic rates.\n");
+               break;
+       case WLAN_MGMT_STATUS_ASSOC_DENIED_SHORTPREAMBLE:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support short preamble.\n");
+               break;
+       case WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support PBCC.\n");
+               break;
+       case WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support channel agility.\n");
+               break;
+       default:
+               DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Unknown status code %d.\n", wStatus);
+               break;
+       }
 }
 
-
 /*
  *
  * Description:
@@ -4778,52 +4553,50 @@ s_vMgrLogStatus(
  *
  * Return Value: none.
  *
--*/
+ -*/
 bool
-bAdd_PMKID_Candidate (
-    void *hDeviceContext,
-    unsigned char *pbyBSSID,
-    PSRSNCapObject psRSNCapObj
-    )
+bAdd_PMKID_Candidate(
+       void *hDeviceContext,
+       unsigned char *pbyBSSID,
+       PSRSNCapObject psRSNCapObj
+)
 {
-    PSDevice         pDevice = (PSDevice)hDeviceContext;
-    PPMKID_CANDIDATE pCandidateList;
-    unsigned int ii = 0;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
-
-    if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL))
-        return false;
-
-    if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST)
-        return false;
-
-
-
-    // Update Old Candidate
-    for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
-        pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
-        if ( !memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
-            if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) {
-                pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
-            } else {
-                pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
-            }
-            return true;
-        }
-    }
-
-    // New Candidate
-    pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
-    if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) {
-        pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
-    } else {
-        pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
-    }
-    memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
-    pDevice->gsPMKIDCandidate.NumCandidates++;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
-    return true;
+       PSDevice         pDevice = (PSDevice)hDeviceContext;
+       PPMKID_CANDIDATE pCandidateList;
+       unsigned int ii = 0;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
+
+       if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL))
+               return false;
+
+       if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST)
+               return false;
+
+       // Update Old Candidate
+       for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
+               pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
+               if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
+                       if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) {
+                               pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
+                       } else {
+                               pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
+                       }
+                       return true;
+               }
+       }
+
+       // New Candidate
+       pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
+       if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) {
+               pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
+       } else {
+               pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
+       }
+       memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
+       pDevice->gsPMKIDCandidate.NumCandidates++;
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
+       return true;
 }
 
 /*
@@ -4839,166 +4612,163 @@ bAdd_PMKID_Candidate (
  *
  * Return Value: none.
  *
--*/
+ -*/
 void
-vFlush_PMKID_Candidate (
-    void *hDeviceContext
-    )
+vFlush_PMKID_Candidate(
+       void *hDeviceContext
+)
 {
-    PSDevice        pDevice = (PSDevice)hDeviceContext;
+       PSDevice        pDevice = (PSDevice)hDeviceContext;
 
-    if (pDevice == NULL)
-        return;
+       if (pDevice == NULL)
+               return;
 
-    memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
+       memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
 }
 
 static bool
-s_bCipherMatch (
-    PKnownBSS                        pBSSNode,
-    NDIS_802_11_ENCRYPTION_STATUS    EncStatus,
-    unsigned char *pbyCCSPK,
-    unsigned char *pbyCCSGK
-    )
+s_bCipherMatch(
+       PKnownBSS                        pBSSNode,
+       NDIS_802_11_ENCRYPTION_STATUS    EncStatus,
+       unsigned char *pbyCCSPK,
+       unsigned char *pbyCCSGK
+)
 {
-    unsigned char byMulticastCipher = KEY_CTL_INVALID;
-    unsigned char byCipherMask = 0x00;
-    int i;
-
-    if (pBSSNode == NULL)
-        return false;
-
-    // check cap. of BSS
-    if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
-         (EncStatus == Ndis802_11Encryption1Enabled)) {
-        // default is WEP only
-        byMulticastCipher = KEY_CTL_WEP;
-    }
-
-    if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
-        (pBSSNode->bWPA2Valid == true) &&
-          //20080123-01,<Add> by Einsn Liu
-        ((EncStatus == Ndis802_11Encryption3Enabled)||(EncStatus == Ndis802_11Encryption2Enabled))) {
-        //WPA2
-        // check Group Key Cipher
-        if ((pBSSNode->byCSSGK == WLAN_11i_CSS_WEP40) ||
-            (pBSSNode->byCSSGK == WLAN_11i_CSS_WEP104)) {
-            byMulticastCipher = KEY_CTL_WEP;
-        } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_TKIP) {
-            byMulticastCipher = KEY_CTL_TKIP;
-        } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
-            byMulticastCipher = KEY_CTL_CCMP;
-        } else {
-            byMulticastCipher = KEY_CTL_INVALID;
-        }
-
-        // check Pairwise Key Cipher
-        for(i=0;i<pBSSNode->wCSSPKCount;i++) {
-            if ((pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP40) ||
-                (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP104)) {
-                // this should not happen as defined 802.11i
-                byCipherMask |= 0x01;
-            } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_TKIP) {
-                byCipherMask |= 0x02;
-            } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_CCMP) {
-                byCipherMask |= 0x04;
-            } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_USE_GROUP) {
-                // use group key only ignore all others
-                byCipherMask = 0;
-                i = pBSSNode->wCSSPKCount;
-            }
-        }
-
-    } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
-                (pBSSNode->bWPAValid == true) &&
-                ((EncStatus == Ndis802_11Encryption3Enabled) || (EncStatus == Ndis802_11Encryption2Enabled))) {
-        //WPA
-        // check Group Key Cipher
-        if ((pBSSNode->byGKType == WPA_WEP40) ||
-            (pBSSNode->byGKType == WPA_WEP104)) {
-            byMulticastCipher = KEY_CTL_WEP;
-        } else if (pBSSNode->byGKType == WPA_TKIP) {
-            byMulticastCipher = KEY_CTL_TKIP;
-        } else if (pBSSNode->byGKType == WPA_AESCCMP) {
-            byMulticastCipher = KEY_CTL_CCMP;
-        } else {
-            byMulticastCipher = KEY_CTL_INVALID;
-        }
-
-        // check Pairwise Key Cipher
-        for(i=0;i<pBSSNode->wPKCount;i++) {
-            if (pBSSNode->abyPKType[i] == WPA_TKIP) {
-                byCipherMask |= 0x02;
-            } else if (pBSSNode->abyPKType[i] == WPA_AESCCMP) {
-                byCipherMask |= 0x04;
-            } else if (pBSSNode->abyPKType[i] == WPA_NONE) {
-                // use group key only ignore all others
-                byCipherMask = 0;
-                i = pBSSNode->wPKCount;
-            }
-        }
-    }
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%d, %d, %d, %d, EncStatus:%d\n",
-        byMulticastCipher, byCipherMask, pBSSNode->bWPAValid, pBSSNode->bWPA2Valid, EncStatus);
-
-    // mask our cap. with BSS
-    if (EncStatus == Ndis802_11Encryption1Enabled) {
-
-        // For supporting Cisco migration mode, don't care pairwise key cipher
-        if ((byMulticastCipher == KEY_CTL_WEP) &&
-            (byCipherMask == 0)) {
-            *pbyCCSGK = KEY_CTL_WEP;
-            *pbyCCSPK = KEY_CTL_NONE;
-            return true;
-        } else {
-            return false;
-        }
-
-    } else if (EncStatus == Ndis802_11Encryption2Enabled) {
-        if ((byMulticastCipher == KEY_CTL_TKIP) &&
-            (byCipherMask == 0)) {
-            *pbyCCSGK = KEY_CTL_TKIP;
-            *pbyCCSPK = KEY_CTL_NONE;
-            return true;
-        } else if ((byMulticastCipher == KEY_CTL_WEP) &&
-                   ((byCipherMask & 0x02) != 0)) {
-            *pbyCCSGK = KEY_CTL_WEP;
-            *pbyCCSPK = KEY_CTL_TKIP;
-            return true;
-        } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
-                   ((byCipherMask & 0x02) != 0)) {
-            *pbyCCSGK = KEY_CTL_TKIP;
-            *pbyCCSPK = KEY_CTL_TKIP;
-            return true;
-        } else {
-            return false;
-        }
-    } else if (EncStatus == Ndis802_11Encryption3Enabled) {
-        if ((byMulticastCipher == KEY_CTL_CCMP) &&
-            (byCipherMask == 0)) {
-            // When CCMP is enable, "Use group cipher suite" shall not be a valid option.
-            return false;
-        } else if ((byMulticastCipher == KEY_CTL_WEP) &&
-                   ((byCipherMask & 0x04) != 0)) {
-            *pbyCCSGK = KEY_CTL_WEP;
-            *pbyCCSPK = KEY_CTL_CCMP;
-            return true;
-        } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
-                   ((byCipherMask & 0x04) != 0)) {
-            *pbyCCSGK = KEY_CTL_TKIP;
-            *pbyCCSPK = KEY_CTL_CCMP;
-            return true;
-        } else if ((byMulticastCipher == KEY_CTL_CCMP) &&
-                   ((byCipherMask & 0x04) != 0)) {
-            *pbyCCSGK = KEY_CTL_CCMP;
-            *pbyCCSPK = KEY_CTL_CCMP;
-            return true;
-        } else {
-            return false;
-        }
-    }
-    return true;
-}
+       unsigned char byMulticastCipher = KEY_CTL_INVALID;
+       unsigned char byCipherMask = 0x00;
+       int i;
+
+       if (pBSSNode == NULL)
+               return false;
+
+       // check cap. of BSS
+       if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
+           (EncStatus == Ndis802_11Encryption1Enabled)) {
+               // default is WEP only
+               byMulticastCipher = KEY_CTL_WEP;
+       }
+
+       if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
+           (pBSSNode->bWPA2Valid == true) &&
+           //20080123-01,<Add> by Einsn Liu
+           ((EncStatus == Ndis802_11Encryption3Enabled) || (EncStatus == Ndis802_11Encryption2Enabled))) {
+               //WPA2
+               // check Group Key Cipher
+               if ((pBSSNode->byCSSGK == WLAN_11i_CSS_WEP40) ||
+                   (pBSSNode->byCSSGK == WLAN_11i_CSS_WEP104)) {
+                       byMulticastCipher = KEY_CTL_WEP;
+               } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_TKIP) {
+                       byMulticastCipher = KEY_CTL_TKIP;
+               } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
+                       byMulticastCipher = KEY_CTL_CCMP;
+               } else {
+                       byMulticastCipher = KEY_CTL_INVALID;
+               }
+
+               // check Pairwise Key Cipher
+               for (i = 0; i < pBSSNode->wCSSPKCount; i++) {
+                       if ((pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP40) ||
+                           (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP104)) {
+                               // this should not happen as defined 802.11i
+                               byCipherMask |= 0x01;
+                       } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_TKIP) {
+                               byCipherMask |= 0x02;
+                       } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_CCMP) {
+                               byCipherMask |= 0x04;
+                       } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_USE_GROUP) {
+                               // use group key only ignore all others
+                               byCipherMask = 0;
+                               i = pBSSNode->wCSSPKCount;
+                       }
+               }
 
+       } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
+                  (pBSSNode->bWPAValid == true) &&
+                  ((EncStatus == Ndis802_11Encryption3Enabled) || (EncStatus == Ndis802_11Encryption2Enabled))) {
+               //WPA
+               // check Group Key Cipher
+               if ((pBSSNode->byGKType == WPA_WEP40) ||
+                   (pBSSNode->byGKType == WPA_WEP104)) {
+                       byMulticastCipher = KEY_CTL_WEP;
+               } else if (pBSSNode->byGKType == WPA_TKIP) {
+                       byMulticastCipher = KEY_CTL_TKIP;
+               } else if (pBSSNode->byGKType == WPA_AESCCMP) {
+                       byMulticastCipher = KEY_CTL_CCMP;
+               } else {
+                       byMulticastCipher = KEY_CTL_INVALID;
+               }
 
+               // check Pairwise Key Cipher
+               for (i = 0; i < pBSSNode->wPKCount; i++) {
+                       if (pBSSNode->abyPKType[i] == WPA_TKIP) {
+                               byCipherMask |= 0x02;
+                       } else if (pBSSNode->abyPKType[i] == WPA_AESCCMP) {
+                               byCipherMask |= 0x04;
+                       } else if (pBSSNode->abyPKType[i] == WPA_NONE) {
+                               // use group key only ignore all others
+                               byCipherMask = 0;
+                               i = pBSSNode->wPKCount;
+                       }
+               }
+       }
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%d, %d, %d, %d, EncStatus:%d\n",
+               byMulticastCipher, byCipherMask, pBSSNode->bWPAValid, pBSSNode->bWPA2Valid, EncStatus);
+
+       // mask our cap. with BSS
+       if (EncStatus == Ndis802_11Encryption1Enabled) {
+               // For supporting Cisco migration mode, don't care pairwise key cipher
+               if ((byMulticastCipher == KEY_CTL_WEP) &&
+                   (byCipherMask == 0)) {
+                       *pbyCCSGK = KEY_CTL_WEP;
+                       *pbyCCSPK = KEY_CTL_NONE;
+                       return true;
+               } else {
+                       return false;
+               }
+
+       } else if (EncStatus == Ndis802_11Encryption2Enabled) {
+               if ((byMulticastCipher == KEY_CTL_TKIP) &&
+                   (byCipherMask == 0)) {
+                       *pbyCCSGK = KEY_CTL_TKIP;
+                       *pbyCCSPK = KEY_CTL_NONE;
+                       return true;
+               } else if ((byMulticastCipher == KEY_CTL_WEP) &&
+                          ((byCipherMask & 0x02) != 0)) {
+                       *pbyCCSGK = KEY_CTL_WEP;
+                       *pbyCCSPK = KEY_CTL_TKIP;
+                       return true;
+               } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
+                          ((byCipherMask & 0x02) != 0)) {
+                       *pbyCCSGK = KEY_CTL_TKIP;
+                       *pbyCCSPK = KEY_CTL_TKIP;
+                       return true;
+               } else {
+                       return false;
+               }
+       } else if (EncStatus == Ndis802_11Encryption3Enabled) {
+               if ((byMulticastCipher == KEY_CTL_CCMP) &&
+                   (byCipherMask == 0)) {
+                       // When CCMP is enable, "Use group cipher suite" shall not be a valid option.
+                       return false;
+               } else if ((byMulticastCipher == KEY_CTL_WEP) &&
+                          ((byCipherMask & 0x04) != 0)) {
+                       *pbyCCSGK = KEY_CTL_WEP;
+                       *pbyCCSPK = KEY_CTL_CCMP;
+                       return true;
+               } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
+                          ((byCipherMask & 0x04) != 0)) {
+                       *pbyCCSGK = KEY_CTL_TKIP;
+                       *pbyCCSPK = KEY_CTL_CCMP;
+                       return true;
+               } else if ((byMulticastCipher == KEY_CTL_CCMP) &&
+                          ((byCipherMask & 0x04) != 0)) {
+                       *pbyCCSGK = KEY_CTL_CCMP;
+                       *pbyCCSPK = KEY_CTL_CCMP;
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+       return true;
+}
index bfa67ae5d40a58608fece072eeec43899b73236b..b91f1f89ed05f1e970a0c0c7cb9fd2324d9cacca 100644 (file)
@@ -45,8 +45,6 @@
 
 /*---------------------  Export Definitions -------------------------*/
 
-
-
 // Scan time
 #define PROBE_DELAY                  100  // (us)
 #define SWITCH_CHANNEL_DELAY         200 // (us)
@@ -58,7 +56,6 @@
 #define WCMD_ACTIVE_SCAN_TIME   50 //(ms)
 #define WCMD_PASSIVE_SCAN_TIME  100 //(ms)
 
-
 #define DEFAULT_MSDU_LIFETIME           512  // ms
 #define DEFAULT_MSDU_LIFETIME_RES_64us  8000 // 64us
 
@@ -67,7 +64,6 @@
 
 #define MAKE_BEACON_RESERVED            10  //(us)
 
-
 #define TIM_MULTICAST_MASK           0x01
 #define TIM_BITMAPOFFSET_MASK        0xFE
 #define DEFAULT_DTIM_PERIOD             1
 
 #define DEFAULT_IBSS_CHANNEL            6  //2.4G
 
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 
 /*---------------------  Export Types  ------------------------------*/
-#define timer_expire(timer,next_tick)   mod_timer(&timer, RUN_AT(next_tick))
+#define timer_expire(timer, next_tick)   mod_timer(&timer, RUN_AT(next_tick))
 typedef void (*TimerFunction)(unsigned long);
 
-
 //+++ NDIS related
 
 typedef unsigned char NDIS_802_11_MAC_ADDRESS[6];
 typedef struct _NDIS_802_11_AI_REQFI
 {
-    unsigned short Capabilities;
-    unsigned short ListenInterval;
-    NDIS_802_11_MAC_ADDRESS  CurrentAPAddress;
+       unsigned short Capabilities;
+       unsigned short ListenInterval;
+       NDIS_802_11_MAC_ADDRESS  CurrentAPAddress;
 } NDIS_802_11_AI_REQFI, *PNDIS_802_11_AI_REQFI;
 
 typedef struct _NDIS_802_11_AI_RESFI
 {
-    unsigned short Capabilities;
-    unsigned short StatusCode;
-    unsigned short AssociationId;
+       unsigned short Capabilities;
+       unsigned short StatusCode;
+       unsigned short AssociationId;
 } NDIS_802_11_AI_RESFI, *PNDIS_802_11_AI_RESFI;
 
 typedef struct _NDIS_802_11_ASSOCIATION_INFORMATION
 {
-    unsigned long Length;
-    unsigned short          AvailableRequestFixedIEs;
-    NDIS_802_11_AI_REQFI    RequestFixedIEs;
-    unsigned long RequestIELength;
-    unsigned long OffsetRequestIEs;
-    unsigned short          AvailableResponseFixedIEs;
-    NDIS_802_11_AI_RESFI    ResponseFixedIEs;
-    unsigned long ResponseIELength;
-    unsigned long OffsetResponseIEs;
+       unsigned long Length;
+       unsigned short          AvailableRequestFixedIEs;
+       NDIS_802_11_AI_REQFI    RequestFixedIEs;
+       unsigned long RequestIELength;
+       unsigned long OffsetRequestIEs;
+       unsigned short          AvailableResponseFixedIEs;
+       NDIS_802_11_AI_RESFI    ResponseFixedIEs;
+       unsigned long ResponseIELength;
+       unsigned long OffsetResponseIEs;
 } NDIS_802_11_ASSOCIATION_INFORMATION, *PNDIS_802_11_ASSOCIATION_INFORMATION;
 
-
-
 typedef struct tagSAssocInfo {
-    NDIS_802_11_ASSOCIATION_INFORMATION     AssocInfo;
-    unsigned char abyIEs[WLAN_BEACON_FR_MAXLEN+WLAN_BEACON_FR_MAXLEN];
-    // store ReqIEs set by OID_802_11_ASSOCIATION_INFORMATION
-    unsigned long RequestIELength;
-    unsigned char abyReqIEs[WLAN_BEACON_FR_MAXLEN];
+       NDIS_802_11_ASSOCIATION_INFORMATION     AssocInfo;
+       unsigned char abyIEs[WLAN_BEACON_FR_MAXLEN+WLAN_BEACON_FR_MAXLEN];
+       // store ReqIEs set by OID_802_11_ASSOCIATION_INFORMATION
+       unsigned long RequestIELength;
+       unsigned char abyReqIEs[WLAN_BEACON_FR_MAXLEN];
 } SAssocInfo, *PSAssocInfo;
 //---
 
-
 /*
-typedef enum tagWMAC_AUTHENTICATION_MODE {
-
-
-    WMAC_AUTH_OPEN,
-    WMAC_AUTH_SHAREKEY,
-    WMAC_AUTH_AUTO,
-    WMAC_AUTH_WPA,
-    WMAC_AUTH_WPAPSK,
-    WMAC_AUTH_WPANONE,
-    WMAC_AUTH_WPA2,
-    WMAC_AUTH_WPA2PSK,
-    WMAC_AUTH_MAX       // Not a real mode, defined as upper bound
-
-
-} WMAC_AUTHENTICATION_MODE, *PWMAC_AUTHENTICATION_MODE;
+  typedef enum tagWMAC_AUTHENTICATION_MODE {
+  WMAC_AUTH_OPEN,
+  WMAC_AUTH_SHAREKEY,
+  WMAC_AUTH_AUTO,
+  WMAC_AUTH_WPA,
+  WMAC_AUTH_WPAPSK,
+  WMAC_AUTH_WPANONE,
+  WMAC_AUTH_WPA2,
+  WMAC_AUTH_WPA2PSK,
+  WMAC_AUTH_MAX       // Not a real mode, defined as upper bound
+
+  } WMAC_AUTHENTICATION_MODE, *PWMAC_AUTHENTICATION_MODE;
 */
 
-
 // Pre-configured Mode (from XP)
 /*
-typedef enum tagWMAC_CONFIG_MODE {
-    WMAC_CONFIG_ESS_STA,
-    WMAC_CONFIG_IBSS_STA,
-    WMAC_CONFIG_AUTO,
-    WMAC_CONFIG_AP
+  typedef enum tagWMAC_CONFIG_MODE {
+  WMAC_CONFIG_ESS_STA,
+  WMAC_CONFIG_IBSS_STA,
+  WMAC_CONFIG_AUTO,
+  WMAC_CONFIG_AP
 
-} WMAC_CONFIG_MODE, *PWMAC_CONFIG_MODE;
+  } WMAC_CONFIG_MODE, *PWMAC_CONFIG_MODE;
 */
 
 typedef enum tagWMAC_SCAN_TYPE {
-
-    WMAC_SCAN_ACTIVE,
-    WMAC_SCAN_PASSIVE,
-    WMAC_SCAN_HYBRID
-
+       WMAC_SCAN_ACTIVE,
+       WMAC_SCAN_PASSIVE,
+       WMAC_SCAN_HYBRID
 } WMAC_SCAN_TYPE, *PWMAC_SCAN_TYPE;
 
-
 typedef enum tagWMAC_SCAN_STATE {
-
-    WMAC_NO_SCANNING,
-    WMAC_IS_SCANNING,
-    WMAC_IS_PROBEPENDING
-
+       WMAC_NO_SCANNING,
+       WMAC_IS_SCANNING,
+       WMAC_IS_PROBEPENDING
 } WMAC_SCAN_STATE, *PWMAC_SCAN_STATE;
 
-
-
 // Notes:
 // Basic Service Set state explained as following:
 // WMAC_STATE_IDLE          : no BSS is selected (Adhoc or Infra)
@@ -188,315 +168,287 @@ typedef enum tagWMAC_SCAN_STATE {
 // WMAC_STATE_ASSOC         : Associated (Infra)
 
 typedef enum tagWMAC_BSS_STATE {
-
-    WMAC_STATE_IDLE,
-    WMAC_STATE_STARTED,
-    WMAC_STATE_JOINTED,
-    WMAC_STATE_AUTHPENDING,
-    WMAC_STATE_AUTH,
-    WMAC_STATE_ASSOCPENDING,
-    WMAC_STATE_ASSOC
-
+       WMAC_STATE_IDLE,
+       WMAC_STATE_STARTED,
+       WMAC_STATE_JOINTED,
+       WMAC_STATE_AUTHPENDING,
+       WMAC_STATE_AUTH,
+       WMAC_STATE_ASSOCPENDING,
+       WMAC_STATE_ASSOC
 } WMAC_BSS_STATE, *PWMAC_BSS_STATE;
 
 // WMAC selected running mode
 typedef enum tagWMAC_CURRENT_MODE {
-
-    WMAC_MODE_STANDBY,
-    WMAC_MODE_ESS_STA,
-    WMAC_MODE_IBSS_STA,
-    WMAC_MODE_ESS_AP
-
+       WMAC_MODE_STANDBY,
+       WMAC_MODE_ESS_STA,
+       WMAC_MODE_IBSS_STA,
+       WMAC_MODE_ESS_AP
 } WMAC_CURRENT_MODE, *PWMAC_CURRENT_MODE;
 
 /*
-typedef enum tagWMAC_POWER_MODE {
+  typedef enum tagWMAC_POWER_MODE {
+  WMAC_POWER_CAM,
+  WMAC_POWER_FAST,
+  WMAC_POWER_MAX
 
-    WMAC_POWER_CAM,
-    WMAC_POWER_FAST,
-    WMAC_POWER_MAX
-
-} WMAC_POWER_MODE, *PWMAC_POWER_MODE;
+  } WMAC_POWER_MODE, *PWMAC_POWER_MODE;
 */
 
-
 // Tx Management Packet descriptor
 typedef struct tagSTxMgmtPacket {
-
-    PUWLAN_80211HDR     p80211Header;
-    unsigned int cbMPDULen;
-    unsigned int cbPayloadLen;
-
+       PUWLAN_80211HDR     p80211Header;
+       unsigned int cbMPDULen;
+       unsigned int cbPayloadLen;
 } STxMgmtPacket, *PSTxMgmtPacket;
 
-
 // Rx Management Packet descriptor
 typedef struct tagSRxMgmtPacket {
-
-    PUWLAN_80211HDR     p80211Header;
-    QWORD               qwLocalTSF;
-    unsigned int cbMPDULen;
-    unsigned int cbPayloadLen;
-    unsigned int uRSSI;
-    unsigned char bySQ;
-    unsigned char byRxRate;
-    unsigned char byRxChannel;
-
+       PUWLAN_80211HDR     p80211Header;
+       QWORD               qwLocalTSF;
+       unsigned int cbMPDULen;
+       unsigned int cbPayloadLen;
+       unsigned int uRSSI;
+       unsigned char bySQ;
+       unsigned char byRxRate;
+       unsigned char byRxChannel;
 } SRxMgmtPacket, *PSRxMgmtPacket;
 
-
-
 typedef struct tagSMgmtObject
 {
+       void *pAdapter;
+       // MAC address
+       unsigned char abyMACAddr[WLAN_ADDR_LEN];
 
-    void *                   pAdapter;
-    // MAC address
-    unsigned char abyMACAddr[WLAN_ADDR_LEN];
-
-    // Configuration Mode
-    WMAC_CONFIG_MODE        eConfigMode; // MAC pre-configed mode
-    CARD_PHY_TYPE           eCurrentPHYMode;
-    CARD_PHY_TYPE           eConfigPHYMode;
-
+       // Configuration Mode
+       WMAC_CONFIG_MODE        eConfigMode; // MAC pre-configed mode
+       CARD_PHY_TYPE           eCurrentPHYMode;
+       CARD_PHY_TYPE           eConfigPHYMode;
 
-    // Operation state variables
-    WMAC_CURRENT_MODE       eCurrMode;   // MAC current connection mode
-    WMAC_BSS_STATE          eCurrState;  // MAC current BSS state
+       // Operation state variables
+       WMAC_CURRENT_MODE       eCurrMode;   // MAC current connection mode
+       WMAC_BSS_STATE          eCurrState;  // MAC current BSS state
 
-    PKnownBSS               pCurrBSS;
-    unsigned char byCSSGK;
-    unsigned char byCSSPK;
+       PKnownBSS               pCurrBSS;
+       unsigned char byCSSGK;
+       unsigned char byCSSPK;
 
 //    unsigned char abyNewSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
 //    unsigned char abyNewExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
 
-    // Current state vars
-    unsigned int       uCurrChannel;
-    unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
-    unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
-    unsigned char abyCurrSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
-    unsigned char abyCurrBSSID[WLAN_BSSID_LEN];
-    unsigned short wCurrCapInfo;
-    unsigned short wCurrAID;
-    unsigned short wCurrATIMWindow;
-    unsigned short wCurrBeaconPeriod;
-    bool bIsDS;
-    unsigned char byERPContext;
-
-    CMD_STATE               eCommandState;
-    unsigned int       uScanChannel;
-
-    // Desire joining BSS vars
-    unsigned char abyDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
-    unsigned char abyDesireBSSID[WLAN_BSSID_LEN];
-
-    // Adhoc or AP configuration vars
-  //unsigned char abyAdHocSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
-    unsigned short wIBSSBeaconPeriod;
-    unsigned short wIBSSATIMWindow;
-    unsigned int       uIBSSChannel;
-    unsigned char abyIBSSSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
-    unsigned char byAPBBType;
-    unsigned char abyWPAIE[MAX_WPA_IE_LEN];
-    unsigned short wWPAIELen;
-
-    unsigned int       uAssocCount;
-    bool bMoreData;
-
-    // Scan state vars
-    WMAC_SCAN_STATE         eScanState;
-    WMAC_SCAN_TYPE          eScanType;
-    unsigned int       uScanStartCh;
-    unsigned int       uScanEndCh;
-    unsigned short wScanSteps;
-    unsigned int       uScanBSSType;
-    // Desire scanning vars
-    unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
-    unsigned char abyScanBSSID[WLAN_BSSID_LEN];
-
-    // Privacy
-    WMAC_AUTHENTICATION_MODE eAuthenMode;
-    WMAC_ENCRYPTION_MODE    eEncryptionMode;
-    bool bShareKeyAlgorithm;
-    unsigned char abyChallenge[WLAN_CHALLENGE_LEN];
-    bool bPrivacyInvoked;
-
-    // Received beacon state vars
-    bool bInTIM;
-    bool bMulticastTIM;
-    unsigned char byDTIMCount;
-    unsigned char byDTIMPeriod;
-
-    // Power saving state vars
-    WMAC_POWER_MODE         ePSMode;
-    unsigned short wListenInterval;
-    unsigned short wCountToWakeUp;
-    bool bInTIMWake;
-    unsigned char *pbyPSPacketPool;
-    unsigned char byPSPacketPool[sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN];
-    bool bRxBeaconInTBTTWake;
-    unsigned char abyPSTxMap[MAX_NODE_NUM + 1];
-
-    // management command related
-    unsigned int       uCmdBusy;
-    unsigned int       uCmdHostAPBusy;
-
-    // management packet pool
-    unsigned char *pbyMgmtPacketPool;
-    unsigned char byMgmtPacketPool[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
-
-
-    // One second callback timer
-    struct timer_list      sTimerSecondCallback;
-
-    // Temporarily Rx Mgmt Packet Descriptor
-    SRxMgmtPacket           sRxPacket;
-
-    // link list of known bss's (scan results)
-    KnownBSS                sBSSList[MAX_BSS_NUM];
-
-
-
-    // table list of known node
-    // sNodeDBList[0] is reserved for AP under Infra mode
-    // sNodeDBList[0] is reserved for Multicast under adhoc/AP mode
-    KnownNodeDB             sNodeDBTable[MAX_NODE_NUM + 1];
-
-
-
-    // WPA2 PMKID Cache
-    SPMKIDCache             gsPMKIDCache;
-    bool bRoaming;
-
-    // rate fall back vars
-
-
-
-    // associate info
-    SAssocInfo              sAssocInfo;
-
-
-    // for 802.11h
-    bool b11hEnable;
-    bool bSwitchChannel;
-    unsigned char byNewChannel;
-    PWLAN_IE_MEASURE_REP    pCurrMeasureEIDRep;
-    unsigned int       uLengthOfRepEIDs;
-    unsigned char abyCurrentMSRReq[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
-    unsigned char abyCurrentMSRRep[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
-    unsigned char abyIECountry[WLAN_A3FR_MAXLEN];
-    unsigned char abyIBSSDFSOwner[6];
-    unsigned char byIBSSDFSRecovery;
-
-    struct sk_buff  skb;
-
+       // Current state vars
+       unsigned int    uCurrChannel;
+       unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
+       unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
+       unsigned char abyCurrSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
+       unsigned char abyCurrBSSID[WLAN_BSSID_LEN];
+       unsigned short wCurrCapInfo;
+       unsigned short wCurrAID;
+       unsigned short wCurrATIMWindow;
+       unsigned short wCurrBeaconPeriod;
+       bool bIsDS;
+       unsigned char byERPContext;
+
+       CMD_STATE               eCommandState;
+       unsigned int    uScanChannel;
+
+       // Desire joining BSS vars
+       unsigned char abyDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
+       unsigned char abyDesireBSSID[WLAN_BSSID_LEN];
+
+       // Adhoc or AP configuration vars
+       //unsigned char abyAdHocSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
+       unsigned short wIBSSBeaconPeriod;
+       unsigned short wIBSSATIMWindow;
+       unsigned int    uIBSSChannel;
+       unsigned char abyIBSSSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
+       unsigned char byAPBBType;
+       unsigned char abyWPAIE[MAX_WPA_IE_LEN];
+       unsigned short wWPAIELen;
+
+       unsigned int    uAssocCount;
+       bool bMoreData;
+
+       // Scan state vars
+       WMAC_SCAN_STATE         eScanState;
+       WMAC_SCAN_TYPE          eScanType;
+       unsigned int    uScanStartCh;
+       unsigned int    uScanEndCh;
+       unsigned short wScanSteps;
+       unsigned int    uScanBSSType;
+       // Desire scanning vars
+       unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
+       unsigned char abyScanBSSID[WLAN_BSSID_LEN];
+
+       // Privacy
+       WMAC_AUTHENTICATION_MODE eAuthenMode;
+       WMAC_ENCRYPTION_MODE    eEncryptionMode;
+       bool bShareKeyAlgorithm;
+       unsigned char abyChallenge[WLAN_CHALLENGE_LEN];
+       bool bPrivacyInvoked;
+
+       // Received beacon state vars
+       bool bInTIM;
+       bool bMulticastTIM;
+       unsigned char byDTIMCount;
+       unsigned char byDTIMPeriod;
+
+       // Power saving state vars
+       WMAC_POWER_MODE         ePSMode;
+       unsigned short wListenInterval;
+       unsigned short wCountToWakeUp;
+       bool bInTIMWake;
+       unsigned char *pbyPSPacketPool;
+       unsigned char byPSPacketPool[sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN];
+       bool bRxBeaconInTBTTWake;
+       unsigned char abyPSTxMap[MAX_NODE_NUM + 1];
+
+       // management command related
+       unsigned int    uCmdBusy;
+       unsigned int    uCmdHostAPBusy;
+
+       // management packet pool
+       unsigned char *pbyMgmtPacketPool;
+       unsigned char byMgmtPacketPool[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
+
+       // One second callback timer
+       struct timer_list           sTimerSecondCallback;
+
+       // Temporarily Rx Mgmt Packet Descriptor
+       SRxMgmtPacket           sRxPacket;
+
+       // link list of known bss's (scan results)
+       KnownBSS                sBSSList[MAX_BSS_NUM];
+
+       // table list of known node
+       // sNodeDBList[0] is reserved for AP under Infra mode
+       // sNodeDBList[0] is reserved for Multicast under adhoc/AP mode
+       KnownNodeDB             sNodeDBTable[MAX_NODE_NUM + 1];
+
+       // WPA2 PMKID Cache
+       SPMKIDCache             gsPMKIDCache;
+       bool bRoaming;
+
+       // rate fall back vars
+
+       // associate info
+       SAssocInfo              sAssocInfo;
+
+       // for 802.11h
+       bool b11hEnable;
+       bool bSwitchChannel;
+       unsigned char byNewChannel;
+       PWLAN_IE_MEASURE_REP    pCurrMeasureEIDRep;
+       unsigned int    uLengthOfRepEIDs;
+       unsigned char abyCurrentMSRReq[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
+       unsigned char abyCurrentMSRRep[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
+       unsigned char abyIECountry[WLAN_A3FR_MAXLEN];
+       unsigned char abyIBSSDFSOwner[6];
+       unsigned char byIBSSDFSRecovery;
+
+       struct sk_buff  skb;
 } SMgmtObject, *PSMgmtObject;
 
-
 /*---------------------  Export Macros ------------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
-
 void
 vMgrObjectInit(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 void
 vMgrTimerInit(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 void
 vMgrObjectReset(
-    void *hDeviceContext
-    );
+       void *hDeviceContext
+);
 
 void
 vMgrAssocBeginSta(
-    void *hDeviceContext,
-    PSMgmtObject pMgmt,
-    PCMD_STATUS pStatus
-    );
+       void *hDeviceContext,
+       PSMgmtObject pMgmt,
+       PCMD_STATUS pStatus
+);
 
 void
 vMgrReAssocBeginSta(
-    void *hDeviceContext,
-    PSMgmtObject pMgmt,
-    PCMD_STATUS pStatus
-    );
+       void *hDeviceContext,
+       PSMgmtObject pMgmt,
+       PCMD_STATUS pStatus
+);
 
 void
 vMgrDisassocBeginSta(
-    void *hDeviceContext,
-    PSMgmtObject pMgmt,
-    unsigned char *abyDestAddress,
-    unsigned short wReason,
-    PCMD_STATUS pStatus
-    );
+       void *hDeviceContext,
+       PSMgmtObject pMgmt,
+       unsigned char *abyDestAddress,
+       unsigned short wReason,
+       PCMD_STATUS pStatus
+);
 
 void
 vMgrAuthenBeginSta(
-    void *hDeviceContext,
-    PSMgmtObject pMgmt,
-    PCMD_STATUS pStatus
-    );
+       void *hDeviceContext,
+       PSMgmtObject pMgmt,
+       PCMD_STATUS pStatus
+);
 
 void
 vMgrCreateOwnIBSS(
-    void *hDeviceContext,
-    PCMD_STATUS pStatus
-    );
+       void *hDeviceContext,
+       PCMD_STATUS pStatus
+);
 
 void
 vMgrJoinBSSBegin(
-    void *hDeviceContext,
-    PCMD_STATUS pStatus
-    );
+       void *hDeviceContext,
+       PCMD_STATUS pStatus
+);
 
 void
 vMgrRxManagePacket(
-    void *hDeviceContext,
-    PSMgmtObject pMgmt,
-    PSRxMgmtPacket pRxPacket
-    );
+       void *hDeviceContext,
+       PSMgmtObject pMgmt,
+       PSRxMgmtPacket pRxPacket
+);
 
 /*
-void
-vMgrScanBegin(
-    void *hDeviceContext,
-    PCMD_STATUS pStatus
-    );
+  void
+  vMgrScanBegin(
+  void *hDeviceContext,
+  PCMD_STATUS pStatus
+);
 */
 
 void
 vMgrDeAuthenBeginSta(
-    void *hDeviceContext,
-    PSMgmtObject  pMgmt,
-    unsigned char *abyDestAddress,
-    unsigned short wReason,
-    PCMD_STATUS pStatus
-    );
+       void *hDeviceContext,
+       PSMgmtObject  pMgmt,
+       unsigned char *abyDestAddress,
+       unsigned short wReason,
+       PCMD_STATUS pStatus
+);
 
 bool
 bMgrPrepareBeaconToSend(
-    void *hDeviceContext,
-    PSMgmtObject pMgmt
-    );
-
+       void *hDeviceContext,
+       PSMgmtObject pMgmt
+);
 
 bool
-bAdd_PMKID_Candidate (
-    void *hDeviceContext,
-    unsigned char *pbyBSSID,
-    PSRSNCapObject psRSNCapObj
-    );
+bAdd_PMKID_Candidate(
+       void *hDeviceContext,
+       unsigned char *pbyBSSID,
+       PSRSNCapObject psRSNCapObj
+);
 
 void
-vFlush_PMKID_Candidate (
-    void *hDeviceContext
-    );
+vFlush_PMKID_Candidate(
+       void *hDeviceContext
+);
 
 #endif // __WMGR_H__
index 4412fe9396a46f1baee4bdd566387b0fe5475f87..c5293bbcdab5012574ab5d77bbf1f6f8cafe1af2 100644 (file)
@@ -43,7 +43,7 @@
 #include "80211mgr.h"
 
 /*---------------------  Static Variables  --------------------------*/
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 
 const unsigned char abyOUI00[4] = { 0x00, 0x50, 0xf2, 0x00 };
 const unsigned char abyOUI01[4] = { 0x00, 0x50, 0xf2, 0x01 };
@@ -52,7 +52,6 @@ const unsigned char abyOUI03[4] = { 0x00, 0x50, 0xf2, 0x03 };
 const unsigned char abyOUI04[4] = { 0x00, 0x50, 0xf2, 0x04 };
 const unsigned char abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 };
 
-
 /*+
  *
  * Description:
@@ -66,29 +65,28 @@ const unsigned char abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 };
  *
  * Return Value: none.
  *
--*/
+ -*/
 
 void
-WPA_ClearRSN (
-    PKnownBSS        pBSSList
-    )
+WPA_ClearRSN(
+       PKnownBSS        pBSSList
+)
 {
-    int ii;
-    pBSSList->byGKType = WPA_TKIP;
-    for (ii=0; ii < 4; ii ++)
-        pBSSList->abyPKType[ii] = WPA_TKIP;
-    pBSSList->wPKCount = 0;
-    for (ii=0; ii < 4; ii ++)
-        pBSSList->abyAuthType[ii] = WPA_AUTH_IEEE802_1X;
-    pBSSList->wAuthCount = 0;
-    pBSSList->byDefaultK_as_PK = 0;
-    pBSSList->byReplayIdx = 0;
-    pBSSList->sRSNCapObj.bRSNCapExist = false;
-    pBSSList->sRSNCapObj.wRSNCap = 0;
-    pBSSList->bWPAValid = false;
+       int ii;
+       pBSSList->byGKType = WPA_TKIP;
+       for (ii = 0; ii < 4; ii++)
+               pBSSList->abyPKType[ii] = WPA_TKIP;
+       pBSSList->wPKCount = 0;
+       for (ii = 0; ii < 4; ii++)
+               pBSSList->abyAuthType[ii] = WPA_AUTH_IEEE802_1X;
+       pBSSList->wAuthCount = 0;
+       pBSSList->byDefaultK_as_PK = 0;
+       pBSSList->byReplayIdx = 0;
+       pBSSList->sRSNCapObj.bRSNCapExist = false;
+       pBSSList->sRSNCapObj.wRSNCap = 0;
+       pBSSList->bWPAValid = false;
 }
 
-
 /*+
  *
  * Description:
@@ -103,122 +101,118 @@ WPA_ClearRSN (
  *
  * Return Value: none.
  *
--*/
+ -*/
 void
-WPA_ParseRSN (
-    PKnownBSS        pBSSList,
-    PWLAN_IE_RSN_EXT pRSN
-    )
+WPA_ParseRSN(
+       PKnownBSS        pBSSList,
+       PWLAN_IE_RSN_EXT pRSN
+)
 {
-    PWLAN_IE_RSN_AUTH  pIE_RSN_Auth = NULL;
-    int                i, j, m, n = 0;
-    unsigned char *pbyCaps;
-
-    WPA_ClearRSN(pBSSList);
+       PWLAN_IE_RSN_AUTH  pIE_RSN_Auth = NULL;
+       int                i, j, m, n = 0;
+       unsigned char *pbyCaps;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA_ParseRSN: [%d]\n", pRSN->len);
+       WPA_ClearRSN(pBSSList);
 
-    // information element header makes sense
-    if ((pRSN->len >= 6) // oui1(4)+ver(2)
-         && (pRSN->byElementID == WLAN_EID_RSN_WPA) &&  !memcmp(pRSN->abyOUI, abyOUI01, 4)
-         && (pRSN->wVersion == 1)) {
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WPA_ParseRSN: [%d]\n", pRSN->len);
 
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal RSN\n");
-        // update each variable if pRSN is long enough to contain the variable
-        if (pRSN->len >= 10) //oui1(4)+ver(2)+GKSuite(4)
-        {
-            if ( !memcmp(pRSN->abyMulticast, abyOUI01, 4))
-                pBSSList->byGKType = WPA_WEP40;
-            else if ( !memcmp(pRSN->abyMulticast, abyOUI02, 4))
-                pBSSList->byGKType = WPA_TKIP;
-            else if ( !memcmp(pRSN->abyMulticast, abyOUI03, 4))
-                pBSSList->byGKType = WPA_AESWRAP;
-            else if ( !memcmp(pRSN->abyMulticast, abyOUI04, 4))
-                pBSSList->byGKType = WPA_AESCCMP;
-            else if ( !memcmp(pRSN->abyMulticast, abyOUI05, 4))
-                pBSSList->byGKType = WPA_WEP104;
-            else
-                // any vendor checks here
-                pBSSList->byGKType = WPA_NONE;
+       // information element header makes sense
+       if ((pRSN->len >= 6) // oui1(4)+ver(2)
+           && (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4)
+           && (pRSN->wVersion == 1)) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Legal RSN\n");
+               // update each variable if pRSN is long enough to contain the variable
+               if (pRSN->len >= 10) //oui1(4)+ver(2)+GKSuite(4)
+               {
+                       if (!memcmp(pRSN->abyMulticast, abyOUI01, 4))
+                               pBSSList->byGKType = WPA_WEP40;
+                       else if (!memcmp(pRSN->abyMulticast, abyOUI02, 4))
+                               pBSSList->byGKType = WPA_TKIP;
+                       else if (!memcmp(pRSN->abyMulticast, abyOUI03, 4))
+                               pBSSList->byGKType = WPA_AESWRAP;
+                       else if (!memcmp(pRSN->abyMulticast, abyOUI04, 4))
+                               pBSSList->byGKType = WPA_AESCCMP;
+                       else if (!memcmp(pRSN->abyMulticast, abyOUI05, 4))
+                               pBSSList->byGKType = WPA_WEP104;
+                       else
+                               // any vendor checks here
+                               pBSSList->byGKType = WPA_NONE;
 
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byGKType: %x\n", pBSSList->byGKType);
-        }
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "byGKType: %x\n", pBSSList->byGKType);
+               }
 
-        if (pRSN->len >= 12) //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)
-        {
-            j = 0;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType));
-            for(i = 0; (i < pRSN->wPKCount) && (j < ARRAY_SIZE(pBSSList->abyPKType)); i++) {
-                if(pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i)
-                    if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI00, 4))
-                        pBSSList->abyPKType[j++] = WPA_NONE;
-                    else if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI02, 4))
-                        pBSSList->abyPKType[j++] = WPA_TKIP;
-                    else if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI03, 4))
-                        pBSSList->abyPKType[j++] = WPA_AESWRAP;
-                    else if ( !memcmp(pRSN->PKSList[i].abyOUI, abyOUI04, 4))
-                        pBSSList->abyPKType[j++] = WPA_AESCCMP;
-                    else
-                        // any vendor checks here
-                        ;
-                }
-                else
-                    break;
-                //DBG_PRN_GRP14(("abyPKType[%d]: %X\n", j-1, pBSSList->abyPKType[j-1]));
-            } //for
-            pBSSList->wPKCount = (unsigned short)j;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d\n", pBSSList->wPKCount);
-        }
+               if (pRSN->len >= 12) //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)
+               {
+                       j = 0;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType));
+                       for (i = 0; (i < pRSN->wPKCount) && (j < ARRAY_SIZE(pBSSList->abyPKType)); i++) {
+                               if (pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i)
+                                       if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI00, 4))
+                                               pBSSList->abyPKType[j++] = WPA_NONE;
+                                       else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI02, 4))
+                                               pBSSList->abyPKType[j++] = WPA_TKIP;
+                                       else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI03, 4))
+                                               pBSSList->abyPKType[j++] = WPA_AESWRAP;
+                                       else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI04, 4))
+                                               pBSSList->abyPKType[j++] = WPA_AESCCMP;
+                                       else
+                                               // any vendor checks here
+                                               ;
+                               } else
+                                       break;
+                               //DBG_PRN_GRP14(("abyPKType[%d]: %X\n", j-1, pBSSList->abyPKType[j-1]));
+                       } //for
+                       pBSSList->wPKCount = (unsigned short)j;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wPKCount: %d\n", pBSSList->wPKCount);
+               }
 
-        m = pRSN->wPKCount;
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"m: %d\n", m);
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+m*4: %d\n", 14+m*4);
+               m = pRSN->wPKCount;
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "m: %d\n", m);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "14+m*4: %d\n", 14+m*4);
 
-        if (pRSN->len >= 14+m*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)
-            // overlay IE_RSN_Auth structure into correct place
-            pIE_RSN_Auth = (PWLAN_IE_RSN_AUTH) pRSN->PKSList[m].abyOUI;
-            j = 0;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu\n",
-                          pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType));
-            for(i = 0; (i < pIE_RSN_Auth->wAuthCount) && (j < ARRAY_SIZE(pBSSList->abyAuthType)); i++) {
-                if(pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
-                    if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
-                        pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
-                    else if ( !memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI02, 4))
-                        pBSSList->abyAuthType[j++] = WPA_AUTH_PSK;
-                    else
-                    // any vendor checks here
-                    ;
-                }
-                else
-                    break;
-                //DBG_PRN_GRP14(("abyAuthType[%d]: %X\n", j-1, pBSSList->abyAuthType[j-1]));
-            }
-            if(j > 0)
-                pBSSList->wAuthCount = (unsigned short)j;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d\n", pBSSList->wAuthCount);
-        }
+               if (pRSN->len >= 14+m*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)
+                       // overlay IE_RSN_Auth structure into correct place
+                       pIE_RSN_Auth = (PWLAN_IE_RSN_AUTH) pRSN->PKSList[m].abyOUI;
+                       j = 0;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu\n",
+                               pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType));
+                       for (i = 0; (i < pIE_RSN_Auth->wAuthCount) && (j < ARRAY_SIZE(pBSSList->abyAuthType)); i++) {
+                               if (pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
+                                       if (!memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
+                                               pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
+                                       else if (!memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI02, 4))
+                                               pBSSList->abyAuthType[j++] = WPA_AUTH_PSK;
+                                       else
+                                               // any vendor checks here
+                                               ;
+                               } else
+                                       break;
+                               //DBG_PRN_GRP14(("abyAuthType[%d]: %X\n", j-1, pBSSList->abyAuthType[j-1]));
+                       }
+                       if (j > 0)
+                               pBSSList->wAuthCount = (unsigned short)j;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wAuthCount: %d\n", pBSSList->wAuthCount);
+               }
 
-        if (pIE_RSN_Auth != NULL) {
+               if (pIE_RSN_Auth != NULL) {
+                       n = pIE_RSN_Auth->wAuthCount;
 
-            n = pIE_RSN_Auth->wAuthCount;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "n: %d\n", n);
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "14+4+(m+n)*4: %d\n", 14+4+(m+n)*4);
 
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"n: %d\n", n);
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+4+(m+n)*4: %d\n", 14+4+(m+n)*4);
-
-            if(pRSN->len+2 >= 14+4+(m+n)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*n)+Cap(2)
-                pbyCaps = (unsigned char *)pIE_RSN_Auth->AuthKSList[n].abyOUI;
-                pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
-                pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
-                pBSSList->sRSNCapObj.bRSNCapExist = true;
-                pBSSList->sRSNCapObj.wRSNCap = *(unsigned short *)pbyCaps;
-                //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps));
-                //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK));
-                //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx));
-            }
-        }
-        pBSSList->bWPAValid = true;
-    }
+                       if (pRSN->len+2 >= 14+4+(m+n)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*n)+Cap(2)
+                               pbyCaps = (unsigned char *)pIE_RSN_Auth->AuthKSList[n].abyOUI;
+                               pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
+                               pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
+                               pBSSList->sRSNCapObj.bRSNCapExist = true;
+                               pBSSList->sRSNCapObj.wRSNCap = *(unsigned short *)pbyCaps;
+                               //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps));
+                               //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK));
+                               //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx));
+                       }
+               }
+               pBSSList->bWPAValid = true;
+       }
 }
 
 /*+
@@ -236,51 +230,47 @@ WPA_ParseRSN (
  *
  * Return Value: none.
  *
--*/
+ -*/
 bool
-WPA_SearchRSN (
-    unsigned char byCmd,
-    unsigned char byEncrypt,
-    PKnownBSS        pBSSList
-    )
+WPA_SearchRSN(
+       unsigned char byCmd,
+       unsigned char byEncrypt,
+       PKnownBSS        pBSSList
+)
 {
-    int ii;
-    unsigned char byPKType = WPA_NONE;
+       int ii;
+       unsigned char byPKType = WPA_NONE;
 
-    if (pBSSList->bWPAValid == false)
-        return false;
+       if (pBSSList->bWPAValid == false)
+               return false;
 
-    switch(byCmd) {
-    case 0:
+       switch (byCmd) {
+       case 0:
 
-        if (byEncrypt != pBSSList->byGKType)
-            return false;
+               if (byEncrypt != pBSSList->byGKType)
+                       return false;
 
-        if (pBSSList->wPKCount > 0) {
-            for (ii = 0; ii < pBSSList->wPKCount; ii ++) {
-                if (pBSSList->abyPKType[ii] == WPA_AESCCMP)
-                    byPKType = WPA_AESCCMP;
-                else if ((pBSSList->abyPKType[ii] == WPA_TKIP) && (byPKType != WPA_AESCCMP))
-                     byPKType = WPA_TKIP;
-                else if ((pBSSList->abyPKType[ii] == WPA_WEP40) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
-                     byPKType = WPA_WEP40;
-                else if ((pBSSList->abyPKType[ii] == WPA_WEP104) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
-                     byPKType = WPA_WEP104;
-            }
-            if (byEncrypt != byPKType)
-                return false;
-        }
-        return true;
-//        if (pBSSList->wAuthCount > 0)
-//            for (ii=0; ii < pBSSList->wAuthCount; ii ++)
-//                if (byAuth == pBSSList->abyAuthType[ii])
-//                    break;
-        break;
+               if (pBSSList->wPKCount > 0) {
+                       for (ii = 0; ii < pBSSList->wPKCount; ii++) {
+                               if (pBSSList->abyPKType[ii] == WPA_AESCCMP)
+                                       byPKType = WPA_AESCCMP;
+                               else if ((pBSSList->abyPKType[ii] == WPA_TKIP) && (byPKType != WPA_AESCCMP))
+                                       byPKType = WPA_TKIP;
+                               else if ((pBSSList->abyPKType[ii] == WPA_WEP40) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
+                                       byPKType = WPA_WEP40;
+                               else if ((pBSSList->abyPKType[ii] == WPA_WEP104) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
+                                       byPKType = WPA_WEP104;
+                       }
+                       if (byEncrypt != byPKType)
+                               return false;
+               }
+               return true;
+               break;
 
-    default:
-        break;
-    }
-    return false;
+       default:
+               break;
+       }
+       return false;
 }
 
 /*+
@@ -296,21 +286,19 @@ WPA_SearchRSN (
  *
  * Return Value: none.
  *
--*/
+ -*/
 bool
-WPAb_Is_RSN (
-    PWLAN_IE_RSN_EXT pRSN
-    )
+WPAb_Is_RSN(
+       PWLAN_IE_RSN_EXT pRSN
+)
 {
-    if (pRSN == NULL)
-        return false;
+       if (pRSN == NULL)
+               return false;
 
-    if ((pRSN->len >= 6) && // oui1(4)+ver(2)
-        (pRSN->byElementID == WLAN_EID_RSN_WPA) &&  !memcmp(pRSN->abyOUI, abyOUI01, 4) &&
-        (pRSN->wVersion == 1)) {
-        return true;
-    }
-    else
-        return false;
+       if ((pRSN->len >= 6) && // oui1(4)+ver(2)
+           (pRSN->byElementID == WLAN_EID_RSN_WPA) &&  !memcmp(pRSN->abyOUI, abyOUI01, 4) &&
+           (pRSN->wVersion == 1)) {
+               return true;
+       } else
+               return false;
 }
-
index 921fd7ae9d3870285d1f4aeed015f75dfa86e87d..1d1918a12641a1c095a753c73f45d9d824796fd6 100644 (file)
 
 /*---------------------  Export Types  ------------------------------*/
 
-
 /*---------------------  Export Functions  --------------------------*/
 
 void
 WPA_ClearRSN(
-    PKnownBSS        pBSSList
-    );
+       PKnownBSS        pBSSList
+);
 
 void
 WPA_ParseRSN(
-    PKnownBSS        pBSSList,
-    PWLAN_IE_RSN_EXT pRSN
-    );
+       PKnownBSS        pBSSList,
+       PWLAN_IE_RSN_EXT pRSN
+);
 
 bool
 WPA_SearchRSN(
-    unsigned char byCmd,
-    unsigned char byEncrypt,
-    PKnownBSS        pBSSList
-    );
+       unsigned char byCmd,
+       unsigned char byEncrypt,
+       PKnownBSS        pBSSList
+);
 
 bool
 WPAb_Is_RSN(
-    PWLAN_IE_RSN_EXT pRSN
-    );
+       PWLAN_IE_RSN_EXT pRSN
+);
 
 #endif // __WPA_H__
index 884db1abe123968396cca2c5c4d5592965d85d94..089788dfba633001b0682b99f6f27d68e266b2f6 100644 (file)
@@ -36,7 +36,7 @@
 #include "wmgr.h"
 
 /*---------------------  Static Definitions -------------------------*/
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 /*---------------------  Static Classes  ----------------------------*/
 
@@ -51,7 +51,6 @@ const unsigned char abyOUICCMP[4]    = { 0x00, 0x0F, 0xAC, 0x04 };
 const unsigned char abyOUI8021X[4]   = { 0x00, 0x0F, 0xAC, 0x01 };
 const unsigned char abyOUIPSK[4]     = { 0x00, 0x0F, 0xAC, 0x02 };
 
-
 /*---------------------  Static Functions  --------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
@@ -71,25 +70,25 @@ const unsigned char abyOUIPSK[4]     = { 0x00, 0x0F, 0xAC, 0x02 };
  *
  * Return Value: none.
  *
--*/
+ -*/
 void
-WPA2_ClearRSN (
-    PKnownBSS        pBSSNode
-    )
+WPA2_ClearRSN(
+       PKnownBSS        pBSSNode
+)
 {
-    int ii;
-
-    pBSSNode->bWPA2Valid = false;
-
-    pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
-    for (ii=0; ii < 4; ii ++)
-        pBSSNode->abyCSSPK[ii] = WLAN_11i_CSS_CCMP;
-    pBSSNode->wCSSPKCount = 1;
-    for (ii=0; ii < 4; ii ++)
-        pBSSNode->abyAKMSSAuthType[ii] = WLAN_11i_AKMSS_802_1X;
-    pBSSNode->wAKMSSAuthCount = 1;
-    pBSSNode->sRSNCapObj.bRSNCapExist = false;
-    pBSSNode->sRSNCapObj.wRSNCap = 0;
+       int ii;
+
+       pBSSNode->bWPA2Valid = false;
+
+       pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
+       for (ii = 0; ii < 4; ii++)
+               pBSSNode->abyCSSPK[ii] = WLAN_11i_CSS_CCMP;
+       pBSSNode->wCSSPKCount = 1;
+       for (ii = 0; ii < 4; ii++)
+               pBSSNode->abyAKMSSAuthType[ii] = WLAN_11i_AKMSS_802_1X;
+       pBSSNode->wAKMSSAuthCount = 1;
+       pBSSNode->sRSNCapObj.bRSNCapExist = false;
+       pBSSNode->sRSNCapObj.wRSNCap = 0;
 }
 
 /*+
@@ -106,147 +105,144 @@ WPA2_ClearRSN (
  *
  * Return Value: none.
  *
--*/
+ -*/
 void
-WPA2vParseRSN (
-    PKnownBSS        pBSSNode,
-    PWLAN_IE_RSN     pRSN
-    )
+WPA2vParseRSN(
+       PKnownBSS        pBSSNode,
+       PWLAN_IE_RSN     pRSN
+)
 {
-    int                 i, j;
-    unsigned short m = 0, n = 0;
-    unsigned char *pbyOUI;
-    bool bUseGK = false;
-
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA2_ParseRSN: [%d]\n", pRSN->len);
-
-    WPA2_ClearRSN(pBSSNode);
-
-    if (pRSN->len == 2) { // ver(2)
-        if ((pRSN->byElementID == WLAN_EID_RSN) && (pRSN->wVersion == 1)) {
-            pBSSNode->bWPA2Valid = true;
-        }
-        return;
-    }
-
-    if (pRSN->len < 6) { // ver(2) + GK(4)
-        // invalid CSS, P802.11i/D10.0, p31
-        return;
-    }
-
-    // information element header makes sense
-    if ((pRSN->byElementID == WLAN_EID_RSN) &&
-        (pRSN->wVersion == 1)) {
-
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal 802.11i RSN\n");
-
-        pbyOUI = &(pRSN->abyRSN[0]);
-        if ( !memcmp(pbyOUI, abyOUIWEP40, 4))
-            pBSSNode->byCSSGK = WLAN_11i_CSS_WEP40;
-        else if ( !memcmp(pbyOUI, abyOUITKIP, 4))
-            pBSSNode->byCSSGK = WLAN_11i_CSS_TKIP;
-        else if ( !memcmp(pbyOUI, abyOUICCMP, 4))
-            pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
-        else if ( !memcmp(pbyOUI, abyOUIWEP104, 4))
-            pBSSNode->byCSSGK = WLAN_11i_CSS_WEP104;
-        else if ( !memcmp(pbyOUI, abyOUIGK, 4)) {
-            // invalid CSS, P802.11i/D10.0, p32
-            return;
-        } else
-            // any vendor checks here
-            pBSSNode->byCSSGK = WLAN_11i_CSS_UNKNOWN;
-
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"802.11i CSS: %X\n", pBSSNode->byCSSGK);
-
-        if (pRSN->len == 6) {
-            pBSSNode->bWPA2Valid = true;
-            return;
-        }
-
-        if (pRSN->len >= 8) { // ver(2) + GK(4) + PK count(2)
-            pBSSNode->wCSSPKCount = *((unsigned short *) &(pRSN->abyRSN[4]));
-            j = 0;
-            pbyOUI = &(pRSN->abyRSN[6]);
-
-            for (i = 0; (i < pBSSNode->wCSSPKCount) && (j < sizeof(pBSSNode->abyCSSPK)/sizeof(unsigned char)); i++) {
-
-                if (pRSN->len >= 8+i*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*i)
-                    if ( !memcmp(pbyOUI, abyOUIGK, 4)) {
-                        pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_USE_GROUP;
-                        bUseGK = true;
-                    } else if ( !memcmp(pbyOUI, abyOUIWEP40, 4)) {
-                        // Invalid CSS, continue to parsing
-                    } else if ( !memcmp(pbyOUI, abyOUITKIP, 4)) {
-                        if (pBSSNode->byCSSGK != WLAN_11i_CSS_CCMP)
-                            pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_TKIP;
-                        else
-                            ; // Invalid CSS, continue to parsing
-                    } else if ( !memcmp(pbyOUI, abyOUICCMP, 4)) {
-                        pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_CCMP;
-                    } else if ( !memcmp(pbyOUI, abyOUIWEP104, 4)) {
-                        // Invalid CSS, continue to parsing
-                    } else {
-                        // any vendor checks here
-                        pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_UNKNOWN;
-                    }
-                    pbyOUI += 4;
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyCSSPK[%d]: %X\n", j-1, pBSSNode->abyCSSPK[j-1]);
-                } else
-                    break;
-            } //for
-
-            if (bUseGK == true) {
-                if (j != 1) {
-                    // invalid CSS, This should be only PK CSS.
-                    return;
-                }
-                if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
-                    // invalid CSS, If CCMP is enable , PK can't be CSSGK.
-                    return;
-                }
-            }
-            if ((pBSSNode->wCSSPKCount != 0) && (j == 0)) {
-                // invalid CSS, No valid PK.
-                return;
-            }
-            pBSSNode->wCSSPKCount = (unsigned short)j;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wCSSPKCount: %d\n", pBSSNode->wCSSPKCount);
-        }
-
-        m = *((unsigned short *) &(pRSN->abyRSN[4]));
-
-        if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2)
-            pBSSNode->wAKMSSAuthCount = *((unsigned short *) &(pRSN->abyRSN[6+4*m]));
-            j = 0;
-            pbyOUI = &(pRSN->abyRSN[8+4*m]);
-            for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(unsigned char)); i++) {
-                if (pRSN->len >= 10+(m+i)*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSS(2)+AKS(4*i)
-                    if ( !memcmp(pbyOUI, abyOUI8021X, 4))
-                        pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_802_1X;
-                    else if ( !memcmp(pbyOUI, abyOUIPSK, 4))
-                        pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_PSK;
-                    else
-                        // any vendor checks here
-                        pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_UNKNOWN;
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyAKMSSAuthType[%d]: %X\n", j-1, pBSSNode->abyAKMSSAuthType[j-1]);
-                } else
-                    break;
-            }
-            pBSSNode->wAKMSSAuthCount = (unsigned short)j;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAKMSSAuthCount: %d\n", pBSSNode->wAKMSSAuthCount);
-
-            n = *((unsigned short *) &(pRSN->abyRSN[6+4*m]));
-            if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2)
-                pBSSNode->sRSNCapObj.bRSNCapExist = true;
-                pBSSNode->sRSNCapObj.wRSNCap = *((unsigned short *) &(pRSN->abyRSN[8+4*m+4*n]));
-            }
-        }
-        //ignore PMKID lists bcs only (Re)Assocrequest has this field
-        pBSSNode->bWPA2Valid = true;
-    }
+       int                 i, j;
+       unsigned short m = 0, n = 0;
+       unsigned char *pbyOUI;
+       bool bUseGK = false;
+
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WPA2_ParseRSN: [%d]\n", pRSN->len);
+
+       WPA2_ClearRSN(pBSSNode);
+
+       if (pRSN->len == 2) { // ver(2)
+               if ((pRSN->byElementID == WLAN_EID_RSN) && (pRSN->wVersion == 1)) {
+                       pBSSNode->bWPA2Valid = true;
+               }
+               return;
+       }
+
+       if (pRSN->len < 6) { // ver(2) + GK(4)
+               // invalid CSS, P802.11i/D10.0, p31
+               return;
+       }
+
+       // information element header makes sense
+       if ((pRSN->byElementID == WLAN_EID_RSN) &&
+           (pRSN->wVersion == 1)) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Legal 802.11i RSN\n");
+
+               pbyOUI = &(pRSN->abyRSN[0]);
+               if (!memcmp(pbyOUI, abyOUIWEP40, 4))
+                       pBSSNode->byCSSGK = WLAN_11i_CSS_WEP40;
+               else if (!memcmp(pbyOUI, abyOUITKIP, 4))
+                       pBSSNode->byCSSGK = WLAN_11i_CSS_TKIP;
+               else if (!memcmp(pbyOUI, abyOUICCMP, 4))
+                       pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
+               else if (!memcmp(pbyOUI, abyOUIWEP104, 4))
+                       pBSSNode->byCSSGK = WLAN_11i_CSS_WEP104;
+               else if (!memcmp(pbyOUI, abyOUIGK, 4)) {
+                       // invalid CSS, P802.11i/D10.0, p32
+                       return;
+               } else
+                       // any vendor checks here
+                       pBSSNode->byCSSGK = WLAN_11i_CSS_UNKNOWN;
+
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "802.11i CSS: %X\n", pBSSNode->byCSSGK);
+
+               if (pRSN->len == 6) {
+                       pBSSNode->bWPA2Valid = true;
+                       return;
+               }
+
+               if (pRSN->len >= 8) { // ver(2) + GK(4) + PK count(2)
+                       pBSSNode->wCSSPKCount = *((unsigned short *)&(pRSN->abyRSN[4]));
+                       j = 0;
+                       pbyOUI = &(pRSN->abyRSN[6]);
+
+                       for (i = 0; (i < pBSSNode->wCSSPKCount) && (j < sizeof(pBSSNode->abyCSSPK)/sizeof(unsigned char)); i++) {
+                               if (pRSN->len >= 8+i*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*i)
+                                       if (!memcmp(pbyOUI, abyOUIGK, 4)) {
+                                               pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_USE_GROUP;
+                                               bUseGK = true;
+                                       } else if (!memcmp(pbyOUI, abyOUIWEP40, 4)) {
+                                               // Invalid CSS, continue to parsing
+                                       } else if (!memcmp(pbyOUI, abyOUITKIP, 4)) {
+                                               if (pBSSNode->byCSSGK != WLAN_11i_CSS_CCMP)
+                                                       pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_TKIP;
+                                               else
+                                                       ; // Invalid CSS, continue to parsing
+                                       } else if (!memcmp(pbyOUI, abyOUICCMP, 4)) {
+                                               pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_CCMP;
+                                       } else if (!memcmp(pbyOUI, abyOUIWEP104, 4)) {
+                                               // Invalid CSS, continue to parsing
+                                       } else {
+                                               // any vendor checks here
+                                               pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_UNKNOWN;
+                                       }
+                                       pbyOUI += 4;
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "abyCSSPK[%d]: %X\n", j-1, pBSSNode->abyCSSPK[j-1]);
+                               } else
+                                       break;
+                       } //for
+
+                       if (bUseGK == true) {
+                               if (j != 1) {
+                                       // invalid CSS, This should be only PK CSS.
+                                       return;
+                               }
+                               if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
+                                       // invalid CSS, If CCMP is enable , PK can't be CSSGK.
+                                       return;
+                               }
+                       }
+                       if ((pBSSNode->wCSSPKCount != 0) && (j == 0)) {
+                               // invalid CSS, No valid PK.
+                               return;
+                       }
+                       pBSSNode->wCSSPKCount = (unsigned short)j;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wCSSPKCount: %d\n", pBSSNode->wCSSPKCount);
+               }
+
+               m = *((unsigned short *)&(pRSN->abyRSN[4]));
+
+               if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2)
+                       pBSSNode->wAKMSSAuthCount = *((unsigned short *)&(pRSN->abyRSN[6+4*m]));
+                       j = 0;
+                       pbyOUI = &(pRSN->abyRSN[8+4*m]);
+                       for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(unsigned char)); i++) {
+                               if (pRSN->len >= 10+(m+i)*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSS(2)+AKS(4*i)
+                                       if (!memcmp(pbyOUI, abyOUI8021X, 4))
+                                               pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_802_1X;
+                                       else if (!memcmp(pbyOUI, abyOUIPSK, 4))
+                                               pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_PSK;
+                                       else
+                                               // any vendor checks here
+                                               pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_UNKNOWN;
+                                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "abyAKMSSAuthType[%d]: %X\n", j-1, pBSSNode->abyAKMSSAuthType[j-1]);
+                               } else
+                                       break;
+                       }
+                       pBSSNode->wAKMSSAuthCount = (unsigned short)j;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wAKMSSAuthCount: %d\n", pBSSNode->wAKMSSAuthCount);
+
+                       n = *((unsigned short *)&(pRSN->abyRSN[6+4*m]));
+                       if (pRSN->len >= 12 + 4 * m + 4 * n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2)
+                               pBSSNode->sRSNCapObj.bRSNCapExist = true;
+                               pBSSNode->sRSNCapObj.wRSNCap = *((unsigned short *)&(pRSN->abyRSN[8+4*m+4*n]));
+                       }
+               }
+               //ignore PMKID lists bcs only (Re)Assocrequest has this field
+               pBSSNode->bWPA2Valid = true;
+       }
 }
 
-
 /*+
  *
  * Description:
@@ -260,105 +256,105 @@ WPA2vParseRSN (
  *
  * Return Value: length of IEs.
  *
--*/
+ -*/
 unsigned int
 WPA2uSetIEs(
-    void *pMgmtHandle,
-    PWLAN_IE_RSN pRSNIEs
-    )
+       void *pMgmtHandle,
+       PWLAN_IE_RSN pRSNIEs
+)
 {
-    PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtHandle;
-    unsigned char *pbyBuffer = NULL;
-    unsigned int ii = 0;
-    unsigned short *pwPMKID = NULL;
-
-    if (pRSNIEs == NULL) {
-        return(0);
-    }
-    if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
-         (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
-        (pMgmt->pCurrBSS != NULL)) {
-        /* WPA2 IE */
-        pbyBuffer = (unsigned char *) pRSNIEs;
-        pRSNIEs->byElementID = WLAN_EID_RSN;
-        pRSNIEs->len = 6; //Version(2)+GK(4)
-        pRSNIEs->wVersion = 1;
-        //Group Key Cipher Suite
-        pRSNIEs->abyRSN[0] = 0x00;
-        pRSNIEs->abyRSN[1] = 0x0F;
-        pRSNIEs->abyRSN[2] = 0xAC;
-        if (pMgmt->byCSSGK == KEY_CTL_WEP) {
-            pRSNIEs->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
-        } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
-            pRSNIEs->abyRSN[3] = WLAN_11i_CSS_TKIP;
-        } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
-            pRSNIEs->abyRSN[3] = WLAN_11i_CSS_CCMP;
-        } else {
-            pRSNIEs->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
-        }
-
-        // Pairwise Key Cipher Suite
-        pRSNIEs->abyRSN[4] = 1;
-        pRSNIEs->abyRSN[5] = 0;
-        pRSNIEs->abyRSN[6] = 0x00;
-        pRSNIEs->abyRSN[7] = 0x0F;
-        pRSNIEs->abyRSN[8] = 0xAC;
-        if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
-            pRSNIEs->abyRSN[9] = WLAN_11i_CSS_TKIP;
-        } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
-            pRSNIEs->abyRSN[9] = WLAN_11i_CSS_CCMP;
-        } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
-            pRSNIEs->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
-        } else {
-            pRSNIEs->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
-        }
-        pRSNIEs->len += 6;
-
-        // Auth Key Management Suite
-        pRSNIEs->abyRSN[10] = 1;
-        pRSNIEs->abyRSN[11] = 0;
-        pRSNIEs->abyRSN[12] = 0x00;
-        pRSNIEs->abyRSN[13] = 0x0F;
-        pRSNIEs->abyRSN[14] = 0xAC;
-        if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
-            pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_PSK;
-        } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
-            pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
-        } else {
-            pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
-        }
-        pRSNIEs->len +=6;
-
-        // RSN Capabilities
-        if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
-            memcpy(&pRSNIEs->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
-        } else {
-            pRSNIEs->abyRSN[16] = 0;
-            pRSNIEs->abyRSN[17] = 0;
-        }
-        pRSNIEs->len +=2;
-
-        if ((pMgmt->gsPMKIDCache.BSSIDInfoCount > 0) &&
-            (pMgmt->bRoaming == true) &&
-            (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
-            // RSN PMKID
-            pwPMKID = (unsigned short *)(&pRSNIEs->abyRSN[18]);  // Point to PMKID count
-            *pwPMKID = 0;                               // Initialize PMKID count
-            pbyBuffer = &pRSNIEs->abyRSN[20];           // Point to PMKID list
-            for (ii = 0; ii < pMgmt->gsPMKIDCache.BSSIDInfoCount; ii++) {
-                if ( !memcmp(&pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyBSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
-                    (*pwPMKID) ++;
-                    memcpy(pbyBuffer, pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyPMKID, 16);
-                    pbyBuffer += 16;
-                }
-            }
-            if (*pwPMKID != 0) {
-                pRSNIEs->len += (2 + (*pwPMKID)*16);
-            } else {
-                pbyBuffer = &pRSNIEs->abyRSN[18];
-            }
-        }
-        return(pRSNIEs->len + WLAN_IEHDR_LEN);
-    }
-    return(0);
+       PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtHandle;
+       unsigned char *pbyBuffer = NULL;
+       unsigned int ii = 0;
+       unsigned short *pwPMKID = NULL;
+
+       if (pRSNIEs == NULL) {
+               return 0;
+       }
+       if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
+            (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
+           (pMgmt->pCurrBSS != NULL)) {
+               /* WPA2 IE */
+               pbyBuffer = (unsigned char *)pRSNIEs;
+               pRSNIEs->byElementID = WLAN_EID_RSN;
+               pRSNIEs->len = 6; //Version(2)+GK(4)
+               pRSNIEs->wVersion = 1;
+               //Group Key Cipher Suite
+               pRSNIEs->abyRSN[0] = 0x00;
+               pRSNIEs->abyRSN[1] = 0x0F;
+               pRSNIEs->abyRSN[2] = 0xAC;
+               if (pMgmt->byCSSGK == KEY_CTL_WEP) {
+                       pRSNIEs->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
+               } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
+                       pRSNIEs->abyRSN[3] = WLAN_11i_CSS_TKIP;
+               } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
+                       pRSNIEs->abyRSN[3] = WLAN_11i_CSS_CCMP;
+               } else {
+                       pRSNIEs->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
+               }
+
+               // Pairwise Key Cipher Suite
+               pRSNIEs->abyRSN[4] = 1;
+               pRSNIEs->abyRSN[5] = 0;
+               pRSNIEs->abyRSN[6] = 0x00;
+               pRSNIEs->abyRSN[7] = 0x0F;
+               pRSNIEs->abyRSN[8] = 0xAC;
+               if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
+                       pRSNIEs->abyRSN[9] = WLAN_11i_CSS_TKIP;
+               } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
+                       pRSNIEs->abyRSN[9] = WLAN_11i_CSS_CCMP;
+               } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
+                       pRSNIEs->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
+               } else {
+                       pRSNIEs->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
+               }
+               pRSNIEs->len += 6;
+
+               // Auth Key Management Suite
+               pRSNIEs->abyRSN[10] = 1;
+               pRSNIEs->abyRSN[11] = 0;
+               pRSNIEs->abyRSN[12] = 0x00;
+               pRSNIEs->abyRSN[13] = 0x0F;
+               pRSNIEs->abyRSN[14] = 0xAC;
+               if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
+                       pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_PSK;
+               } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
+                       pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
+               } else {
+                       pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
+               }
+               pRSNIEs->len += 6;
+
+               // RSN Capabilities
+               if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
+                       memcpy(&pRSNIEs->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
+               } else {
+                       pRSNIEs->abyRSN[16] = 0;
+                       pRSNIEs->abyRSN[17] = 0;
+               }
+               pRSNIEs->len += 2;
+
+               if ((pMgmt->gsPMKIDCache.BSSIDInfoCount > 0) &&
+                   (pMgmt->bRoaming == true) &&
+                   (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
+                       // RSN PMKID
+                       pwPMKID = (unsigned short *)(&pRSNIEs->abyRSN[18]);  // Point to PMKID count
+                       *pwPMKID = 0;                               // Initialize PMKID count
+                       pbyBuffer = &pRSNIEs->abyRSN[20];           // Point to PMKID list
+                       for (ii = 0; ii < pMgmt->gsPMKIDCache.BSSIDInfoCount; ii++) {
+                               if (!memcmp(&pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyBSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
+                                       (*pwPMKID)++;
+                                       memcpy(pbyBuffer, pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyPMKID, 16);
+                                       pbyBuffer += 16;
+                               }
+                       }
+                       if (*pwPMKID != 0) {
+                               pRSNIEs->len += (2 + (*pwPMKID)*16);
+                       } else {
+                               pbyBuffer = &pRSNIEs->abyRSN[18];
+                       }
+               }
+               return pRSNIEs->len + WLAN_IEHDR_LEN;
+       }
+       return 0;
 }
index 718208beb72fa87e0ff3d62de446b25295b2b376..2d0bd2e515f301d5c7f7a600284b8cbc1512fda4 100644 (file)
 #define MAX_PMKID_CACHE         16
 
 typedef struct tagsPMKIDInfo {
-    unsigned char abyBSSID[6];
-    unsigned char abyPMKID[16];
+       unsigned char abyBSSID[6];
+       unsigned char abyPMKID[16];
 } PMKIDInfo, *PPMKIDInfo;
 
 typedef struct tagSPMKIDCache {
-    unsigned long BSSIDInfoCount;
-    PMKIDInfo   BSSIDInfo[MAX_PMKID_CACHE];
+       unsigned long BSSIDInfoCount;
+       PMKIDInfo   BSSIDInfo[MAX_PMKID_CACHE];
 } SPMKIDCache, *PSPMKIDCache;
 
-
 /*---------------------  Export Classes  ----------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
@@ -59,20 +58,20 @@ typedef struct tagSPMKIDCache {
 /*---------------------  Export Functions  --------------------------*/
 
 void
-WPA2_ClearRSN (
-    PKnownBSS        pBSSNode
-    );
+WPA2_ClearRSN(
+       PKnownBSS        pBSSNode
+);
 
 void
-WPA2vParseRSN (
-    PKnownBSS        pBSSNode,
-    PWLAN_IE_RSN     pRSN
-    );
+WPA2vParseRSN(
+       PKnownBSS        pBSSNode,
+       PWLAN_IE_RSN     pRSN
+);
 
 unsigned int
 WPA2uSetIEs(
-    void *pMgmtHandle,
-    PWLAN_IE_RSN pRSNIEs
-    );
+       void *pMgmtHandle,
+       PWLAN_IE_RSN pRSNIEs
+);
 
 #endif // __WPA2_H__
index 2b6ae1e403bf1f4d3dd7c81ede41e6b014e98390..869f62c678e60c1e67f4d624fc5a724fe733be1e 100644 (file)
@@ -44,8 +44,6 @@
 
 #define VIAWGET_WPA_MAX_BUF_SIZE 1024
 
-
-
 static const int frequency_list[] = {
        2412, 2417, 2422, 2427, 2432, 2437, 2442,
        2447, 2452, 2457, 2462, 2467, 2472, 2484
@@ -54,13 +52,10 @@ static const int frequency_list[] = {
 
 /*---------------------  Static Variables  --------------------------*/
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 
 /*---------------------  Static Functions  --------------------------*/
 
-
-
-
 /*---------------------  Export Variables  --------------------------*/
 static void wpadev_setup(struct net_device *dev)
 {
@@ -70,7 +65,7 @@ static void wpadev_setup(struct net_device *dev)
        dev->addr_len           = ETH_ALEN;
        dev->tx_queue_len       = 1000;
 
-       memset(dev->broadcast,0xFF, ETH_ALEN);
+       memset(dev->broadcast, 0xFF, ETH_ALEN);
 
        dev->flags              = IFF_BROADCAST|IFF_MULTICAST;
 }
@@ -91,42 +86,41 @@ static void wpadev_setup(struct net_device *dev)
 
 static int wpa_init_wpadev(PSDevice pDevice)
 {
-    PSDevice wpadev_priv;
+       PSDevice wpadev_priv;
        struct net_device *dev = pDevice->dev;
-         int ret=0;
+       int ret = 0;
 
        pDevice->wpadev = alloc_netdev(sizeof(PSDevice), "vntwpa", wpadev_setup);
        if (pDevice->wpadev == NULL)
                return -ENOMEM;
 
-    wpadev_priv = netdev_priv(pDevice->wpadev);
-    *wpadev_priv = *pDevice;
+       wpadev_priv = netdev_priv(pDevice->wpadev);
+       *wpadev_priv = *pDevice;
        memcpy(pDevice->wpadev->dev_addr, dev->dev_addr, ETH_ALEN);
-         pDevice->wpadev->base_addr = dev->base_addr;
+       pDevice->wpadev->base_addr = dev->base_addr;
        pDevice->wpadev->irq = dev->irq;
        pDevice->wpadev->mem_start = dev->mem_start;
        pDevice->wpadev->mem_end = dev->mem_end;
        ret = register_netdev(pDevice->wpadev);
        if (ret) {
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdev(WPA) failed!\n",
-                      dev->name);
+                       dev->name);
                free_netdev(pDevice->wpadev);
                return -1;
        }
 
        if (pDevice->skb == NULL) {
-        pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-        if (pDevice->skb == NULL)
-                   return -ENOMEM;
-    }
+               pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
+               if (pDevice->skb == NULL)
+                       return -ENOMEM;
+       }
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdev %s for WPA management\n",
-              dev->name, pDevice->wpadev->name);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdev %s for WPA management\n",
+               dev->name, pDevice->wpadev->name);
 
        return 0;
 }
 
-
 /*
  * Description:
  *      unregister net_device (wpadev)
@@ -142,26 +136,22 @@ static int wpa_init_wpadev(PSDevice pDevice)
 
 static int wpa_release_wpadev(PSDevice pDevice)
 {
-    if (pDevice->skb) {
-        dev_kfree_skb(pDevice->skb);
-        pDevice->skb = NULL;
-    }
-
-    if (pDevice->wpadev) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
-              pDevice->dev->name, pDevice->wpadev->name);
-       unregister_netdev(pDevice->wpadev);
-       free_netdev(pDevice->wpadev);
-         pDevice->wpadev = NULL;
-    }
+       if (pDevice->skb) {
+               dev_kfree_skb(pDevice->skb);
+               pDevice->skb = NULL;
+       }
+
+       if (pDevice->wpadev) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
+                       pDevice->dev->name, pDevice->wpadev->name);
+               unregister_netdev(pDevice->wpadev);
+               free_netdev(pDevice->wpadev);
+               pDevice->wpadev = NULL;
+       }
 
        return 0;
 }
 
-
-
-
-
 /*
  * Description:
  *      Set enable/disable dev for wpa supplicant daemon
@@ -184,7 +174,6 @@ int wpa_set_wpadev(PSDevice pDevice, int val)
                return wpa_release_wpadev(pDevice);
 }
 
-
 /*
  * Description:
  *      Set WPA algorithm & keys
@@ -199,252 +188,245 @@ int wpa_set_wpadev(PSDevice pDevice, int val)
  *
  */
 
- int wpa_set_keys(PSDevice pDevice, void *ctx, bool fcpfkernel)
+int wpa_set_keys(PSDevice pDevice, void *ctx, bool fcpfkernel)
 {
-    struct viawget_wpa_param *param=ctx;
-    PSMgmtObject pMgmt = pDevice->pMgmt;
-    unsigned long dwKeyIndex = 0;
-    unsigned char abyKey[MAX_KEY_LEN];
-    unsigned char abySeq[MAX_KEY_LEN];
-    QWORD   KeyRSC;
+       struct viawget_wpa_param *param = ctx;
+       PSMgmtObject pMgmt = pDevice->pMgmt;
+       unsigned long dwKeyIndex = 0;
+       unsigned char abyKey[MAX_KEY_LEN];
+       unsigned char abySeq[MAX_KEY_LEN];
+       QWORD   KeyRSC;
 //    NDIS_802_11_KEY_RSC KeyRSC;
-    unsigned char byKeyDecMode = KEY_CTL_WEP;
+       unsigned char byKeyDecMode = KEY_CTL_WEP;
        int ret = 0;
        int uu, ii;
 
-
        if (param->u.wpa_key.alg_name > WPA_ALG_CCMP ||
-                       param->u.wpa_key.key_len >= MAX_KEY_LEN ||
-                       param->u.wpa_key.seq_len >= MAX_KEY_LEN)
+           param->u.wpa_key.key_len >= MAX_KEY_LEN ||
+           param->u.wpa_key.seq_len >= MAX_KEY_LEN)
                return -EINVAL;
 
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n", param->u.wpa_key.alg_name);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n", param->u.wpa_key.alg_name);
        if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
-        pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
-        pDevice->bEncryptionEnable = false;
-        pDevice->byKeyIndex = 0;
-        pDevice->bTransmitKey = false;
-        KeyvRemoveAllWEPKey(&(pDevice->sKey), pDevice->PortOffset);
-        for (uu=0; uu<MAX_KEY_TABLE; uu++) {
-            MACvDisableKeyEntry(pDevice->PortOffset, uu);
-        }
-        return ret;
-    }
-
-    //spin_unlock_irq(&pDevice->lock);
-    if(param->u.wpa_key.key && fcpfkernel) {
-       memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
-     }
-    else {
-       spin_unlock_irq(&pDevice->lock);
-       if (param->u.wpa_key.key &&
-           copy_from_user(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len)) {
-           spin_lock_irq(&pDevice->lock);
-           return -EINVAL;
-       }
-spin_lock_irq(&pDevice->lock);
-       }
+               pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
+               pDevice->bEncryptionEnable = false;
+               pDevice->byKeyIndex = 0;
+               pDevice->bTransmitKey = false;
+               KeyvRemoveAllWEPKey(&(pDevice->sKey), pDevice->PortOffset);
+               for (uu = 0; uu < MAX_KEY_TABLE; uu++) {
+                       MACvDisableKeyEntry(pDevice->PortOffset, uu);
+               }
+               return ret;
+       }
+
+       //spin_unlock_irq(&pDevice->lock);
+       if (param->u.wpa_key.key && fcpfkernel) {
+               memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
+       } else {
+               spin_unlock_irq(&pDevice->lock);
+               if (param->u.wpa_key.key &&
+                   copy_from_user(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len)) {
+                       spin_lock_irq(&pDevice->lock);
+                       return -EINVAL;
+               }
+               spin_lock_irq(&pDevice->lock);
+       }
 
-    dwKeyIndex = (unsigned long)(param->u.wpa_key.key_index);
+       dwKeyIndex = (unsigned long)(param->u.wpa_key.key_index);
 
        if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
-        if (dwKeyIndex > 3) {
-            return -EINVAL;
-        }
-        else {
-            if (param->u.wpa_key.set_tx) {
-                pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
-                pDevice->bTransmitKey = true;
-                       dwKeyIndex |= (1 << 31);
-            }
-            KeybSetDefaultKey(&(pDevice->sKey),
-                                dwKeyIndex & ~(BIT30 | USE_KEYRSC),
-                                param->u.wpa_key.key_len,
-                                NULL,
-                                abyKey,
-                                KEY_CTL_WEP,
-                                pDevice->PortOffset,
-                                pDevice->byLocalID);
-
-        }
-        pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
-        pDevice->bEncryptionEnable = true;
-        return ret;
-       }
-
-           //spin_unlock_irq(&pDevice->lock);
-        if(param->u.wpa_key.seq && fcpfkernel) {
-           memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
-               }
-       else {
-               spin_unlock_irq(&pDevice->lock);
-       if (param->u.wpa_key.seq &&
-           copy_from_user(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len)) {
-           spin_lock_irq(&pDevice->lock);
-           return -EINVAL;
-               }
-spin_lock_irq(&pDevice->lock);
-}
+               if (dwKeyIndex > 3) {
+                       return -EINVAL;
+               } else {
+                       if (param->u.wpa_key.set_tx) {
+                               pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
+                               pDevice->bTransmitKey = true;
+                               dwKeyIndex |= (1 << 31);
+                       }
+                       KeybSetDefaultKey(&(pDevice->sKey),
+                                         dwKeyIndex & ~(BIT30 | USE_KEYRSC),
+                                         param->u.wpa_key.key_len,
+                                         NULL,
+                                         abyKey,
+                                         KEY_CTL_WEP,
+                                         pDevice->PortOffset,
+                                         pDevice->byLocalID);
+
+               }
+               pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
+               pDevice->bEncryptionEnable = true;
+               return ret;
+       }
+
+       //spin_unlock_irq(&pDevice->lock);
+       if (param->u.wpa_key.seq && fcpfkernel) {
+               memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
+       } else {
+               spin_unlock_irq(&pDevice->lock);
+               if (param->u.wpa_key.seq &&
+                   copy_from_user(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len)) {
+                       spin_lock_irq(&pDevice->lock);
+                       return -EINVAL;
+               }
+               spin_lock_irq(&pDevice->lock);
+       }
 
        if (param->u.wpa_key.seq_len > 0) {
-               for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) {
-                    if (ii < 4)
-                           LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
-                        else
-                           HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
-                //KeyRSC |= (abySeq[ii] << (ii * 8));
+               for (ii = 0; ii < param->u.wpa_key.seq_len; ii++) {
+                       if (ii < 4)
+                               LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
+                       else
+                               HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
+                       //KeyRSC |= (abySeq[ii] << (ii * 8));
                }
                dwKeyIndex |= 1 << 29;
        }
 
-    if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return  dwKeyIndex > 3\n");
-        return -EINVAL;
-    }
+       if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return  dwKeyIndex > 3\n");
+               return -EINVAL;
+       }
 
        if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) {
-        pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
-    }
+               pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
+       }
 
        if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) {
-        pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
-    }
+               pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
+       }
 
        if (param->u.wpa_key.set_tx)
                dwKeyIndex |= (1 << 31);
 
+       if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
+               byKeyDecMode = KEY_CTL_CCMP;
+       else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
+               byKeyDecMode = KEY_CTL_TKIP;
+       else
+               byKeyDecMode = KEY_CTL_WEP;
+
+       // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
+       if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
+               if (param->u.wpa_key.key_len == MAX_KEY_LEN)
+                       byKeyDecMode = KEY_CTL_TKIP;
+               else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
+                       byKeyDecMode = KEY_CTL_WEP;
+               else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
+                       byKeyDecMode = KEY_CTL_WEP;
+       } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
+               if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
+                       byKeyDecMode = KEY_CTL_WEP;
+               else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
+                       byKeyDecMode = KEY_CTL_WEP;
+       }
+
+       // Check TKIP key length
+       if ((byKeyDecMode == KEY_CTL_TKIP) &&
+           (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
+               // TKIP Key must be 256 bits
+               //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - TKIP Key must be 256 bits\n"));
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
+               return -EINVAL;
+       }
+       // Check AES key length
+       if ((byKeyDecMode == KEY_CTL_CCMP) &&
+           (param->u.wpa_key.key_len != AES_KEY_LEN)) {
+               // AES Key must be 128 bits
+               //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - AES Key must be 128 bits\n"));
+               return -EINVAL;
+       }
+
+       // spin_lock_irq(&pDevice->lock);
+       if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) {
+               // If is_broadcast_ether_addr, set the key as every key entry's group key.
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");
+
+               if ((KeybSetAllGroupKey(&(pDevice->sKey),
+                                       dwKeyIndex,
+                                       param->u.wpa_key.key_len,
+                                       (PQWORD) &(KeyRSC),
+                                       (unsigned char *)abyKey,
+                                       byKeyDecMode,
+                                       pDevice->PortOffset,
+                                       pDevice->byLocalID) == true) &&
+                   (KeybSetDefaultKey(&(pDevice->sKey),
+                                      dwKeyIndex,
+                                      param->u.wpa_key.key_len,
+                                      (PQWORD) &(KeyRSC),
+                                      (unsigned char *)abyKey,
+                                      byKeyDecMode,
+                                      pDevice->PortOffset,
+                                      pDevice->byLocalID) == true)) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
+
+               } else {
+                       //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
+                       // spin_unlock_irq(&pDevice->lock);
+                       return -EINVAL;
+               }
+
+       } else {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
+               // BSSID not 0xffffffffffff
+               // Pairwise Key can't be WEP
+               if (byKeyDecMode == KEY_CTL_WEP) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
+                       //spin_unlock_irq(&pDevice->lock);
+                       return -EINVAL;
+               }
 
-    if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
-        byKeyDecMode = KEY_CTL_CCMP;
-    else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
-        byKeyDecMode = KEY_CTL_TKIP;
-    else
-        byKeyDecMode = KEY_CTL_WEP;
-
-    // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
-    if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
-        if (param->u.wpa_key.key_len == MAX_KEY_LEN)
-            byKeyDecMode = KEY_CTL_TKIP;
-        else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
-            byKeyDecMode = KEY_CTL_WEP;
-        else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
-            byKeyDecMode = KEY_CTL_WEP;
-    } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
-        if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
-            byKeyDecMode = KEY_CTL_WEP;
-        else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
-            byKeyDecMode = KEY_CTL_WEP;
-    }
-
-    // Check TKIP key length
-    if ((byKeyDecMode == KEY_CTL_TKIP) &&
-        (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
-        // TKIP Key must be 256 bits
-        //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - TKIP Key must be 256 bits\n"));
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
-        return -EINVAL;
-    }
-    // Check AES key length
-    if ((byKeyDecMode == KEY_CTL_CCMP) &&
-        (param->u.wpa_key.key_len != AES_KEY_LEN)) {
-        // AES Key must be 128 bits
-        //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - AES Key must be 128 bits\n"));
-        return -EINVAL;
-    }
-
-   // spin_lock_irq(&pDevice->lock);
-    if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) {
-        // If is_broadcast_ether_addr, set the key as every key entry's group key.
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");
-
-        if ((KeybSetAllGroupKey(&(pDevice->sKey),
-                            dwKeyIndex,
-                            param->u.wpa_key.key_len,
-                            (PQWORD) &(KeyRSC),
-                            (unsigned char *)abyKey,
-                            byKeyDecMode,
-                            pDevice->PortOffset,
-                            pDevice->byLocalID) == true) &&
-            (KeybSetDefaultKey(&(pDevice->sKey),
-                            dwKeyIndex,
-                            param->u.wpa_key.key_len,
-                            (PQWORD) &(KeyRSC),
-                            (unsigned char *)abyKey,
-                            byKeyDecMode,
-                            pDevice->PortOffset,
-                            pDevice->byLocalID) == true) ) {
-             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
-
-        } else {
-            //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
-           // spin_unlock_irq(&pDevice->lock);
-            return -EINVAL;
-        }
-
-    } else {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
-        // BSSID not 0xffffffffffff
-        // Pairwise Key can't be WEP
-        if (byKeyDecMode == KEY_CTL_WEP) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
-            //spin_unlock_irq(&pDevice->lock);
-            return -EINVAL;
-        }
-
-        dwKeyIndex |= (1 << 30); // set pairwise key
-        if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
-            //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
-            //spin_unlock_irq(&pDevice->lock);
-            return -EINVAL;
-        }
-        if (KeybSetKey(&(pDevice->sKey),
-                       &param->addr[0],
-                       dwKeyIndex,
-                       param->u.wpa_key.key_len,
-                       (PQWORD) &(KeyRSC),
-                       (unsigned char *)abyKey,
-                        byKeyDecMode,
-                        pDevice->PortOffset,
-                        pDevice->byLocalID) == true) {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
-
-        } else {
-            // Key Table Full
-            if (!compare_ether_addr(&param->addr[0], pDevice->abyBSSID)) {
-                //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
-                //spin_unlock_irq(&pDevice->lock);
-                return -EINVAL;
-
-            } else {
-                // Save Key and configure just before associate/reassociate to BSSID
-                // we do not implement now
-                //spin_unlock_irq(&pDevice->lock);
-                return -EINVAL;
-            }
-        }
-    } // BSSID not 0xffffffffffff
-    if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
-        pDevice->byKeyIndex = (unsigned char)param->u.wpa_key.key_index;
-        pDevice->bTransmitKey = true;
-    }
-    pDevice->bEncryptionEnable = true;
-    //spin_unlock_irq(&pDevice->lock);
+               dwKeyIndex |= (1 << 30); // set pairwise key
+               if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
+                       //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
+                       //spin_unlock_irq(&pDevice->lock);
+                       return -EINVAL;
+               }
+               if (KeybSetKey(&(pDevice->sKey),
+                              &param->addr[0],
+                              dwKeyIndex,
+                              param->u.wpa_key.key_len,
+                              (PQWORD) &(KeyRSC),
+                              (unsigned char *)abyKey,
+                              byKeyDecMode,
+                              pDevice->PortOffset,
+                              pDevice->byLocalID) == true) {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
+
+               } else {
+                       // Key Table Full
+                       if (!compare_ether_addr(&param->addr[0], pDevice->abyBSSID)) {
+                               //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
+                               //spin_unlock_irq(&pDevice->lock);
+                               return -EINVAL;
+
+                       } else {
+                               // Save Key and configure just before associate/reassociate to BSSID
+                               // we do not implement now
+                               //spin_unlock_irq(&pDevice->lock);
+                               return -EINVAL;
+                       }
+               }
+       } // BSSID not 0xffffffffffff
+       if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
+               pDevice->byKeyIndex = (unsigned char)param->u.wpa_key.key_index;
+               pDevice->bTransmitKey = true;
+       }
+       pDevice->bEncryptionEnable = true;
+       //spin_unlock_irq(&pDevice->lock);
 
 /*
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
-               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][0],
-               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][1],
-               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][2],
-               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][3],
-               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][4]
-              );
+  DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
+  pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][0],
+  pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][1],
+  pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][2],
+  pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][3],
+  pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][4]
+);
 */
 
        return ret;
-
 }
 
-
 /*
  * Description:
  *      enable wpa auth & mode
@@ -460,22 +442,18 @@ spin_lock_irq(&pDevice->lock);
  */
 
 static int wpa_set_wpa(PSDevice pDevice,
-                                    struct viawget_wpa_param *param)
+                      struct viawget_wpa_param *param)
 {
-
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
        int ret = 0;
 
-    pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
-    pMgmt->bShareKeyAlgorithm = false;
+       pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
+       pMgmt->bShareKeyAlgorithm = false;
 
-    return ret;
+       return ret;
 }
 
-
-
-
- /*
+/*
  * Description:
  *      set disassociate
  *
@@ -490,23 +468,21 @@ static int wpa_set_wpa(PSDevice pDevice,
  */
 
 static int wpa_set_disassociate(PSDevice pDevice,
-                                    struct viawget_wpa_param *param)
+                               struct viawget_wpa_param *param)
 {
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
        int ret = 0;
 
-    spin_lock_irq(&pDevice->lock);
-    if (pDevice->bLinkPass) {
-        if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6))
-            bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
-    }
-    spin_unlock_irq(&pDevice->lock);
+       spin_lock_irq(&pDevice->lock);
+       if (pDevice->bLinkPass) {
+               if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6))
+                       bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
+       }
+       spin_unlock_irq(&pDevice->lock);
 
-    return ret;
+       return ret;
 }
 
-
-
 /*
  * Description:
  *      enable scan process
@@ -522,20 +498,18 @@ static int wpa_set_disassociate(PSDevice pDevice,
  */
 
 static int wpa_set_scan(PSDevice pDevice,
-                                    struct viawget_wpa_param *param)
+                       struct viawget_wpa_param *param)
 {
        int ret = 0;
 
-    spin_lock_irq(&pDevice->lock);
-    BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
-    bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
-    spin_unlock_irq(&pDevice->lock);
+       spin_lock_irq(&pDevice->lock);
+       BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
+       bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
+       spin_unlock_irq(&pDevice->lock);
 
-    return ret;
+       return ret;
 }
 
-
-
 /*
  * Description:
  *      get bssid
@@ -551,18 +525,16 @@ static int wpa_set_scan(PSDevice pDevice,
  */
 
 static int wpa_get_bssid(PSDevice pDevice,
-                                    struct viawget_wpa_param *param)
+                        struct viawget_wpa_param *param)
 {
-    PSMgmtObject        pMgmt = pDevice->pMgmt;
+       PSMgmtObject        pMgmt = pDevice->pMgmt;
        int ret = 0;
 
        memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6);
 
-    return ret;
-
+       return ret;
 }
 
-
 /*
  * Description:
  *      get bssid
@@ -578,22 +550,20 @@ static int wpa_get_bssid(PSDevice pDevice,
  */
 
 static int wpa_get_ssid(PSDevice pDevice,
-                                    struct viawget_wpa_param *param)
+                       struct viawget_wpa_param *param)
 {
-    PSMgmtObject        pMgmt = pDevice->pMgmt;
+       PSMgmtObject        pMgmt = pDevice->pMgmt;
        PWLAN_IE_SSID       pItemSSID;
        int ret = 0;
 
-    pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
+       pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
 
        memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID , pItemSSID->len);
        param->u.wpa_associate.ssid_len = pItemSSID->len;
 
-    return ret;
+       return ret;
 }
 
-
-
 /*
  * Description:
  *      get scan results
@@ -609,132 +579,112 @@ static int wpa_get_ssid(PSDevice pDevice,
  */
 
 static int wpa_get_scan(PSDevice pDevice,
-                                    struct viawget_wpa_param *param)
+                       struct viawget_wpa_param *param)
 {
        struct viawget_scan_result *scan_buf;
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    PWLAN_IE_SSID   pItemSSID;
-    PKnownBSS pBSS;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PWLAN_IE_SSID   pItemSSID;
+       PKnownBSS pBSS;
        unsigned char *pBuf;
        int ret = 0;
        u16 count = 0;
        u16 ii, jj;
 #if 1
 
-    unsigned char *ptempBSS;
-
-
-
-    ptempBSS = kmalloc(sizeof(KnownBSS), (int)GFP_ATOMIC);
-
-    if (ptempBSS == NULL) {
-
-       printk("bubble sort kmalloc memory fail@@@\n");
+       unsigned char *ptempBSS;
 
-        ret = -ENOMEM;
+       ptempBSS = kmalloc(sizeof(KnownBSS), (int)GFP_ATOMIC);
 
-        return ret;
+       if (ptempBSS == NULL) {
+               printk("bubble sort kmalloc memory fail@@@\n");
 
-    }
+               ret = -ENOMEM;
 
-    for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+               return ret;
 
-         for(jj=0;jj<MAX_BSS_NUM-ii-1;jj++) {
-
-           if((pMgmt->sBSSList[jj].bActive!=true) ||
-
-                ((pMgmt->sBSSList[jj].uRSSI>pMgmt->sBSSList[jj+1].uRSSI) &&(pMgmt->sBSSList[jj+1].bActive!=false))) {
-
-                 memcpy(ptempBSS,&pMgmt->sBSSList[jj],sizeof(KnownBSS));
-
-                 memcpy(&pMgmt->sBSSList[jj],&pMgmt->sBSSList[jj+1],sizeof(KnownBSS));
-
-                 memcpy(&pMgmt->sBSSList[jj+1],ptempBSS,sizeof(KnownBSS));
-
-              }
+       }
 
-         }
+       for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+               for (jj = 0; jj < MAX_BSS_NUM - ii - 1; jj++) {
+                       if ((pMgmt->sBSSList[jj].bActive != true) ||
 
-    }
+                           ((pMgmt->sBSSList[jj].uRSSI > pMgmt->sBSSList[jj + 1].uRSSI) && (pMgmt->sBSSList[jj + 1].bActive != false))) {
+                               memcpy(ptempBSS, &pMgmt->sBSSList[jj], sizeof(KnownBSS));
 
-  kfree(ptempBSS);
+                               memcpy(&pMgmt->sBSSList[jj], &pMgmt->sBSSList[jj + 1], sizeof(KnownBSS));
 
// printk("bubble sort result:\n");
                              memcpy(&pMgmt->sBSSList[jj + 1], ptempBSS, sizeof(KnownBSS));
 
-  //for (ii = 0; ii < MAX_BSS_NUM; ii++)
+                       }
 
-  //    printk("%d [%s]:RSSI=%d\n",ii,((PWLAN_IE_SSID)(pMgmt->sBSSList[ii].abySSID))->abySSID,
+               }
 
-  //                                                                 pMgmt->sBSSList[ii].uRSSI);
+       }
 
- #endif
+       kfree(ptempBSS);
+#endif
 
 //******mike:bubble sort by stronger RSSI*****//
 
-
-
-
        count = 0;
        pBSS = &(pMgmt->sBSSList[0]);
-    for (ii = 0; ii < MAX_BSS_NUM; ii++) {
-        pBSS = &(pMgmt->sBSSList[ii]);
-        if (!pBSS->bActive)
-            continue;
-        count++;
-    }
-
-    pBuf = kcalloc(count, sizeof(struct viawget_scan_result), (int)GFP_ATOMIC);
-
-    if (pBuf == NULL) {
-        ret = -ENOMEM;
-        return ret;
-    }
-    scan_buf = (struct viawget_scan_result *)pBuf;
+       for (ii = 0; ii < MAX_BSS_NUM; ii++) {
+               pBSS = &(pMgmt->sBSSList[ii]);
+               if (!pBSS->bActive)
+                       continue;
+               count++;
+       }
+
+       pBuf = kcalloc(count, sizeof(struct viawget_scan_result), (int)GFP_ATOMIC);
+
+       if (pBuf == NULL) {
+               ret = -ENOMEM;
+               return ret;
+       }
+       scan_buf = (struct viawget_scan_result *)pBuf;
        pBSS = &(pMgmt->sBSSList[0]);
-    for (ii = 0, jj = 0; ii < MAX_BSS_NUM ; ii++) {
-        pBSS = &(pMgmt->sBSSList[ii]);
-        if (pBSS->bActive) {
-            if (jj >= count)
-                break;
-            memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN);
-            pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
-                   memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len);
-                   scan_buf->ssid_len = pItemSSID->len;
-            scan_buf->freq = frequency_list[pBSS->uChannel-1];
-         scan_buf->caps = pBSS->wCapInfo;
-            //scan_buf->caps = pBSS->wCapInfo;
-            //scan_buf->qual =
-            //scan_buf->noise =
-            //scan_buf->level =
-            //scan_buf->maxrate =
-            if (pBSS->wWPALen != 0) {
-                scan_buf->wpa_ie_len = pBSS->wWPALen;
-                memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
-            }
-            if (pBSS->wRSNLen != 0) {
-                scan_buf->rsn_ie_len = pBSS->wRSNLen;
-                memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
-            }
-            scan_buf = (struct viawget_scan_result *)((unsigned char *)scan_buf + sizeof(struct viawget_scan_result));
-            jj ++;
-        }
-    }
-
-    if (jj < count)
-        count = jj;
-
-    if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count)) {
+       for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
+               pBSS = &(pMgmt->sBSSList[ii]);
+               if (pBSS->bActive) {
+                       if (jj >= count)
+                               break;
+                       memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN);
+                       pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
+                       memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len);
+                       scan_buf->ssid_len = pItemSSID->len;
+                       scan_buf->freq = frequency_list[pBSS->uChannel-1];
+                       scan_buf->caps = pBSS->wCapInfo;
+                       //scan_buf->caps = pBSS->wCapInfo;
+                       //scan_buf->qual =
+                       //scan_buf->noise =
+                       //scan_buf->level =
+                       //scan_buf->maxrate =
+                       if (pBSS->wWPALen != 0) {
+                               scan_buf->wpa_ie_len = pBSS->wWPALen;
+                               memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
+                       }
+                       if (pBSS->wRSNLen != 0) {
+                               scan_buf->rsn_ie_len = pBSS->wRSNLen;
+                               memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
+                       }
+                       scan_buf = (struct viawget_scan_result *)((unsigned char *)scan_buf + sizeof(struct viawget_scan_result));
+                       jj++;
+               }
+       }
+
+       if (jj < count)
+               count = jj;
+
+       if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count)) {
                ret = -EFAULT;
        }
        param->u.scan_results.scan_count = count;
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " param->u.scan_results.scan_count = %d\n", count)
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " param->u.scan_results.scan_count = %d\n", count)
 
-    kfree(pBuf);
-    return ret;
+               kfree(pBuf);
+       return ret;
 }
 
-
-
 /*
  * Description:
  *      set associate with AP
@@ -750,23 +700,22 @@ static int wpa_get_scan(PSDevice pDevice,
  */
 
 static int wpa_set_associate(PSDevice pDevice,
-                                    struct viawget_wpa_param *param)
+                            struct viawget_wpa_param *param)
 {
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    PWLAN_IE_SSID   pItemSSID;
-    unsigned char abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-    unsigned char abyWPAIE[64];
-    int ret = 0;
-    bool bWepEnabled=false;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PWLAN_IE_SSID   pItemSSID;
+       unsigned char abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+       unsigned char abyWPAIE[64];
+       int ret = 0;
+       bool bWepEnabled = false;
 
        // set key type & algorithm
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
-    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
-
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
+       DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
 
        if (param->u.wpa_associate.wpa_ie_len) {
                if (!param->u.wpa_associate.wpa_ie)
@@ -778,28 +727,27 @@ static int wpa_set_associate(PSDevice pDevice,
        }
 
        if (param->u.wpa_associate.mode == 1)
-           pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
+               pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
        else
-           pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
-    // set ssid
+               pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
+       // set ssid
        memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
-    pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
-    pItemSSID->byElementID = WLAN_EID_SSID;
+       pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
+       pItemSSID->byElementID = WLAN_EID_SSID;
        pItemSSID->len = param->u.wpa_associate.ssid_len;
        memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
        // set bssid
-    if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
-        memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
-else
-{
-   bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pItemSSID->abySSID);
-}
+       if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
+               memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
+       else {
+               bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pItemSSID->abySSID);
+       }
 
-    if (param->u.wpa_associate.wpa_ie_len == 0) {
-           if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
-            pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
-           else
-            pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
+       if (param->u.wpa_associate.wpa_ie_len == 0) {
+               if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
+                       pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
+               else
+                       pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
        } else if (abyWPAIE[0] == RSN_INFO_ELEM) {
                if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
                        pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
@@ -809,9 +757,9 @@ else
                if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
                        pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
                else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
-                   pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
+                       pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
                else
-                   pMgmt->eAuthenMode = WMAC_AUTH_WPA;
+                       pMgmt->eAuthenMode = WMAC_AUTH_WPA;
        }
 
        switch (param->u.wpa_associate.pairwise_suite) {
@@ -824,7 +772,7 @@ else
        case CIPHER_WEP40:
        case CIPHER_WEP104:
                pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
-               bWepEnabled=true;
+               bWepEnabled = true;
                break;
        case CIPHER_NONE:
                if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
@@ -838,55 +786,53 @@ else
 
 //DavidWang add for WPA_supplicant support open/share mode
 
-      if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) {
-            pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
-            //pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
-            pMgmt->bShareKeyAlgorithm = true;
-             }
-     else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
-          if(!bWepEnabled)  pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
-       else pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
-            //pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
-            //pMgmt->bShareKeyAlgorithm = false; //20080717-06,<Modify> by chester//Fix Open mode, WEP encryption
-           }
+       if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) {
+               pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
+               //pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
+               pMgmt->bShareKeyAlgorithm = true;
+       } else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
+               if (!bWepEnabled)  pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
+               else pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
+               //pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
+               //pMgmt->bShareKeyAlgorithm = false; //20080717-06,<Modify> by chester//Fix Open mode, WEP encryption
+       }
 //mike save old encryption status
        pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;
 
-    if (pDevice->eEncryptionStatus !=  Ndis802_11EncryptionDisabled)
-        pDevice->bEncryptionEnable = true;
-    else
-        pDevice->bEncryptionEnable = false;
-if (!((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
-      ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && (bWepEnabled==true))) )  //DavidWang  //20080717-06,<Modify> by chester//Not to initial WEP
-    KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
-    spin_lock_irq(&pDevice->lock);
-    pDevice->bLinkPass = false;
-    memset(pMgmt->abyCurrBSSID, 0, 6);
-    pMgmt->eCurrState = WMAC_STATE_IDLE;
-    netif_stop_queue(pDevice->dev);
+       if (pDevice->eEncryptionStatus !=  Ndis802_11EncryptionDisabled)
+               pDevice->bEncryptionEnable = true;
+       else
+               pDevice->bEncryptionEnable = false;
+       if (!((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
+             ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && (bWepEnabled == true))))  //DavidWang  //20080717-06,<Modify> by chester//Not to initial WEP
+               KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
+       spin_lock_irq(&pDevice->lock);
+       pDevice->bLinkPass = false;
+       memset(pMgmt->abyCurrBSSID, 0, 6);
+       pMgmt->eCurrState = WMAC_STATE_IDLE;
+       netif_stop_queue(pDevice->dev);
        //20080701-02,<Add> by Mike Liu
 /*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
-{
-   PKnownBSS       pCurr = NULL;
-    pCurr = BSSpSearchBSSList(pDevice,
-                              pMgmt->abyDesireBSSID,
-                              pMgmt->abyDesireSSID,
-                              pMgmt->eConfigPHYMode
-                              );
-
-    if (pCurr == NULL){
-    printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
-    bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
-  }
-}
+       {
+               PKnownBSS       pCurr = NULL;
+               pCurr = BSSpSearchBSSList(pDevice,
+                                         pMgmt->abyDesireBSSID,
+                                         pMgmt->abyDesireSSID,
+                                         pMgmt->eConfigPHYMode
+);
+
+               if (pCurr == NULL) {
+                       printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
+                       bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
+               }
+       }
 /****************************************************************/
-    bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
-    spin_unlock_irq(&pDevice->lock);
+       bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
+       spin_unlock_irq(&pDevice->lock);
 
-    return ret;
+       return ret;
 }
 
-
 /*
  * Description:
  *      wpa_ioctl main function supported for wpa supplicant
@@ -922,61 +868,61 @@ int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
 
        switch (param->cmd) {
        case VIAWGET_SET_WPA:
-        ret = wpa_set_wpa(pDevice, param);
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_WPA \n");
+               ret = wpa_set_wpa(pDevice, param);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_WPA \n");
                break;
 
        case VIAWGET_SET_KEY:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_KEY \n");
-           spin_lock_irq(&pDevice->lock);
-        ret = wpa_set_keys(pDevice, param, false);
-        spin_unlock_irq(&pDevice->lock);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_KEY \n");
+               spin_lock_irq(&pDevice->lock);
+               ret = wpa_set_keys(pDevice, param, false);
+               spin_unlock_irq(&pDevice->lock);
                break;
 
        case VIAWGET_SET_SCAN:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_SCAN \n");
-        ret = wpa_set_scan(pDevice, param);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_SCAN \n");
+               ret = wpa_set_scan(pDevice, param);
                break;
 
        case VIAWGET_GET_SCAN:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SCAN\n");
-        ret = wpa_get_scan(pDevice, param);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SCAN\n");
+               ret = wpa_get_scan(pDevice, param);
                wpa_ioctl = 1;
                break;
 
        case VIAWGET_GET_SSID:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SSID \n");
-        ret = wpa_get_ssid(pDevice, param);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SSID \n");
+               ret = wpa_get_ssid(pDevice, param);
                wpa_ioctl = 1;
                break;
 
        case VIAWGET_GET_BSSID:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_BSSID \n");
-        ret = wpa_get_bssid(pDevice, param);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_BSSID \n");
+               ret = wpa_get_bssid(pDevice, param);
                wpa_ioctl = 1;
                break;
 
        case VIAWGET_SET_ASSOCIATE:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_ASSOCIATE \n");
-        ret = wpa_set_associate(pDevice, param);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_ASSOCIATE \n");
+               ret = wpa_set_associate(pDevice, param);
                break;
 
        case VIAWGET_SET_DISASSOCIATE:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DISASSOCIATE \n");
-        ret = wpa_set_disassociate(pDevice, param);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DISASSOCIATE \n");
+               ret = wpa_set_disassociate(pDevice, param);
                break;
 
        case VIAWGET_SET_DROP_UNENCRYPT:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT \n");
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT \n");
                break;
 
-    case VIAWGET_SET_DEAUTHENTICATE:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE \n");
+       case VIAWGET_SET_DEAUTHENTICATE:
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE \n");
                break;
 
        default:
-           DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ioctl: unknown cmd=%d\n",
-                      param->cmd);
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ioctl: unknown cmd=%d\n",
+                       param->cmd);
                return -EOPNOTSUPP;
                break;
        }
@@ -993,4 +939,3 @@ out:
 
        return ret;
 }
-
index dbe8e861d991e226648fbd53b15d4fc1164e14b5..b9e2ab231f1bd299b67799dc91e8347079f83e07 100644 (file)
 
 /*---------------------  Export Definitions -------------------------*/
 
-
 //WPA related
 
 typedef enum { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP } wpa_alg;
 typedef enum { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP,
               CIPHER_WEP104 } wpa_cipher;
-typedef enum { KEY_MGMT_802_1X, KEY_MGMT_CCKM,KEY_MGMT_PSK, KEY_MGMT_NONE,
+typedef enum { KEY_MGMT_802_1X, KEY_MGMT_CCKM, KEY_MGMT_PSK, KEY_MGMT_NONE,
               KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE } wpa_key_mgmt;
 
 #define AUTH_ALG_OPEN_SYSTEM   0x01
@@ -52,8 +51,6 @@ typedef enum { KEY_MGMT_802_1X, KEY_MGMT_CCKM,KEY_MGMT_PSK, KEY_MGMT_NONE,
 #define GENERIC_INFO_ELEM 0xdd
 #define RSN_INFO_ELEM 0x30
 
-
-
 typedef unsigned long long   NDIS_802_11_KEY_RSC;
 
 /*---------------------  Export Classes  ----------------------------*/
@@ -67,6 +64,3 @@ int wpa_ioctl(PSDevice pDevice, struct iw_point *p);
 int wpa_set_keys(PSDevice pDevice, void *ctx, bool fcpfkernel);
 
 #endif // __WPACL_H__
-
-
-
index 82e93cb820535a2d36fd5c8c39a00005cc999954..b61328fbee87d41b68789e909c85d360e27577a7 100644 (file)
 /*---------------------  Static Classes  ----------------------------*/
 
 /*---------------------  Static Variables  --------------------------*/
-static int          msglevel                =MSG_LEVEL_INFO;
+static int msglevel = MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 /*---------------------  Static Functions  --------------------------*/
 
 /*---------------------  Export Variables  --------------------------*/
 
-
-
 /*
  * Description:
  *      Relay packet.  Return true if packet is copy to DMA1
@@ -65,135 +63,128 @@ static int          msglevel                =MSG_LEVEL_INFO;
  * Return Value: true if packet duplicate; otherwise false
  *
  */
-bool ROUTEbRelay (PSDevice pDevice, unsigned char *pbySkbData, unsigned int uDataLen, unsigned int uNodeIndex)
+bool ROUTEbRelay(PSDevice pDevice, unsigned char *pbySkbData, unsigned int uDataLen, unsigned int uNodeIndex)
 {
-    PSMgmtObject    pMgmt = pDevice->pMgmt;
-    PSTxDesc        pHeadTD, pLastTD;
-    unsigned int cbFrameBodySize;
-    unsigned int uMACfragNum;
-    unsigned char byPktType;
-    bool bNeedEncryption = false;
-    SKeyItem        STempKey;
-    PSKeyItem       pTransmitKey = NULL;
-    unsigned int cbHeaderSize;
-    unsigned int ii;
-    unsigned char *pbyBSSID;
-
-
-
-
-    if (AVAIL_TD(pDevice, TYPE_AC0DMA)<=0) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Relay can't allocate TD1..\n");
-        return false;
-    }
-
-    pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
-
-    pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
-
-    memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)pbySkbData, ETH_HLEN);
-
-    cbFrameBodySize = uDataLen - ETH_HLEN;
-
-    if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN) {
-        cbFrameBodySize += 8;
-    }
-
-    if (pDevice->bEncryptionEnable == true) {
-        bNeedEncryption = true;
-
-        // get group key
-        pbyBSSID = pDevice->abyBroadcastAddr;
-        if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
-            pTransmitKey = NULL;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
-        } else {
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
-        }
-    }
-
-    if (pDevice->bEnableHostWEP) {
-       if (uNodeIndex < MAX_NODE_NUM + 1) {
-            pTransmitKey = &STempKey;
-            pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
-            pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
-            pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
-            pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
-            pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
-            memcpy(pTransmitKey->abyKey,
-                &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
-                pTransmitKey->uKeyLength
-                );
-        }
-    }
-
-    uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
-
-    if (uMACfragNum > AVAIL_TD(pDevice,TYPE_AC0DMA)) {
-        return false;
-    }
-    byPktType = (unsigned char)pDevice->byPacketType;
-
-    if (pDevice->bFixRate) {
-        if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
-            if (pDevice->uConnectionRate >= RATE_11M) {
-                pDevice->wCurrentRate = RATE_11M;
-            } else {
-                pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
-            }
-        } else {
-            if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
-                (pDevice->uConnectionRate <= RATE_6M)) {
-                pDevice->wCurrentRate = RATE_6M;
-            } else {
-                if (pDevice->uConnectionRate >= RATE_54M)
-                    pDevice->wCurrentRate = RATE_54M;
-                else
-                    pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
-            }
-        }
-    }
-    else {
-        pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
-    }
-
-    if (pDevice->wCurrentRate <= RATE_11M)
-        byPktType = PK_TYPE_11B;
-
-    vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
-                        cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
-                        &pDevice->sTxEthHeader, pbySkbData, pTransmitKey, uNodeIndex,
-                        &uMACfragNum,
-                        &cbHeaderSize
-                        );
-
-    if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
-        // Disable PS
-        MACbPSWakeup(pDevice->PortOffset);
-    }
-
-    pDevice->bPWBitOn = false;
-
-    pLastTD = pHeadTD;
-    for (ii = 0; ii < uMACfragNum; ii++) {
-        // Poll Transmit the adapter
-        wmb();
-        pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
-        wmb();
-        if (ii == (uMACfragNum - 1))
-            pLastTD = pHeadTD;
-        pHeadTD = pHeadTD->next;
-    }
-
-    pLastTD->pTDInfo->skb = 0;
-    pLastTD->pTDInfo->byFlags = 0;
-
-    pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
-
-    MACvTransmitAC0(pDevice->PortOffset);
-
-    return true;
+       PSMgmtObject    pMgmt = pDevice->pMgmt;
+       PSTxDesc        pHeadTD, pLastTD;
+       unsigned int cbFrameBodySize;
+       unsigned int uMACfragNum;
+       unsigned char byPktType;
+       bool bNeedEncryption = false;
+       SKeyItem        STempKey;
+       PSKeyItem       pTransmitKey = NULL;
+       unsigned int cbHeaderSize;
+       unsigned int ii;
+       unsigned char *pbyBSSID;
+
+       if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 0) {
+               DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Relay can't allocate TD1..\n");
+               return false;
+       }
+
+       pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
+
+       pHeadTD->m_td1TD1.byTCR = (TCR_EDP | TCR_STP);
+
+       memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)pbySkbData, ETH_HLEN);
+
+       cbFrameBodySize = uDataLen - ETH_HLEN;
+
+       if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN) {
+               cbFrameBodySize += 8;
+       }
+
+       if (pDevice->bEncryptionEnable == true) {
+               bNeedEncryption = true;
+
+               // get group key
+               pbyBSSID = pDevice->abyBroadcastAddr;
+               if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
+                       pTransmitKey = NULL;
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
+               } else {
+                       DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
+               }
+       }
+
+       if (pDevice->bEnableHostWEP) {
+               if (uNodeIndex < MAX_NODE_NUM + 1) {
+                       pTransmitKey = &STempKey;
+                       pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
+                       pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
+                       pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
+                       pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
+                       pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
+                       memcpy(pTransmitKey->abyKey,
+                              &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
+                              pTransmitKey->uKeyLength
+);
+               }
+       }
+
+       uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
+
+       if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
+               return false;
+       }
+       byPktType = (unsigned char)pDevice->byPacketType;
+
+       if (pDevice->bFixRate) {
+               if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
+                       if (pDevice->uConnectionRate >= RATE_11M) {
+                               pDevice->wCurrentRate = RATE_11M;
+                       } else {
+                               pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
+                       }
+               } else {
+                       if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
+                           (pDevice->uConnectionRate <= RATE_6M)) {
+                               pDevice->wCurrentRate = RATE_6M;
+                       } else {
+                               if (pDevice->uConnectionRate >= RATE_54M)
+                                       pDevice->wCurrentRate = RATE_54M;
+                               else
+                                       pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
+                       }
+               }
+       } else {
+               pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
+       }
+
+       if (pDevice->wCurrentRate <= RATE_11M)
+               byPktType = PK_TYPE_11B;
+
+       vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
+                           cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
+                           &pDevice->sTxEthHeader, pbySkbData, pTransmitKey, uNodeIndex,
+                           &uMACfragNum,
+                           &cbHeaderSize
+);
+
+       if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
+               // Disable PS
+               MACbPSWakeup(pDevice->PortOffset);
+       }
+
+       pDevice->bPWBitOn = false;
+
+       pLastTD = pHeadTD;
+       for (ii = 0; ii < uMACfragNum; ii++) {
+               // Poll Transmit the adapter
+               wmb();
+               pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
+               wmb();
+               if (ii == (uMACfragNum - 1))
+                       pLastTD = pHeadTD;
+               pHeadTD = pHeadTD->next;
+       }
+
+       pLastTD->pTDInfo->skb = 0;
+       pLastTD->pTDInfo->byFlags = 0;
+
+       pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
+
+       MACvTransmitAC0(pDevice->PortOffset);
+
+       return true;
 }
-
-
-
index 34f9e43a6cc478ccae3df77dc38ee26a27790aba..5ecc190ae775581e41224cedcfc48fa5876b3b4e 100644 (file)
@@ -39,9 +39,6 @@
 
 /*---------------------  Export Functions  --------------------------*/
 
-bool ROUTEbRelay (PSDevice pDevice, unsigned char *pbySkbData, unsigned int uDataLen, unsigned int uNodeIndex);
+bool ROUTEbRelay(PSDevice pDevice, unsigned char *pbySkbData, unsigned int uDataLen, unsigned int uNodeIndex);
 
 #endif // __WROUTE_H__
-
-
-
index b87d5434077a55660ac194e916509ff8dbcfffa1..000304ffad6c13bbb5c11711dcd1ded11da061e0 100644 (file)
 #ifndef __80211HDR_H__
 #define __80211HDR_H__
 
-#include "ttype.h"
-
-/*---------------------  Export Definitions -------------------------*/
-
 /* bit type */
 #define BIT0   0x00000001
 #define BIT1   0x00000002
 #ifdef __BIG_ENDIAN
 
 /* GET & SET Frame Control bit */
-#define WLAN_GET_FC_PRVER(n)    ((((WORD)(n) >> 8) & (BIT0 | BIT1))
-#define WLAN_GET_FC_FTYPE(n)    ((((WORD)(n) >> 8) & (BIT2 | BIT3)) >> 2)
-#define WLAN_GET_FC_FSTYPE(n)   ((((WORD)(n) >> 8) \
+#define WLAN_GET_FC_PRVER(n)    ((((u16)(n) >> 8) & (BIT0 | BIT1))
+#define WLAN_GET_FC_FTYPE(n)    ((((u16)(n) >> 8) & (BIT2 | BIT3)) >> 2)
+#define WLAN_GET_FC_FSTYPE(n)   ((((u16)(n) >> 8) \
                                  & (BIT4|BIT5|BIT6|BIT7)) >> 4)
-#define WLAN_GET_FC_TODS(n)     ((((WORD)(n) << 8) & (BIT8)) >> 8)
-#define WLAN_GET_FC_FROMDS(n)   ((((WORD)(n) << 8) & (BIT9)) >> 9)
-#define WLAN_GET_FC_MOREFRAG(n) ((((WORD)(n) << 8) & (BIT10)) >> 10)
-#define WLAN_GET_FC_RETRY(n)    ((((WORD)(n) << 8) & (BIT11)) >> 11)
-#define WLAN_GET_FC_PWRMGT(n)   ((((WORD)(n) << 8) & (BIT12)) >> 12)
-#define WLAN_GET_FC_MOREDATA(n) ((((WORD)(n) << 8) & (BIT13)) >> 13)
-#define WLAN_GET_FC_ISWEP(n)    ((((WORD)(n) << 8) & (BIT14)) >> 14)
-#define WLAN_GET_FC_ORDER(n)    ((((WORD)(n) << 8) & (BIT15)) >> 15)
+#define WLAN_GET_FC_TODS(n)     ((((u16)(n) << 8) & (BIT8)) >> 8)
+#define WLAN_GET_FC_FROMDS(n)   ((((u16)(n) << 8) & (BIT9)) >> 9)
+#define WLAN_GET_FC_MOREFRAG(n) ((((u16)(n) << 8) & (BIT10)) >> 10)
+#define WLAN_GET_FC_RETRY(n)    ((((u16)(n) << 8) & (BIT11)) >> 11)
+#define WLAN_GET_FC_PWRMGT(n)   ((((u16)(n) << 8) & (BIT12)) >> 12)
+#define WLAN_GET_FC_MOREDATA(n) ((((u16)(n) << 8) & (BIT13)) >> 13)
+#define WLAN_GET_FC_ISWEP(n)    ((((u16)(n) << 8) & (BIT14)) >> 14)
+#define WLAN_GET_FC_ORDER(n)    ((((u16)(n) << 8) & (BIT15)) >> 15)
 
 /* Sequence Field bit */
-#define WLAN_GET_SEQ_FRGNUM(n) (((WORD)(n) >> 8) & (BIT0|BIT1|BIT2|BIT3))
-#define WLAN_GET_SEQ_SEQNUM(n) ((((WORD)(n) >> 8) \
+#define WLAN_GET_SEQ_FRGNUM(n) (((u16)(n) >> 8) & (BIT0|BIT1|BIT2|BIT3))
+#define WLAN_GET_SEQ_SEQNUM(n) ((((u16)(n) >> 8) \
                                 & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
 
 /* Capability Field bit */
 #else
 
 /* GET & SET Frame Control bit */
-#define WLAN_GET_FC_PRVER(n)    (((WORD)(n)) & (BIT0 | BIT1))
-#define WLAN_GET_FC_FTYPE(n)    ((((WORD)(n)) & (BIT2 | BIT3)) >> 2)
-#define WLAN_GET_FC_FSTYPE(n)   ((((WORD)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
-#define WLAN_GET_FC_TODS(n)     ((((WORD)(n)) & (BIT8)) >> 8)
-#define WLAN_GET_FC_FROMDS(n)   ((((WORD)(n)) & (BIT9)) >> 9)
-#define WLAN_GET_FC_MOREFRAG(n) ((((WORD)(n)) & (BIT10)) >> 10)
-#define WLAN_GET_FC_RETRY(n)    ((((WORD)(n)) & (BIT11)) >> 11)
-#define WLAN_GET_FC_PWRMGT(n)   ((((WORD)(n)) & (BIT12)) >> 12)
-#define WLAN_GET_FC_MOREDATA(n) ((((WORD)(n)) & (BIT13)) >> 13)
-#define WLAN_GET_FC_ISWEP(n)    ((((WORD)(n)) & (BIT14)) >> 14)
-#define WLAN_GET_FC_ORDER(n)    ((((WORD)(n)) & (BIT15)) >> 15)
+#define WLAN_GET_FC_PRVER(n)    (((u16)(n)) & (BIT0 | BIT1))
+#define WLAN_GET_FC_FTYPE(n)    ((((u16)(n)) & (BIT2 | BIT3)) >> 2)
+#define WLAN_GET_FC_FSTYPE(n)   ((((u16)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
+#define WLAN_GET_FC_TODS(n)     ((((u16)(n)) & (BIT8)) >> 8)
+#define WLAN_GET_FC_FROMDS(n)   ((((u16)(n)) & (BIT9)) >> 9)
+#define WLAN_GET_FC_MOREFRAG(n) ((((u16)(n)) & (BIT10)) >> 10)
+#define WLAN_GET_FC_RETRY(n)    ((((u16)(n)) & (BIT11)) >> 11)
+#define WLAN_GET_FC_PWRMGT(n)   ((((u16)(n)) & (BIT12)) >> 12)
+#define WLAN_GET_FC_MOREDATA(n) ((((u16)(n)) & (BIT13)) >> 13)
+#define WLAN_GET_FC_ISWEP(n)    ((((u16)(n)) & (BIT14)) >> 14)
+#define WLAN_GET_FC_ORDER(n)    ((((u16)(n)) & (BIT15)) >> 15)
 
 /* Sequence Field bit */
-#define WLAN_GET_SEQ_FRGNUM(n) (((WORD)(n)) & (BIT0|BIT1|BIT2|BIT3))
-#define WLAN_GET_SEQ_SEQNUM(n) ((((WORD)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
+#define WLAN_GET_SEQ_FRGNUM(n) (((u16)(n)) & (BIT0|BIT1|BIT2|BIT3))
+#define WLAN_GET_SEQ_SEQNUM(n) ((((u16)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
 
 /* Capability Field bit */
 #define WLAN_GET_CAP_INFO_ESS(n)           ((n) & BIT0)
 #define WLAN_SET_CAP_INFO_DSSSOFDM(n)      ((n) << 13)
 #define WLAN_SET_CAP_INFO_GRPACK(n)        ((n) << 14)
 
-#define WLAN_SET_FC_PRVER(n)    ((WORD)(n))
-#define WLAN_SET_FC_FTYPE(n)    (((WORD)(n)) << 2)
-#define WLAN_SET_FC_FSTYPE(n)   (((WORD)(n)) << 4)
-#define WLAN_SET_FC_TODS(n)     (((WORD)(n)) << 8)
-#define WLAN_SET_FC_FROMDS(n)   (((WORD)(n)) << 9)
-#define WLAN_SET_FC_MOREFRAG(n) (((WORD)(n)) << 10)
-#define WLAN_SET_FC_RETRY(n)    (((WORD)(n)) << 11)
-#define WLAN_SET_FC_PWRMGT(n)   (((WORD)(n)) << 12)
-#define WLAN_SET_FC_MOREDATA(n) (((WORD)(n)) << 13)
-#define WLAN_SET_FC_ISWEP(n)    (((WORD)(n)) << 14)
-#define WLAN_SET_FC_ORDER(n)    (((WORD)(n)) << 15)
-
-#define WLAN_SET_SEQ_FRGNUM(n) ((WORD)(n))
-#define WLAN_SET_SEQ_SEQNUM(n) (((WORD)(n)) << 4)
+#define WLAN_SET_FC_PRVER(n)    ((u16)(n))
+#define WLAN_SET_FC_FTYPE(n)    (((u16)(n)) << 2)
+#define WLAN_SET_FC_FSTYPE(n)   (((u16)(n)) << 4)
+#define WLAN_SET_FC_TODS(n)     (((u16)(n)) << 8)
+#define WLAN_SET_FC_FROMDS(n)   (((u16)(n)) << 9)
+#define WLAN_SET_FC_MOREFRAG(n) (((u16)(n)) << 10)
+#define WLAN_SET_FC_RETRY(n)    (((u16)(n)) << 11)
+#define WLAN_SET_FC_PWRMGT(n)   (((u16)(n)) << 12)
+#define WLAN_SET_FC_MOREDATA(n) (((u16)(n)) << 13)
+#define WLAN_SET_FC_ISWEP(n)    (((u16)(n)) << 14)
+#define WLAN_SET_FC_ORDER(n)    (((u16)(n)) << 15)
+
+#define WLAN_SET_SEQ_FRGNUM(n) ((u16)(n))
+#define WLAN_SET_SEQ_SEQNUM(n) (((u16)(n)) << 4)
 
 /* ERP Field bit */
 
 #define WLAN_MGMT_GET_TIM_OFFSET(b)     (((b) & ~BIT0) >> 1)
 
 /* 3-Addr & 4-Addr */
-#define WLAN_HDR_A3_DATA_PTR(p) (((PBYTE)(p)) + WLAN_HDR_ADDR3_LEN)
-#define WLAN_HDR_A4_DATA_PTR(p) (((PBYTE)(p)) + WLAN_HDR_ADDR4_LEN)
+#define WLAN_HDR_A3_DATA_PTR(p) (((u8 *)(p)) + WLAN_HDR_ADDR3_LEN)
+#define WLAN_HDR_A4_DATA_PTR(p) (((u8 *)(p)) + WLAN_HDR_ADDR4_LEN)
 
 /* IEEE ADDR */
 #define IEEE_ADDR_UNIVERSAL         0x02
 #define IEEE_ADDR_GROUP             0x01
 
 typedef struct {
-    BYTE            abyAddr[6];
+    u8            abyAddr[6];
 } IEEE_ADDR, *PIEEE_ADDR;
 
 /* 802.11 Header Format */
 
 typedef struct tagWLAN_80211HDR_A2 {
 
-    WORD    wFrameCtl;
-    WORD    wDurationID;
-    BYTE    abyAddr1[WLAN_ADDR_LEN];
-    BYTE    abyAddr2[WLAN_ADDR_LEN];
+    u16    wFrameCtl;
+    u16    wDurationID;
+    u8    abyAddr1[WLAN_ADDR_LEN];
+    u8    abyAddr2[WLAN_ADDR_LEN];
 
 } __attribute__ ((__packed__))
 WLAN_80211HDR_A2, *PWLAN_80211HDR_A2;
 
 typedef struct tagWLAN_80211HDR_A3 {
 
-    WORD    wFrameCtl;
-    WORD    wDurationID;
-    BYTE    abyAddr1[WLAN_ADDR_LEN];
-    BYTE    abyAddr2[WLAN_ADDR_LEN];
-    BYTE    abyAddr3[WLAN_ADDR_LEN];
-    WORD    wSeqCtl;
+    u16    wFrameCtl;
+    u16    wDurationID;
+    u8    abyAddr1[WLAN_ADDR_LEN];
+    u8    abyAddr2[WLAN_ADDR_LEN];
+    u8    abyAddr3[WLAN_ADDR_LEN];
+    u16    wSeqCtl;
 
 } __attribute__ ((__packed__))
 WLAN_80211HDR_A3, *PWLAN_80211HDR_A3;
 
 typedef struct tagWLAN_80211HDR_A4 {
 
-    WORD    wFrameCtl;
-    WORD    wDurationID;
-    BYTE    abyAddr1[WLAN_ADDR_LEN];
-    BYTE    abyAddr2[WLAN_ADDR_LEN];
-    BYTE    abyAddr3[WLAN_ADDR_LEN];
-    WORD    wSeqCtl;
-    BYTE    abyAddr4[WLAN_ADDR_LEN];
+    u16    wFrameCtl;
+    u16    wDurationID;
+    u8    abyAddr1[WLAN_ADDR_LEN];
+    u8    abyAddr2[WLAN_ADDR_LEN];
+    u8    abyAddr3[WLAN_ADDR_LEN];
+    u16    wSeqCtl;
+    u8    abyAddr4[WLAN_ADDR_LEN];
 
 } __attribute__ ((__packed__))
 WLAN_80211HDR_A4, *PWLAN_80211HDR_A4;
@@ -325,10 +321,4 @@ typedef union tagUWLAN_80211HDR {
 
 } UWLAN_80211HDR, *PUWLAN_80211HDR;
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 #endif /* __80211HDR_H__ */
index 534d490539b614a0869152a28f18afc8b4bd7d3a..61edb51f383698d1259b69ea13deedacb28f7c26 100644 (file)
@@ -27,8 +27,6 @@
  * Functions:
  *      vMgrEncodeBeacon - Encode the Beacon frame
  *      vMgrDecodeBeacon - Decode the Beacon frame
- *      vMgrEncodeIBSSATIM - Encode the IBSS ATIM frame
- *      vMgrDecodeIBSSATIM - Decode the IBSS ATIM frame
  *      vMgrEncodeDisassociation - Encode the Disassociation frame
  *      vMgrDecodeDisassociation - Decode the Disassociation frame
  *      vMgrEncodeAssocRequest - Encode the Association request frame
@@ -46,7 +44,6 @@
  *      vMgrEncodeDeauthen - Encode the DeAuthentication frame
  *      vMgrDecodeDeauthen - Decode the DeAuthentication frame
  *      vMgrEncodeReassocResponse - Encode the Reassociation response frame
- *      vMgrDecodeReassocResponse - Decode the Reassociation response frame
  *
  * Revision History:
  *
 #include "80211hdr.h"
 #include "wpa.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
 static int          msglevel                = MSG_LEVEL_INFO;
 /*static int          msglevel                =MSG_LEVEL_DEBUG;*/
-/*---------------------  Static Functions  --------------------------*/
-
-
-
-/*---------------------  Export Variables  --------------------------*/
-
-
-/*---------------------  Export Functions  --------------------------*/
-
 
 /*+
  *
@@ -100,9 +80,9 @@ vMgrEncodeBeacon(
        pFrame->pqwTimestamp =
                (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
                        WLAN_BEACON_OFF_TS);
-    pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwBeaconInterval = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                        + WLAN_BEACON_OFF_BCN_INT);
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwCapInfo = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_BEACON_OFF_CAPINFO);
 
     pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_BEACON_OFF_SSID;
@@ -121,7 +101,6 @@ vMgrEncodeBeacon(
  *
 -*/
 
-
 void
 vMgrDecodeBeacon(
       PWLAN_FR_BEACON  pFrame
@@ -135,15 +114,15 @@ vMgrDecodeBeacon(
        pFrame->pqwTimestamp =
                (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
                        WLAN_BEACON_OFF_TS);
-    pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwBeaconInterval = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                        + WLAN_BEACON_OFF_BCN_INT);
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwCapInfo = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_BEACON_OFF_CAPINFO);
 
     /* Information elements */
-    pItem = (PWLAN_IE)((PBYTE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)))
+    pItem = (PWLAN_IE)((u8 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)))
                        + WLAN_BEACON_OFF_SSID);
-    while (((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) {
+    while (((u8 *)pItem) < (pFrame->pBuf + pFrame->len)) {
 
         switch (pItem->byElementID) {
         case WLAN_EID_SSID:
@@ -224,53 +203,10 @@ vMgrDecodeBeacon(
                 break;
 
         }
-        pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
+        pItem = (PWLAN_IE)(((u8 *)pItem) + 2 + pItem->len);
     }
 }
 
-
-/*+
- *
- * Routine Description:
- *  Encode IBSS ATIM
- *
- *
- * Return Value:
- *    None.
- *
--*/
-
-
-void
-vMgrEncodeIBSSATIM(
-      PWLAN_FR_IBSSATIM   pFrame
-    )
-{
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-    pFrame->len = WLAN_HDR_ADDR3_LEN;
-}
-
-
-/*+
- *
- * Routine Description:
- *  Decode IBSS ATIM
- *
- *
- * Return Value:
- *    None.
- *
--*/
-
-void
-vMgrDecodeIBSSATIM(
-      PWLAN_FR_IBSSATIM   pFrame
-    )
-{
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-}
-
-
 /*+
  *
  * Routine Description:
@@ -289,14 +225,12 @@ vMgrEncodeDisassociation(
 {
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
-
     /* Fixed Fields */
-    pFrame->pwReason = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwReason = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                + WLAN_DISASSOC_OFF_REASON);
     pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DISASSOC_OFF_REASON + sizeof(*(pFrame->pwReason));
 }
 
-
 /*+
  *
  * Routine Description:
@@ -316,7 +250,7 @@ vMgrDecodeDisassociation(
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
     /* Fixed Fields */
-    pFrame->pwReason = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwReason = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                + WLAN_DISASSOC_OFF_REASON);
 }
 
@@ -331,7 +265,6 @@ vMgrDecodeDisassociation(
  *
 -*/
 
-
 void
 vMgrEncodeAssocRequest(
       PWLAN_FR_ASSOCREQ  pFrame
@@ -339,14 +272,13 @@ vMgrEncodeAssocRequest(
 {
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
     /* Fixed Fields */
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwCapInfo = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_ASSOCREQ_OFF_CAP_INFO);
-    pFrame->pwListenInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwListenInterval = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                        + WLAN_ASSOCREQ_OFF_LISTEN_INT);
     pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCREQ_OFF_LISTEN_INT + sizeof(*(pFrame->pwListenInterval));
 }
 
-
 /*+
  *
  * Routine Description: (AP)
@@ -367,16 +299,16 @@ vMgrDecodeAssocRequest(
 
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
     /* Fixed Fields */
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwCapInfo = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_ASSOCREQ_OFF_CAP_INFO);
-    pFrame->pwListenInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwListenInterval = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_ASSOCREQ_OFF_LISTEN_INT);
 
     /* Information elements */
     pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                             + WLAN_ASSOCREQ_OFF_SSID);
 
-    while (((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) {
+    while (((u8 *)pItem) < (pFrame->pBuf + pFrame->len)) {
         switch (pItem->byElementID) {
         case WLAN_EID_SSID:
             if (pFrame->pSSID == NULL)
@@ -407,7 +339,7 @@ vMgrDecodeAssocRequest(
                     pItem->byElementID);
             break;
         }
-        pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
+        pItem = (PWLAN_IE)(((u8 *)pItem) + 2 + pItem->len);
     }
 }
 
@@ -430,17 +362,16 @@ vMgrEncodeAssocResponse(
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
     /* Fixed Fields */
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwCapInfo = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_ASSOCRESP_OFF_CAP_INFO);
-    pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwStatus = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                + WLAN_ASSOCRESP_OFF_STATUS);
-    pFrame->pwAid = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwAid = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                             + WLAN_ASSOCRESP_OFF_AID);
     pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCRESP_OFF_AID
                   + sizeof(*(pFrame->pwAid));
 }
 
-
 /*+
  *
  * Routine Description:
@@ -462,11 +393,11 @@ vMgrDecodeAssocResponse(
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
     /* Fixed Fields */
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwCapInfo = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_ASSOCRESP_OFF_CAP_INFO);
-    pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwStatus = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                + WLAN_ASSOCRESP_OFF_STATUS);
-    pFrame->pwAid = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwAid = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                             + WLAN_ASSOCRESP_OFF_AID);
 
     /* Information elements */
@@ -474,16 +405,15 @@ vMgrDecodeAssocResponse(
                            + WLAN_ASSOCRESP_OFF_SUPP_RATES);
 
     pItem = (PWLAN_IE)(pFrame->pSuppRates);
-    pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
+    pItem = (PWLAN_IE)(((u8 *)pItem) + 2 + pItem->len);
 
-    if ((((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) && (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
+    if ((((u8 *)pItem) < (pFrame->pBuf + pFrame->len)) && (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
         pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pFrame->pExtSuppRates=[%p].\n", pItem);
        } else
         pFrame->pExtSuppRates = NULL;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -503,16 +433,15 @@ vMgrEncodeReassocRequest(
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
     /* Fixed Fields */
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwCapInfo = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_REASSOCREQ_OFF_CAP_INFO);
-    pFrame->pwListenInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwListenInterval = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                       + WLAN_REASSOCREQ_OFF_LISTEN_INT);
     pFrame->pAddrCurrAP = (PIEEE_ADDR)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                        + WLAN_REASSOCREQ_OFF_CURR_AP);
     pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCREQ_OFF_CURR_AP + sizeof(*(pFrame->pAddrCurrAP));
 }
 
-
 /*+
  *
  * Routine Description: (AP)
@@ -524,7 +453,6 @@ vMgrEncodeReassocRequest(
  *
 -*/
 
-
 void
 vMgrDecodeReassocRequest(
       PWLAN_FR_REASSOCREQ  pFrame
@@ -534,9 +462,9 @@ vMgrDecodeReassocRequest(
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
     /* Fixed Fields */
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwCapInfo = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_REASSOCREQ_OFF_CAP_INFO);
-    pFrame->pwListenInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwListenInterval = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                       + WLAN_REASSOCREQ_OFF_LISTEN_INT);
     pFrame->pAddrCurrAP = (PIEEE_ADDR)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                        + WLAN_REASSOCREQ_OFF_CURR_AP);
@@ -545,7 +473,7 @@ vMgrDecodeReassocRequest(
     pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                        + WLAN_REASSOCREQ_OFF_SSID);
 
-    while (((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) {
+    while (((u8 *)pItem) < (pFrame->pBuf + pFrame->len)) {
 
         switch (pItem->byElementID) {
         case WLAN_EID_SSID:
@@ -576,12 +504,10 @@ vMgrDecodeReassocRequest(
                         pItem->byElementID);
             break;
         }
-        pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
+        pItem = (PWLAN_IE)(((u8 *)pItem) + 2 + pItem->len);
     }
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -593,7 +519,6 @@ vMgrDecodeReassocRequest(
  *
 -*/
 
-
 void
 vMgrEncodeProbeRequest(
      PWLAN_FR_PROBEREQ  pFrame
@@ -626,7 +551,7 @@ vMgrDecodeProbeRequest(
     /* Information elements */
     pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)));
 
-    while (((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) {
+    while (((u8 *)pItem) < (pFrame->pBuf + pFrame->len)) {
 
         switch (pItem->byElementID) {
         case WLAN_EID_SSID:
@@ -649,11 +574,10 @@ vMgrDecodeProbeRequest(
             break;
         }
 
-        pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 +  pItem->len);
+        pItem = (PWLAN_IE)(((u8 *)pItem) + 2 +  pItem->len);
     }
 }
 
-
 /*+
  *
  * Routine Description:
@@ -665,7 +589,6 @@ vMgrDecodeProbeRequest(
  *
 -*/
 
-
 void
 vMgrEncodeProbeResponse(
      PWLAN_FR_PROBERESP  pFrame
@@ -677,17 +600,15 @@ vMgrEncodeProbeResponse(
        pFrame->pqwTimestamp =
                (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
                        WLAN_PROBERESP_OFF_TS);
-    pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwBeaconInterval = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                        + WLAN_PROBERESP_OFF_BCN_INT);
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwCapInfo = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_PROBERESP_OFF_CAP_INFO);
 
     pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_PROBERESP_OFF_CAP_INFO +
                   sizeof(*(pFrame->pwCapInfo));
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -706,23 +627,22 @@ vMgrDecodeProbeResponse(
 {
     PWLAN_IE    pItem;
 
-
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
        /* Fixed Fields */
        pFrame->pqwTimestamp =
                (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
                        WLAN_PROBERESP_OFF_TS);
-    pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwBeaconInterval = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                        + WLAN_PROBERESP_OFF_BCN_INT);
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwCapInfo = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_PROBERESP_OFF_CAP_INFO);
 
     /* Information elements */
     pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                        + WLAN_PROBERESP_OFF_SSID);
 
-    while (((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) {
+    while (((u8 *)pItem) < (pFrame->pBuf + pFrame->len)) {
         switch (pItem->byElementID) {
         case WLAN_EID_SSID:
             if (pFrame->pSSID == NULL)
@@ -796,11 +716,10 @@ vMgrDecodeProbeResponse(
             break;
         }
 
-        pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 +  pItem->len);
+        pItem = (PWLAN_IE)(((u8 *)pItem) + 2 +  pItem->len);
     }
 }
 
-
 /*+
  *
  * Routine Description:
@@ -820,16 +739,15 @@ vMgrEncodeAuthen(
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
     /* Fixed Fields */
-    pFrame->pwAuthAlgorithm = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwAuthAlgorithm = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                       + WLAN_AUTHEN_OFF_AUTH_ALG);
-    pFrame->pwAuthSequence = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwAuthSequence = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                      + WLAN_AUTHEN_OFF_AUTH_SEQ);
-    pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwStatus = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                + WLAN_AUTHEN_OFF_STATUS);
     pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_AUTHEN_OFF_STATUS + sizeof(*(pFrame->pwStatus));
 }
 
-
 /*+
  *
  * Routine Description:
@@ -851,22 +769,21 @@ vMgrDecodeAuthen(
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
     /* Fixed Fields */
-    pFrame->pwAuthAlgorithm = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwAuthAlgorithm = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                       + WLAN_AUTHEN_OFF_AUTH_ALG);
-    pFrame->pwAuthSequence = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwAuthSequence = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                      + WLAN_AUTHEN_OFF_AUTH_SEQ);
-    pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwStatus = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                + WLAN_AUTHEN_OFF_STATUS);
 
     /* Information elements */
     pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                        + WLAN_AUTHEN_OFF_CHALLENGE);
 
-    if ((((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) && (pItem->byElementID == WLAN_EID_CHALLENGE))
+    if ((((u8 *)pItem) < (pFrame->pBuf + pFrame->len)) && (pItem->byElementID == WLAN_EID_CHALLENGE))
         pFrame->pChallenge = (PWLAN_IE_CHALLENGE)pItem;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -886,12 +803,11 @@ vMgrEncodeDeauthen(
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
     /* Fixed Fields */
-    pFrame->pwReason = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwReason = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                + WLAN_DEAUTHEN_OFF_REASON);
     pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DEAUTHEN_OFF_REASON + sizeof(*(pFrame->pwReason));
 }
 
-
 /*+
  *
  * Routine Description:
@@ -911,11 +827,10 @@ vMgrDecodeDeauthen(
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
     /* Fixed Fields */
-    pFrame->pwReason = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwReason = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                + WLAN_DEAUTHEN_OFF_REASON);
 }
 
-
 /*+
  *
  * Routine Description: (AP)
@@ -935,53 +850,12 @@ vMgrEncodeReassocResponse(
     pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
 
     /* Fixed Fields */
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwCapInfo = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                 + WLAN_REASSOCRESP_OFF_CAP_INFO);
-    pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwStatus = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                                + WLAN_REASSOCRESP_OFF_STATUS);
-    pFrame->pwAid = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
+    pFrame->pwAid = (u16 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
                             + WLAN_REASSOCRESP_OFF_AID);
 
     pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCRESP_OFF_AID + sizeof(*(pFrame->pwAid));
 }
-
-
-/*+
- *
- * Routine Description:
- *   Decode Reassociation Response
- *
- *
- * Return Value:
- *    None.
- *
--*/
-
-
-void
-vMgrDecodeReassocResponse(
-      PWLAN_FR_REASSOCRESP  pFrame
-     )
-{
-    PWLAN_IE   pItem;
-
-    pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
-
-    /* Fixed Fields */
-    pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                + WLAN_REASSOCRESP_OFF_CAP_INFO);
-    pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                               + WLAN_REASSOCRESP_OFF_STATUS);
-    pFrame->pwAid = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                            + WLAN_REASSOCRESP_OFF_AID);
-
-    /* Information elements */
-    pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
-                                               + WLAN_REASSOCRESP_OFF_SUPP_RATES);
-
-    pItem = (PWLAN_IE)(pFrame->pSuppRates);
-    pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
-
-    if ((((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) && (pItem->byElementID == WLAN_EID_EXTSUPP_RATES))
-        pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
-}
index f8e16d8989eac457896742c8cde1998328d38e63..39cde1a0b66c22cbb45e1f04a96fb6c3ffeeeba2 100644 (file)
 #ifndef __80211MGR_H__
 #define __80211MGR_H__
 
-#include "ttype.h"
 #include "80211hdr.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
 #define WLAN_MIN_ARRAY          1
 
 /* Information Element ID value */
 #define MEASURE_MODE_INCAPABLE  0x02
 #define MEASURE_MODE_REFUSED    0x04
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Types  ------------------------------*/
-
 /* Information Element types */
 
 #pragma pack(1)
 typedef struct tagWLAN_IE {
-    BYTE   byElementID;
-    BYTE   len;
+    u8   byElementID;
+    u8   len;
 } __attribute__ ((__packed__))
 WLAN_IE, *PWLAN_IE;
 
 /* Service Set IDentity (SSID) */
 #pragma pack(1)
 typedef struct tagWLAN_IE_SSID {
-    BYTE   byElementID;
-    BYTE   len;
-    BYTE   abySSID[1];
+    u8   byElementID;
+    u8   len;
+    u8   abySSID[1];
 } __attribute__ ((__packed__))
 WLAN_IE_SSID, *PWLAN_IE_SSID;
 
 /* Supported Rates */
 #pragma pack(1)
 typedef struct tagWLAN_IE_SUPP_RATES {
-    BYTE   byElementID;
-    BYTE   len;
-    BYTE   abyRates[1];
+    u8   byElementID;
+    u8   len;
+    u8   abyRates[1];
 } __attribute__ ((__packed__))
 WLAN_IE_SUPP_RATES,  *PWLAN_IE_SUPP_RATES;
 
 /* FH Parameter Set */
 #pragma pack(1)
 typedef struct _WLAN_IE_FH_PARMS {
-    BYTE    byElementID;
-    BYTE    len;
-    WORD    wDwellTime;
-    BYTE    byHopSet;
-    BYTE    byHopPattern;
-    BYTE    byHopIndex;
+    u8    byElementID;
+    u8    len;
+    u16    wDwellTime;
+    u8    byHopSet;
+    u8    byHopPattern;
+    u8    byHopIndex;
 } WLAN_IE_FH_PARMS,  *PWLAN_IE_FH_PARMS;
 
 /* DS Parameter Set */
 #pragma pack(1)
 typedef struct tagWLAN_IE_DS_PARMS {
-    BYTE   byElementID;
-    BYTE   len;
-    BYTE   byCurrChannel;
+    u8   byElementID;
+    u8   len;
+    u8   byCurrChannel;
 } __attribute__ ((__packed__))
 WLAN_IE_DS_PARMS,  *PWLAN_IE_DS_PARMS;
 
 /* CF Parameter Set */
 #pragma pack(1)
 typedef struct tagWLAN_IE_CF_PARMS {
-    BYTE   byElementID;
-    BYTE   len;
-    BYTE   byCFPCount;
-    BYTE   byCFPPeriod;
-    WORD   wCFPMaxDuration;
-    WORD   wCFPDurRemaining;
+    u8   byElementID;
+    u8   len;
+    u8   byCFPCount;
+    u8   byCFPPeriod;
+    u16   wCFPMaxDuration;
+    u16   wCFPDurRemaining;
 } __attribute__ ((__packed__))
 WLAN_IE_CF_PARMS,  *PWLAN_IE_CF_PARMS;
 
 /* TIM */
 #pragma pack(1)
 typedef struct tagWLAN_IE_TIM {
-    BYTE   byElementID;
-    BYTE   len;
-    BYTE   byDTIMCount;
-    BYTE   byDTIMPeriod;
-    BYTE   byBitMapCtl;
-    BYTE   byVirtBitMap[1];
+    u8   byElementID;
+    u8   len;
+    u8   byDTIMCount;
+    u8   byDTIMPeriod;
+    u8   byBitMapCtl;
+    u8   byVirtBitMap[1];
 } __attribute__ ((__packed__))
 WLAN_IE_TIM,  *PWLAN_IE_TIM;
 
 /* IBSS Parameter Set */
 #pragma pack(1)
 typedef struct tagWLAN_IE_IBSS_PARMS {
-    BYTE   byElementID;
-    BYTE   len;
-    WORD   wATIMWindow;
+    u8   byElementID;
+    u8   len;
+    u16   wATIMWindow;
 } __attribute__ ((__packed__))
 WLAN_IE_IBSS_PARMS, *PWLAN_IE_IBSS_PARMS;
 
 /* Challenge Text */
 #pragma pack(1)
 typedef struct tagWLAN_IE_CHALLENGE {
-    BYTE   byElementID;
-    BYTE   len;
-    BYTE   abyChallenge[1];
+    u8   byElementID;
+    u8   len;
+    u8   abyChallenge[1];
 } __attribute__ ((__packed__))
 WLAN_IE_CHALLENGE,  *PWLAN_IE_CHALLENGE;
 
 #pragma pack(1)
 typedef struct tagWLAN_IE_RSN_EXT {
-    BYTE byElementID;
-    BYTE len;
-    BYTE abyOUI[4];
-    WORD wVersion;
-    BYTE abyMulticast[4];
-    WORD wPKCount;
+    u8 byElementID;
+    u8 len;
+    u8 abyOUI[4];
+    u16 wVersion;
+    u8 abyMulticast[4];
+    u16 wPKCount;
        struct {
-               BYTE abyOUI[4];
+               u8 abyOUI[4];
        } PKSList[1];
        /* the rest is variable so need to overlay ieauth structure */
 } WLAN_IE_RSN_EXT, *PWLAN_IE_RSN_EXT;
 
 #pragma pack(1)
 typedef struct tagWLAN_IE_RSN_AUTH {
-    WORD wAuthCount;
+    u16 wAuthCount;
     struct {
-        BYTE abyOUI[4];
+        u8 abyOUI[4];
     } AuthKSList[1];
 } WLAN_IE_RSN_AUTH, *PWLAN_IE_RSN_AUTH;
 
 /* RSN Identity */
 #pragma pack(1)
 typedef struct tagWLAN_IE_RSN {
-    BYTE   byElementID;
-    BYTE   len;
-    WORD   wVersion;
-    BYTE   abyRSN[WLAN_MIN_ARRAY];
+    u8   byElementID;
+    u8   len;
+    u16   wVersion;
+    u8   abyRSN[WLAN_MIN_ARRAY];
 } WLAN_IE_RSN, *PWLAN_IE_RSN;
 
 /* CCX Identity DavidWang */
 #pragma pack(1)
 typedef struct tagWLAN_IE_CCX {
-BYTE   byElementID;
-BYTE   len;
-BYTE   abyCCX[30];
+u8   byElementID;
+u8   len;
+u8   abyCCX[30];
 } WLAN_IE_CCX, *PWLAN_IE_CCX;
 #pragma pack(1)
 typedef struct tagWLAN_IE_CCX_IP {
-BYTE   byElementID;
-BYTE   len;
-BYTE   abyCCXOUI[4];
-BYTE   abyCCXIP[4];
-BYTE   abyCCXREV[2];
+u8   byElementID;
+u8   len;
+u8   abyCCXOUI[4];
+u8   abyCCXIP[4];
+u8   abyCCXREV[2];
 } WLAN_IE_CCX_IP, *PWLAN_IE_CCX_IP;
 #pragma pack(1)
 typedef struct tagWLAN_IE_CCX_Ver {
-BYTE   byElementID;
-BYTE   len;
-BYTE   abyCCXVer[5];
+u8   byElementID;
+u8   len;
+u8   abyCCXVer[5];
 } WLAN_IE_CCX_Ver, *PWLAN_IE_CCX_Ver;
 
 /* ERP */
 #pragma pack(1)
 typedef struct tagWLAN_IE_ERP {
-    BYTE   byElementID;
-    BYTE   len;
-    BYTE   byContext;
+    u8   byElementID;
+    u8   len;
+    u8   byContext;
 } __attribute__ ((__packed__))
 WLAN_IE_ERP,  *PWLAN_IE_ERP;
 
 #pragma pack(1)
 typedef struct _MEASEURE_REQ {
-    BYTE                byChannel;
-    BYTE                abyStartTime[8];
-    BYTE                abyDuration[2];
+    u8                byChannel;
+    u8                abyStartTime[8];
+    u8                abyDuration[2];
 } MEASEURE_REQ, *PMEASEURE_REQ,
   MEASEURE_REQ_BASIC, *PMEASEURE_REQ_BASIC,
   MEASEURE_REQ_CCA, *PMEASEURE_REQ_CCA,
   MEASEURE_REQ_RPI, *PMEASEURE_REQ_RPI;
 
 typedef struct _MEASEURE_REP_BASIC {
-    BYTE                byChannel;
-    BYTE                abyStartTime[8];
-    BYTE                abyDuration[2];
-    BYTE                byMap;
+    u8                byChannel;
+    u8                abyStartTime[8];
+    u8                abyDuration[2];
+    u8                byMap;
 } MEASEURE_REP_BASIC, *PMEASEURE_REP_BASIC;
 
 typedef struct _MEASEURE_REP_CCA {
-    BYTE                byChannel;
-    BYTE                abyStartTime[8];
-    BYTE                abyDuration[2];
-    BYTE                byCCABusyFraction;
+    u8                byChannel;
+    u8                abyStartTime[8];
+    u8                abyDuration[2];
+    u8                byCCABusyFraction;
 } MEASEURE_REP_CCA, *PMEASEURE_REP_CCA;
 
 typedef struct _MEASEURE_REP_RPI {
-    BYTE                byChannel;
-    BYTE                abyStartTime[8];
-    BYTE                abyDuration[2];
-    BYTE                abyRPIdensity[8];
+    u8                byChannel;
+    u8                abyStartTime[8];
+    u8                abyDuration[2];
+    u8                abyRPIdensity[8];
 } MEASEURE_REP_RPI, *PMEASEURE_REP_RPI;
 
 typedef union _MEASEURE_REP {
@@ -410,85 +401,84 @@ typedef union _MEASEURE_REP {
 } MEASEURE_REP, *PMEASEURE_REP;
 
 typedef struct _WLAN_IE_MEASURE_REQ {
-    BYTE                byElementID;
-    BYTE                len;
-    BYTE                byToken;
-    BYTE                byMode;
-    BYTE                byType;
+    u8                byElementID;
+    u8                len;
+    u8                byToken;
+    u8                byMode;
+    u8                byType;
     MEASEURE_REQ        sReq;
 } WLAN_IE_MEASURE_REQ, *PWLAN_IE_MEASURE_REQ;
 
 typedef struct _WLAN_IE_MEASURE_REP {
-    BYTE                byElementID;
-    BYTE                len;
-    BYTE                byToken;
-    BYTE                byMode;
-    BYTE                byType;
+    u8                byElementID;
+    u8                len;
+    u8                byToken;
+    u8                byMode;
+    u8                byType;
     MEASEURE_REP        sRep;
 } WLAN_IE_MEASURE_REP, *PWLAN_IE_MEASURE_REP;
 
 typedef struct _WLAN_IE_CH_SW {
-    BYTE                byElementID;
-    BYTE                len;
-    BYTE                byMode;
-    BYTE                byChannel;
-    BYTE                byCount;
+    u8                byElementID;
+    u8                len;
+    u8                byMode;
+    u8                byChannel;
+    u8                byCount;
 } WLAN_IE_CH_SW, *PWLAN_IE_CH_SW;
 
 typedef struct _WLAN_IE_QUIET {
-    BYTE                byElementID;
-    BYTE                len;
-    BYTE                byQuietCount;
-    BYTE                byQuietPeriod;
-    BYTE                abyQuietDuration[2];
-    BYTE                abyQuietOffset[2];
+    u8                byElementID;
+    u8                len;
+    u8                byQuietCount;
+    u8                byQuietPeriod;
+    u8                abyQuietDuration[2];
+    u8                abyQuietOffset[2];
 } WLAN_IE_QUIET, *PWLAN_IE_QUIET;
 
 typedef struct _WLAN_IE_COUNTRY {
-    BYTE                byElementID;
-    BYTE                len;
-    BYTE                abyCountryString[3];
-    BYTE                abyCountryInfo[3];
+    u8                byElementID;
+    u8                len;
+    u8                abyCountryString[3];
+    u8                abyCountryInfo[3];
 } WLAN_IE_COUNTRY, *PWLAN_IE_COUNTRY;
 
 typedef struct _WLAN_IE_PW_CONST {
-    BYTE                byElementID;
-    BYTE                len;
-    BYTE                byPower;
+    u8                byElementID;
+    u8                len;
+    u8                byPower;
 } WLAN_IE_PW_CONST, *PWLAN_IE_PW_CONST;
 
 typedef struct _WLAN_IE_PW_CAP {
-    BYTE                byElementID;
-    BYTE                len;
-    BYTE                byMinPower;
-    BYTE                byMaxPower;
+    u8                byElementID;
+    u8                len;
+    u8                byMinPower;
+    u8                byMaxPower;
 } WLAN_IE_PW_CAP, *PWLAN_IE_PW_CAP;
 
 typedef struct _WLAN_IE_SUPP_CH {
-    BYTE                byElementID;
-    BYTE                len;
-    BYTE                abyChannelTuple[2];
+    u8                byElementID;
+    u8                len;
+    u8                abyChannelTuple[2];
 } WLAN_IE_SUPP_CH, *PWLAN_IE_SUPP_CH;
 
 typedef struct _WLAN_IE_TPC_REQ {
-    BYTE                byElementID;
-    BYTE                len;
+    u8                byElementID;
+    u8                len;
 } WLAN_IE_TPC_REQ, *PWLAN_IE_TPC_REQ;
 
 typedef struct _WLAN_IE_TPC_REP {
-    BYTE                byElementID;
-    BYTE                len;
-    BYTE                byTxPower;
-    BYTE                byLinkMargin;
+    u8                byElementID;
+    u8                len;
+    u8                byTxPower;
+    u8                byLinkMargin;
 } WLAN_IE_TPC_REP, *PWLAN_IE_TPC_REP;
 
-
 typedef struct _WLAN_IE_IBSS_DFS {
-    BYTE                byElementID;
-    BYTE                len;
-    BYTE                abyDFSOwner[6];
-    BYTE                byDFSRecovery;
-    BYTE                abyChannelMap[2];
+    u8                byElementID;
+    u8                len;
+    u8                abyDFSOwner[6];
+    u8                byDFSRecovery;
+    u8                abyChannelMap[2];
 } WLAN_IE_IBSS_DFS, *PWLAN_IE_IBSS_DFS;
 
 #pragma pack()
@@ -500,7 +490,7 @@ typedef struct tagWLAN_FR_MGMT {
 
     unsigned int                  uType;
     unsigned int                  len;
-    PBYTE                 pBuf;
+    u8 *                 pBuf;
     PUWLAN_80211HDR       pHdr;
 
 } WLAN_FR_MGMT,  *PWLAN_FR_MGMT;
@@ -510,12 +500,12 @@ typedef struct tagWLAN_FR_BEACON {
 
     unsigned int                    uType;
     unsigned int                    len;
-    PBYTE                   pBuf;
+    u8 *                   pBuf;
     PUWLAN_80211HDR         pHdr;
        /* fixed fields */
        u64 *pqwTimestamp;
-    PWORD                   pwBeaconInterval;
-    PWORD                   pwCapInfo;
+    u16 *                   pwBeaconInterval;
+    u16 *                   pwCapInfo;
     /* info elements */
     PWLAN_IE_SSID           pSSID;
     PWLAN_IE_SUPP_RATES     pSuppRates;
@@ -541,7 +531,7 @@ typedef struct tagWLAN_FR_IBSSATIM {
 
     unsigned int                    uType;
     unsigned int                    len;
-    PBYTE                   pBuf;
+    u8 *                   pBuf;
     PUWLAN_80211HDR         pHdr;
 
        /* fixed fields */
@@ -555,10 +545,10 @@ typedef struct tagWLAN_FR_DISASSOC {
 
     unsigned int                    uType;
     unsigned int                    len;
-    PBYTE                   pBuf;
+    u8 *                   pBuf;
     PUWLAN_80211HDR         pHdr;
     /* fixed fields */
-    PWORD                   pwReason;
+    u16 *                   pwReason;
     /* info elements */
 
 } WLAN_FR_DISASSOC, *PWLAN_FR_DISASSOC;
@@ -568,11 +558,11 @@ typedef struct tagWLAN_FR_ASSOCREQ {
 
     unsigned int                    uType;
     unsigned int                    len;
-    PBYTE                   pBuf;
+    u8 *                   pBuf;
     PUWLAN_80211HDR         pHdr;
     /* fixed fields */
-    PWORD                   pwCapInfo;
-    PWORD                   pwListenInterval;
+    u16 *                   pwCapInfo;
+    u16 *                   pwListenInterval;
     /* info elements */
     PWLAN_IE_SSID           pSSID;
     PWLAN_IE_SUPP_RATES     pSuppRates;
@@ -592,12 +582,12 @@ typedef struct tagWLAN_FR_ASSOCRESP {
 
     unsigned int                    uType;
     unsigned int                    len;
-    PBYTE                   pBuf;
+    u8 *                   pBuf;
     PUWLAN_80211HDR         pHdr;
     /* fixed fields */
-    PWORD                   pwCapInfo;
-    PWORD                   pwStatus;
-    PWORD                   pwAid;
+    u16 *                   pwCapInfo;
+    u16 *                   pwStatus;
+    u16 *                   pwAid;
     /* info elements */
     PWLAN_IE_SUPP_RATES     pSuppRates;
     PWLAN_IE_SUPP_RATES     pExtSuppRates;
@@ -609,12 +599,12 @@ typedef struct tagWLAN_FR_REASSOCREQ {
 
     unsigned int                    uType;
     unsigned int                    len;
-    PBYTE                   pBuf;
+    u8 *                   pBuf;
     PUWLAN_80211HDR         pHdr;
 
     /* fixed fields */
-    PWORD                   pwCapInfo;
-    PWORD                   pwListenInterval;
+    u16 *                   pwCapInfo;
+    u16 *                   pwListenInterval;
     PIEEE_ADDR              pAddrCurrAP;
 
     /* info elements */
@@ -634,12 +624,12 @@ typedef struct tagWLAN_FR_REASSOCRESP {
 
     unsigned int                    uType;
     unsigned int                    len;
-    PBYTE                   pBuf;
+    u8 *                   pBuf;
     PUWLAN_80211HDR         pHdr;
     /* fixed fields */
-    PWORD                   pwCapInfo;
-    PWORD                   pwStatus;
-    PWORD                   pwAid;
+    u16 *                   pwCapInfo;
+    u16 *                   pwStatus;
+    u16 *                   pwAid;
     /* info elements */
     PWLAN_IE_SUPP_RATES     pSuppRates;
     PWLAN_IE_SUPP_RATES     pExtSuppRates;
@@ -651,7 +641,7 @@ typedef struct tagWLAN_FR_PROBEREQ {
 
     unsigned int                    uType;
     unsigned int                    len;
-    PBYTE                   pBuf;
+    u8 *                   pBuf;
     PUWLAN_80211HDR         pHdr;
     /* fixed fields */
     /* info elements */
@@ -666,12 +656,12 @@ typedef struct tagWLAN_FR_PROBERESP {
 
     unsigned int                    uType;
     unsigned int                    len;
-    PBYTE                   pBuf;
+    u8 *                   pBuf;
     PUWLAN_80211HDR         pHdr;
     /* fixed fields */
        u64 *pqwTimestamp;
-    PWORD                   pwBeaconInterval;
-    PWORD                   pwCapInfo;
+    u16 *                   pwBeaconInterval;
+    u16 *                   pwCapInfo;
     /* info elements */
     PWLAN_IE_SSID           pSSID;
     PWLAN_IE_SUPP_RATES     pSuppRates;
@@ -695,12 +685,12 @@ typedef struct tagWLAN_FR_AUTHEN {
 
     unsigned int                    uType;
     unsigned int                    len;
-    PBYTE                   pBuf;
+    u8 *                   pBuf;
     PUWLAN_80211HDR         pHdr;
     /* fixed fields */
-    PWORD                   pwAuthAlgorithm;
-    PWORD                   pwAuthSequence;
-    PWORD                   pwStatus;
+    u16 *                   pwAuthAlgorithm;
+    u16 *                   pwAuthSequence;
+    u16 *                   pwStatus;
     /* info elements */
     PWLAN_IE_CHALLENGE      pChallenge;
 
@@ -711,17 +701,15 @@ typedef struct tagWLAN_FR_DEAUTHEN {
 
     unsigned int                    uType;
     unsigned int                    len;
-    PBYTE                   pBuf;
+    u8 *                   pBuf;
     PUWLAN_80211HDR         pHdr;
     /* fixed fields */
-    PWORD                   pwReason;
+    u16 *                   pwReason;
 
     /* info elements */
 
 } WLAN_FR_DEAUTHEN, *PWLAN_FR_DEAUTHEN;
 
-/*---------------------  Export Functions  --------------------------*/
-
 void
 vMgrEncodeBeacon(
       PWLAN_FR_BEACON  pFrame
@@ -732,16 +720,6 @@ vMgrDecodeBeacon(
       PWLAN_FR_BEACON  pFrame
     );
 
-void
-vMgrEncodeIBSSATIM(
-      PWLAN_FR_IBSSATIM   pFrame
-    );
-
-void
-vMgrDecodeIBSSATIM(
-      PWLAN_FR_IBSSATIM   pFrame
-    );
-
 void
 vMgrEncodeDisassociation(
       PWLAN_FR_DISASSOC  pFrame
@@ -827,9 +805,4 @@ vMgrEncodeReassocResponse(
       PWLAN_FR_REASSOCRESP  pFrame
     );
 
-void
-vMgrDecodeReassocResponse(
-      PWLAN_FR_REASSOCRESP  pFrame
-    );
-
 #endif /* __80211MGR_H__ */
index a318995ba07f471032d46885e0303fdf66e94d50..e154b2f3b247845a3e428f62a5533b36de51a9fc 100644 (file)
@@ -7,7 +7,7 @@ TODO:
   - split rf.c
   - abstract VT3184 chipset specific code
 - add common vt665x infrastructure
-- kill ttype.h
+- kill ttype.h -- done
 - switch to use LIB80211
 - switch to use MAC80211
 - use kernel coding style
index fb6124d9082a76676600d0d28e18d6dc37f789b0..28a4c4c30416cc7fb699a6d593216d3d1a3a8839 100644 (file)
 #include "device.h"
 #include "80211hdr.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
 /*
  * SBOX Table
  */
 
-BYTE sbox_table[256] = {
+u8 sbox_table[256] = {
        0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
        0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
        0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
@@ -62,7 +56,7 @@ BYTE sbox_table[256] = {
        0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
 };
 
-BYTE dot2_table[256] = {
+u8 dot2_table[256] = {
        0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
        0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e,
        0x40, 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e,
@@ -81,7 +75,7 @@ BYTE dot2_table[256] = {
        0xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, 0xf5, 0xeb, 0xe9, 0xef, 0xed, 0xe3, 0xe1, 0xe7, 0xe5
 };
 
-BYTE dot3_table[256] = {
+u8 dot3_table[256] = {
        0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x18, 0x1b, 0x1e, 0x1d, 0x14, 0x17, 0x12, 0x11,
        0x30, 0x33, 0x36, 0x35, 0x3c, 0x3f, 0x3a, 0x39, 0x28, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21,
        0x60, 0x63, 0x66, 0x65, 0x6c, 0x6f, 0x6a, 0x69, 0x78, 0x7b, 0x7e, 0x7d, 0x74, 0x77, 0x72, 0x71,
@@ -100,17 +94,11 @@ BYTE dot3_table[256] = {
        0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a
 };
 
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
-static void xor_128(BYTE *a, BYTE *b, BYTE *out)
+static void xor_128(u8 *a, u8 *b, u8 *out)
 {
-       PDWORD dwPtrA = (PDWORD) a;
-       PDWORD dwPtrB = (PDWORD) b;
-       PDWORD dwPtrOut = (PDWORD) out;
+       u32 * dwPtrA = (u32 *) a;
+       u32 * dwPtrB = (u32 *) b;
+       u32 * dwPtrOut = (u32 *) out;
 
        (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
        (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
@@ -118,20 +106,19 @@ static void xor_128(BYTE *a, BYTE *b, BYTE *out)
        (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
 }
 
-
-static void xor_32(BYTE *a, BYTE *b, BYTE *out)
+static void xor_32(u8 *a, u8 *b, u8 *out)
 {
-       PDWORD dwPtrA = (PDWORD) a;
-       PDWORD dwPtrB = (PDWORD) b;
-       PDWORD dwPtrOut = (PDWORD) out;
+       u32 * dwPtrA = (u32 *) a;
+       u32 * dwPtrB = (u32 *) b;
+       u32 * dwPtrOut = (u32 *) out;
 
        (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
 }
 
-void AddRoundKey(BYTE *key, int round)
+void AddRoundKey(u8 *key, int round)
 {
-       BYTE sbox_key[4];
-       BYTE rcon_table[10] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36};
+       u8 sbox_key[4];
+       u8 rcon_table[10] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36};
 
        sbox_key[0] = sbox_table[key[13]];
        sbox_key[1] = sbox_table[key[14]];
@@ -146,7 +133,7 @@ void AddRoundKey(BYTE *key, int round)
        xor_32(&key[12], &key[8], &key[12]);
 }
 
-void SubBytes(BYTE *in, BYTE *out)
+void SubBytes(u8 *in, u8 *out)
 {
        int i;
 
@@ -154,7 +141,7 @@ void SubBytes(BYTE *in, BYTE *out)
                out[i] = sbox_table[in[i]];
 }
 
-void ShiftRows(BYTE *in, BYTE *out)
+void ShiftRows(u8 *in, u8 *out)
 {
        out[0]  = in[0];
        out[1]  = in[5];
@@ -174,7 +161,7 @@ void ShiftRows(BYTE *in, BYTE *out)
        out[15] = in[11];
 }
 
-void MixColumns(BYTE *in, BYTE *out)
+void MixColumns(u8 *in, u8 *out)
 {
 
        out[0] = dot2_table[in[0]] ^ dot3_table[in[1]] ^ in[2] ^ in[3];
@@ -183,13 +170,13 @@ void MixColumns(BYTE *in, BYTE *out)
        out[3] = dot3_table[in[0]] ^ in[1] ^ in[2] ^ dot2_table[in[3]];
 }
 
-void AESv128(BYTE *key, BYTE *data, BYTE *ciphertext)
+void AESv128(u8 *key, u8 *data, u8 *ciphertext)
 {
        int  i;
        int  round;
-       BYTE TmpdataA[16];
-       BYTE TmpdataB[16];
-       BYTE abyRoundKey[16];
+       u8 TmpdataA[16];
+       u8 TmpdataB[16];
+       u8 abyRoundKey[16];
 
        for (i = 0; i < 16; i++)
                abyRoundKey[i] = key[i];
@@ -231,32 +218,32 @@ void AESv128(BYTE *key, BYTE *data, BYTE *ciphertext)
  *
  */
 
-bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize)
+bool AESbGenCCMP(u8 * pbyRxKey, u8 * pbyFrame, u16 wFrameSize)
 {
-       BYTE            abyNonce[13];
-       BYTE            MIC_IV[16];
-       BYTE            MIC_HDR1[16];
-       BYTE            MIC_HDR2[16];
-       BYTE            abyMIC[16];
-       BYTE            abyCTRPLD[16];
-       BYTE            abyTmp[16];
-       BYTE            abyPlainText[16];
-       BYTE            abyLastCipher[16];
-
-       PS802_11Header  pMACHeader = (PS802_11Header) pbyFrame;
-       PBYTE           pbyIV;
-       PBYTE           pbyPayload;
-       WORD            wHLen = 22;
+       u8            abyNonce[13];
+       u8            MIC_IV[16];
+       u8            MIC_HDR1[16];
+       u8            MIC_HDR2[16];
+       u8            abyMIC[16];
+       u8            abyCTRPLD[16];
+       u8            abyTmp[16];
+       u8            abyPlainText[16];
+       u8            abyLastCipher[16];
+
+       struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *) pbyFrame;
+       u8 *           pbyIV;
+       u8 *           pbyPayload;
+       u16            wHLen = 22;
        /* 8 is IV, 8 is MIC, 4 is CRC */
-       WORD            wPayloadSize = wFrameSize - 8 - 8 - 4 - WLAN_HDR_ADDR3_LEN;
+       u16            wPayloadSize = wFrameSize - 8 - 8 - 4 - WLAN_HDR_ADDR3_LEN;
        bool            bA4 = false;
-       BYTE            byTmp;
-       WORD            wCnt;
+       u8            byTmp;
+       u16            wCnt;
        int             ii, jj, kk;
 
        pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
-       if (WLAN_GET_FC_TODS(*(PWORD) pbyFrame) &&
-           WLAN_GET_FC_FROMDS(*(PWORD) pbyFrame)) {
+       if (WLAN_GET_FC_TODS(*(u16 *) pbyFrame) &&
+           WLAN_GET_FC_FROMDS(*(u16 *) pbyFrame)) {
                bA4 = true;
                pbyIV += 6;             /* 6 is 802.11 address4 */
                wHLen += 6;
@@ -265,7 +252,7 @@ bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize)
        pbyPayload = pbyIV + 8; /* IV-length */
 
        abyNonce[0]  = 0x00; /* now is 0, if Qos here will be priority */
-       memcpy(&(abyNonce[1]), pMACHeader->abyAddr2, ETH_ALEN);
+       memcpy(&(abyNonce[1]), pMACHeader->addr2, ETH_ALEN);
        abyNonce[7]  = pbyIV[7];
        abyNonce[8]  = pbyIV[6];
        abyNonce[9]  = pbyIV[5];
@@ -276,28 +263,28 @@ bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize)
        /* MIC_IV */
        MIC_IV[0] = 0x59;
        memcpy(&(MIC_IV[1]), &(abyNonce[0]), 13);
-       MIC_IV[14] = (BYTE)(wPayloadSize >> 8);
-       MIC_IV[15] = (BYTE)(wPayloadSize & 0xff);
+       MIC_IV[14] = (u8)(wPayloadSize >> 8);
+       MIC_IV[15] = (u8)(wPayloadSize & 0xff);
 
        /* MIC_HDR1 */
-       MIC_HDR1[0] = (BYTE)(wHLen >> 8);
-       MIC_HDR1[1] = (BYTE)(wHLen & 0xff);
-       byTmp = (BYTE)(pMACHeader->wFrameCtl & 0xff);
+       MIC_HDR1[0] = (u8)(wHLen >> 8);
+       MIC_HDR1[1] = (u8)(wHLen & 0xff);
+       byTmp = (u8)(pMACHeader->frame_control & 0xff);
        MIC_HDR1[2] = byTmp & 0x8f;
-       byTmp = (BYTE)(pMACHeader->wFrameCtl >> 8);
+       byTmp = (u8)(pMACHeader->frame_control >> 8);
        byTmp &= 0x87;
        MIC_HDR1[3] = byTmp | 0x40;
-       memcpy(&(MIC_HDR1[4]), pMACHeader->abyAddr1, ETH_ALEN);
-       memcpy(&(MIC_HDR1[10]), pMACHeader->abyAddr2, ETH_ALEN);
+       memcpy(&(MIC_HDR1[4]), pMACHeader->addr1, ETH_ALEN);
+       memcpy(&(MIC_HDR1[10]), pMACHeader->addr2, ETH_ALEN);
 
        /* MIC_HDR2 */
-       memcpy(&(MIC_HDR2[0]), pMACHeader->abyAddr3, ETH_ALEN);
-       byTmp = (BYTE)(pMACHeader->wSeqCtl & 0xff);
+       memcpy(&(MIC_HDR2[0]), pMACHeader->addr3, ETH_ALEN);
+       byTmp = (u8)(pMACHeader->seq_ctrl & 0xff);
        MIC_HDR2[6] = byTmp & 0x0f;
        MIC_HDR2[7] = 0;
 
        if (bA4) {
-               memcpy(&(MIC_HDR2[8]), pMACHeader->abyAddr4, ETH_ALEN);
+               memcpy(&(MIC_HDR2[8]), pMACHeader->addr4, ETH_ALEN);
        } else {
                MIC_HDR2[8]  = 0x00;
                MIC_HDR2[9]  = 0x00;
@@ -326,8 +313,8 @@ bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize)
 
        for (jj = wPayloadSize; jj > 16; jj = jj-16) {
 
-               abyCTRPLD[14] = (BYTE) (wCnt >> 8);
-               abyCTRPLD[15] = (BYTE) (wCnt & 0xff);
+               abyCTRPLD[14] = (u8) (wCnt >> 8);
+               abyCTRPLD[15] = (u8) (wCnt & 0xff);
 
                AESv128(pbyRxKey, abyCTRPLD, abyTmp);
 
@@ -349,8 +336,8 @@ bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize)
        for (ii = jj; ii < 16; ii++)
                abyLastCipher[ii] = 0x00;
 
-       abyCTRPLD[14] = (BYTE) (wCnt >> 8);
-       abyCTRPLD[15] = (BYTE) (wCnt & 0xff);
+       abyCTRPLD[14] = (u8) (wCnt >> 8);
+       abyCTRPLD[15] = (u8) (wCnt & 0xff);
 
        AESv128(pbyRxKey, abyCTRPLD, abyTmp);
        for (kk = 0; kk < 16; kk++)
@@ -370,8 +357,8 @@ bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize)
        /* => above is the calculated MIC */
 
        wCnt = 0;
-       abyCTRPLD[14] = (BYTE) (wCnt >> 8);
-       abyCTRPLD[15] = (BYTE) (wCnt & 0xff);
+       abyCTRPLD[14] = (u8) (wCnt >> 8);
+       abyCTRPLD[15] = (u8) (wCnt & 0xff);
        AESv128(pbyRxKey, abyCTRPLD, abyTmp);
 
        for (kk = 0; kk < 8; kk++)
index a2e2c4e9a5c9a3debfe3eaccdec0c859cd539caf..ed6a9ae315de6d851921464a49b81545cebeda77 100644 (file)
 #ifndef __AES_H__
 #define __AES_H__
 
-#include "ttype.h"
-
-/*---------------------  Export Definitions -------------------------*/
-
-/*---------------------  Export Types  ------------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize);
+bool AESbGenCCMP(u8 * pbyRxKey, u8 * pbyFrame, u16 wFrameSize);
 
 #endif /* __AES_CCMP_H__ */
index a9f525e9d16ebc95a4be6079b0bc6ae0f50df042..33fa76759bf172a7b46047bc0ab7acea3bf83909 100644 (file)
@@ -29,8 +29,6 @@
  *      BBuGetFrameTime        - Calculate data frame transmitting time
  *      BBvCalculateParameter   - Calculate PhyLength, PhyService and Phy Signal parameter for baseband Tx
  *      BBbVT3184Init          - VIA VT3184 baseband chip init code
- *      BBvLoopbackOn          - Turn on BaseBand Loopback mode
- *      BBvLoopbackOff         - Turn off BaseBand Loopback mode
  *
  * Revision History:
  *
 #include "datarate.h"
 #include "rndis.h"
 
-/*---------------------  Static Definitions -------------------------*/
 static int          msglevel                =MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-
-BYTE abyVT3184_AGC[] = {
+u8 abyVT3184_AGC[] = {
     0x00,   //0
     0x00,   //1
     0x02,   //2
@@ -133,8 +115,7 @@ BYTE abyVT3184_AGC[] = {
     0x3E    //3F
 };
 
-
-BYTE abyVT3184_AL2230[] = {
+u8 abyVT3184_AL2230[] = {
         0x31,//00
         0x00,
         0x00,
@@ -393,10 +374,8 @@ BYTE abyVT3184_AL2230[] = {
         0x00
 };
 
-
-
 //{{RobertYu:20060515, new BB setting for VT3226D0
-BYTE abyVT3184_VT3226D0[] = {
+u8 abyVT3184_VT3226D0[] = {
         0x31,//00
         0x00,
         0x00,
@@ -655,11 +634,9 @@ BYTE abyVT3184_VT3226D0[] = {
         0x00,
 };
 
-const WORD awcFrameTime[MAX_RATE] =
+const u16 awcFrameTime[MAX_RATE] =
 {10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216};
 
-/*---------------------  Static Functions  --------------------------*/
-
 /*
 static
 unsigned long
@@ -674,7 +651,6 @@ void
 s_vClearSQ3Value(PSDevice pDevice);
 */
 
-/*---------------------  Export Variables  --------------------------*/
 /*
  * Description: Calculate data frame transmitting time
  *
@@ -691,10 +667,10 @@ s_vClearSQ3Value(PSDevice pDevice);
  */
 unsigned int
 BBuGetFrameTime(
-     BYTE byPreambleType,
-     BYTE byPktType,
+     u8 byPreambleType,
+     u8 byPktType,
      unsigned int cbFrameLength,
-     WORD wRate
+     u16 wRate
     )
 {
     unsigned int uFrameTime;
@@ -703,7 +679,6 @@ BBuGetFrameTime(
     unsigned int uRateIdx = (unsigned int)wRate;
     unsigned int uRate = 0;
 
-
     if (uRateIdx > RATE_54M) {
         ASSERT(0);
         return 0;
@@ -900,15 +875,14 @@ void BBvCalculateParameter(struct vnt_private *pDevice, u32 cbFrameLength,
         *pbyPhySrv = 0x00;
         if (bExtBit)
             *pbyPhySrv = *pbyPhySrv | 0x80;
-        *pwPhyLen = (WORD) cbUsCount;
+        *pwPhyLen = (u16) cbUsCount;
     }
     else {
         *pbyPhySrv = 0x00;
-        *pwPhyLen = (WORD)cbFrameLength;
+        *pwPhyLen = (u16)cbFrameLength;
     }
 }
 
-
 /*
  * Description: Set Antenna mode
  *
@@ -937,10 +911,9 @@ void BBvSetAntennaMode(struct vnt_private *pDevice, u8 byAntennaMode)
             break;
     }
 
-
     CONTROLnsRequestOut(pDevice,
                     MESSAGE_TYPE_SET_ANTMD,
-                    (WORD) byAntennaMode,
+                    (u16) byAntennaMode,
                     0,
                     0,
                     NULL);
@@ -963,11 +936,11 @@ void BBvSetAntennaMode(struct vnt_private *pDevice, u8 byAntennaMode)
 int BBbVT3184Init(struct vnt_private *pDevice)
 {
        int ntStatus;
-    WORD                    wLength;
-    PBYTE                   pbyAddr;
-    PBYTE                   pbyAgc;
-    WORD                    wLengthAgc;
-    BYTE                    abyArray[256];
+    u16                    wLength;
+    u8 *                   pbyAddr;
+    u8 *                   pbyAgc;
+    u16                    wLengthAgc;
+    u8                    abyArray[256];
 
     ntStatus = CONTROLnsRequestIn(pDevice,
                                   MESSAGE_TYPE_READ,
@@ -979,7 +952,6 @@ int BBbVT3184Init(struct vnt_private *pDevice)
         return false;
     }
 
-
 //    if ((pDevice->abyEEPROM[EEP_OFS_RADIOCTL]&0x06)==0x04)
 //        return false;
 
@@ -1118,7 +1090,6 @@ else {
                     abyArray
                     );
 
-
     if ((pDevice->byRFType == RF_VT3226) || //RobertYu:20051116, 20060111 remove VT3226D0
          (pDevice->byRFType == RF_VT3342A0)  //RobertYu:20060609
          ) {
@@ -1131,7 +1102,6 @@ else {
         MACvRegBitsOn(pDevice,MAC_REG_PAPEDELAY,0x01);
     }
 
-
     ControlvWriteByte(pDevice,MESSAGE_REQUEST_BBREG,0x04,0x7F);
     ControlvWriteByte(pDevice,MESSAGE_REQUEST_BBREG,0x0D,0x01);
 
@@ -1139,96 +1109,6 @@ else {
     return true;//ntStatus;
 }
 
-
-/*
- * Description: Turn on BaseBand Loopback mode
- *
- * Parameters:
- *  In:
- *      pDevice         - Device Structure
- *
- *  Out:
- *      none
- *
- * Return Value: none
- *
- */
-void BBvLoopbackOn(struct vnt_private *pDevice)
-{
-    BYTE      byData;
-
-    //CR C9 = 0x00
-    ControlvReadByte (pDevice, MESSAGE_REQUEST_BBREG, 0xC9, &pDevice->byBBCRc9);//CR201
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xC9, 0);
-    ControlvReadByte (pDevice, MESSAGE_REQUEST_BBREG, 0x4D, &pDevice->byBBCR4d);//CR77
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x4D, 0x90);
-
-    //CR 88 = 0x02(CCK), 0x03(OFDM)
-    ControlvReadByte (pDevice, MESSAGE_REQUEST_BBREG, 0x88, &pDevice->byBBCR88);//CR136
-
-    if (pDevice->wCurrentRate <= RATE_11M) { //CCK
-        // Enable internal digital loopback: CR33 |= 0000 0001
-        ControlvReadByte (pDevice, MESSAGE_REQUEST_BBREG, 0x21, &byData);//CR33
-        ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x21, (BYTE)(byData | 0x01));//CR33
-        // CR154 = 0x00
-        ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x9A, 0);   //CR154
-
-        ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x02);//CR239
-    }
-    else { //OFDM
-        // Enable internal digital loopback:CR154 |= 0000 0001
-        ControlvReadByte (pDevice, MESSAGE_REQUEST_BBREG, 0x9A, &byData);//CR154
-        ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x9A, (BYTE)(byData | 0x01));//CR154
-        // CR33 = 0x00
-        ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x21, 0);   //CR33
-
-        ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, 0x03);//CR239
-    }
-
-    //CR14 = 0x00
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0E, 0);//CR14
-
-    // Disable TX_IQUN
-    ControlvReadByte (pDevice, MESSAGE_REQUEST_BBREG, 0x09, &pDevice->byBBCR09);
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x09, (BYTE)(pDevice->byBBCR09 & 0xDE));
-}
-
-/*
- * Description: Turn off BaseBand Loopback mode
- *
- * Parameters:
- *  In:
- *      pDevice         - Device Structure
- *
- *  Out:
- *      none
- *
- * Return Value: none
- *
- */
-void BBvLoopbackOff(struct vnt_private *pDevice)
-{
-       u8 byData;
-
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xC9, pDevice->byBBCRc9);//CR201
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, pDevice->byBBCR88);//CR136
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x09, pDevice->byBBCR09);//CR136
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x4D, pDevice->byBBCR4d);//CR77
-
-    if (pDevice->wCurrentRate <= RATE_11M) { // CCK
-        // Set the CR33 Bit2 to disable internal Loopback.
-        ControlvReadByte (pDevice, MESSAGE_REQUEST_BBREG, 0x21, &byData);//CR33
-        ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x21, (BYTE)(byData & 0xFE));//CR33
-       } else { /* OFDM */
-        ControlvReadByte (pDevice, MESSAGE_REQUEST_BBREG, 0x9A, &byData);//CR154
-        ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x9A, (BYTE)(byData & 0xFE));//CR154
-    }
-    ControlvReadByte (pDevice, MESSAGE_REQUEST_BBREG, 0x0E, &byData);//CR14
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0E, (BYTE)(byData | 0x80));//CR14
-
-}
-
-
 /*
  * Description: Set ShortSlotTime mode
  *
@@ -1243,7 +1123,7 @@ void BBvLoopbackOff(struct vnt_private *pDevice)
  */
 void BBvSetShortSlotTime(struct vnt_private *pDevice)
 {
-    BYTE byBBVGA=0;
+    u8 byBBVGA=0;
 
        if (pDevice->bShortSlotTime)
         pDevice->byBBRxConf &= 0xDF;//1101 1111
@@ -1257,8 +1137,7 @@ void BBvSetShortSlotTime(struct vnt_private *pDevice)
     ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0A, pDevice->byBBRxConf);
 }
 
-
-void BBvSetVGAGainOffset(struct vnt_private *pDevice, BYTE byData)
+void BBvSetVGAGainOffset(struct vnt_private *pDevice, u8 byData)
 {
 
     ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, byData);
@@ -1272,27 +1151,6 @@ void BBvSetVGAGainOffset(struct vnt_private *pDevice, BYTE byData)
     ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0A, pDevice->byBBRxConf);//CR10
 }
 
-
-/*
- * Description: Baseband SoftwareReset
- *
- * Parameters:
- *  In:
- *      dwIoBase    - I/O base address
- *  Out:
- *      none
- *
- * Return Value: none
- *
- */
-void BBvSoftwareReset(struct vnt_private *pDevice)
-{
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x50, 0x40);
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x50, 0);
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x9C, 0x01);
-    ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x9C, 0);
-}
-
 /*
  * Description: BBvSetDeepSleep
  *
@@ -1317,7 +1175,6 @@ void BBvExitDeepSleep(struct vnt_private *pDevice)
     ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0D, 0x01);//CR13
 }
 
-
 static unsigned long s_ulGetLowSQ3(struct vnt_private *pDevice)
 {
        int ii;
@@ -1364,7 +1221,6 @@ static unsigned long s_ulGetRatio(struct vnt_private *pDevice)
     return ulRatio;
 }
 
-
 static void s_vClearSQ3Value(struct vnt_private *pDevice)
 {
     int ii;
@@ -1376,7 +1232,6 @@ static void s_vClearSQ3Value(struct vnt_private *pDevice)
     }
 }
 
-
 /*
  * Description: Antenna Diversity
  *
@@ -1508,7 +1363,6 @@ void BBvAntennaDiversity(struct vnt_private *pDevice,
     } //byAntennaState
 }
 
-
 /*+
  *
  * Description:
@@ -1541,11 +1395,9 @@ void TimerSQ3CallBack(struct vnt_private *pDevice)
     add_timer(&pDevice->TimerSQ3Tmax3);
     add_timer(&pDevice->TimerSQ3Tmax2);
 
-
     spin_unlock_irq(&pDevice->lock);
 }
 
-
 /*+
  *
  * Description:
@@ -1594,7 +1446,6 @@ void TimerSQ3Tmax3CallBack(struct vnt_private *pDevice)
 void BBvUpdatePreEDThreshold(struct vnt_private *pDevice, int bScanning)
 {
 
-
     switch(pDevice->byRFType)
     {
         case RF_AL2230:
index fba61605a692f66bdd8941cd962c39b3e7b29ec4..0a634adabf0efb2d416d72b8caab1cd224103268 100644 (file)
 #ifndef __BASEBAND_H__
 #define __BASEBAND_H__
 
-#include "ttype.h"
 #include "tether.h"
 #include "device.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
 #define PREAMBLE_LONG   0
 #define PREAMBLE_SHORT  1
 
 #define TOP_RATE_2M         0x00200000
 #define TOP_RATE_1M         0x00100000
 
-
-/*---------------------  Export Types  ------------------------------*/
-
-/*---------------------  Export Macros ------------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 unsigned int
 BBuGetFrameTime(
-     BYTE byPreambleType,
-     BYTE byFreqType,
+     u8 byPreambleType,
+     u8 byFreqType,
      unsigned int cbFrameLength,
-     WORD wRate
+     u16 wRate
     );
 
 void BBvCalculateParameter(struct vnt_private *, u32 cbFrameLength,
@@ -113,9 +99,6 @@ void TimerSQ3CallBack(struct vnt_private *);
 void TimerSQ3Tmax3CallBack(struct vnt_private *);
 
 void BBvAntennaDiversity(struct vnt_private *, u8 byRxRate, u8 bySQ3);
-void BBvLoopbackOn(struct vnt_private *);
-void BBvLoopbackOff(struct vnt_private *);
-void BBvSoftwareReset(struct vnt_private *);
 
 void BBvSetShortSlotTime(struct vnt_private *);
 void BBvSetVGAGainOffset(struct vnt_private *, u8 byData);
index e214fcf838687b62a9faf97a9e786d45c946b859..ee79bbdf1a06ad0e48c23a24ba48f40be1d2778e 100644 (file)
@@ -39,7 +39,6 @@
  *
  */
 
-#include "ttype.h"
 #include "tmacro.h"
 #include "tether.h"
 #include "device.h"
 #include "rndis.h"
 #include "iowpa.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-
-
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
 static int          msglevel                =MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 
-
-
-const WORD             awHWRetry0[5][5] = {
+const u16             awHWRetry0[5][5] = {
                                             {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
                                             {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
                                             {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
                                             {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
                                             {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
                                            };
-const WORD             awHWRetry1[5][5] = {
+const u16             awHWRetry1[5][5] = {
                                             {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
                                             {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
                                             {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
@@ -87,23 +76,10 @@ const WORD             awHWRetry1[5][5] = {
                                             {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
                                            };
 
-
-
-/*---------------------  Static Functions  --------------------------*/
-
 static void s_vCheckSensitivity(struct vnt_private *pDevice);
 static void s_vCheckPreEDThreshold(struct vnt_private *pDevice);
 static void s_uCalculateLinkQual(struct vnt_private *pDevice);
 
-/*---------------------  Export Variables  --------------------------*/
-
-
-/*---------------------  Export Functions  --------------------------*/
-
-
-
-
-
 /*+
  *
  * Routine Description:
@@ -221,7 +197,6 @@ PKnownBSS BSSpSearchBSSList(struct vnt_private *pDevice,
                        pCurrBSS->abyBSSID);
         jj++;
 
-
                 if (pSelect == NULL) {
                     pSelect = pCurrBSS;
                 } else {
@@ -249,7 +224,6 @@ pDevice->bSameBSSMaxNum = jj;
 
 }
 
-
 /*+
  *
  * Routine Description:
@@ -260,7 +234,6 @@ pDevice->bSameBSSMaxNum = jj;
  *
 -*/
 
-
 void BSSvClearBSSList(struct vnt_private *pDevice, int bKeepCurrBSSID)
 {
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
@@ -285,8 +258,6 @@ void BSSvClearBSSList(struct vnt_private *pDevice, int bKeepCurrBSSID)
     BSSvClearAnyBSSJoinRecord(pDevice);
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -320,8 +291,6 @@ PKnownBSS BSSpAddrIsInBSSList(struct vnt_private *pDevice,
     return NULL;
 };
 
-
-
 /*+
  *
  * Routine Description:
@@ -357,7 +326,6 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice,
        unsigned int ii;
        bool bParsingQuiet = false;
 
-
     pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
 
     for (ii = 0; ii < MAX_BSS_NUM; ii++) {
@@ -430,7 +398,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice,
        unsigned int uLen = pRSNWPA->len + 2;
 
        if (uLen <= (uIELength -
-                    (unsigned int) (ULONG_PTR) ((PBYTE) pRSNWPA - pbyIEs))) {
+                    (unsigned int) (u32) ((u8 *) pRSNWPA - pbyIEs))) {
                pBSSList->wWPALen = uLen;
                memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
                WPA_ParseRSN(pBSSList, pRSNWPA);
@@ -443,7 +411,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice,
        unsigned int uLen = pRSN->len + 2;
 
        if (uLen <= (uIELength -
-                    (unsigned int) (ULONG_PTR) ((PBYTE) pRSN - pbyIEs))) {
+                    (unsigned int) (u32) ((u8 *) pRSN - pbyIEs))) {
                pBSSList->wRSNLen = uLen;
                memcpy(pBSSList->byRSNIE, pRSN, uLen);
                WPA2vParseRSN(pBSSList, pRSN);
@@ -483,7 +451,7 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice,
     if (pDevice->bUpdateBBVGA) {
         // Monitor if RSSI is too strong.
         pBSSList->byRSSIStatCnt = 0;
-        RFvRSSITodBm(pDevice, (BYTE)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
+        RFvRSSITodBm(pDevice, (u8)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
         pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
         pBSSList->ldBmAverRange = pBSSList->ldBmMAX;
         for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
@@ -498,7 +466,6 @@ int BSSbInsertToBSSList(struct vnt_private *pDevice,
     return true;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -539,7 +506,6 @@ int BSSbUpdateToBSSList(struct vnt_private *pDevice,
     if (pBSSList == NULL)
         return false;
 
-
        pBSSList->qwBSSTimestamp = cpu_to_le64(qwTimestamp);
 
     pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
@@ -592,7 +558,7 @@ int BSSbUpdateToBSSList(struct vnt_private *pDevice,
    if (pRSNWPA != NULL) {
        unsigned int uLen = pRSNWPA->len + 2;
        if (uLen <= (uIELength -
-                    (unsigned int) (ULONG_PTR) ((PBYTE) pRSNWPA - pbyIEs))) {
+                    (unsigned int) (u32) ((u8 *) pRSNWPA - pbyIEs))) {
                pBSSList->wWPALen = uLen;
                memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
                WPA_ParseRSN(pBSSList, pRSNWPA);
@@ -604,7 +570,7 @@ int BSSbUpdateToBSSList(struct vnt_private *pDevice,
     if (pRSN != NULL) {
        unsigned int uLen = pRSN->len + 2;
        if (uLen <= (uIELength -
-                       (unsigned int) (ULONG_PTR) ((PBYTE) pRSN - pbyIEs))) {
+                       (unsigned int) (u32) ((u8 *) pRSN - pbyIEs))) {
                pBSSList->wRSNLen = uLen;
                memcpy(pBSSList->byRSNIE, pRSN, uLen);
                WPA2vParseRSN(pBSSList, pRSN);
@@ -612,7 +578,7 @@ int BSSbUpdateToBSSList(struct vnt_private *pDevice,
     }
 
     if (pRxPacket->uRSSI != 0) {
-        RFvRSSITodBm(pDevice, (BYTE)(pRxPacket->uRSSI), &ldBm);
+        RFvRSSITodBm(pDevice, (u8)(pRxPacket->uRSSI), &ldBm);
         // Monitor if RSSI is too strong.
         pBSSList->byRSSIStatCnt++;
         pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
@@ -638,10 +604,6 @@ int BSSbUpdateToBSSList(struct vnt_private *pDevice,
     return true;
 }
 
-
-
-
-
 /*+
  *
  * Routine Description:
@@ -672,8 +634,6 @@ int BSSbIsSTAInNodeDB(struct vnt_private *pDevice,
    return false;
 };
 
-
-
 /*+
  *
  * Routine Description:
@@ -731,8 +691,6 @@ void BSSvCreateOneNode(struct vnt_private *pDevice, u32 *puNodeIndex)
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
 };
 
-
-
 /*+
  *
  * Routine Description:
@@ -750,7 +708,6 @@ void BSSvRemoveOneNode(struct vnt_private *pDevice, u32 uNodeIndex)
        u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
        struct sk_buff  *skb;
 
-
     while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
             dev_kfree_skb(skb);
     // clear context
@@ -948,7 +905,6 @@ if(pDevice->byReAssocCount > 0) {
                 if (pMgmt->sNodeDBTable[ii].bPSEnable)
                     uSleepySTACnt++;
 
-
             }
 
             // Rate fallback check
@@ -981,7 +937,6 @@ if(pDevice->byReAssocCount > 0) {
 
     }
 
-
     if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->byBBType == BB_TYPE_11G)) {
 
         // on/off protect mode
@@ -1031,7 +986,6 @@ if(pDevice->byReAssocCount > 0) {
 
     }
 
-
     // Check if any STA in PS mode, enable DTIM multicast deliver
     if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
         if (uSleepySTACnt > 0)
@@ -1205,9 +1159,9 @@ void BSSvUpdateNodeTxCounter(struct vnt_private *pDevice,
 
     byPktNum = (byPktNO & 0x0F) >> 4;
     byTxRetry = (byTSR & 0xF0) >> 4;
-    wRate = (WORD) (byPktNO & 0xF0) >> 4;
+    wRate = (u16) (byPktNO & 0xF0) >> 4;
     wFIFOCtl = pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl;
-    pbyDestAddr = (PBYTE) &( pStatistic->abyTxPktInfo[byPktNum].abyDestAddr[0]);
+    pbyDestAddr = (u8 *) &( pStatistic->abyTxPktInfo[byPktNum].abyDestAddr[0]);
 
     if (wFIFOCtl & FIFOCTL_AUTO_FB_0) {
         byFallBack = AUTO_FB_0;
@@ -1433,7 +1387,7 @@ if(pDevice->bLinkPass !=true)
 }
 else
 {
-   RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
+   RFvRSSITodBm(pDevice, (u8)(pDevice->uCurrRSSI), &ldBm);
    if(-ldBm < 50)  {
        RssiRatio = 4000;
      }
@@ -1473,7 +1427,7 @@ static void s_vCheckPreEDThreshold(struct vnt_private *pDevice)
         ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
         pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
         if (pBSSList != NULL) {
-            pDevice->byBBPreEDRSSI = (BYTE) (~(pBSSList->ldBmAverRange) + 1);
+            pDevice->byBBPreEDRSSI = (u8) (~(pBSSList->ldBmAverRange) + 1);
             BBvUpdatePreEDThreshold(pDevice, false);
         }
     }
index 08091a0a7c40e834eb54f225ffd1a0098071bde5..bce3b46541656f71a603ad6d402db19813f7e2c3 100644 (file)
@@ -36,8 +36,6 @@
 #include "card.h"
 #include "mib.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
 #define MAX_NODE_NUM             64
 #define MAX_BSS_NUM              42
 #define LOST_BEACON_COUNT        10   /* 10 sec, XP defined */
 
 #define MAX_WPA_IE_LEN      64
 
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-
-/*---------------------  Export Types  ------------------------------*/
-
 //
 // IEEE 802.11 Structures and definitions
 //
 
 typedef struct tagSERPObject {
     bool    bERPExist;
-    BYTE    byERP;
+    u8    byERP;
 } ERPObject, *PERPObject;
 
-
 typedef struct tagSRSNCapObject {
     bool    bRSNCapExist;
-    WORD    wRSNCap;
+    u16    wRSNCap;
 } SRSNCapObject, *PSRSNCapObject;
 
 // BSS info(AP)
 typedef struct tagKnownBSS {
     // BSS info
     bool            bActive;
-    BYTE            abyBSSID[WLAN_BSSID_LEN];
+    u8            abyBSSID[WLAN_BSSID_LEN];
     unsigned int            uChannel;
-    BYTE            abySuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
-    BYTE            abyExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
+    u8            abySuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
+    u8            abyExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
     unsigned int            uRSSI;
-    BYTE            bySQ;
-    WORD            wBeaconInterval;
-    WORD            wCapInfo;
-    BYTE            abySSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
-    BYTE            byRxRate;
-
-//    WORD            wATIMWindow;
-    BYTE            byRSSIStatCnt;
+    u8            bySQ;
+    u16            wBeaconInterval;
+    u16            wCapInfo;
+    u8            abySSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
+    u8            byRxRate;
+
+//    u16            wATIMWindow;
+    u8            byRSSIStatCnt;
     signed long            ldBmMAX;
     signed long            ldBmAverage[RSSI_STAT_COUNT];
     signed long            ldBmAverRange;
@@ -114,32 +103,32 @@ typedef struct tagKnownBSS {
 
     //++ WPA informations
     bool            bWPAValid;
-    BYTE            byGKType;
-    BYTE            abyPKType[4];
-    WORD            wPKCount;
-    BYTE            abyAuthType[4];
-    WORD            wAuthCount;
-    BYTE            byDefaultK_as_PK;
-    BYTE            byReplayIdx;
+    u8            byGKType;
+    u8            abyPKType[4];
+    u16            wPKCount;
+    u8            abyAuthType[4];
+    u16            wAuthCount;
+    u8            byDefaultK_as_PK;
+    u8            byReplayIdx;
     //--
 
     //++ WPA2 informations
     bool            bWPA2Valid;
-    BYTE            byCSSGK;
-    WORD            wCSSPKCount;
-    BYTE            abyCSSPK[4];
-    WORD            wAKMSSAuthCount;
-    BYTE            abyAKMSSAuthType[4];
+    u8            byCSSGK;
+    u16            wCSSPKCount;
+    u8            abyCSSPK[4];
+    u16            wAKMSSAuthCount;
+    u8            abyAKMSSAuthType[4];
 
     //++  wpactl
-    BYTE            byWPAIE[MAX_WPA_IE_LEN];
-    BYTE            byRSNIE[MAX_WPA_IE_LEN];
-    WORD            wWPALen;
-    WORD            wRSNLen;
+    u8            byWPAIE[MAX_WPA_IE_LEN];
+    u8            byRSNIE[MAX_WPA_IE_LEN];
+    u16            wWPALen;
+    u16            wRSNLen;
 
     // Clear count
     unsigned int            uClearCount;
-//    BYTE            abyIEs[WLAN_BEACON_FR_MAXLEN];
+//    u8            abyIEs[WLAN_BEACON_FR_MAXLEN];
     unsigned int            uIELength;
        u64 qwBSSTimestamp;
        u64 qwLocalTSF;/* local TSF timer */
@@ -148,13 +137,11 @@ typedef struct tagKnownBSS {
 
     ERPObject       sERP;
     SRSNCapObject   sRSNCapObj;
-    BYTE            abyIEs[1024];   // don't move this field !!
+    u8            abyIEs[1024];   // don't move this field !!
 
 } __attribute__ ((__packed__))
 KnownBSS , *PKnownBSS;
 
-
-
 typedef enum tagNODE_STATE {
     NODE_FREE,
     NODE_AGED,
@@ -163,48 +150,47 @@ typedef enum tagNODE_STATE {
     NODE_ASSOC
 } NODE_STATE, *PNODE_STATE;
 
-
 // STA node info
 typedef struct tagKnownNodeDB {
     // STA info
     bool            bActive;
-    BYTE            abyMACAddr[WLAN_ADDR_LEN];
-    BYTE            abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
-    BYTE            abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
-    WORD            wTxDataRate;
+    u8            abyMACAddr[WLAN_ADDR_LEN];
+    u8            abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
+    u8            abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
+    u16            wTxDataRate;
     bool            bShortPreamble;
     bool            bERPExist;
     bool            bShortSlotTime;
     unsigned int            uInActiveCount;
-    WORD            wMaxBasicRate;     //Get from byTopOFDMBasicRate or byTopCCKBasicRate which depends on packetTyp.
-    WORD            wMaxSuppRate;      //Records the highest supported rate getting from SuppRates IE and ExtSuppRates IE in Beacon.
-    WORD            wSuppRate;
-    BYTE            byTopOFDMBasicRate;//Records the highest basic rate in OFDM mode
-    BYTE            byTopCCKBasicRate; //Records the highest basic rate in CCK mode
+    u16            wMaxBasicRate;     //Get from byTopOFDMBasicRate or byTopCCKBasicRate which depends on packetTyp.
+    u16            wMaxSuppRate;      //Records the highest supported rate getting from SuppRates IE and ExtSuppRates IE in Beacon.
+    u16            wSuppRate;
+    u8            byTopOFDMBasicRate;//Records the highest basic rate in OFDM mode
+    u8            byTopCCKBasicRate; //Records the highest basic rate in CCK mode
 
     // For AP mode
     struct sk_buff_head sTxPSQueue;
-    WORD            wCapInfo;
-    WORD            wListenInterval;
-    WORD            wAID;
+    u16            wCapInfo;
+    u16            wListenInterval;
+    u16            wAID;
     NODE_STATE      eNodeState;
     bool            bPSEnable;
     bool            bRxPSPoll;
-    BYTE            byAuthSequence;
+    u8            byAuthSequence;
     unsigned long           ulLastRxJiffer;
-    BYTE            bySuppRate;
-    DWORD           dwFlags;
-    WORD            wEnQueueCnt;
+    u8            bySuppRate;
+    u32           dwFlags;
+    u16            wEnQueueCnt;
 
     bool            bOnFly;
     unsigned long long       KeyRSC;
-    BYTE            byKeyIndex;
-    DWORD           dwKeyIndex;
-    BYTE            byCipherSuite;
-    DWORD           dwTSC47_16;
-    WORD            wTSC15_0;
+    u8            byKeyIndex;
+    u32           dwKeyIndex;
+    u8            byCipherSuite;
+    u32           dwTSC47_16;
+    u16            wTSC15_0;
     unsigned int            uWepKeyLength;
-    BYTE            abyWepKey[WLAN_WEPMAX_KEYLEN];
+    u8            abyWepKey[WLAN_WEPMAX_KEYLEN];
     //
     // Auto rate fallback vars
     bool            bIsInFallback;
@@ -223,8 +209,6 @@ typedef struct tagKnownNodeDB {
 
 } KnownNodeDB, *PKnownNodeDB;
 
-/*---------------------  Export Functions  --------------------------*/
-
 PKnownBSS BSSpSearchBSSList(struct vnt_private *, u8 *pbyDesireBSSID,
        u8 *pbyDesireSSID, CARD_PHY_TYPE ePhyType);
 
@@ -270,7 +254,7 @@ int BSSbUpdateToBSSList(struct vnt_private *,
                        u8 *pbyIEs,
                        void *pRxPacketContext);
 
-int BSSbIsSTAInNodeDB(struct vnt_private *, PBYTE abyDstAddr,
+int BSSbIsSTAInNodeDB(struct vnt_private *, u8 * abyDstAddr,
        u32 *puNodeIndex);
 
 void BSSvCreateOneNode(struct vnt_private *, u32 *puNodeIndex);
index d2479b766450e69e81d198ad768b5564ad3f6336..24291aee58b5575485e7d4dd1c720a09e854a596 100644 (file)
 #include "rndis.h"
 #include "control.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 static int          msglevel                =MSG_LEVEL_INFO;
 
-
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-//const WORD cwRXBCNTSFOff[MAX_RATE] =
+//const u16 cwRXBCNTSFOff[MAX_RATE] =
 //{17, 34, 96, 192, 34, 23, 17, 11, 8, 5, 4, 3};
 
-const WORD cwRXBCNTSFOff[MAX_RATE] =
+const u16 cwRXBCNTSFOff[MAX_RATE] =
 {192, 96, 34, 17, 34, 23, 17, 11, 8, 5, 4, 3};
 
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
 /*
  * Description: Set NIC media channel
  *
@@ -114,7 +101,7 @@ void CARDbSetMediaChannel(struct vnt_private *pDevice, u32 uConnectionChannel)
 
     CONTROLnsRequestOut(pDevice,
                         MESSAGE_TYPE_SELECT_CHANNLE,
-                        (WORD) uConnectionChannel,
+                        (u16) uConnectionChannel,
                         0,
                         0,
                         NULL
@@ -133,7 +120,7 @@ void CARDbSetMediaChannel(struct vnt_private *pDevice, u32 uConnectionChannel)
         pDevice->byCurPwr = 0xFF;
         RFbRawSetPower(pDevice, pDevice->abyCCKPwrTbl[uConnectionChannel-1], RATE_1M);
     }
-    ControlvWriteByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_CHANNEL,(BYTE)(uConnectionChannel|0x80));
+    ControlvWriteByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_CHANNEL,(u8)(uConnectionChannel|0x80));
 }
 
 /*
@@ -220,10 +207,10 @@ static u16 swGetOFDMControlRate(struct vnt_private *pDevice, u16 wRateIdx)
  */
 void
 CARDvCalculateOFDMRParameter (
-      WORD wRate,
-      BYTE byBBType,
-     PBYTE pbyTxRate,
-     PBYTE pbyRsvTime
+      u16 wRate,
+      u8 byBBType,
+     u8 * pbyTxRate,
+     u8 * pbyRsvTime
     )
 {
     switch (wRate) {
@@ -434,23 +421,23 @@ void CARDvSetRSPINF(struct vnt_private *pDevice, u8 byBBType)
                                  &abyTxRate[8],
                                  &abyRsvTime[8]);
 
-    abyData[0] = (BYTE)(awLen[0]&0xFF);
-    abyData[1] = (BYTE)(awLen[0]>>8);
+    abyData[0] = (u8)(awLen[0]&0xFF);
+    abyData[1] = (u8)(awLen[0]>>8);
     abyData[2] = abySignal[0];
     abyData[3] = abyServ[0];
 
-    abyData[4] = (BYTE)(awLen[1]&0xFF);
-    abyData[5] = (BYTE)(awLen[1]>>8);
+    abyData[4] = (u8)(awLen[1]&0xFF);
+    abyData[5] = (u8)(awLen[1]>>8);
     abyData[6] = abySignal[1];
     abyData[7] = abyServ[1];
 
-    abyData[8] = (BYTE)(awLen[2]&0xFF);
-    abyData[9] = (BYTE)(awLen[2]>>8);
+    abyData[8] = (u8)(awLen[2]&0xFF);
+    abyData[9] = (u8)(awLen[2]>>8);
     abyData[10] = abySignal[2];
     abyData[11] = abyServ[2];
 
-    abyData[12] = (BYTE)(awLen[3]&0xFF);
-    abyData[13] = (BYTE)(awLen[3]>>8);
+    abyData[12] = (u8)(awLen[3]&0xFF);
+    abyData[13] = (u8)(awLen[3]>>8);
     abyData[14] = abySignal[3];
     abyData[15] = abyServ[3];
 
@@ -500,7 +487,7 @@ void vUpdateIFS(struct vnt_private *pDevice)
         byMaxMin = 5;
     }
     else {// PK_TYPE_11GA & PK_TYPE_11GB
-        BYTE byRate = 0;
+        u8 byRate = 0;
         bool bOFDMRate = false;
        unsigned int ii = 0;
         PWLAN_IE_SUPP_RATES pItemRates = NULL;
@@ -515,7 +502,7 @@ void vUpdateIFS(struct vnt_private *pDevice)
 
        pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt.abyCurrSuppRates;
         for (ii = 0; ii < pItemRates->len; ii++) {
-            byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
+            byRate = (u8)(pItemRates->abyRates[ii]&0x7F);
             if (RATEwGetRateIdx(byRate) > RATE_11M) {
                 bOFDMRate = true;
                 break;
@@ -525,7 +512,7 @@ void vUpdateIFS(struct vnt_private *pDevice)
                pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt
                        .abyCurrExtSuppRates;
             for (ii = 0; ii < pItemRates->len; ii++) {
-                byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
+                byRate = (u8)(pItemRates->abyRates[ii]&0x7F);
                 if (RATEwGetRateIdx(byRate) > RATE_11M) {
                     bOFDMRate = true;
                     break;
@@ -544,10 +531,10 @@ void vUpdateIFS(struct vnt_private *pDevice)
     pDevice->uCwMax = C_CWMAX;
     pDevice->uEIFS = C_EIFS;
 
-    byData[0] = (BYTE)pDevice->uSIFS;
-    byData[1] = (BYTE)pDevice->uDIFS;
-    byData[2] = (BYTE)pDevice->uEIFS;
-    byData[3] = (BYTE)pDevice->uSlot;
+    byData[0] = (u8)pDevice->uSIFS;
+    byData[1] = (u8)pDevice->uDIFS;
+    byData[2] = (u8)pDevice->uEIFS;
+    byData[3] = (u8)pDevice->uSlot;
     CONTROLnsRequestOut(pDevice,
                         MESSAGE_TYPE_WRITE,
                         MAC_REG_SIFS,
@@ -571,7 +558,7 @@ void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
 
      //Determines the highest basic rate.
      for (ii = RATE_54M; ii >= RATE_6M; ii --) {
-         if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) ) {
+         if ( (pDevice->wBasicRate) & ((u16)(1<<ii)) ) {
              byTopOFDM = ii;
              break;
          }
@@ -579,7 +566,7 @@ void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
      pDevice->byTopOFDMBasicRate = byTopOFDM;
 
      for (ii = RATE_11M;; ii --) {
-         if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) ) {
+         if ( (pDevice->wBasicRate) & ((u16)(1<<ii)) ) {
              byTopCCK = ii;
              break;
          }
@@ -617,7 +604,7 @@ int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
        int ii;
 
     for (ii = RATE_54M; ii >= RATE_6M; ii --) {
-        if ((pDevice->wBasicRate) & ((WORD)(1<<ii)))
+        if ((pDevice->wBasicRate) & ((u16)(1<<ii)))
             return true;
     }
     return false;
@@ -627,7 +614,7 @@ u8 CARDbyGetPktType(struct vnt_private *pDevice)
 {
 
     if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
-        return (BYTE)pDevice->byBBType;
+        return (u8)pDevice->byBBType;
     }
     else if (CARDbIsOFDMinBasicRate(pDevice)) {
         return PK_TYPE_11GA;
@@ -637,7 +624,6 @@ u8 CARDbyGetPktType(struct vnt_private *pDevice)
     }
 }
 
-
 /*
  * Description: Calculate TSF offset of two TSF input
  *              Get TSF Offset from RxBCN's TSF and local TSF
@@ -653,10 +639,10 @@ u8 CARDbyGetPktType(struct vnt_private *pDevice)
  * Return Value: TSF Offset value
  *
  */
-u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2)
+u64 CARDqGetTSFOffset(u8 byRxRate, u64 qwTSF1, u64 qwTSF2)
 {
        u64 qwTSFOffset = 0;
-       WORD wRxBcnTSFOffst = 0;
+       u16 wRxBcnTSFOffst = 0;
 
        wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate % MAX_RATE];
 
@@ -667,8 +653,6 @@ u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2)
        return qwTSFOffset;
 }
 
-
-
 /*
  * Description: Sync. TSF counter to BSS
  *              Get TSF offset and write to HW
@@ -690,7 +674,6 @@ void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate,
        u64 qwTSFOffset = 0;
        u8 pbyData[8];
 
-
     qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
     // adjust TSF
     // HW's TSF add TSF Offset reg
@@ -734,7 +717,6 @@ bool CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF)
        return true;
 }
 
-
 /*
  * Description: Clear NIC TSF counter
  *              Clear local TSF counter
@@ -770,7 +752,7 @@ bool CARDbClearCurrentTSF(struct vnt_private *pDevice)
  * Return Value: TSF value of next Beacon
  *
  */
-u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval)
+u64 CARDqGetNextTBTT(u64 qwTSF, u16 wBeaconInterval)
 {
 
     unsigned int    uLowNextTBTT;
@@ -796,7 +778,6 @@ u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval)
     return (qwTSF);
 }
 
-
 /*
  * Description: Set NIC TSF counter for first Beacon time
  *              Get NEXTTBTT from adjusted TSF and Beacon Interval
@@ -811,7 +792,7 @@ u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval)
  * Return Value: none
  *
  */
-void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, WORD wBeaconInterval)
+void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, u16 wBeaconInterval)
 {
        u64 qwNextTBTT = 0;
        u8 pbyData[8];
@@ -841,7 +822,6 @@ void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, WORD wBeaconInterval)
     return;
 }
 
-
 /*
  * Description: Sync NIC TSF counter for Beacon time
  *              Get NEXTTBTT and write to HW
@@ -883,7 +863,6 @@ void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF,
                         pbyData
                         );
 
-
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
                "Card:Update Next TBTT[%8lx]\n", (unsigned long)qwTSF);
 
@@ -929,7 +908,6 @@ int CARDbRadioPowerOff(struct vnt_private *pDevice)
     return bResult;
 }
 
-
 /*
  * Description: Turn on Radio power
  *
@@ -996,7 +974,7 @@ void CARDvSetBSSMode(struct vnt_private *pDevice)
     }
 
     vUpdateIFS(pDevice);
-    CARDvSetRSPINF(pDevice, (BYTE)pDevice->byBBType);
+    CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
 
     if ( pDevice->byBBType == BB_TYPE_11A ) {
         //request by Jack 2005-04-26
@@ -1016,44 +994,3 @@ void CARDvSetBSSMode(struct vnt_private *pDevice)
         pDevice->abyBBVGA[3] = 0x0;
     }
 }
-
-/*
- *
- * Description:
- *    Do Channel Switch defined in 802.11h
- *
- * Parameters:
- *  In:
- *      hDeviceContext - device structure point
- *  Out:
- *      none
- *
- * Return Value: none.
- *
--*/
-int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode,
-       u8 byNewChannel, u8 byCount)
-{
-       int bResult = true;
-
-       if (byCount == 0) {
-               pDevice->vnt_mgmt.uCurrChannel = byNewChannel;
-               CARDbSetMediaChannel(pDevice, byNewChannel);
-               return bResult;
-       }
-    pDevice->byChannelSwitchCount = byCount;
-    pDevice->byNewChannel = byNewChannel;
-    pDevice->bChannelSwitch = true;
-
-    if (byMode == 1) {
-        //bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
-        pDevice->bStopDataPkt = true;
-    }
-       return bResult;
-}
-
-
-
-
-
-
index 5123bc7d0dcd7d6e9268e9a5e57558b6fcc8cef4..c3017a74fa0f8695b5a83d84188aea0f9a9c649c 100644 (file)
 #ifndef __CARD_H__
 #define __CARD_H__
 #include "device.h"
-#include "ttype.h"
-
-/*---------------------  Export Definitions -------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
 
 /* init card type */
 
@@ -55,9 +50,6 @@ typedef enum _CARD_OP_MODE {
 #define CB_MAX_CHANNEL_5G       42 /* add channel9(5045MHz), 41==>42 */
 #define CB_MAX_CHANNEL      (CB_MAX_CHANNEL_24G+CB_MAX_CHANNEL_5G)
 
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
 struct vnt_private;
 
 void CARDbSetMediaChannel(struct vnt_private *pDevice, u32 uConnectionChannel);
@@ -70,16 +62,14 @@ void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate,
                u64 qwBSSTimestamp, u64 qwLocalTSF);
 bool CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF);
 bool CARDbClearCurrentTSF(struct vnt_private *pDevice);
-void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, WORD wBeaconInterval);
+void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, u16 wBeaconInterval);
 void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF,
-                        WORD wBeaconInterval);
-u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval);
-u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2);
+                        u16 wBeaconInterval);
+u64 CARDqGetNextTBTT(u64 qwTSF, u16 wBeaconInterval);
+u64 CARDqGetTSFOffset(u8 byRxRate, u64 qwTSF1, u64 qwTSF2);
 int CARDbRadioPowerOff(struct vnt_private *pDevice);
 int CARDbRadioPowerOn(struct vnt_private *pDevice);
 u8 CARDbyGetPktType(struct vnt_private *pDevice);
 void CARDvSetBSSMode(struct vnt_private *pDevice);
-int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode,
-       u8 byNewChannel, u8 byCount);
 
 #endif /* __CARD_H__ */
index 4181e3e12ea94c4fa58bf76aff3d30c8404bc2ca..5158ff4b346a135db1dda3cc225f1e4405cc5edd 100644 (file)
 #include "channel.h"
 #include "rf.h"
 
-/*---------------------  Static Definitions -------------------------*/
 static int          msglevel                = MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Export Definitions -------------------------*/
-
-
 static SChannelTblElement sChannelTbl[CB_MAX_CHANNEL+1] =
 {
   {0,   0,    false},
@@ -109,17 +103,15 @@ static SChannelTblElement sChannelTbl[CB_MAX_CHANNEL+1] =
   {165, 5825, true}  //56
 };
 
-
-
 /************************************************************************
  * The Radar regulation rules for each country
  ************************************************************************/
 static  struct
 {
-    BYTE    byChannelCountryCode;             /* The country code         */
+    u8    byChannelCountryCode;             /* The country code         */
     char    chCountryCode[2];
-    BYTE    bChannelIdxList[CB_MAX_CHANNEL];  /* Available channels Index */
-    BYTE    byPower[CB_MAX_CHANNEL];
+    u8    bChannelIdxList[CB_MAX_CHANNEL];  /* Available channels Index */
+    u8    byPower[CB_MAX_CHANNEL];
 }   ChannelRuleTab[] =
 {
 /************************************************************************
@@ -368,7 +360,6 @@ static  struct
 /*                                           1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  */
 };
 
-/*---------------------  Export function  -------------------------*/
 /************************************************************************
  * Country Channel Valid
  *  Input:  CountryCode, ChannelNum
@@ -410,32 +401,6 @@ exit:
 
 } /* end ChannelValid */
 
-/************************************************************************
- * CHvChannelGetList
- * Get Available Channel List for a given country
- * Input:
- *      CountryCode     =   The country code defined in country.h
- * Output:
- *      ChannelBitMask  =   (QWORD *) correspondent bit mask
- *                          of available channels
- *                          0x0000000000000001 means channel 1 is supported
- *                          0x0000000000000003 means channel 1,2 are supported
- *                          0x000000000000000F means channel 1,2,..15 are supported
- ************************************************************************/
-bool
-CHvChannelGetList (
-      unsigned int       uCountryCodeIdx,
-     PBYTE      pbyChannelTable
-    )
-{
-    if (uCountryCodeIdx >= CCODE_MAX) {
-        return (false);
-    }
-    memcpy(pbyChannelTable, ChannelRuleTab[uCountryCodeIdx].bChannelIdxList, CB_MAX_CHANNEL);
-    return (true);
-}
-
-
 void CHvInitChannelTable(struct vnt_private *pDevice)
 {
        int bMultiBand = false;
@@ -507,15 +472,3 @@ void CHvInitChannelTable(struct vnt_private *pDevice)
         }*/
     }
 }
-
-BYTE CHbyGetChannelMapping(BYTE byChannelNumber)
-{
-BYTE    ii;
-BYTE    byCHMapping = 0;
-
-       for (ii = 1; ii <= CB_MAX_CHANNEL; ii++) {
-               if (sChannelTbl[ii].byChannelNumber == byChannelNumber)
-                       byCHMapping = ii;
-    }
-    return byCHMapping;
-}
index 9914dba0ba0c927459503bbf0cd001d42f585773..95701e0cbee3c7af9731f0b869f2f6a3115daf88 100644 (file)
 #define _CHANNEL_H_
 
 #include "device.h"
-#include "ttype.h"
-
-/*---------------------  Export Definitions -------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
 
 typedef struct tagSChannelTblElement {
-    BYTE    byChannelNumber;
+    u8    byChannelNumber;
     unsigned int    uFrequency;
     bool    bValid;
 } SChannelTblElement, *PSChannelTblElement;
 
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 bool    ChannelValid(unsigned int CountryCode, unsigned int ChannelNum);
 void    CHvInitChannelTable(struct vnt_private *pDevice);
-BYTE    CHbyGetChannelMapping(BYTE byChannelNumber);
-
-bool CHvChannelGetList(unsigned int uCountryCodeIdx, PBYTE pbyChannelTable);
 
 #endif  /* _CHANNEL_H_ */
index 743ef5fb7fe748f00cc5fd6f65163ecf179c0e80..026784fcde82dda8edf9d42533202a6c15454b3f 100644 (file)
 #include "control.h"
 #include "rndis.h"
 
-/*---------------------  Static Definitions -------------------------*/
 /* static int          msglevel                =MSG_LEVEL_INFO;  */
 /* static int          msglevel                =MSG_LEVEL_DEBUG; */
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
 
 void ControlvWriteByte(struct vnt_private *pDevice, u8 reg, u8 reg_off,
                        u8 data)
index 76ce0244e100525c7b3584f2219cf1b55cafa5e2..9da9b96add70c100aa507004c0b123ce377e77a6 100644 (file)
 #ifndef __CONTROL_H__
 #define __CONTROL_H__
 
-#include "ttype.h"
 #include "device.h"
 #include "usbpipe.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
 #define CONTROLnsRequestOut(Device, Request, Value, Index, Length, Buffer) \
        PIPEnsControlOut(Device, Request, Value, Index, Length, Buffer)
 
 #define CONTROLnsRequestIn(Device, Request, Value, Index, Length, Buffer) \
        PIPEnsControlIn(Device, Request, Value, Index, Length, Buffer)
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 void ControlvWriteByte(struct vnt_private *pDevice, u8 reg, u8 reg_off,
                        u8 data);
 
@@ -60,5 +51,4 @@ void ControlvReadByte(struct vnt_private *pDevice, u8 reg, u8 reg_off,
 void ControlvMaskByte(struct vnt_private *pDevice, u8 reg_type, u8 reg_off,
                        u8 reg_mask, u8 data);
 
-
 #endif /* __CONTROL_H__ */
index 7bdc8d47aedb98f70db6c79dcd778572d0ade378..a0320d8f13623bd94ad122215dc0598ae971392e 100644 (file)
@@ -156,7 +156,6 @@ typedef enum _COUNTRY_CODE {
     CCODE_MAX
 } COUNTRY_CODE;
 
-
 /************************************************************************
  * Function prototype
  ************************************************************************/
index 77464e819f6d11397ee913484cbc6b90baf1777a..17fbc35ebcbfe4022fbfe40afbac8faf2c89eb54 100644 (file)
@@ -33,7 +33,6 @@
  *
  */
 
-#include "ttype.h"
 #include "tmacro.h"
 #include "mac.h"
 #include "80211mgr.h"
 #include "srom.h"
 #include "rf.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-
-
-
-/*---------------------  Static Classes  ----------------------------*/
-
-
-
-/*---------------------  Static Variables  --------------------------*/
-
 /* static int msglevel = MSG_LEVEL_DEBUG; */
 static int          msglevel                =MSG_LEVEL_INFO;
-const BYTE acbyIERate[MAX_RATE] =
+const u8 acbyIERate[MAX_RATE] =
 {0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
 
 #define AUTORATE_TXOK_CNT       0x0400
 #define AUTORATE_TXFAIL_CNT     0x0064
 #define AUTORATE_TIMEOUT        10
 
-/*---------------------  Static Functions  --------------------------*/
-
 void s_vResetCounter(PKnownNodeDB psNodeDBTable);
 
 void s_vResetCounter(PKnownNodeDB psNodeDBTable)
 {
-    BYTE            ii;
+    u8            ii;
 
     /* clear statistics counter for auto_rate */
     for (ii = 0; ii <= MAX_RATE; ii++) {
@@ -79,45 +65,6 @@ void s_vResetCounter(PKnownNodeDB psNodeDBTable)
     }
 }
 
-/*---------------------  Export Variables  --------------------------*/
-
-
-/*---------------------  Export Functions  --------------------------*/
-
-
-/*+
- *
- * Description:
- *      Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
- *
- * Parameters:
- *  In:
- *      BYTE    - Rate value in SuppRates IE or ExtSuppRates IE
- *  Out:
- *      none
- *
- * Return Value: RateIdx
- *
--*/
-BYTE
-DATARATEbyGetRateIdx (
-     BYTE byRate
-    )
-{
-    BYTE    ii;
-
-    /* erase BasicRate flag */
-    byRate = byRate & 0x7F;
-
-    for (ii = 0; ii < MAX_RATE; ii ++) {
-        if (acbyIERate[ii] == byRate)
-            return ii;
-    }
-    return 0;
-}
-
-
-
 /*+
  *
  * Routine Description:
@@ -136,9 +83,6 @@ DATARATEbyGetRateIdx (
 #define AUTORATE_TXCNT_THRESHOLD        20
 #define AUTORATE_INC_THRESHOLD          30
 
-
-
-
 /*+
  *
  * Description:
@@ -146,19 +90,19 @@ DATARATEbyGetRateIdx (
  *
  * Parameters:
  *  In:
- *      BYTE    - Rate value in SuppRates IE or ExtSuppRates IE
+ *      u8    - Rate value in SuppRates IE or ExtSuppRates IE
  *  Out:
  *      none
  *
  * Return Value: RateIdx
  *
 -*/
-WORD
+u16
 RATEwGetRateIdx(
-     BYTE byRate
+     u8 byRate
     )
 {
-    WORD    ii;
+    u16    ii;
 
     /* erase BasicRate flag */
     byRate = byRate & 0x7F;
@@ -216,7 +160,7 @@ void RATEvParseMaxRate(struct vnt_private *pDevice,
     }
 
     for (ii = 0; ii < uRateLen; ii++) {
-       byRate = (BYTE)(pItemRates->abyRates[ii]);
+       byRate = (u8)(pItemRates->abyRates[ii]);
         if (WLAN_MGMT_IS_BASICRATE(byRate) &&
             (bUpdateBasicRate == true))  {
          /*
@@ -226,7 +170,7 @@ void RATEvParseMaxRate(struct vnt_private *pDevice,
                CARDbAddBasicRate((void *)pDevice, RATEwGetRateIdx(byRate));
             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", RATEwGetRateIdx(byRate));
         }
-        byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
+        byRate = (u8)(pItemRates->abyRates[ii]&0x7F);
         if (byHighSuppRate == 0)
             byHighSuppRate = byRate;
         if (byRate > byHighSuppRate)
@@ -242,7 +186,7 @@ void RATEvParseMaxRate(struct vnt_private *pDevice,
             uExtRateLen = WLAN_RATES_MAXLEN;
 
         for (ii = 0; ii < uExtRateLen ; ii++) {
-            byRate = (BYTE)(pItemExtRates->abyRates[ii]);
+            byRate = (u8)(pItemExtRates->abyRates[ii]);
            /* select highest basic rate */
             if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) {
              /*
@@ -252,7 +196,7 @@ void RATEvParseMaxRate(struct vnt_private *pDevice,
                    CARDbAddBasicRate((void *)pDevice, RATEwGetRateIdx(byRate));
                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", RATEwGetRateIdx(byRate));
             }
-            byRate = (BYTE)(pItemExtRates->abyRates[ii]&0x7F);
+            byRate = (u8)(pItemExtRates->abyRates[ii]&0x7F);
             if (byHighSuppRate == 0)
                 byHighSuppRate = byRate;
             if (byRate > byHighSuppRate)
@@ -282,7 +226,6 @@ void RATEvParseMaxRate(struct vnt_private *pDevice,
      DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Exit ParseMaxRate\n");
 }
 
-
 /*+
  *
  * Routine Description:
@@ -336,7 +279,7 @@ void RATEvTxRateFallBack(struct vnt_private *pDevice,
     for (ii = 0; ii < MAX_RATE; ii++) {
         if (psNodeDBTable->wSuppRate & (0x0001<<ii)) {
             if (bAutoRate[ii] == true) {
-                wIdxUpRate = (WORD) ii;
+                wIdxUpRate = (u16) ii;
             }
         } else {
             bAutoRate[ii] = false;
@@ -363,7 +306,7 @@ void RATEvTxRateFallBack(struct vnt_private *pDevice,
         if ( (dwThroughputTbl[ii] > dwThroughput) &&
              (bAutoRate[ii]==true) ) {
             dwThroughput = dwThroughputTbl[ii];
-            wIdxDownRate = (WORD) ii;
+            wIdxDownRate = (u16) ii;
         }
     }
     psNodeDBTable->wTxDataRate = wIdxDownRate;
@@ -400,7 +343,7 @@ void RATEvTxRateFallBack(struct vnt_private *pDevice,
  * Return Value: None
  *
 -*/
-BYTE
+u8
 RATEuSetIE (
      PWLAN_IE_SUPP_RATES pSrcRates,
      PWLAN_IE_SUPP_RATES pDstRates,
@@ -423,6 +366,6 @@ RATEuSetIE (
             }
         }
     }
-    return (BYTE)uRateCnt;
+    return (u8)uRateCnt;
 }
 
index 8dc55bd6166948e9581def533c27cc5da7b7bd77..43cb77894b66daa0203df4c666c2a028f214c69c 100644 (file)
@@ -29,9 +29,6 @@
 #ifndef __DATARATE_H__
 #define __DATARATE_H__
 
-
-/*---------------------  Export Definitions -------------------------*/
-
 #define FALLBACK_PKT_COLLECT_TR_H  50   /* pkts */
 #define FALLBACK_PKT_COLLECT_TR_L  10   /* pkts */
 #define FALLBACK_POLL_SECOND       5    /* 5 sec */
 #define RATE_AUTO      12
 #define MAX_RATE       12
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-
-/*---------------------  Export Types  ------------------------------*/
-
-
-/*---------------------  Export Functions  --------------------------*/
-
-
-
 void RATEvParseMaxRate(struct vnt_private *, PWLAN_IE_SUPP_RATES pItemRates,
        PWLAN_IE_SUPP_RATES pItemExtRates, int bUpdateBasicRate,
        u16 *pwMaxBasicRate, u16 *pwMaxSuppRate, u16 *pwSuppRate,
@@ -77,22 +62,16 @@ void RATEvParseMaxRate(struct vnt_private *, PWLAN_IE_SUPP_RATES pItemRates,
 void RATEvTxRateFallBack(struct vnt_private *pDevice,
        PKnownNodeDB psNodeDBTable);
 
-BYTE
+u8
 RATEuSetIE(
      PWLAN_IE_SUPP_RATES pSrcRates,
      PWLAN_IE_SUPP_RATES pDstRates,
      unsigned int                uRateLen
     );
 
-WORD
+u16
 RATEwGetRateIdx(
-     BYTE byRate
-    );
-
-
-BYTE
-DATARATEbyGetRateIdx(
-     BYTE byRate
+     u8 byRate
     );
 
 #endif /* __DATARATE_H__ */
index 0c0b614aaa11a014d1199e732f2686ae8840beb9..64cb046fe9885a5bf13f2875d6559b5f80059394 100644 (file)
@@ -33,7 +33,7 @@
 
 #include <linux/types.h>
 #include <linux/mm.h>
-#include "ttype.h"
+
 #include "tether.h"
 
 /* max transmit or receive buffer size */
  * RsvTime buffer header
  */
 typedef struct tagSRrvTime_gRTS {
-    WORD        wRTSTxRrvTime_ba;
-    WORD        wRTSTxRrvTime_aa;
-    WORD        wRTSTxRrvTime_bb;
-    WORD        wReserved;
-    WORD        wTxRrvTime_b;
-    WORD        wTxRrvTime_a;
+    u16        wRTSTxRrvTime_ba;
+    u16        wRTSTxRrvTime_aa;
+    u16        wRTSTxRrvTime_bb;
+    u16        wReserved;
+    u16        wTxRrvTime_b;
+    u16        wTxRrvTime_a;
 } __attribute__ ((__packed__))
 SRrvTime_gRTS, *PSRrvTime_gRTS;
 
 typedef const SRrvTime_gRTS *PCSRrvTime_gRTS;
 
 typedef struct tagSRrvTime_gCTS {
-    WORD        wCTSTxRrvTime_ba;
-    WORD        wReserved;
-    WORD        wTxRrvTime_b;
-    WORD        wTxRrvTime_a;
+    u16        wCTSTxRrvTime_ba;
+    u16        wReserved;
+    u16        wTxRrvTime_b;
+    u16        wTxRrvTime_a;
 } __attribute__ ((__packed__))
 SRrvTime_gCTS, *PSRrvTime_gCTS;
 
 typedef const SRrvTime_gCTS *PCSRrvTime_gCTS;
 
 typedef struct tagSRrvTime_ab {
-    WORD        wRTSTxRrvTime;
-    WORD        wTxRrvTime;
+    u16        wRTSTxRrvTime;
+    u16        wTxRrvTime;
 } __attribute__ ((__packed__))
 SRrvTime_ab, *PSRrvTime_ab;
 
 typedef const SRrvTime_ab *PCSRrvTime_ab;
 
 typedef struct tagSRrvTime_atim {
-    WORD        wCTSTxRrvTime_ba;
-    WORD        wTxRrvTime_a;
+    u16        wCTSTxRrvTime_ba;
+    u16        wTxRrvTime_a;
 } __attribute__ ((__packed__))
 SRrvTime_atim, *PSRrvTime_atim;
 
@@ -188,46 +188,46 @@ typedef const SRrvTime_atim *PCSRrvTime_atim;
  * RTS buffer header
  */
 typedef struct tagSRTSData {
-    WORD    wFrameControl;
-    WORD    wDurationID;
-    BYTE    abyRA[ETH_ALEN];
-    BYTE    abyTA[ETH_ALEN];
+    u16    wFrameControl;
+    u16    wDurationID;
+    u8    abyRA[ETH_ALEN];
+    u8    abyTA[ETH_ALEN];
 } __attribute__ ((__packed__))
 SRTSData, *PSRTSData;
 
 typedef const SRTSData *PCSRTSData;
 
 typedef struct tagSRTS_g {
-    BYTE        bySignalField_b;
-    BYTE        byServiceField_b;
-    WORD        wTransmitLength_b;
-    BYTE        bySignalField_a;
-    BYTE        byServiceField_a;
-    WORD        wTransmitLength_a;
-    WORD        wDuration_ba;
-    WORD        wDuration_aa;
-    WORD        wDuration_bb;
-    WORD        wReserved;
+    u8        bySignalField_b;
+    u8        byServiceField_b;
+    u16        wTransmitLength_b;
+    u8        bySignalField_a;
+    u8        byServiceField_a;
+    u16        wTransmitLength_a;
+    u16        wDuration_ba;
+    u16        wDuration_aa;
+    u16        wDuration_bb;
+    u16        wReserved;
     SRTSData    Data;
 } __attribute__ ((__packed__))
 SRTS_g, *PSRTS_g;
 typedef const SRTS_g *PCSRTS_g;
 
 typedef struct tagSRTS_g_FB {
-    BYTE        bySignalField_b;
-    BYTE        byServiceField_b;
-    WORD        wTransmitLength_b;
-    BYTE        bySignalField_a;
-    BYTE        byServiceField_a;
-    WORD        wTransmitLength_a;
-    WORD        wDuration_ba;
-    WORD        wDuration_aa;
-    WORD        wDuration_bb;
-    WORD        wReserved;
-    WORD        wRTSDuration_ba_f0;
-    WORD        wRTSDuration_aa_f0;
-    WORD        wRTSDuration_ba_f1;
-    WORD        wRTSDuration_aa_f1;
+    u8        bySignalField_b;
+    u8        byServiceField_b;
+    u16        wTransmitLength_b;
+    u8        bySignalField_a;
+    u8        byServiceField_a;
+    u16        wTransmitLength_a;
+    u16        wDuration_ba;
+    u16        wDuration_aa;
+    u16        wDuration_bb;
+    u16        wReserved;
+    u16        wRTSDuration_ba_f0;
+    u16        wRTSDuration_aa_f0;
+    u16        wRTSDuration_ba_f1;
+    u16        wRTSDuration_aa_f1;
     SRTSData    Data;
 } __attribute__ ((__packed__))
 SRTS_g_FB, *PSRTS_g_FB;
@@ -235,11 +235,11 @@ SRTS_g_FB, *PSRTS_g_FB;
 typedef const SRTS_g_FB *PCSRTS_g_FB;
 
 typedef struct tagSRTS_ab {
-    BYTE        bySignalField;
-    BYTE        byServiceField;
-    WORD        wTransmitLength;
-    WORD        wDuration;
-    WORD        wReserved;
+    u8        bySignalField;
+    u8        byServiceField;
+    u16        wTransmitLength;
+    u16        wDuration;
+    u16        wReserved;
     SRTSData    Data;
 } __attribute__ ((__packed__))
 SRTS_ab, *PSRTS_ab;
@@ -247,13 +247,13 @@ SRTS_ab, *PSRTS_ab;
 typedef const SRTS_ab *PCSRTS_ab;
 
 typedef struct tagSRTS_a_FB {
-    BYTE        bySignalField;
-    BYTE        byServiceField;
-    WORD        wTransmitLength;
-    WORD        wDuration;
-    WORD        wReserved;
-    WORD        wRTSDuration_f0;
-    WORD        wRTSDuration_f1;
+    u8        bySignalField;
+    u8        byServiceField;
+    u16        wTransmitLength;
+    u16        wDuration;
+    u16        wReserved;
+    u16        wRTSDuration_f0;
+    u16        wRTSDuration_f1;
     SRTSData    Data;
 } __attribute__ ((__packed__))
 SRTS_a_FB, *PSRTS_a_FB;
@@ -264,19 +264,19 @@ typedef const SRTS_a_FB *PCSRTS_a_FB;
  * CTS buffer header
  */
 typedef struct tagSCTSData {
-    WORD    wFrameControl;
-    WORD    wDurationID;
-    BYTE    abyRA[ETH_ALEN];
-    WORD    wReserved;
+    u16    wFrameControl;
+    u16    wDurationID;
+    u8    abyRA[ETH_ALEN];
+    u16    wReserved;
 } __attribute__ ((__packed__))
 SCTSData, *PSCTSData;
 
 typedef struct tagSCTS {
-    BYTE        bySignalField_b;
-    BYTE        byServiceField_b;
-    WORD        wTransmitLength_b;
-    WORD        wDuration_ba;
-    WORD        wReserved;
+    u8        bySignalField_b;
+    u8        byServiceField_b;
+    u16        wTransmitLength_b;
+    u16        wDuration_ba;
+    u16        wReserved;
     SCTSData    Data;
 } __attribute__ ((__packed__))
 SCTS, *PSCTS;
@@ -284,13 +284,13 @@ SCTS, *PSCTS;
 typedef const SCTS *PCSCTS;
 
 typedef struct tagSCTS_FB {
-    BYTE        bySignalField_b;
-    BYTE        byServiceField_b;
-    WORD        wTransmitLength_b;
-    WORD        wDuration_ba;
-    WORD        wReserved;
-    WORD        wCTSDuration_ba_f0;
-    WORD        wCTSDuration_ba_f1;
+    u8        bySignalField_b;
+    u8        byServiceField_b;
+    u16        wTransmitLength_b;
+    u16        wDuration_ba;
+    u16        wReserved;
+    u16        wCTSDuration_ba_f0;
+    u16        wCTSDuration_ba_f1;
     SCTSData    Data;
 } __attribute__ ((__packed__))
 SCTS_FB, *PSCTS_FB;
@@ -302,17 +302,17 @@ typedef const SCTS_FB *PCSCTS_FB;
  */
 typedef struct tagSTxBufHead {
        u32 adwTxKey[4];
-    WORD    wFIFOCtl;
-    WORD    wTimeStamp;
-    WORD    wFragCtl;
-    WORD    wReserved;
+    u16    wFIFOCtl;
+    u16    wTimeStamp;
+    u16    wFragCtl;
+    u16    wReserved;
 } __attribute__ ((__packed__))
 STxBufHead, *PSTxBufHead;
 typedef const STxBufHead *PCSTxBufHead;
 
 typedef struct tagSTxShortBufHead {
-    WORD    wFIFOCtl;
-    WORD    wTimeStamp;
+    u16    wFIFOCtl;
+    u16    wTimeStamp;
 } __attribute__ ((__packed__))
 STxShortBufHead, *PSTxShortBufHead;
 typedef const STxShortBufHead *PCSTxShortBufHead;
@@ -321,56 +321,56 @@ typedef const STxShortBufHead *PCSTxShortBufHead;
  * TX data header
  */
 typedef struct tagSTxDataHead_g {
-    BYTE    bySignalField_b;
-    BYTE    byServiceField_b;
-    WORD    wTransmitLength_b;
-    BYTE    bySignalField_a;
-    BYTE    byServiceField_a;
-    WORD    wTransmitLength_a;
-    WORD    wDuration_b;
-    WORD    wDuration_a;
-    WORD    wTimeStampOff_b;
-    WORD    wTimeStampOff_a;
+    u8    bySignalField_b;
+    u8    byServiceField_b;
+    u16    wTransmitLength_b;
+    u8    bySignalField_a;
+    u8    byServiceField_a;
+    u16    wTransmitLength_a;
+    u16    wDuration_b;
+    u16    wDuration_a;
+    u16    wTimeStampOff_b;
+    u16    wTimeStampOff_a;
 } __attribute__ ((__packed__))
 STxDataHead_g, *PSTxDataHead_g;
 
 typedef const STxDataHead_g *PCSTxDataHead_g;
 
 typedef struct tagSTxDataHead_g_FB {
-    BYTE    bySignalField_b;
-    BYTE    byServiceField_b;
-    WORD    wTransmitLength_b;
-    BYTE    bySignalField_a;
-    BYTE    byServiceField_a;
-    WORD    wTransmitLength_a;
-    WORD    wDuration_b;
-    WORD    wDuration_a;
-    WORD    wDuration_a_f0;
-    WORD    wDuration_a_f1;
-    WORD    wTimeStampOff_b;
-    WORD    wTimeStampOff_a;
+    u8    bySignalField_b;
+    u8    byServiceField_b;
+    u16    wTransmitLength_b;
+    u8    bySignalField_a;
+    u8    byServiceField_a;
+    u16    wTransmitLength_a;
+    u16    wDuration_b;
+    u16    wDuration_a;
+    u16    wDuration_a_f0;
+    u16    wDuration_a_f1;
+    u16    wTimeStampOff_b;
+    u16    wTimeStampOff_a;
 } __attribute__ ((__packed__))
 STxDataHead_g_FB, *PSTxDataHead_g_FB;
 typedef const STxDataHead_g_FB *PCSTxDataHead_g_FB;
 
 typedef struct tagSTxDataHead_ab {
-    BYTE    bySignalField;
-    BYTE    byServiceField;
-    WORD    wTransmitLength;
-    WORD    wDuration;
-    WORD    wTimeStampOff;
+    u8    bySignalField;
+    u8    byServiceField;
+    u16    wTransmitLength;
+    u16    wDuration;
+    u16    wTimeStampOff;
 } __attribute__ ((__packed__))
 STxDataHead_ab, *PSTxDataHead_ab;
 typedef const STxDataHead_ab *PCSTxDataHead_ab;
 
 typedef struct tagSTxDataHead_a_FB {
-    BYTE    bySignalField;
-    BYTE    byServiceField;
-    WORD    wTransmitLength;
-    WORD    wDuration;
-    WORD    wTimeStampOff;
-    WORD    wDuration_f0;
-    WORD    wDuration_f1;
+    u8    bySignalField;
+    u8    byServiceField;
+    u16    wTransmitLength;
+    u16    wDuration;
+    u16    wTimeStampOff;
+    u16    wDuration_f0;
+    u16    wDuration_f1;
 } __attribute__ ((__packed__))
 STxDataHead_a_FB, *PSTxDataHead_a_FB;
 typedef const STxDataHead_a_FB *PCSTxDataHead_a_FB;
@@ -397,14 +397,14 @@ SBEACONCtl;
 
 typedef struct tagSSecretKey {
        u32 dwLowDword;
-    BYTE    byHighByte;
+    u8    byHighByte;
 } __attribute__ ((__packed__))
 SSecretKey;
 
 typedef struct tagSKeyEntry {
-    BYTE  abyAddrHi[2];
-    WORD  wKCTL;
-    BYTE  abyAddrLo[4];
+    u8  abyAddrHi[2];
+    u16  wKCTL;
+    u8  abyAddrLo[4];
        u32 dwKey0[4];
        u32 dwKey1[4];
        u32 dwKey2[4];
index 6bba2e06fa640c0a45014e2b84f12d99e00f9194..f07ba242811bb7b757b8874b25bbe7d8b4117923 100644 (file)
@@ -45,7 +45,6 @@
 #include <linux/timer.h>
 #include <linux/usb.h>
 
-
 #ifdef SIOCETHTOOL
 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
 #include <linux/ethtool.h>
@@ -66,7 +65,6 @@
  */
 
 #include "device_cfg.h"
-#include "ttype.h"
 #include "80211hdr.h"
 #include "tether.h"
 #include "wmgr.h"
@@ -78,7 +76,6 @@
 #include "key.h"
 #include "card.h"
 
-/*---------------------  Export Definitions -------------------------*/
 #define VNT_USB_VENDOR_ID                     0x160a
 #define VNT_USB_PRODUCT_ID                    0x3184
 
 #define ANT_RXA                 2
 #define ANT_RXB                 3
 
-
 #define MAXCHECKHANGCNT         4
 
 /* Packet type */
 
 #define PRIVATE_Message                 0
 
-/*---------------------  Export Types  ------------------------------*/
-
 #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
 #define PRINT_K(p, args...) { if (PRIVATE_Message) printk(p, ##args); }
 
@@ -191,7 +185,7 @@ typedef struct _USB_SEND_CONTEXT {
     struct urb      *pUrb;
     unsigned int            uBufLen;
     CONTEXT_TYPE    Type;
-    SEthernetHeader sEthHeader;
+    struct ethhdr sEthHeader;
     void *Next;
     bool            bBoolInUse;
     unsigned char           Data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
@@ -212,7 +206,7 @@ typedef struct _DEFAULT_CONFIG {
  */
 typedef struct {
     unsigned int            uDataLen;
-    PBYTE           pDataBuf;
+    u8 *           pDataBuf;
   /* struct urb *pUrb; */
     bool            bInUse;
 } INT_BUFFER, *PINT_BUFFER;
@@ -251,7 +245,6 @@ typedef enum __DEVICE_NDIS_STATUS {
 /* PMKID Structures */
 typedef unsigned char   NDIS_802_11_PMKID_VALUE[16];
 
-
 typedef enum _NDIS_802_11_WEP_STATUS
 {
     Ndis802_11WEPEnabled,
@@ -269,7 +262,6 @@ typedef enum _NDIS_802_11_WEP_STATUS
 } NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
   NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
 
-
 typedef enum _NDIS_802_11_STATUS_TYPE
 {
        Ndis802_11StatusType_Authentication,
@@ -284,7 +276,6 @@ typedef struct _PMKID_CANDIDATE {
     unsigned long Flags;
 } PMKID_CANDIDATE, *PPMKID_CANDIDATE;
 
-
 typedef struct _BSSID_INFO
 {
     NDIS_802_11_MAC_ADDRESS BSSID;
@@ -309,16 +300,16 @@ typedef struct tagSPMKIDCandidateEvent {
 
 typedef struct tagSQuietControl {
     bool        bEnable;
-    DWORD       dwStartTime;
-    BYTE        byPeriod;
-    WORD        wDuration;
+    u32       dwStartTime;
+    u8        byPeriod;
+    u16        wDuration;
 } SQuietControl, *PSQuietControl;
 
 /* The receive duplicate detection cache entry */
 typedef struct tagSCacheEntry{
-    WORD        wFmSequence;
-    BYTE        abyAddr2[ETH_ALEN];
-    WORD        wFrameCtl;
+    u16        wFmSequence;
+    u8        abyAddr2[ETH_ALEN];
+    u16        wFrameCtl;
 } SCacheEntry, *PSCacheEntry;
 
 typedef struct tagSCache{
@@ -335,12 +326,12 @@ typedef struct tagSCache{
  */
 typedef struct tagSDeFragControlBlock
 {
-    WORD            wSequence;
-    WORD            wFragNum;
-    BYTE            abyAddr2[ETH_ALEN];
+    u16            wSequence;
+    u16            wFragNum;
+    u8            abyAddr2[ETH_ALEN];
        unsigned int            uLifetime;
     struct sk_buff* skb;
-    PBYTE           pbyRxBuffer;
+    u8 *           pbyRxBuffer;
     unsigned int            cbFrameLength;
     bool            bInUse;
 } SDeFragControlBlock, *PSDeFragControlBlock;
@@ -371,7 +362,6 @@ typedef struct tagSDeFragControlBlock
 /* for device_set_media_duplex */
 #define     DEVICE_LINK_CHANGE           0x00000001UL
 
-
 typedef struct __device_opt {
        int nRxDescs0;  /* number of RX descriptors 0 */
        int nTxDescs0;  /* number of TX descriptors 0, 1, 2, 3 */
@@ -386,7 +376,6 @@ typedef struct __device_opt {
     u32         flags;
 } OPTIONS, *POPTIONS;
 
-
 struct vnt_private {
        /* netdev */
        struct usb_device *usb;
@@ -420,7 +409,6 @@ struct vnt_private {
        u32 cbFreeDFCB;
        u32 uCurrentDFCBIdx;
 
-
        /* USB */
        struct urb *pControlURB;
        struct urb *pInterruptURB;
@@ -453,7 +441,6 @@ struct vnt_private {
        /* default config from file by user setting */
        DEFAULT_CONFIG config_file;
 
-
        /* Statistic for USB */
        unsigned long ulBulkInPosted;
        unsigned long ulBulkInError;
@@ -470,14 +457,12 @@ struct vnt_private {
        unsigned long ulIntInContCRCError;
        unsigned long ulIntInBytesRead;
 
-
        /* Version control */
        u16 wFirmwareVersion;
        u8 byLocalID;
        u8 byRFType;
        u8 byBBRxConf;
 
-
        u8 byZoneType;
        int bZoneRegExist;
 
@@ -571,7 +556,6 @@ struct vnt_private {
        u8 byTopOFDMBasicRate;
        u8 byTopCCKBasicRate;
 
-
        u32 dwAotoRateTxOkCnt;
        u32 dwAotoRateTxFailCnt;
        u32 dwErrorRateThreshold[13];
@@ -684,7 +668,6 @@ struct vnt_private {
        SKeyManagement sKey;
        u32 dwIVCounter;
 
-
        RC4Ext SBox;
        u8 abyPRNG[WLAN_WEPMAX_KEYLEN+3];
        u8 byKeyIndex;
@@ -701,13 +684,11 @@ struct vnt_private {
        /* QoS */
        int bGrpAckPolicy;
 
-
        u8 byAutoFBCtrl;
 
        int bTxMICFail;
        int bRxMICFail;
 
-
        /* For Update BaseBand VGA Gain Offset */
        int bUpdateBBVGA;
        u32 uBBVGADiffCount;
@@ -719,7 +700,6 @@ struct vnt_private {
        u8 byBBPreEDRSSI;
        u8 byBBPreEDIndex;
 
-
        int bRadioCmd;
        u32 dwDiagRefCount;
 
@@ -747,8 +727,8 @@ struct vnt_private {
        u8 byReAssocCount;
        u8 byLinkWaitCount;
 
-       SEthernetHeader sTxEthHeader;
-       SEthernetHeader sRxEthHeader;
+       struct ethhdr sTxEthHeader;
+       struct ethhdr sRxEthHeader;
        u8 abyBroadcastAddr[ETH_ALEN];
        u8 abySNAP_RFC1042[ETH_ALEN];
        u8 abySNAP_Bridgetunnel[ETH_ALEN];
@@ -757,7 +737,6 @@ struct vnt_private {
        SPMKID gsPMKID;
        SPMKIDCandidateEvent gsPMKIDCandidate;
 
-
        /* for 802.11h */
        int b11hEnable;
 
@@ -788,9 +767,6 @@ struct vnt_private {
 
 };
 
-
-
-
 #define EnqueueRCB(_Head, _Tail, _RCB)                  \
 {                                                       \
     if (!_Head) {                                       \
@@ -812,7 +788,6 @@ struct vnt_private {
     Head = RCB->Next;                                   \
 }
 
-
 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) {   \
     if ((uVar) >= ((uModulo) - 1))                  \
         (uVar) = 0;                                 \
@@ -820,7 +795,6 @@ struct vnt_private {
         (uVar)++;                                   \
 }
 
-
 #define fMP_RESET_IN_PROGRESS               0x00000001
 #define fMP_DISCONNECTED                    0x00000002
 #define fMP_HALT_IN_PROGRESS                0x00000004
@@ -841,8 +815,6 @@ struct vnt_private {
 #define MP_IS_READY(_M)        (((_M)->Flags & \
                                  (fMP_DISCONNECTED | fMP_RESET_IN_PROGRESS | fMP_HALT_IN_PROGRESS | fMP_INIT_IN_PROGRESS | fMP_SURPRISE_REMOVED)) == 0)
 
-/*---------------------  Export Functions  --------------------------*/
-
 int device_alloc_frag_buf(struct vnt_private *, PSDeFragControlBlock pDeF);
 
 #endif
index 62290d0ac195a399e6377fe1e6036c4b44ec91ae..ea66b975fa5b03e4b34cd1a2577641df8a2c0d27 100644 (file)
@@ -29,8 +29,6 @@
 
 #include <linux/types.h>
 
-#include "ttype.h"
-
 typedef
 struct _version {
     unsigned char   major;
index e83f95e1d9a8b3380280e40cdf179925495a39f0..7ec166a2ac81102c98976bba27e08929bb1cbd78 100644 (file)
 #include "datarate.h"
 #include "usbpipe.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 static int          msglevel                =MSG_LEVEL_INFO;
 
-const BYTE acbyRxRate[MAX_RATE] =
+const u8 acbyRxRate[MAX_RATE] =
 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
 
-
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
-
-static BYTE s_byGetRateIdx(BYTE byRate);
+static u8 s_byGetRateIdx(u8 byRate);
 
 static
 void
 s_vGetDASA(
-      PBYTE pbyRxBufferAddr,
+      u8 * pbyRxBufferAddr,
      unsigned int *pcbHeaderSize,
-     PSEthernetHeader psEthHeader
+     struct ethhdr *psEthHeader
     );
 
 static void s_vProcessRxMACHeader(struct vnt_private *pDevice,
@@ -102,8 +90,6 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
        u32 FrameSize, u8 *pbyRsr, int bOnFly, PSKeyItem pKey, u8 *pbyNewRsr,
        s32 *pbExtIV, u16 *pwRxTSC15_0, u32 *pdwRxTSC47_16);
 
-/*---------------------  Export Variables  --------------------------*/
-
 /*+
  *
  * Description:
@@ -129,13 +115,12 @@ static void s_vProcessRxMACHeader(struct vnt_private *pDevice,
        u8 *pbyRxBuffer;
        u32 cbHeaderSize = 0;
        u16 *pwType;
-       PS802_11Header pMACHeader;
+       struct ieee80211_hdr *pMACHeader;
        int ii;
 
+    pMACHeader = (struct ieee80211_hdr *) (pbyRxBufferAddr + cbHeaderSize);
 
-    pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
-
-    s_vGetDASA((PBYTE)pMACHeader, &cbHeaderSize, &pDevice->sRxEthHeader);
+    s_vGetDASA((u8 *)pMACHeader, &cbHeaderSize, &pDevice->sRxEthHeader);
 
     if (bIsWEP) {
         if (bExtIV) {
@@ -150,16 +135,16 @@ static void s_vProcessRxMACHeader(struct vnt_private *pDevice,
         cbHeaderSize += WLAN_HDR_ADDR3_LEN;
     };
 
-    pbyRxBuffer = (PBYTE) (pbyRxBufferAddr + cbHeaderSize);
+    pbyRxBuffer = (u8 *) (pbyRxBufferAddr + cbHeaderSize);
     if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_Bridgetunnel[0])) {
         cbHeaderSize += 6;
     } else if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_RFC1042[0])) {
         cbHeaderSize += 6;
-        pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
+        pwType = (u16 *) (pbyRxBufferAddr + cbHeaderSize);
        if ((*pwType == cpu_to_be16(ETH_P_IPX)) ||
            (*pwType == cpu_to_le16(0xF380))) {
                cbHeaderSize -= 8;
-            pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
+            pwType = (u16 *) (pbyRxBufferAddr + cbHeaderSize);
             if (bIsWEP) {
                 if (bExtIV) {
                     *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8);    // 8 is IV&ExtIV
@@ -174,7 +159,7 @@ static void s_vProcessRxMACHeader(struct vnt_private *pDevice,
     }
     else {
         cbHeaderSize -= 2;
-        pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
+        pwType = (u16 *) (pbyRxBufferAddr + cbHeaderSize);
         if (bIsWEP) {
             if (bExtIV) {
                 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8);    // 8 is IV&ExtIV
@@ -188,21 +173,18 @@ static void s_vProcessRxMACHeader(struct vnt_private *pDevice,
     }
 
     cbHeaderSize -= (ETH_ALEN * 2);
-    pbyRxBuffer = (PBYTE) (pbyRxBufferAddr + cbHeaderSize);
+    pbyRxBuffer = (u8 *) (pbyRxBufferAddr + cbHeaderSize);
     for (ii = 0; ii < ETH_ALEN; ii++)
-        *pbyRxBuffer++ = pDevice->sRxEthHeader.abyDstAddr[ii];
+        *pbyRxBuffer++ = pDevice->sRxEthHeader.h_dest[ii];
     for (ii = 0; ii < ETH_ALEN; ii++)
-        *pbyRxBuffer++ = pDevice->sRxEthHeader.abySrcAddr[ii];
+        *pbyRxBuffer++ = pDevice->sRxEthHeader.h_source[ii];
 
     *pcbHeadSize = cbHeaderSize;
 }
 
-
-
-
-static BYTE s_byGetRateIdx(BYTE byRate)
+static u8 s_byGetRateIdx(u8 byRate)
 {
-    BYTE    byRateIdx;
+    u8    byRateIdx;
 
     for (byRateIdx = 0; byRateIdx <MAX_RATE ; byRateIdx++) {
         if (acbyRxRate[byRateIdx%MAX_RATE] == byRate)
@@ -211,61 +193,59 @@ static BYTE s_byGetRateIdx(BYTE byRate)
     return 0;
 }
 
-
 static
 void
 s_vGetDASA (
-      PBYTE pbyRxBufferAddr,
+      u8 * pbyRxBufferAddr,
      unsigned int *pcbHeaderSize,
-     PSEthernetHeader psEthHeader
+     struct ethhdr *psEthHeader
     )
 {
        unsigned int            cbHeaderSize = 0;
-       PS802_11Header  pMACHeader;
+       struct ieee80211_hdr *pMACHeader;
        int             ii;
 
-       pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
+       pMACHeader = (struct ieee80211_hdr *) (pbyRxBufferAddr + cbHeaderSize);
 
-       if ((pMACHeader->wFrameCtl & FC_TODS) == 0) {
-               if (pMACHeader->wFrameCtl & FC_FROMDS) {
+       if ((pMACHeader->frame_control & FC_TODS) == 0) {
+               if (pMACHeader->frame_control & FC_FROMDS) {
                        for (ii = 0; ii < ETH_ALEN; ii++) {
-                               psEthHeader->abyDstAddr[ii] =
-                                       pMACHeader->abyAddr1[ii];
-                               psEthHeader->abySrcAddr[ii] =
-                                       pMACHeader->abyAddr3[ii];
+                               psEthHeader->h_dest[ii] =
+                                       pMACHeader->addr1[ii];
+                               psEthHeader->h_source[ii] =
+                                       pMACHeader->addr3[ii];
                        }
                } else {
                        /* IBSS mode */
                        for (ii = 0; ii < ETH_ALEN; ii++) {
-                               psEthHeader->abyDstAddr[ii] =
-                                       pMACHeader->abyAddr1[ii];
-                               psEthHeader->abySrcAddr[ii] =
-                                       pMACHeader->abyAddr2[ii];
+                               psEthHeader->h_dest[ii] =
+                                       pMACHeader->addr1[ii];
+                               psEthHeader->h_source[ii] =
+                                       pMACHeader->addr2[ii];
                        }
                }
        } else {
                /* Is AP mode.. */
-               if (pMACHeader->wFrameCtl & FC_FROMDS) {
+               if (pMACHeader->frame_control & FC_FROMDS) {
                        for (ii = 0; ii < ETH_ALEN; ii++) {
-                               psEthHeader->abyDstAddr[ii] =
-                                       pMACHeader->abyAddr3[ii];
-                               psEthHeader->abySrcAddr[ii] =
-                                       pMACHeader->abyAddr4[ii];
+                               psEthHeader->h_dest[ii] =
+                                       pMACHeader->addr3[ii];
+                               psEthHeader->h_source[ii] =
+                                       pMACHeader->addr4[ii];
                                cbHeaderSize += 6;
                        }
                } else {
                        for (ii = 0; ii < ETH_ALEN; ii++) {
-                               psEthHeader->abyDstAddr[ii] =
-                                       pMACHeader->abyAddr3[ii];
-                               psEthHeader->abySrcAddr[ii] =
-                                       pMACHeader->abyAddr2[ii];
+                               psEthHeader->h_dest[ii] =
+                                       pMACHeader->addr3[ii];
+                               psEthHeader->h_source[ii] =
+                                       pMACHeader->addr2[ii];
                        }
                }
        };
     *pcbHeaderSize = cbHeaderSize;
 }
 
-
 int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
        unsigned long BytesToIndicate)
 {
@@ -273,7 +253,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
        struct sk_buff *skb;
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
        struct vnt_rx_mgmt *pRxPacket = &pMgmt->sRxPacket;
-       PS802_11Header p802_11Header;
+       struct ieee80211_hdr *p802_11Header;
        u8 *pbyRsr, *pbyNewRsr, *pbyRSSI, *pbyFrame;
        u64 *pqwTSFTime;
        u32 bDeFragRx = false;
@@ -297,10 +277,9 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
        u8 abyVaildRate[MAX_RATE]
                = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
        u16 wPLCPwithPadding;
-       PS802_11Header pMACHeader;
+       struct ieee80211_hdr *pMACHeader;
        int bRxeapol_key = false;
 
-
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- RXbBulkInProcessData---\n");
 
     skb = pRCB->skb;
@@ -321,14 +300,14 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
         return false;
     }
 
-    pbyDAddress = (PBYTE)(skb->data);
+    pbyDAddress = (u8 *)(skb->data);
     pbyRxSts = pbyDAddress+4;
     pbyRxRate = pbyDAddress+5;
 
     //real Frame Size = USBFrameSize -4WbkStatus - 4RxStatus - 8TSF - 4RSR - 4SQ3 - ?Padding
     //if SQ3 the range is 24~27, if no SQ3 the range is 20~23
     //real Frame size in PLCPLength field.
-    pwPLCP_Length = (PWORD) (pbyDAddress + 6);
+    pwPLCP_Length = (u16 *) (pbyDAddress + 6);
     //Fix hardware bug => PLCP_Length error
     if ( ((BytesToIndicate - (*pwPLCP_Length)) > 27) ||
          ((BytesToIndicate - (*pwPLCP_Length)) < 24) ||
@@ -377,45 +356,43 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
                             FrameSize
                             );
 
-
-    pMACHeader = (PS802_11Header) pbyFrame;
+    pMACHeader = (struct ieee80211_hdr *) pbyFrame;
 
 //mike add: to judge if current AP is activated?
     if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
         (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
        if (pMgmt->sNodeDBTable[0].bActive) {
-        if (!compare_ether_addr(pMgmt->abyCurrBSSID, pMACHeader->abyAddr2)) {
+        if (!compare_ether_addr(pMgmt->abyCurrBSSID, pMACHeader->addr2)) {
            if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
                   pMgmt->sNodeDBTable[0].uInActiveCount = 0;
            }
        }
     }
 
-    if (!is_multicast_ether_addr(pMACHeader->abyAddr1)) {
-        if ( WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header) pbyFrame) ) {
+    if (!is_multicast_ether_addr(pMACHeader->addr1)) {
+        if (WCTLbIsDuplicate(&(pDevice->sDupRxCache), (struct ieee80211_hdr *) pbyFrame)) {
             pDevice->s802_11Counter.FrameDuplicateCount++;
             return false;
         }
 
        if (compare_ether_addr(pDevice->abyCurrentNetAddr,
-                              pMACHeader->abyAddr1)) {
+                              pMACHeader->addr1)) {
                return false;
         }
     }
 
-
     // Use for TKIP MIC
     s_vGetDASA(pbyFrame, &cbHeaderSize, &pDevice->sRxEthHeader);
 
-    if (!compare_ether_addr((PBYTE)&(pDevice->sRxEthHeader.abySrcAddr[0]),
+    if (!compare_ether_addr((u8 *)&(pDevice->sRxEthHeader.h_source[0]),
                            pDevice->abyCurrentNetAddr))
         return false;
 
     if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
         if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
-            p802_11Header = (PS802_11Header) (pbyFrame);
+            p802_11Header = (struct ieee80211_hdr *) (pbyFrame);
             // get SA NodeIndex
-            if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p802_11Header->abyAddr2), &iSANodeIndex)) {
+            if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p802_11Header->addr2), &iSANodeIndex)) {
                 pMgmt->sNodeDBTable[iSANodeIndex].ulLastRxJiffer = jiffies;
                 pMgmt->sNodeDBTable[iSANodeIndex].uInActiveCount = 0;
             }
@@ -428,7 +405,6 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
         }
     }
 
-
     if (IS_FC_WEP(pbyFrame)) {
         bool     bRxDecryOK = false;
 
@@ -497,7 +473,6 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
             FrameSize -= 4;         // 4 is ICV
     }
 
-
     //
     // RX OK
     //
@@ -508,7 +483,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
         (IS_FRAGMENT_PKT((pbyFrame)))
         ) {
         // defragment
-        bDeFragRx = WCTLbHandleFragment(pDevice, (PS802_11Header) (pbyFrame), FrameSize, bIsWEP, bExtIV);
+        bDeFragRx = WCTLbHandleFragment(pDevice, (struct ieee80211_hdr *) (pbyFrame), FrameSize, bIsWEP, bExtIV);
         pDevice->s802_11Counter.ReceivedFragmentCount++;
         if (bDeFragRx) {
             // defrag complete
@@ -529,8 +504,8 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
         // Handle Control & Manage Frame
 
         if (IS_TYPE_MGMT((pbyFrame))) {
-            PBYTE pbyData1;
-            PBYTE pbyData2;
+            u8 * pbyData1;
+            u8 * pbyData2;
 
             pRxPacket = &(pRCB->sMngPacket);
             pRxPacket->p80211Header = (PUWLAN_80211HDR)(pbyFrame);
@@ -622,10 +597,10 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
             }
    //mike add:station mode check eapol-key challenge--->
          {
-           BYTE  Protocol_Version;    //802.1x Authentication
-           BYTE  Packet_Type;           //802.1x Authentication
-           BYTE  Descriptor_type;
-             WORD Key_info;
+           u8  Protocol_Version;    //802.1x Authentication
+           u8  Packet_Type;           //802.1x Authentication
+           u8  Descriptor_type;
+             u16 Key_info;
               if (bIsWEP)
                   cbIVOffset = 8;
               else
@@ -653,10 +628,8 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
         }
     }
 
-
 // Data frame Handle
 
-
     if (pDevice->bEnablePSMode) {
         if (IS_FC_MOREDATA((pbyFrame))) {
             if (*pbyRsr & RSR_ADDROK) {
@@ -699,11 +672,10 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
     }
 */
 
-
     // -----------------------------------------------
 
     if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == true)){
-        BYTE    abyMacHdr[24];
+        u8    abyMacHdr[24];
 
         // Only 802.1x packet incoming allowed
         if (bIsWEP)
@@ -739,7 +711,6 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
             return false;
     }
 
-
     if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
         if (bIsWEP) {
             FrameSize -= 8;  //MIC
@@ -750,44 +721,42 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
     // Soft MIC
     if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
         if (bIsWEP) {
-            PDWORD          pdwMIC_L;
-            PDWORD          pdwMIC_R;
-            DWORD           dwMIC_Priority;
-            DWORD           dwMICKey0 = 0, dwMICKey1 = 0;
-            DWORD           dwLocalMIC_L = 0;
-            DWORD           dwLocalMIC_R = 0;
-
+            u32 *          pdwMIC_L;
+            u32 *          pdwMIC_R;
+            u32           dwMIC_Priority;
+            u32           dwMICKey0 = 0, dwMICKey1 = 0;
+            u32           dwLocalMIC_L = 0;
+            u32           dwLocalMIC_R = 0;
 
             if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
-                dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
-                dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
+                dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[24]));
+                dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[28]));
             }
             else {
                 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
-                    dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
-                    dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
+                    dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[16]));
+                    dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[20]));
                 } else if ((pKey->dwKeyIndex & BIT28) == 0) {
-                    dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
-                    dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
+                    dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[16]));
+                    dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[20]));
                 } else {
-                    dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
-                    dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
+                    dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[24]));
+                    dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[28]));
                 }
             }
 
             MIC_vInit(dwMICKey0, dwMICKey1);
-            MIC_vAppend((PBYTE)&(pDevice->sRxEthHeader.abyDstAddr[0]), 12);
+            MIC_vAppend((u8 *)&(pDevice->sRxEthHeader.h_dest[0]), 12);
             dwMIC_Priority = 0;
-            MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
+            MIC_vAppend((u8 *)&dwMIC_Priority, 4);
             // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
-            MIC_vAppend((PBYTE)(skb->data + 8 + WLAN_HDR_ADDR3_LEN + 8),
+            MIC_vAppend((u8 *)(skb->data + 8 + WLAN_HDR_ADDR3_LEN + 8),
                         FrameSize - WLAN_HDR_ADDR3_LEN - 8);
             MIC_vGetMIC(&dwLocalMIC_L, &dwLocalMIC_R);
             MIC_vUnInit();
 
-            pdwMIC_L = (PDWORD)(skb->data + 8 + FrameSize);
-            pdwMIC_R = (PDWORD)(skb->data + 8 + FrameSize + 4);
-
+            pdwMIC_L = (u32 *)(skb->data + 8 + FrameSize);
+            pdwMIC_R = (u32 *)(skb->data + 8 + FrameSize + 4);
 
             if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) ||
                 (pDevice->bRxMICFail == true)) {
@@ -818,7 +787,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
                                        }
 
                                        ev.src_addr.sa_family = ARPHRD_ETHER;
-                                       memcpy(ev.src_addr.sa_data, pMACHeader->abyAddr2, ETH_ALEN);
+                                       memcpy(ev.src_addr.sa_data, pMACHeader->addr2, ETH_ALEN);
                                        memset(&wrqu, 0, sizeof(wrqu));
                                        wrqu.data.length = sizeof(ev);
                        PRINT_K("wireless_send_event--->IWEVMICHAELMICFAILURE\n");
@@ -837,13 +806,13 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
     if ((pKey != NULL) && ((pKey->byCipherSuite == KEY_CTL_TKIP) ||
                            (pKey->byCipherSuite == KEY_CTL_CCMP))) {
         if (bIsWEP) {
-            WORD        wLocalTSC15_0 = 0;
-            DWORD       dwLocalTSC47_16 = 0;
+            u16        wLocalTSC15_0 = 0;
+            u32       dwLocalTSC47_16 = 0;
            unsigned long long       RSC = 0;
             // endian issues
            RSC = *((unsigned long long *) &(pKey->KeyRSC));
-            wLocalTSC15_0 = (WORD) RSC;
-            dwLocalTSC47_16 = (DWORD) (RSC>>16);
+            wLocalTSC15_0 = (u16) RSC;
+            dwLocalTSC47_16 = (u32) (RSC>>16);
 
             RSC = dwRxTSC47_16;
             RSC <<= 16;
@@ -876,8 +845,7 @@ int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
         }
     } // ----- End of Reply Counter Check --------------------------
 
-
-    s_vProcessRxMACHeader(pDevice, (PBYTE)(skb->data+8), FrameSize, bIsWEP, bExtIV, &cbHeaderOffset);
+    s_vProcessRxMACHeader(pDevice, (u8 *)(skb->data+8), FrameSize, bIsWEP, bExtIV, &cbHeaderOffset);
     FrameSize -= cbHeaderOffset;
     cbHeaderOffset += 8;        // 8 is Rcv buffer header
 
@@ -928,13 +896,12 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame,
        s32 iSANodeIndex)
 {
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
-       PS802_11Header p802_11Header;
+       struct ieee80211_hdr *p802_11Header;
        CMD_STATUS Status;
 
-
     if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
 
-        p802_11Header = (PS802_11Header) (pbyFrame);
+        p802_11Header = (struct ieee80211_hdr *) (pbyFrame);
         if (!IS_TYPE_MGMT(pbyFrame)) {
 
             // Data & PS-Poll packet
@@ -946,7 +913,7 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame,
                     // reason = (6) class 2 received from nonauth sta
                     vMgrDeAuthenBeginSta(pDevice,
                                          pMgmt,
-                                         (PBYTE)(p802_11Header->abyAddr2),
+                                         (u8 *)(p802_11Header->addr2),
                                          (WLAN_MGMT_REASON_CLASS2_NONAUTH),
                                          &Status
                                          );
@@ -958,7 +925,7 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame,
                     // reason = (7) class 3 received from nonassoc sta
                     vMgrDisassocBeginSta(pDevice,
                                          pMgmt,
-                                         (PBYTE)(p802_11Header->abyAddr2),
+                                         (u8 *)(p802_11Header->addr2),
                                          (WLAN_MGMT_REASON_CLASS3_NONASSOC),
                                          &Status
                                          );
@@ -1011,18 +978,18 @@ static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame,
             else {
                   vMgrDeAuthenBeginSta(pDevice,
                                        pMgmt,
-                                       (PBYTE)(p802_11Header->abyAddr2),
+                                       (u8 *)(p802_11Header->addr2),
                                        (WLAN_MGMT_REASON_CLASS2_NONAUTH),
                                        &Status
                                        );
                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 3\n");
                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSID:%pM\n",
-                               p802_11Header->abyAddr3);
+                               p802_11Header->addr3);
                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR2:%pM\n",
-                               p802_11Header->abyAddr2);
+                               p802_11Header->addr2);
                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%pM\n",
-                               p802_11Header->abyAddr1);
-                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl );
+                               p802_11Header->addr1);
+                    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: frame_control= %x\n", p802_11Header->frame_control);
                     return true;
             }
         }
@@ -1042,13 +1009,12 @@ static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
        PSKeyItem pKey = NULL;
        u8 byDecMode = KEY_CTL_WEP;
 
-
     *pwRxTSC15_0 = 0;
     *pdwRxTSC47_16 = 0;
 
     pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
-    if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
-         WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
+    if ( WLAN_GET_FC_TODS(*(u16 *)pbyFrame) &&
+         WLAN_GET_FC_FROMDS(*(u16 *)pbyFrame) ) {
          pbyIV += 6;             // 6 is 802.11 address4
          PayloadLen -= 6;
     }
@@ -1136,12 +1102,12 @@ static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
         // TKIP/AES
 
         PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
-        *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
+        *pdwRxTSC47_16 = cpu_to_le32(*(u32 *)(pbyIV + 4));
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %x\n", *pdwRxTSC47_16);
         if (byDecMode == KEY_CTL_TKIP) {
             *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
         } else {
-            *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
+            *pwRxTSC15_0 = cpu_to_le16(*(u16 *)pbyIV);
         }
         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
 
@@ -1149,8 +1115,8 @@ static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
             (pDevice->byLocalID <= REV_ID_VT3253_A1)) {
             // Software TKIP
             // 1. 3253 A
-            PS802_11Header  pMACHeader = (PS802_11Header) (pbyFrame);
-            TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
+            struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *) (pbyFrame);
+            TKIPvMixKey(pKey->abyKey, pMACHeader->addr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
             rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
             rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
             if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
@@ -1173,7 +1139,7 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
        s32 *pbExtIV, u16 *pwRxTSC15_0, u32 *pdwRxTSC47_16)
 {
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
-       PS802_11Header  pMACHeader;
+       struct ieee80211_hdr *pMACHeader;
        u32 PayloadLen = FrameSize;
        u8 *pbyIV;
        u8 byKeyIdx;
@@ -1183,8 +1149,8 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
        *pdwRxTSC47_16 = 0;
 
     pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
-    if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
-         WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
+    if ( WLAN_GET_FC_TODS(*(u16 *)pbyFrame) &&
+         WLAN_GET_FC_FROMDS(*(u16 *)pbyFrame) ) {
          pbyIV += 6;             // 6 is 802.11 address4
          PayloadLen -= 6;
     }
@@ -1192,7 +1158,6 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
     byKeyIdx >>= 6;
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
 
-
     if (pMgmt->byCSSGK == KEY_CTL_TKIP)
         byDecMode = KEY_CTL_TKIP;
     else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
@@ -1235,13 +1200,13 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
         // TKIP/AES
 
         PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
-        *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
+        *pdwRxTSC47_16 = cpu_to_le32(*(u32 *)(pbyIV + 4));
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %x\n", *pdwRxTSC47_16);
 
         if (byDecMode == KEY_CTL_TKIP) {
             *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
         } else {
-            *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
+            *pwRxTSC15_0 = cpu_to_le16(*(u16 *)pbyIV);
         }
         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
 
@@ -1252,8 +1217,8 @@ static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
                 // 1. 3253 A
                 // 2. NotOnFly
                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_TKIP \n");
-                pMACHeader = (PS802_11Header) (pbyFrame);
-                TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
+                pMACHeader = (struct ieee80211_hdr *) (pbyFrame);
+                TKIPvMixKey(pKey->abyKey, pMACHeader->addr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
                 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
                 rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
                 if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
@@ -1297,11 +1262,10 @@ static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb,
        u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
        u16 wAID;
 
-
     if (FrameSize > CB_MAX_BUF_SIZE)
         return false;
     // check DA
-    if (is_multicast_ether_addr((PBYTE)(skb->data+cbHeaderOffset))) {
+    if (is_multicast_ether_addr((u8 *)(skb->data+cbHeaderOffset))) {
        if (pMgmt->sNodeDBTable[0].bPSEnable) {
 
            skbcpy = dev_alloc_skb((int)pDevice->rx_buf_sz);
@@ -1326,7 +1290,7 @@ static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb,
     }
     else {
         // check if relay
-        if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(skb->data+cbHeaderOffset), &iDANodeIndex)) {
+        if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data+cbHeaderOffset), &iDANodeIndex)) {
             if (pMgmt->sNodeDBTable[iDANodeIndex].eNodeState >= NODE_ASSOC) {
                 if (pMgmt->sNodeDBTable[iDANodeIndex].bPSEnable) {
                     // queue this skb until next PS tx, and then release.
@@ -1356,7 +1320,7 @@ static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb,
             iDANodeIndex = 0;
 
         if ((pDevice->uAssocCount > 1) && (iDANodeIndex >= 0)) {
-               bRelayPacketSend(pDevice, (PBYTE) (skb->data + cbHeaderOffset),
+               bRelayPacketSend(pDevice, (u8 *) (skb->data + cbHeaderOffset),
                                 FrameSize, (unsigned int) iDANodeIndex);
         }
 
@@ -1370,9 +1334,6 @@ static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb,
     return true;
 }
 
-
-
-
 void RXvWorkItem(struct vnt_private *pDevice)
 {
        int ntStatus;
@@ -1395,12 +1356,10 @@ void RXvWorkItem(struct vnt_private *pDevice)
 
 }
 
-
 void RXvFreeRCB(PRCB pRCB, int bReAllocSkb)
 {
        struct vnt_private *pDevice = pRCB->pDevice;
 
-
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->RXvFreeRCB\n");
 
     ASSERT(!pRCB->Ref);     // should be 0
@@ -1426,7 +1385,6 @@ void RXvFreeRCB(PRCB pRCB, int bReAllocSkb)
     EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB);
     pDevice->NumRecvFreeList++;
 
-
     if ((pDevice->Flags & fMP_POST_READS) && MP_IS_READY(pDevice) &&
         (pDevice->bIsRxWorkItemQueued == false) ) {
 
@@ -1436,7 +1394,6 @@ void RXvFreeRCB(PRCB pRCB, int bReAllocSkb)
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----RXFreeRCB %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList);
 }
 
-
 void RXvMngWorkItem(struct vnt_private *pDevice)
 {
        PRCB pRCB = NULL;
@@ -1471,4 +1428,3 @@ void RXvMngWorkItem(struct vnt_private *pDevice)
 
 }
 
-
index 786c523f547975c4da00ef788dcc0e5677ca868c..876468f2c3d2924e2d954ec998e086dd895d81fc 100644 (file)
 #ifndef __DPC_H__
 #define __DPC_H__
 
-#include "ttype.h"
 #include "device.h"
 #include "wcmd.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 void RXvWorkItem(void *Context);
 
 void RXvMngWorkItem(void *Context);
index 4371a77e9adc72f86fa56ee76a1f70f27c052567..a1dc3a4cfd9c1e6a47583ea425cfb42ab7d59404 100644 (file)
@@ -35,8 +35,6 @@
 #include "control.h"
 #include "rndis.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
 static int          msglevel                =MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 
@@ -45,17 +43,6 @@ static int          msglevel                =MSG_LEVEL_INFO;
 
 #define FIRMWARE_CHUNK_SIZE    0x400
 
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
-
 int FIRMWAREbDownload(struct vnt_private *pDevice)
 {
        struct device *dev = &pDevice->usb->dev;
@@ -66,7 +53,6 @@ int FIRMWAREbDownload(struct vnt_private *pDevice)
        u16 wLength;
        int ii, rc;
 
-
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Download firmware\n");
        spin_unlock_irq(&pDevice->lock);
 
@@ -132,7 +118,6 @@ int FIRMWAREbBrach2Sram(struct vnt_private *pDevice)
     }
 }
 
-
 int FIRMWAREbCheckVersion(struct vnt_private *pDevice)
 {
        int ntStatus;
@@ -142,7 +127,7 @@ int FIRMWAREbCheckVersion(struct vnt_private *pDevice)
                                     0,
                                     MESSAGE_REQUEST_VERSION,
                                     2,
-                                    (PBYTE) &(pDevice->wFirmwareVersion));
+                                    (u8 *) &(pDevice->wFirmwareVersion));
 
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
     if (ntStatus != STATUS_SUCCESS) {
index ebab3a6351b3d2369cca25916f617f30ad8e16b6..e3b08db6a7347a02fc9932972aa64b00beb3f6e9 100644 (file)
 #ifndef __FIRMWARE_H__
 #define __FIRMWARE_H__
 
-#include "ttype.h"
 #include "device.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 int FIRMWAREbDownload(struct vnt_private *);
 int FIRMWAREbBrach2Sram(struct vnt_private *);
 int FIRMWAREbCheckVersion(struct vnt_private *);
index bc5e9da475862bff35d321897a247234e66d5ac0..f4f1bf7a30fdff871cedd0cceaeb95b2cd8c24c7 100644 (file)
@@ -142,7 +142,6 @@ static int hostap_disable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
        return 0;
 }
 
-
 /*
  * Description:
  *      Set enable/disable hostapd mode
@@ -174,7 +173,6 @@ int vt6656_hostap_set_hostapd(struct vnt_private *pDevice,
                return hostap_disable_hostapd(pDevice, rtnl_locked);
 }
 
-
 /*
  * Description:
  *      remove station function supported for hostap daemon
@@ -193,7 +191,6 @@ static int hostap_remove_sta(struct vnt_private *pDevice,
 {
        unsigned int uNodeIndex;
 
-
     if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
         BSSvRemoveOneNode(pDevice, uNodeIndex);
     }
@@ -242,7 +239,7 @@ static int hostap_add_sta(struct vnt_private *pDevice,
     pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
             WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo);
 
-    pMgmt->sNodeDBTable[uNodeIndex].wAID = (WORD)param->u.add_sta.aid;
+    pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)param->u.add_sta.aid;
 
     pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies;
 
@@ -294,7 +291,6 @@ static int hostap_get_info_sta(struct vnt_private *pDevice,
        return 0;
 }
 
-
 /*
  * Description:
  *      set station flag
@@ -327,8 +323,6 @@ static int hostap_set_flags_sta(struct vnt_private *pDevice,
        return 0;
 }
 
-
-
 /*
  * Description:
  *      set generic element (wpa ie)
@@ -347,8 +341,6 @@ static int hostap_set_generic_element(struct vnt_private *pDevice,
 {
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
 
-
-
     memcpy( pMgmt->abyWPAIE,
             param->u.generic_elem.data,
             param->u.generic_elem.len
@@ -425,13 +417,11 @@ static int hostap_set_encryption(struct vnt_private *pDevice,
        int bKeyTableFull = false;
        u16 wKeyCtl = 0;
 
-
        param->u.crypt.err = 0;
 
        if (param->u.crypt.alg > WPA_ALG_CCMP)
                return -EINVAL;
 
-
        if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) {
                param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n");
@@ -489,9 +479,9 @@ static int hostap_set_encryption(struct vnt_private *pDevice,
             param->u.crypt.key_len
            );
 
-    dwKeyIndex = (DWORD)(param->u.crypt.idx);
+    dwKeyIndex = (u32)(param->u.crypt.idx);
     if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
-        pDevice->byKeyIndex = (BYTE)dwKeyIndex;
+        pDevice->byKeyIndex = (u8)dwKeyIndex;
         pDevice->bTransmitKey = true;
         dwKeyIndex |= (1 << 31);
     }
@@ -515,11 +505,10 @@ static int hostap_set_encryption(struct vnt_private *pDevice,
                        &param->sta_addr[0],
                        dwKeyIndex & ~(USE_KEYRSC),
                        param->u.crypt.key_len,
-                       &KeyRSC, (PBYTE)abyKey,
+                       &KeyRSC, (u8 *)abyKey,
                        KEY_CTL_WEP
                            ) == true) {
 
-
                 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
 
             } else {
@@ -565,7 +554,6 @@ static int hostap_set_encryption(struct vnt_private *pDevice,
         pMgmt->byCSSGK = KEY_CTL_CCMP;
     }
 
-
     if (iNodeIndex == 0) {
        KeybSetDefaultKey(  pDevice,
                            &(pDevice->sKey),
@@ -585,7 +573,7 @@ static int hostap_set_encryption(struct vnt_private *pDevice,
                        dwKeyIndex,
                        param->u.crypt.key_len,
                        &KeyRSC,
-                       (PBYTE)abyKey,
+                       (u8 *)abyKey,
                         byKeyDecMode
                        ) == true) {
 
@@ -631,8 +619,6 @@ static int hostap_set_encryption(struct vnt_private *pDevice,
        return ret;
 }
 
-
-
 /*
  * Description:
  *      get each stations encryption key
@@ -655,7 +641,6 @@ static int hostap_get_encryption(struct vnt_private *pDevice,
        int ii;
        s32 iNodeIndex = 0;
 
-
        param->u.crypt.err = 0;
 
        if (is_broadcast_ether_addr(param->sta_addr)) {
@@ -670,13 +655,12 @@ static int hostap_get_encryption(struct vnt_private *pDevice,
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: %d\n", iNodeIndex);
     memset(param->u.crypt.seq, 0, 8);
     for (ii = 0 ; ii < 8 ; ii++) {
-        param->u.crypt.seq[ii] = (BYTE)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
+        param->u.crypt.seq[ii] = (u8)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
     }
 
        return ret;
 }
 
-
 /*
  * Description:
  *      vt6656_hostap_ioctl main function supported for hostap daemon.
@@ -779,7 +763,6 @@ int vt6656_hostap_ioctl(struct vnt_private *pDevice, struct iw_point *p)
                goto out;
        }
 
-
        if ((ret == 0) && ap_ioctl) {
                if (copy_to_user(p->pointer, param, p->length)) {
                        ret = -EFAULT;
index f5656cd96a8f307d8d2004058a7b280101ba6a02..6a68f7e69cffe6e45af79cead5566bb72e4c151b 100644 (file)
@@ -31,8 +31,6 @@
 
 #include "device.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
 #define WLAN_RATE_1M    BIT0
 #define WLAN_RATE_2M    BIT1
 #define WLAN_RATE_5M5   BIT2
 #define WLAN_RATE_48M   BIT10
 #define WLAN_RATE_54M   BIT11
 
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 #ifndef ETH_P_PAE
 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
 #endif /* ETH_P_PAE */
index 51990bd3dd457f6b439c11d4fc4049a5dd6c51d2..a2b4ba6d4f010720f45c94736a0ec17382003932 100644 (file)
 #include "bssdb.h"
 #include "usbpipe.h"
 
-/*---------------------  Static Definitions -------------------------*/
 static int msglevel = MSG_LEVEL_INFO; /* MSG_LEVEL_DEBUG */
 
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 /*+
  *
  *  Function:   InterruptPollingThread
@@ -98,8 +87,8 @@ void INTnsProcessData(struct vnt_private *pDevice)
        pINTData = (PSINTData) pDevice->intBuf.pDataBuf;
        if (pINTData->byTSR0 & TSR_VALID) {
                STAvUpdateTDStatCounter(&(pDevice->scStatistic),
-                                       (BYTE)(pINTData->byPkt0 & 0x0F),
-                                       (BYTE)(pINTData->byPkt0>>4),
+                                       (u8)(pINTData->byPkt0 & 0x0F),
+                                       (u8)(pINTData->byPkt0>>4),
                                        pINTData->byTSR0);
                BSSvUpdateNodeTxCounter(pDevice,
                                        &(pDevice->scStatistic),
@@ -109,8 +98,8 @@ void INTnsProcessData(struct vnt_private *pDevice)
        }
        if (pINTData->byTSR1 & TSR_VALID) {
                STAvUpdateTDStatCounter(&(pDevice->scStatistic),
-                                       (BYTE)(pINTData->byPkt1 & 0x0F),
-                                       (BYTE)(pINTData->byPkt1>>4),
+                                       (u8)(pINTData->byPkt1 & 0x0F),
+                                       (u8)(pINTData->byPkt1>>4),
                                        pINTData->byTSR1);
                BSSvUpdateNodeTxCounter(pDevice,
                                        &(pDevice->scStatistic),
@@ -120,8 +109,8 @@ void INTnsProcessData(struct vnt_private *pDevice)
        }
        if (pINTData->byTSR2 & TSR_VALID) {
                STAvUpdateTDStatCounter(&(pDevice->scStatistic),
-                                       (BYTE)(pINTData->byPkt2 & 0x0F),
-                                       (BYTE)(pINTData->byPkt2>>4),
+                                       (u8)(pINTData->byPkt2 & 0x0F),
+                                       (u8)(pINTData->byPkt2>>4),
                                        pINTData->byTSR2);
                BSSvUpdateNodeTxCounter(pDevice,
                                        &(pDevice->scStatistic),
@@ -131,8 +120,8 @@ void INTnsProcessData(struct vnt_private *pDevice)
        }
        if (pINTData->byTSR3 & TSR_VALID) {
                STAvUpdateTDStatCounter(&(pDevice->scStatistic),
-                                       (BYTE)(pINTData->byPkt3 & 0x0F),
-                                       (BYTE)(pINTData->byPkt3>>4),
+                                       (u8)(pINTData->byPkt3 & 0x0F),
+                                       (u8)(pINTData->byPkt3>>4),
                                        pINTData->byTSR3);
                BSSvUpdateNodeTxCounter(pDevice,
                                        &(pDevice->scStatistic),
index 27c725f1ce1189bee0362cbde8f10d285b901abf..8e6e217ba4ffe8b7247f3947ab5a086a106aa525 100644 (file)
 #ifndef __INT_H__
 #define __INT_H__
 
-#include "ttype.h"
 #include "device.h"
 
-/*---------------------  Export Definitions -------------------------*/
 typedef struct tagSINTData {
-       BYTE byTSR0;
-       BYTE byPkt0;
-       WORD wTime0;
-       BYTE byTSR1;
-       BYTE byPkt1;
-       WORD wTime1;
-       BYTE byTSR2;
-       BYTE byPkt2;
-       WORD wTime2;
-       BYTE byTSR3;
-       BYTE byPkt3;
-       WORD wTime3;
+       u8 byTSR0;
+       u8 byPkt0;
+       u16 wTime0;
+       u8 byTSR1;
+       u8 byPkt1;
+       u16 wTime1;
+       u8 byTSR2;
+       u8 byPkt2;
+       u16 wTime2;
+       u8 byTSR3;
+       u8 byPkt3;
+       u16 wTime3;
        u64 qwTSF;
-       BYTE byISR0;
-       BYTE byISR1;
-       BYTE byRTSSuccess;
-       BYTE byRTSFail;
-       BYTE byACKFail;
-       BYTE byFCSErr;
-       BYTE abySW[2];
+       u8 byISR0;
+       u8 byISR1;
+       u8 byRTSSuccess;
+       u8 byRTSFail;
+       u8 byACKFail;
+       u8 byFCSErr;
+       u8 abySW[2];
 } __attribute__ ((__packed__))
 SINTData, *PSINTData;
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 void INTvWorkItem(struct vnt_private *);
 void INTnsProcessData(struct vnt_private *);
 
index c354a77964d8664cc354af8f9a898692b365ba53..f3406da7336e0cab1c3f32a176563c1f3012e9cb 100644 (file)
 #ifndef __IOCMD_H__
 #define __IOCMD_H__
 
-#include "ttype.h"
-
-/*---------------------  Export Definitions -------------------------*/
-
 // ioctl Command code
 #define MAGIC_CODE                      0x3142
 #define IOCTL_CMD_TEST             (SIOCDEVPRIVATE + 0)
@@ -181,14 +177,12 @@ typedef struct tagSBSSIDItem {
 
 } __packed SBSSIDItem;
 
-
 typedef struct tagSBSSIDList {
 
        u32                 uItem;
        SBSSIDItem      sBSSIDList[0];
 } __packed SBSSIDList, *PSBSSIDList;
 
-
 typedef struct tagSNodeItem {
     // STA info
     u16            wAID;
@@ -209,7 +203,6 @@ typedef struct tagSNodeItem {
 
 } __packed SNodeItem;
 
-
 typedef struct tagSNodeList {
 
        u32                 uItem;
@@ -217,7 +210,6 @@ typedef struct tagSNodeList {
 
 } __packed SNodeList, *PSNodeList;
 
-
 typedef struct tagSCmdLinkStatus {
 
     bool    bLink;
@@ -248,8 +240,6 @@ typedef struct tagSDot11MIBCount {
     u32 FCSErrorCount;
 } __packed SDot11MIBCount, *PSDot11MIBCount;
 
-
-
 //
 // statistic counter
 //
@@ -432,12 +422,4 @@ struct viawget_hostapd_param {
        } u;
 } __packed;
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Types  ------------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 #endif /* __IOCMD_H__ */
index 2522ddec718d3dd3f930097d80841ec2b8bdda88..97af32e1fa44a15244d5184ee6afa420cd95d672 100644 (file)
@@ -29,8 +29,6 @@
 #ifndef __IOWPA_H__
 #define __IOWPA_H__
 
-/*---------------------  Export Definitions -------------------------*/
-
 #define WPA_IE_LEN 64
 
 //WPA related
@@ -55,7 +53,6 @@ enum {
        VIAWGET_SET_DISASSOCIATE = 10
 };
 
-
 enum {
        VIAWGET_ASSOC_MSG = 1,
        VIAWGET_DISASSOC_MSG = 2,
@@ -65,8 +62,6 @@ enum {
        VIAWGET_DEVICECLOSE_MSG = 6
 };
 
-
-
 typedef struct viawget_wpa_header {
        u8 type;
        u16 req_ie_len;
@@ -130,12 +125,4 @@ struct viawget_scan_result {
        int maxrate;
 } __packed;
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Types  ------------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 #endif /* __IOWPA_H__ */
index 69971f35e49030726d551ef0f226b3452412c6e7..c335808211ee54b929441028e738797d457ead86 100644 (file)
@@ -42,7 +42,6 @@
 #include "control.h"
 #include "rndis.h"
 
-
 static const long frequency_list[] = {
        2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
        4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
@@ -61,8 +60,8 @@ struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
        pDevice->wstats.status = pDevice->eOPMode;
        if (pDevice->scStatistic.LinkQuality > 100)
                pDevice->scStatistic.LinkQuality = 100;
-       pDevice->wstats.qual.qual =(BYTE)pDevice->scStatistic.LinkQuality;
-       RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
+       pDevice->wstats.qual.qual =(u8)pDevice->scStatistic.LinkQuality;
+       RFvRSSITodBm(pDevice, (u8)(pDevice->uCurrRSSI), &ldBm);
        pDevice->wstats.qual.level = ldBm;
        pDevice->wstats.qual.noise = 0;
        pDevice->wstats.qual.updated = 1;
@@ -95,7 +94,7 @@ int iwctl_siwscan(struct net_device *dev, struct iw_request_info *info,
        struct iw_point *wrq = &wrqu->data;
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
        struct iw_scan_req *req = (struct iw_scan_req *)extra;
-       BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
+       u8 abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
        PWLAN_IE_SSID pItemSSID = NULL;
 
        if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
@@ -238,7 +237,7 @@ int iwctl_giwscan(struct net_device *dev, struct iw_request_info *info,
                        // ADD quality
                        memset(&iwe, 0, sizeof(iwe));
                        iwe.cmd = IWEVQUAL;
-                       RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
+                       RFvRSSITodBm(pDevice, (u8)(pBSS->uRSSI), &ldBm);
                        iwe.u.qual.level = ldBm;
                        iwe.u.qual.noise = 0;
 
@@ -357,7 +356,6 @@ int iwctl_giwfreq(struct net_device *dev, struct iw_request_info *info,
        if (pMgmt == NULL)
                return -EFAULT;
 
-
 #ifdef WEXT_USECHANNELS
        wrq->m = (int)pMgmt->uCurrChannel;
        wrq->e = 0;
@@ -482,7 +480,6 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
                pDevice->bCommit = false;
        }
 
-
        return rc;
 }
 
@@ -532,7 +529,7 @@ int iwctl_giwrange(struct net_device *dev, struct iw_request_info *info,
        struct iw_range *range = (struct iw_range *)extra;
        int i;
        int k;
-       BYTE abySupportedRates[13] = {
+       u8 abySupportedRates[13] = {
                0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
                0x60, 0x6C, 0x90
        };
@@ -635,7 +632,7 @@ int iwctl_siwap(struct net_device *dev, struct iw_request_info *info,
        struct sockaddr *wrq = &wrqu->ap_addr;
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
        int rc = 0;
-       BYTE ZeroBSSID[WLAN_BSSID_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+       u8 ZeroBSSID[WLAN_BSSID_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 
        PRINT_K(" SIOCSIWAP\n");
 
@@ -819,7 +816,7 @@ int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
                if (pDevice->bWPASuppWextEnabled == true)  {
                        /*******search if  in hidden ssid mode ****/
                        PKnownBSS pCurr = NULL;
-                       BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
+                       u8 abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
                        unsigned ii;
                        unsigned uSameBssidNum = 0;
 
@@ -913,7 +910,7 @@ int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info,
        int rc = 0;
        u8 brate = 0;
        int i;
-       BYTE abySupportedRates[13] = {
+       u8 abySupportedRates[13] = {
                0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
                0x60, 0x6C, 0x90
        };
@@ -996,7 +993,7 @@ int iwctl_giwrate(struct net_device *dev, struct iw_request_info *info,
                return -EFAULT;
 
        {
-               BYTE abySupportedRates[13] = {
+               u8 abySupportedRates[13] = {
                        0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
                        0x48, 0x60, 0x6C, 0x90
                };
@@ -1227,7 +1224,7 @@ int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info,
                                        KEY_CTL_WEP);
                        spin_unlock_irq(&pDevice->lock);
                }
-               pDevice->byKeyIndex = (BYTE)dwKeyIndex;
+               pDevice->byKeyIndex = (u8)dwKeyIndex;
                pDevice->uKeyLength = wrq->length;
                pDevice->bTransmitKey = true;
                pDevice->bEncryptionEnable = true;
@@ -1317,7 +1314,7 @@ int iwctl_giwencode(struct net_device *dev, struct iw_request_info *info,
                        memcpy(abyKey, pKey->abyKey,    pKey->uKeyLength);
                        memcpy(extra,  abyKey, WLAN_WEP232_KEYLEN);
                }
-       } else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index, &pKey)) {
+       } else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (u8)index, &pKey)) {
                wrq->length = pKey->uKeyLength;
                memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
                memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
@@ -1424,7 +1421,7 @@ int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info,
 
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS\n");
        if (pDevice->bLinkPass == true) {
-               RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
+               RFvRSSITodBm(pDevice, (u8)(pDevice->uCurrRSSI), &ldBm);
                wrq->value = ldBm;
        } else {
                wrq->value = 0;
index b594a10db318440944b453c04013e43189fa2f85..dceda0dbdfe1f53d33e45f86a3769fc5525bfd21 100644 (file)
 
 #include "device.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev);
 
 int iwctl_siwap(struct net_device *dev, struct iw_request_info *info,
index 416175e8ba53a76464ba23fb317546b631bf30d3..205590b0e9c839018a390cd79a0c23fe97d341ec 100644 (file)
 #include "rndis.h"
 #include "control.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
 static int          msglevel                =MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
 
-/*---------------------  Static Variables  --------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
 static void s_vCheckKeyTableValid(struct vnt_private *pDevice,
        PSKeyManagement pTable)
 {
@@ -79,7 +64,7 @@ static void s_vCheckKeyTableValid(struct vnt_private *pDevice,
             pTable->KeyTable[i].bInUse = false;
             pTable->KeyTable[i].wKeyCtl = 0;
             pTable->KeyTable[i].bSoftWEP = false;
-            pbyData[wLength++] = (BYTE) i;
+            pbyData[wLength++] = (u8) i;
             //MACvDisableKeyEntry(pDevice, i);
         }
     }
@@ -95,10 +80,6 @@ static void s_vCheckKeyTableValid(struct vnt_private *pDevice,
 
 }
 
-
-/*---------------------  Export Functions  --------------------------*/
-
-
 /*
  * Description: Init Key management table
  *
@@ -130,9 +111,9 @@ void KeyvInitTable(struct vnt_private *pDevice, PSKeyManagement pTable)
         pTable->KeyTable[i].wKeyCtl = 0;
         pTable->KeyTable[i].dwGTKeyIndex = 0;
         pTable->KeyTable[i].bSoftWEP = false;
-        pbyData[i] = (BYTE) i;
+        pbyData[i] = (u8) i;
     }
-    pbyData[i] = (BYTE) i;
+    pbyData[i] = (u8) i;
     CONTROLnsRequestOut(pDevice,
                         MESSAGE_TYPE_CLRKEYENTRY,
                         0,
@@ -146,7 +127,6 @@ void KeyvInitTable(struct vnt_private *pDevice, PSKeyManagement pTable)
     return;
 }
 
-
 /*
  * Description: Get Key from table
  *
@@ -197,7 +177,6 @@ int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex,
     return (false);
 }
 
-
 /*
  * Description: Set Key to table
  *
@@ -272,7 +251,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable,
                 if (uKeyLength == WLAN_WEP104_KEYLEN)
                     pKey->abyKey[15] |= 0x80;
             }
-            MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey);
+            MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (u32 *)pKey->abyKey);
 
                if ((dwKeyIndex & USE_KEYRSC) == 0)
                        pKey->KeyRSC = 0; /* RSC set by NIC */
@@ -340,7 +319,7 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable,
             if (uKeyLength == WLAN_WEP104_KEYLEN)
                 pKey->abyKey[15] |= 0x80;
         }
-        MACvSetKeyEntry(pDevice, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey);
+        MACvSetKeyEntry(pDevice, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (u32 *)pKey->abyKey);
 
                if ((dwKeyIndex & USE_KEYRSC) == 0)
                        pKey->KeyRSC = 0; /* RSC set by NIC */
@@ -370,7 +349,6 @@ int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable,
     return (false);
 }
 
-
 /*
  * Description: Remove Key from table
  *
@@ -445,10 +423,8 @@ int KeybRemoveKey(struct vnt_private *pDevice, PSKeyManagement pTable,
     s_vCheckKeyTableValid(pDevice,pTable);
     return bReturnValue;
 
-
 }
 
-
 /*
  * Description: Remove Key from table
  *
@@ -482,45 +458,6 @@ int KeybRemoveAllKey(struct vnt_private *pDevice, PSKeyManagement pTable,
     return (false);
 }
 
-/*
- * Description: Remove WEP Key from table
- *
- * Parameters:
- *  In:
- *      pTable          - Pointer to Key table
- *  Out:
- *      none
- *
- * Return Value: true if success otherwise false
- *
- */
-void KeyvRemoveWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable,
-       u32 dwKeyIndex)
-{
-
-   if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
-        if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == true) {
-            if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) {
-                pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
-                if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) {
-                    // remove Group transmit key
-                    pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0;
-                }
-            }
-        }
-        s_vCheckKeyTableValid(pDevice, pTable);
-    }
-    return;
-}
-
-void KeyvRemoveAllWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable)
-{
-       int i;
-
-       for (i = 0; i < MAX_GROUP_KEY; i++)
-               KeyvRemoveWEPKey(pDevice, pTable, i);
-}
-
 /*
  * Description: Get Transmit Key from table
  *
@@ -557,7 +494,6 @@ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType,
                     }
                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
 
-
                     return (true);
                 }
                 else {
@@ -599,35 +535,6 @@ int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType,
     return (false);
 }
 
-
-/*
- * Description: Check Pairwise Key
- *
- * Parameters:
- *  In:
- *      pTable          - Pointer to Key table
- *  Out:
- *      none
- *
- * Return Value: true if found otherwise false
- *
- */
-int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey)
-{
-       int i;
-
-       *pKey = NULL;
-
-    for (i=0;i<MAX_KEY_TABLE;i++) {
-        if ((pTable->KeyTable[i].bInUse == true) &&
-            (pTable->KeyTable[i].PairwiseKey.bKeyValid == true)) {
-            *pKey = &(pTable->KeyTable[i].PairwiseKey);
-            return (true);
-        }
-    }
-    return (false);
-}
-
 /*
  * Description: Set Key to table
  *
@@ -707,18 +614,16 @@ int KeybSetDefaultKey(struct vnt_private *pDevice, PSKeyManagement pTable,
             pKey->abyKey[15] |= 0x80;
     }
 
-    MACvSetKeyEntry(pDevice, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (PDWORD) pKey->abyKey);
+    MACvSetKeyEntry(pDevice, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (u32 *) pKey->abyKey);
 
                if ((dwKeyIndex & USE_KEYRSC) == 0)
                        pKey->KeyRSC = 0; /* RSC set by NIC */
                else
                        pKey->KeyRSC = *KeyRSC;
 
-
     pKey->dwTSC47_16 = 0;
     pKey->wTSC15_0 = 0;
 
-
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n", pKey->bKeyValid);
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n", (int)pKey->uKeyLength);
@@ -737,7 +642,6 @@ int KeybSetDefaultKey(struct vnt_private *pDevice, PSKeyManagement pTable,
     return (true);
 }
 
-
 /*
  * Description: Set Key to table
  *
@@ -766,7 +670,6 @@ int KeybSetAllGroupKey(struct vnt_private *pDevice, PSKeyManagement pTable,
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %X\n",
                dwKeyIndex);
 
-
     if ((dwKeyIndex & PAIRWISE_KEY) != 0) {                  // Pairwise key
         return (false);
     } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
@@ -805,7 +708,7 @@ int KeybSetAllGroupKey(struct vnt_private *pDevice, PSKeyManagement pTable,
                     pKey->abyKey[15] |= 0x80;
             }
 
-            MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (PDWORD) pKey->abyKey);
+            MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (u32 *) pKey->abyKey);
 
                if ((dwKeyIndex & USE_KEYRSC) == 0)
                        pKey->KeyRSC = 0; /* RSC set by NIC */
index 7ecddcd6bcfae15c21e5bbc2cd1bbead73acd78c..23e188d125ba7219237d6fea1099c2691aed507f 100644 (file)
 #ifndef __KEY_H__
 #define __KEY_H__
 
-#include "ttype.h"
 #include "tether.h"
 #include "80211mgr.h"
 
-/*---------------------  Export Definitions -------------------------*/
 #define MAX_GROUP_KEY       4
 #define MAX_KEY_TABLE       11
 #define MAX_KEY_LEN         32
 #define AES_KEY_LEN         16
 
-
 #define AUTHENTICATOR_KEY   0x10000000
 #define USE_KEYRSC          0x20000000
 #define PAIRWISE_KEY        0x40000000
 #define KEY_CTL_CCMP        0x03
 #define KEY_CTL_INVALID     0xFF
 
-
 typedef struct tagSKeyItem
 {
     bool        bKeyValid;
        u32 uKeyLength;
-    BYTE        abyKey[MAX_KEY_LEN];
+    u8        abyKey[MAX_KEY_LEN];
        u64 KeyRSC;
-    DWORD       dwTSC47_16;
-    WORD        wTSC15_0;
-    BYTE        byCipherSuite;
-    BYTE        byReserved0;
-    DWORD       dwKeyIndex;
+    u32       dwTSC47_16;
+    u16        wTSC15_0;
+    u8        byCipherSuite;
+    u8        byReserved0;
+    u32       dwKeyIndex;
     void *pvKeyTable;
 } SKeyItem, *PSKeyItem; //64
 
 typedef struct tagSKeyTable
 {
-    BYTE        abyBSSID[ETH_ALEN];  /* 6 */
-    BYTE        byReserved0[2];              //8
+    u8        abyBSSID[ETH_ALEN];  /* 6 */
+    u8        byReserved0[2];              //8
     SKeyItem    PairwiseKey;
     SKeyItem    GroupKey[MAX_GROUP_KEY]; //64*5 = 320, 320+8=328
-    DWORD       dwGTKeyIndex;            // GroupTransmitKey Index
+    u32       dwGTKeyIndex;            // GroupTransmitKey Index
     bool        bInUse;
-    WORD        wKeyCtl;
+    u16        wKeyCtl;
     bool        bSoftWEP;
-    BYTE        byReserved1[6];
+    u8        byReserved1[6];
 } SKeyTable, *PSKeyTable; //352
 
 typedef struct tagSKeyManagement
@@ -87,16 +83,6 @@ typedef struct tagSKeyManagement
     SKeyTable   KeyTable[MAX_KEY_TABLE];
 } SKeyManagement, *PSKeyManagement;
 
-/*---------------------  Export Types  ------------------------------*/
-
-/*---------------------  Export Macros ------------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 void KeyvInitTable(struct vnt_private *, PSKeyManagement pTable);
 
 int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex,
@@ -112,16 +98,9 @@ int KeybRemoveKey(struct vnt_private *, PSKeyManagement pTable,
 int KeybRemoveAllKey(struct vnt_private *, PSKeyManagement pTable,
        u8 *pbyBSSID);
 
-void KeyvRemoveWEPKey(struct vnt_private *, PSKeyManagement pTable,
-       u32 dwKeyIndex);
-
-void KeyvRemoveAllWEPKey(struct vnt_private *, PSKeyManagement pTable);
-
 int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType,
        PSKeyItem *pKey);
 
-int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey);
-
 int KeybSetDefaultKey(struct vnt_private *, PSKeyManagement pTable,
        u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey,
        u8 byKeyDecMode);
index 76d307b58d5246d5432ea77985909ff8a704d0a0..343db19283a2b193eef211775b1972fa30d62362 100644 (file)
 #include "rndis.h"
 #include "control.h"
 
-/*---------------------  Static Definitions -------------------------*/
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 static int          msglevel                =MSG_LEVEL_INFO;
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
-
-
-
-
-/*
- * Description:
- *      Set this hash index into multicast address register bit
- *
- * Parameters:
- *  In:
- *      byHashIdx   - Hash index to set
- *  Out:
- *      none
- *
- * Return Value: none
- *
- */
-void MACvSetMultiAddrByHash(struct vnt_private *pDevice, u8 byHashIdx)
-{
-       u8 uByteIdx;
-       u8 byBitMask;
-       u8 pbyData[2];
-
-
-    // calculate byte position
-    uByteIdx = byHashIdx / 8;
-
-    // calculate bit position
-    byBitMask = 1;
-    byBitMask <<= (byHashIdx % 8);
-    // turn on the bit
-
-    pbyData[0] = byBitMask;
-    pbyData[1] = byBitMask;
-
-    CONTROLnsRequestOut(pDevice,
-                        MESSAGE_TYPE_WRITE_MASK,
-                        (WORD) (MAC_REG_MAR0 + uByteIdx),
-                        MESSAGE_REQUEST_MACREG,
-                        2,
-                        pbyData);
-}
-
-
 
 /*
  * Description:
@@ -117,13 +62,12 @@ void MACvWriteMultiAddr(struct vnt_private *pDevice, u32 uByteIdx, u8 byData)
     byData1 = byData;
     CONTROLnsRequestOut(pDevice,
                         MESSAGE_TYPE_WRITE,
-                        (WORD) (MAC_REG_MAR0 + uByteIdx),
+                        (u16) (MAC_REG_MAR0 + uByteIdx),
                         MESSAGE_REQUEST_MACREG,
                         1,
                         &byData1);
 }
 
-
 /*
  * Description:
  *      Shut Down MAC
@@ -150,7 +94,6 @@ void MACvSetBBType(struct vnt_private *pDevice, u8 byType)
 {
        u8 pbyData[2];
 
-
     pbyData[0] = byType;
     pbyData[1] = EnCFG_BBType_MASK;
 
@@ -163,26 +106,6 @@ void MACvSetBBType(struct vnt_private *pDevice, u8 byType)
                         );
 }
 
-void MACvSetMISCFifo(struct vnt_private *pDevice, u16 wOffset, u32 dwData)
-{
-       u8 pbyData[4];
-
-    if (wOffset > 273)
-        return;
-    pbyData[0] = (BYTE)dwData;
-    pbyData[1] = (BYTE)(dwData>>8);
-    pbyData[2] = (BYTE)(dwData>>16);
-    pbyData[3] = (BYTE)(dwData>>24);
-
-    CONTROLnsRequestOut(pDevice,
-                        MESSAGE_TYPE_WRITE_MISCFF,
-                        wOffset,
-                        0,
-                        4,
-                        pbyData
-                        );
-}
-
 /*
  * Description:
  *      Disable the Key Entry by MISCFIFO
@@ -202,8 +125,7 @@ void MACvDisableKeyEntry(struct vnt_private *pDevice, u32 uEntryIdx)
        u16 wOffset;
        u8 byData;
 
-
-    byData = (BYTE) uEntryIdx;
+    byData = (u8) uEntryIdx;
 
     wOffset = MISCFIFO_KEYETRY0;
     wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
@@ -222,7 +144,6 @@ void MACvDisableKeyEntry(struct vnt_private *pDevice, u32 uEntryIdx)
                         );
 }
 
-
 /*
  * Description:
  *      Set the Key by MISCFIFO
@@ -294,31 +215,29 @@ void MACvSetKeyEntry(struct vnt_private *pDevice, u16 wKeyCtl, u32 uEntryIdx,
         VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
     }
 */
-    pbyKey = (PBYTE)pdwKey;
-
-    pbyData[0] = (BYTE)dwData1;
-    pbyData[1] = (BYTE)(dwData1>>8);
-    pbyData[2] = (BYTE)(dwData1>>16);
-    pbyData[3] = (BYTE)(dwData1>>24);
-    pbyData[4] = (BYTE)dwData2;
-    pbyData[5] = (BYTE)(dwData2>>8);
-    pbyData[6] = (BYTE)(dwData2>>16);
-    pbyData[7] = (BYTE)(dwData2>>24);
+    pbyKey = (u8 *)pdwKey;
+
+    pbyData[0] = (u8)dwData1;
+    pbyData[1] = (u8)(dwData1>>8);
+    pbyData[2] = (u8)(dwData1>>16);
+    pbyData[3] = (u8)(dwData1>>24);
+    pbyData[4] = (u8)dwData2;
+    pbyData[5] = (u8)(dwData2>>8);
+    pbyData[6] = (u8)(dwData2>>16);
+    pbyData[7] = (u8)(dwData2>>24);
     for (ii = 8; ii < 24; ii++)
        pbyData[ii] = *pbyKey++;
 
     CONTROLnsRequestOut(pDevice,
                         MESSAGE_TYPE_SETKEY,
                         wOffset,
-                        (WORD)uKeyIdx,
+                        (u16)uKeyIdx,
                         24,
                         pbyData
                         );
 
-
 }
 
-
 void MACvRegBitsOff(struct vnt_private *pDevice, u8 byRegOfs, u8 byBits)
 {
        u8 pbyData[2];
@@ -335,12 +254,10 @@ void MACvRegBitsOff(struct vnt_private *pDevice, u8 byRegOfs, u8 byBits)
                         );
 }
 
-
 void MACvRegBitsOn(struct vnt_private *pDevice, u8 byRegOfs, u8 byBits)
 {
        u8 pbyData[2];
 
-
     pbyData[0] = byBits;
     pbyData[1] = byBits;
 
@@ -357,9 +274,8 @@ void MACvWriteWord(struct vnt_private *pDevice, u8 byRegOfs, u16 wData)
 {
        u8 pbyData[2];
 
-
-    pbyData[0] = (BYTE)(wData & 0xff);
-    pbyData[1] = (BYTE)(wData >> 8);
+    pbyData[0] = (u8)(wData & 0xff);
+    pbyData[1] = (u8)(wData >> 8);
 
     CONTROLnsRequestOut(pDevice,
                         MESSAGE_TYPE_WRITE,
@@ -375,13 +291,12 @@ void MACvWriteBSSIDAddress(struct vnt_private *pDevice, u8 *pbyEtherAddr)
 {
        u8 pbyData[6];
 
-
-    pbyData[0] = *((PBYTE)pbyEtherAddr);
-    pbyData[1] = *((PBYTE)pbyEtherAddr+1);
-    pbyData[2] = *((PBYTE)pbyEtherAddr+2);
-    pbyData[3] = *((PBYTE)pbyEtherAddr+3);
-    pbyData[4] = *((PBYTE)pbyEtherAddr+4);
-    pbyData[5] = *((PBYTE)pbyEtherAddr+5);
+    pbyData[0] = *((u8 *)pbyEtherAddr);
+    pbyData[1] = *((u8 *)pbyEtherAddr+1);
+    pbyData[2] = *((u8 *)pbyEtherAddr+2);
+    pbyData[3] = *((u8 *)pbyEtherAddr+3);
+    pbyData[4] = *((u8 *)pbyEtherAddr+4);
+    pbyData[5] = *((u8 *)pbyEtherAddr+5);
 
     CONTROLnsRequestOut(pDevice,
                         MESSAGE_TYPE_WRITE,
@@ -396,7 +311,6 @@ void MACvEnableProtectMD(struct vnt_private *pDevice)
 {
        u8 pbyData[2];
 
-
     pbyData[0] = EnCFG_ProtectMd;
     pbyData[1] = EnCFG_ProtectMd;
 
@@ -413,7 +327,6 @@ void MACvDisableProtectMD(struct vnt_private *pDevice)
 {
        u8 pbyData[2];
 
-
     pbyData[0] = 0;
     pbyData[1] = EnCFG_ProtectMd;
 
@@ -430,7 +343,6 @@ void MACvEnableBarkerPreambleMd(struct vnt_private *pDevice)
 {
        u8 pbyData[2];
 
-
     pbyData[0] = EnCFG_BarkerPream;
     pbyData[1] = EnCFG_BarkerPream;
 
@@ -447,7 +359,6 @@ void MACvDisableBarkerPreambleMd(struct vnt_private *pDevice)
 {
        u8 pbyData[2];
 
-
     pbyData[0] = 0;
     pbyData[1] = EnCFG_BarkerPream;
 
@@ -460,7 +371,6 @@ void MACvDisableBarkerPreambleMd(struct vnt_private *pDevice)
                         );
 }
 
-
 void MACvWriteBeaconInterval(struct vnt_private *pDevice, u16 wInterval)
 {
        u8 pbyData[2];
index 6e28500ae5f824dde2f7fe8aadd795ccc3328249..0db1be5b01c86f6f05ddaeddf302b340adbf4131 100644 (file)
 #ifndef __MAC_H__
 #define __MAC_H__
 
-#include "ttype.h"
 #include "device.h"
 #include "tmacro.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
 #define REV_ID_VT3253_A0    0x00
 #define REV_ID_VT3253_A1    0x01
 #define REV_ID_VT3253_B0    0x08
 #define MAC_REG_RSPINF_A_54 0xFA
 #define MAC_REG_RSPINF_A_72 0xFC
 
-
 //
 // Bits in the I2MCFG EEPROM register
 //
 #define TCR_SYNCDCFOPT      0x02        //
 #define TCR_AUTOBCNTX       0x01        // Beacon automatically transmit enable
 
-
 //ISR1
 #define ISR_GPIO3           0x40
 #define ISR_RXNOBUF         0x08
 //
 #define MISCFFCTL_WRITE     0x0001      //
 
-
 // Loopback mode
 #define MAC_LB_EXT          0x02        //
 #define MAC_LB_INTERNAL     0x01        //
 #define MAC_REVISION_A0     0x00
 #define MAC_REVISION_A1     0x01
 
-
-/*---------------------  Export Types  ------------------------------*/
-
-/*---------------------  Export Macros ------------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
-void MACvSetMultiAddrByHash(struct vnt_private *, u8);
 void MACvWriteMultiAddr(struct vnt_private *, u32, u8);
 void MACbShutdown(struct vnt_private *);
 void MACvSetBBType(struct vnt_private *, u8);
-void MACvSetMISCFifo(struct vnt_private *pDevice, u16, u32);
 void MACvDisableKeyEntry(struct vnt_private *, u32);
 void MACvSetKeyEntry(struct vnt_private *, u16, u32, u32, u8 *, u32 *);
 void MACvRegBitsOff(struct vnt_private *, u8, u8);
index a5063a6f64d9f669e59eb08167a1ef0e93ec277d..2161af83eaa0a04a6696bd5c58b5563ee26b222b 100644 (file)
@@ -72,7 +72,6 @@
 #include "int.h"
 #include "iowpa.h"
 
-/*---------------------  Static Definitions -------------------------*/
 /* static int msglevel = MSG_LEVEL_DEBUG; */
 static int          msglevel                =MSG_LEVEL_INFO;
 
@@ -95,14 +94,12 @@ MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
 #define RX_DESC_DEF0     64
 DEVICE_PARAM(RxDescriptors0,"Number of receive usb desc buffer");
 
-
 #define TX_DESC_DEF0     64
 DEVICE_PARAM(TxDescriptors0,"Number of transmit usb desc buffer");
 
 #define CHANNEL_DEF     6
 DEVICE_PARAM(Channel, "Channel number");
 
-
 /* PreambleType[] is the preamble length used for transmit.
    0: indicate allows long preamble type
    1: indicate allows short preamble type
@@ -118,7 +115,6 @@ DEVICE_PARAM(RTSThreshold, "RTS threshold");
 #define FRAG_THRESH_DEF     2346
 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
 
-
 #define DATA_RATE_DEF     13
 /* datarate[] index
    0: indicate 1 Mbps   0x02
@@ -148,7 +144,6 @@ DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
    2: indicate AP mode used
 */
 
-
 /* PSMode[]
    0: indicate disable power saving mode
    1: indicate enable power saving mode
@@ -157,7 +152,6 @@ DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
 #define PS_MODE_DEF     0
 DEVICE_PARAM(PSMode, "Power saving mode");
 
-
 #define SHORT_RETRY_DEF     8
 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
 
@@ -173,8 +167,6 @@ DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
 #define BBP_TYPE_DEF     2
 DEVICE_PARAM(BasebandType, "baseband type");
 
-
-
 /* 80211hEnable[]
    0: indicate disable 802.11h
    1: indicate enable 802.11h
@@ -184,7 +176,6 @@ DEVICE_PARAM(BasebandType, "baseband type");
 
 DEVICE_PARAM(b80211hEnable, "802.11h mode");
 
-
 /*
  * Static vars definitions
  */
@@ -204,12 +195,9 @@ static const long frequency_list[] = {
     5700, 5745, 5765, 5785, 5805, 5825
        };
 
-
 static const struct iw_handler_def     iwctl_handler_def;
 */
 
-/*---------------------  Static Functions  --------------------------*/
-
 static int vt6656_probe(struct usb_interface *intf,
                        const struct usb_device_id *id);
 static void vt6656_disconnect(struct usb_interface *intf);
@@ -245,21 +233,13 @@ static int Config_FileGetParameter(unsigned char *string,
                                   unsigned char *dest,
                                   unsigned char *source);
 
-
 static void usb_device_reset(struct vnt_private *pDevice);
 
-
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
-
 static void
 device_set_options(struct vnt_private *pDevice) {
 
-    BYTE    abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-    BYTE    abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
+    u8    abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+    u8    abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
     u8 abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
 
     memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
@@ -293,7 +273,6 @@ device_set_options(struct vnt_private *pDevice) {
     pDevice->bDiversityRegCtlON = false;
 }
 
-
 static void device_init_diversity_timer(struct vnt_private *pDevice)
 {
     init_timer(&pDevice->TimerSQ3Tmax1);
@@ -314,7 +293,6 @@ static void device_init_diversity_timer(struct vnt_private *pDevice)
     return;
 }
 
-
 /*
  * initialization of MAC & BBP registers
  */
@@ -366,8 +344,8 @@ static int device_init_registers(struct vnt_private *pDevice,
         }
     }
 
-    sInitCmd.byInitClass = (BYTE)InitType;
-    sInitCmd.bExistSWNetAddr = (BYTE) pDevice->bExistSWNetAddr;
+    sInitCmd.byInitClass = (u8)InitType;
+    sInitCmd.bExistSWNetAddr = (u8) pDevice->bExistSWNetAddr;
     for (ii = 0; ii < 6; ii++)
        sInitCmd.bySWNetAddr[ii] = pDevice->abyCurrentNetAddr[ii];
     sInitCmd.byShortRetryLimit = pDevice->byShortRetryLimit;
@@ -379,7 +357,7 @@ static int device_init_registers(struct vnt_private *pDevice,
                                     0,
                                     0,
                                     sizeof(CMD_CARD_INIT),
-                                    (PBYTE) &(sInitCmd));
+                                    (u8 *) &(sInitCmd));
 
     if ( ntStatus != STATUS_SUCCESS ) {
         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Issue Card init fail \n");
@@ -388,7 +366,7 @@ static int device_init_registers(struct vnt_private *pDevice,
     }
     if (InitType == DEVICE_INIT_COLD) {
 
-        ntStatus = CONTROLnsRequestIn(pDevice,MESSAGE_TYPE_INIT_RSP,0,0,sizeof(RSP_CARD_INIT), (PBYTE) &(sInitRsp));
+        ntStatus = CONTROLnsRequestIn(pDevice,MESSAGE_TYPE_INIT_RSP,0,0,sizeof(RSP_CARD_INIT), (u8 *) &(sInitRsp));
 
         if (ntStatus != STATUS_SUCCESS) {
             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Cardinit request in status fail!\n");
@@ -418,7 +396,7 @@ static int device_init_registers(struct vnt_private *pDevice,
         pDevice->bNonERPPresent = false;
         pDevice->bBarkerPreambleMd = false;
         if ( pDevice->bFixRate ) {
-            pDevice->wCurrentRate = (WORD) pDevice->uConnectionRate;
+            pDevice->wCurrentRate = (u16) pDevice->uConnectionRate;
         } else {
             if ( pDevice->byBBType == BB_TYPE_11B )
                 pDevice->wCurrentRate = RATE_11M;
@@ -771,7 +749,6 @@ static void device_free_tx_bufs(struct vnt_private *pDevice)
     return;
 }
 
-
 static void device_free_rx_bufs(struct vnt_private *pDevice)
 {
     PRCB pRCB;
@@ -809,7 +786,6 @@ static void device_free_int_bufs(struct vnt_private *pDevice)
     return;
 }
 
-
 static bool device_alloc_bufs(struct vnt_private *pDevice)
 {
 
@@ -817,7 +793,6 @@ static bool device_alloc_bufs(struct vnt_private *pDevice)
     PRCB pRCB;
     int ii;
 
-
     for (ii = 0; ii < pDevice->cbTD; ii++) {
 
         pTxContext = kmalloc(sizeof(USB_SEND_CONTEXT), GFP_KERNEL);
@@ -843,7 +818,6 @@ static bool device_alloc_bufs(struct vnt_private *pDevice)
         goto free_tx;
     }
 
-
     pDevice->FirstRecvFreeList = NULL;
     pDevice->LastRecvFreeList = NULL;
     pDevice->FirstRecvMngList = NULL;
@@ -874,7 +848,6 @@ static bool device_alloc_bufs(struct vnt_private *pDevice)
         pRCB++;
     }
 
-
        pDevice->pControlURB = usb_alloc_urb(0, GFP_ATOMIC);
        if (pDevice->pControlURB == NULL) {
            DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc control urb\n");
@@ -907,9 +880,6 @@ free_tx:
        return false;
 }
 
-
-
-
 static bool device_init_defrag_cb(struct vnt_private *pDevice)
 {
        int i;
@@ -933,8 +903,6 @@ free_frag:
     return false;
 }
 
-
-
 static void device_free_frag_bufs(struct vnt_private *pDevice)
 {
        PSDeFragControlBlock pDeF;
@@ -949,8 +917,6 @@ static void device_free_frag_bufs(struct vnt_private *pDevice)
     }
 }
 
-
-
 int device_alloc_frag_buf(struct vnt_private *pDevice,
                PSDeFragControlBlock pDeF)
 {
@@ -964,9 +930,6 @@ int device_alloc_frag_buf(struct vnt_private *pDevice,
     return true;
 }
 
-
-/*-----------------------------------------------------------------*/
-
 static int  device_open(struct net_device *dev)
 {
        struct vnt_private *pDevice = netdev_priv(dev);
@@ -975,7 +938,6 @@ static int  device_open(struct net_device *dev)
 
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n");
 
-
     pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
 
     if (device_alloc_bufs(pDevice) == false) {
@@ -1061,7 +1023,6 @@ static int  device_open(struct net_device *dev)
        else
                bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
 
-
     netif_stop_queue(pDevice->dev);
     pDevice->flags |= DEVICE_FLAGS_OPENED;
 
@@ -1083,8 +1044,6 @@ free_rx_tx:
     return -ENOMEM;
 }
 
-
-
 static int device_close(struct net_device *dev)
 {
        struct vnt_private *pDevice = netdev_priv(dev);
@@ -1100,7 +1059,6 @@ static int device_close(struct net_device *dev)
         mdelay(30);
     }
 
-
         memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
         pMgmt->bShareKeyAlgorithm = false;
         pDevice->bEncryptionEnable = false;
@@ -1165,7 +1123,6 @@ static void vt6656_disconnect(struct usb_interface *intf)
        if (!device)
                return;
 
-
        usb_set_intfdata(intf, NULL);
        usb_put_dev(interface_to_usbdev(intf));
 
@@ -1430,7 +1387,6 @@ static void device_set_multi(struct net_device *dev)
        u8 byTmpMode = 0;
        int rc;
 
-
        spin_lock_irq(&pDevice->lock);
     rc = CONTROLnsRequestIn(pDevice,
                             MESSAGE_TYPE_READ,
@@ -1466,8 +1422,8 @@ static void device_set_multi(struct net_device *dev)
             mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
         }
         for (ii = 0; ii < 4; ii++) {
-             MACvWriteMultiAddr(pDevice, ii, *((PBYTE)&mc_filter[0] + ii));
-             MACvWriteMultiAddr(pDevice, ii+ 4, *((PBYTE)&mc_filter[1] + ii));
+             MACvWriteMultiAddr(pDevice, ii, *((u8 *)&mc_filter[0] + ii));
+             MACvWriteMultiAddr(pDevice, ii+ 4, *((u8 *)&mc_filter[1] + ii));
         }
         pDevice->byRxMode &= ~(RCR_UNICAST);
         pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
@@ -1518,7 +1474,6 @@ static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        return rc;
 }
 
-
 static int ethtool_ioctl(struct net_device *dev, void *useraddr)
 {
        u32 ethcmd;
index d4c7b0cc7ecd9826566c4f08f6dee74e2c08d0e9..12333cdcbc6a0d22285615723d317dec42605a42 100644 (file)
  * Date: May 21, 1996
  *
  * Functions:
- *      STAvClearAllCounter - Clear All MIB Counter
  *      STAvUpdateIstStatCounter - Update ISR statistic counter
  *      STAvUpdateRDStatCounter - Update Rx statistic counter
- *      STAvUpdateRDStatCounterEx - Update Rx statistic counter and copy rcv data
  *      STAvUpdateTDStatCounter - Update Tx statistic counter
  *      STAvUpdateTDStatCounterEx - Update Tx statistic counter and copy tx data
  *      STAvUpdate802_11Counter - Update 802.11 mib counter
 #include "wctl.h"
 #include "baseband.h"
 
-/*---------------------  Static Definitions -------------------------*/
 static int          msglevel                =MSG_LEVEL_INFO;
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
-
-
-/*
- * Description: Clear All Statistic Counter
- *
- * Parameters:
- *  In:
- *      pStatistic  - Pointer to Statistic Counter Data Structure
- *  Out:
- *      none
- *
- * Return Value: none
- *
- */
-void STAvClearAllCounter (PSStatCounter pStatistic)
-{
-    // set memory to zero
-       memset(pStatistic, 0, sizeof(SStatCounter));
-}
-
 
 /*
  * Description: Update Isr Statistic Counter
@@ -89,7 +56,7 @@ void STAvClearAllCounter (PSStatCounter pStatistic)
  * Return Value: none
  *
  */
-void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, BYTE byIsr0, BYTE byIsr1)
+void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, u8 byIsr0, u8 byIsr1)
 {
     /**********************/
     /* ABNORMAL interrupt */
@@ -100,7 +67,6 @@ void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, BYTE byIsr0, BYTE byIsr
         return;
     }
 
-
     if (byIsr0 & ISR_ACTX)              // ISR, bit0
         pStatistic->ISRStat.dwIsrTx0OK++;           // TXDMA0 successful
 
@@ -119,7 +85,6 @@ void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, BYTE byIsr0, BYTE byIsr
     if (byIsr0 & ISR_WATCHDOG)          // ISR, bit7
         pStatistic->ISRStat.dwIsrWatchDog++;
 
-
     if (byIsr1 & ISR_FETALERR)              // ISR, bit8
         pStatistic->ISRStat.dwIsrUnrecoverableError++;
 
@@ -134,7 +99,6 @@ void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, BYTE byIsr0, BYTE byIsr
 
 }
 
-
 /*
  * Description: Update Rx Statistic Counter
  *
@@ -152,12 +116,12 @@ void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, BYTE byIsr0, BYTE byIsr
  *
  */
 void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
-                            BYTE byRSR, BYTE byNewRSR,
-                            BYTE byRxSts, BYTE byRxRate,
-                            PBYTE pbyBuffer, unsigned int cbFrameLength)
+                            u8 byRSR, u8 byNewRSR,
+                            u8 byRxSts, u8 byRxRate,
+                            u8 * pbyBuffer, unsigned int cbFrameLength)
 {
        /* need change */
-       PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
+       struct ieee80211_hdr *pHeader = (struct ieee80211_hdr *)pbyBuffer;
 
        if (byRSR & RSR_ADDROK)
                pStatistic->dwRsrADDROk++;
@@ -327,7 +291,6 @@ void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
     pStatistic->dwRsrRxPacket++;
     pStatistic->dwRsrRxOctet += cbFrameLength;
 
-
     if (IS_TYPE_DATA(pbyBuffer)) {
         pStatistic->dwRsrRxData++;
     } else if (IS_TYPE_MGMT(pbyBuffer)){
@@ -343,7 +306,7 @@ void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
     else
         pStatistic->dwRsrDirected++;
 
-    if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
+    if (WLAN_GET_FC_MOREFRAG(pHeader->frame_control))
         pStatistic->dwRsrRxFragment++;
 
     if (cbFrameLength < ETH_ZLEN + 4) {
@@ -370,51 +333,6 @@ void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
     }
 }
 
-/*
- * Description: Update Rx Statistic Counter and copy Rx buffer
- *
- * Parameters:
- *  In:
- *      pStatistic      - Pointer to Statistic Counter Data Structure
- *      byRSR           - Rx Status
- *      byNewRSR        - Rx Status
- *      pbyBuffer       - Rx Buffer
- *      cbFrameLength   - Rx Length
- *  Out:
- *      none
- *
- * Return Value: none
- *
- */
-
-void
-STAvUpdateRDStatCounterEx (
-    PSStatCounter   pStatistic,
-    BYTE            byRSR,
-    BYTE            byNewRSR,
-    BYTE            byRxSts,
-    BYTE            byRxRate,
-    PBYTE           pbyBuffer,
-    unsigned int            cbFrameLength
-    )
-{
-    STAvUpdateRDStatCounter(
-                    pStatistic,
-                    byRSR,
-                    byNewRSR,
-                    byRxSts,
-                    byRxRate,
-                    pbyBuffer,
-                    cbFrameLength
-                    );
-
-    // rx length
-    pStatistic->dwCntRxFrmLength = cbFrameLength;
-    // rx pattern, we just see 10 bytes for sample
-    memcpy(pStatistic->abyCntRxPattern, (PBYTE)pbyBuffer, 10);
-}
-
-
 /*
  * Description: Update Tx Statistic Counter
  *
@@ -435,12 +353,12 @@ STAvUpdateRDStatCounterEx (
 void
 STAvUpdateTDStatCounter (
     PSStatCounter   pStatistic,
-    BYTE            byPktNum,
-    BYTE            byRate,
-    BYTE            byTSR
+    u8            byPktNum,
+    u8            byRate,
+    u8            byTSR
     )
 {
-    BYTE    byRetyCnt;
+    u8    byRetyCnt;
     // increase tx packet count
     pStatistic->dwTsrTxPacket++;
 
@@ -504,8 +422,6 @@ STAvUpdateTDStatCounter (
     }
 }
 
-
-
 /*
  * Description: Update 802.11 mib counter
  *
@@ -524,10 +440,10 @@ void
 STAvUpdate802_11Counter(
     PSDot11Counters         p802_11Counter,
     PSStatCounter           pStatistic,
-    BYTE                    byRTSSuccess,
-    BYTE                    byRTSFail,
-    BYTE                    byACKFail,
-    BYTE                    byFCSErr
+    u8                    byRTSSuccess,
+    u8                    byRTSFail,
+    u8                    byACKFail,
+    u8                    byFCSErr
     )
 {
     //p802_11Counter->TransmittedFragmentCount
@@ -549,25 +465,6 @@ STAvUpdate802_11Counter(
                            pStatistic->dwRsrMulticast);
 }
 
-/*
- * Description: Clear 802.11 mib counter
- *
- * Parameters:
- *  In:
- *      p802_11Counter  - Pointer to 802.11 mib counter
- *  Out:
- *      none
- *
- * Return Value: none
- *
- */
-void
-STAvClear802_11Counter(PSDot11Counters p802_11Counter)
-{
-    // set memory to zero
-       memset(p802_11Counter, 0, sizeof(SDot11Counters));
-}
-
 /*
  * Description: Clear 802.11 mib counter
  *
index 85c28e923663a7ea6ad66c3c0966e43f2923587a..35375325a777a62868bc07149ac77e1107d990a7 100644 (file)
 #ifndef __MIB_H__
 #define __MIB_H__
 
-#include "ttype.h"
 #include "tether.h"
 #include "desc.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
-
 //
 // USB counter
 //
 typedef struct tagSUSBCounter {
-    DWORD dwCrc;
+    u32 dwCrc;
 
 } SUSBCounter, *PSUSBCounter;
 
-
-
 //
 // 802.11 counter
 //
 
-
 typedef struct tagSDot11Counters {
   /* unsigned long Length; // Length of structure */
     unsigned long long   TransmittedFragmentCount;
@@ -81,7 +74,6 @@ typedef struct tagSDot11Counters {
    */
 } SDot11Counters, *PSDot11Counters;
 
-
 //
 // MIB2 counter
 //
@@ -91,24 +83,24 @@ typedef struct tagSMib2Counter {
                                         // e.g. "interface 1"
     signed long    ifType;
     signed long    ifMtu;
-    DWORD   ifSpeed;
-    BYTE    ifPhysAddress[ETH_ALEN];
+    u32   ifSpeed;
+    u8    ifPhysAddress[ETH_ALEN];
     signed long    ifAdminStatus;
     signed long    ifOperStatus;
-    DWORD   ifLastChange;
-    DWORD   ifInOctets;
-    DWORD   ifInUcastPkts;
-    DWORD   ifInNUcastPkts;
-    DWORD   ifInDiscards;
-    DWORD   ifInErrors;
-    DWORD   ifInUnknownProtos;
-    DWORD   ifOutOctets;
-    DWORD   ifOutUcastPkts;
-    DWORD   ifOutNUcastPkts;
-    DWORD   ifOutDiscards;
-    DWORD   ifOutErrors;
-    DWORD   ifOutQLen;
-    DWORD   ifSpecific;
+    u32   ifLastChange;
+    u32   ifInOctets;
+    u32   ifInUcastPkts;
+    u32   ifInNUcastPkts;
+    u32   ifInDiscards;
+    u32   ifInErrors;
+    u32   ifInUnknownProtos;
+    u32   ifOutOctets;
+    u32   ifOutUcastPkts;
+    u32   ifOutNUcastPkts;
+    u32   ifOutDiscards;
+    u32   ifOutErrors;
+    u32   ifOutQLen;
+    u32   ifSpecific;
 } SMib2Counter, *PSMib2Counter;
 
 // Value in the ifType entry
@@ -119,32 +111,31 @@ typedef struct tagSMib2Counter {
 #define DOWN                2           //
 #define TESTING             3           //
 
-
 //
 // RMON counter
 //
 typedef struct tagSRmonCounter {
     signed long    etherStatsIndex;
-    DWORD   etherStatsDataSource;
-    DWORD   etherStatsDropEvents;
-    DWORD   etherStatsOctets;
-    DWORD   etherStatsPkts;
-    DWORD   etherStatsBroadcastPkts;
-    DWORD   etherStatsMulticastPkts;
-    DWORD   etherStatsCRCAlignErrors;
-    DWORD   etherStatsUndersizePkts;
-    DWORD   etherStatsOversizePkts;
-    DWORD   etherStatsFragments;
-    DWORD   etherStatsJabbers;
-    DWORD   etherStatsCollisions;
-    DWORD   etherStatsPkt64Octets;
-    DWORD   etherStatsPkt65to127Octets;
-    DWORD   etherStatsPkt128to255Octets;
-    DWORD   etherStatsPkt256to511Octets;
-    DWORD   etherStatsPkt512to1023Octets;
-    DWORD   etherStatsPkt1024to1518Octets;
-    DWORD   etherStatsOwners;
-    DWORD   etherStatsStatus;
+    u32   etherStatsDataSource;
+    u32   etherStatsDropEvents;
+    u32   etherStatsOctets;
+    u32   etherStatsPkts;
+    u32   etherStatsBroadcastPkts;
+    u32   etherStatsMulticastPkts;
+    u32   etherStatsCRCAlignErrors;
+    u32   etherStatsUndersizePkts;
+    u32   etherStatsOversizePkts;
+    u32   etherStatsFragments;
+    u32   etherStatsJabbers;
+    u32   etherStatsCollisions;
+    u32   etherStatsPkt64Octets;
+    u32   etherStatsPkt65to127Octets;
+    u32   etherStatsPkt128to255Octets;
+    u32   etherStatsPkt256to511Octets;
+    u32   etherStatsPkt512to1023Octets;
+    u32   etherStatsPkt1024to1518Octets;
+    u32   etherStatsOwners;
+    u32   etherStatsStatus;
 } SRmonCounter, *PSRmonCounter;
 
 //
@@ -185,56 +176,52 @@ typedef struct tagSCustomCounters {
 
 } SCustomCounters, *PSCustomCounters;
 
-
 //
 // Custom counter
 //
 typedef struct tagSISRCounters {
     unsigned long   Length;
 
-    DWORD   dwIsrTx0OK;
-    DWORD   dwIsrAC0TxOK;
-    DWORD   dwIsrBeaconTxOK;
-    DWORD   dwIsrRx0OK;
-    DWORD   dwIsrTBTTInt;
-    DWORD   dwIsrSTIMERInt;
-    DWORD   dwIsrWatchDog;
-    DWORD   dwIsrUnrecoverableError;
-    DWORD   dwIsrSoftInterrupt;
-    DWORD   dwIsrMIBNearfull;
-    DWORD   dwIsrRxNoBuf;
-
-    DWORD   dwIsrUnknown;               // unknown interrupt count
-
-    DWORD   dwIsrRx1OK;
-    DWORD   dwIsrATIMTxOK;
-    DWORD   dwIsrSYNCTxOK;
-    DWORD   dwIsrCFPEnd;
-    DWORD   dwIsrATIMEnd;
-    DWORD   dwIsrSYNCFlushOK;
-    DWORD   dwIsrSTIMER1Int;
+    u32   dwIsrTx0OK;
+    u32   dwIsrAC0TxOK;
+    u32   dwIsrBeaconTxOK;
+    u32   dwIsrRx0OK;
+    u32   dwIsrTBTTInt;
+    u32   dwIsrSTIMERInt;
+    u32   dwIsrWatchDog;
+    u32   dwIsrUnrecoverableError;
+    u32   dwIsrSoftInterrupt;
+    u32   dwIsrMIBNearfull;
+    u32   dwIsrRxNoBuf;
+
+    u32   dwIsrUnknown;               // unknown interrupt count
+
+    u32   dwIsrRx1OK;
+    u32   dwIsrATIMTxOK;
+    u32   dwIsrSYNCTxOK;
+    u32   dwIsrCFPEnd;
+    u32   dwIsrATIMEnd;
+    u32   dwIsrSYNCFlushOK;
+    u32   dwIsrSTIMER1Int;
     /////////////////////////////////////
 } SISRCounters, *PSISRCounters;
 
-
 // Value in the etherStatsStatus entry
 #define VALID               1           //
 #define CREATE_REQUEST      2           //
 #define UNDER_CREATION      3           //
 #define INVALID             4           //
 
-
 //
 // Tx packet information
 //
 typedef struct tagSTxPktInfo {
-    BYTE    byBroadMultiUni;
-    WORD    wLength;
-    WORD    wFIFOCtl;
-    BYTE    abyDestAddr[ETH_ALEN];
+    u8    byBroadMultiUni;
+    u16    wLength;
+    u16    wFIFOCtl;
+    u8    abyDestAddr[ETH_ALEN];
 } STxPktInfo, *PSTxPktInfo;
 
-
 #define MAX_RATE            12
 //
 // statistic counter
@@ -248,34 +235,34 @@ typedef struct tagSStatCounter {
 
     // RSR status count
     //
-    DWORD   dwRsrFrmAlgnErr;
-    DWORD   dwRsrErr;
-    DWORD   dwRsrCRCErr;
-    DWORD   dwRsrCRCOk;
-    DWORD   dwRsrBSSIDOk;
-    DWORD   dwRsrADDROk;
-    DWORD   dwRsrBCNSSIDOk;
-    DWORD   dwRsrLENErr;
-    DWORD   dwRsrTYPErr;
-
-    DWORD   dwNewRsrDECRYPTOK;
-    DWORD   dwNewRsrCFP;
-    DWORD   dwNewRsrUTSF;
-    DWORD   dwNewRsrHITAID;
-    DWORD   dwNewRsrHITAID0;
-
-    DWORD   dwRsrLong;
-    DWORD   dwRsrRunt;
-
-    DWORD   dwRsrRxControl;
-    DWORD   dwRsrRxData;
-    DWORD   dwRsrRxManage;
-
-    DWORD   dwRsrRxPacket;
-    DWORD   dwRsrRxOctet;
-    DWORD   dwRsrBroadcast;
-    DWORD   dwRsrMulticast;
-    DWORD   dwRsrDirected;
+    u32   dwRsrFrmAlgnErr;
+    u32   dwRsrErr;
+    u32   dwRsrCRCErr;
+    u32   dwRsrCRCOk;
+    u32   dwRsrBSSIDOk;
+    u32   dwRsrADDROk;
+    u32   dwRsrBCNSSIDOk;
+    u32   dwRsrLENErr;
+    u32   dwRsrTYPErr;
+
+    u32   dwNewRsrDECRYPTOK;
+    u32   dwNewRsrCFP;
+    u32   dwNewRsrUTSF;
+    u32   dwNewRsrHITAID;
+    u32   dwNewRsrHITAID0;
+
+    u32   dwRsrLong;
+    u32   dwRsrRunt;
+
+    u32   dwRsrRxControl;
+    u32   dwRsrRxData;
+    u32   dwRsrRxManage;
+
+    u32   dwRsrRxPacket;
+    u32   dwRsrRxOctet;
+    u32   dwRsrBroadcast;
+    u32   dwRsrMulticast;
+    u32   dwRsrDirected;
     // 64-bit OID
     unsigned long long   ullRsrOK;
 
@@ -287,47 +274,44 @@ typedef struct tagSStatCounter {
     unsigned long long   ullRxMulticastFrames;
     unsigned long long   ullRxDirectedFrames;
 
-    DWORD   dwRsrRxFragment;
-    DWORD   dwRsrRxFrmLen64;
-    DWORD   dwRsrRxFrmLen65_127;
-    DWORD   dwRsrRxFrmLen128_255;
-    DWORD   dwRsrRxFrmLen256_511;
-    DWORD   dwRsrRxFrmLen512_1023;
-    DWORD   dwRsrRxFrmLen1024_1518;
+    u32   dwRsrRxFragment;
+    u32   dwRsrRxFrmLen64;
+    u32   dwRsrRxFrmLen65_127;
+    u32   dwRsrRxFrmLen128_255;
+    u32   dwRsrRxFrmLen256_511;
+    u32   dwRsrRxFrmLen512_1023;
+    u32   dwRsrRxFrmLen1024_1518;
 
     // TSR status count
     //
-    DWORD   dwTsrTotalRetry;        // total collision retry count
-    DWORD   dwTsrOnceRetry;         // this packet only occur one collision
-    DWORD   dwTsrMoreThanOnceRetry; // this packet occur more than one collision
-    DWORD   dwTsrRetry;             // this packet has ever occur collision,
+    u32   dwTsrTotalRetry;        // total collision retry count
+    u32   dwTsrOnceRetry;         // this packet only occur one collision
+    u32   dwTsrMoreThanOnceRetry; // this packet occur more than one collision
+    u32   dwTsrRetry;             // this packet has ever occur collision,
                                          // that is (dwTsrOnceCollision0 + dwTsrMoreThanOnceCollision0)
-    DWORD   dwTsrACKData;
-    DWORD   dwTsrErr;
-    DWORD   dwAllTsrOK;
-    DWORD   dwTsrRetryTimeout;
-    DWORD   dwTsrTransmitTimeout;
-
-    DWORD   dwTsrTxPacket;
-    DWORD   dwTsrTxOctet;
-    DWORD   dwTsrBroadcast;
-    DWORD   dwTsrMulticast;
-    DWORD   dwTsrDirected;
+    u32   dwTsrACKData;
+    u32   dwTsrErr;
+    u32   dwAllTsrOK;
+    u32   dwTsrRetryTimeout;
+    u32   dwTsrTransmitTimeout;
+
+    u32   dwTsrTxPacket;
+    u32   dwTsrTxOctet;
+    u32   dwTsrBroadcast;
+    u32   dwTsrMulticast;
+    u32   dwTsrDirected;
 
     // RD/TD count
-    DWORD   dwCntRxFrmLength;
-    DWORD   dwCntTxBufLength;
-
-    BYTE    abyCntRxPattern[16];
-    BYTE    abyCntTxPattern[16];
-
+    u32   dwCntRxFrmLength;
+    u32   dwCntTxBufLength;
 
+    u8    abyCntRxPattern[16];
+    u8    abyCntTxPattern[16];
 
     // Software check....
-    DWORD   dwCntRxDataErr;             // rx buffer data software compare CRC err count
-    DWORD   dwCntDecryptErr;            // rx buffer data software compare CRC err count
-    DWORD   dwCntRxICVErr;              // rx buffer data software compare CRC err count
-
+    u32   dwCntRxDataErr;             // rx buffer data software compare CRC err count
+    u32   dwCntDecryptErr;            // rx buffer data software compare CRC err count
+    u32   dwCntRxICVErr;              // rx buffer data software compare CRC err count
 
     // 64-bit OID
     unsigned long long   ullTsrOK;
@@ -341,9 +325,9 @@ typedef struct tagSStatCounter {
     unsigned long long   ullTxDirectedBytes;
 
     // for autorate
-    DWORD   dwTxOk[MAX_RATE+1];
-    DWORD   dwTxFail[MAX_RATE+1];
-    DWORD   dwTxRetryCount[8];
+    u32   dwTxOk[MAX_RATE+1];
+    u32   dwTxFail[MAX_RATE+1];
+    u32   dwTxRetryCount[8];
 
     STxPktInfo  abyTxPktInfo[16];
 
@@ -367,42 +351,28 @@ typedef struct tagSStatCounter {
 
 } SStatCounter, *PSStatCounter;
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
-void STAvClearAllCounter(PSStatCounter pStatistic);
-
 void STAvUpdateIsrStatCounter(PSStatCounter pStatistic,
-                             BYTE byIsr0,
-                             BYTE byIsr1);
+                             u8 byIsr0,
+                             u8 byIsr1);
 
 void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
-                            BYTE byRSR, BYTE byNewRSR, BYTE byRxSts,
-                            BYTE byRxRate, PBYTE pbyBuffer,
+                            u8 byRSR, u8 byNewRSR, u8 byRxSts,
+                            u8 byRxRate, u8 * pbyBuffer,
                             unsigned int cbFrameLength);
 
-void STAvUpdateRDStatCounterEx(PSStatCounter pStatistic,
-                              BYTE byRSR, BYTE byNewRSR, BYTE byRxSts,
-                              BYTE byRxRate, PBYTE pbyBuffer,
-                              unsigned int cbFrameLength);
-
-void STAvUpdateTDStatCounter(PSStatCounter pStatistic, BYTE byPktNum,
-                            BYTE byRate, BYTE byTSR);
+void STAvUpdateTDStatCounter(PSStatCounter pStatistic, u8 byPktNum,
+                            u8 byRate, u8 byTSR);
 
 void
 STAvUpdate802_11Counter(
     PSDot11Counters         p802_11Counter,
     PSStatCounter           pStatistic,
-    BYTE                    byRTSSuccess,
-    BYTE                    byRTSFail,
-    BYTE                    byACKFail,
-    BYTE                    byFCSErr
+    u8                    byRTSSuccess,
+    u8                    byRTSFail,
+    u8                    byACKFail,
+    u8                    byFCSErr
     );
 
-void STAvClear802_11Counter(PSDot11Counters p802_11Counter);
 void STAvUpdateUSBCounter(PSUSBCounter pUsbCounter, int ntStatus);
 
 #endif /* __MIB_H__ */
index 4d419814f27f63c60cf386b442ad988b14de0ff1..9a5a0b6761ed344ba31e20542fc7427fb343e3f8 100644 (file)
@@ -26,8 +26,8 @@
  * Date: Sep 4, 2002
  *
  * Functions:
- *      s_dwGetUINT32 - Convert from BYTE[] to DWORD in a portable way
- *      s_vPutUINT32 - Convert from DWORD to BYTE[] in a portable way
+ *      s_dwGetUINT32 - Convert from u8[] to u32 in a portable way
+ *      s_vPutUINT32 - Convert from u32 to u8[] in a portable way
  *      s_vClear - Reset the state to the empty message.
  *      s_vSetKey - Set the key.
  *      MIC_vInit - Set the key.
 #include "tmacro.h"
 #include "michael.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
 /*
- * static DWORD s_dwGetUINT32(BYTE * p);         Get DWORD from
+ * static u32 s_dwGetUINT32(u8 * p);         Get u32 from
  *                                                     4 bytes LSByte first
- * static void s_vPutUINT32(BYTE* p, DWORD val); Put DWORD into
+ * static void s_vPutUINT32(u8* p, u32 val); Put u32 into
  *                                                     4 bytes LSByte first
  */
 static void s_vClear(void);            /* Clear the internal message,
                                         * resets the object to the
                                         * state just after construction. */
-static void s_vSetKey(DWORD dwK0, DWORD dwK1);
-static void s_vAppendByte(BYTE b);     /* Add a single byte to the internal
+static void s_vSetKey(u32 dwK0, u32 dwK1);
+static void s_vAppendByte(u8 b);       /* Add a single byte to the internal
                                         * message */
 
-/*---------------------  Export Variables  --------------------------*/
-static DWORD  L, R;            /* Current state */
-static DWORD  K0, K1;          /* Key */
-static DWORD  M;               /* Message accumulator (single word) */
+static u32  L, R;              /* Current state */
+static u32  K0, K1;            /* Key */
+static u32  M;         /* Message accumulator (single word) */
 static unsigned int   nBytesInM;       /* # bytes in M */
 
-/*---------------------  Export Functions  --------------------------*/
-
 /*
-static DWORD s_dwGetUINT32 (BYTE * p)
-// Convert from BYTE[] to DWORD in a portable way
+static u32 s_dwGetUINT32 (u8 * p)
+// Convert from u8[] to u32 in a portable way
 {
-       DWORD res = 0;
+       u32 res = 0;
        unsigned int i;
        for (i = 0; i < 4; i++)
                res |= (*p++) << (8*i);
        return res;
 }
 
-static void s_vPutUINT32(BYTE *p, DWORD val)
-// Convert from DWORD to BYTE[] in a portable way
+static void s_vPutUINT32(u8 *p, u32 val)
+// Convert from u32 to u8[] in a portable way
 {
        unsigned int i;
        for (i = 0; i < 4; i++) {
-               *p++ = (BYTE) (val & 0xff);
+               *p++ = (u8) (val & 0xff);
                val >>= 8;
        }
 }
@@ -99,7 +91,7 @@ static void s_vClear(void)
        M = 0;
 }
 
-static void s_vSetKey(DWORD dwK0, DWORD dwK1)
+static void s_vSetKey(u32 dwK0, u32 dwK1)
 {
        /* Set the key */
        K0 = dwK0;
@@ -108,7 +100,7 @@ static void s_vSetKey(DWORD dwK0, DWORD dwK1)
        s_vClear();
 }
 
-static void s_vAppendByte(BYTE b)
+static void s_vAppendByte(u8 b)
 {
        /* Append the byte to our word-sized buffer */
        M |= b << (8*nBytesInM);
@@ -130,13 +122,12 @@ static void s_vAppendByte(BYTE b)
        }
 }
 
-void MIC_vInit(DWORD dwK0, DWORD dwK1)
+void MIC_vInit(u32 dwK0, u32 dwK1)
 {
        /* Set the key */
        s_vSetKey(dwK0, dwK1);
 }
 
-
 void MIC_vUnInit(void)
 {
        /* Wipe the key material */
@@ -148,7 +139,7 @@ void MIC_vUnInit(void)
        s_vClear();
 }
 
-void MIC_vAppend(PBYTE src, unsigned int nBytes)
+void MIC_vAppend(u8 * src, unsigned int nBytes)
 {
     /* This is simple */
        while (nBytes > 0) {
@@ -157,7 +148,7 @@ void MIC_vAppend(PBYTE src, unsigned int nBytes)
        }
 }
 
-void MIC_vGetMIC(PDWORD pdwL, PDWORD pdwR)
+void MIC_vGetMIC(u32 * pdwL, u32 * pdwR)
 {
        /* Append the minimum padding */
        s_vAppendByte(0x5a);
index 81351f506232339188d54468792329756de93932..9c69a42640a7e6d8978599c4dc4b79f733be7465 100644 (file)
 #ifndef __MICHAEL_H__
 #define __MICHAEL_H__
 
-/*---------------------  Export Definitions -------------------------*/
+#include <linux/types.h>
 
-/*---------------------  Export Types  ------------------------------*/
-
-void MIC_vInit(DWORD dwK0, DWORD dwK1);
+void MIC_vInit(u32 dwK0, u32 dwK1);
 
 void MIC_vUnInit(void);
 
 // Append bytes to the message to be MICed
-void MIC_vAppend(PBYTE src, unsigned int nBytes);
+void MIC_vAppend(u8 * src, unsigned int nBytes);
 
 // Get the MIC result. Destination should accept 8 bytes of result.
 // This also resets the message to empty.
-void MIC_vGetMIC(PDWORD pdwL, PDWORD pdwR);
-
-/*---------------------  Export Macros ------------------------------*/
+void MIC_vGetMIC(u32 * pdwL, u32 * pdwR);
 
 // Rotation functions on 32 bit values
 #define ROL32(A, n) \
index 527c259f67580e46645599b0d3d0e25c34a13ed3..edc8975b2e2a0ceae17aabea15813285cd8c3846 100644 (file)
@@ -37,7 +37,6 @@
  *
  */
 
-#include "ttype.h"
 #include "mac.h"
 #include "device.h"
 #include "wmgr.h"
 #include "control.h"
 #include "rndis.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
 static int msglevel = MSG_LEVEL_INFO;
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
 
 /*
  *
@@ -290,7 +279,7 @@ int PSbSendNullPacket(struct vnt_private *pDevice)
        pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(flags);
 
        if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA)
-               pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_TODS(1));
+               pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((u16)WLAN_SET_FC_TODS(1));
 
        memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
        memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
index 879b10c0d42e6ce1e7c2f8fc2d67754f64e5baea..77835823943764e01ac909ecfffb72287d23ffb5 100644 (file)
 #ifndef __POWER_H__
 #define __POWER_H__
 
-
-/*---------------------  Export Definitions -------------------------*/
 #define     C_PWBT                   1000      // micro sec. power up before TBTT
 #define     PS_FAST_INTERVAL         1         // Fast power saving listen interval
 #define     PS_MAX_INTERVAL          4         // MAX power saving listen interval
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-
-/*---------------------  Export Types  ------------------------------*/
-
-
-/*---------------------  Export Functions  --------------------------*/
-
 /*  PSDevice pDevice */
 /*  PSDevice hDeviceContext */
 
index 5c3c2d0552b49f6ba51549b911208f966ea00c8d..2fd836f07536aba95ac198ce8d407d3db9b0e231 100644 (file)
 
 #include "rc4.h"
 
-void rc4_init(PRC4Ext pRC4, PBYTE pbyKey, unsigned int cbKey_len)
+void rc4_init(PRC4Ext pRC4, u8 * pbyKey, unsigned int cbKey_len)
 {
        unsigned int  ust1, ust2;
        unsigned int  keyindex;
        unsigned int  stateindex;
-       PBYTE pbyst;
+       u8 * pbyst;
        unsigned int  idx;
 
        pbyst = pRC4->abystate;
        pRC4->ux = 0;
        pRC4->uy = 0;
        for (idx = 0; idx < 256; idx++)
-               pbyst[idx] = (BYTE)idx;
+               pbyst[idx] = (u8)idx;
        keyindex = 0;
        stateindex = 0;
        for (idx = 0; idx < 256; idx++) {
                ust1 = pbyst[idx];
                stateindex = (stateindex + pbyKey[keyindex] + ust1) & 0xff;
                ust2 = pbyst[stateindex];
-               pbyst[stateindex] = (BYTE)ust1;
-               pbyst[idx] = (BYTE)ust2;
+               pbyst[stateindex] = (u8)ust1;
+               pbyst[idx] = (u8)ust2;
                if (++keyindex >= cbKey_len)
                        keyindex = 0;
        }
@@ -63,7 +63,7 @@ unsigned int rc4_byte(PRC4Ext pRC4)
        unsigned int ux;
        unsigned int uy;
        unsigned int ustx, usty;
-       PBYTE pbyst;
+       u8 * pbyst;
 
        pbyst = pRC4->abystate;
        ux = (pRC4->ux + 1) & 0xff;
@@ -72,16 +72,16 @@ unsigned int rc4_byte(PRC4Ext pRC4)
        usty = pbyst[uy];
        pRC4->ux = ux;
        pRC4->uy = uy;
-       pbyst[uy] = (BYTE)ustx;
-       pbyst[ux] = (BYTE)usty;
+       pbyst[uy] = (u8)ustx;
+       pbyst[ux] = (u8)usty;
 
        return pbyst[(ustx + usty) & 0xff];
 }
 
-void rc4_encrypt(PRC4Ext pRC4, PBYTE pbyDest,
-                       PBYTE pbySrc, unsigned int cbData_len)
+void rc4_encrypt(PRC4Ext pRC4, u8 * pbyDest,
+                       u8 * pbySrc, unsigned int cbData_len)
 {
        unsigned int ii;
        for (ii = 0; ii < cbData_len; ii++)
-               pbyDest[ii] = (BYTE)(pbySrc[ii] ^ rc4_byte(pRC4));
+               pbyDest[ii] = (u8)(pbySrc[ii] ^ rc4_byte(pRC4));
 }
index d447879c8f99e3603c886e1b14d0bbbf2dfef5c7..d376e1adcc1c119af73591a4d829d2f9d0541f0c 100644 (file)
 #ifndef __RC4_H__
 #define __RC4_H__
 
-#include "ttype.h"
+#include <linux/types.h>
 
-/*---------------------  Export Definitions -------------------------*/
-/*---------------------  Export Types  ------------------------------*/
 typedef struct {
     unsigned int ux;
     unsigned int uy;
-    BYTE abystate[256];
+    u8 abystate[256];
 } RC4Ext, *PRC4Ext;
 
-void rc4_init(PRC4Ext pRC4, PBYTE pbyKey, unsigned int cbKey_len);
+void rc4_init(PRC4Ext pRC4, u8 * pbyKey, unsigned int cbKey_len);
 unsigned int rc4_byte(PRC4Ext pRC4);
-void rc4_encrypt(PRC4Ext pRC4, PBYTE pbyDest, PBYTE pbySrc,
+void rc4_encrypt(PRC4Ext pRC4, u8 * pbyDest, u8 * pbySrc,
                 unsigned int cbData_len);
 
 #endif /* __RC4_H__ */
index a415705297b2f32b7e59892344b5227c206c8545..44cfe0b141800d5cbb3a0fa8f46314f7e9279941 100644 (file)
@@ -41,7 +41,6 @@
 
 static int          msglevel                =MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-/*---------------------  Static Definitions -------------------------*/
 #define BY_AL2230_REG_LEN     23 //24bit
 #define CB_AL2230_INIT_SEQ    15
 #define AL2230_PWR_IDX_LEN    64
@@ -62,13 +61,6 @@ static int          msglevel                =MSG_LEVEL_INFO;
 #define VT3342_PWR_IDX_LEN    64
 //}}
 
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-
-
-
 u8 abyAL2230InitTable[CB_AL2230_INIT_SEQ][3] = {
     {0x03, 0xF7, 0x90},
     {0x03, 0x33, 0x31},
@@ -388,7 +380,6 @@ u8 abyVT3226D0_InitTable[CB_VT3226_INIT_SEQ][3] = {
     {0x02, 0x01, 0xAA}  //RobertYu:20060523
     };
 
-
 u8 abyVT3226_ChannelTable0[CB_MAX_CHANNEL_24G][3] = {
     {0x01, 0x97, 0x83}, // channel = 1, Tf = 2412MHz
     {0x01, 0x97, 0x83}, // channel = 2, Tf = 2417MHz
@@ -424,7 +415,6 @@ u8 abyVT3226_ChannelTable1[CB_MAX_CHANNEL_24G][3] = {
     };
 ///}}RobertYu
 
-
 //{{RobertYu:20060502, TWIF 1.14, LO Current for 11b mode
 u32 dwVT3226D0LoCurrentTable[CB_MAX_CHANNEL_24G] = {
     0x0135C600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz
@@ -444,7 +434,6 @@ u32 dwVT3226D0LoCurrentTable[CB_MAX_CHANNEL_24G] = {
 };
 //}}
 
-
 //{{RobertYu:20060609
 u8 abyVT3342A0_InitTable[CB_VT3342_INIT_SEQ][3] = { /* 11b/g mode */
     {0x03, 0xFF, 0x80}, //update for mode//
@@ -599,7 +588,6 @@ u8 abyVT3342_ChannelTable1[CB_MAX_CHANNEL][3] = {
     {0x03, 0x00, 0x04}  // channel = 165, Tf = 5825MHz (56), TBD
     };
 
-
 /*+
  *
  * Power Table
@@ -673,10 +661,6 @@ const u32 dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = {
     0x0407F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW
     };
 
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
 //{{ RobertYu:20050103, Channel 11a Number To Index
 // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196  (Value:15 ~ 22)
 // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
@@ -708,8 +692,6 @@ const u8 RFaby11aChannelIndex[200] = {
 };
 //}} RobertYu
 
-/*---------------------  Export Functions  --------------------------*/
-
 /*
  * Description: Write to IF/RF, by embedded programming
  *
@@ -734,11 +716,9 @@ int IFRFbWriteEmbedded(struct vnt_private *pDevice, u32 dwData)
        CONTROLnsRequestOut(pDevice,
                MESSAGE_TYPE_WRITE_IFRF, 0, 0, 4, pbyData);
 
-
        return true;
 }
 
-
 /*
  * Description: Set Tx power
  *
@@ -790,7 +770,6 @@ int RFbSetPower(struct vnt_private *pDevice, u32 uRATE, u32 uCH)
     return bResult;
 }
 
-
 /*
  * Description: Set Tx power
  *
@@ -839,10 +818,9 @@ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE)
             }
             break;
 
-
         case RF_AIROHA7230:
             {
-                DWORD       dwMax7230Pwr;
+                u32       dwMax7230Pwr;
 
                 if (uRATE <= RATE_11M) { //RobertYu:20060426, for better 11b mask
                     bResult &= IFRFbWriteEmbedded(pDevice, 0x111BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW);
@@ -864,7 +842,7 @@ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE)
 
         case RF_VT3226: //RobertYu:20051111, VT3226C0 and before
         {
-            DWORD       dwVT3226Pwr;
+            u32       dwVT3226Pwr;
 
             if (pDevice->byCurPwr >= VT3226_PWR_IDX_LEN)
                 return false;
@@ -876,7 +854,7 @@ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE)
 
         case RF_VT3226D0: //RobertYu:20051228
         {
-            DWORD       dwVT3226Pwr;
+            u32       dwVT3226Pwr;
 
             if (pDevice->byCurPwr >= VT3226_PWR_IDX_LEN)
                 return false;
@@ -921,7 +899,7 @@ int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE)
         //{{RobertYu:20060609
         case RF_VT3342A0:
         {
-            DWORD       dwVT3342Pwr;
+            u32       dwVT3342Pwr;
 
             if (pDevice->byCurPwr >= VT3342_PWR_IDX_LEN)
                 return false;
@@ -976,8 +954,6 @@ void RFvRSSITodBm(struct vnt_private *pDevice, u8 byCurrRSSI, long *pldBm)
     *pldBm = -1 * (a + b * 2);
 }
 
-
-
 void RFbRFTableDownload(struct vnt_private *pDevice)
 {
        u16 wLength1 = 0, wLength2 = 0, wLength3 = 0;
@@ -1121,20 +1097,3 @@ void RFbRFTableDownload(struct vnt_private *pDevice)
     }
 
 }
-
-int s_bVT3226D0_11bLoCurrentAdjust(struct vnt_private *pDevice, u8 byChannel,
-       int b11bMode)
-{
-       int bResult = true;
-
-       if (b11bMode)
-               bResult &= IFRFbWriteEmbedded(pDevice,
-                       dwVT3226D0LoCurrentTable[byChannel-1]);
-       else
-               bResult &= IFRFbWriteEmbedded(pDevice, 0x016bc600 +
-                       (BY_VT3226_REG_LEN << 3) + IFREGCTL_REGW);
-
-       return bResult;
-}
-
-
index 9f70cf740baefc46fbafb121f6048c20f58c3ab6..de5c613b4ef992273b96416b11b79489da80ff12 100644 (file)
 #ifndef __RF_H__
 #define __RF_H__
 
-#include "ttype.h"
 #include "device.h"
 
-/*---------------------  Export Definitions -------------------------*/
 //
 // Baseband RF pair definition in eeprom (Bits 6..0)
 //
 #define RF_EMU              0x80
 #define RF_MASK             0x7F
 
-
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
 extern const u8 RFaby11aChannelIndex[200];
-/*---------------------  Export Functions  --------------------------*/
 
 int IFRFbWriteEmbedded(struct vnt_private *, u32 dwData);
 int RFbSetPower(struct vnt_private *, u32 uRATE, u32 uCH);
 int RFbRawSetPower(struct vnt_private *, u8 byPwr, u32 uRATE);
 void RFvRSSITodBm(struct vnt_private *, u8 byCurrRSSI, long *pldBm);
 void RFbRFTableDownload(struct vnt_private *pDevice);
-int s_bVT3226D0_11bLoCurrentAdjust(struct vnt_private *, u8 byChannel,
-       int b11bMode);
 
 #endif /* __RF_H__ */
index fccf7e98eb68d17e6b7c586b12bb92443f4e0d2f..5e073062017a2e657e1f0b33ebddcaa1d2fa21c4 100644 (file)
  *
  */
 
-
 #ifndef __RNDIS_H__
 #define __RNDIS_H__
 
-/*---------------------  Export Definitions -------------------------*/
 #define MESSAGE_TYPE_READ               0x01
 #define MESSAGE_TYPE_WRITE              0x00
 #define MESSAGE_TYPE_LOCK_OR            0x02
 #define MESSAGE_REQUEST_RF_CH1          0x0C
 #define MESSAGE_REQUEST_RF_CH2          0x0D
 
-
 #define VIAUSB20_PACKET_HEADER          0x04
 
-
-/*---------------------  Export Classes  ----------------------------*/
-
 typedef struct _CMD_MESSAGE
 {
-    BYTE        byData[256];
+    u8        byData[256];
 } CMD_MESSAGE, *PCMD_MESSAGE;
 
 typedef struct _CMD_WRITE_MASK
 {
-    BYTE        byData;
-    BYTE        byMask;
+    u8        byData;
+    u8        byMask;
 } CMD_WRITE_MASK, *PCMD_WRITE_MASK;
 
 typedef struct _CMD_CARD_INIT
 {
-    BYTE        byInitClass;
-    BYTE        bExistSWNetAddr;
-    BYTE        bySWNetAddr[6];
-    BYTE        byShortRetryLimit;
-    BYTE        byLongRetryLimit;
+    u8        byInitClass;
+    u8        bExistSWNetAddr;
+    u8        bySWNetAddr[6];
+    u8        byShortRetryLimit;
+    u8        byLongRetryLimit;
 } CMD_CARD_INIT, *PCMD_CARD_INIT;
 
 typedef struct _RSP_CARD_INIT
 {
-    BYTE        byStatus;
-    BYTE        byNetAddr[6];
-    BYTE        byRFType;
-    BYTE        byMinChannel;
-    BYTE        byMaxChannel;
+    u8        byStatus;
+    u8        byNetAddr[6];
+    u8        byRFType;
+    u8        byMinChannel;
+    u8        byMaxChannel;
 } RSP_CARD_INIT, *PRSP_CARD_INIT;
 
 typedef struct _CMD_SET_KEY
 {
-    WORD        wKCTL;
-    BYTE        abyMacAddr[6];
-    BYTE        abyKey[16];
+    u16        wKCTL;
+    u8        abyMacAddr[6];
+    u8        abyKey[16];
 } CMD_SET_KEY, *PCMD_SET_KEY;
 
 typedef struct _CMD_CLRKEY_ENTRY
 {
-    BYTE        abyKeyEntry[11];
+    u8        abyKeyEntry[11];
 } CMD_CLRKEY_ENTRY, *PCMD_CLRKEY_ENTRY;
 
 typedef struct _CMD_WRITE_MISCFF
 {
-    DWORD       adwMiscFFData[22][4];  //a key entry has only 22 dwords
+    u32       adwMiscFFData[22][4];  //a key entry has only 22 dwords
 } CMD_WRITE_MISCFF, *PCMD_WRITE_MISCFF;
 
 typedef struct _CMD_SET_TSFTBTT
 {
-    BYTE        abyTSF_TBTT[8];
+    u8        abyTSF_TBTT[8];
 } CMD_SET_TSFTBTT, *PCMD_SET_TSFTBTT;
 
 typedef struct _CMD_SET_SSTIFS
 {
-    BYTE        bySIFS;
-    BYTE        byDIFS;
-    BYTE        byEIFS;
-    BYTE        bySlotTime;
-    BYTE        byCwMax_Min;
-    BYTE        byBBCR10;
+    u8        bySIFS;
+    u8        byDIFS;
+    u8        byEIFS;
+    u8        bySlotTime;
+    u8        byCwMax_Min;
+    u8        byBBCR10;
 } CMD_SET_SSTIFS, *PCMD_SET_SSTIFS;
 
 typedef struct _CMD_CHANGE_BBTYPE
 {
-    BYTE        bySIFS;
-    BYTE        byDIFS;
-    BYTE        byEIFS;
-    BYTE        bySlotTime;
-    BYTE        byCwMax_Min;
-    BYTE        byBBCR10;
-    BYTE        byBB_BBType;    //CR88
-    BYTE        byMAC_BBType;
-    DWORD       dwRSPINF_b_1;
-    DWORD       dwRSPINF_b_2;
-    DWORD       dwRSPINF_b_55;
-    DWORD       dwRSPINF_b_11;
-    WORD        wRSPINF_a[9];
+    u8        bySIFS;
+    u8        byDIFS;
+    u8        byEIFS;
+    u8        bySlotTime;
+    u8        byCwMax_Min;
+    u8        byBBCR10;
+    u8        byBB_BBType;    //CR88
+    u8        byMAC_BBType;
+    u32       dwRSPINF_b_1;
+    u32       dwRSPINF_b_2;
+    u32       dwRSPINF_b_55;
+    u32       dwRSPINF_b_11;
+    u16        wRSPINF_a[9];
 } CMD_CHANGE_BBTYPE, *PCMD_CHANGE_BBTYPE;
 
-/*---------------------  Export Macros -------------------------*/
-
-#define EXCH_WORD(w) ((WORD)((WORD)(w)<<8) | (WORD)((WORD)(w)>>8))
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
+#define EXCH_WORD(w) ((u16)((u16)(w)<<8) | (u16)((u16)(w)>>8))
 
 #endif /* _RNDIS_H_ */
index b939dcf689d6c31ac19ccd733b579d794a98dd3c..9bf2f8d562c3faf6c7bdb4540b66f42ac5e27b64 100644 (file)
 #include "usbpipe.h"
 #include "iocmd.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
 static int          msglevel                = MSG_LEVEL_INFO;
 
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Static Definitions -------------------------*/
-
-const WORD wTimeStampOff[2][MAX_RATE] = {
+const u16 wTimeStampOff[2][MAX_RATE] = {
         {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
         {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
     };
 
-const WORD wFB_Opt0[2][5] = {
+const u16 wFB_Opt0[2][5] = {
         {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
         {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
     };
-const WORD wFB_Opt1[2][5] = {
+const u16 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
     };
 
-
 #define RTSDUR_BB       0
 #define RTSDUR_BA       1
 #define RTSDUR_AA       2
@@ -104,8 +94,6 @@ const WORD wFB_Opt1[2][5] = {
 #define DATADUR_A_F0    12
 #define DATADUR_A_F1    13
 
-/*---------------------  Static Functions  --------------------------*/
-
 static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
        u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
 
@@ -114,16 +102,15 @@ static void *s_vGetFreeContext(struct vnt_private *pDevice);
 static void s_vGenerateTxParameter(struct vnt_private *pDevice,
        u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
        void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
-       PSEthernetHeader psEthHeader);
+       struct ethhdr *psEthHeader);
 
 static u32 s_uFillDataHead(struct vnt_private *pDevice,
        u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
        u32 uDMAIdx, int bNeedAck, u32 uFragIdx, u32 cbLastFragmentSize,
        u32 uMACfragNum, u8 byFBOption);
 
-
 static void s_vGenerateMACHeader(struct vnt_private *pDevice,
-       u8 *pbyBufferAddr, u16 wDuration, PSEthernetHeader psEthHeader,
+       u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
        int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
 
 static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
@@ -145,7 +132,7 @@ static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
 
 static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
        void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
-       PSEthernetHeader psEthHeader, u16 wCurrentRate, u8 byFBOption);
+       struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
 
 static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
        u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
@@ -156,9 +143,6 @@ static unsigned int s_uGetRTSCTSDuration(struct vnt_private *pDevice,
        u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
        int bNeedAck, u8 byFBOption);
 
-
-/*---------------------  Export Variables  --------------------------*/
-
 static void *s_vGetFreeContext(struct vnt_private *pDevice)
 {
        PUSB_SEND_CONTEXT pContext = NULL;
@@ -181,7 +165,6 @@ static void *s_vGetFreeContext(struct vnt_private *pDevice)
     return (void *) pReturnContext;
 }
 
-
 static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
        u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
 {
@@ -208,10 +191,9 @@ static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
        u32 *pdwIV = (u32 *)pbyIVHead;
        u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
        u16 wValue;
-       PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
+       struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
        u32 dwRevIVCounter;
 
-
     //Fill TXKEY
     if (pTransmitKey == NULL)
         return;
@@ -222,13 +204,13 @@ static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
 
     if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
         if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
-            memcpy(pDevice->abyPRNG, (PBYTE)&(dwRevIVCounter), 3);
+            memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
             memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
         } else {
-            memcpy(pbyBuf, (PBYTE)&(dwRevIVCounter), 3);
+            memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
             memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
             if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
-                memcpy(pbyBuf+8, (PBYTE)&(dwRevIVCounter), 3);
+                memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
                 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
             }
             memcpy(pDevice->abyPRNG, pbyBuf, 16);
@@ -252,7 +234,7 @@ static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
         // Make IV
         memcpy(pdwIV, pDevice->abyPRNG, 3);
 
-        *(pbyIVHead+3) = (BYTE)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
+        *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
         // Append IV&ExtIV after Mac Header
         *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
@@ -267,49 +249,48 @@ static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
 
         // Make IV
         *pdwIV = 0;
-        *(pbyIVHead+3) = (BYTE)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
-        *pdwIV |= cpu_to_le16((WORD)(pTransmitKey->wTSC15_0));
+        *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
+        *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
         //Append IV&ExtIV after Mac Header
         *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
 
         //Fill MICHDR0
         *pMICHDR = 0x59;
-        *((PBYTE)(pMICHDR+1)) = 0; // TxPriority
-        memcpy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
-        *((PBYTE)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
-        *((PBYTE)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
-        *((PBYTE)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
-        *((PBYTE)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
-        *((PBYTE)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
-        *((PBYTE)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
-        *((PBYTE)(pMICHDR+14)) = HIBYTE(wPayloadLen);
-        *((PBYTE)(pMICHDR+15)) = LOBYTE(wPayloadLen);
+        *((u8 *)(pMICHDR+1)) = 0; // TxPriority
+        memcpy(pMICHDR+2, &(pMACHeader->addr2[0]), 6);
+        *((u8 *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
+        *((u8 *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
+        *((u8 *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
+        *((u8 *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
+        *((u8 *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
+        *((u8 *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
+        *((u8 *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
+        *((u8 *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
 
         //Fill MICHDR1
-        *((PBYTE)(pMICHDR+16)) = 0; // HLEN[15:8]
+        *((u8 *)(pMICHDR+16)) = 0; // HLEN[15:8]
         if (pDevice->bLongHeader) {
-            *((PBYTE)(pMICHDR+17)) = 28; // HLEN[7:0]
+            *((u8 *)(pMICHDR+17)) = 28; // HLEN[7:0]
         } else {
-            *((PBYTE)(pMICHDR+17)) = 22; // HLEN[7:0]
+            *((u8 *)(pMICHDR+17)) = 22; // HLEN[7:0]
         }
-        wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
-        memcpy(pMICHDR+18, (PBYTE)&wValue, 2); // MSKFRACTL
-        memcpy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
-        memcpy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
+        wValue = cpu_to_le16(pMACHeader->frame_control & 0xC78F);
+        memcpy(pMICHDR+18, (u8 *)&wValue, 2); // MSKFRACTL
+        memcpy(pMICHDR+20, &(pMACHeader->addr1[0]), 6);
+        memcpy(pMICHDR+26, &(pMACHeader->addr2[0]), 6);
 
         //Fill MICHDR2
-        memcpy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
-        wValue = pMACHeader->wSeqCtl;
+        memcpy(pMICHDR+32, &(pMACHeader->addr3[0]), 6);
+        wValue = pMACHeader->seq_ctrl;
         wValue &= 0x000F;
         wValue = cpu_to_le16(wValue);
-        memcpy(pMICHDR+38, (PBYTE)&wValue, 2); // MSKSEQCTL
+        memcpy(pMICHDR+38, (u8 *)&wValue, 2); // MSKSEQCTL
         if (pDevice->bLongHeader) {
-            memcpy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
+            memcpy(pMICHDR+40, &(pMACHeader->addr4[0]), 6);
         }
     }
 }
 
-
 static void s_vSWencryption(struct vnt_private *pDevice,
        PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
 {
@@ -324,7 +305,7 @@ static void s_vSWencryption(struct vnt_private *pDevice,
         //=======================================================================
         // Append ICV after payload
         dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
-        pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
+        pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
         // finally, we must invert dwCRC to get the correct answer
         *pdwICV = cpu_to_le32(~dwICV);
         // RC4 encryption
@@ -335,7 +316,7 @@ static void s_vSWencryption(struct vnt_private *pDevice,
         //=======================================================================
         //Append ICV after payload
         dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
-        pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
+        pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
         // finally, we must invert dwCRC to get the correct answer
         *pdwICV = cpu_to_le32(~dwICV);
         // RC4 encryption
@@ -345,9 +326,6 @@ static void s_vSWencryption(struct vnt_private *pDevice,
     }
 }
 
-
-
-
 /*byPktType : PK_TYPE_11A     0
              PK_TYPE_11B     1
              PK_TYPE_11GB    2
@@ -360,9 +338,9 @@ static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
 
     uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
     if (byPktType == PK_TYPE_11B) {//llb,CCK mode
-        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopCCKBasicRate);
+        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
     } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
-        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopOFDMBasicRate);
+        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
     }
 
     if (bNeedAck) {
@@ -381,7 +359,6 @@ static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
 
     uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
 
-
     uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
     if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
         uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
@@ -447,7 +424,6 @@ static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
         }
         break;
 
-
     case DATADUR_A:    //DATADUR_A
         if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
             if(bNeedAck){
@@ -566,7 +542,6 @@ static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
        return 0;
 }
 
-
 //byFreqType: 0=>5GHZ 1=>2.4GHZ
 static u32 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
        u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
@@ -574,7 +549,6 @@ static u32 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
 {
        u32 uCTSTime = 0, uDurTime = 0;
 
-
     switch (byDurType) {
 
     case RTSDUR_BB:    //RTSDuration_bb
@@ -671,10 +645,10 @@ static u32 s_uFillDataHead(struct vnt_private *pDevice,
                PSTxDataHead_ab pBuf = (PSTxDataHead_ab) pTxDataHead;
             //Get SignalField,ServiceField,Length
             BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
-                (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
+                (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
             );
             //Get Duration and TimeStampOff
-            pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
+            pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
                                                        wCurrentRate, bNeedAck, uFragIdx,
                                                        cbLastFragmentSize, uMACfragNum,
                                                        byFBOption); //1: 2.4GHz
@@ -688,17 +662,17 @@ static u32 s_uFillDataHead(struct vnt_private *pDevice,
                 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
                 //Get SignalField,ServiceField,Length
                 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
-                    (PWORD)&(pBuf->wTransmitLength_a), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
+                    (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
                 );
                 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                    (PWORD)&(pBuf->wTransmitLength_b), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
+                    (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
                 );
                 //Get Duration and TimeStamp
-                pBuf->wDuration_a = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
+                pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
                                                              byPktType, wCurrentRate, bNeedAck, uFragIdx,
                                                              cbLastFragmentSize, uMACfragNum,
                                                              byFBOption); //1: 2.4GHz
-                pBuf->wDuration_b = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
+                pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
                                                              PK_TYPE_11B, pDevice->byTopCCKBasicRate,
                                                              bNeedAck, uFragIdx, cbLastFragmentSize,
                                                              uMACfragNum, byFBOption); //1: 2.4GHz
@@ -711,19 +685,19 @@ static u32 s_uFillDataHead(struct vnt_private *pDevice,
                 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
                 //Get SignalField,ServiceField,Length
                 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
-                    (PWORD)&(pBuf->wTransmitLength_a), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
+                    (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
                 );
                 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                    (PWORD)&(pBuf->wTransmitLength_b), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
+                    (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
                 );
                 //Get Duration and TimeStamp
-                pBuf->wDuration_a = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
+                pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
                                              wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
-                pBuf->wDuration_b = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
+                pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
                                              pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
-                pBuf->wDuration_a_f0 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
+                pBuf->wDuration_a_f0 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
                                              wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
-                pBuf->wDuration_a_f1 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
+                pBuf->wDuration_a_f1 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
                                              wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
                 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
                 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
@@ -737,14 +711,14 @@ static u32 s_uFillDataHead(struct vnt_private *pDevice,
             PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
             //Get SignalField,ServiceField,Length
             BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
-                (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
+                (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
             );
             //Get Duration and TimeStampOff
-            pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
+            pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
                                         wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
-            pBuf->wDuration_f0 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
+            pBuf->wDuration_f0 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
                                         wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
-            pBuf->wDuration_f1 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
+            pBuf->wDuration_f1 = (u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
                                         wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
             if(uDMAIdx!=TYPE_ATIMDMA) {
                 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
@@ -754,10 +728,10 @@ static u32 s_uFillDataHead(struct vnt_private *pDevice,
             PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
             //Get SignalField,ServiceField,Length
             BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
-                (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
+                (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
             );
             //Get Duration and TimeStampOff
-            pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
+            pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
                                                        wCurrentRate, bNeedAck, uFragIdx,
                                                        cbLastFragmentSize, uMACfragNum,
                                                        byFBOption);
@@ -772,10 +746,10 @@ static u32 s_uFillDataHead(struct vnt_private *pDevice,
             PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
             //Get SignalField,ServiceField,Length
             BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
-                (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
+                (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
             );
             //Get Duration and TimeStampOff
-            pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
+            pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
                                                        wCurrentRate, bNeedAck, uFragIdx,
                                                        cbLastFragmentSize, uMACfragNum,
                                                        byFBOption);
@@ -789,7 +763,7 @@ static u32 s_uFillDataHead(struct vnt_private *pDevice,
 
 static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
        void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
-       PSEthernetHeader psEthHeader, u16 wCurrentRate, u8 byFBOption)
+       struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
 {
        u32 uRTSFrameLen = 20;
        u16 wLen = 0;
@@ -810,17 +784,17 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
             PSRTS_g pBuf = (PSRTS_g)pvRTS;
             //Get SignalField,ServiceField,Length
             BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
+                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
             );
             pBuf->wTransmitLength_b = cpu_to_le16(wLen);
             BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
-                (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
+                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
             );
             pBuf->wTransmitLength_a = cpu_to_le16(wLen);
             //Get Duration
-            pBuf->wDuration_bb = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption));    //0:RTSDuration_bb, 1:2.4G, 1:CCKData
-            pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
-            pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
+            pBuf->wDuration_bb = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption));    //0:RTSDuration_bb, 1:2.4G, 1:CCKData
+            pBuf->wDuration_aa = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
+            pBuf->wDuration_ba = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
 
             pBuf->Data.wDurationID = pBuf->wDuration_aa;
             //Get RTS Frame body
@@ -829,7 +803,7 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
        if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
            (pDevice->eOPMode == OP_MODE_AP)) {
                memcpy(&(pBuf->Data.abyRA[0]),
-                      &(psEthHeader->abyDstAddr[0]),
+                      &(psEthHeader->h_dest[0]),
                       ETH_ALEN);
        }
             else {
@@ -844,7 +818,7 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
        }
             else {
                    memcpy(&(pBuf->Data.abyTA[0]),
-                          &(psEthHeader->abySrcAddr[0]),
+                          &(psEthHeader->h_source[0]),
                           ETH_ALEN);
             }
         }
@@ -852,21 +826,21 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
            PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
             //Get SignalField,ServiceField,Length
             BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
+                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
             );
             pBuf->wTransmitLength_b = cpu_to_le16(wLen);
             BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
-                (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
+                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
             );
             pBuf->wTransmitLength_a = cpu_to_le16(wLen);
             //Get Duration
-            pBuf->wDuration_bb = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption));    //0:RTSDuration_bb, 1:2.4G, 1:CCKData
-            pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
-            pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
-            pBuf->wRTSDuration_ba_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
-            pBuf->wRTSDuration_aa_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
-            pBuf->wRTSDuration_ba_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
-            pBuf->wRTSDuration_aa_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
+            pBuf->wDuration_bb = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption));    //0:RTSDuration_bb, 1:2.4G, 1:CCKData
+            pBuf->wDuration_aa = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
+            pBuf->wDuration_ba = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
+            pBuf->wRTSDuration_ba_f0 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
+            pBuf->wRTSDuration_aa_f0 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
+            pBuf->wRTSDuration_ba_f1 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
+            pBuf->wRTSDuration_aa_f1 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));    //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
             pBuf->Data.wDurationID = pBuf->wDuration_aa;
             //Get RTS Frame body
             pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
@@ -874,7 +848,7 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
        if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
            (pDevice->eOPMode == OP_MODE_AP)) {
                memcpy(&(pBuf->Data.abyRA[0]),
-                      &(psEthHeader->abyDstAddr[0]),
+                      &(psEthHeader->h_dest[0]),
                       ETH_ALEN);
        }
             else {
@@ -890,7 +864,7 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
        }
             else {
                    memcpy(&(pBuf->Data.abyTA[0]),
-                          &(psEthHeader->abySrcAddr[0]),
+                          &(psEthHeader->h_source[0]),
                           ETH_ALEN);
             }
 
@@ -901,11 +875,11 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
             PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
             //Get SignalField,ServiceField,Length
             BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
-                (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
+                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
             );
             pBuf->wTransmitLength = cpu_to_le16(wLen);
             //Get Duration
-            pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
+            pBuf->wDuration = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
            pBuf->Data.wDurationID = pBuf->wDuration;
             //Get RTS Frame body
             pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
@@ -913,7 +887,7 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
        if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
            (pDevice->eOPMode == OP_MODE_AP)) {
                memcpy(&(pBuf->Data.abyRA[0]),
-                      &(psEthHeader->abyDstAddr[0]),
+                      &(psEthHeader->h_dest[0]),
                       ETH_ALEN);
        } else {
                memcpy(&(pBuf->Data.abyRA[0]),
@@ -927,7 +901,7 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
                       ETH_ALEN);
        } else {
                memcpy(&(pBuf->Data.abyTA[0]),
-                      &(psEthHeader->abySrcAddr[0]),
+                      &(psEthHeader->h_source[0]),
                       ETH_ALEN);
        }
 
@@ -936,13 +910,13 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
             PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
             //Get SignalField,ServiceField,Length
             BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
-                (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
+                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
             );
             pBuf->wTransmitLength = cpu_to_le16(wLen);
             //Get Duration
-            pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
-           pBuf->wRTSDuration_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
-           pBuf->wRTSDuration_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:RTSDuration_aa_f1, 0:5G, 0:
+            pBuf->wDuration = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
+           pBuf->wRTSDuration_f0 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
+           pBuf->wRTSDuration_f1 = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:RTSDuration_aa_f1, 0:5G, 0:
            pBuf->Data.wDurationID = pBuf->wDuration;
            //Get RTS Frame body
             pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
@@ -950,7 +924,7 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
        if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
            (pDevice->eOPMode == OP_MODE_AP)) {
                memcpy(&(pBuf->Data.abyRA[0]),
-                      &(psEthHeader->abyDstAddr[0]),
+                      &(psEthHeader->h_dest[0]),
                       ETH_ALEN);
        } else {
                memcpy(&(pBuf->Data.abyRA[0]),
@@ -963,7 +937,7 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
                       ETH_ALEN);
        } else {
                memcpy(&(pBuf->Data.abyTA[0]),
-                      &(psEthHeader->abySrcAddr[0]),
+                      &(psEthHeader->h_source[0]),
                       ETH_ALEN);
        }
         }
@@ -972,11 +946,11 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
         PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
         //Get SignalField,ServiceField,Length
         BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-            (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
+            (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
         );
         pBuf->wTransmitLength = cpu_to_le16(wLen);
         //Get Duration
-        pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
+        pBuf->wDuration = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
         pBuf->Data.wDurationID = pBuf->wDuration;
         //Get RTS Frame body
         pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
@@ -984,7 +958,7 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
        if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
             (pDevice->eOPMode == OP_MODE_AP)) {
                memcpy(&(pBuf->Data.abyRA[0]),
-                      &(psEthHeader->abyDstAddr[0]),
+                      &(psEthHeader->h_dest[0]),
                       ETH_ALEN);
         }
         else {
@@ -999,7 +973,7 @@ static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
                       ETH_ALEN);
        } else {
                memcpy(&(pBuf->Data.abyTA[0]),
-                      &(psEthHeader->abySrcAddr[0]),
+                      &(psEthHeader->h_source[0]),
                       ETH_ALEN);
         }
     }
@@ -1028,18 +1002,18 @@ static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
             PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
             //Get SignalField,ServiceField,Length
             BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
+                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
             );
             pBuf->wTransmitLength_b = cpu_to_le16(wLen);
-            pBuf->wDuration_ba = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
+            pBuf->wDuration_ba = (u16)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
             pBuf->wDuration_ba += pDevice->wCTSDuration;
             pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
             //Get CTSDuration_ba_f0
-            pBuf->wCTSDuration_ba_f0 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
+            pBuf->wCTSDuration_ba_f0 = (u16)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
             pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
             pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
             //Get CTSDuration_ba_f1
-            pBuf->wCTSDuration_ba_f1 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
+            pBuf->wCTSDuration_ba_f1 = (u16)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
             pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
             pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
             //Get CTS Frame body
@@ -1053,11 +1027,11 @@ static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
             PSCTS pBuf = (PSCTS)pvCTS;
             //Get SignalField,ServiceField,Length
             BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
-                (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
+                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
             );
             pBuf->wTransmitLength_b = cpu_to_le16(wLen);
             //Get CTSDuration_ba
-            pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
+            pBuf->wDuration_ba = cpu_to_le16((u16)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
             pBuf->wDuration_ba += pDevice->wCTSDuration;
             pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
 
@@ -1098,7 +1072,7 @@ static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
 static void s_vGenerateTxParameter(struct vnt_private *pDevice,
        u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
        void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
-       PSEthernetHeader psEthHeader)
+       struct ethhdr *psEthHeader)
 {
        u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
        u16 wFifoCtl;
@@ -1130,11 +1104,11 @@ static void s_vGenerateTxParameter(struct vnt_private *pDevice,
             //Fill RsvTime
             if (pvRrvTime) {
                 PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
-                pBuf->wRTSTxRrvTime_aa = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
-                pBuf->wRTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
-                pBuf->wRTSTxRrvTime_bb = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
-                pBuf->wTxRrvTime_a = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
-                pBuf->wTxRrvTime_b = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
+                pBuf->wRTSTxRrvTime_aa = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
+                pBuf->wRTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
+                pBuf->wRTSTxRrvTime_bb = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
+                pBuf->wTxRrvTime_a = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
+                pBuf->wTxRrvTime_b = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
             }
             //Fill RTS
             s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
@@ -1144,9 +1118,9 @@ static void s_vGenerateTxParameter(struct vnt_private *pDevice,
             //Fill RsvTime
             if (pvRrvTime) {
                 PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
-                pBuf->wTxRrvTime_a = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
-                pBuf->wTxRrvTime_b = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
-                pBuf->wCTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
+                pBuf->wTxRrvTime_a = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
+                pBuf->wTxRrvTime_b = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
+                pBuf->wCTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
             }
             //Fill CTS
             s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
@@ -1158,8 +1132,8 @@ static void s_vGenerateTxParameter(struct vnt_private *pDevice,
             //Fill RsvTime
             if (pvRrvTime) {
                 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
-                pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
-                pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
+                pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
+                pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
             }
             //Fill RTS
             s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
@@ -1168,7 +1142,7 @@ static void s_vGenerateTxParameter(struct vnt_private *pDevice,
             //Fill RsvTime
             if (pvRrvTime) {
                 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
-                pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
+                pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
             }
         }
     }
@@ -1178,8 +1152,8 @@ static void s_vGenerateTxParameter(struct vnt_private *pDevice,
             //Fill RsvTime
             if (pvRrvTime) {
                 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
-                pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
-                pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
+                pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
+                pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
             }
             //Fill RTS
             s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
@@ -1188,21 +1162,21 @@ static void s_vGenerateTxParameter(struct vnt_private *pDevice,
             //Fill RsvTime
             if (pvRrvTime) {
                 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
-                pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
+                pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
             }
         }
     }
     //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
 }
 /*
-    PBYTE pbyBuffer,//point to pTxBufHead
-    WORD  wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
+    u8 * pbyBuffer,//point to pTxBufHead
+    u16  wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
     unsigned int  cbFragmentSize,//Hdr+payoad+FCS
 */
 
 static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
        u8 *usbPacketBuf, int bNeedEncryption, u32 uSkbPacketLen, u32 uDMAIdx,
-       PSEthernetHeader psEthHeader, u8 *pPacket, PSKeyItem pTransmitKey,
+       struct ethhdr *psEthHeader, u8 *pPacket, PSKeyItem pTransmitKey,
        u32 uNodeIndex, u16 wCurrentRate, u32 *pcbHeaderLen, u32 *pcbTotalLen)
 {
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
@@ -1240,7 +1214,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
     memset(pTxBufHead, 0, sizeof(TX_BUFFER));
 
     // Get pkt type
-    if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
+    if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
         if (pDevice->dwDiagRefCount == 0) {
             cb802_1_H_len = 8;
         } else {
@@ -1253,7 +1227,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
     cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
 
     //Set packet type
-    pTxBufHead->wFIFOCtl |= (WORD)(byPktType<<8);
+    pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
 
     if (pDevice->dwDiagRefCount != 0) {
         bNeedACK = false;
@@ -1261,7 +1235,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
     } else { //if (pDevice->dwDiagRefCount != 0) {
        if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
            (pDevice->eOPMode == OP_MODE_AP)) {
-               if (is_multicast_ether_addr(psEthHeader->abyDstAddr)) {
+               if (is_multicast_ether_addr(psEthHeader->h_dest)) {
                        bNeedACK = false;
                        pTxBufHead->wFIFOCtl =
                                pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
@@ -1293,7 +1267,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
     } else {
         cbMACHdLen = WLAN_HDR_ADDR3_LEN;
     }
-    pTxBufHead->wFragCtl |= (WORD)(cbMACHdLen << 10);
+    pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
 
     //Set FIFOCTL_GrpAckPolicy
     if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
@@ -1326,7 +1300,6 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
         }
     }
 
-
     if ((bNeedEncryption) && (pTransmitKey != NULL))  {
         if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
             cbIVlen = 4;
@@ -1358,7 +1331,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
         pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
     }
 
-    pbyTxBufferAddr = (PBYTE) &(pTxBufHead->adwTxKey[0]);
+    pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
     wTxBufSize = sizeof(STxBufHead);
     if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
         if (byFBOption == AUTO_FB_NONE) {
@@ -1437,10 +1410,9 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
         } // Auto Fall Back
     }
 
-    pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderLength);
-    pbyIVHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding);
-    pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
-
+    pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
+    pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
+    pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
 
     //=========================
     //    No Fragmentation
@@ -1450,7 +1422,6 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
     //uDMAIdx = TYPE_AC0DMA;
     //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
 
-
     //Fill FIFO,RrvTime,RTS,and CTS
     s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
                           (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
@@ -1459,13 +1430,13 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
     uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
                                     0, 0, 1/*uMACfragNum*/, byFBOption);
     // Generate TX MAC Header
-    s_vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncryption,
+    s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
                            byFragType, uDMAIdx, 0);
 
     if (bNeedEncryption == true) {
         //Fill TXKEY
-        s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
-                         pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
+        s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
+                         pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
 
         if (pDevice->bEnableHostWEP) {
             pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
@@ -1474,25 +1445,24 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
     }
 
     // 802.1H
-    if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
+    if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
        if (pDevice->dwDiagRefCount == 0) {
-               if ((psEthHeader->wType == cpu_to_be16(ETH_P_IPX)) ||
-                   (psEthHeader->wType == cpu_to_le16(0xF380))) {
-                       memcpy((PBYTE) (pbyPayloadHead),
+               if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
+                   (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
+                       memcpy((u8 *) (pbyPayloadHead),
                               abySNAP_Bridgetunnel, 6);
             } else {
-                memcpy((PBYTE) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
+                memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
             }
-            pbyType = (PBYTE) (pbyPayloadHead + 6);
-            memcpy(pbyType, &(psEthHeader->wType), sizeof(WORD));
+            pbyType = (u8 *) (pbyPayloadHead + 6);
+            memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
         } else {
-            memcpy((PBYTE) (pbyPayloadHead), &(psEthHeader->wType), sizeof(WORD));
+            memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
 
         }
 
     }
 
-
     if (pPacket != NULL) {
         // Copy the Packet into a tx Buffer
         memcpy((pbyPayloadHead + cb802_1_H_len),
@@ -1502,7 +1472,7 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
 
     } else {
         // while bRelayPacketSend psEthHeader is point to header+payload
-        memcpy((pbyPayloadHead + cb802_1_H_len), ((PBYTE)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
+        memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
     }
 
     ASSERT(uLength == cbNdisBodySize);
@@ -1516,18 +1486,18 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
                dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
        }
         else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
-            dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
-            dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
+            dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
+            dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
         }
         else {
-            dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[24]);
-            dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[28]);
+            dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
+            dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
         }
         // DO Software Michael
         MIC_vInit(dwMICKey0, dwMICKey1);
-        MIC_vAppend((PBYTE)&(psEthHeader->abyDstAddr[0]), 12);
+        MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
         dwMIC_Priority = 0;
-        MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
+        MIC_vAppend((u8 *)&dwMIC_Priority, 4);
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
                dwMICKey0, dwMICKey1);
 
@@ -1535,14 +1505,14 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
 
         //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
         //for (ii = 0; ii < cbFrameBodySize; ii++) {
-        //    DBG_PRN_GRP12(("%02x ", *((PBYTE)((pbyPayloadHead + cb802_1_H_len) + ii))));
+        //    DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
         //}
         //DBG_PRN_GRP12(("\n\n\n"));
 
         MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
 
-        pdwMIC_L = (PDWORD)(pbyPayloadHead + cbFrameBodySize);
-        pdwMIC_R = (PDWORD)(pbyPayloadHead + cbFrameBodySize + 4);
+        pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
+        pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
 
         MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
         MIC_vUnInit();
@@ -1557,10 +1527,9 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
         //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
     }
 
-
     if (bSoftWEP == true) {
 
-        s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (WORD)(cbFrameBodySize + cbMIClen));
+        s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
 
     } else if (  ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true))  ||
           ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true))   ||
@@ -1570,13 +1539,13 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
 
     if (pDevice->bSoftwareGenCrcErr == true) {
        unsigned int cbLen;
-        PDWORD pdwCRC;
+        u32 * pdwCRC;
 
         dwCRC = 0xFFFFFFFFL;
         cbLen = cbFrameSize - cbFCSlen;
         // calculate CRC, and wrtie CRC value to end of TD
         dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
-        pdwCRC = (PDWORD)(pbyMacHdr + cbLen);
+        pdwCRC = (u32 *)(pbyMacHdr + cbLen);
         // finally, we must invert dwCRC to get the correct answer
         *pdwCRC = ~dwCRC;
         // Force Error
@@ -1588,16 +1557,13 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
     *pcbHeaderLen = cbHeaderLength;
     *pcbTotalLen = cbHeaderLength + cbFrameSize ;
 
-
     //Set FragCtl in TxBufferHead
-    pTxBufHead->wFragCtl |= (WORD)byFragType;
-
+    pTxBufHead->wFragCtl |= (u16)byFragType;
 
     return true;
 
 }
 
-
 /*+
  *
  * Description:
@@ -1618,67 +1584,67 @@ static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
 -*/
 
 static void s_vGenerateMACHeader(struct vnt_private *pDevice,
-       u8 *pbyBufferAddr, u16 wDuration, PSEthernetHeader psEthHeader,
+       u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
        int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
 {
-       PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
+       struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
 
-    memset(pMACHeader, 0, (sizeof(S802_11Header)));  //- sizeof(pMACHeader->dwIV)));
+    memset(pMACHeader, 0, (sizeof(struct ieee80211_hdr)));
 
     if (uDMAIdx == TYPE_ATIMDMA) {
-       pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
+       pMACHeader->frame_control = TYPE_802_11_ATIM;
     } else {
-        pMACHeader->wFrameCtl = TYPE_802_11_DATA;
+        pMACHeader->frame_control = TYPE_802_11_DATA;
     }
 
     if (pDevice->eOPMode == OP_MODE_AP) {
-       memcpy(&(pMACHeader->abyAddr1[0]),
-              &(psEthHeader->abyDstAddr[0]),
+       memcpy(&(pMACHeader->addr1[0]),
+              &(psEthHeader->h_dest[0]),
               ETH_ALEN);
-       memcpy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
-       memcpy(&(pMACHeader->abyAddr3[0]),
-              &(psEthHeader->abySrcAddr[0]),
+       memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
+       memcpy(&(pMACHeader->addr3[0]),
+              &(psEthHeader->h_source[0]),
               ETH_ALEN);
-        pMACHeader->wFrameCtl |= FC_FROMDS;
+        pMACHeader->frame_control |= FC_FROMDS;
     } else {
        if (pDevice->eOPMode == OP_MODE_ADHOC) {
-               memcpy(&(pMACHeader->abyAddr1[0]),
-                      &(psEthHeader->abyDstAddr[0]),
+               memcpy(&(pMACHeader->addr1[0]),
+                      &(psEthHeader->h_dest[0]),
                       ETH_ALEN);
-               memcpy(&(pMACHeader->abyAddr2[0]),
-                      &(psEthHeader->abySrcAddr[0]),
+               memcpy(&(pMACHeader->addr2[0]),
+                      &(psEthHeader->h_source[0]),
                       ETH_ALEN);
-               memcpy(&(pMACHeader->abyAddr3[0]),
+               memcpy(&(pMACHeader->addr3[0]),
                       &(pDevice->abyBSSID[0]),
                       ETH_ALEN);
        } else {
-               memcpy(&(pMACHeader->abyAddr3[0]),
-                      &(psEthHeader->abyDstAddr[0]),
+               memcpy(&(pMACHeader->addr3[0]),
+                      &(psEthHeader->h_dest[0]),
                       ETH_ALEN);
-               memcpy(&(pMACHeader->abyAddr2[0]),
-                      &(psEthHeader->abySrcAddr[0]),
+               memcpy(&(pMACHeader->addr2[0]),
+                      &(psEthHeader->h_source[0]),
                       ETH_ALEN);
-               memcpy(&(pMACHeader->abyAddr1[0]),
+               memcpy(&(pMACHeader->addr1[0]),
                       &(pDevice->abyBSSID[0]),
                       ETH_ALEN);
-            pMACHeader->wFrameCtl |= FC_TODS;
+            pMACHeader->frame_control |= FC_TODS;
         }
     }
 
     if (bNeedEncrypt)
-        pMACHeader->wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_ISWEP(1));
+        pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
 
-    pMACHeader->wDurationID = cpu_to_le16(wDuration);
+    pMACHeader->duration_id = cpu_to_le16(wDuration);
 
     if (pDevice->bLongHeader) {
         PWLAN_80211HDR_A4 pMACA4Header  = (PWLAN_80211HDR_A4) pbyBufferAddr;
-        pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
+        pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
         memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
     }
-    pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
+    pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
 
     //Set FragNumber in Sequence Control
-    pMACHeader->wSeqCtl |= cpu_to_le16((WORD)uFragIdx);
+    pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
 
     if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
         pDevice->wSeqCounter++;
@@ -1687,12 +1653,10 @@ static void s_vGenerateMACHeader(struct vnt_private *pDevice,
     }
 
     if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
-        pMACHeader->wFrameCtl |= FC_MOREFRAG;
+        pMACHeader->frame_control |= FC_MOREFRAG;
     }
 }
 
-
-
 /*+
  *
  * Description:
@@ -1717,9 +1681,9 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
        PTX_BUFFER pTX_Buffer;
        PSTxBufHead pTxBufHead;
        PUSB_SEND_CONTEXT pContext;
-       PS802_11Header pMACHeader;
+       struct ieee80211_hdr *pMACHeader;
        PSCTS pCTS;
-       SEthernetHeader sEthHeader;
+       struct ethhdr sEthHeader;
        u8 byPktType, *pbyTxBufferAddr;
        void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
        u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
@@ -1730,8 +1694,6 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
        u32 cbMacHdLen;
        u16 wCurrentRate = RATE_1M;
 
-
-
     pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
 
     if (NULL == pContext) {
@@ -1740,7 +1702,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
     }
 
     pTX_Buffer = (PTX_BUFFER) (&pContext->Data[0]);
-    pbyTxBufferAddr = (PBYTE)&(pTX_Buffer->adwTxKey[0]);
+    pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
     cbFrameBodySize = pPacket->cbPayloadLen;
     pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
     wTxBufSize = sizeof(STxBufHead);
@@ -1765,7 +1727,6 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
     }
     pDevice->wCurrentRate = wCurrentRate;
 
-
     //Set packet type
     if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
         pTxBufHead->wFIFOCtl = 0;
@@ -1814,7 +1775,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
     }
 
     //Set FRAGCTL_MACHDCNT
-    pTxBufHead->wFragCtl |= cpu_to_le16((WORD)(cbMacHdLen << 10));
+    pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
 
     // Notes:
     // Although spec says MMPDU can be fragmented; In most case,
@@ -1877,17 +1838,16 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
     memset((void *)(pbyTxBufferAddr + wTxBufSize), 0,
           (cbHeaderSize - wTxBufSize));
 
-    memcpy(&(sEthHeader.abyDstAddr[0]),
+    memcpy(&(sEthHeader.h_dest[0]),
           &(pPacket->p80211Header->sA3.abyAddr1[0]),
           ETH_ALEN);
-    memcpy(&(sEthHeader.abySrcAddr[0]),
+    memcpy(&(sEthHeader.h_source[0]),
           &(pPacket->p80211Header->sA3.abyAddr2[0]),
           ETH_ALEN);
     //=========================
     //    No Fragmentation
     //=========================
-    pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
-
+    pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
 
     //Fill FIFO,RrvTime,RTS,and CTS
     s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,  pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
@@ -1897,18 +1857,18 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
     uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
                                 0, 0, 1, AUTO_FB_NONE);
 
-    pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
+    pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
 
     cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
 
     if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
-        PBYTE           pbyIVHead;
-        PBYTE           pbyPayloadHead;
-        PBYTE           pbyBSSID;
+        u8 *           pbyIVHead;
+        u8 *           pbyPayloadHead;
+        u8 *           pbyBSSID;
         PSKeyItem       pTransmitKey = NULL;
 
-        pbyIVHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
-        pbyPayloadHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
+        pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
+        pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
         do {
             if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
                 (pDevice->bLinkPass == true)) {
@@ -1935,11 +1895,11 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
             }
         } while(false);
         //Fill TXKEY
-        s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
-                     (PBYTE)pMACHeader, (WORD)cbFrameBodySize, NULL);
+        s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
+                     (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
 
         memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
-        memcpy(pbyPayloadHead, ((PBYTE)(pPacket->p80211Header) + cbMacHdLen),
+        memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
                  cbFrameBodySize);
     }
     else {
@@ -1947,7 +1907,7 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
         memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
     }
 
-    pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
+    pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
     pDevice->wSeqCounter++ ;
     if (pDevice->wSeqCounter > 0x0fff)
         pDevice->wSeqCounter = 0;
@@ -1966,27 +1926,25 @@ CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
         }
     }
 
-
-    pTX_Buffer->wTxByteCount = cpu_to_le16((WORD)(cbReqCount));
-    pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
+    pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
+    pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
     pTX_Buffer->byType = 0x00;
 
     pContext->pPacket = NULL;
     pContext->Type = CONTEXT_MGMT_PACKET;
-    pContext->uBufLen = (WORD)cbReqCount + 4;  //USB header
+    pContext->uBufLen = (u16)cbReqCount + 4;  //USB header
 
-    if (WLAN_GET_FC_TODS(pMACHeader->wFrameCtl) == 0) {
-        s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr1[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
+    if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
+        s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
     }
     else {
-        s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr3[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
+        s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
     }
 
     PIPEnsSendBulkOut(pDevice,pContext);
     return CMD_STATUS_PENDING;
 }
 
-
 CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
        struct vnt_tx_mgmt *pPacket)
 {
@@ -1994,7 +1952,7 @@ CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
        u32 cbHeaderSize = 0;
        u16 wTxBufSize = sizeof(STxShortBufHead);
        PSTxShortBufHead pTxBufHead;
-       PS802_11Header pMACHeader;
+       struct ieee80211_hdr *pMACHeader;
        PSTxDataHead_ab pTxDataHead;
        u16 wCurrentRate;
        u32 cbFrameBodySize;
@@ -2004,7 +1962,6 @@ CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
        PUSB_SEND_CONTEXT pContext;
        CMD_STATUS status;
 
-
     pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
     if (NULL == pContext) {
         status = CMD_STATUS_RESOURCES;
@@ -2012,7 +1969,7 @@ CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
         return status ;
     }
     pTX_Buffer = (PBEACON_BUFFER) (&pContext->Data[0]);
-    pbyTxBufferAddr = (PBYTE)&(pTX_Buffer->wFIFOCtl);
+    pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
 
     cbFrameBodySize = pPacket->cbPayloadLen;
 
@@ -2025,10 +1982,10 @@ CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
         pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
         //Get SignalField,ServiceField,Length
         BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
-            (PWORD)&(pTxDataHead->wTransmitLength), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
+            (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
         );
         //Get Duration and TimeStampOff
-        pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, PK_TYPE_11A,
+        pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, PK_TYPE_11A,
                                                           wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
         pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
         cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
@@ -2038,41 +1995,40 @@ CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
         pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
         //Get SignalField,ServiceField,Length
         BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
-            (PWORD)&(pTxDataHead->wTransmitLength), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
+            (u16 *)&(pTxDataHead->wTransmitLength), (u8 *)&(pTxDataHead->byServiceField), (u8 *)&(pTxDataHead->bySignalField)
         );
         //Get Duration and TimeStampOff
-        pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, PK_TYPE_11B,
+        pTxDataHead->wDuration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, PK_TYPE_11B,
                                                           wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
         pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
         cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
     }
 
     //Generate Beacon Header
-    pMACHeader = (PS802_11Header)(pbyTxBufferAddr + cbHeaderSize);
+    pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
     memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
 
-    pMACHeader->wDurationID = 0;
-    pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
+    pMACHeader->duration_id = 0;
+    pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
     pDevice->wSeqCounter++ ;
     if (pDevice->wSeqCounter > 0x0fff)
         pDevice->wSeqCounter = 0;
 
     cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
 
-    pTX_Buffer->wTxByteCount = (WORD)cbReqCount;
-    pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
+    pTX_Buffer->wTxByteCount = (u16)cbReqCount;
+    pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
     pTX_Buffer->byType = 0x01;
 
     pContext->pPacket = NULL;
     pContext->Type = CONTEXT_MGMT_PACKET;
-    pContext->uBufLen = (WORD)cbReqCount + 4;  //USB header
+    pContext->uBufLen = (u16)cbReqCount + 4;  //USB header
 
     PIPEnsSendBulkOut(pDevice,pContext);
     return CMD_STATUS_PENDING;
 
 }
 
-
 void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
 {
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
@@ -2080,7 +2036,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
        u8 *pbyTxBufferAddr;
        void *pvRTS, *pvCTS, *pvTxDataHd;
        u32 uDuration, cbReqCount;
-       PS802_11Header  pMACHeader;
+       struct ieee80211_hdr *pMACHeader;
        u32 cbHeaderSize, cbFrameBodySize;
        int bNeedACK, bIsPSPOLL = false;
        PSTxBufHead pTxBufHead;
@@ -2093,7 +2049,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
        u32 *pdwMIC_L, *pdwMIC_R;
        u16 wTxBufSize;
        u32 cbMacHdLen;
-       SEthernetHeader sEthHeader;
+       struct ethhdr sEthHeader;
        void *pvRrvTime, *pMICHDR;
        u32 wCurrentRate = RATE_1M;
        PUWLAN_80211HDR  p80211Header;
@@ -2106,7 +2062,6 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
        PTX_BUFFER pTX_Buffer;
        PUSB_SEND_CONTEXT pContext;
 
-
     pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
 
     if(skb->len <= WLAN_HDR_ADDR3_LEN) {
@@ -2126,7 +2081,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
     }
 
     pTX_Buffer = (PTX_BUFFER)(&pContext->Data[0]);
-    pbyTxBufferAddr = (PBYTE)(&pTX_Buffer->adwTxKey[0]);
+    pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
     pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
     wTxBufSize = sizeof(STxBufHead);
     memset(pTxBufHead, 0, wTxBufSize);
@@ -2177,7 +2132,7 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
     }
     else {
         if (pDevice->bEnableHostWEP) {
-            if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p80211Header->sA3.abyAddr1), &uNodeIndex))
+            if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
                 bNodeExist = true;
         }
         bNeedACK = true;
@@ -2223,16 +2178,14 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
          }
     }
 
-
     //Set FRAGCTL_MACHDCNT
-    pTxBufHead->wFragCtl |= cpu_to_le16((WORD)cbMacHdLen << 10);
+    pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
 
     // Notes:
     // Although spec says MMPDU can be fragmented; In most case,
     // no one will send a MMPDU under fragmentation. With RTS may occur.
     pDevice->bAES = false;  //Set FRAGCTL_WEPTYP
 
-
     if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
         if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
             cbIVlen = 4;
@@ -2268,7 +2221,6 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
     }
     //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
 
-
     if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
 
         pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
@@ -2290,17 +2242,16 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
     }
     memset((void *)(pbyTxBufferAddr + wTxBufSize), 0,
           (cbHeaderSize - wTxBufSize));
-    memcpy(&(sEthHeader.abyDstAddr[0]),
+    memcpy(&(sEthHeader.h_dest[0]),
           &(p80211Header->sA3.abyAddr1[0]),
           ETH_ALEN);
-    memcpy(&(sEthHeader.abySrcAddr[0]),
+    memcpy(&(sEthHeader.h_source[0]),
           &(p80211Header->sA3.abyAddr2[0]),
           ETH_ALEN);
     //=========================
     //    No Fragmentation
     //=========================
-    pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
-
+    pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
 
     //Fill FIFO,RrvTime,RTS,and CTS
     s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
@@ -2310,19 +2261,19 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
     uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
                                 0, 0, 1, AUTO_FB_NONE);
 
-    pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
+    pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
 
     cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
 
-    pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderSize);
-    pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
-    pbyIVHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding);
+    pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
+    pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
+    pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
 
     // Copy the Packet into a tx Buffer
     memcpy(pbyMacHdr, skb->data, cbMacHdLen);
 
     // version set to 0, patch for hostapd deamon
-    pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
+    pMACHeader->frame_control &= cpu_to_le16(0xfffc);
     memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
 
     // replace support rate, patch for hostapd daemon( only support 11M)
@@ -2359,14 +2310,14 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
 
         if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
 
-            dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
-            dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
+            dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
+            dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
 
             // DO Software Michael
             MIC_vInit(dwMICKey0, dwMICKey1);
-            MIC_vAppend((PBYTE)&(sEthHeader.abyDstAddr[0]), 12);
+            MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
             dwMIC_Priority = 0;
-            MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
+            MIC_vAppend((u8 *)&dwMIC_Priority, 4);
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
                        " %X, %X\n", dwMICKey0, dwMICKey1);
 
@@ -2374,8 +2325,8 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
 
             MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
 
-            pdwMIC_L = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize);
-            pdwMIC_R = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
+            pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
+            pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
 
             MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
             MIC_vUnInit();
@@ -2393,8 +2344,8 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
 
         }
 
-        s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
-                     pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
+        s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
+                     pbyMacHdr, (u16)cbFrameBodySize, (u8 *)pMICHDR);
 
         if (pDevice->bEnableHostWEP) {
             pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
@@ -2402,16 +2353,15 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
         }
 
         if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
-            s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (WORD)(cbFrameBodySize + cbMIClen));
+            s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
         }
     }
 
-    pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
+    pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
     pDevice->wSeqCounter++ ;
     if (pDevice->wSeqCounter > 0x0fff)
         pDevice->wSeqCounter = 0;
 
-
     if (bIsPSPOLL) {
         // The MAC will automatically replace the Duration-field of MAC header by Duration-field
         // of  FIFO control header.
@@ -2426,28 +2376,25 @@ void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
         }
     }
 
-    pTX_Buffer->wTxByteCount = cpu_to_le16((WORD)(cbReqCount));
-    pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
+    pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
+    pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
     pTX_Buffer->byType = 0x00;
 
     pContext->pPacket = skb;
     pContext->Type = CONTEXT_MGMT_PACKET;
-    pContext->uBufLen = (WORD)cbReqCount + 4;  //USB header
+    pContext->uBufLen = (u16)cbReqCount + 4;  //USB header
 
-    if (WLAN_GET_FC_TODS(pMACHeader->wFrameCtl) == 0) {
-        s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr1[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
+    if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
+        s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
     }
     else {
-        s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr3[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
+        s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
     }
     PIPEnsSendBulkOut(pDevice,pContext);
     return ;
 
 }
 
-
-
-
 //TYPE_AC0DMA data tx
 /*
  * Description:
@@ -2488,7 +2435,6 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
        u16 wKeepRate = pDevice->wCurrentRate;
        int bTxeapol_key = false;
 
-
     if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
 
         if (pDevice->uAssocCount == 0) {
@@ -2496,7 +2442,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
             return 0;
         }
 
-       if (is_multicast_ether_addr((PBYTE)(skb->data))) {
+       if (is_multicast_ether_addr((u8 *)(skb->data))) {
             uNodeIndex = 0;
             bNodeExist = true;
             if (pMgmt->sNodeDBTable[0].bPSEnable) {
@@ -2518,7 +2464,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
 
         }else {
 
-            if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(skb->data), &uNodeIndex)) {
+            if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
 
                 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
 
@@ -2562,20 +2508,20 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
         return STATUS_RESOURCES;
     }
 
-    memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), ETH_HLEN);
+    memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
 
 //mike add:station mode check eapol-key challenge--->
 {
-    BYTE  Protocol_Version;    //802.1x Authentication
-    BYTE  Packet_Type;           //802.1x Authentication
-    BYTE  Descriptor_type;
-    WORD Key_info;
+    u8  Protocol_Version;    //802.1x Authentication
+    u8  Packet_Type;           //802.1x Authentication
+    u8  Descriptor_type;
+    u16 Key_info;
 
     Protocol_Version = skb->data[ETH_HLEN];
     Packet_Type = skb->data[ETH_HLEN+1];
     Descriptor_type = skb->data[ETH_HLEN+1+1+2];
     Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
-       if (pDevice->sTxEthHeader.wType == cpu_to_be16(ETH_P_PAE)) {
+       if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
                /* 802.1x OR eapol-key challenge frame transfer */
                if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
                        (Packet_Type == 3)) {
@@ -2622,8 +2568,8 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
                     break;
                 }
             }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
-
-                pbyBSSID = pDevice->sTxEthHeader.abyDstAddr;  //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
+             /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
+                pbyBSSID = pDevice->sTxEthHeader.h_dest;
                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
                 for (ii = 0; ii< 6; ii++)
                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
@@ -2665,14 +2611,14 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
          }
     }
 
-    byPktType = (BYTE)pDevice->byPacketType;
+    byPktType = (u8)pDevice->byPacketType;
 
     if (pDevice->bFixRate) {
         if (pDevice->byBBType == BB_TYPE_11B) {
             if (pDevice->uConnectionRate >= RATE_11M) {
                 pDevice->wCurrentRate = RATE_11M;
             } else {
-                pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
+                pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
             }
         } else {
             if ((pDevice->byBBType == BB_TYPE_11A) &&
@@ -2682,21 +2628,21 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
                 if (pDevice->uConnectionRate >= RATE_54M)
                     pDevice->wCurrentRate = RATE_54M;
                 else
-                    pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
+                    pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
             }
         }
     }
     else {
         if (pDevice->eOPMode == OP_MODE_ADHOC) {
             // Adhoc Tx rate decided from node DB
-           if (is_multicast_ether_addr(pDevice->sTxEthHeader.abyDstAddr)) {
+           if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
                 // Multicast use highest data rate
                 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
                 // preamble type
                 pDevice->byPreambleType = pDevice->byShortPreamble;
             }
             else {
-                if(BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.abyDstAddr[0]), &uNodeIndex)) {
+                if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
                     pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
                     if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
                         pDevice->byPreambleType = pDevice->byShortPreamble;
@@ -2724,7 +2670,7 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
         }
     }
 
-       if (pDevice->sTxEthHeader.wType == cpu_to_be16(ETH_P_PAE)) {
+       if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
                if (pDevice->byBBType != BB_TYPE_11A) {
                        pDevice->wCurrentRate = RATE_1M;
                        pDevice->byACKRate = RATE_1M;
@@ -2751,10 +2697,10 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
     }
 
     if (bNeedEncryption == true) {
-        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
-       if ((pDevice->sTxEthHeader.wType) == cpu_to_be16(ETH_P_PAE)) {
+        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
+       if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
                bNeedEncryption = false;
-            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
+            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
             if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
                 if (pTransmitKey == NULL) {
                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
@@ -2793,9 +2739,9 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
     }
 
     fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
-                        (PBYTE)(&pContext->Data[0]), bNeedEncryption,
+                        (u8 *)(&pContext->Data[0]), bNeedEncryption,
                         skb->len, uDMAIdx, &pDevice->sTxEthHeader,
-                        (PBYTE)skb->data, pTransmitKey, uNodeIndex,
+                        (u8 *)skb->data, pTransmitKey, uNodeIndex,
                         pDevice->wCurrentRate,
                         &uHeaderLen, &BytesToWrite
                        );
@@ -2816,21 +2762,21 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
     }
 
     pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
-    pTX_Buffer->byPKTNO = (BYTE) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
-    pTX_Buffer->wTxByteCount = (WORD)BytesToWrite;
+    pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
+    pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
 
     pContext->pPacket = skb;
     pContext->Type = CONTEXT_DATA_PACKET;
-    pContext->uBufLen = (WORD)BytesToWrite + 4 ; //USB header
+    pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
 
-    s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.abyDstAddr[0]),(WORD) (BytesToWrite-uHeaderLen),pTX_Buffer->wFIFOCtl);
+    s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.h_dest[0]), (u16) (BytesToWrite-uHeaderLen), pTX_Buffer->wFIFOCtl);
 
     status = PIPEnsSendBulkOut(pDevice,pContext);
 
     if (bNeedDeAuth == true) {
-        WORD wReason = WLAN_MGMT_REASON_MIC_FAILURE;
+        u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
 
-       bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (PBYTE) &wReason);
+       bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
     }
 
   if(status!=STATUS_PENDING) {
@@ -2843,8 +2789,6 @@ int nsDMA_tx_packet(struct vnt_private *pDevice,
 
 }
 
-
-
 /*
  * Description:
  *      Relay packet send (AC1DMA) from rx dpc.
@@ -2877,15 +2821,13 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
        u32 status;
        u16 wKeepRate = pDevice->wCurrentRate;
 
-
-
     pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
 
     if (NULL == pContext) {
         return false;
     }
 
-    memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)pbySkbData, ETH_HLEN);
+    memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
 
     if (pDevice->bEncryptionEnable == true) {
         bNeedEncryption = true;
@@ -2919,14 +2861,14 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
         return false;
     }
 
-    byPktTyp = (BYTE)pDevice->byPacketType;
+    byPktTyp = (u8)pDevice->byPacketType;
 
     if (pDevice->bFixRate) {
         if (pDevice->byBBType == BB_TYPE_11B) {
             if (pDevice->uConnectionRate >= RATE_11M) {
                 pDevice->wCurrentRate = RATE_11M;
             } else {
-                pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
+                pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
             }
         } else {
             if ((pDevice->byBBType == BB_TYPE_11A) &&
@@ -2936,7 +2878,7 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
                 if (pDevice->uConnectionRate >= RATE_54M)
                     pDevice->wCurrentRate = RATE_54M;
                 else
-                    pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
+                    pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
             }
         }
     }
@@ -2957,7 +2899,7 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
     // and send the irp.
 
     fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
-                         (PBYTE)(&pContext->Data[0]), bNeedEncryption,
+                         (u8 *)(&pContext->Data[0]), bNeedEncryption,
                          uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
                          pbySkbData, pTransmitKey, uNodeIndex,
                          pDevice->wCurrentRate,
@@ -2970,14 +2912,14 @@ int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
     }
 
     pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
-    pTX_Buffer->byPKTNO = (BYTE) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
-    pTX_Buffer->wTxByteCount = (WORD)BytesToWrite;
+    pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
+    pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
 
     pContext->pPacket = NULL;
     pContext->Type = CONTEXT_DATA_PACKET;
-    pContext->uBufLen = (WORD)BytesToWrite + 4 ; //USB header
+    pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
 
-    s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.abyDstAddr[0]),(WORD) (BytesToWrite-uHeaderLen),pTX_Buffer->wFIFOCtl);
+    s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.h_dest[0]), (u16) (BytesToWrite-uHeaderLen), pTX_Buffer->wFIFOCtl);
 
     status = PIPEnsSendBulkOut(pDevice,pContext);
 
index 9f537022cdd1f87df34ad2c1e66f85a49836b6b8..dd7e85dde1a28f0584f1e1c6b3656b653ebdfeb0 100644 (file)
 #ifndef __RXTX_H__
 #define __RXTX_H__
 
-#include "ttype.h"
 #include "device.h"
 #include "wcmd.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
 //
 // RTS buffer header
 //
 typedef struct tagSRTSDataF {
-    WORD    wFrameControl;
-    WORD    wDurationID;
-    BYTE    abyRA[ETH_ALEN];
-    BYTE    abyTA[ETH_ALEN];
+    u16    wFrameControl;
+    u16    wDurationID;
+    u8    abyRA[ETH_ALEN];
+    u8    abyTA[ETH_ALEN];
 } SRTSDataF, *PSRTSDataF;
 
 //
 // CTS buffer header
 //
 typedef struct tagSCTSDataF {
-    WORD    wFrameControl;
-    WORD    wDurationID;
-    BYTE    abyRA[ETH_ALEN];
-    WORD    wReserved;
+    u16    wFrameControl;
+    u16    wDurationID;
+    u8    abyRA[ETH_ALEN];
+    u16    wReserved;
 } SCTSDataF, *PSCTSDataF;
 
 //
@@ -66,534 +61,510 @@ typedef struct tagSMICHDR {
        u32 adwHDR2[4];
 } SMICHDR, *PSMICHDR;
 
-
 typedef struct tagSTX_NAF_G_RTS
 {
     //RsvTime
-    WORD            wRTSTxRrvTime_ba;
-    WORD            wRTSTxRrvTime_aa;
-    WORD            wRTSTxRrvTime_bb;
-    WORD            wReserved2;
-    WORD            wTxRrvTime_b;
-    WORD            wTxRrvTime_a;
+    u16            wRTSTxRrvTime_ba;
+    u16            wRTSTxRrvTime_aa;
+    u16            wRTSTxRrvTime_bb;
+    u16            wReserved2;
+    u16            wTxRrvTime_b;
+    u16            wTxRrvTime_a;
 
     //RTS
-    BYTE            byRTSSignalField_b;
-    BYTE            byRTSServiceField_b;
-    WORD            wRTSTransmitLength_b;
-    BYTE            byRTSSignalField_a;
-    BYTE            byRTSServiceField_a;
-    WORD            wRTSTransmitLength_a;
-    WORD            wRTSDuration_ba;
-    WORD            wRTSDuration_aa;
-    WORD            wRTSDuration_bb;
-    WORD            wReserved3;
+    u8            byRTSSignalField_b;
+    u8            byRTSServiceField_b;
+    u16            wRTSTransmitLength_b;
+    u8            byRTSSignalField_a;
+    u8            byRTSServiceField_a;
+    u16            wRTSTransmitLength_a;
+    u16            wRTSDuration_ba;
+    u16            wRTSDuration_aa;
+    u16            wRTSDuration_bb;
+    u16            wReserved3;
     SRTSDataF       sRTS;
 
     //Data
-    BYTE            bySignalField_b;
-    BYTE            byServiceField_b;
-    WORD            wTransmitLength_b;
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_b;
-    WORD            wDuration_a;
-    WORD            wTimeStampOff_b;
-    WORD            wTimeStampOff_a;
+    u8            bySignalField_b;
+    u8            byServiceField_b;
+    u16            wTransmitLength_b;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_b;
+    u16            wDuration_a;
+    u16            wTimeStampOff_b;
+    u16            wTimeStampOff_a;
 
 } TX_NAF_G_RTS, *PTX_NAF_G_RTS;
 
 typedef struct tagSTX_NAF_G_RTS_MIC
 {
     //RsvTime
-    WORD            wRTSTxRrvTime_ba;
-    WORD            wRTSTxRrvTime_aa;
-    WORD            wRTSTxRrvTime_bb;
-    WORD            wReserved2;
-    WORD            wTxRrvTime_b;
-    WORD            wTxRrvTime_a;
+    u16            wRTSTxRrvTime_ba;
+    u16            wRTSTxRrvTime_aa;
+    u16            wRTSTxRrvTime_bb;
+    u16            wReserved2;
+    u16            wTxRrvTime_b;
+    u16            wTxRrvTime_a;
 
     SMICHDR         sMICHDR;
 
     //RTS
-    BYTE            byRTSSignalField_b;
-    BYTE            byRTSServiceField_b;
-    WORD            wRTSTransmitLength_b;
-    BYTE            byRTSSignalField_a;
-    BYTE            byRTSServiceField_a;
-    WORD            wRTSTransmitLength_a;
-    WORD            wRTSDuration_ba;
-    WORD            wRTSDuration_aa;
-    WORD            wRTSDuration_bb;
-    WORD            wReserved3;
+    u8            byRTSSignalField_b;
+    u8            byRTSServiceField_b;
+    u16            wRTSTransmitLength_b;
+    u8            byRTSSignalField_a;
+    u8            byRTSServiceField_a;
+    u16            wRTSTransmitLength_a;
+    u16            wRTSDuration_ba;
+    u16            wRTSDuration_aa;
+    u16            wRTSDuration_bb;
+    u16            wReserved3;
     SRTSDataF       sRTS;
 
     //Data
-    BYTE            bySignalField_b;
-    BYTE            byServiceField_b;
-    WORD            wTransmitLength_b;
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_b;
-    WORD            wDuration_a;
-    WORD            wTimeStampOff_b;
-    WORD            wTimeStampOff_a;
+    u8            bySignalField_b;
+    u8            byServiceField_b;
+    u16            wTransmitLength_b;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_b;
+    u16            wDuration_a;
+    u16            wTimeStampOff_b;
+    u16            wTimeStampOff_a;
 
 } TX_NAF_G_RTS_MIC, *PTX_NAF_G_RTS_MIC;
 
 typedef struct tagSTX_NAF_G_CTS
 {
     //RsvTime
-    WORD            wCTSTxRrvTime_ba;
-    WORD            wReserved2;
-    WORD            wTxRrvTime_b;
-    WORD            wTxRrvTime_a;
+    u16            wCTSTxRrvTime_ba;
+    u16            wReserved2;
+    u16            wTxRrvTime_b;
+    u16            wTxRrvTime_a;
 
     //CTS
-    BYTE            byCTSSignalField_b;
-    BYTE            byCTSServiceField_b;
-    WORD            wCTSTransmitLength_b;
-    WORD            wCTSDuration_ba;
-    WORD            wReserved3;
+    u8            byCTSSignalField_b;
+    u8            byCTSServiceField_b;
+    u16            wCTSTransmitLength_b;
+    u16            wCTSDuration_ba;
+    u16            wReserved3;
     SCTSDataF       sCTS;
 
     //Data
-    BYTE            bySignalField_b;
-    BYTE            byServiceField_b;
-    WORD            wTransmitLength_b;
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_b;
-    WORD            wDuration_a;
-    WORD            wTimeStampOff_b;
-    WORD            wTimeStampOff_a;
+    u8            bySignalField_b;
+    u8            byServiceField_b;
+    u16            wTransmitLength_b;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_b;
+    u16            wDuration_a;
+    u16            wTimeStampOff_b;
+    u16            wTimeStampOff_a;
 
 } TX_NAF_G_CTS, *PTX_NAF_G_CTS;
 
-
 typedef struct tagSTX_NAF_G_CTS_MIC
 {
     //RsvTime
-    WORD            wCTSTxRrvTime_ba;
-    WORD            wReserved2;
-    WORD            wTxRrvTime_b;
-    WORD            wTxRrvTime_a;
-
+    u16            wCTSTxRrvTime_ba;
+    u16            wReserved2;
+    u16            wTxRrvTime_b;
+    u16            wTxRrvTime_a;
 
     SMICHDR         sMICHDR;
 
     //CTS
-    BYTE            byCTSSignalField_b;
-    BYTE            byCTSServiceField_b;
-    WORD            wCTSTransmitLength_b;
-    WORD            wCTSDuration_ba;
-    WORD            wReserved3;
+    u8            byCTSSignalField_b;
+    u8            byCTSServiceField_b;
+    u16            wCTSTransmitLength_b;
+    u16            wCTSDuration_ba;
+    u16            wReserved3;
     SCTSDataF       sCTS;
 
     //Data
-    BYTE            bySignalField_b;
-    BYTE            byServiceField_b;
-    WORD            wTransmitLength_b;
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_b;
-    WORD            wDuration_a;
-    WORD            wTimeStampOff_b;
-    WORD            wTimeStampOff_a;
+    u8            bySignalField_b;
+    u8            byServiceField_b;
+    u16            wTransmitLength_b;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_b;
+    u16            wDuration_a;
+    u16            wTimeStampOff_b;
+    u16            wTimeStampOff_a;
 
 } TX_NAF_G_CTS_MIC, *PTX_NAF_G_CTS_MIC;
 
-
 typedef struct tagSTX_NAF_G_BEACON
 {
-    WORD            wFIFOCtl;
-    WORD            wTimeStamp;
+    u16            wFIFOCtl;
+    u16            wTimeStamp;
 
     //CTS
-    BYTE            byCTSSignalField_b;
-    BYTE            byCTSServiceField_b;
-    WORD            wCTSTransmitLength_b;
-    WORD            wCTSDuration_ba;
-    WORD            wReserved1;
+    u8            byCTSSignalField_b;
+    u8            byCTSServiceField_b;
+    u16            wCTSTransmitLength_b;
+    u16            wCTSDuration_ba;
+    u16            wReserved1;
     SCTSDataF       sCTS;
 
     //Data
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_a;
-    WORD            wTimeStampOff_a;
-
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_a;
+    u16            wTimeStampOff_a;
 
 } TX_NAF_G_BEACON, *PTX_NAF_G_BEACON;
 
-
 typedef struct tagSTX_NAF_AB_RTS
 {
     //RsvTime
-    WORD            wRTSTxRrvTime_ab;
-    WORD            wTxRrvTime_ab;
+    u16            wRTSTxRrvTime_ab;
+    u16            wTxRrvTime_ab;
 
     //RTS
-    BYTE            byRTSSignalField_ab;
-    BYTE            byRTSServiceField_ab;
-    WORD            wRTSTransmitLength_ab;
-    WORD            wRTSDuration_ab;
-    WORD            wReserved2;
+    u8            byRTSSignalField_ab;
+    u8            byRTSServiceField_ab;
+    u16            wRTSTransmitLength_ab;
+    u16            wRTSDuration_ab;
+    u16            wReserved2;
     SRTSDataF       sRTS;
 
     //Data
-    BYTE            bySignalField_ab;
-    BYTE            byServiceField_ab;
-    WORD            wTransmitLength_ab;
-    WORD            wDuration_ab;
-    WORD            wTimeStampOff_ab;
-
+    u8            bySignalField_ab;
+    u8            byServiceField_ab;
+    u16            wTransmitLength_ab;
+    u16            wDuration_ab;
+    u16            wTimeStampOff_ab;
 
 } TX_NAF_AB_RTS, *PTX_NAF_AB_RTS;
 
-
 typedef struct tagSTX_NAF_AB_RTS_MIC
 {
     //RsvTime
-    WORD            wRTSTxRrvTime_ab;
-    WORD            wTxRrvTime_ab;
+    u16            wRTSTxRrvTime_ab;
+    u16            wTxRrvTime_ab;
 
     SMICHDR         sMICHDR;
 
     //RTS
-    BYTE            byRTSSignalField_ab;
-    BYTE            byRTSServiceField_ab;
-    WORD            wRTSTransmitLength_ab;
-    WORD            wRTSDuration_ab;
-    WORD            wReserved2;
+    u8            byRTSSignalField_ab;
+    u8            byRTSServiceField_ab;
+    u16            wRTSTransmitLength_ab;
+    u16            wRTSDuration_ab;
+    u16            wReserved2;
     SRTSDataF       sRTS;
 
     //Data
-    BYTE            bySignalField_ab;
-    BYTE            byServiceField_ab;
-    WORD            wTransmitLength_ab;
-    WORD            wDuration_ab;
-    WORD            wTimeStampOff_ab;
-
+    u8            bySignalField_ab;
+    u8            byServiceField_ab;
+    u16            wTransmitLength_ab;
+    u16            wDuration_ab;
+    u16            wTimeStampOff_ab;
 
 } TX_NAF_AB_RTS_MIC, *PTX_NAF_AB_RTS_MIC;
 
-
-
 typedef struct tagSTX_NAF_AB_CTS
 {
     //RsvTime
-    WORD            wReserved2;
-    WORD            wTxRrvTime_ab;
+    u16            wReserved2;
+    u16            wTxRrvTime_ab;
 
     //Data
-    BYTE            bySignalField_ab;
-    BYTE            byServiceField_ab;
-    WORD            wTransmitLength_ab;
-    WORD            wDuration_ab;
-    WORD            wTimeStampOff_ab;
+    u8            bySignalField_ab;
+    u8            byServiceField_ab;
+    u16            wTransmitLength_ab;
+    u16            wDuration_ab;
+    u16            wTimeStampOff_ab;
 
 } TX_NAF_AB_CTS, *PTX_NAF_AB_CTS;
 
 typedef struct tagSTX_NAF_AB_CTS_MIC
 {
     //RsvTime
-    WORD            wReserved2;
-    WORD            wTxRrvTime_ab;
+    u16            wReserved2;
+    u16            wTxRrvTime_ab;
 
     SMICHDR         sMICHDR;
 
     //Data
-    BYTE            bySignalField_ab;
-    BYTE            byServiceField_ab;
-    WORD            wTransmitLength_ab;
-    WORD            wDuration_ab;
-    WORD            wTimeStampOff_ab;
+    u8            bySignalField_ab;
+    u8            byServiceField_ab;
+    u16            wTransmitLength_ab;
+    u16            wDuration_ab;
+    u16            wTimeStampOff_ab;
 
 } TX_NAF_AB_CTS_MIC, *PTX_NAF_AB_CTS_MIC;
 
-
 typedef struct tagSTX_NAF_AB_BEACON
 {
-    WORD            wFIFOCtl;
-    WORD            wTimeStamp;
+    u16            wFIFOCtl;
+    u16            wTimeStamp;
 
    //Data
-    BYTE            bySignalField_ab;
-    BYTE            byServiceField_ab;
-    WORD            wTransmitLength_ab;
-    WORD            wDuration_ab;
-    WORD            wTimeStampOff_ab;
+    u8            bySignalField_ab;
+    u8            byServiceField_ab;
+    u16            wTransmitLength_ab;
+    u16            wDuration_ab;
+    u16            wTimeStampOff_ab;
 
 } TX_NAF_AB_BEACON, *PTX_NAF_AB_BEACON;
 
 typedef struct tagSTX_AF_G_RTS
 {
     //RsvTime
-    WORD            wRTSTxRrvTime_ba;
-    WORD            wRTSTxRrvTime_aa;
-    WORD            wRTSTxRrvTime_bb;
-    WORD            wReserved2;
-    WORD            wTxRrvTime_b;
-    WORD            wTxRrvTime_a;
+    u16            wRTSTxRrvTime_ba;
+    u16            wRTSTxRrvTime_aa;
+    u16            wRTSTxRrvTime_bb;
+    u16            wReserved2;
+    u16            wTxRrvTime_b;
+    u16            wTxRrvTime_a;
 
     //RTS
-    BYTE            byRTSSignalField_b;
-    BYTE            byRTSServiceField_b;
-    WORD            wRTSTransmitLength_b;
-    BYTE            byRTSSignalField_a;
-    BYTE            byRTSServiceField_a;
-    WORD            wRTSTransmitLength_a;
-    WORD            wRTSDuration_ba;
-    WORD            wRTSDuration_aa;
-    WORD            wRTSDuration_bb;
-    WORD            wReserved3;
-    WORD            wRTSDuration_ba_f0;
-    WORD            wRTSDuration_aa_f0;
-    WORD            wRTSDuration_ba_f1;
-    WORD            wRTSDuration_aa_f1;
+    u8            byRTSSignalField_b;
+    u8            byRTSServiceField_b;
+    u16            wRTSTransmitLength_b;
+    u8            byRTSSignalField_a;
+    u8            byRTSServiceField_a;
+    u16            wRTSTransmitLength_a;
+    u16            wRTSDuration_ba;
+    u16            wRTSDuration_aa;
+    u16            wRTSDuration_bb;
+    u16            wReserved3;
+    u16            wRTSDuration_ba_f0;
+    u16            wRTSDuration_aa_f0;
+    u16            wRTSDuration_ba_f1;
+    u16            wRTSDuration_aa_f1;
     SRTSDataF       sRTS;
 
     //Data
-    BYTE            bySignalField_b;
-    BYTE            byServiceField_b;
-    WORD            wTransmitLength_b;
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_b;
-    WORD            wDuration_a;
-    WORD            wDuration_a_f0;
-    WORD            wDuration_a_f1;
-    WORD            wTimeStampOff_b;
-    WORD            wTimeStampOff_a;
+    u8            bySignalField_b;
+    u8            byServiceField_b;
+    u16            wTransmitLength_b;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_b;
+    u16            wDuration_a;
+    u16            wDuration_a_f0;
+    u16            wDuration_a_f1;
+    u16            wTimeStampOff_b;
+    u16            wTimeStampOff_a;
 
 } TX_AF_G_RTS, *PTX_AF_G_RTS;
 
-
 typedef struct tagSTX_AF_G_RTS_MIC
 {
     //RsvTime
-    WORD            wRTSTxRrvTime_ba;
-    WORD            wRTSTxRrvTime_aa;
-    WORD            wRTSTxRrvTime_bb;
-    WORD            wReserved2;
-    WORD            wTxRrvTime_b;
-    WORD            wTxRrvTime_a;
+    u16            wRTSTxRrvTime_ba;
+    u16            wRTSTxRrvTime_aa;
+    u16            wRTSTxRrvTime_bb;
+    u16            wReserved2;
+    u16            wTxRrvTime_b;
+    u16            wTxRrvTime_a;
 
     SMICHDR         sMICHDR;
 
     //RTS
-    BYTE            byRTSSignalField_b;
-    BYTE            byRTSServiceField_b;
-    WORD            wRTSTransmitLength_b;
-    BYTE            byRTSSignalField_a;
-    BYTE            byRTSServiceField_a;
-    WORD            wRTSTransmitLength_a;
-    WORD            wRTSDuration_ba;
-    WORD            wRTSDuration_aa;
-    WORD            wRTSDuration_bb;
-    WORD            wReserved3;
-    WORD            wRTSDuration_ba_f0;
-    WORD            wRTSDuration_aa_f0;
-    WORD            wRTSDuration_ba_f1;
-    WORD            wRTSDuration_aa_f1;
+    u8            byRTSSignalField_b;
+    u8            byRTSServiceField_b;
+    u16            wRTSTransmitLength_b;
+    u8            byRTSSignalField_a;
+    u8            byRTSServiceField_a;
+    u16            wRTSTransmitLength_a;
+    u16            wRTSDuration_ba;
+    u16            wRTSDuration_aa;
+    u16            wRTSDuration_bb;
+    u16            wReserved3;
+    u16            wRTSDuration_ba_f0;
+    u16            wRTSDuration_aa_f0;
+    u16            wRTSDuration_ba_f1;
+    u16            wRTSDuration_aa_f1;
     SRTSDataF       sRTS;
 
     //Data
-    BYTE            bySignalField_b;
-    BYTE            byServiceField_b;
-    WORD            wTransmitLength_b;
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_b;
-    WORD            wDuration_a;
-    WORD            wDuration_a_f0;
-    WORD            wDuration_a_f1;
-    WORD            wTimeStampOff_b;
-    WORD            wTimeStampOff_a;
+    u8            bySignalField_b;
+    u8            byServiceField_b;
+    u16            wTransmitLength_b;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_b;
+    u16            wDuration_a;
+    u16            wDuration_a_f0;
+    u16            wDuration_a_f1;
+    u16            wTimeStampOff_b;
+    u16            wTimeStampOff_a;
 
 } TX_AF_G_RTS_MIC, *PTX_AF_G_RTS_MIC;
 
-
-
 typedef struct tagSTX_AF_G_CTS
 {
     //RsvTime
-    WORD            wCTSTxRrvTime_ba;
-    WORD            wReserved2;
-    WORD            wTxRrvTime_b;
-    WORD            wTxRrvTime_a;
+    u16            wCTSTxRrvTime_ba;
+    u16            wReserved2;
+    u16            wTxRrvTime_b;
+    u16            wTxRrvTime_a;
 
     //CTS
-    BYTE            byCTSSignalField_b;
-    BYTE            byCTSServiceField_b;
-    WORD            wCTSTransmitLength_b;
-    WORD            wCTSDuration_ba;
-    WORD            wReserved3;
-    WORD            wCTSDuration_ba_f0;
-    WORD            wCTSDuration_ba_f1;
+    u8            byCTSSignalField_b;
+    u8            byCTSServiceField_b;
+    u16            wCTSTransmitLength_b;
+    u16            wCTSDuration_ba;
+    u16            wReserved3;
+    u16            wCTSDuration_ba_f0;
+    u16            wCTSDuration_ba_f1;
     SCTSDataF       sCTS;
 
     //Data
-    BYTE            bySignalField_b;
-    BYTE            byServiceField_b;
-    WORD            wTransmitLength_b;
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_b;
-    WORD            wDuration_a;
-    WORD            wDuration_a_f0;
-    WORD            wDuration_a_f1;
-    WORD            wTimeStampOff_b;
-    WORD            wTimeStampOff_a;
+    u8            bySignalField_b;
+    u8            byServiceField_b;
+    u16            wTransmitLength_b;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_b;
+    u16            wDuration_a;
+    u16            wDuration_a_f0;
+    u16            wDuration_a_f1;
+    u16            wTimeStampOff_b;
+    u16            wTimeStampOff_a;
 
 } TX_AF_G_CTS, *PTX_AF_G_CTS;
 
-
 typedef struct tagSTX_AF_G_CTS_MIC
 {
     //RsvTime
-    WORD            wCTSTxRrvTime_ba;
-    WORD            wReserved2;
-    WORD            wTxRrvTime_b;
-    WORD            wTxRrvTime_a;
-
+    u16            wCTSTxRrvTime_ba;
+    u16            wReserved2;
+    u16            wTxRrvTime_b;
+    u16            wTxRrvTime_a;
 
     SMICHDR         sMICHDR;
 
     //CTS
-    BYTE            byCTSSignalField_b;
-    BYTE            byCTSServiceField_b;
-    WORD            wCTSTransmitLength_b;
-    WORD            wCTSDuration_ba;
-    WORD            wReserved3;
-    WORD            wCTSDuration_ba_f0;
-    WORD            wCTSDuration_ba_f1;
+    u8            byCTSSignalField_b;
+    u8            byCTSServiceField_b;
+    u16            wCTSTransmitLength_b;
+    u16            wCTSDuration_ba;
+    u16            wReserved3;
+    u16            wCTSDuration_ba_f0;
+    u16            wCTSDuration_ba_f1;
     SCTSDataF       sCTS;
 
     //Data
-    BYTE            bySignalField_b;
-    BYTE            byServiceField_b;
-    WORD            wTransmitLength_b;
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_b;
-    WORD            wDuration_a;
-    WORD            wDuration_a_f0;
-    WORD            wDuration_a_f1;
-    WORD            wTimeStampOff_b;
-    WORD            wTimeStampOff_a;
+    u8            bySignalField_b;
+    u8            byServiceField_b;
+    u16            wTransmitLength_b;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_b;
+    u16            wDuration_a;
+    u16            wDuration_a_f0;
+    u16            wDuration_a_f1;
+    u16            wTimeStampOff_b;
+    u16            wTimeStampOff_a;
 
 } TX_AF_G_CTS_MIC, *PTX_AF_G_CTS_MIC;
 
-
-
 typedef struct tagSTX_AF_A_RTS
 {
     //RsvTime
-    WORD            wRTSTxRrvTime_a;
-    WORD            wTxRrvTime_a;
+    u16            wRTSTxRrvTime_a;
+    u16            wTxRrvTime_a;
 
     //RTS
-    BYTE            byRTSSignalField_a;
-    BYTE            byRTSServiceField_a;
-    WORD            wRTSTransmitLength_a;
-    WORD            wRTSDuration_a;
-    WORD            wReserved2;
-    WORD            wRTSDuration_a_f0;
-    WORD            wRTSDuration_a_f1;
+    u8            byRTSSignalField_a;
+    u8            byRTSServiceField_a;
+    u16            wRTSTransmitLength_a;
+    u16            wRTSDuration_a;
+    u16            wReserved2;
+    u16            wRTSDuration_a_f0;
+    u16            wRTSDuration_a_f1;
     SRTSDataF       sRTS;
 
     //Data
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_a;
-    WORD            wTimeStampOff_a;
-    WORD            wDuration_a_f0;
-    WORD            wDuration_a_f1;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_a;
+    u16            wTimeStampOff_a;
+    u16            wDuration_a_f0;
+    u16            wDuration_a_f1;
 
 } TX_AF_A_RTS, *PTX_AF_A_RTS;
 
-
 typedef struct tagSTX_AF_A_RTS_MIC
 {
     //RsvTime
-    WORD            wRTSTxRrvTime_a;
-    WORD            wTxRrvTime_a;
+    u16            wRTSTxRrvTime_a;
+    u16            wTxRrvTime_a;
 
     SMICHDR         sMICHDR;
 
     //RTS
-    BYTE            byRTSSignalField_a;
-    BYTE            byRTSServiceField_a;
-    WORD            wRTSTransmitLength_a;
-    WORD            wRTSDuration_a;
-    WORD            wReserved2;
-    WORD            wRTSDuration_a_f0;
-    WORD            wRTSDuration_a_f1;
+    u8            byRTSSignalField_a;
+    u8            byRTSServiceField_a;
+    u16            wRTSTransmitLength_a;
+    u16            wRTSDuration_a;
+    u16            wReserved2;
+    u16            wRTSDuration_a_f0;
+    u16            wRTSDuration_a_f1;
     SRTSDataF       sRTS;
 
     //Data
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_a;
-    WORD            wTimeStampOff_a;
-    WORD            wDuration_a_f0;
-    WORD            wDuration_a_f1;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_a;
+    u16            wTimeStampOff_a;
+    u16            wDuration_a_f0;
+    u16            wDuration_a_f1;
 
 } TX_AF_A_RTS_MIC, *PTX_AF_A_RTS_MIC;
 
-
-
 typedef struct tagSTX_AF_A_CTS
 {
     //RsvTime
-    WORD            wReserved2;
-    WORD            wTxRrvTime_a;
+    u16            wReserved2;
+    u16            wTxRrvTime_a;
 
     //Data
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_a;
-    WORD            wTimeStampOff_a;
-    WORD            wDuration_a_f0;
-    WORD            wDuration_a_f1;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_a;
+    u16            wTimeStampOff_a;
+    u16            wDuration_a_f0;
+    u16            wDuration_a_f1;
 
 } TX_AF_A_CTS, *PTX_AF_A_CTS;
 
-
 typedef struct tagSTX_AF_A_CTS_MIC
 {
     //RsvTime
-    WORD            wReserved2;
-    WORD            wTxRrvTime_a;
+    u16            wReserved2;
+    u16            wTxRrvTime_a;
 
     SMICHDR         sMICHDR;
 
     //Data
-    BYTE            bySignalField_a;
-    BYTE            byServiceField_a;
-    WORD            wTransmitLength_a;
-    WORD            wDuration_a;
-    WORD            wTimeStampOff_a;
-    WORD            wDuration_a_f0;
-    WORD            wDuration_a_f1;
+    u8            bySignalField_a;
+    u8            byServiceField_a;
+    u16            wTransmitLength_a;
+    u16            wDuration_a;
+    u16            wTimeStampOff_a;
+    u16            wDuration_a_f0;
+    u16            wDuration_a_f1;
 
 } TX_AF_A_CTS_MIC, *PTX_AF_A_CTS_MIC;
 
-
 //
 // union with all of the TX Buffer Type
 //
@@ -620,51 +591,43 @@ typedef union tagUTX_BUFFER_CONTAINER
 
 } TX_BUFFER_CONTAINER, *PTX_BUFFER_CONTAINER;
 
-
 //
 // Remote NDIS message format
 //
 typedef struct tagSTX_BUFFER
 {
-    BYTE                            byType;
-    BYTE                            byPKTNO;
-    WORD                            wTxByteCount;
+    u8                            byType;
+    u8                            byPKTNO;
+    u16                            wTxByteCount;
 
        u32 adwTxKey[4];
-    WORD                            wFIFOCtl;
-    WORD                            wTimeStamp;
-    WORD                            wFragCtl;
-    WORD                            wReserved;
-
+    u16                            wFIFOCtl;
+    u16                            wTimeStamp;
+    u16                            wFragCtl;
+    u16                            wReserved;
 
     // Actual message
     TX_BUFFER_CONTAINER             BufferHeader;
 
 } TX_BUFFER, *PTX_BUFFER;
 
-
 //
 // Remote NDIS message format
 //
 typedef struct tagSBEACON_BUFFER
 {
-    BYTE                            byType;
-    BYTE                            byPKTNO;
-    WORD                            wTxByteCount;
+    u8                            byType;
+    u8                            byPKTNO;
+    u16                            wTxByteCount;
 
-    WORD                            wFIFOCtl;
-    WORD                            wTimeStamp;
+    u16                            wFIFOCtl;
+    u16                            wTimeStamp;
 
     // Actual message
     TX_BUFFER_CONTAINER             BufferHeader;
 
 } BEACON_BUFFER, *PBEACON_BUFFER;
 
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 void vDMA0_tx_80211(struct vnt_private *, struct sk_buff *skb);
 int nsDMA_tx_packet(struct vnt_private *, u32 uDMAIdx, struct sk_buff *skb);
 CMD_STATUS csMgmt_xmit(struct vnt_private *, struct vnt_tx_mgmt *);
index dba21a54414be647b1be82f46a79270d6af33b72..488192d79ac95f916379a8f7dde0c5afba4fc708 100644 (file)
 #ifndef __SROM_H__
 #define __SROM_H__
 
-#include "ttype.h"
-
-/*---------------------  Export Definitions -------------------------*/
-
 #define EEP_MAX_CONTEXT_SIZE    256
 
 #define CB_EEPROM_READBYTE_WAIT 900     //us
@@ -56,7 +52,6 @@
 #define EEP_OFS_SETPT_CCK   0x21
 #define EEP_OFS_PWR_OFDMG   0x23
 
-
 #define EEP_OFS_CALIB_TX_IQ 0x24
 #define EEP_OFS_CALIB_TX_DC 0x25
 #define EEP_OFS_CALIB_RX_IQ 0x26
 //
 #define EEP_RADIOCTL_ENABLE 0x80
 
-/*---------------------  Export Types  ------------------------------*/
-
 // AT24C02 eeprom contents
 //      2048 bits = 256 bytes = 128 words
 //
 typedef struct tagSSromReg {
-    BYTE    abyPAR[6];                  // 0x00 (WORD)
-
-    WORD    wSUB_VID;                   // 0x03 (WORD)
-    WORD    wSUB_SID;
-
-    BYTE    byBCFG0;                    // 0x05 (WORD)
-    BYTE    byBCFG1;
-
-    BYTE    byFCR0;                     // 0x06 (WORD)
-    BYTE    byFCR1;
-    BYTE    byPMC0;                     // 0x07 (WORD)
-    BYTE    byPMC1;
-    BYTE    byMAXLAT;                   // 0x08 (WORD)
-    BYTE    byMINGNT;
-    BYTE    byCFG0;                     // 0x09 (WORD)
-    BYTE    byCFG1;
-    WORD    wCISPTR;                    // 0x0A (WORD)
-    WORD    wRsv0;                      // 0x0B (WORD)
-    WORD    wRsv1;                      // 0x0C (WORD)
-    BYTE    byBBPAIR;                   // 0x0D (WORD)
-    BYTE    byRFTYPE;
-    BYTE    byMinChannel;               // 0x0E (WORD)
-    BYTE    byMaxChannel;
-    BYTE    bySignature;                // 0x0F (WORD)
-    BYTE    byCheckSum;
-
-    BYTE    abyReserved0[96];           // 0x10 (WORD)
-    BYTE    abyCIS[128];                // 0x80 (WORD)
+    u8    abyPAR[6];                  // 0x00 (u16)
+
+    u16    wSUB_VID;                   // 0x03 (u16)
+    u16    wSUB_SID;
+
+    u8    byBCFG0;                    // 0x05 (u16)
+    u8    byBCFG1;
+
+    u8    byFCR0;                     // 0x06 (u16)
+    u8    byFCR1;
+    u8    byPMC0;                     // 0x07 (u16)
+    u8    byPMC1;
+    u8    byMAXLAT;                   // 0x08 (u16)
+    u8    byMINGNT;
+    u8    byCFG0;                     // 0x09 (u16)
+    u8    byCFG1;
+    u16    wCISPTR;                    // 0x0A (u16)
+    u16    wRsv0;                      // 0x0B (u16)
+    u16    wRsv1;                      // 0x0C (u16)
+    u8    byBBPAIR;                   // 0x0D (u16)
+    u8    byRFTYPE;
+    u8    byMinChannel;               // 0x0E (u16)
+    u8    byMaxChannel;
+    u8    bySignature;                // 0x0F (u16)
+    u8    byCheckSum;
+
+    u8    abyReserved0[96];           // 0x10 (u16)
+    u8    abyCIS[128];                // 0x80 (u16)
 } SSromReg, *PSSromReg;
 
-/*---------------------  Export Macros ------------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 #endif /* __EEPROM_H__ */
index 2237eeb5ec5bba7133f9377fb862f660dbd4606e..7229f26c052cc4f04abab54d6b10f1d4cc68bccd 100644 (file)
 
 #include "tcrc.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
 /* 32-bit CRC table */
-static const DWORD s_adwCrc32Table[256] = {
+static const u32 s_adwCrc32Table[256] = {
     0x00000000L, 0x77073096L, 0xEE0E612CL, 0x990951BAL,
     0x076DC419L, 0x706AF48FL, 0xE963A535L, 0x9E6495A3L,
     0x0EDB8832L, 0x79DCB8A4L, 0xE0D5E91EL, 0x97D2D988L,
@@ -109,13 +103,6 @@ static const DWORD s_adwCrc32Table[256] = {
     0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL, 0x2D02EF8DL
 };
 
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-
-
-
 /*+
  *
  * Description:
@@ -132,13 +119,13 @@ static const DWORD s_adwCrc32Table[256] = {
  * Return Value: CRC-32
  *
 -*/
-DWORD CRCdwCrc32(PBYTE pbyData, unsigned int cbByte, DWORD dwCrcSeed)
+u32 CRCdwCrc32(u8 * pbyData, unsigned int cbByte, u32 dwCrcSeed)
 {
-       DWORD dwCrc;
+       u32 dwCrc;
 
        dwCrc = dwCrcSeed;
        while (cbByte--) {
-               dwCrc = s_adwCrc32Table[(BYTE)((dwCrc ^ (*pbyData)) & 0xFF)] ^
+               dwCrc = s_adwCrc32Table[(u8)((dwCrc ^ (*pbyData)) & 0xFF)] ^
                        (dwCrc >> 8);
                pbyData++;
        }
@@ -146,7 +133,6 @@ DWORD CRCdwCrc32(PBYTE pbyData, unsigned int cbByte, DWORD dwCrcSeed)
        return dwCrc;
 }
 
-
 /*+
  *
  * Description:
@@ -165,12 +151,11 @@ DWORD CRCdwCrc32(PBYTE pbyData, unsigned int cbByte, DWORD dwCrcSeed)
  * Return Value: CRC-32
  *
 -*/
-DWORD CRCdwGetCrc32(PBYTE pbyData, unsigned int cbByte)
+u32 CRCdwGetCrc32(u8 * pbyData, unsigned int cbByte)
 {
     return ~CRCdwCrc32(pbyData, cbByte, 0xFFFFFFFFL);
 }
 
-
 /*+
  *
  * Description:
@@ -191,9 +176,8 @@ DWORD CRCdwGetCrc32(PBYTE pbyData, unsigned int cbByte)
  * Return Value: CRC-32
  *
 -*/
-DWORD CRCdwGetCrc32Ex(PBYTE pbyData, unsigned int cbByte, DWORD dwPreCRC)
+u32 CRCdwGetCrc32Ex(u8 * pbyData, unsigned int cbByte, u32 dwPreCRC)
 {
     return CRCdwCrc32(pbyData, cbByte, dwPreCRC);
 }
 
-
index dc54bd8fc4fcc833b5b79672f42e3e15482a9398..5b1f368964eb63f36aba1eeb6c703c14bed322f9 100644 (file)
 #ifndef __TCRC_H__
 #define __TCRC_H__
 
-#include "ttype.h"
+#include <linux/types.h>
 
-/*---------------------  Export Definitions -------------------------*/
-
-/*---------------------  Export Types  ------------------------------*/
-
-/*---------------------  Export Macros ------------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
-DWORD CRCdwCrc32(PBYTE pbyData, unsigned int cbByte, DWORD dwCrcSeed);
-DWORD CRCdwGetCrc32(PBYTE pbyData, unsigned int cbByte);
-DWORD CRCdwGetCrc32Ex(PBYTE pbyData, unsigned int cbByte, DWORD dwPreCRC);
+u32 CRCdwCrc32(u8 * pbyData, unsigned int cbByte, u32 dwCrcSeed);
+u32 CRCdwGetCrc32(u8 * pbyData, unsigned int cbByte);
+u32 CRCdwGetCrc32Ex(u8 * pbyData, unsigned int cbByte, u32 dwPreCRC);
 
 #endif /* __TCRC_H__ */
index 95286c4d5572f6fb8b003d318e3b1b089112f7e7..1db1e8419a9a846ff734a133dbf14b135add6f10 100644 (file)
@@ -25,7 +25,6 @@
  * Date: May 21, 1996
  *
  * Functions:
- *      ETHbyGetHashIndexByCrc32 - Calculate multicast hash value by CRC32
  *      ETHbIsBufferCrc32Ok - Check CRC value of the buffer if Ok or not
  *
  * Revision History:
 #include "tcrc.h"
 #include "tether.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-
-
-/*
- * Description: Calculate multicast hash value by CRC32
- *
- * Parameters:
- *  In:
- *             pbyMultiAddr    - Multicast Address
- *  Out:
- *      none
- *
- * Return Value: Hash value
- *
- */
-BYTE ETHbyGetHashIndexByCrc32(PBYTE pbyMultiAddr)
-{
-       int     ii;
-       BYTE    byTmpHash;
-       BYTE    byHash = 0;
-
-       /* get the least 6-bits from CRC generator */
-       byTmpHash = (BYTE)(CRCdwCrc32(pbyMultiAddr, ETH_ALEN,
-                       0xFFFFFFFFL) & 0x3F);
-       /* reverse most bit to least bit */
-       for (ii = 0; ii < (sizeof(byTmpHash) * 8); ii++) {
-               byHash <<= 1;
-               if (byTmpHash & 0x01)
-                       byHash |= 1;
-               byTmpHash >>= 1;
-       }
-
-       /* adjust 6-bits to the right most */
-       return byHash >> 2;
-}
-
-
 /*
  * Description: Check CRC value of the buffer if Ok or not
  *
@@ -96,12 +49,12 @@ BYTE ETHbyGetHashIndexByCrc32(PBYTE pbyMultiAddr)
  * Return Value: true if ok; false if error.
  *
  */
-bool ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength)
+bool ETHbIsBufferCrc32Ok(u8 * pbyBuffer, unsigned int cbFrameLength)
 {
-       DWORD dwCRC;
+       u32 dwCRC;
 
        dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4);
-       if (cpu_to_le32(*((PDWORD)(pbyBuffer + cbFrameLength - 4))) != dwCRC)
+       if (cpu_to_le32(*((u32 *)(pbyBuffer + cbFrameLength - 4))) != dwCRC)
                return false;
        return true;
 }
index 2f8f4853fd9d832aea6fe08680c1f555bc441f94..24465cfe3e6dd02330799dbbdff85de8d985eb7c 100644 (file)
@@ -30,9 +30,7 @@
 #define __TETHER_H__
 
 #include <linux/if_ether.h>
-#include "ttype.h"
 
-/*---------------------  Export Definitions -------------------------*/
 //
 // constants
 //
 
 #define TYPE_MGMT_PROBE_RSP 0x5000
 
-//
-// wFrameCtl field in the S802_11Header
-//
-// NOTE....
-//   in network byte order, high byte is going first
 #define FC_TODS             0x0001
 #define FC_FROMDS           0x0002
 #define FC_MOREFRAG         0x0004
@@ -71,8 +64,6 @@
 #define TYPE_CTL_CTS        0xc400
 #define TYPE_CTL_ACK        0xd400
 
-
-
 #else //if LITTLE_ENDIAN
 //
 // wType field in the SEthernetHeader
 
 #define TYPE_MGMT_PROBE_RSP 0x0050
 
-//
-// wFrameCtl field in the S802_11Header
-//
-// NOTE....
-//   in network byte order, high byte is going first
 #define FC_TODS             0x0100
 #define FC_FROMDS           0x0200
 #define FC_MOREFRAG         0x0400
 #define TYPE_CTL_CTS        0x00c4
 #define TYPE_CTL_ACK        0x00d4
 
-
-
 #endif //#ifdef __BIG_ENDIAN
 
 #define WEP_IV_MASK         0x00FFFFFF
 
-/*---------------------  Export Types  ------------------------------*/
-//
-// Ethernet packet
-//
-typedef struct tagSEthernetHeader {
-    BYTE    abyDstAddr[ETH_ALEN];
-    BYTE    abySrcAddr[ETH_ALEN];
-    WORD    wType;
-} __attribute__ ((__packed__))
-SEthernetHeader, *PSEthernetHeader;
-
-
 //
 // 802_3 packet
 //
 typedef struct tagS802_3Header {
-    BYTE    abyDstAddr[ETH_ALEN];
-    BYTE    abySrcAddr[ETH_ALEN];
-    WORD    wLen;
+    u8    abyDstAddr[ETH_ALEN];
+    u8    abySrcAddr[ETH_ALEN];
+    u16    wLen;
 } __attribute__ ((__packed__))
 S802_3Header, *PS802_3Header;
 
-//
-// 802_11 packet
-//
-typedef struct tagS802_11Header {
-    WORD    wFrameCtl;
-    WORD    wDurationID;
-    BYTE    abyAddr1[ETH_ALEN];
-    BYTE    abyAddr2[ETH_ALEN];
-    BYTE    abyAddr3[ETH_ALEN];
-    WORD    wSeqCtl;
-    BYTE    abyAddr4[ETH_ALEN];
-} __attribute__ ((__packed__))
-S802_11Header, *PS802_11Header;
-
-/*---------------------  Export Macros ------------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
-BYTE ETHbyGetHashIndexByCrc32(PBYTE pbyMultiAddr);
-//BYTE ETHbyGetHashIndexByCrc(PBYTE pbyMultiAddr);
-bool ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength);
+//u8 ETHbyGetHashIndexByCrc(u8 * pbyMultiAddr);
+bool ETHbIsBufferCrc32Ok(u8 * pbyBuffer, unsigned int cbFrameLength);
 
 #endif /* __TETHER_H__ */
index 282c08d65761a7f353cca2b0c3092b8b99a8a567..9d643e449ac3c1ce97ecb84bd031820510c88415 100644 (file)
 #include "tmacro.h"
 #include "tkip.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
 /* The Sbox is reduced to 2 16-bit wide tables, each with 256 entries. */
 /* The 2nd table is the same as the 1st but with the upper and lower   */
 /* bytes swapped. To allow an endian tolerant implementation, the byte */
 /* halves have been expressed independently here.                      */
-const BYTE TKIP_Sbox_Lower[256] = {
+const u8 TKIP_Sbox_Lower[256] = {
     0xA5,0x84,0x99,0x8D,0x0D,0xBD,0xB1,0x54,
     0x50,0x03,0xA9,0x7D,0x19,0x62,0xE6,0x9A,
     0x45,0x9D,0x40,0x87,0x15,0xEB,0xC9,0x0B,
@@ -90,7 +74,7 @@ const BYTE TKIP_Sbox_Lower[256] = {
     0xC3,0xB0,0x77,0x11,0xCB,0xFC,0xD6,0x3A
 };
 
-const BYTE TKIP_Sbox_Upper[256] = {
+const u8 TKIP_Sbox_Upper[256] = {
     0xC6,0xF8,0xEE,0xF6,0xFF,0xD6,0xDE,0x91,
     0x60,0x02,0xCE,0x56,0xE7,0xB5,0x4D,0xEC,
     0x8F,0x1F,0x89,0xFA,0xEF,0xB2,0x8E,0xFB,
@@ -125,13 +109,8 @@ const BYTE TKIP_Sbox_Upper[256] = {
     0x82,0x29,0x5A,0x1E,0x7B,0xA8,0x6D,0x2C
 };
 
-
 //STKIPKeyManagement  sTKIPKeyTable[MAX_TKIP_KEY];
 
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
 /************************************************************/
 /* tkip_sbox()                                              */
 /* Returns a 16 bit value from a 64K entry table. The Table */
@@ -152,7 +131,6 @@ static unsigned int tkip_sbox(unsigned int index)
     return (left ^ right);
 };
 
-
 static unsigned int rotr1(unsigned int a)
 {
     unsigned int b;
@@ -166,7 +144,6 @@ static unsigned int rotr1(unsigned int a)
     return b;
 }
 
-
 /*
  * Description: Calculate RC4Key fom TK, TA, and TSC
  *
@@ -182,11 +159,11 @@ static unsigned int rotr1(unsigned int a)
  *
  */
 void TKIPvMixKey(
-    PBYTE   pbyTKey,
-    PBYTE   pbyTA,
-    WORD    wTSC15_0,
-    DWORD   dwTSC47_16,
-    PBYTE   pbyRC4Key
+    u8 *   pbyTKey,
+    u8 *   pbyTA,
+    u16    wTSC15_0,
+    u32   dwTSC47_16,
+    u8 *   pbyRC4Key
     )
 {
        u32 p1k[5];
index 47c3a853b92a682482d6c8a4348f17128337ed04..4fba7ef38266d89b170106b699f95127a55d0036 100644 (file)
 #ifndef __TKIP_H__
 #define __TKIP_H__
 
-#include "ttype.h"
 #include "tether.h"
 
-/*---------------------  Export Definitions -------------------------*/
 #define TKIP_KEY_LEN        16
 
-/*---------------------  Export Types  ------------------------------*/
-
-/*---------------------  Export Macros ------------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 void TKIPvMixKey(
-    PBYTE   pbyTKey,
-    PBYTE   pbyTA,
-    WORD    wTSC15_0,
-    DWORD   dwTSC47_16,
-    PBYTE   pbyRC4Key
+    u8 *   pbyTKey,
+    u8 *   pbyTA,
+    u16    wTSC15_0,
+    u32   dwTSC47_16,
+    u8 *   pbyRC4Key
     );
 
 #endif /* __TKIP_H__ */
index 3c81e2b0791df640907a97b28b35355f7c82d0b0..15cd5abb8004b6be1b893a8fded64fe7c5aaa942 100644 (file)
 #ifndef __TMACRO_H__
 #define __TMACRO_H__
 
-#include "ttype.h"
-
 /****** Common helper macros ***********************************************/
 
 #if !defined(LOBYTE)
-#define LOBYTE(w)           ((BYTE)(w))
+#define LOBYTE(w)           ((u8)(w))
 #endif
 #if !defined(HIBYTE)
-#define HIBYTE(w)           ((BYTE)(((WORD)(w) >> 8) & 0xFF))
+#define HIBYTE(w)           ((u8)(((u16)(w) >> 8) & 0xFF))
 #endif
 
 #if !defined(LOWORD)
-#define LOWORD(d)           ((WORD)(d))
+#define LOWORD(d)           ((u16)(d))
 #endif
 #if !defined(HIWORD)
-#define HIWORD(d)           ((WORD)((((DWORD)(d)) >> 16) & 0xFFFF))
+#define HIWORD(d)           ((u16)((((u32)(d)) >> 16) & 0xFFFF))
 #endif
 
 #define LODWORD(q)          ((q).u.dwLowDword)
 #define HIDWORD(q)          ((q).u.dwHighDword)
 
 #if !defined(MAKEWORD)
-#define MAKEWORD(lb, hb)    ((WORD)(((BYTE)(lb)) | (((WORD)((BYTE)(hb))) << 8)))
+#define MAKEWORD(lb, hb)    ((u16)(((u8)(lb)) | (((u16)((u8)(hb))) << 8)))
 #endif
 #if !defined(MAKEDWORD)
-#define MAKEDWORD(lw, hw)   ((DWORD)(((WORD)(lw)) | (((DWORD)((WORD)(hw))) << 16)))
+#define MAKEDWORD(lw, hw)   ((u32)(((u16)(lw)) | (((u32)((u16)(hw))) << 16)))
 #endif
 
 #endif /* __TMACRO_H__ */
diff --git a/drivers/staging/vt6656/ttype.h b/drivers/staging/vt6656/ttype.h
deleted file mode 100644 (file)
index d7b6489..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
- * 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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * File: ttype.h
- *
- * Purpose: define basic common types and macros
- *
- * Author: Tevin Chen
- *
- * Date: May 21, 1996
- *
- */
-
-#ifndef __TTYPE_H__
-#define __TTYPE_H__
-
-#include <linux/types.h>
-
-/******* Common definitions and typedefs ***********************************/
-
-/****** Simple typedefs  ***************************************************/
-
-typedef u8 BYTE;
-typedef u16 WORD;
-typedef u32 DWORD;
-
-/****** Common pointer types ***********************************************/
-
-typedef u32 ULONG_PTR;
-typedef u32 DWORD_PTR;
-
-// boolean pointer
-
-typedef BYTE *           PBYTE;
-
-typedef WORD *           PWORD;
-
-typedef DWORD *          PDWORD;
-
-#endif /* __TTYPE_H__ */
index 00fd0f8a58c26cdc6920aab3504d3fbb2b31237b..098be609107c8d27ab96096523355277e6005c57 100644 (file)
@@ -45,7 +45,6 @@
 #include "desc.h"
 #include "device.h"
 
-/*---------------------  Static Definitions -------------------------*/
 //endpoint def
 //endpoint 0: control
 //endpoint 1: interrupt
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 static int          msglevel                =MSG_LEVEL_INFO;
 
-
 #define USB_CTL_WAIT   500 //ms
 
 #ifndef URB_ASYNC_UNLINK
 #define URB_ASYNC_UNLINK    0
 #endif
 
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
-
-/*---------------------  Static Functions  --------------------------*/
 static void s_nsInterruptUsbIoCompleteRead(struct urb *urb);
 static void s_nsBulkInUsbIoCompleteRead(struct urb *urb);
 static void s_nsBulkOutIoCompleteWrite(struct urb *urb);
 static void s_nsControlInUsbIoCompleteRead(struct urb *urb);
 static void s_nsControlInUsbIoCompleteWrite(struct urb *urb);
 
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 int PIPEnsControlOutAsyn(struct vnt_private *pDevice, u8 byRequest,
        u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer)
 {
@@ -251,8 +240,6 @@ static void s_nsControlInUsbIoCompleteWrite(struct urb *urb)
     MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
 }
 
-
-
 /*
  * Description:
  *      Complete function of usb Control callback
@@ -288,9 +275,6 @@ static void s_nsControlInUsbIoCompleteRead(struct urb *urb)
     MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
 }
 
-
-
-
 /*
  * Description:
  *      Allocates an usb interrupt in irp and calls USBD.
@@ -341,7 +325,6 @@ usb_fill_bulk_urb(pDevice->pInterruptURB,
     return ntStatus;
 }
 
-
 /*
  * Description:
  *      Complete function of usb interrupt in irp.
@@ -403,7 +386,6 @@ static void s_nsInterruptUsbIoCompleteRead(struct urb *urb)
 
     STAvUpdateUSBCounter(&pDevice->scStatistic.USB_InterruptStat, ntStatus);
 
-
     if (pDevice->fKillEventPollingThread != true) {
        usb_fill_bulk_urb(pDevice->pInterruptURB,
                      pDevice->usb,
@@ -444,7 +426,6 @@ int PIPEnsBulkInUsbRead(struct vnt_private *pDevice, PRCB pRCB)
        int ntStatus = 0;
        struct urb *pUrb;
 
-
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n");
 
     if (pDevice->Flags & fMP_DISCONNECTED)
@@ -452,7 +433,6 @@ int PIPEnsBulkInUsbRead(struct vnt_private *pDevice, PRCB pRCB)
 
     pDevice->ulBulkInPosted++;
 
-
        pUrb = pRCB->pUrb;
     //
     // Now that we have created the urb, we will send a
@@ -482,9 +462,6 @@ int PIPEnsBulkInUsbRead(struct vnt_private *pDevice, PRCB pRCB)
     return ntStatus;
 }
 
-
-
-
 /*
  * Description:
  *      Complete function of usb BulkIn irp.
@@ -535,7 +512,6 @@ static void s_nsBulkInUsbIoCompleteRead(struct urb *urb)
            pDevice->scStatistic.RxOkCnt ++;
     }
 
-
     STAvUpdateUSBCounter(&pDevice->scStatistic.USB_BulkInStat, status);
 
     if (bIndicateReceive) {
@@ -553,7 +529,6 @@ static void s_nsBulkInUsbIoCompleteRead(struct urb *urb)
         spin_unlock(&pDevice->lock);
     }
 
-
     return;
 }
 
@@ -576,8 +551,6 @@ int PIPEnsSendBulkOut(struct vnt_private *pDevice, PUSB_SEND_CONTEXT pContext)
        int status;
        struct urb          *pUrb;
 
-
-
     pDevice->bPWBitOn = false;
 
 /*
@@ -657,7 +630,6 @@ static void s_nsBulkOutIoCompleteWrite(struct urb *urb)
        unsigned long ulBufLen;
        PUSB_SEND_CONTEXT pContext;
 
-
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n");
     //
     // The context given to IoSetCompletionRoutine is an USB_CONTEXT struct
@@ -705,7 +677,6 @@ static void s_nsBulkOutIoCompleteWrite(struct urb *urb)
 
         pDevice->dev->trans_start = jiffies;
 
-
         if (status == STATUS_SUCCESS) {
             pDevice->packetsSent++;
         }
index b3023559c15bcfefe032ba0312d1a8a893746406..bb7a61111a621d39ec21470b68b742e330646782 100644 (file)
 #ifndef __USBPIPE_H__
 #define __USBPIPE_H__
 
-#include "ttype.h"
 #include "device.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 int PIPEnsControlOut(struct vnt_private *, u8 byRequest, u16 wValue,
                u16 wIndex, u16 wLength, u8 *pbyBuffer);
 int PIPEnsControlOutAsyn(struct vnt_private *, u8 byRequest,
index 4bb652bf7cf6ce4d1df2d2a9deafd58f90ae3cbf..0013cb73d83bcc94dfdadb5e5f3c0aadfdfe9236 100644 (file)
@@ -38,7 +38,6 @@
  *
  */
 
-#include "ttype.h"
 #include "tmacro.h"
 #include "device.h"
 #include "mac.h"
 #include "channel.h"
 #include "iowpa.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-
-
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
 static int          msglevel                =MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-/*---------------------  Static Functions  --------------------------*/
 
 static void s_vProbeChannel(struct vnt_private *);
 
@@ -74,16 +64,10 @@ static struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *,
        struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
        PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
 
-
 static int s_bCommandComplete(struct vnt_private *);
 
-
 static int s_bClearBSSID_SCAN(struct vnt_private *);
 
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 /*
  * Description:
  *      Stop AdHoc beacon during scan process
@@ -138,7 +122,6 @@ static void vAdHocBeaconStop(struct vnt_private *pDevice)
 
 } /* vAdHocBeaconStop */
 
-
 /*
  * Description:
  *      Restart AdHoc beacon after scan process complete
@@ -171,7 +154,6 @@ static void vAdHocBeaconRestart(struct vnt_private *pDevice)
 
 }
 
-
 /*+
  *
  * Routine Description:
@@ -200,7 +182,6 @@ static void s_vProbeChannel(struct vnt_private *pDevice)
        u8 *pbyRate;
        int ii;
 
-
     if (pDevice->byBBType == BB_TYPE_11A) {
         pbyRate = &abyCurrSuppRatesA[0];
     } else if (pDevice->byBBType == BB_TYPE_11B) {
@@ -232,9 +213,6 @@ static void s_vProbeChannel(struct vnt_private *pDevice)
 
 }
 
-
-
-
 /*+
  *
  * Routine Description:
@@ -246,7 +224,6 @@ static void s_vProbeChannel(struct vnt_private *pDevice)
  *
 -*/
 
-
 struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *pDevice,
        struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
        PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
@@ -254,13 +231,12 @@ struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *pDevice,
        struct vnt_tx_mgmt *pTxPacket = NULL;
        WLAN_FR_PROBEREQ sFrame;
 
-
        pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
        memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
                + WLAN_PROBEREQ_FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
                + sizeof(struct vnt_tx_mgmt));
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
     vMgrEncodeProbeRequest(&sFrame);
     sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
@@ -316,7 +292,6 @@ void vRunCommand(struct vnt_private *pDevice)
        u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
        u8 byData;
 
-
     if (pDevice->dwDiagRefCount != 0)
         return;
     if (pDevice->bCmdRunning != true)
@@ -347,29 +322,7 @@ void vRunCommand(struct vnt_private *pDevice)
                 pMgmt->uScanChannel = pDevice->byMinChannel;
             }
             if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
-                pMgmt->eScanState = WMAC_NO_SCANNING;
-
-                if (pDevice->byBBType != pDevice->byScanBBType) {
-                    pDevice->byBBType = pDevice->byScanBBType;
-                    CARDvSetBSSMode(pDevice);
-                }
-
-                if (pDevice->bUpdateBBVGA) {
-                    BBvSetShortSlotTime(pDevice);
-                    BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
-                    BBvUpdatePreEDThreshold(pDevice, false);
-                }
-                // Set channel back
-                vAdHocBeaconRestart(pDevice);
-                // Set channel back
-                CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
-                // Set Filter
-                if (pMgmt->bCurrBSSIDFilterOn) {
-                    MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
-                    pDevice->byRxMode |= RCR_BSSID;
-                }
-                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
-                pDevice->bStopDataPkt = false;
+               pDevice->eCommandState = WLAN_CMD_SCAN_END;
                 s_bCommandComplete(pDevice);
                 spin_unlock_irq(&pDevice->lock);
                 return;
@@ -377,6 +330,7 @@ void vRunCommand(struct vnt_private *pDevice)
             } else {
                 if (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel)) {
                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n",pMgmt->uScanChannel);
+                       pMgmt->uScanChannel++;
                     s_bCommandComplete(pDevice);
                     spin_unlock_irq(&pDevice->lock);
                     return;
@@ -473,6 +427,7 @@ void vRunCommand(struct vnt_private *pDevice)
                 pDevice->byRxMode |= RCR_BSSID;
             }
             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
+               pMgmt->uScanChannel = 0;
             pMgmt->eScanState = WMAC_NO_SCANNING;
             pDevice->bStopDataPkt = false;
 
@@ -523,7 +478,6 @@ void vRunCommand(struct vnt_private *pDevice)
             s_bCommandComplete(pDevice);
             break;
 
-
         case WLAN_CMD_SSID_START:
 
                pDevice->byReAssocCount = 0;
@@ -845,7 +799,7 @@ void vRunCommand(struct vnt_private *pDevice)
 
        {
               int ntStatus = STATUS_SUCCESS;
-        BYTE            byTmp;
+        u8            byTmp;
 
         ntStatus = CONTROLnsRequestIn(pDevice,
                                     MESSAGE_TYPE_READ,
@@ -930,7 +884,6 @@ void vRunCommand(struct vnt_private *pDevice)
             s_bCommandComplete(pDevice);
             break;
 
-
         case WLAN_CMD_CHANGE_BBSENSITIVITY_START:
 
             pDevice->bStopDataPkt = true;
@@ -981,7 +934,6 @@ void vRunCommand(struct vnt_private *pDevice)
             s_bCommandComplete(pDevice);
             break;
 
-
         case WLAN_CMD_MAC_DISPOWERSAVING_START:
             ControlvReadByte (pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
             if ( (byData & PSCTL_PS) != 0 ) {
@@ -1014,7 +966,6 @@ void vRunCommand(struct vnt_private *pDevice)
     return;
 }
 
-
 static int s_bCommandComplete(struct vnt_private *pDevice)
 {
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
@@ -1022,7 +973,6 @@ static int s_bCommandComplete(struct vnt_private *pDevice)
        int bRadioCmd = false;
        int bForceSCAN = true;
 
-
     pDevice->eCommandState = WLAN_CMD_IDLE;
     if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
         //Command Queue Empty
@@ -1147,7 +1097,7 @@ int bScheduleCommand(struct vnt_private *pDevice,
                 break;
 /*
             case WLAN_CMD_DEAUTH:
-                pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((PWORD)pbyItem0);
+                pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((u16 *)pbyItem0);
                 break;
 */
 
@@ -1203,7 +1153,6 @@ static int s_bClearBSSID_SCAN(struct vnt_private *pDevice)
     return true;
 }
 
-
 //mike add:reset command timer
 void vResetCommandTimer(struct vnt_private *pDevice)
 {
index c40e6baa0b5d20535e03052653a2430e474008d1..db8b4cf7fd601ff4f29832658481abbb2c8c3708 100644 (file)
 
 #ifndef __WCMD_H__
 #define __WCMD_H__
-#include "ttype.h"
+
 #include "80211hdr.h"
 #include "80211mgr.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
-
-
 #define AUTHENTICATE_TIMEOUT   1000 //ms
 #define ASSOCIATE_TIMEOUT      1000 //ms
 
-
 // Command code
 typedef enum tagCMD_CODE {
     WLAN_CMD_BSSID_SCAN,
@@ -73,11 +68,11 @@ typedef enum tagCMD_STATUS {
 
 typedef struct tagCMD_ITEM {
     CMD_CODE eCmd;
-    BYTE     abyCmdDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
+    u8     abyCmdDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
     bool     bNeedRadioOFF;
     bool     bRadioCmd;
     bool     bForceSCAN;
-    WORD     wDeAuthenReason;
+    u16     wDeAuthenReason;
 } CMD_ITEM, *PCMD_ITEM;
 
 // Command state
@@ -104,13 +99,6 @@ typedef enum tagCMD_STATE {
     WLAN_CMD_IDLE
 } CMD_STATE, *PCMD_STATE;
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Types  ------------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
 struct vnt_private;
 
 void vResetCommandTimer(struct vnt_private *);
index baa48a1f0d364430f9bae2e941c23d0692ea4bcb..47a655db51efe7491af61f9243691e3660ea7ff4 100644 (file)
 #include "card.h"
 #include "tmacro.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
 // static int          msglevel                =MSG_LEVEL_INFO;
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-
 
 /*
  * Description:
@@ -67,7 +57,7 @@
  *
  */
 
-bool WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
+bool WCTLbIsDuplicate (PSCache pCache, struct ieee80211_hdr *pMACHeader)
 {
     unsigned int            uIndex;
     unsigned int            ii;
@@ -78,10 +68,10 @@ bool WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
         uIndex = pCache->uInPtr;
         for (ii = 0; ii < DUPLICATE_RX_CACHE_LENGTH; ii++) {
             pCacheEntry = &(pCache->asCacheEntry[uIndex]);
-            if ((pCacheEntry->wFmSequence == pMACHeader->wSeqCtl) &&
+            if ((pCacheEntry->wFmSequence == pMACHeader->seq_ctrl) &&
                (!compare_ether_addr(&(pCacheEntry->abyAddr2[0]),
-                                    &(pMACHeader->abyAddr2[0]))) &&
-                (LOBYTE(pCacheEntry->wFrameCtl) == LOBYTE(pMACHeader->wFrameCtl))
+                                    &(pMACHeader->addr2[0]))) &&
+                (LOBYTE(pCacheEntry->wFrameCtl) == LOBYTE(pMACHeader->frame_control))
                 ) {
                 /* Duplicate match */
                 return true;
@@ -91,9 +81,9 @@ bool WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
     }
     /* Not found in cache - insert */
     pCacheEntry = &pCache->asCacheEntry[pCache->uInPtr];
-    pCacheEntry->wFmSequence = pMACHeader->wSeqCtl;
-    memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN);
-    pCacheEntry->wFrameCtl = pMACHeader->wFrameCtl;
+    pCacheEntry->wFmSequence = pMACHeader->seq_ctrl;
+    memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->addr2[0]), ETH_ALEN);
+    pCacheEntry->wFrameCtl = pMACHeader->frame_control;
     ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH);
     return false;
 }
@@ -114,14 +104,14 @@ bool WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
  */
 
 unsigned int WCTLuSearchDFCB(struct vnt_private *pDevice,
-       PS802_11Header pMACHeader)
+                            struct ieee80211_hdr *pMACHeader)
 {
        unsigned int ii;
 
        for (ii = 0; ii < pDevice->cbDFCB; ii++) {
                if ((pDevice->sRxDFCB[ii].bInUse == true) &&
                    (!compare_ether_addr(&(pDevice->sRxDFCB[ii].abyAddr2[0]),
-                                         &(pMACHeader->abyAddr2[0])))) {
+                                         &(pMACHeader->addr2[0])))) {
                        return ii;
                }
        }
@@ -143,7 +133,7 @@ unsigned int WCTLuSearchDFCB(struct vnt_private *pDevice,
  *
  */
 unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice,
-       PS802_11Header pMACHeader)
+                            struct ieee80211_hdr *pMACHeader)
 {
        unsigned int ii;
 
@@ -154,10 +144,10 @@ unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice,
             pDevice->cbFreeDFCB--;
             pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime;
             pDevice->sRxDFCB[ii].bInUse = true;
-            pDevice->sRxDFCB[ii].wSequence = (pMACHeader->wSeqCtl >> 4);
-            pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
+            pDevice->sRxDFCB[ii].wSequence = (pMACHeader->seq_ctrl >> 4);
+            pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->seq_ctrl & 0x000F);
            memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]),
-                  &(pMACHeader->abyAddr2[0]),
+                  &(pMACHeader->addr2[0]),
                   ETH_ALEN);
             return(ii);
         }
@@ -165,7 +155,6 @@ unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice,
     return(pDevice->cbDFCB);
 }
 
-
 /*
  * Description:
  *      Handle received fragment packet
@@ -182,12 +171,10 @@ unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice,
  * Return Value: true if it is valid fragment packet and we have resource to defragment; otherwise false
  *
  */
-bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader,
-       unsigned int cbFrameLength, bool bWEP, bool bExtIV)
+bool WCTLbHandleFragment(struct vnt_private *pDevice, struct ieee80211_hdr *pMACHeader,        unsigned int cbFrameLength, bool bWEP, bool bExtIV)
 {
        unsigned int uHeaderSize;
 
-
     if (bWEP == true) {
         uHeaderSize = 28;
         if (bExtIV)
@@ -203,8 +190,8 @@ bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader,
         if (pDevice->uCurrentDFCBIdx < pDevice->cbDFCB) {
             // duplicate, we must flush previous DCB
             pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].uLifetime = pDevice->dwMaxReceiveLifetime;
-            pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence = (pMACHeader->wSeqCtl >> 4);
-            pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
+            pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence = (pMACHeader->seq_ctrl >> 4);
+            pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum = (pMACHeader->seq_ctrl & 0x000F);
         }
         else {
             pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader);
@@ -213,8 +200,8 @@ bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader,
             }
         }
         // reserve 8 byte to match MAC RX Buffer
-        pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (PBYTE) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 8);
-//        pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (PBYTE) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4);
+        pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (u8 *) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 8);
+//        pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (u8 *) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4);
         memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, pMACHeader, cbFrameLength);
         pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength = cbFrameLength;
         pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength;
@@ -225,11 +212,11 @@ bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader,
     else {
         pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
         if (pDevice->uCurrentDFCBIdx != pDevice->cbDFCB) {
-            if ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence == (pMACHeader->wSeqCtl >> 4)) &&
-                (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum == (pMACHeader->wSeqCtl & 0x000F)) &&
+            if ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence == (pMACHeader->seq_ctrl >> 4)) &&
+                (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum == (pMACHeader->seq_ctrl & 0x000F)) &&
                 ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength + cbFrameLength - uHeaderSize) < 2346)) {
 
-                memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, ((PBYTE) (pMACHeader) + uHeaderSize), (cbFrameLength - uHeaderSize));
+                memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, ((u8 *) (pMACHeader) + uHeaderSize), (cbFrameLength - uHeaderSize));
                 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength += (cbFrameLength - uHeaderSize);
                 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += (cbFrameLength - uHeaderSize);
                 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
@@ -256,4 +243,3 @@ bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader,
     }
 }
 
-
index 1b21e32e99e5aff63f095d00833b5d6e800e9ee8..14cb41177045d2064579a45f0d027027016a8e2b 100644 (file)
 #ifndef __WCTL_H__
 #define __WCTL_H__
 
-#include "ttype.h"
 #include "tether.h"
 #include "device.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
 #define IS_TYPE_DATA(pMACHeader)                                                        \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_DATA)
+    ((((struct ieee80211_hdr *) pMACHeader)->frame_control & TYPE_802_11_MASK) == TYPE_802_11_DATA)
 
 #define IS_TYPE_MGMT(pMACHeader)                                                        \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_MGMT)
+    ((((struct ieee80211_hdr *) pMACHeader)->frame_control & TYPE_802_11_MASK) == TYPE_802_11_MGMT)
 
 #define IS_TYPE_CONTROL(pMACHeader)                                                     \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_CTL)
+    ((((struct ieee80211_hdr *) pMACHeader)->frame_control & TYPE_802_11_MASK) == TYPE_802_11_CTL)
 
 #define IS_FC_MOREDATA(pMACHeader)                                                      \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREDATA) == FC_MOREDATA)
+    ((((struct ieee80211_hdr *) pMACHeader)->frame_control & FC_MOREDATA) == FC_MOREDATA)
 
 #define IS_FC_POWERMGT(pMACHeader)                                                      \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_POWERMGT) == FC_POWERMGT)
+    ((((struct ieee80211_hdr *) pMACHeader)->frame_control & FC_POWERMGT) == FC_POWERMGT)
 
 #define IS_FC_RETRY(pMACHeader)                                                         \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_RETRY) == FC_RETRY)
+    ((((struct ieee80211_hdr *) pMACHeader)->frame_control & FC_RETRY) == FC_RETRY)
 
 #define IS_FC_WEP(pMACHeader)                                                           \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_WEP) == FC_WEP)
+    ((((struct ieee80211_hdr *) pMACHeader)->frame_control & FC_WEP) == FC_WEP)
 
 #ifdef __BIG_ENDIAN
 
 #define IS_FRAGMENT_PKT(pMACHeader)                                                     \
-    (((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) != 0) |                  \
-     ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x0F00) != 0))
+    (((((struct ieee80211_hdr *) pMACHeader)->frame_control & FC_MOREFRAG) != 0) |                  \
+     ((((struct ieee80211_hdr *) pMACHeader)->seq_ctrl & 0x0F00) != 0))
 
 #define IS_FIRST_FRAGMENT_PKT(pMACHeader)                                               \
-    ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x0F00) == 0)
+    ((((struct ieee80211_hdr *) pMACHeader)->seq_ctrl & 0x0F00) == 0)
 
 #else
 
 #define IS_FRAGMENT_PKT(pMACHeader)                                                     \
-    (((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) != 0) |                  \
-     ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x000F) != 0))
+    (((((struct ieee80211_hdr *) pMACHeader)->frame_control & FC_MOREFRAG) != 0) |                  \
+     ((((struct ieee80211_hdr *) pMACHeader)->seq_ctrl & 0x000F) != 0))
 
 #define IS_FIRST_FRAGMENT_PKT(pMACHeader)                                               \
-    ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x000F) == 0)
+    ((((struct ieee80211_hdr *) pMACHeader)->seq_ctrl & 0x000F) == 0)
 
 #endif//#ifdef __BIG_ENDIAN
 
 #define IS_LAST_FRAGMENT_PKT(pMACHeader)                                                \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) == 0)
+    ((((struct ieee80211_hdr *) pMACHeader)->frame_control & FC_MOREFRAG) == 0)
 
 #define IS_CTL_PSPOLL(pMACHeader)                                                       \
-    ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL)
-
+    ((((struct ieee80211_hdr *) pMACHeader)->frame_control & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL)
 
 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) {   \
     if ((uVar) >= ((uModulo) - 1))                  \
         (uVar)++;                                   \
 }
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
-bool WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader);
-bool WCTLbHandleFragment(struct vnt_private *, PS802_11Header pMACHeader,
-       unsigned int cbFrameLength, bool bWEP, bool bExtIV);
-unsigned int WCTLuSearchDFCB(struct vnt_private *, PS802_11Header pMACHeader);
-unsigned int WCTLuInsertDFCB(struct vnt_private *, PS802_11Header pMACHeader);
+bool WCTLbIsDuplicate(PSCache pCache, struct ieee80211_hdr *pMACHeader);
+bool WCTLbHandleFragment(struct vnt_private *, struct ieee80211_hdr *pMACHeader, unsigned int cbFrameLength, bool bWEP, bool bExtIV);
+unsigned int WCTLuSearchDFCB(struct vnt_private *, struct ieee80211_hdr *pMACHeader);
+unsigned int WCTLuInsertDFCB(struct vnt_private *, struct ieee80211_hdr *pMACHeader);
 
 #endif /* __WCTL_H__ */
index 5dced0a4379779b6ce1b28c489c567c99379d320..6d1ff5eeafa9501bcf7f1a5f7bbb39a03fde7b2e 100644 (file)
 #include "control.h"
 #include "rndis.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
 static int          msglevel                =MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
 
-/*---------------------  Static Functions  --------------------------*/
-
 static int ChannelExceedZoneType(struct vnt_private *, u8 byCurrChannel);
 
 /* Association/diassociation functions */
@@ -158,7 +149,6 @@ static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
        u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates,
        PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
 
-
 /* Association response */
 static struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *,
        struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
@@ -182,25 +172,19 @@ static struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *,
 /* received status */
 static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus);
 
-
 static void s_vMgrSynchBSS(struct vnt_private *, u32 uBSSMode,
        PKnownBSS pCurr, PCMD_STATUS  pStatus);
 
-
 static bool
 s_bCipherMatch (
      PKnownBSS                        pBSSNode,
      NDIS_802_11_ENCRYPTION_STATUS    EncStatus,
-     PBYTE                           pbyCCSPK,
-     PBYTE                           pbyCCSGK
+     u8 *                           pbyCCSPK,
+     u8 *                           pbyCCSGK
     );
 
 static void Encyption_Rebuild(struct vnt_private *, PKnownBSS pCurr);
 
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 /*+
  *
  * Routine Description:
@@ -216,7 +200,6 @@ void vMgrObjectInit(struct vnt_private *pDevice)
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
        int ii;
 
-
     pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
     pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
     pMgmt->uCurrChannel = pDevice->uChannel;
@@ -274,7 +257,6 @@ void vMgrAssocBeginSta(struct vnt_private *pDevice,
 {
        struct vnt_tx_mgmt *pTxPacket;
 
-
     pMgmt->wCurrCapInfo = 0;
     pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
     if (pDevice->bEncryptionEnable) {
@@ -329,7 +311,6 @@ void vMgrAssocBeginSta(struct vnt_private *pDevice,
     return ;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -359,7 +340,6 @@ void vMgrReAssocBeginSta(struct vnt_private *pDevice,
     if (pMgmt->wListenInterval == 0)
         pMgmt->wListenInterval = 1;    // at least one.
 
-
     // ERP Phy (802.11g) should support short preamble.
     if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
         pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
@@ -374,7 +354,6 @@ void vMgrReAssocBeginSta(struct vnt_private *pDevice,
     if (pMgmt->b11hEnable == true)
         pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
 
-
     pTxPacket = s_MgrMakeReAssocRequest
                 (
                   pDevice,
@@ -398,7 +377,6 @@ void vMgrReAssocBeginSta(struct vnt_private *pDevice,
         }
     }
 
-
     return ;
 }
 
@@ -426,7 +404,7 @@ void vMgrDisassocBeginSta(struct vnt_private *pDevice,
                + sizeof(struct vnt_tx_mgmt));
 
     // Setup the sFrame structure
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_DISASSOC_FR_MAXLEN;
 
     // format fixed field frame structure
@@ -458,8 +436,6 @@ void vMgrDisassocBeginSta(struct vnt_private *pDevice,
     return;
 }
 
-
-
 /*+
  *
  * Routine Description:(AP function)
@@ -483,7 +459,6 @@ static void s_vMgrRxAssocRequest(struct vnt_private *pDevice,
        u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
        u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
 
-
     if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
         return;
     //  node index not found
@@ -496,7 +471,7 @@ static void s_vMgrRxAssocRequest(struct vnt_private *pDevice,
     memset(abyCurrSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
     memset(abyCurrExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
     sFrame.len = pRxPacket->cbMPDULen;
-    sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
 
     vMgrDecodeAssocRequest(&sFrame);
 
@@ -523,7 +498,6 @@ static void s_vMgrRxAssocRequest(struct vnt_private *pDevice,
             abyCurrExtSuppRates[1] = 0;
         }
 
-
        RATEvParseMaxRate((void *)pDevice,
                            (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
                            (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
@@ -543,9 +517,9 @@ static void s_vMgrRxAssocRequest(struct vnt_private *pDevice,
                 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
         pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
                 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
-        pMgmt->sNodeDBTable[uNodeIndex].wAID = (WORD)uNodeIndex;
+        pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)uNodeIndex;
         wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
-        wAssocAID = (WORD)uNodeIndex;
+        wAssocAID = (u16)uNodeIndex;
         // check if ERP support
         if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
            pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
@@ -572,7 +546,6 @@ static void s_vMgrRxAssocRequest(struct vnt_private *pDevice,
                    pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
     }
 
-
     // assoc response reply..
     pTxPacket = s_MgrMakeAssocResponse
                 (
@@ -604,7 +577,6 @@ static void s_vMgrRxAssocRequest(struct vnt_private *pDevice,
     return;
 }
 
-
 /*+
  *
  * Description:(AP function)
@@ -643,7 +615,7 @@ static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice,
     //decode the frame
     memset(&sFrame, 0, sizeof(WLAN_FR_REASSOCREQ));
     sFrame.len = pRxPacket->cbMPDULen;
-    sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
     vMgrDecodeReassocRequest(&sFrame);
 
     if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
@@ -671,7 +643,6 @@ static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice,
             abyCurrExtSuppRates[1] = 0;
         }
 
-
        RATEvParseMaxRate((void *)pDevice,
                           (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
                           (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
@@ -691,9 +662,9 @@ static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice,
                 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
         pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
                 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
-        pMgmt->sNodeDBTable[uNodeIndex].wAID = (WORD)uNodeIndex;
+        pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)uNodeIndex;
         wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
-        wAssocAID = (WORD)uNodeIndex;
+        wAssocAID = (u16)uNodeIndex;
 
         // if suppurt ERP
         if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
@@ -722,7 +693,6 @@ static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice,
 
     }
 
-
     // assoc response reply..
     pTxPacket = s_MgrMakeReAssocResponse
                 (
@@ -752,7 +722,6 @@ static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice,
     return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -771,13 +740,11 @@ static void s_vMgrRxAssocResponse(struct vnt_private *pDevice,
        PWLAN_IE_SSID   pItemSSID;
        u8 *pbyIEs;
 
-
-
     if (pMgmt->eCurrState == WMAC_STATE_ASSOCPENDING ||
          pMgmt->eCurrState == WMAC_STATE_ASSOC) {
 
         sFrame.len = pRxPacket->cbMPDULen;
-        sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
+        sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
         // decode the frame
         vMgrDecodeAssocResponse(&sFrame);
        if ((sFrame.pwCapInfo == NULL)
@@ -820,7 +787,7 @@ static void s_vMgrRxAssocResponse(struct vnt_private *pDevice,
 
        //if(pDevice->bWPASuppWextEnabled == true)
           {
-               BYTE buf[512];
+               u8 buf[512];
                size_t len;
                union iwreq_data  wrqu;
                int we_event;
@@ -906,7 +873,7 @@ void vMgrAuthenBeginSta(struct vnt_private *pDevice,
                + WLAN_AUTHEN_FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
                + sizeof(struct vnt_tx_mgmt));
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
     vMgrEncodeAuthen(&sFrame);
     /* insert values */
@@ -960,7 +927,7 @@ void vMgrDeAuthenBeginSta(struct vnt_private *pDevice,
                + WLAN_DEAUTHEN_FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
                + sizeof(struct vnt_tx_mgmt));
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
     vMgrEncodeDeauthen(&sFrame);
     /* insert values */
@@ -984,11 +951,9 @@ void vMgrDeAuthenBeginSta(struct vnt_private *pDevice,
         *pStatus = CMD_STATUS_SUCCESS;
     }
 
-
     return ;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -1012,7 +977,7 @@ static void s_vMgrRxAuthentication(struct vnt_private *pDevice,
 
     // decode the frame
     sFrame.len = pRxPacket->cbMPDULen;
-    sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
     vMgrDecodeAuthen(&sFrame);
     switch (cpu_to_le16((*(sFrame.pwAuthSequence )))){
         case 1:
@@ -1037,8 +1002,6 @@ static void s_vMgrRxAuthentication(struct vnt_private *pDevice,
     return;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -1051,7 +1014,6 @@ static void s_vMgrRxAuthentication(struct vnt_private *pDevice,
  *
 -*/
 
-
 static void s_vMgrRxAuthenSequence_1(struct vnt_private *pDevice,
        struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
 {
@@ -1082,7 +1044,7 @@ static void s_vMgrRxAuthenSequence_1(struct vnt_private *pDevice,
                + WLAN_AUTHEN_FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
                + sizeof(struct vnt_tx_mgmt));
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
     // format buffer structure
     vMgrEncodeAuthen(&sFrame);
@@ -1142,8 +1104,6 @@ static void s_vMgrRxAuthenSequence_1(struct vnt_private *pDevice,
     return;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -1162,7 +1122,6 @@ static void s_vMgrRxAuthenSequence_2(struct vnt_private *pDevice,
        WLAN_FR_AUTHEN sFrame;
        struct vnt_tx_mgmt *pTxPacket = NULL;
 
-
     switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm))))
     {
         case WLAN_AUTH_ALG_OPENSYSTEM:
@@ -1193,7 +1152,7 @@ static void s_vMgrRxAuthenSequence_2(struct vnt_private *pDevice,
                        pTxPacket->p80211Header
                                = (PUWLAN_80211HDR)((u8 *)pTxPacket
                                        + sizeof(struct vnt_tx_mgmt));
-                sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+                sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
                 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
                 // format buffer structure
                 vMgrEncodeAuthen(&sFrame);
@@ -1241,8 +1200,6 @@ static void s_vMgrRxAuthenSequence_2(struct vnt_private *pDevice,
     return;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -1297,7 +1254,7 @@ reply:
                + WLAN_AUTHEN_FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
                + sizeof(struct vnt_tx_mgmt));
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
     // format buffer structure
     vMgrEncodeAuthen(&sFrame);
@@ -1329,8 +1286,6 @@ reply:
 
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -1385,7 +1340,7 @@ static void s_vMgrRxDisassociation(struct vnt_private *pDevice,
         // if is acting an AP..
         // a STA is leaving this BSS..
         sFrame.len = pRxPacket->cbMPDULen;
-        sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
+        sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
         if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
             BSSvRemoveOneNode(pDevice, uNodeIndex);
         }
@@ -1395,7 +1350,7 @@ static void s_vMgrRxDisassociation(struct vnt_private *pDevice,
     }
     else if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ){
         sFrame.len = pRxPacket->cbMPDULen;
-        sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
+        sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
         vMgrDecodeDisassociation(&sFrame);
         DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason)));
 
@@ -1430,7 +1385,6 @@ static void s_vMgrRxDisassociation(struct vnt_private *pDevice,
     return;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -1448,13 +1402,12 @@ static void s_vMgrRxDeauthentication(struct vnt_private *pDevice,
        WLAN_FR_DEAUTHEN sFrame;
        u32 uNodeIndex = 0;
 
-
     if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
         //Todo:
         // if is acting an AP..
         // a STA is leaving this BSS..
         sFrame.len = pRxPacket->cbMPDULen;
-        sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
+        sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
         if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
             BSSvRemoveOneNode(pDevice, uNodeIndex);
         }
@@ -1465,7 +1418,7 @@ static void s_vMgrRxDeauthentication(struct vnt_private *pDevice,
     else {
         if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ) {
             sFrame.len = pRxPacket->cbMPDULen;
-            sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
+            sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
             vMgrDecodeDeauthen(&sFrame);
           pDevice->fWPA_Authened = false;
             DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO  "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason))));
@@ -1569,14 +1522,12 @@ static void s_vMgrRxBeacon(struct vnt_private *pDevice,
        int bChannelHit = false;
        u8 byOldPreambleType;
 
-
-
      if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
         return;
 
     memset(&sFrame, 0, sizeof(WLAN_FR_BEACON));
     sFrame.len = pRxPacket->cbMPDULen;
-    sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
 
     // decode the beacon frame
     vMgrDecodeBeacon(&sFrame);
@@ -1672,7 +1623,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
         return;
     }
 
-    if(byCurrChannel == (BYTE)pMgmt->uCurrChannel)
+    if(byCurrChannel == (u8)pMgmt->uCurrChannel)
        bIsChannelEqual = true;
 
     if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
@@ -1785,7 +1736,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
                     pDevice->byPreambleType = 0;
                 }
                 if (pDevice->byPreambleType != byOldPreambleType)
-                    CARDvSetRSPINF(pDevice, (BYTE)pDevice->byBBType);
+                    CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
             //
             // Basic Rate Set may change dynamically
             //
@@ -1839,7 +1790,6 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
        if (qwTSFOffset > TRIVIAL_SYNC_DIFFERENCE)
                bTSFLargeDiff = true;
 
-
     // if infra mode
     if (bIsAPBeacon == true) {
 
@@ -2009,8 +1959,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
                         pDevice->byPreambleType = 0;
                     }
                     if (pDevice->byPreambleType != byOldPreambleType)
-                        CARDvSetRSPINF(pDevice, (BYTE)pDevice->byBBType);
-
+                        CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
 
                      // MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
                      // set highest basic rate
@@ -2061,8 +2010,6 @@ void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus)
        u8 abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
        u16 wSuppRate;
 
-
-
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n");
 
     if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
@@ -2101,7 +2048,6 @@ void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus)
             pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
     }
 
-
     if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
         pMgmt->abyCurrSuppRates[1] = 8;
         pMgmt->abyCurrExtSuppRates[1] = 4;
@@ -2113,7 +2059,6 @@ void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus)
             pMgmt->abyCurrExtSuppRates[2+ii] =  abyOFDM_RATE[ii+4];
     }
 
-
     // Disable Protect Mode
     pDevice->bProtectMode = 0;
     MACvDisableProtectMD(pDevice);
@@ -2156,8 +2101,6 @@ void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus)
                       &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
                       &byTopCCKBasicRate, &byTopOFDMBasicRate);
 
-
-
     if (pDevice->byBBType == BB_TYPE_11A) {
         pDevice->bShortSlotTime = true;
     } else {
@@ -2221,7 +2164,6 @@ void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus)
         pMgmt->abyCurrBSSID[0] &= ~IEEE_ADDR_GROUP;
         pMgmt->abyCurrBSSID[0] |= IEEE_ADDR_UNIVERSAL;
 
-
                DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"Adhoc beacon created bssid:"
                        "%pM\n", pMgmt->abyCurrBSSID);
     }
@@ -2313,7 +2255,6 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
        u8 byTopOFDMBasicRate = RATE_1M;
        u8 bShortSlotTime = false;
 
-
     for (ii = 0; ii < MAX_BSS_NUM; ii++) {
         if (pMgmt->sBSSList[ii].bActive == true)
             break;
@@ -2411,9 +2352,9 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
                     if (pItemExtRates->len <= ii)
                         break;
                 }
-                pItemRates->len += (BYTE)ii;
+                pItemRates->len += (u8)ii;
                 if (pItemExtRates->len - ii > 0) {
-                    pItemExtRates->len -= (BYTE)ii;
+                    pItemExtRates->len -= (u8)ii;
                     for (uu = 0; uu < pItemExtRates->len; uu ++) {
                         pItemExtRates->abyRates[uu] = pItemExtRates->abyRates[uu + ii];
                     }
@@ -2466,7 +2407,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
                 pDevice->byPreambleType = 0;
             }
             // Change PreambleType must set RSPINF again
-            CARDvSetRSPINF(pDevice, (BYTE)pDevice->byBBType);
+            CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
 
             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join ESS\n");
 
@@ -2519,7 +2460,6 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
             pMgmt->eCurrState = WMAC_STATE_IDLE;
         };
 
-
      }
      else {
         // ad-hoc mode BSS
@@ -2559,7 +2499,6 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
             // TODO: check if CapInfo privacy on, but we don't..
             pMgmt->uCurrChannel = pCurr->uChannel;
 
-
             // Parse Support Rate IE
             pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
             pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
@@ -2597,7 +2536,7 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
                 pDevice->byPreambleType = 0;
             }
             // Change PreambleType must set RSPINF again
-            CARDvSetRSPINF(pDevice, (BYTE)pDevice->byBBType);
+            CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
 
             // Prepare beacon
                bMgrPrepareBeaconToSend((void *) pDevice, pMgmt);
@@ -2609,8 +2548,6 @@ void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
     return;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -2806,7 +2743,6 @@ static void Encyption_Rebuild(struct vnt_private *pDevice, PKnownBSS pCurr)
       return;
  }
 
-
 /*+
  *
  * Routine Description:
@@ -2828,7 +2764,6 @@ static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM)
        u16 wStartIndex = 0;
        u16 wEndIndex = 0;
 
-
     // Find size of partial virtual bitmap
     for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
         byMap = pMgmt->abyPSTxMap[ii];
@@ -2843,13 +2778,12 @@ static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM)
         if (byMap) {
             if (!bStartFound) {
                 bStartFound = true;
-                wStartIndex = (WORD)ii;
+                wStartIndex = (u16)ii;
             }
-            wEndIndex = (WORD)ii;
+            wEndIndex = (u16)ii;
         }
     }
 
-
     // Round start index down to nearest even number
     wStartIndex &=  ~BIT0;
 
@@ -2876,7 +2810,6 @@ static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM)
     pTIM->byVirtBitMap[0]  &= ~BIT0;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -2898,7 +2831,6 @@ static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
        WLAN_FR_BEACON sFrame;
        u8 abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
-
        /* prepare beacon frame */
        pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
        memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
@@ -2906,7 +2838,7 @@ static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
                + sizeof(struct vnt_tx_mgmt));
     // Setup the sFrame structure.
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_BEACON_FR_MAXLEN;
     vMgrEncodeBeacon(&sFrame);
     // Setup the header
@@ -2917,7 +2849,7 @@ static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
         ));
 
     if (pDevice->bEnablePSMode) {
-        sFrame.pHdr->sA3.wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_PWRMGT(1));
+        sFrame.pHdr->sA3.wFrameCtl |= cpu_to_le16((u16)WLAN_SET_FC_PWRMGT(1));
     }
 
     memcpy( sFrame.pHdr->sA3.abyAddr1, abyBroadcastAddr, WLAN_ADDR_LEN);
@@ -2945,7 +2877,7 @@ static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
         sFrame.len += (1) + WLAN_IEHDR_LEN;
         sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
         sFrame.pDSParms->len = 1;
-        sFrame.pDSParms->byCurrChannel = (BYTE)uCurrChannel;
+        sFrame.pDSParms->byCurrChannel = (u8)uCurrChannel;
     }
     // TIM field
     if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
@@ -2988,17 +2920,16 @@ static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
             // Pairwise Key Cipher Suite
             sFrame.pRSNWPA->wPKCount = 0;
             // Auth Key Management Suite
-            *((PWORD)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
+            *((u16 *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
             sFrame.pRSNWPA->len +=2;
 
             // RSN Capabilites
-            *((PWORD)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
+            *((u16 *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
             sFrame.pRSNWPA->len +=2;
             sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
         }
     }
 
-
     if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
         sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
         sFrame.len += 1 + WLAN_IEHDR_LEN;
@@ -3038,10 +2969,6 @@ static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
     return pTxPacket;
 }
 
-
-
-
-
 /*+
  *
  * Routine Description:
@@ -3053,9 +2980,6 @@ static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
  *
 -*/
 
-
-
-
 struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice,
        struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
        u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr,
@@ -3066,14 +2990,13 @@ struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice,
        struct vnt_tx_mgmt *pTxPacket = NULL;
        WLAN_FR_PROBERESP sFrame;
 
-
        pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
        memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
                + WLAN_PROBERESP_FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
                + sizeof(struct vnt_tx_mgmt));
     // Setup the sFrame structure.
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_PROBERESP_FR_MAXLEN;
     vMgrEncodeProbeResponse(&sFrame);
     // Setup the header
@@ -3089,7 +3012,7 @@ struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice,
     *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
 
     if (byPHYType == BB_TYPE_11B) {
-        *sFrame.pwCapInfo &= cpu_to_le16((WORD)~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)));
+        *sFrame.pwCapInfo &= cpu_to_le16((u16)~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)));
     }
 
     // Copy SSID
@@ -3114,7 +3037,7 @@ struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice,
         sFrame.len += (1) + WLAN_IEHDR_LEN;
         sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
         sFrame.pDSParms->len = 1;
-        sFrame.pDSParms->byCurrChannel = (BYTE)uCurrChannel;
+        sFrame.pDSParms->byCurrChannel = (u8)uCurrChannel;
     }
 
     if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
@@ -3166,8 +3089,6 @@ struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice,
     return pTxPacket;
 }
 
-
-
 /*+
  *
  * Routine Description:
@@ -3179,7 +3100,6 @@ struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice,
  *
 -*/
 
-
 struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
        struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
        u16 wListenInterval,
@@ -3192,14 +3112,13 @@ struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
        u8 *pbyIEs;
        u8 *pbyRSN;
 
-
        pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
        memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
                + WLAN_ASSOCREQ_FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
                + sizeof(struct vnt_tx_mgmt));
     // Setup the sFrame structure.
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN;
     // format fixed field frame structure
     vMgrEncodeAssocRequest(&sFrame);
@@ -3247,7 +3166,6 @@ struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
     memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
     pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
 
-
     if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
          (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
          (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
@@ -3287,7 +3205,7 @@ struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
             sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
         }
         // Auth Key Management Suite
-        pbyRSN = (PBYTE)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
+        pbyRSN = (u8 *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
         *pbyRSN++=0x01;
         *pbyRSN++=0x00;
         *pbyRSN++=0x00;
@@ -3322,7 +3240,7 @@ struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
                 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
                (pMgmt->pCurrBSS != NULL)) {
        unsigned int ii;
-        PWORD               pwPMKID;
+        u16 *               pwPMKID;
 
         // WPA IE
         sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
@@ -3387,7 +3305,7 @@ struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
         if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
             // RSN PMKID
             pbyRSN = &sFrame.pRSN->abyRSN[18];
-            pwPMKID = (PWORD)pbyRSN; // Point to PMKID count
+            pwPMKID = (u16 *)pbyRSN; // Point to PMKID count
             *pwPMKID = 0;            // Initialize PMKID count
             pbyRSN += 2;             // Point to PMKID list
        for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
@@ -3413,20 +3331,12 @@ struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
         pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
     }
 
-
     // Adjust the length fields
     pTxPacket->cbMPDULen = sFrame.len;
     pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
     return pTxPacket;
 }
 
-
-
-
-
-
-
-
 /*+
  *
  * Routine Description:
@@ -3438,7 +3348,6 @@ struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
  *
 -*/
 
-
 struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice,
        struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
        u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
@@ -3450,14 +3359,13 @@ struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice,
        u8 *pbyIEs;
        u8 *pbyRSN;
 
-
        pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
        memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
                + WLAN_REASSOCREQ_FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
                + sizeof(struct vnt_tx_mgmt));
     /* Setup the sFrame structure. */
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN;
 
     // format fixed field frame structure
@@ -3546,7 +3454,7 @@ struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice,
             sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
         }
         // Auth Key Management Suite
-        pbyRSN = (PBYTE)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
+        pbyRSN = (u8 *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
         *pbyRSN++=0x01;
         *pbyRSN++=0x00;
         *pbyRSN++=0x00;
@@ -3578,7 +3486,7 @@ struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice,
                 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
                (pMgmt->pCurrBSS != NULL)) {
        unsigned int ii;
-        PWORD               pwPMKID;
+        u16 *               pwPMKID;
 
         /* WPA IE */
         sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
@@ -3643,7 +3551,7 @@ struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice,
         if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
             // RSN PMKID
             pbyRSN = &sFrame.pRSN->abyRSN[18];
-            pwPMKID = (PWORD)pbyRSN; // Point to PMKID count
+            pwPMKID = (u16 *)pbyRSN; // Point to PMKID count
             *pwPMKID = 0;            // Initialize PMKID count
             pbyRSN += 2;             // Point to PMKID list
             for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
@@ -3669,8 +3577,6 @@ struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice,
         pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
     }
 
-
-
     /* Adjust the length fields */
     pTxPacket->cbMPDULen = sFrame.len;
     pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
@@ -3697,14 +3603,13 @@ struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *pDevice,
        struct vnt_tx_mgmt *pTxPacket = NULL;
        WLAN_FR_ASSOCRESP   sFrame;
 
-
        pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
        memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
                + WLAN_ASSOCREQ_FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
                + sizeof(struct vnt_tx_mgmt));
     // Setup the sFrame structure
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
     vMgrEncodeAssocResponse(&sFrame);
     // Setup the header
@@ -3719,7 +3624,7 @@ struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *pDevice,
 
     *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
     *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
-    *sFrame.pwAid = cpu_to_le16((WORD)(wAssocAID | BIT14 | BIT15));
+    *sFrame.pwAid = cpu_to_le16((u16)(wAssocAID | BIT14 | BIT15));
 
     // Copy the rate set
     sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
@@ -3745,7 +3650,6 @@ struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *pDevice,
     return pTxPacket;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -3757,7 +3661,6 @@ struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *pDevice,
  *
 -*/
 
-
 struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *pDevice,
        struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
        u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
@@ -3766,14 +3669,13 @@ struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *pDevice,
        struct vnt_tx_mgmt *pTxPacket = NULL;
        WLAN_FR_REASSOCRESP sFrame;
 
-
        pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
        memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
                + WLAN_ASSOCREQ_FR_MAXLEN);
        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
                + sizeof(struct vnt_tx_mgmt));
     // Setup the sFrame structure
-    sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
     sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
     vMgrEncodeReassocResponse(&sFrame);
     // Setup the header
@@ -3788,7 +3690,7 @@ struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *pDevice,
 
     *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
     *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
-    *sFrame.pwAid = cpu_to_le16((WORD)(wAssocAID | BIT14 | BIT15));
+    *sFrame.pwAid = cpu_to_le16((u16)(wAssocAID | BIT14 | BIT15));
 
     // Copy the rate set
     sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
@@ -3814,7 +3716,6 @@ struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *pDevice,
     return pTxPacket;
 }
 
-
 /*+
  *
  * Routine Description:
@@ -3835,11 +3736,10 @@ static void s_vMgrRxProbeResponse(struct vnt_private *pDevice,
        ERPObject sERP;
        int bChannelHit = true;
 
-
     memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP));
     // decode the frame
     sFrame.len = pRxPacket->cbMPDULen;
-    sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
+    sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
     vMgrDecodeProbeResponse(&sFrame);
 
     if ((sFrame.pqwTimestamp == NULL)
@@ -3857,7 +3757,6 @@ static void s_vMgrRxProbeResponse(struct vnt_private *pDevice,
     if(sFrame.pSSID->len == 0)
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx Probe resp: SSID len = 0 \n");
 
-
     //{{ RobertYu:20050201, 11a  byCurrChannel != sFrame.pDSParms->byCurrChannel mapping
     if( byCurrChannel > CB_MAX_CHANNEL_24G )
     {
@@ -3892,7 +3791,6 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
         sERP.byERP = 0;
     }
 
-
     // update or insert the bss
     pBSSList = BSSpAddrIsInBSSList((void *) pDevice,
                                   sFrame.pHdr->sA3.abyAddr3,
@@ -3952,7 +3850,6 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
  *
 -*/
 
-
 static void s_vMgrRxProbeRequest(struct vnt_private *pDevice,
        struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
 {
@@ -3969,7 +3866,7 @@ static void s_vMgrRxProbeRequest(struct vnt_private *pDevice,
         memset(&sFrame, 0, sizeof(WLAN_FR_PROBEREQ));
         // decode the frame
         sFrame.len = pRxPacket->cbMPDULen;
-        sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
+        sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
         vMgrDecodeProbeRequest(&sFrame);
 /*
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request rx:MAC addr:%pM\n",
@@ -4000,7 +3897,7 @@ static void s_vMgrRxProbeRequest(struct vnt_private *pDevice,
                       0,
                       sFrame.pHdr->sA3.abyAddr2,
                       (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
-                      (PBYTE)pMgmt->abyCurrBSSID,
+                      (u8 *)pMgmt->abyCurrBSSID,
                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
                        byPHYType
@@ -4042,7 +3939,6 @@ void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt,
        NODE_STATE eNodeState = 0;
        CMD_STATUS Status;
 
-
     if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
         if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
             eNodeState = pMgmt->sNodeDBTable[uNodeIndex].eNodeState;
@@ -4199,7 +4095,7 @@ int bMgrPrepareBeaconToSend(struct vnt_private *pDevice,
                   pMgmt->uCurrChannel,
                   pMgmt->wCurrATIMWindow, //0,
                   (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
-                  (PBYTE)pMgmt->abyCurrBSSID,
+                  (u8 *)pMgmt->abyCurrBSSID,
                   (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
                   (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
                 );
@@ -4214,9 +4110,6 @@ int bMgrPrepareBeaconToSend(struct vnt_private *pDevice,
     return true;
 }
 
-
-
-
 /*+
  *
  * Routine Description:
@@ -4308,8 +4201,6 @@ int bAdd_PMKID_Candidate(struct vnt_private *pDevice, u8 *pbyBSSID,
     if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST)
         return false;
 
-
-
     // Update Old Candidate
     for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
        pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
@@ -4368,12 +4259,12 @@ static bool
 s_bCipherMatch (
      PKnownBSS                        pBSSNode,
      NDIS_802_11_ENCRYPTION_STATUS    EncStatus,
-     PBYTE                           pbyCCSPK,
-     PBYTE                           pbyCCSGK
+     u8 *                           pbyCCSPK,
+     u8 *                           pbyCCSGK
     )
 {
-    BYTE byMulticastCipher = KEY_CTL_INVALID;
-    BYTE byCipherMask = 0x00;
+    u8 byMulticastCipher = KEY_CTL_INVALID;
+    u8 byCipherMask = 0x00;
     int i;
 
     if (pBSSNode == NULL)
@@ -4515,4 +4406,3 @@ s_bCipherMatch (
     return true;
 }
 
-
index 83aed45f68a3c3c41470eb0ad3e44a6c7753245a..5424c7f820ade84f57ac0a1af70fcc195b246cea 100644 (file)
@@ -34,7 +34,6 @@
 #ifndef __WMGR_H__
 #define __WMGR_H__
 
-#include "ttype.h"
 #include "80211mgr.h"
 #include "80211hdr.h"
 #include "wcmd.h"
 #include "wpa2.h"
 #include "card.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
-
-
 // Scan time
 #define PROBE_DELAY                  100  // (us)
 #define SWITCH_CHANNEL_DELAY         200 // (us)
@@ -57,7 +52,6 @@
 #define WCMD_ACTIVE_SCAN_TIME   20 //(ms)
 #define WCMD_PASSIVE_SCAN_TIME  100 //(ms)
 
-
 #define DEFAULT_MSDU_LIFETIME           512  // ms
 #define DEFAULT_MSDU_LIFETIME_RES_64us  8000 // 64us
 
@@ -66,7 +60,6 @@
 
 #define MAKE_BEACON_RESERVED            10  //(us)
 
-
 #define TIM_MULTICAST_MASK           0x01
 #define TIM_BITMAPOFFSET_MASK        0xFE
 #define DEFAULT_DTIM_PERIOD             1
 
 #define DEFAULT_IBSS_CHANNEL            6  //2.4G
 
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Types  ------------------------------*/
 //mike define: make timer  to expire after desired times
 #define timer_expire(timer, next_tick) mod_timer(&timer, RUN_AT(next_tick))
 
 typedef void (*TimerFunction)(unsigned long);
 
-
 //+++ NDIS related
 
 typedef u8 NDIS_802_11_MAC_ADDRESS[ETH_ALEN];
@@ -117,8 +103,6 @@ typedef struct _NDIS_802_11_ASSOCIATION_INFORMATION
        u32 OffsetResponseIEs;
 } NDIS_802_11_ASSOCIATION_INFORMATION, *PNDIS_802_11_ASSOCIATION_INFORMATION;
 
-
-
 typedef struct tagSAssocInfo {
        NDIS_802_11_ASSOCIATION_INFORMATION AssocInfo;
        u8 abyIEs[WLAN_BEACON_FR_MAXLEN+WLAN_BEACON_FR_MAXLEN];
@@ -127,9 +111,6 @@ typedef struct tagSAssocInfo {
        u8 abyReqIEs[WLAN_BEACON_FR_MAXLEN];
 } SAssocInfo, *PSAssocInfo;
 
-
-
-
 typedef enum tagWMAC_AUTHENTICATION_MODE {
 
     WMAC_AUTH_OPEN,
@@ -143,8 +124,6 @@ typedef enum tagWMAC_AUTHENTICATION_MODE {
     WMAC_AUTH_MAX       // Not a real mode, defined as upper bound
 } WMAC_AUTHENTICATION_MODE, *PWMAC_AUTHENTICATION_MODE;
 
-
-
 // Pre-configured Mode (from XP)
 
 typedef enum tagWMAC_CONFIG_MODE {
@@ -155,7 +134,6 @@ typedef enum tagWMAC_CONFIG_MODE {
 
 } WMAC_CONFIG_MODE, *PWMAC_CONFIG_MODE;
 
-
 typedef enum tagWMAC_SCAN_TYPE {
 
     WMAC_SCAN_ACTIVE,
@@ -164,7 +142,6 @@ typedef enum tagWMAC_SCAN_TYPE {
 
 } WMAC_SCAN_TYPE, *PWMAC_SCAN_TYPE;
 
-
 typedef enum tagWMAC_SCAN_STATE {
 
     WMAC_NO_SCANNING,
@@ -173,8 +150,6 @@ typedef enum tagWMAC_SCAN_STATE {
 
 } WMAC_SCAN_STATE, *PWMAC_SCAN_STATE;
 
-
-
 // Notes:
 // Basic Service Set state explained as following:
 // WMAC_STATE_IDLE          : no BSS is selected (Adhoc or Infra)
@@ -207,7 +182,6 @@ typedef enum tagWMAC_CURRENT_MODE {
 
 } WMAC_CURRENT_MODE, *PWMAC_CURRENT_MODE;
 
-
 typedef enum tagWMAC_POWER_MODE {
 
     WMAC_POWER_CAM,
@@ -216,8 +190,6 @@ typedef enum tagWMAC_POWER_MODE {
 
 } WMAC_POWER_MODE, *PWMAC_POWER_MODE;
 
-
-
 /* Tx Management Packet descriptor */
 struct vnt_tx_mgmt {
        PUWLAN_80211HDR p80211Header;
@@ -225,7 +197,6 @@ struct vnt_tx_mgmt {
        u32 cbPayloadLen;
 };
 
-
 /* Rx Management Packet descriptor */
 struct vnt_rx_mgmt {
        PUWLAN_80211HDR p80211Header;
@@ -238,7 +209,6 @@ struct vnt_rx_mgmt {
        u8 byRxChannel;
 };
 
-
 struct vnt_manager {
        void *pAdapter;
 
@@ -340,7 +310,6 @@ struct vnt_manager {
        u8 byMgmtPacketPool[sizeof(struct vnt_tx_mgmt)
                + WLAN_A3FR_MAXLEN];
 
-
        /* One second callback timer */
        struct timer_list sTimerSecondCallback;
 
@@ -384,10 +353,6 @@ struct vnt_manager {
 
 };
 
-/*---------------------  Export Macros ------------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 void vMgrObjectInit(struct vnt_private *pDevice);
 
 void vMgrAssocBeginSta(struct vnt_private *pDevice,
index f037be3aa1641f750f21489e339788bbcdc4dc92..01db4e7154da9b39f29ef399a7f012bc799620e5 100644 (file)
@@ -32,7 +32,6 @@
  *
  */
 
-#include "ttype.h"
 #include "tmacro.h"
 #include "tether.h"
 #include "device.h"
 #include "wpa.h"
 #include "80211mgr.h"
 
-/*---------------------  Static Variables  --------------------------*/
 static int          msglevel                =MSG_LEVEL_INFO;
 
-const BYTE abyOUI00[4] = { 0x00, 0x50, 0xf2, 0x00 };
-const BYTE abyOUI01[4] = { 0x00, 0x50, 0xf2, 0x01 };
-const BYTE abyOUI02[4] = { 0x00, 0x50, 0xf2, 0x02 };
-const BYTE abyOUI03[4] = { 0x00, 0x50, 0xf2, 0x03 };
-const BYTE abyOUI04[4] = { 0x00, 0x50, 0xf2, 0x04 };
-const BYTE abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 };
-
+const u8 abyOUI00[4] = { 0x00, 0x50, 0xf2, 0x00 };
+const u8 abyOUI01[4] = { 0x00, 0x50, 0xf2, 0x01 };
+const u8 abyOUI02[4] = { 0x00, 0x50, 0xf2, 0x02 };
+const u8 abyOUI03[4] = { 0x00, 0x50, 0xf2, 0x03 };
+const u8 abyOUI04[4] = { 0x00, 0x50, 0xf2, 0x04 };
+const u8 abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 };
 
 /*+
  *
@@ -88,7 +85,6 @@ WPA_ClearRSN(
     pBSSList->bWPAValid = false;
 }
 
-
 /*+
  *
  * Description:
@@ -112,7 +108,7 @@ WPA_ParseRSN(
 {
     PWLAN_IE_RSN_AUTH  pIE_RSN_Auth = NULL;
     int                i, j, m, n = 0;
-    PBYTE              pbyCaps;
+    u8 *              pbyCaps;
 
     WPA_ClearRSN(pBSSList);
 
@@ -167,7 +163,7 @@ WPA_ParseRSN(
                     break;
                 //DBG_PRN_GRP14(("abyPKType[%d]: %X\n", j-1, pBSSList->abyPKType[j-1]));
             } //for
-            pBSSList->wPKCount = (WORD)j;
+            pBSSList->wPKCount = (u16)j;
             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d\n", pBSSList->wPKCount);
         }
 
@@ -197,7 +193,7 @@ WPA_ParseRSN(
                 //DBG_PRN_GRP14(("abyAuthType[%d]: %X\n", j-1, pBSSList->abyAuthType[j-1]));
             }
             if(j > 0)
-                pBSSList->wAuthCount = (WORD)j;
+                pBSSList->wAuthCount = (u16)j;
             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d\n", pBSSList->wAuthCount);
         }
 
@@ -209,11 +205,11 @@ WPA_ParseRSN(
             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+4+(m+n)*4: %d\n", 14+4+(m+n)*4);
 
             if(pRSN->len+2 >= 14+4+(m+n)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*n)+Cap(2)
-                pbyCaps = (PBYTE)pIE_RSN_Auth->AuthKSList[n].abyOUI;
+                pbyCaps = (u8 *)pIE_RSN_Auth->AuthKSList[n].abyOUI;
                 pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
                 pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
                 pBSSList->sRSNCapObj.bRSNCapExist = true;
-                pBSSList->sRSNCapObj.wRSNCap = *(PWORD)pbyCaps;
+                pBSSList->sRSNCapObj.wRSNCap = *(u16 *)pbyCaps;
                 //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps));
                 //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK));
                 //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx));
@@ -241,13 +237,13 @@ WPA_ParseRSN(
 -*/
 bool
 WPA_SearchRSN(
-    BYTE                byCmd,
-    BYTE                byEncrypt,
+    u8                byCmd,
+    u8                byEncrypt,
      PKnownBSS        pBSSList
     )
 {
     int ii;
-    BYTE byPKType = WPA_NONE;
+    u8 byPKType = WPA_NONE;
 
     if (pBSSList->bWPAValid == false)
         return false;
index 0369cbf32c49be807dd9b868a69af90faefd860e..2a724c064e591f837d56417b966d0363cb932582 100644 (file)
 #ifndef __WPA_H__
 #define __WPA_H__
 
-#include "ttype.h"
 #include "80211hdr.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
 #define WPA_NONE            0
 #define WPA_WEP40           1
 #define WPA_TKIP            2
 #define WPA_REPLAYBITSSHIFT 2
 #define WPA_REPLAYBITS      0x03
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Types  ------------------------------*/
-
-
-/*---------------------  Export Functions  --------------------------*/
-
 void
 WPA_ClearRSN(
      PKnownBSS        pBSSList
@@ -71,8 +59,8 @@ WPA_ParseRSN(
 
 bool
 WPA_SearchRSN(
-    BYTE                byCmd,
-    BYTE                byEncrypt,
+    u8                byCmd,
+    u8                byEncrypt,
      PKnownBSS        pBSSList
     );
 
index a89456a9137acab889d6d4afb86696f5c6a9dd7c..aa2216184345192dabe1e524c2779d809f6038d6 100644 (file)
 #include "device.h"
 #include "wpa2.h"
 
-/*---------------------  Static Definitions -------------------------*/
 static int          msglevel                =MSG_LEVEL_INFO;
 //static int          msglevel                =MSG_LEVEL_DEBUG;
-/*---------------------  Static Classes  ----------------------------*/
 
-/*---------------------  Static Variables  --------------------------*/
+const u8 abyOUIGK[4]      = { 0x00, 0x0F, 0xAC, 0x00 };
+const u8 abyOUIWEP40[4]   = { 0x00, 0x0F, 0xAC, 0x01 };
+const u8 abyOUIWEP104[4]  = { 0x00, 0x0F, 0xAC, 0x05 };
+const u8 abyOUITKIP[4]    = { 0x00, 0x0F, 0xAC, 0x02 };
+const u8 abyOUICCMP[4]    = { 0x00, 0x0F, 0xAC, 0x04 };
 
-const BYTE abyOUIGK[4]      = { 0x00, 0x0F, 0xAC, 0x00 };
-const BYTE abyOUIWEP40[4]   = { 0x00, 0x0F, 0xAC, 0x01 };
-const BYTE abyOUIWEP104[4]  = { 0x00, 0x0F, 0xAC, 0x05 };
-const BYTE abyOUITKIP[4]    = { 0x00, 0x0F, 0xAC, 0x02 };
-const BYTE abyOUICCMP[4]    = { 0x00, 0x0F, 0xAC, 0x04 };
-
-const BYTE abyOUI8021X[4]   = { 0x00, 0x0F, 0xAC, 0x01 };
-const BYTE abyOUIPSK[4]     = { 0x00, 0x0F, 0xAC, 0x02 };
-
-
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
+const u8 abyOUI8021X[4]   = { 0x00, 0x0F, 0xAC, 0x01 };
+const u8 abyOUIPSK[4]     = { 0x00, 0x0F, 0xAC, 0x02 };
 
 /*+
  *
@@ -113,8 +102,8 @@ WPA2vParseRSN (
     )
 {
     int                 i, j;
-    WORD                m = 0, n = 0;
-    PBYTE               pbyOUI;
+    u16                m = 0, n = 0;
+    u8 *               pbyOUI;
     bool                bUseGK = false;
 
     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA2_ParseRSN: [%d]\n", pRSN->len);
@@ -163,11 +152,11 @@ WPA2vParseRSN (
         }
 
         if (pRSN->len >= 8) { // ver(2) + GK(4) + PK count(2)
-            pBSSNode->wCSSPKCount = *((PWORD) &(pRSN->abyRSN[4]));
+            pBSSNode->wCSSPKCount = *((u16 *) &(pRSN->abyRSN[4]));
             j = 0;
             pbyOUI = &(pRSN->abyRSN[6]);
 
-            for (i = 0; (i < pBSSNode->wCSSPKCount) && (j < sizeof(pBSSNode->abyCSSPK)/sizeof(BYTE)); i++) {
+            for (i = 0; (i < pBSSNode->wCSSPKCount) && (j < sizeof(pBSSNode->abyCSSPK)/sizeof(u8)); i++) {
 
                 if (pRSN->len >= 8+i*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*i)
                     if ( !memcmp(pbyOUI, abyOUIGK, 4)) {
@@ -208,17 +197,17 @@ WPA2vParseRSN (
                 // invalid CSS, No valid PK.
                 return;
             }
-            pBSSNode->wCSSPKCount = (WORD)j;
+            pBSSNode->wCSSPKCount = (u16)j;
             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wCSSPKCount: %d\n", pBSSNode->wCSSPKCount);
         }
 
-        m = *((PWORD) &(pRSN->abyRSN[4]));
+        m = *((u16 *) &(pRSN->abyRSN[4]));
 
         if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2)
-            pBSSNode->wAKMSSAuthCount = *((PWORD) &(pRSN->abyRSN[6+4*m]));
+            pBSSNode->wAKMSSAuthCount = *((u16 *) &(pRSN->abyRSN[6+4*m]));
             j = 0;
             pbyOUI = &(pRSN->abyRSN[8+4*m]);
-            for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(BYTE)); i++) {
+            for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(u8)); i++) {
                 if (pRSN->len >= 10+(m+i)*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSS(2)+AKS(4*i)
                     if ( !memcmp(pbyOUI, abyOUI8021X, 4))
                         pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_802_1X;
@@ -231,134 +220,16 @@ WPA2vParseRSN (
                 } else
                     break;
             }
-            pBSSNode->wAKMSSAuthCount = (WORD)j;
+            pBSSNode->wAKMSSAuthCount = (u16)j;
             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAKMSSAuthCount: %d\n", pBSSNode->wAKMSSAuthCount);
 
-            n = *((PWORD) &(pRSN->abyRSN[6+4*m]));
+            n = *((u16 *) &(pRSN->abyRSN[6+4*m]));
             if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2)
                 pBSSNode->sRSNCapObj.bRSNCapExist = true;
-                pBSSNode->sRSNCapObj.wRSNCap = *((PWORD) &(pRSN->abyRSN[8+4*m+4*n]));
+                pBSSNode->sRSNCapObj.wRSNCap = *((u16 *) &(pRSN->abyRSN[8+4*m+4*n]));
             }
         }
         //ignore PMKID lists bcs only (Re)Assocrequest has this field
         pBSSNode->bWPA2Valid = true;
     }
 }
-
-
-/*+
- *
- * Description:
- *    Set WPA IEs
- *
- * Parameters:
- *  In:
- *      pMgmtHandle - Pointer to management object
- *  Out:
- *      pRSNIEs     - Pointer to the RSN IE to set.
- *
- * Return Value: length of IEs.
- *
--*/
-unsigned int WPA2uSetIEs(void *pMgmtHandle, PWLAN_IE_RSN pRSNIEs)
-{
-       struct vnt_manager *pMgmt = (struct vnt_manager *)pMgmtHandle;
-       u8 *pbyBuffer = NULL;
-       int ii = 0;
-       u16 *pwPMKID = NULL;
-
-       if (pRSNIEs == NULL)
-               return 0;
-
-    if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
-         (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
-        (pMgmt->pCurrBSS != NULL)) {
-        /* WPA2 IE */
-        pbyBuffer = (PBYTE) pRSNIEs;
-        pRSNIEs->byElementID = WLAN_EID_RSN;
-        pRSNIEs->len = 6; //Version(2)+GK(4)
-        pRSNIEs->wVersion = 1;
-        //Group Key Cipher Suite
-        pRSNIEs->abyRSN[0] = 0x00;
-        pRSNIEs->abyRSN[1] = 0x0F;
-        pRSNIEs->abyRSN[2] = 0xAC;
-        if (pMgmt->byCSSGK == KEY_CTL_WEP) {
-            pRSNIEs->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
-        } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
-            pRSNIEs->abyRSN[3] = WLAN_11i_CSS_TKIP;
-        } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
-            pRSNIEs->abyRSN[3] = WLAN_11i_CSS_CCMP;
-        } else {
-            pRSNIEs->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
-        }
-
-        // Pairwise Key Cipher Suite
-        pRSNIEs->abyRSN[4] = 1;
-        pRSNIEs->abyRSN[5] = 0;
-        pRSNIEs->abyRSN[6] = 0x00;
-        pRSNIEs->abyRSN[7] = 0x0F;
-        pRSNIEs->abyRSN[8] = 0xAC;
-        if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
-            pRSNIEs->abyRSN[9] = WLAN_11i_CSS_TKIP;
-        } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
-            pRSNIEs->abyRSN[9] = WLAN_11i_CSS_CCMP;
-        } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
-            pRSNIEs->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
-        } else {
-            pRSNIEs->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
-        }
-        pRSNIEs->len += 6;
-
-        // Auth Key Management Suite
-        pRSNIEs->abyRSN[10] = 1;
-        pRSNIEs->abyRSN[11] = 0;
-        pRSNIEs->abyRSN[12] = 0x00;
-        pRSNIEs->abyRSN[13] = 0x0F;
-        pRSNIEs->abyRSN[14] = 0xAC;
-        if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
-            pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_PSK;
-        } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
-            pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
-        } else {
-            pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
-        }
-        pRSNIEs->len +=6;
-
-        // RSN Capabilites
-        if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
-            memcpy(&pRSNIEs->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
-        } else {
-            pRSNIEs->abyRSN[16] = 0;
-            pRSNIEs->abyRSN[17] = 0;
-        }
-        pRSNIEs->len +=2;
-
-       if ((pMgmt->gsPMKIDCache.BSSIDInfoCount > 0) &&
-           (pMgmt->bRoaming == true) &&
-            (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
-               /* RSN PMKID, pointer to PMKID count */
-               pwPMKID = (PWORD)(&pRSNIEs->abyRSN[18]);
-               *pwPMKID = 0;                     /* Initialize PMKID count */
-               pbyBuffer = &pRSNIEs->abyRSN[20];    /* Point to PMKID list */
-               for (ii = 0; ii < pMgmt->gsPMKIDCache.BSSIDInfoCount; ii++) {
-                       if (!memcmp(&pMgmt->
-                                   gsPMKIDCache.BSSIDInfo[ii].abyBSSID[0],
-                                   pMgmt->abyCurrBSSID,
-                                   ETH_ALEN)) {
-                               (*pwPMKID)++;
-                               memcpy(pbyBuffer,
-                       pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyPMKID,
-                                      16);
-                               pbyBuffer += 16;
-                       }
-               }
-            if (*pwPMKID != 0) {
-                pRSNIEs->len += (2 + (*pwPMKID)*16);
-            } else {
-                pbyBuffer = &pRSNIEs->abyRSN[18];
-            }
-        }
-        return(pRSNIEs->len + WLAN_IEHDR_LEN);
-    }
-    return(0);
-}
index c359252a6b0e37af1d160a1811fc3dcbab24ab69..dc505ce7a7e42dab082e4c3c55084a39e03e1647 100644 (file)
 #ifndef __WPA2_H__
 #define __WPA2_H__
 
-#include "ttype.h"
 #include "80211mgr.h"
 #include "80211hdr.h"
 #include "bssdb.h"
 
-/*---------------------  Export Definitions -------------------------*/
 #define MAX_PMKID_CACHE         16
 
 typedef struct tagsPMKIDInfo {
-    BYTE    abyBSSID[6];
-    BYTE    abyPMKID[16];
+    u8    abyBSSID[6];
+    u8    abyPMKID[16];
 } PMKIDInfo, *PPMKIDInfo;
 
 typedef struct tagSPMKIDCache {
@@ -49,18 +47,7 @@ typedef struct tagSPMKIDCache {
        PMKIDInfo BSSIDInfo[MAX_PMKID_CACHE];
 } SPMKIDCache, *PSPMKIDCache;
 
-
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Types  ------------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 void WPA2_ClearRSN(PKnownBSS pBSSNode);
 void WPA2vParseRSN(PKnownBSS pBSSNode, PWLAN_IE_RSN pRSN);
 
-unsigned int WPA2uSetIEs(void *pMgmtHandle, PWLAN_IE_RSN pRSNIEs);
-
 #endif /* __WPA2_H__ */
index 53629b26f24da0ce05e8705a5f36485c738da4d6..9f1b413ce86f7534cf7ccc30bb2de26cc0c7ded0 100644 (file)
 #include "rndis.h"
 #include "rf.h"
 
-/*---------------------  Static Definitions -------------------------*/
-
-/*---------------------  Static Classes  ----------------------------*/
-
-/*---------------------  Static Variables  --------------------------*/
 static int msglevel = MSG_LEVEL_INFO;
 
-/*---------------------  Static Functions  --------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-
 /*
  * Description:
  *      Set WPA algorithm & keys
@@ -71,11 +61,11 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx)
 {
        struct viawget_wpa_param *param = ctx;
        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
-       DWORD dwKeyIndex = 0;
-       BYTE abyKey[MAX_KEY_LEN];
-       BYTE abySeq[MAX_KEY_LEN];
+       u32 dwKeyIndex = 0;
+       u8 abyKey[MAX_KEY_LEN];
+       u8 abySeq[MAX_KEY_LEN];
        u64 KeyRSC;
-       BYTE byKeyDecMode = KEY_CTL_WEP;
+       u8 byKeyDecMode = KEY_CTL_WEP;
        int ret = 0;
        int uu;
        int ii;
@@ -101,14 +91,14 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx)
 
        memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
 
-       dwKeyIndex = (DWORD)(param->u.wpa_key.key_index);
+       dwKeyIndex = (u32)(param->u.wpa_key.key_index);
 
        if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
                if (dwKeyIndex > 3) {
                        return -EINVAL;
                } else {
                        if (param->u.wpa_key.set_tx) {
-                               pDevice->byKeyIndex = (BYTE)dwKeyIndex;
+                               pDevice->byKeyIndex = (u8)dwKeyIndex;
                                pDevice->bTransmitKey = true;
                                dwKeyIndex |= (1 << 31);
                        }
@@ -127,7 +117,6 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx)
                return ret;
        }
 
-
        if (param->u.wpa_key.seq && param->u.wpa_key.seq_len > sizeof(abySeq))
                return -EINVAL;
 
@@ -159,7 +148,6 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx)
        if (param->u.wpa_key.set_tx)
                dwKeyIndex |= (1 << 31);
 
-
        if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
                byKeyDecMode = KEY_CTL_CCMP;
        else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
@@ -204,7 +192,7 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx)
                if ((KeybSetAllGroupKey(pDevice, &(pDevice->sKey), dwKeyIndex,
                                                        param->u.wpa_key.key_len,
                                                        &KeyRSC,
-                                                       (PBYTE)abyKey,
+                                                       (u8 *)abyKey,
                                                        byKeyDecMode
                                        ) == true) &&
                        (KeybSetDefaultKey(pDevice,
@@ -212,7 +200,7 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx)
                                        dwKeyIndex,
                                        param->u.wpa_key.key_len,
                                        &KeyRSC,
-                                       (PBYTE)abyKey,
+                                       (u8 *)abyKey,
                                        byKeyDecMode
                                ) == true) ) {
                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
@@ -234,7 +222,7 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx)
                }
                if (KeybSetKey(pDevice, &(pDevice->sKey), &param->addr[0],
                                dwKeyIndex, param->u.wpa_key.key_len,
-                               &KeyRSC, (PBYTE)abyKey, byKeyDecMode
+                               &KeyRSC, (u8 *)abyKey, byKeyDecMode
                                ) == true) {
                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
                } else {
@@ -250,7 +238,7 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx)
                }
        } // BSSID not 0xffffffffffff
        if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
-               pDevice->byKeyIndex = (BYTE)param->u.wpa_key.key_index;
+               pDevice->byKeyIndex = (u8)param->u.wpa_key.key_index;
                pDevice->bTransmitKey = true;
        }
        pDevice->bEncryptionEnable = true;
@@ -258,4 +246,3 @@ int wpa_set_keys(struct vnt_private *pDevice, void *ctx)
        return ret;
 }
 
-
index 2235ee97012e16a30991e9054f535f01af586e96..e032a1b94ae8367f1bfc6a9c324c7f3fb44fe1f5 100644 (file)
@@ -32,9 +32,6 @@
 #include "device.h"
 #include "iowpa.h"
 
-/*---------------------  Export Definitions -------------------------*/
-
-
 //WPA related
 
 typedef enum { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP } wpa_alg;
@@ -43,15 +40,8 @@ typedef enum { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP } wpa_alg;
 #define AUTH_ALG_SHARED_KEY    0x02
 #define AUTH_ALG_LEAP          0x04
 
-
 typedef unsigned long long NDIS_802_11_KEY_RSC;
 
-/*---------------------  Export Classes  ----------------------------*/
-
-/*---------------------  Export Variables  --------------------------*/
-
-/*---------------------  Export Functions  --------------------------*/
-
 int wpa_set_keys(struct vnt_private *, void *ctx);
 
 #endif /* __WPACL_H__ */
index 8d2277bb898fd3489b8ea39f42decdaa1b306200..428a9be2501069800ce960c882374206e3ff25d4 100644 (file)
@@ -1160,30 +1160,33 @@ static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
            le16_to_cpu(inf->info.chinforesult.scanchannels);
 
        for (i = 0, n = 0; i < HFA384x_CHINFORESULT_MAX; i++) {
-               if (hw->channel_info.results.scanchannels & (1 << i)) {
-                       int channel =
-                           le16_to_cpu(inf->info.chinforesult.result[n].chid) -
-                           1;
-                       hfa384x_ChInfoResultSub_t *chinforesult =
-                           &hw->channel_info.results.result[channel];
-                       chinforesult->chid = channel;
-                       chinforesult->anl =
-                           le16_to_cpu(inf->info.chinforesult.result[n].anl);
-                       chinforesult->pnl =
-                           le16_to_cpu(inf->info.chinforesult.result[n].pnl);
-                       chinforesult->active =
-                           le16_to_cpu(inf->info.chinforesult.result[n].
-                                       active);
-       pr_debug
-               ("chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
-                            channel + 1,
-                            chinforesult->
-                            active & HFA384x_CHINFORESULT_BSSACTIVE ? "signal"
-                            : "noise", chinforesult->anl, chinforesult->pnl,
-                            chinforesult->
-                            active & HFA384x_CHINFORESULT_PCFACTIVE ? 1 : 0);
-                       n++;
-               }
+               hfa384x_ChInfoResultSub_t *result;
+               hfa384x_ChInfoResultSub_t *chinforesult;
+               int chan;
+
+               if (!(hw->channel_info.results.scanchannels & (1 << i)))
+                       continue;
+
+               result = &inf->info.chinforesult.result[n];
+               chan = le16_to_cpu(result->chid) - 1;
+
+               if (chan < 0 || chan >= HFA384x_CHINFORESULT_MAX)
+                       continue;
+
+               chinforesult = &hw->channel_info.results.result[chan];
+               chinforesult->chid = chan;
+               chinforesult->anl = le16_to_cpu(result->anl);
+               chinforesult->pnl = le16_to_cpu(result->pnl);
+               chinforesult->active = le16_to_cpu(result->active);
+
+               pr_debug("chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n",
+                        chan + 1,
+                        (chinforesult->active & HFA384x_CHINFORESULT_BSSACTIVE)
+                               ? "signal" : "noise",
+                        chinforesult->anl, chinforesult->pnl,
+                        (chinforesult->active & HFA384x_CHINFORESULT_PCFACTIVE)
+                               ? 1 : 0);
+               n++;
        }
        atomic_set(&hw->channel_info.done, 2);
 
index b1aed1f1f749c28216b93e1b21e5e28ac830271a..b401974fb282e1a52967d31df2025791352fadda 100644 (file)
@@ -113,14 +113,14 @@ static int prism2sta_probe_usb(struct usb_interface *interface,
        dev = interface_to_usbdev(interface);
        wlandev = create_wlan();
        if (wlandev == NULL) {
-               printk(KERN_ERR "%s: Memory allocation failure.\n", dev_info);
+               dev_err(&interface->dev, "Memory allocation failure.\n");
                result = -EIO;
                goto failed;
        }
        hw = wlandev->priv;
 
        if (wlan_setup(wlandev, &(interface->dev)) != 0) {
-               printk(KERN_ERR "%s: wlan_setup() failed.\n", dev_info);
+               dev_err(&interface->dev, "wlan_setup() failed.\n");
                result = -EIO;
                goto failed;
        }
@@ -143,8 +143,7 @@ static int prism2sta_probe_usb(struct usb_interface *interface,
                        unregister_wlandev(wlandev);
                        hfa384x_destroy(hw);
                        result = -EIO;
-                       printk(KERN_ERR
-                              "%s: hfa384x_corereset() failed.\n", dev_info);
+                       dev_err(&interface->dev, "hfa384x_corereset() failed.\n");
                        goto failed;
                }
        }
@@ -158,7 +157,7 @@ static int prism2sta_probe_usb(struct usb_interface *interface,
        prism2sta_ifstate(wlandev, P80211ENUM_ifstate_enable);
 
        if (register_wlandev(wlandev) != 0) {
-               printk(KERN_ERR "%s: register_wlandev() failed.\n", dev_info);
+               dev_err(&interface->dev, "register_wlandev() failed.\n");
                result = -EIO;
                goto failed;
        }
@@ -329,8 +328,7 @@ static int prism2sta_resume(struct usb_interface *interface)
                if (result != 0) {
                        unregister_wlandev(wlandev);
                        hfa384x_destroy(hw);
-                       printk(KERN_ERR
-                              "%s: hfa384x_corereset() failed.\n", dev_info);
+                       dev_err(&interface->dev, "hfa384x_corereset() failed.\n");
                        kfree(wlandev);
                        kfree(hw);
                        wlandev = NULL;
index 148f6373c9a264e3848eeddf7e96b06e9a47d8de..80c972305885babd09f61a0c1db00ddae2b0475d 100644 (file)
 #define EnableVBCLKDRVLOW    0x4000
 #define EnablePLLSPLOW       0x8000
 
-#define LCDBToA              0x20   /* LCD SetFlag */
-#define StLCDBToA            0x40
-#define LockLCDBToA          0x80
-#define   LCDToFull          0x10
 #define AVIDEOSense          0x01   /* CR32 */
 #define SVIDEOSense          0x02
 #define SCARTSense           0x04
index df127e4069520c7410e2525268aa6ef9d5a0a291..19ce5a978cae732817745befba348b26cb99c490 100644 (file)
@@ -90,18 +90,14 @@ static void XGINew_DDR1x_MRS_340(unsigned long P3c4,
        xgifb_reg_set(P3c4, 0x16, 0x80);
 
        udelay(60);
-       xgifb_reg_set(P3c4,
-                     0x18,
-                     pVBInfo->SR15[2][pVBInfo->ram_type]); /* SR18 */
+       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);
        xgifb_reg_set(P3c4, 0x1B, 0x03);
        udelay(500);
-       xgifb_reg_set(P3c4,
-                     0x18,
-                     pVBInfo->SR15[2][pVBInfo->ram_type]); /* SR18 */
+       xgifb_reg_set(P3c4, 0x18, pVBInfo->SR18[pVBInfo->ram_type]); /* SR18 */
        xgifb_reg_set(P3c4, 0x19, 0x00);
        xgifb_reg_set(P3c4, 0x16, 0x03);
        xgifb_reg_set(P3c4, 0x16, 0x83);
@@ -265,18 +261,14 @@ static void XGINew_DDR1x_MRS_XG20(unsigned long P3c4,
        xgifb_reg_set(P3c4, 0x16, 0x00);
        xgifb_reg_set(P3c4, 0x16, 0x80);
        udelay(60);
-       xgifb_reg_set(P3c4,
-                     0x18,
-                     pVBInfo->SR15[2][pVBInfo->ram_type]); /* SR18 */
+       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);
        xgifb_reg_set(P3c4, 0x1B, 0x03);
        udelay(500);
-       xgifb_reg_set(P3c4,
-                     0x18,
-                     pVBInfo->SR15[2][pVBInfo->ram_type]); /* SR18 */
+       xgifb_reg_set(P3c4, 0x18, pVBInfo->SR18[pVBInfo->ram_type]); /* SR18 */
        xgifb_reg_set(P3c4, 0x19, 0x00);
        xgifb_reg_set(P3c4, 0x16, 0x03);
        xgifb_reg_set(P3c4, 0x16, 0x83);
@@ -507,9 +499,7 @@ static void XGINew_SetDRAMDefaultRegister340(
                xgifb_reg_set(P3d4, 0xB0, 0x80); /* DDRII Dual frequency mode */
                XGINew_DDR2_DefaultRegister(HwDeviceExtension, P3d4, pVBInfo);
        }
-       xgifb_reg_set(P3c4,
-                     0x1B,
-                     pVBInfo->SR15[3][pVBInfo->ram_type]); /* SR1B */
+       xgifb_reg_set(P3c4, 0x1B, 0x03); /* SR1B */
 }
 
 
@@ -888,7 +878,7 @@ done:
        return rom_copy;
 }
 
-static void xgifb_read_vbios(struct pci_dev *pdev,
+static bool xgifb_read_vbios(struct pci_dev *pdev,
                              struct vb_device_info *pVBInfo)
 {
        struct xgifb_video_info *xgifb_info = pci_get_drvdata(pdev);
@@ -899,13 +889,10 @@ static void xgifb_read_vbios(struct pci_dev *pdev,
        size_t vbios_size;
        int entry;
 
-       if (xgifb_info->chip != XG21)
-               return;
-       pVBInfo->IF_DEF_LVDS = 0;
        vbios = xgifb_copy_rom(pdev, &vbios_size);
        if (vbios == NULL) {
                dev_err(&pdev->dev, "Video BIOS not available\n");
-               return;
+               return false;
        }
        if (vbios_size <= 0x65)
                goto error;
@@ -917,7 +904,7 @@ static void xgifb_read_vbios(struct pci_dev *pdev,
            (!xgifb_info->display2_force ||
             xgifb_info->display2 != XGIFB_DISP_LCD)) {
                vfree(vbios);
-               return;
+               return false;
        }
        if (vbios_size <= 0x317)
                goto error;
@@ -956,11 +943,11 @@ static void xgifb_read_vbios(struct pci_dev *pdev,
        lvds->PSC_S4            = vbios[i + 23];
        lvds->PSC_S5            = vbios[i + 24];
        vfree(vbios);
-       pVBInfo->IF_DEF_LVDS = 1;
-       return;
+       return true;
 error:
        dev_err(&pdev->dev, "Video BIOS corrupted\n");
        vfree(vbios);
+       return false;
 }
 
 static void XGINew_ChkSenseStatus(struct xgi_hw_device_info *HwDeviceExtension,
@@ -1132,12 +1119,13 @@ static unsigned short XGINew_SenseLCD(struct xgi_hw_device_info
        }
 }
 
-static void XGINew_GetXG21Sense(struct xgi_hw_device_info *HwDeviceExtension,
+static void XGINew_GetXG21Sense(struct pci_dev *pdev,
                struct vb_device_info *pVBInfo)
 {
+       struct xgifb_video_info *xgifb_info = pci_get_drvdata(pdev);
        unsigned char Temp;
 
-       if (pVBInfo->IF_DEF_LVDS) { /* For XG21 LVDS */
+       if (xgifb_read_vbios(pdev, pVBInfo)) { /* For XG21 LVDS */
                xgifb_reg_or(pVBInfo->P3d4, 0x32, LCDSense);
                /* LVDS on chip */
                xgifb_reg_and_or(pVBInfo->P3d4, 0x38, ~0xE0, 0xC0);
@@ -1146,7 +1134,7 @@ static void XGINew_GetXG21Sense(struct xgi_hw_device_info *HwDeviceExtension,
                xgifb_reg_and_or(pVBInfo->P3d4, 0x4A, ~0x03, 0x03);
                Temp = xgifb_reg_get(pVBInfo->P3d4, 0x48) & 0xC0;
                if (Temp == 0xC0) { /* DVI & DVO GPIOA/B pull high */
-                       XGINew_SenseLCD(HwDeviceExtension, pVBInfo);
+                       XGINew_SenseLCD(&xgifb_info->hw_info, pVBInfo);
                        xgifb_reg_or(pVBInfo->P3d4, 0x32, LCDSense);
                        /* Enable read GPIOF */
                        xgifb_reg_and_or(pVBInfo->P3d4, 0x4A, ~0x20, 0x20);
@@ -1172,7 +1160,6 @@ static void XGINew_GetXG27Sense(struct xgi_hw_device_info *HwDeviceExtension,
 {
        unsigned char Temp, bCR4A;
 
-       pVBInfo->IF_DEF_LVDS = 0;
        bCR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
        /* Enable GPIOA/B/C read  */
        xgifb_reg_and_or(pVBInfo->P3d4, 0x4A, ~0x07, 0x07);
@@ -1254,14 +1241,12 @@ unsigned char XGIInitNew(struct pci_dev *pdev)
 
        InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
 
-       xgifb_read_vbios(pdev, pVBInfo);
-
        /* Openkey */
        xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
 
        /* GetXG21Sense (GPIO) */
        if (HwDeviceExtension->jChipType == XG21)
-               XGINew_GetXG21Sense(HwDeviceExtension, pVBInfo);
+               XGINew_GetXG21Sense(pdev, pVBInfo);
 
        if (HwDeviceExtension->jChipType == XG27)
                XGINew_GetXG27Sense(HwDeviceExtension, pVBInfo);
@@ -1369,17 +1354,14 @@ unsigned char XGIInitNew(struct pci_dev *pdev)
 
        if (HwDeviceExtension->jChipType < XG20) {
                if (XGI_BridgeIsOn(pVBInfo) == 1) {
-                       if (pVBInfo->IF_DEF_LVDS == 0) {
-                               xgifb_reg_set(pVBInfo->Part2Port, 0x00, 0x1C);
-                               xgifb_reg_set(pVBInfo->Part4Port,
-                                             0x0D, XGI330_CRT2Data_4_D);
-                               xgifb_reg_set(pVBInfo->Part4Port,
-                                             0x0E, XGI330_CRT2Data_4_E);
-                               xgifb_reg_set(pVBInfo->Part4Port,
-                                             0x10, XGI330_CRT2Data_4_10);
-                               xgifb_reg_set(pVBInfo->Part4Port, 0x0F, 0x3F);
-                       }
-
+                       xgifb_reg_set(pVBInfo->Part2Port, 0x00, 0x1C);
+                       xgifb_reg_set(pVBInfo->Part4Port,
+                                     0x0D, XGI330_CRT2Data_4_D);
+                       xgifb_reg_set(pVBInfo->Part4Port,
+                                     0x0E, XGI330_CRT2Data_4_E);
+                       xgifb_reg_set(pVBInfo->Part4Port,
+                                     0x10, XGI330_CRT2Data_4_10);
+                       xgifb_reg_set(pVBInfo->Part4Port, 0x0F, 0x3F);
                        XGI_LockCRT2(HwDeviceExtension, pVBInfo);
                }
        } /* != XG20 */
index dfa5303379e95be384c2bbd8615eb3b56abbc116..3adec3f184621153fa0cae6fce7ea08a7f087175 100644 (file)
@@ -32,7 +32,7 @@ void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
        pVBInfo->VBInfo = 0;
        pVBInfo->TVInfo = 0;
 
-       pVBInfo->SR15 = XGI340_SR13;
+       pVBInfo->SR18 = XGI340_SR18;
        pVBInfo->CR40 = XGI340_cr41;
 
        /* 310 customization related */
@@ -49,7 +49,7 @@ void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
                pVBInfo->MCLKData = XGI27New_MCLKData;
                pVBInfo->CR40 = XGI27_cr41;
                pVBInfo->XGINew_CR97 = 0xc1;
-               pVBInfo->SR15 = XG27_SR13;
+               pVBInfo->SR18 = XG27_SR18;
 
                /*Z11m DDR*/
                temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
index ae0c18b320a48cb97d4ae219a4d59cb7ceb22e38..c08ff5b2d6ee055dbca9092c9d6475bcb5375b6e 100644 (file)
@@ -81,7 +81,6 @@ struct XGI_XG21CRT1Struct {
 struct XGI330_LCDCapStruct {
        unsigned char   LCD_ID;
        unsigned short  LCD_Capability;
-       unsigned char   LCD_SetFlag;
        unsigned char   LCD_HSyncWidth;
        unsigned char   LCD_VSyncWidth;
        unsigned char   LCD_VCLK;
@@ -89,16 +88,6 @@ struct XGI330_LCDCapStruct {
        unsigned char   LCDA_VCLKData2;
        unsigned char   LCUCHAR_VCLKData1;
        unsigned char   LCUCHAR_VCLKData2;
-       unsigned char   PSC_S1;
-       unsigned char   PSC_S2;
-       unsigned char   PSC_S3;
-       unsigned char   PSC_S4;
-       unsigned char   PSC_S5;
-       unsigned char   PWD_2B;
-       unsigned char   PWD_2C;
-       unsigned char   PWD_2D;
-       unsigned char   PWD_2E;
-       unsigned char   PWD_2F;
        unsigned char   Spectrum_31;
        unsigned char   Spectrum_32;
        unsigned char   Spectrum_33;
@@ -145,7 +134,7 @@ struct vb_device_info {
        unsigned short   LCDHRS, LCDVRS, LCDHDES, LCDVDES;
 
        unsigned short   ModeType;
-       unsigned short   IF_DEF_LVDS, IF_DEF_TRUMPION, IF_DEF_DSTN;
+       unsigned short   IF_DEF_LVDS;
        unsigned short   IF_DEF_CRT2Monitor;
        unsigned short   IF_DEF_YPbPr;
        unsigned short   IF_DEF_HiVision;
@@ -157,12 +146,11 @@ struct vb_device_info {
 
        void __iomem *FBAddr;
 
-       unsigned char const (*SR15)[3];
+       unsigned char const *SR18;
        unsigned char const (*CR40)[3];
 
        struct SiS_MCLKData const *MCLKData;
 
-       unsigned char   *pXGINew_DRAMTypeDefinition;
        unsigned char   XGINew_CR97;
 
        struct XGI330_LCDCapStruct const *LCDCapList;
index b4c05c80b9371768647e4e8ec619f581c592b73a..7168eedbd96a1bb471666af8b74a1fa2c08249a0 100644 (file)
@@ -18,18 +18,12 @@ const struct XGI_ECLKDataStruct XGI340_ECLKData[] = {
        {0x7C, 0x08, 0x01, 200},
 };
 
-static const unsigned char XG27_SR13[4][3] = {
-       {0x35, 0x45, 0xb1}, /* SR13 */
-       {0x41, 0x51, 0x5c}, /* SR14 */
-       {0x32, 0x32, 0x42}, /* SR18 */
-       {0x03, 0x03, 0x03}  /* SR1B */
+static const unsigned char XG27_SR18[3] = {
+       0x32, 0x32, 0x42 /* SR18 */
 };
 
-static const unsigned char XGI340_SR13[4][3] = {
-       {0x35, 0x45, 0xb1}, /* SR13 */
-       {0x41, 0x51, 0x5c}, /* SR14 */
-       {0x31, 0x42, 0x42}, /* SR18 */
-       {0x03, 0x03, 0x03}  /* SR1B */
+static const unsigned char XGI340_SR18[3] = {
+       0x31, 0x42, 0x42 /* SR18 */
 };
 
 static const unsigned char XGI340_cr41[24][3] = {
@@ -1867,72 +1861,72 @@ static const struct XGI330_TVDataTablStruct XGI_TVDataTable[] = {
 /* Dual link only */
 static const struct XGI330_LCDCapStruct XGI_LCDDLCapList[] = {
 /* LCDCap1024x768 */
-       {Panel_1024x768, DefaultLCDCap, 0, 0x88, 0x06, VCLK65_315,
-       0x6C, 0xC3, 0x35, 0x62, 0x02, 0x14, 0x0A, 0x02, 0x00,
-       0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x28, 0x10},
+       {Panel_1024x768, DefaultLCDCap, 0x88, 0x06, VCLK65_315,
+       0x6C, 0xC3, 0x35, 0x62,
+       0x0A, 0xC0, 0x28, 0x10},
 /* LCDCap1280x1024 */
-       {Panel_1280x1024, XGI_LCDDualLink+DefaultLCDCap, StLCDBToA,
+       {Panel_1280x1024, XGI_LCDDualLink+DefaultLCDCap,
        0x70, 0x03, VCLK108_2_315,
-       0x70, 0x44, 0xF8, 0x2F, 0x02, 0x14, 0x0A, 0x02, 0x00,
-       0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x30, 0x10},
+       0x70, 0x44, 0xF8, 0x2F,
+       0x0A, 0xC0, 0x30, 0x10},
 /* LCDCap1400x1050 */
-       {Panel_1400x1050, XGI_LCDDualLink+DefaultLCDCap, StLCDBToA,
+       {Panel_1400x1050, XGI_LCDDualLink+DefaultLCDCap,
        0x70, 0x03, VCLK108_2_315,
-        0x70, 0x44, 0xF8, 0x2F, 0x02, 0x14, 0x0A, 0x02, 0x00,
-        0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x30, 0x10},
+        0x70, 0x44, 0xF8, 0x2F,
+        0x0A, 0xC0, 0x30, 0x10},
 /* LCDCap1600x1200 */
-       {Panel_1600x1200, XGI_LCDDualLink+DefaultLCDCap, LCDToFull,
+       {Panel_1600x1200, XGI_LCDDualLink+DefaultLCDCap,
        0xC0, 0x03, VCLK162,
-        0x43, 0x22, 0x70, 0x24, 0x02, 0x14, 0x0A, 0x02, 0x00,
-        0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x30, 0x10},
+        0x43, 0x22, 0x70, 0x24,
+        0x0A, 0xC0, 0x30, 0x10},
 /* LCDCap1024x768x75 */
-       {Panel_1024x768x75, DefaultLCDCap, 0, 0x60, 0, VCLK78_75,
-        0x2B, 0x61, 0x2B, 0x61, 0x02, 0x14, 0x0A, 0x02, 0x00,
-        0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x28, 0x10},
+       {Panel_1024x768x75, DefaultLCDCap, 0x60, 0, VCLK78_75,
+        0x2B, 0x61, 0x2B, 0x61,
+        0x0A, 0xC0, 0x28, 0x10},
 /* LCDCap1280x1024x75 */
-       {Panel_1280x1024x75, XGI_LCDDualLink+DefaultLCDCap, StLCDBToA,
+       {Panel_1280x1024x75, XGI_LCDDualLink+DefaultLCDCap,
         0x90, 0x03, VCLK135_5,
-        0x54, 0x42, 0x4A, 0x61, 0x02, 0x14, 0x0A, 0x02, 0x00,
-        0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x30, 0x10},
+        0x54, 0x42, 0x4A, 0x61,
+        0x0A, 0xC0, 0x30, 0x10},
 /* LCDCapDefault */
-       {0xFF, DefaultLCDCap, 0, 0x88, 0x06, VCLK65_315,
-       0x6C, 0xC3, 0x35, 0x62, 0x02, 0x14, 0x0A, 0x02, 0x00,
-       0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x28, 0x10}
+       {0xFF, DefaultLCDCap, 0x88, 0x06, VCLK65_315,
+       0x6C, 0xC3, 0x35, 0x62,
+       0x0A, 0xC0, 0x28, 0x10}
 };
 
 static const struct XGI330_LCDCapStruct XGI_LCDCapList[] = {
 /* LCDCap1024x768 */
-       {Panel_1024x768, DefaultLCDCap, 0, 0x88, 0x06, VCLK65_315,
-       0x6C, 0xC3, 0x35, 0x62, 0x02, 0x14, 0x0A, 0x02, 0x00,
-       0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x28, 0x10},
+       {Panel_1024x768, DefaultLCDCap, 0x88, 0x06, VCLK65_315,
+       0x6C, 0xC3, 0x35, 0x62,
+       0x0A, 0xC0, 0x28, 0x10},
 /* LCDCap1280x1024 */
-       {Panel_1280x1024, DefaultLCDCap, StLCDBToA,
+       {Panel_1280x1024, DefaultLCDCap,
        0x70, 0x03, VCLK108_2_315,
-       0x70, 0x44, 0xF8, 0x2F, 0x02, 0x14, 0x0A, 0x02, 0x00,
-       0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x30, 0x10},
+       0x70, 0x44, 0xF8, 0x2F,
+       0x0A, 0xC0, 0x30, 0x10},
 /* LCDCap1400x1050 */
-       {Panel_1400x1050, DefaultLCDCap, StLCDBToA,
+       {Panel_1400x1050, DefaultLCDCap,
         0x70, 0x03, VCLK108_2_315,
-        0x70, 0x44, 0xF8, 0x2F, 0x02, 0x14, 0x0A, 0x02, 0x00,
-        0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x30, 0x10},
+        0x70, 0x44, 0xF8, 0x2F,
+        0x0A, 0xC0, 0x30, 0x10},
 /* LCDCap1600x1200 */
-       {Panel_1600x1200, DefaultLCDCap, LCDToFull,
+       {Panel_1600x1200, DefaultLCDCap,
         0xC0, 0x03, VCLK162,
-        0x5A, 0x23, 0x5A, 0x23, 0x02, 0x14, 0x0A, 0x02, 0x00,
-        0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x30, 0x10},
+        0x5A, 0x23, 0x5A, 0x23,
+        0x0A, 0xC0, 0x30, 0x10},
 /* LCDCap1024x768x75 */
-       {Panel_1024x768x75, DefaultLCDCap, 0, 0x60, 0, VCLK78_75,
-        0x2B, 0x61, 0x2B, 0x61, 0x02, 0x14, 0x0A, 0x02, 0x00,
-        0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x28, 0x10},
+       {Panel_1024x768x75, DefaultLCDCap, 0x60, 0, VCLK78_75,
+        0x2B, 0x61, 0x2B, 0x61,
+        0x0A, 0xC0, 0x28, 0x10},
 /* LCDCap1280x1024x75 */
-       {Panel_1280x1024x75, DefaultLCDCap, StLCDBToA,
+       {Panel_1280x1024x75, DefaultLCDCap,
         0x90, 0x03, VCLK135_5,
-        0x54, 0x42, 0x4A, 0x61, 0x02, 0x14, 0x0A, 0x02, 0x00,
-        0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x30, 0x10},
+        0x54, 0x42, 0x4A, 0x61,
+        0x0A, 0xC0, 0x30, 0x10},
 /* LCDCapDefault */
-       {0xFF, DefaultLCDCap, 0, 0x88, 0x06, VCLK65_315,
-       0x6C, 0xC3, 0x35, 0x62, 0x02, 0x14, 0x0A, 0x02, 0x00,
-       0x30, 0x10, 0x5A, 0x10, 0x10, 0x0A, 0xC0, 0x28, 0x10}
+       {0xFF, DefaultLCDCap, 0x88, 0x06, VCLK65_315,
+       0x6C, 0xC3, 0x35, 0x62,
+       0x0A, 0xC0, 0x28, 0x10}
 };
 
 const struct XGI_Ext2Struct XGI330_RefIndex[] = {
index 5c3714530961c5ede430f7745706d24c833781ce..c3b8a10e170fff2285977637e4d8f0ec31eafb73 100644 (file)
@@ -10,6 +10,14 @@ config ZCACHE
          memory to store clean page cache pages and swap in RAM,
          providing a noticeable reduction in disk I/O.
 
+config ZCACHE_DEBUG
+       bool "Enable debug statistics"
+       depends on DEBUG_FS && ZCACHE
+       default n
+       help
+         This is used to provide an debugfs directory with counters of
+         how zcache is doing. You probably want to set this to 'N'.
+
 config RAMSTER
        bool "Cross-machine RAM capacity sharing, aka peer-to-peer tmem"
        depends on CONFIGFS_FS=y && SYSFS=y && !HIGHMEM && ZCACHE=y
index 471104957dadaaa3e851359510793c6cd49407a0..24fd6aa238179d6d6e622f081c3a3422c9f4de12 100644 (file)
@@ -1,4 +1,5 @@
 zcache-y       :=              zcache-main.o tmem.o zbud.o
+zcache-$(CONFIG_ZCACHE_DEBUG) += debug.o
 zcache-$(CONFIG_RAMSTER)       +=      ramster/ramster.o ramster/r2net.o
 zcache-$(CONFIG_RAMSTER)       +=      ramster/nodemanager.o ramster/tcp.o
 zcache-$(CONFIG_RAMSTER)       +=      ramster/heartbeat.o ramster/masklog.o
index c1e26d4973dc62cd5c5b80855563e87738ce88fd..ec9aa11653b971fab2cb83c8dd53c0ad9a0c8b05 100644 (file)
@@ -41,14 +41,10 @@ STATUS/OWNERSHIP
     for 3.9, see https://lkml.org/lkml/2013/2/6/437;
 7. PROTOTYPED as part of "new" zcache; in staging/zcache for 3.9;
     needs more review (plan to discuss at LSF/MM 2013)
-8. IN PROGRESS; owned by Konrad Wilk; v2 recently posted
-   http://lkml.org/lkml/2013/2/1/542
 9. IN PROGRESS; owned by Konrad Wilk; Mel Gorman provided
    great feedback in August 2012 (unfortunately of "old"
    zcache)
-10. Konrad posted series of fixes (that now need rebasing)
-    https://lkml.org/lkml/2013/2/1/566 
-11. NOT DONE; owned by Konrad Wilk
+11. NOT DONE; owned by Konrad Wilk and Bob Liu
 12. TBD (depends on quantity of feedback)
 13. PROPOSED; one suggestion proposed by Dan; needs more ideas/feedback
 14. TBD (depends on feedback)
diff --git a/drivers/staging/zcache/debug.c b/drivers/staging/zcache/debug.c
new file mode 100644 (file)
index 0000000..e951c64
--- /dev/null
@@ -0,0 +1,71 @@
+#include <linux/atomic.h>
+#include "debug.h"
+
+#ifdef CONFIG_ZCACHE_DEBUG
+#include <linux/debugfs.h>
+
+#define ATTR(x)  { .name = #x, .val = &zcache_##x, }
+static struct debug_entry {
+       const char *name;
+       ssize_t *val;
+} attrs[] = {
+       ATTR(obj_count), ATTR(obj_count_max),
+       ATTR(objnode_count), ATTR(objnode_count_max),
+       ATTR(flush_total), ATTR(flush_found),
+       ATTR(flobj_total), ATTR(flobj_found),
+       ATTR(failed_eph_puts), ATTR(failed_pers_puts),
+       ATTR(failed_getfreepages), ATTR(failed_alloc),
+       ATTR(put_to_flush),
+       ATTR(compress_poor), ATTR(mean_compress_poor),
+       ATTR(eph_ate_tail), ATTR(eph_ate_tail_failed),
+       ATTR(pers_ate_eph), ATTR(pers_ate_eph_failed),
+       ATTR(evicted_eph_zpages), ATTR(evicted_eph_pageframes),
+       ATTR(eph_pageframes), ATTR(eph_pageframes_max),
+       ATTR(eph_zpages), ATTR(eph_zpages_max),
+       ATTR(pers_zpages), ATTR(pers_zpages_max),
+       ATTR(last_active_file_pageframes),
+       ATTR(last_inactive_file_pageframes),
+       ATTR(last_active_anon_pageframes),
+       ATTR(last_inactive_anon_pageframes),
+       ATTR(eph_nonactive_puts_ignored),
+       ATTR(pers_nonactive_puts_ignored),
+#ifdef CONFIG_ZCACHE_WRITEBACK
+       ATTR(zcache_outstanding_writeback_pages),
+       ATTR(zcache_writtenback_pages),
+#endif
+};
+#undef ATTR
+int zcache_debugfs_init(void)
+{
+       unsigned int i;
+       struct dentry *root = debugfs_create_dir("zcache", NULL);
+       if (root == NULL)
+               return -ENXIO;
+
+       for (i = 0; i < ARRAY_SIZE(attrs); i++)
+               if (!debugfs_create_size_t(attrs[i].name, S_IRUGO, root, attrs[i].val))
+                       goto out;
+
+       debugfs_create_u64("eph_zbytes", S_IRUGO, root, &zcache_eph_zbytes);
+       debugfs_create_u64("eph_zbytes_max", S_IRUGO, root, &zcache_eph_zbytes_max);
+       debugfs_create_u64("pers_zbytes", S_IRUGO, root, &zcache_pers_zbytes);
+       debugfs_create_u64("pers_zbytes_max", S_IRUGO, root, &zcache_pers_zbytes_max);
+
+       return 0;
+out:
+       return -ENODEV;
+}
+
+/* developers can call this in case of ooms, e.g. to find memory leaks */
+void zcache_dump(void)
+{
+       unsigned int i;
+       for (i = 0; i < ARRAY_SIZE(attrs); i++)
+               pr_debug("zcache: %s=%zu\n", attrs[i].name, *attrs[i].val);
+
+       pr_debug("zcache: eph_zbytes=%llu\n", (unsigned long long)zcache_eph_zbytes);
+       pr_debug("zcache: eph_zbytes_max=%llu\n", (unsigned long long)zcache_eph_zbytes_max);
+       pr_debug("zcache: pers_zbytes=%llu\n", (unsigned long long)zcache_pers_zbytes);
+       pr_debug("zcache: pers_zbytes_max=%llu\n", (unsigned long long)zcache_pers_zbytes_max);
+}
+#endif
diff --git a/drivers/staging/zcache/debug.h b/drivers/staging/zcache/debug.h
new file mode 100644 (file)
index 0000000..4bbe49b
--- /dev/null
@@ -0,0 +1,231 @@
+#include <linux/bug.h>
+
+#ifdef CONFIG_ZCACHE_DEBUG
+
+/* we try to keep these statistics SMP-consistent */
+static ssize_t zcache_obj_count;
+static atomic_t zcache_obj_atomic = ATOMIC_INIT(0);
+static ssize_t zcache_obj_count_max;
+static inline void inc_zcache_obj_count(void)
+{
+       zcache_obj_count = atomic_inc_return(&zcache_obj_atomic);
+       if (zcache_obj_count > zcache_obj_count_max)
+               zcache_obj_count_max = zcache_obj_count;
+}
+static inline void dec_zcache_obj_count(void)
+{
+       zcache_obj_count = atomic_dec_return(&zcache_obj_atomic);
+       BUG_ON(zcache_obj_count < 0);
+};
+static ssize_t zcache_objnode_count;
+static atomic_t zcache_objnode_atomic = ATOMIC_INIT(0);
+static ssize_t zcache_objnode_count_max;
+static inline void inc_zcache_objnode_count(void)
+{
+       zcache_objnode_count = atomic_inc_return(&zcache_objnode_atomic);
+       if (zcache_objnode_count > zcache_objnode_count_max)
+               zcache_objnode_count_max = zcache_objnode_count;
+};
+static inline void dec_zcache_objnode_count(void)
+{
+       zcache_objnode_count = atomic_dec_return(&zcache_objnode_atomic);
+       BUG_ON(zcache_objnode_count < 0);
+};
+static u64 zcache_eph_zbytes;
+static atomic_long_t zcache_eph_zbytes_atomic = ATOMIC_INIT(0);
+static u64 zcache_eph_zbytes_max;
+static inline void inc_zcache_eph_zbytes(unsigned clen)
+{
+       zcache_eph_zbytes = atomic_long_add_return(clen, &zcache_eph_zbytes_atomic);
+       if (zcache_eph_zbytes > zcache_eph_zbytes_max)
+               zcache_eph_zbytes_max = zcache_eph_zbytes;
+};
+static inline void dec_zcache_eph_zbytes(unsigned zsize)
+{
+       zcache_eph_zbytes = atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic);
+};
+extern  u64 zcache_pers_zbytes;
+static atomic_long_t zcache_pers_zbytes_atomic = ATOMIC_INIT(0);
+static u64 zcache_pers_zbytes_max;
+static inline void inc_zcache_pers_zbytes(unsigned clen)
+{
+       zcache_pers_zbytes = atomic_long_add_return(clen, &zcache_pers_zbytes_atomic);
+       if (zcache_pers_zbytes > zcache_pers_zbytes_max)
+               zcache_pers_zbytes_max = zcache_pers_zbytes;
+}
+static inline void dec_zcache_pers_zbytes(unsigned zsize)
+{
+       zcache_pers_zbytes = atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic);
+}
+extern ssize_t zcache_eph_pageframes;
+static atomic_t zcache_eph_pageframes_atomic = ATOMIC_INIT(0);
+static ssize_t zcache_eph_pageframes_max;
+static inline void inc_zcache_eph_pageframes(void)
+{
+       zcache_eph_pageframes = atomic_inc_return(&zcache_eph_pageframes_atomic);
+       if (zcache_eph_pageframes > zcache_eph_pageframes_max)
+               zcache_eph_pageframes_max = zcache_eph_pageframes;
+};
+static inline void dec_zcache_eph_pageframes(void)
+{
+       zcache_eph_pageframes = atomic_dec_return(&zcache_eph_pageframes_atomic);
+};
+extern ssize_t zcache_pers_pageframes;
+static atomic_t zcache_pers_pageframes_atomic = ATOMIC_INIT(0);
+static ssize_t zcache_pers_pageframes_max;
+static inline void inc_zcache_pers_pageframes(void)
+{
+       zcache_pers_pageframes = atomic_inc_return(&zcache_pers_pageframes_atomic);
+       if (zcache_pers_pageframes > zcache_pers_pageframes_max)
+               zcache_pers_pageframes_max = zcache_pers_pageframes;
+}
+static inline void dec_zcache_pers_pageframes(void)
+{
+       zcache_pers_pageframes = atomic_dec_return(&zcache_pers_pageframes_atomic);
+}
+static ssize_t zcache_pageframes_alloced;
+static atomic_t zcache_pageframes_alloced_atomic = ATOMIC_INIT(0);
+static inline void inc_zcache_pageframes_alloced(void)
+{
+       zcache_pageframes_alloced = atomic_inc_return(&zcache_pageframes_alloced_atomic);
+};
+static ssize_t zcache_pageframes_freed;
+static atomic_t zcache_pageframes_freed_atomic = ATOMIC_INIT(0);
+static inline void inc_zcache_pageframes_freed(void)
+{
+       zcache_pageframes_freed = atomic_inc_return(&zcache_pageframes_freed_atomic);
+}
+static ssize_t zcache_eph_zpages;
+static atomic_t zcache_eph_zpages_atomic = ATOMIC_INIT(0);
+static ssize_t zcache_eph_zpages_max;
+static inline void inc_zcache_eph_zpages(void)
+{
+       zcache_eph_zpages = atomic_inc_return(&zcache_eph_zpages_atomic);
+       if (zcache_eph_zpages > zcache_eph_zpages_max)
+               zcache_eph_zpages_max = zcache_eph_zpages;
+}
+static inline void dec_zcache_eph_zpages(unsigned zpages)
+{
+       zcache_eph_zpages = atomic_sub_return(zpages, &zcache_eph_zpages_atomic);
+}
+extern ssize_t zcache_pers_zpages;
+static atomic_t zcache_pers_zpages_atomic = ATOMIC_INIT(0);
+static ssize_t zcache_pers_zpages_max;
+static inline void inc_zcache_pers_zpages(void)
+{
+       zcache_pers_zpages = atomic_inc_return(&zcache_pers_zpages_atomic);
+       if (zcache_pers_zpages > zcache_pers_zpages_max)
+               zcache_pers_zpages_max = zcache_pers_zpages;
+}
+static inline void dec_zcache_pers_zpages(unsigned zpages)
+{
+       zcache_pers_zpages = atomic_sub_return(zpages, &zcache_pers_zpages_atomic);
+}
+
+static inline unsigned long curr_pageframes_count(void)
+{
+       return zcache_pageframes_alloced -
+               atomic_read(&zcache_pageframes_freed_atomic) -
+               atomic_read(&zcache_eph_pageframes_atomic) -
+               atomic_read(&zcache_pers_pageframes_atomic);
+};
+/* but for the rest of these, counting races are ok */
+static ssize_t zcache_flush_total;
+static ssize_t zcache_flush_found;
+static ssize_t zcache_flobj_total;
+static ssize_t zcache_flobj_found;
+static ssize_t zcache_failed_eph_puts;
+static ssize_t zcache_failed_pers_puts;
+static ssize_t zcache_failed_getfreepages;
+static ssize_t zcache_failed_alloc;
+static ssize_t zcache_put_to_flush;
+static ssize_t zcache_compress_poor;
+static ssize_t zcache_mean_compress_poor;
+static ssize_t zcache_eph_ate_tail;
+static ssize_t zcache_eph_ate_tail_failed;
+static ssize_t zcache_pers_ate_eph;
+static ssize_t zcache_pers_ate_eph_failed;
+static ssize_t zcache_evicted_eph_zpages;
+static ssize_t zcache_evicted_eph_pageframes;
+
+extern ssize_t zcache_last_active_file_pageframes;
+extern ssize_t zcache_last_inactive_file_pageframes;
+extern ssize_t zcache_last_active_anon_pageframes;
+extern ssize_t zcache_last_inactive_anon_pageframes;
+static ssize_t zcache_eph_nonactive_puts_ignored;
+static ssize_t zcache_pers_nonactive_puts_ignored;
+#ifdef CONFIG_ZCACHE_WRITEBACK
+extern ssize_t zcache_writtenback_pages;
+extern ssize_t zcache_outstanding_writeback_pages;
+#endif
+
+static inline void inc_zcache_flush_total(void) { zcache_flush_total ++; };
+static inline void inc_zcache_flush_found(void) { zcache_flush_found ++; };
+static inline void inc_zcache_flobj_total(void) { zcache_flobj_total ++; };
+static inline void inc_zcache_flobj_found(void) { zcache_flobj_found ++; };
+static inline void inc_zcache_failed_eph_puts(void) { zcache_failed_eph_puts ++; };
+static inline void inc_zcache_failed_pers_puts(void) { zcache_failed_pers_puts ++; };
+static inline void inc_zcache_failed_getfreepages(void) { zcache_failed_getfreepages ++; };
+static inline void inc_zcache_failed_alloc(void) { zcache_failed_alloc ++; };
+static inline void inc_zcache_put_to_flush(void) { zcache_put_to_flush ++; };
+static inline void inc_zcache_compress_poor(void) { zcache_compress_poor ++; };
+static inline void inc_zcache_mean_compress_poor(void) { zcache_mean_compress_poor ++; };
+static inline void inc_zcache_eph_ate_tail(void) { zcache_eph_ate_tail ++; };
+static inline void inc_zcache_eph_ate_tail_failed(void) { zcache_eph_ate_tail_failed ++; };
+static inline void inc_zcache_pers_ate_eph(void) { zcache_pers_ate_eph ++; };
+static inline void inc_zcache_pers_ate_eph_failed(void) { zcache_pers_ate_eph_failed ++; };
+static inline void inc_zcache_evicted_eph_zpages(unsigned zpages) { zcache_evicted_eph_zpages += zpages; };
+static inline void inc_zcache_evicted_eph_pageframes(void) { zcache_evicted_eph_pageframes ++; };
+
+static inline void inc_zcache_eph_nonactive_puts_ignored(void) { zcache_eph_nonactive_puts_ignored ++; };
+static inline void inc_zcache_pers_nonactive_puts_ignored(void) { zcache_pers_nonactive_puts_ignored ++; };
+
+int zcache_debugfs_init(void);
+#else
+static inline void inc_zcache_obj_count(void) { };
+static inline void dec_zcache_obj_count(void) { };
+static inline void inc_zcache_objnode_count(void) { };
+static inline void dec_zcache_objnode_count(void) { };
+static inline void inc_zcache_eph_zbytes(unsigned clen) { };
+static inline void dec_zcache_eph_zbytes(unsigned zsize) { };
+static inline void inc_zcache_pers_zbytes(unsigned clen) { };
+static inline void dec_zcache_pers_zbytes(unsigned zsize) { };
+static inline void inc_zcache_eph_pageframes(void) { };
+static inline void dec_zcache_eph_pageframes(void) { };
+static inline void inc_zcache_pers_pageframes(void) { };
+static inline void dec_zcache_pers_pageframes(void) { };
+static inline void inc_zcache_pageframes_alloced(void) { };
+static inline void inc_zcache_pageframes_freed(void) { };
+static inline void inc_zcache_eph_zpages(void) { };
+static inline void dec_zcache_eph_zpages(unsigned zpages) { };
+static inline void inc_zcache_pers_zpages(void) { };
+static inline void dec_zcache_pers_zpages(unsigned zpages) { };
+static inline unsigned long curr_pageframes_count(void)
+{
+       return 0;
+};
+static inline int zcache_debugfs_init(void)
+{
+       return 0;
+};
+static inline void inc_zcache_flush_total(void) { };
+static inline void inc_zcache_flush_found(void) { };
+static inline void inc_zcache_flobj_total(void) { };
+static inline void inc_zcache_flobj_found(void) { };
+static inline void inc_zcache_failed_eph_puts(void) { };
+static inline void inc_zcache_failed_pers_puts(void) { };
+static inline void inc_zcache_failed_getfreepages(void) { };
+static inline void inc_zcache_failed_alloc(void) { };
+static inline void inc_zcache_put_to_flush(void) { };
+static inline void inc_zcache_compress_poor(void) { };
+static inline void inc_zcache_mean_compress_poor(void) { };
+static inline void inc_zcache_eph_ate_tail(void) { };
+static inline void inc_zcache_eph_ate_tail_failed(void) { };
+static inline void inc_zcache_pers_ate_eph(void) { };
+static inline void inc_zcache_pers_ate_eph_failed(void) { };
+static inline void inc_zcache_evicted_eph_zpages(unsigned zpages) { };
+static inline void inc_zcache_evicted_eph_pageframes(void) { };
+
+static inline void inc_zcache_eph_nonactive_puts_ignored(void) { };
+static inline void inc_zcache_pers_nonactive_puts_ignored(void) { };
+#endif
index 328898ea76c389284e2f57b18ecf224c1c7ae231..7a6dd966931bb78fba747d132b130d2718df3f49 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/types.h>
+#include <linux/string.h>
 #include <linux/atomic.h>
 #include <linux/math64.h>
 #include <linux/crypto.h>
 #include "zcache.h"
 #include "zbud.h"
 #include "ramster.h"
+#include "debug.h"
 #ifdef CONFIG_RAMSTER
-static int ramster_enabled;
+static bool ramster_enabled __read_mostly;
 #else
-#define ramster_enabled 0
+#define ramster_enabled false
 #endif
 
 #ifndef __PG_WAS_ACTIVE
@@ -62,18 +64,16 @@ static inline void frontswap_tmem_exclusive_gets(bool b)
 /* enable (or fix code) when Seth's patches are accepted upstream */
 #define zcache_writeback_enabled 0
 
-static int zcache_enabled __read_mostly;
-static int disable_cleancache __read_mostly;
-static int disable_frontswap __read_mostly;
-static int disable_frontswap_ignore_nonactive __read_mostly;
-static int disable_cleancache_ignore_nonactive __read_mostly;
+static bool zcache_enabled __read_mostly;
+static bool disable_cleancache __read_mostly;
+static bool disable_frontswap __read_mostly;
+static bool disable_frontswap_ignore_nonactive __read_mostly;
+static bool disable_cleancache_ignore_nonactive __read_mostly;
 static char *namestr __read_mostly = "zcache";
 
 #define ZCACHE_GFP_MASK \
        (__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC)
 
-MODULE_LICENSE("GPL");
-
 /* crypto API for zcache  */
 #define ZCACHE_COMP_NAME_SZ CRYPTO_MAX_ALG_NAME
 static char zcache_comp_name[ZCACHE_COMP_NAME_SZ] __read_mostly;
@@ -134,196 +134,21 @@ static struct kmem_cache *zcache_obj_cache;
 
 static DEFINE_PER_CPU(struct zcache_preload, zcache_preloads) = { 0, };
 
-/* we try to keep these statistics SMP-consistent */
-static ssize_t zcache_obj_count;
-static atomic_t zcache_obj_atomic = ATOMIC_INIT(0);
-static ssize_t zcache_obj_count_max;
-static ssize_t zcache_objnode_count;
-static atomic_t zcache_objnode_atomic = ATOMIC_INIT(0);
-static ssize_t zcache_objnode_count_max;
-static u64 zcache_eph_zbytes;
-static atomic_long_t zcache_eph_zbytes_atomic = ATOMIC_INIT(0);
-static u64 zcache_eph_zbytes_max;
-static u64 zcache_pers_zbytes;
-static atomic_long_t zcache_pers_zbytes_atomic = ATOMIC_INIT(0);
-static u64 zcache_pers_zbytes_max;
-static ssize_t zcache_eph_pageframes;
-static atomic_t zcache_eph_pageframes_atomic = ATOMIC_INIT(0);
-static ssize_t zcache_eph_pageframes_max;
-static ssize_t zcache_pers_pageframes;
-static atomic_t zcache_pers_pageframes_atomic = ATOMIC_INIT(0);
-static ssize_t zcache_pers_pageframes_max;
-static ssize_t zcache_pageframes_alloced;
-static atomic_t zcache_pageframes_alloced_atomic = ATOMIC_INIT(0);
-static ssize_t zcache_pageframes_freed;
-static atomic_t zcache_pageframes_freed_atomic = ATOMIC_INIT(0);
-static ssize_t zcache_eph_zpages;
-static ssize_t zcache_eph_zpages;
-static atomic_t zcache_eph_zpages_atomic = ATOMIC_INIT(0);
-static ssize_t zcache_eph_zpages_max;
-static ssize_t zcache_pers_zpages;
-static atomic_t zcache_pers_zpages_atomic = ATOMIC_INIT(0);
-static ssize_t zcache_pers_zpages_max;
-
-/* but for the rest of these, counting races are ok */
-static ssize_t zcache_flush_total;
-static ssize_t zcache_flush_found;
-static ssize_t zcache_flobj_total;
-static ssize_t zcache_flobj_found;
-static ssize_t zcache_failed_eph_puts;
-static ssize_t zcache_failed_pers_puts;
-static ssize_t zcache_failed_getfreepages;
-static ssize_t zcache_failed_alloc;
-static ssize_t zcache_put_to_flush;
-static ssize_t zcache_compress_poor;
-static ssize_t zcache_mean_compress_poor;
-static ssize_t zcache_eph_ate_tail;
-static ssize_t zcache_eph_ate_tail_failed;
-static ssize_t zcache_pers_ate_eph;
-static ssize_t zcache_pers_ate_eph_failed;
-static ssize_t zcache_evicted_eph_zpages;
-static ssize_t zcache_evicted_eph_pageframes;
-static ssize_t zcache_last_active_file_pageframes;
-static ssize_t zcache_last_inactive_file_pageframes;
-static ssize_t zcache_last_active_anon_pageframes;
-static ssize_t zcache_last_inactive_anon_pageframes;
-static ssize_t zcache_eph_nonactive_puts_ignored;
-static ssize_t zcache_pers_nonactive_puts_ignored;
-static ssize_t zcache_writtenback_pages;
-static ssize_t zcache_outstanding_writeback_pages;
-
-#ifdef CONFIG_DEBUG_FS
-#include <linux/debugfs.h>
-#define        zdfs    debugfs_create_size_t
-#define        zdfs64  debugfs_create_u64
-static int zcache_debugfs_init(void)
-{
-       struct dentry *root = debugfs_create_dir("zcache", NULL);
-       if (root == NULL)
-               return -ENXIO;
-
-       zdfs("obj_count", S_IRUGO, root, &zcache_obj_count);
-       zdfs("obj_count_max", S_IRUGO, root, &zcache_obj_count_max);
-       zdfs("objnode_count", S_IRUGO, root, &zcache_objnode_count);
-       zdfs("objnode_count_max", S_IRUGO, root, &zcache_objnode_count_max);
-       zdfs("flush_total", S_IRUGO, root, &zcache_flush_total);
-       zdfs("flush_found", S_IRUGO, root, &zcache_flush_found);
-       zdfs("flobj_total", S_IRUGO, root, &zcache_flobj_total);
-       zdfs("flobj_found", S_IRUGO, root, &zcache_flobj_found);
-       zdfs("failed_eph_puts", S_IRUGO, root, &zcache_failed_eph_puts);
-       zdfs("failed_pers_puts", S_IRUGO, root, &zcache_failed_pers_puts);
-       zdfs("failed_get_free_pages", S_IRUGO, root,
-                               &zcache_failed_getfreepages);
-       zdfs("failed_alloc", S_IRUGO, root, &zcache_failed_alloc);
-       zdfs("put_to_flush", S_IRUGO, root, &zcache_put_to_flush);
-       zdfs("compress_poor", S_IRUGO, root, &zcache_compress_poor);
-       zdfs("mean_compress_poor", S_IRUGO, root, &zcache_mean_compress_poor);
-       zdfs("eph_ate_tail", S_IRUGO, root, &zcache_eph_ate_tail);
-       zdfs("eph_ate_tail_failed", S_IRUGO, root, &zcache_eph_ate_tail_failed);
-       zdfs("pers_ate_eph", S_IRUGO, root, &zcache_pers_ate_eph);
-       zdfs("pers_ate_eph_failed", S_IRUGO, root, &zcache_pers_ate_eph_failed);
-       zdfs("evicted_eph_zpages", S_IRUGO, root, &zcache_evicted_eph_zpages);
-       zdfs("evicted_eph_pageframes", S_IRUGO, root,
-                               &zcache_evicted_eph_pageframes);
-       zdfs("eph_pageframes", S_IRUGO, root, &zcache_eph_pageframes);
-       zdfs("eph_pageframes_max", S_IRUGO, root, &zcache_eph_pageframes_max);
-       zdfs("pers_pageframes", S_IRUGO, root, &zcache_pers_pageframes);
-       zdfs("pers_pageframes_max", S_IRUGO, root, &zcache_pers_pageframes_max);
-       zdfs("eph_zpages", S_IRUGO, root, &zcache_eph_zpages);
-       zdfs("eph_zpages_max", S_IRUGO, root, &zcache_eph_zpages_max);
-       zdfs("pers_zpages", S_IRUGO, root, &zcache_pers_zpages);
-       zdfs("pers_zpages_max", S_IRUGO, root, &zcache_pers_zpages_max);
-       zdfs("last_active_file_pageframes", S_IRUGO, root,
-                               &zcache_last_active_file_pageframes);
-       zdfs("last_inactive_file_pageframes", S_IRUGO, root,
-                               &zcache_last_inactive_file_pageframes);
-       zdfs("last_active_anon_pageframes", S_IRUGO, root,
-                               &zcache_last_active_anon_pageframes);
-       zdfs("last_inactive_anon_pageframes", S_IRUGO, root,
-                               &zcache_last_inactive_anon_pageframes);
-       zdfs("eph_nonactive_puts_ignored", S_IRUGO, root,
-                               &zcache_eph_nonactive_puts_ignored);
-       zdfs("pers_nonactive_puts_ignored", S_IRUGO, root,
-                               &zcache_pers_nonactive_puts_ignored);
-       zdfs64("eph_zbytes", S_IRUGO, root, &zcache_eph_zbytes);
-       zdfs64("eph_zbytes_max", S_IRUGO, root, &zcache_eph_zbytes_max);
-       zdfs64("pers_zbytes", S_IRUGO, root, &zcache_pers_zbytes);
-       zdfs64("pers_zbytes_max", S_IRUGO, root, &zcache_pers_zbytes_max);
-       zdfs("outstanding_writeback_pages", S_IRUGO, root,
-                               &zcache_outstanding_writeback_pages);
-       zdfs("writtenback_pages", S_IRUGO, root, &zcache_writtenback_pages);
-       return 0;
-}
-#undef zdebugfs
-#undef zdfs64
-#endif
-
-#define ZCACHE_DEBUG
-#ifdef ZCACHE_DEBUG
-/* developers can call this in case of ooms, e.g. to find memory leaks */
-void zcache_dump(void)
-{
-       pr_info("zcache: obj_count=%zd\n", zcache_obj_count);
-       pr_info("zcache: obj_count_max=%zd\n", zcache_obj_count_max);
-       pr_info("zcache: objnode_count=%zd\n", zcache_objnode_count);
-       pr_info("zcache: objnode_count_max=%zd\n", zcache_objnode_count_max);
-       pr_info("zcache: flush_total=%zd\n", zcache_flush_total);
-       pr_info("zcache: flush_found=%zd\n", zcache_flush_found);
-       pr_info("zcache: flobj_total=%zd\n", zcache_flobj_total);
-       pr_info("zcache: flobj_found=%zd\n", zcache_flobj_found);
-       pr_info("zcache: failed_eph_puts=%zd\n", zcache_failed_eph_puts);
-       pr_info("zcache: failed_pers_puts=%zd\n", zcache_failed_pers_puts);
-       pr_info("zcache: failed_get_free_pages=%zd\n",
-                               zcache_failed_getfreepages);
-       pr_info("zcache: failed_alloc=%zd\n", zcache_failed_alloc);
-       pr_info("zcache: put_to_flush=%zd\n", zcache_put_to_flush);
-       pr_info("zcache: compress_poor=%zd\n", zcache_compress_poor);
-       pr_info("zcache: mean_compress_poor=%zd\n",
-                               zcache_mean_compress_poor);
-       pr_info("zcache: eph_ate_tail=%zd\n", zcache_eph_ate_tail);
-       pr_info("zcache: eph_ate_tail_failed=%zd\n",
-                               zcache_eph_ate_tail_failed);
-       pr_info("zcache: pers_ate_eph=%zd\n", zcache_pers_ate_eph);
-       pr_info("zcache: pers_ate_eph_failed=%zd\n",
-                               zcache_pers_ate_eph_failed);
-       pr_info("zcache: evicted_eph_zpages=%zd\n", zcache_evicted_eph_zpages);
-       pr_info("zcache: evicted_eph_pageframes=%zd\n",
-                               zcache_evicted_eph_pageframes);
-       pr_info("zcache: eph_pageframes=%zd\n", zcache_eph_pageframes);
-       pr_info("zcache: eph_pageframes_max=%zd\n", zcache_eph_pageframes_max);
-       pr_info("zcache: pers_pageframes=%zd\n", zcache_pers_pageframes);
-       pr_info("zcache: pers_pageframes_max=%zd\n",
-                               zcache_pers_pageframes_max);
-       pr_info("zcache: eph_zpages=%zd\n", zcache_eph_zpages);
-       pr_info("zcache: eph_zpages_max=%zd\n", zcache_eph_zpages_max);
-       pr_info("zcache: pers_zpages=%zd\n", zcache_pers_zpages);
-       pr_info("zcache: pers_zpages_max=%zd\n", zcache_pers_zpages_max);
-       pr_info("zcache: last_active_file_pageframes=%zd\n",
-                               zcache_last_active_file_pageframes);
-       pr_info("zcache: last_inactive_file_pageframes=%zd\n",
-                               zcache_last_inactive_file_pageframes);
-       pr_info("zcache: last_active_anon_pageframes=%zd\n",
-                               zcache_last_active_anon_pageframes);
-       pr_info("zcache: last_inactive_anon_pageframes=%zd\n",
-                               zcache_last_inactive_anon_pageframes);
-       pr_info("zcache: eph_nonactive_puts_ignored=%zd\n",
-                               zcache_eph_nonactive_puts_ignored);
-       pr_info("zcache: pers_nonactive_puts_ignored=%zd\n",
-                               zcache_pers_nonactive_puts_ignored);
-       pr_info("zcache: eph_zbytes=%llu\n",
-                               zcache_eph_zbytes);
-       pr_info("zcache: eph_zbytes_max=%llu\n",
-                               zcache_eph_zbytes_max);
-       pr_info("zcache: pers_zbytes=%llu\n",
-                               zcache_pers_zbytes);
-       pr_info("zcache: pers_zbytes_max=%llu\n",
-                               zcache_pers_zbytes_max);
-       pr_info("zcache: outstanding_writeback_pages=%zd\n",
-                               zcache_outstanding_writeback_pages);
-       pr_info("zcache: writtenback_pages=%zd\n", zcache_writtenback_pages);
-}
+/* Used by debug.c */
+ssize_t zcache_pers_zpages;
+u64 zcache_pers_zbytes;
+ssize_t zcache_eph_pageframes;
+ssize_t zcache_pers_pageframes;
+
+/* Used by this code. */
+ssize_t zcache_last_active_file_pageframes;
+ssize_t zcache_last_inactive_file_pageframes;
+ssize_t zcache_last_active_anon_pageframes;
+ssize_t zcache_last_inactive_anon_pageframes;
+#ifdef CONFIG_ZCACHE_WRITEBACK
+ssize_t zcache_writtenback_pages;
+ssize_t zcache_outstanding_writeback_pages;
 #endif
-
 /*
  * zcache core code starts here
  */
@@ -422,18 +247,14 @@ static struct tmem_objnode *zcache_objnode_alloc(struct tmem_pool *pool)
                }
        }
        BUG_ON(objnode == NULL);
-       zcache_objnode_count = atomic_inc_return(&zcache_objnode_atomic);
-       if (zcache_objnode_count > zcache_objnode_count_max)
-               zcache_objnode_count_max = zcache_objnode_count;
+       inc_zcache_objnode_count();
        return objnode;
 }
 
 static void zcache_objnode_free(struct tmem_objnode *objnode,
                                        struct tmem_pool *pool)
 {
-       zcache_objnode_count =
-               atomic_dec_return(&zcache_objnode_atomic);
-       BUG_ON(zcache_objnode_count < 0);
+       dec_zcache_objnode_count();
        kmem_cache_free(zcache_objnode_cache, objnode);
 }
 
@@ -446,17 +267,13 @@ static struct tmem_obj *zcache_obj_alloc(struct tmem_pool *pool)
        obj = kp->obj;
        BUG_ON(obj == NULL);
        kp->obj = NULL;
-       zcache_obj_count = atomic_inc_return(&zcache_obj_atomic);
-       if (zcache_obj_count > zcache_obj_count_max)
-               zcache_obj_count_max = zcache_obj_count;
+       inc_zcache_obj_count();
        return obj;
 }
 
 static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool)
 {
-       zcache_obj_count =
-               atomic_dec_return(&zcache_obj_atomic);
-       BUG_ON(zcache_obj_count < 0);
+       dec_zcache_obj_count();
        kmem_cache_free(zcache_obj_cache, obj);
 }
 
@@ -472,8 +289,7 @@ static struct page *zcache_alloc_page(void)
        struct page *page = alloc_page(ZCACHE_GFP_MASK);
 
        if (page != NULL)
-               zcache_pageframes_alloced =
-                       atomic_inc_return(&zcache_pageframes_alloced_atomic);
+               inc_zcache_pageframes_alloced();
        return page;
 }
 
@@ -485,17 +301,13 @@ static void zcache_free_page(struct page *page)
        if (page == NULL)
                BUG();
        __free_page(page);
-       zcache_pageframes_freed =
-               atomic_inc_return(&zcache_pageframes_freed_atomic);
-       curr_pageframes = zcache_pageframes_alloced -
-                       atomic_read(&zcache_pageframes_freed_atomic) -
-                       atomic_read(&zcache_eph_pageframes_atomic) -
-                       atomic_read(&zcache_pers_pageframes_atomic);
+       inc_zcache_pageframes_freed();
+       curr_pageframes = curr_pageframes_count();
        if (curr_pageframes > max_pageframes)
                max_pageframes = curr_pageframes;
        if (curr_pageframes < min_pageframes)
                min_pageframes = curr_pageframes;
-#ifdef ZCACHE_DEBUG
+#ifdef CONFIG_ZCACHE_DEBUG
        if (curr_pageframes > 2L || curr_pageframes < -2L) {
                /* pr_info here */
        }
@@ -522,7 +334,7 @@ static void *zcache_pampd_eph_create(char *data, size_t size, bool raw,
        if (!raw) {
                zcache_compress(page, &cdata, &clen);
                if (clen > zbud_max_buddy_size()) {
-                       zcache_compress_poor++;
+                       inc_zcache_compress_poor();
                        goto out;
                }
        } else {
@@ -539,31 +351,23 @@ static void *zcache_pampd_eph_create(char *data, size_t size, bool raw,
        if (newpage != NULL)
                goto create_in_new_page;
 
-       zcache_failed_getfreepages++;
+       inc_zcache_failed_getfreepages();
        /* can't allocate a page, evict an ephemeral page via LRU */
        newpage = zcache_evict_eph_pageframe();
        if (newpage == NULL) {
-               zcache_eph_ate_tail_failed++;
+               inc_zcache_eph_ate_tail_failed();
                goto out;
        }
-       zcache_eph_ate_tail++;
+       inc_zcache_eph_ate_tail();
 
 create_in_new_page:
        pampd = (void *)zbud_create_prep(th, true, cdata, clen, newpage);
        BUG_ON(pampd == NULL);
-       zcache_eph_pageframes =
-               atomic_inc_return(&zcache_eph_pageframes_atomic);
-       if (zcache_eph_pageframes > zcache_eph_pageframes_max)
-               zcache_eph_pageframes_max = zcache_eph_pageframes;
+       inc_zcache_eph_pageframes();
 
 got_pampd:
-       zcache_eph_zbytes =
-               atomic_long_add_return(clen, &zcache_eph_zbytes_atomic);
-       if (zcache_eph_zbytes > zcache_eph_zbytes_max)
-               zcache_eph_zbytes_max = zcache_eph_zbytes;
-       zcache_eph_zpages = atomic_inc_return(&zcache_eph_zpages_atomic);
-       if (zcache_eph_zpages > zcache_eph_zpages_max)
-               zcache_eph_zpages_max = zcache_eph_zpages;
+       inc_zcache_eph_zbytes(clen);
+       inc_zcache_eph_zpages();
        if (ramster_enabled && raw)
                ramster_count_foreign_pages(true, 1);
 out:
@@ -589,7 +393,7 @@ static void *zcache_pampd_pers_create(char *data, size_t size, bool raw,
                zcache_compress(page, &cdata, &clen);
        /* reject if compression is too poor */
        if (clen > zbud_max_zsize) {
-               zcache_compress_poor++;
+               inc_zcache_compress_poor();
                goto out;
        }
        /* reject if mean compression is too poor */
@@ -600,7 +404,7 @@ static void *zcache_pampd_pers_create(char *data, size_t size, bool raw,
                zbud_mean_zsize = div_u64(total_zsize,
                                        curr_pers_zpages);
                if (zbud_mean_zsize > zbud_max_mean_zsize) {
-                       zcache_mean_compress_poor++;
+                       inc_zcache_mean_compress_poor();
                        goto out;
                }
        }
@@ -621,31 +425,23 @@ create_pampd:
         * (global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE) +
         * global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE)))
         */
-       zcache_failed_getfreepages++;
+       inc_zcache_failed_getfreepages();
        /* can't allocate a page, evict an ephemeral page via LRU */
        newpage = zcache_evict_eph_pageframe();
        if (newpage == NULL) {
-               zcache_pers_ate_eph_failed++;
+               inc_zcache_pers_ate_eph_failed();
                goto out;
        }
-       zcache_pers_ate_eph++;
+       inc_zcache_pers_ate_eph();
 
 create_in_new_page:
        pampd = (void *)zbud_create_prep(th, false, cdata, clen, newpage);
        BUG_ON(pampd == NULL);
-       zcache_pers_pageframes =
-               atomic_inc_return(&zcache_pers_pageframes_atomic);
-       if (zcache_pers_pageframes > zcache_pers_pageframes_max)
-               zcache_pers_pageframes_max = zcache_pers_pageframes;
+       inc_zcache_pers_pageframes();
 
 got_pampd:
-       zcache_pers_zpages = atomic_inc_return(&zcache_pers_zpages_atomic);
-       if (zcache_pers_zpages > zcache_pers_zpages_max)
-               zcache_pers_zpages_max = zcache_pers_zpages;
-       zcache_pers_zbytes =
-               atomic_long_add_return(clen, &zcache_pers_zbytes_atomic);
-       if (zcache_pers_zbytes > zcache_pers_zbytes_max)
-               zcache_pers_zbytes_max = zcache_pers_zbytes;
+       inc_zcache_pers_zpages();
+       inc_zcache_pers_zbytes(clen);
        if (ramster_enabled && raw)
                ramster_count_foreign_pages(false, 1);
 out:
@@ -676,7 +472,7 @@ void *zcache_pampd_create(char *data, unsigned int size, bool raw,
                        objnode = kmem_cache_alloc(zcache_objnode_cache,
                                                        ZCACHE_GFP_MASK);
                        if (unlikely(objnode == NULL)) {
-                               zcache_failed_alloc++;
+                               inc_zcache_failed_alloc();
                                goto out;
                        }
                        kp->objnodes[i] = objnode;
@@ -687,7 +483,7 @@ void *zcache_pampd_create(char *data, unsigned int size, bool raw,
                kp->obj = obj;
        }
        if (unlikely(kp->obj == NULL)) {
-               zcache_failed_alloc++;
+               inc_zcache_failed_alloc();
                goto out;
        }
        /*
@@ -794,20 +590,14 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw,
                                        &zsize, &zpages);
        if (eph) {
                if (page)
-                       zcache_eph_pageframes =
-                           atomic_dec_return(&zcache_eph_pageframes_atomic);
-               zcache_eph_zpages =
-                   atomic_sub_return(zpages, &zcache_eph_zpages_atomic);
-               zcache_eph_zbytes =
-                   atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic);
+                       dec_zcache_eph_pageframes();
+               dec_zcache_eph_zpages(zpages);
+               dec_zcache_eph_zbytes(zsize);
        } else {
                if (page)
-                       zcache_pers_pageframes =
-                           atomic_dec_return(&zcache_pers_pageframes_atomic);
-               zcache_pers_zpages =
-                   atomic_sub_return(zpages, &zcache_pers_zpages_atomic);
-               zcache_pers_zbytes =
-                   atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic);
+                       dec_zcache_pers_pageframes();
+               dec_zcache_pers_zpages(zpages);
+               dec_zcache_pers_zbytes(zsize);
        }
        if (!is_local_client(pool->client))
                ramster_count_foreign_pages(eph, -1);
@@ -837,23 +627,17 @@ static void zcache_pampd_free(void *pampd, struct tmem_pool *pool,
                page = zbud_free_and_delist((struct zbudref *)pampd,
                                                true, &zsize, &zpages);
                if (page)
-                       zcache_eph_pageframes =
-                           atomic_dec_return(&zcache_eph_pageframes_atomic);
-               zcache_eph_zpages =
-                   atomic_sub_return(zpages, &zcache_eph_zpages_atomic);
-               zcache_eph_zbytes =
-                   atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic);
+                       dec_zcache_eph_pageframes();
+               dec_zcache_eph_zpages(zpages);
+               dec_zcache_eph_zbytes(zsize);
                /* FIXME CONFIG_RAMSTER... check acct parameter? */
        } else {
                page = zbud_free_and_delist((struct zbudref *)pampd,
                                                false, &zsize, &zpages);
                if (page)
-                       zcache_pers_pageframes =
-                           atomic_dec_return(&zcache_pers_pageframes_atomic);
-               zcache_pers_zpages =
-                    atomic_sub_return(zpages, &zcache_pers_zpages_atomic);
-               zcache_pers_zbytes =
-                   atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic);
+                       dec_zcache_pers_pageframes();
+               dec_zcache_pers_zpages(zpages);
+               dec_zcache_pers_zbytes(zsize);
        }
        if (!is_local_client(pool->client))
                ramster_count_foreign_pages(is_ephemeral(pool), -1);
@@ -975,14 +759,11 @@ static struct page *zcache_evict_eph_pageframe(void)
        page = zbud_evict_pageframe_lru(&zsize, &zpages);
        if (page == NULL)
                goto out;
-       zcache_eph_zbytes = atomic_long_sub_return(zsize,
-                                       &zcache_eph_zbytes_atomic);
-       zcache_eph_zpages = atomic_sub_return(zpages,
-                                       &zcache_eph_zpages_atomic);
-       zcache_evicted_eph_zpages += zpages;
-       zcache_eph_pageframes =
-               atomic_dec_return(&zcache_eph_pageframes_atomic);
-       zcache_evicted_eph_pageframes++;
+       dec_zcache_eph_zbytes(zsize);
+       dec_zcache_eph_zpages(zpages);
+       inc_zcache_evicted_eph_zpages(zpages);
+       dec_zcache_eph_pageframes();
+       inc_zcache_evicted_eph_pageframes();
 out:
        return page;
 }
@@ -991,6 +772,16 @@ out:
 
 static atomic_t zcache_outstanding_writeback_pages_atomic = ATOMIC_INIT(0);
 
+static inline void inc_zcache_outstanding_writeback_pages(void)
+{
+       zcache_outstanding_writeback_pages =
+           atomic_inc_return(&zcache_outstanding_writeback_pages_atomic);
+}
+static inline void dec_zcache_outstanding_writeback_pages(void)
+{
+       zcache_outstanding_writeback_pages =
+         atomic_dec_return(&zcache_outstanding_writeback_pages_atomic);
+};
 static void unswiz(struct tmem_oid oid, u32 index,
                                unsigned *type, pgoff_t *offset);
 
@@ -1004,8 +795,7 @@ static void unswiz(struct tmem_oid oid, u32 index,
 static void zcache_end_swap_write(struct bio *bio, int err)
 {
        end_swap_bio_write(bio, err);
-       zcache_outstanding_writeback_pages =
-         atomic_dec_return(&zcache_outstanding_writeback_pages_atomic);
+       dec_zcache_outstanding_writeback_pages();
        zcache_writtenback_pages++;
 }
 
@@ -1120,8 +910,7 @@ static int zcache_frontswap_writeback_zpage(int type, pgoff_t offset,
         */
        (void)__swap_writepage(page, &wbc, zcache_end_swap_write);
        page_cache_release(page);
-       zcache_outstanding_writeback_pages =
-           atomic_inc_return(&zcache_outstanding_writeback_pages_atomic);
+       inc_zcache_outstanding_writeback_pages();
 
        return 0;
 }
@@ -1357,9 +1146,9 @@ int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp,
                if (pampd == NULL) {
                        ret = -ENOMEM;
                        if (ephemeral)
-                               zcache_failed_eph_puts++;
+                               inc_zcache_failed_eph_puts();
                        else
-                               zcache_failed_pers_puts++;
+                               inc_zcache_failed_pers_puts();
                } else {
                        if (ramster_enabled)
                                ramster_do_preload_flnode(pool);
@@ -1369,7 +1158,7 @@ int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp,
                }
                zcache_put_pool(pool);
        } else {
-               zcache_put_to_flush++;
+               inc_zcache_put_to_flush();
                if (ramster_enabled)
                        ramster_do_preload_flnode(pool);
                if (atomic_read(&pool->obj_count) > 0)
@@ -1419,7 +1208,7 @@ int zcache_flush_page(int cli_id, int pool_id,
        unsigned long flags;
 
        local_irq_save(flags);
-       zcache_flush_total++;
+       inc_zcache_flush_total();
        pool = zcache_get_pool_by_id(cli_id, pool_id);
        if (ramster_enabled)
                ramster_do_preload_flnode(pool);
@@ -1429,7 +1218,7 @@ int zcache_flush_page(int cli_id, int pool_id,
                zcache_put_pool(pool);
        }
        if (ret >= 0)
-               zcache_flush_found++;
+               inc_zcache_flush_found();
        local_irq_restore(flags);
        return ret;
 }
@@ -1442,7 +1231,7 @@ int zcache_flush_object(int cli_id, int pool_id,
        unsigned long flags;
 
        local_irq_save(flags);
-       zcache_flobj_total++;
+       inc_zcache_flobj_total();
        pool = zcache_get_pool_by_id(cli_id, pool_id);
        if (ramster_enabled)
                ramster_do_preload_flnode(pool);
@@ -1452,7 +1241,7 @@ int zcache_flush_object(int cli_id, int pool_id,
                zcache_put_pool(pool);
        }
        if (ret >= 0)
-               zcache_flobj_found++;
+               inc_zcache_flobj_found();
        local_irq_restore(flags);
        return ret;
 }
@@ -1615,7 +1404,7 @@ static void zcache_cleancache_put_page(int pool_id,
        struct tmem_oid oid = *(struct tmem_oid *)&key;
 
        if (!disable_cleancache_ignore_nonactive && !PageWasActive(page)) {
-               zcache_eph_nonactive_puts_ignored++;
+               inc_zcache_eph_nonactive_puts_ignored();
                return;
        }
        if (likely(ind == index))
@@ -1744,7 +1533,7 @@ static int zcache_frontswap_put_page(unsigned type, pgoff_t offset,
 
        BUG_ON(!PageLocked(page));
        if (!disable_frontswap_ignore_nonactive && !PageWasActive(page)) {
-               zcache_pers_nonactive_puts_ignored++;
+               inc_zcache_pers_nonactive_puts_ignored();
                ret = -ERANGE;
                goto out;
        }
@@ -1841,16 +1630,16 @@ struct frontswap_ops zcache_frontswap_register_ops(void)
 
 static int __init enable_zcache(char *s)
 {
-       zcache_enabled = 1;
+       zcache_enabled = true;
        return 1;
 }
 __setup("zcache", enable_zcache);
 
 static int __init enable_ramster(char *s)
 {
-       zcache_enabled = 1;
+       zcache_enabled = true;
 #ifdef CONFIG_RAMSTER
-       ramster_enabled = 1;
+       ramster_enabled = true;
 #endif
        return 1;
 }
@@ -1860,7 +1649,7 @@ __setup("ramster", enable_ramster);
 
 static int __init no_cleancache(char *s)
 {
-       disable_cleancache = 1;
+       disable_cleancache = true;
        return 1;
 }
 
@@ -1868,7 +1657,7 @@ __setup("nocleancache", no_cleancache);
 
 static int __init no_frontswap(char *s)
 {
-       disable_frontswap = 1;
+       disable_frontswap = true;
        return 1;
 }
 
@@ -1884,7 +1673,7 @@ __setup("nofrontswapexclusivegets", no_frontswap_exclusive_gets);
 
 static int __init no_frontswap_ignore_nonactive(char *s)
 {
-       disable_frontswap_ignore_nonactive = 1;
+       disable_frontswap_ignore_nonactive = true;
        return 1;
 }
 
@@ -1892,7 +1681,7 @@ __setup("nofrontswapignorenonactive", no_frontswap_ignore_nonactive);
 
 static int __init no_cleancache_ignore_nonactive(char *s)
 {
-       disable_cleancache_ignore_nonactive = 1;
+       disable_cleancache_ignore_nonactive = true;
        return 1;
 }
 
@@ -1900,8 +1689,8 @@ __setup("nocleancacheignorenonactive", no_cleancache_ignore_nonactive);
 
 static int __init enable_zcache_compressor(char *s)
 {
-       strncpy(zcache_comp_name, s, ZCACHE_COMP_NAME_SZ);
-       zcache_enabled = 1;
+       strlcpy(zcache_comp_name, s, sizeof(zcache_comp_name));
+       zcache_enabled = true;
        return 1;
 }
 __setup("zcache=", enable_zcache_compressor);
@@ -1986,7 +1775,7 @@ static int __init zcache_init(void)
                old_ops = zcache_cleancache_register_ops();
                pr_info("%s: cleancache enabled using kernel transcendent "
                        "memory and compression buddies\n", namestr);
-#ifdef ZCACHE_DEBUG
+#ifdef CONFIG_ZCACHE_DEBUG
                pr_info("%s: cleancache: ignorenonactive = %d\n",
                        namestr, !disable_cleancache_ignore_nonactive);
 #endif
@@ -2001,7 +1790,7 @@ static int __init zcache_init(void)
                        frontswap_tmem_exclusive_gets(true);
                pr_info("%s: frontswap enabled using kernel transcendent "
                        "memory and compression buddies\n", namestr);
-#ifdef ZCACHE_DEBUG
+#ifdef CONFIG_ZCACHE_DEBUG
                pr_info("%s: frontswap: excl gets = %d active only = %d\n",
                        namestr, frontswap_has_exclusive_gets,
                        !disable_frontswap_ignore_nonactive);
index 5918fd7d7e36942ff813e4f7399907fe3e194cb2..e34e3fe0ae2e61f12f7c167ba74588d663dee09a 100644 (file)
@@ -207,11 +207,8 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
 
        ret = zram_decompress_page(zram, uncmem, index);
        /* Should NEVER happen. Return bio error if it does. */
-       if (unlikely(ret != LZO_E_OK)) {
-               pr_err("Decompression failed! err=%d, page=%u\n", ret, index);
-               zram_stat64_inc(zram, &zram->stats.failed_reads);
+       if (unlikely(ret != LZO_E_OK))
                goto out_cleanup;
-       }
 
        if (is_partial_io(bvec))
                memcpy(user_mem + bvec->bv_offset, uncmem + offset,
index 908456565796770c44065eb432622071bf8cbcf2..7fab032298f33986cd55b518d3db60eebadb4d9b 100644 (file)
@@ -1,5 +1,5 @@
 config ZSMALLOC
-       tristate "Memory allocator for compressed pages"
+       bool "Memory allocator for compressed pages"
        default n
        help
          zsmalloc is a slab-based memory allocator designed to store
index e78d262c5249887415b4b5a628ee684a47408f87..324e123335d69b61f3f1c94084711b803bdeb61d 100644 (file)
@@ -656,11 +656,8 @@ static inline void __zs_unmap_object(struct mapping_area *area,
                                struct page *pages[2], int off, int size)
 {
        unsigned long addr = (unsigned long)area->vm_addr;
-       unsigned long end = addr + (PAGE_SIZE * 2);
 
-       flush_cache_vunmap(addr, end);
-       unmap_kernel_range_noflush(addr, PAGE_SIZE * 2);
-       flush_tlb_kernel_range(addr, end);
+       unmap_kernel_range(addr, PAGE_SIZE * 2);
 }
 
 #else /* USE_PGTABLE_MAPPING */
index 2e4eab9868a3f18f4d068450517a697c78fdf326..e7fdec4db9dac5dc9b73ccf64f3fbbd1a00c12d6 100644 (file)
@@ -133,9 +133,9 @@ int ad_sd_validate_trigger(struct iio_dev *indio_dev, struct iio_trigger *trig);
                .channel2 = (_channel2), \
                .address = (_address), \
                .extend_name = (_extend_name), \
-               .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-                       IIO_CHAN_INFO_SCALE_SHARED_BIT | \
-                       IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, \
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+                       BIT(IIO_CHAN_INFO_OFFSET), \
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
                .scan_index = (_si), \
                .scan_type = { \
                        .sign = 'u', \
index 8bd12be0b02f875f1182e9fdcaee69598bc8e083..172c5b23cb840d5270fde51d9809e321f012211a 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/spi/spi.h>
 #include <linux/irqreturn.h>
 #include <linux/iio/trigger.h>
+#include <linux/bitops.h>
 
 #define ST_SENSORS_TX_MAX_LENGTH               2
 #define ST_SENSORS_RX_MAX_LENGTH               6
@@ -45,8 +46,8 @@
 { \
        .type = device_type, \
        .modified = 1, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-                       IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+                       BIT(IIO_CHAN_INFO_SCALE), \
        .scan_index = index, \
        .channel2 = mod, \
        .address = addr, \
index da8c776ba0bdd0415bb6714903275d9e1baac362..8d171f42763261cc15f7944fd3f27f22fb003c1b 100644 (file)
@@ -38,76 +38,6 @@ enum iio_chan_info_enum {
        IIO_CHAN_INFO_HYSTERESIS,
 };
 
-#define IIO_CHAN_INFO_SHARED_BIT(type) BIT(type*2)
-#define IIO_CHAN_INFO_SEPARATE_BIT(type) BIT(type*2 + 1)
-#define IIO_CHAN_INFO_BITS(type) (IIO_CHAN_INFO_SHARED_BIT(type) | \
-                                   IIO_CHAN_INFO_SEPARATE_BIT(type))
-
-#define IIO_CHAN_INFO_RAW_SEPARATE_BIT                 \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_RAW)
-#define IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT                   \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PROCESSED)
-#define IIO_CHAN_INFO_SCALE_SEPARATE_BIT               \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_SCALE)
-#define IIO_CHAN_INFO_SCALE_SHARED_BIT                 \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_SCALE)
-#define IIO_CHAN_INFO_OFFSET_SEPARATE_BIT                      \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_OFFSET)
-#define IIO_CHAN_INFO_OFFSET_SHARED_BIT                        \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_OFFSET)
-#define IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT                  \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_CALIBSCALE)
-#define IIO_CHAN_INFO_CALIBSCALE_SHARED_BIT                    \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_CALIBSCALE)
-#define IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT                   \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_CALIBBIAS)
-#define IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT                     \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_CALIBBIAS)
-#define IIO_CHAN_INFO_PEAK_SEPARATE_BIT                        \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PEAK)
-#define IIO_CHAN_INFO_PEAK_SHARED_BIT                  \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PEAK)
-#define IIO_CHAN_INFO_PEAKSCALE_SEPARATE_BIT                   \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PEAKSCALE)
-#define IIO_CHAN_INFO_PEAKSCALE_SHARED_BIT                     \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PEAKSCALE)
-#define IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT   \
-       IIO_CHAN_INFO_SEPARATE_BIT(                             \
-               IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW)
-#define IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SHARED_BIT     \
-       IIO_CHAN_INFO_SHARED_BIT(                               \
-               IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW)
-#define IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT                 \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_AVERAGE_RAW)
-#define IIO_CHAN_INFO_AVERAGE_RAW_SHARED_BIT                   \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_AVERAGE_RAW)
-#define IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT \
-       IIO_CHAN_INFO_SHARED_BIT(                              \
-               IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY)
-#define IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SEPARATE_BIT \
-       IIO_CHAN_INFO_SEPARATE_BIT(                            \
-               IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY)
-#define IIO_CHAN_INFO_SAMP_FREQ_SEPARATE_BIT           \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_SAMP_FREQ)
-#define IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT                     \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_SAMP_FREQ)
-#define IIO_CHAN_INFO_FREQUENCY_SEPARATE_BIT                   \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_FREQUENCY)
-#define IIO_CHAN_INFO_FREQUENCY_SHARED_BIT                     \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_FREQUENCY)
-#define IIO_CHAN_INFO_PHASE_SEPARATE_BIT                       \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PHASE)
-#define IIO_CHAN_INFO_PHASE_SHARED_BIT                 \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PHASE)
-#define IIO_CHAN_INFO_HARDWAREGAIN_SEPARATE_BIT                        \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_HARDWAREGAIN)
-#define IIO_CHAN_INFO_HARDWAREGAIN_SHARED_BIT                  \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_HARDWAREGAIN)
-#define IIO_CHAN_INFO_HYSTERESIS_SEPARATE_BIT                  \
-       IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_HYSTERESIS)
-#define IIO_CHAN_INFO_HYSTERESIS_SHARED_BIT                    \
-       IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_HYSTERESIS)
-
 enum iio_endian {
        IIO_CPU,
        IIO_BE,
@@ -218,6 +148,10 @@ ssize_t iio_enum_write(struct iio_dev *indio_dev,
  *                     endianness:     little or big endian
  * @info_mask:         What information is to be exported about this channel.
  *                     This includes calibbias, scale etc.
+ * @info_mask_separate: What information is to be exported that is specific to
+ *                     this channel.
+ * @info_mask_shared_by_type: What information is to be exported that is shared
+*                      by all channels of the same type.
  * @event_mask:                What events can this channel produce.
  * @ext_info:          Array of extended info attributes for this channel.
  *                     The array is NULL terminated, the last element should
@@ -253,6 +187,8 @@ struct iio_chan_spec {
                enum iio_endian endianness;
        } scan_type;
        long                    info_mask;
+       long                    info_mask_separate;
+       long                    info_mask_shared_by_type;
        long                    event_mask;
        const struct iio_chan_spec_ext_info *ext_info;
        const char              *extend_name;
@@ -275,7 +211,8 @@ struct iio_chan_spec {
 static inline bool iio_channel_has_info(const struct iio_chan_spec *chan,
        enum iio_chan_info_enum type)
 {
-       return chan->info_mask & IIO_CHAN_INFO_BITS(type);
+       return (chan->info_mask_separate & type) |
+              (chan->info_mask_shared_by_type & type);
 }
 
 #define IIO_ST(si, rb, sb, sh)                                         \
index ff781dca2e9ab2727446d96b97d808f7dc0f18a4..b665dc7f017b5f57f81ae06d7c102841003ceea9 100644 (file)
@@ -162,8 +162,8 @@ int adis_single_conversion(struct iio_dev *indio_dev,
        .indexed = 1, \
        .channel = (chan), \
        .extend_name = name, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+               BIT(IIO_CHAN_INFO_SCALE), \
        .address = (addr), \
        .scan_index = (si), \
        .scan_type = { \
@@ -184,9 +184,9 @@ int adis_single_conversion(struct iio_dev *indio_dev,
        .type = IIO_TEMP, \
        .indexed = 1, \
        .channel = 0, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-               IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \
-               IIO_CHAN_INFO_OFFSET_SEPARATE_BIT, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+               BIT(IIO_CHAN_INFO_SCALE) | \
+               BIT(IIO_CHAN_INFO_OFFSET), \
        .address = (addr), \
        .scan_index = (si), \
        .scan_type = { \
@@ -197,13 +197,13 @@ int adis_single_conversion(struct iio_dev *indio_dev,
        }, \
 }
 
-#define ADIS_MOD_CHAN(_type, mod, addr, si, info, bits) { \
+#define ADIS_MOD_CHAN(_type, mod, addr, si, info_sep, bits) { \
        .type = (_type), \
        .modified = 1, \
        .channel2 = IIO_MOD_ ## mod, \
-       .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
-                IIO_CHAN_INFO_SCALE_SHARED_BIT | \
-                info, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+                info_sep, \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
        .address = (addr), \
        .scan_index = (si), \
        .scan_type = { \
@@ -214,17 +214,17 @@ int adis_single_conversion(struct iio_dev *indio_dev,
        }, \
 }
 
-#define ADIS_ACCEL_CHAN(mod, addr, si, info, bits) \
-       ADIS_MOD_CHAN(IIO_ACCEL, mod, addr, si, info, bits)
+#define ADIS_ACCEL_CHAN(mod, addr, si, info_sep, bits) \
+       ADIS_MOD_CHAN(IIO_ACCEL, mod, addr, si, info_sep, bits)
 
-#define ADIS_GYRO_CHAN(mod, addr, si, info, bits) \
-       ADIS_MOD_CHAN(IIO_ANGL_VEL, mod, addr, si, info, bits)
+#define ADIS_GYRO_CHAN(mod, addr, si, info_sep, bits) \
+       ADIS_MOD_CHAN(IIO_ANGL_VEL, mod, addr, si, info_sep, bits)
 
-#define ADIS_INCLI_CHAN(mod, addr, si, info, bits) \
-       ADIS_MOD_CHAN(IIO_INCLI, mod, addr, si, info, bits)
+#define ADIS_INCLI_CHAN(mod, addr, si, info_sep, bits) \
+       ADIS_MOD_CHAN(IIO_INCLI, mod, addr, si, info_sep, bits)
 
-#define ADIS_ROT_CHAN(mod, addr, si, info, bits) \
-       ADIS_MOD_CHAN(IIO_ROT, mod, addr, si, info, bits)
+#define ADIS_ROT_CHAN(mod, addr, si, info_sep, bits) \
+       ADIS_MOD_CHAN(IIO_ROT, mod, addr, si, info_sep, bits)
 
 #ifdef CONFIG_IIO_ADIS_LIB_BUFFER
 
index c66e0a96f6e8aa9a3d6940e2f563b74e1cae0f8c..3869c525b052171fff8bbe3000d61d5999bae7ee 100644 (file)
@@ -44,7 +44,6 @@ struct iio_trigger_ops {
  * @id:                        [INTERN] unique id number
  * @name:              [DRIVER] unique name
  * @dev:               [DRIVER] associated device (if relevant)
- * @private_data:      [DRIVER] device specific data
  * @list:              [INTERN] used in maintenance of global trigger list
  * @alloc_list:                [DRIVER] used for driver specific trigger list
  * @use_count:         use count for the trigger
@@ -60,7 +59,6 @@ struct iio_trigger {
        const char                      *name;
        struct device                   dev;
 
-       void                            *private_data;
        struct list_head                list;
        struct list_head                alloc_list;
        int use_count;
@@ -91,6 +89,30 @@ static inline void iio_trigger_get(struct iio_trigger *trig)
        __module_get(trig->ops->owner);
 }
 
+/**
+ * iio_device_set_drvdata() - Set trigger driver data
+ * @trig: IIO trigger structure
+ * @data: Driver specific data
+ *
+ * Allows to attach an arbitrary pointer to an IIO trigger, which can later be
+ * retrieved by iio_trigger_get_drvdata().
+ */
+static inline void iio_trigger_set_drvdata(struct iio_trigger *trig, void *data)
+{
+       dev_set_drvdata(&trig->dev, data);
+}
+
+/**
+ * iio_trigger_get_drvdata() - Get trigger driver data
+ * @trig: IIO trigger structure
+ *
+ * Returns the data previously set with iio_trigger_set_drvdata()
+ */
+static inline void *iio_trigger_get_drvdata(struct iio_trigger *trig)
+{
+       return dev_get_drvdata(&trig->dev);
+}
+
 /**
  * iio_trigger_register() - register a trigger with the IIO core
  * @trig_info: trigger to be registered
This page took 2.138831 seconds and 5 git commands to generate.